{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_HADDOCK show-extensions #-}

{- |
Module      :  Aftovolio.ConstraintsEncoded
Copyright   :  (c) OleksandrZhabenko 2020-2024
License     :  MIT
Stability   :  Experimental
Maintainer  :  oleksandr.zhabenko@yahoo.com

Provides a way to encode the needed constraint with possibly less symbols.
Uses arrays instead of vectors.
-}
module Aftovolio.ConstraintsEncoded (
    -- * Data types
    EncodedContraints (..),
    EncodedCnstrs,

    -- * Functions to work with them

    -- ** Read functions
    readMaybeECG,

    -- ** Process-encoding functions
    decodeConstraint1,
    decodeLConstraints,
    isConstraint1,

    -- ** Modifiers and getters
    getIEl,
    setIEl,

    -- ** Predicates
    isE,
    isP,
    isF,
    isQ,
    isT,
    isSA,
    isSB,
    isV,
    isW,
    isH,
    isR,
    isM,
    isN,
    isD,
    isI,
    isU,
    isG,

    -- * Algebraic general conversion
    validOrdStr,
    generalConversion,
    filterGeneralConv,
) where

import Aftovolio.Constraints
import Data.Char (isDigit, isLetter)
import Data.InsertLeft (InsertLeft (..), splitAtEndG)
import Data.List (groupBy, nub, words)
import Data.Maybe
import Data.Tuple (fst)
import GHC.Arr
import GHC.Base
import GHC.List
import GHC.Num (abs, (+), (-))
import Text.Read (readMaybe)
import Text.Show (Show (..), show)

data EncodedContraints a b d
    = -- | Represents no additional constraint, corresponds to the whole set of theoretically possible permutations.
      E
    | -- | Represents the set of permutations with the fixed positions of some elements.
      P a b
    | -- | Represents the set of permutations with the preserved pairwise order between first and second, second and third, third and fourth elements.
      Q a a a a a
    | -- | Represents the set of permutations with the preserved pairwise order between first and second, second and third elements.
      T a a a a
    | -- | Represents the set of permutations with the preserved position of the elements AFTER the another selected one.
      SA a a b
    | -- | Represents the set of permutations with the preserved position of the elements BEFORE the another selected one.
      SB a a b
    | -- | Represents the set of permutations with the preserved order between first and second elements.
      F a a a
    | -- | Represents the set of permutations with the preserved both distance between and order of the two elements.
      V a a a
    | -- | Represents the set of permutations with the preserved distance between the two elements.
      W a a a
    | -- | Represents the set of permutations with the preserved both distances between and order of the three elements.
      H a a a a
    | -- | Represents the set of permutations with the preserved pairwise distances between the first and second, second and third elements.
      R a a a a
    | -- | Represents the set of permutations with the preserved pairwise distances between the first and second, second and third elements, and additionally the order of the first and second elements.
      M a a a a
    | -- | Represents the set of permutations with the moved fixed positions of some elements (at least one).
      N a d
    | -- | Pepresents the set of permutations with the specified order and distance between the two elements.
      D a a a a
    | -- | Pepresents the set of permutations with the specified distance between the two elements.
      I a a a a
    | -- | Represents the set of permutations with the preserved order of the 5 elements
      U a a a a a a
    | -- | Represents the set of permutations with the groupped more than two elements together
      G a a a
    deriving (EncodedContraints a b d -> EncodedContraints a b d -> Bool
(EncodedContraints a b d -> EncodedContraints a b d -> Bool)
-> (EncodedContraints a b d -> EncodedContraints a b d -> Bool)
-> Eq (EncodedContraints a b d)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b d.
(Eq b, Eq d, Eq a) =>
EncodedContraints a b d -> EncodedContraints a b d -> Bool
$c== :: forall a b d.
(Eq b, Eq d, Eq a) =>
EncodedContraints a b d -> EncodedContraints a b d -> Bool
== :: EncodedContraints a b d -> EncodedContraints a b d -> Bool
$c/= :: forall a b d.
(Eq b, Eq d, Eq a) =>
EncodedContraints a b d -> EncodedContraints a b d -> Bool
/= :: EncodedContraints a b d -> EncodedContraints a b d -> Bool
Eq, Eq (EncodedContraints a b d)
Eq (EncodedContraints a b d) =>
(EncodedContraints a b d -> EncodedContraints a b d -> Ordering)
-> (EncodedContraints a b d -> EncodedContraints a b d -> Bool)
-> (EncodedContraints a b d -> EncodedContraints a b d -> Bool)
-> (EncodedContraints a b d -> EncodedContraints a b d -> Bool)
-> (EncodedContraints a b d -> EncodedContraints a b d -> Bool)
-> (EncodedContraints a b d
    -> EncodedContraints a b d -> EncodedContraints a b d)
-> (EncodedContraints a b d
    -> EncodedContraints a b d -> EncodedContraints a b d)
-> Ord (EncodedContraints a b d)
EncodedContraints a b d -> EncodedContraints a b d -> Bool
EncodedContraints a b d -> EncodedContraints a b d -> Ordering
EncodedContraints a b d
-> EncodedContraints a b d -> EncodedContraints a b d
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a b d. (Ord b, Ord d, Ord a) => Eq (EncodedContraints a b d)
forall a b d.
(Ord b, Ord d, Ord a) =>
EncodedContraints a b d -> EncodedContraints a b d -> Bool
forall a b d.
(Ord b, Ord d, Ord a) =>
EncodedContraints a b d -> EncodedContraints a b d -> Ordering
forall a b d.
(Ord b, Ord d, Ord a) =>
EncodedContraints a b d
-> EncodedContraints a b d -> EncodedContraints a b d
$ccompare :: forall a b d.
(Ord b, Ord d, Ord a) =>
EncodedContraints a b d -> EncodedContraints a b d -> Ordering
compare :: EncodedContraints a b d -> EncodedContraints a b d -> Ordering
$c< :: forall a b d.
(Ord b, Ord d, Ord a) =>
EncodedContraints a b d -> EncodedContraints a b d -> Bool
< :: EncodedContraints a b d -> EncodedContraints a b d -> Bool
$c<= :: forall a b d.
(Ord b, Ord d, Ord a) =>
EncodedContraints a b d -> EncodedContraints a b d -> Bool
<= :: EncodedContraints a b d -> EncodedContraints a b d -> Bool
$c> :: forall a b d.
(Ord b, Ord d, Ord a) =>
EncodedContraints a b d -> EncodedContraints a b d -> Bool
> :: EncodedContraints a b d -> EncodedContraints a b d -> Bool
$c>= :: forall a b d.
(Ord b, Ord d, Ord a) =>
EncodedContraints a b d -> EncodedContraints a b d -> Bool
>= :: EncodedContraints a b d -> EncodedContraints a b d -> Bool
$cmax :: forall a b d.
(Ord b, Ord d, Ord a) =>
EncodedContraints a b d
-> EncodedContraints a b d -> EncodedContraints a b d
max :: EncodedContraints a b d
-> EncodedContraints a b d -> EncodedContraints a b d
$cmin :: forall a b d.
(Ord b, Ord d, Ord a) =>
EncodedContraints a b d
-> EncodedContraints a b d -> EncodedContraints a b d
min :: EncodedContraints a b d
-> EncodedContraints a b d -> EncodedContraints a b d
Ord, Int -> EncodedContraints a b d -> ShowS
[EncodedContraints a b d] -> ShowS
EncodedContraints a b d -> String
(Int -> EncodedContraints a b d -> ShowS)
-> (EncodedContraints a b d -> String)
-> ([EncodedContraints a b d] -> ShowS)
-> Show (EncodedContraints a b d)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b d.
(Show b, Show d, Show a) =>
Int -> EncodedContraints a b d -> ShowS
forall a b d.
(Show b, Show d, Show a) =>
[EncodedContraints a b d] -> ShowS
forall a b d.
(Show b, Show d, Show a) =>
EncodedContraints a b d -> String
$cshowsPrec :: forall a b d.
(Show b, Show d, Show a) =>
Int -> EncodedContraints a b d -> ShowS
showsPrec :: Int -> EncodedContraints a b d -> ShowS
$cshow :: forall a b d.
(Show b, Show d, Show a) =>
EncodedContraints a b d -> String
show :: EncodedContraints a b d -> String
$cshowList :: forall a b d.
(Show b, Show d, Show a) =>
[EncodedContraints a b d] -> ShowS
showList :: [EncodedContraints a b d] -> ShowS
Show)

validOrdStr0 ::
    String ->
    -- | Number of seen so far \'(\' parentheses
    Int ->
    -- | Number of seen so far \')\' parentheses
    Int ->
    Bool
validOrdStr0 :: String -> Int -> Int -> Bool
validOrdStr0 (Char
'E' : String
ys) Int
n Int
m = String -> Int -> Int -> Bool
validOrdStr0 String
ys Int
n Int
m
validOrdStr0 (Char
' ' : Char
y : Char
t : String
ys) Int
n Int
m
    | Char
y Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
"ABDFGHIMNPQRTUVW" Bool -> Bool -> Bool
&& Char -> Bool
isDigit Char
t =
        String -> Int -> Int -> Bool
validOrdStr0 ((Char -> Bool) -> ShowS
forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
isDigit String
ys) Int
n Int
m
    | Char
y Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
"-(E" = String -> Int -> Int -> Bool
validOrdStr0 (Char
y Char -> ShowS
forall a. a -> [a] -> [a]
: Char
t Char -> ShowS
forall a. a -> [a] -> [a]
: String
ys) Int
n Int
m
    | Bool
otherwise = Bool
False
validOrdStr0 (Char
'(' : Char
y : Char
t : String
ys) Int
n Int
m
    | Char
y Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
"ABDFGHIMNPQRTUVW" Bool -> Bool -> Bool
&& Char -> Bool
isDigit Char
t =
        String -> Int -> Int -> Bool
validOrdStr0 ((Char -> Bool) -> ShowS
forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
isDigit String
ys) (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int
m
    | Char
y Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
"-(E" = String -> Int -> Int -> Bool
validOrdStr0 (Char
y Char -> ShowS
forall a. a -> [a] -> [a]
: Char
t Char -> ShowS
forall a. a -> [a] -> [a]
: String
ys) (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int
m
    | Bool
otherwise = Bool
False
validOrdStr0 (Char
')' : Char
y : Char
t : String
ys) Int
n Int
m
    | Char
y Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
"ABDFGHIMNPQRTUVW" Bool -> Bool -> Bool
&& Char -> Bool
isDigit Char
t =
        String -> Int -> Int -> Bool
validOrdStr0 ((Char -> Bool) -> ShowS
forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
isDigit String
ys) Int
n (Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
    | Char
y Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
"-()E" = String -> Int -> Int -> Bool
validOrdStr0 (Char
y Char -> ShowS
forall a. a -> [a] -> [a]
: Char
t Char -> ShowS
forall a. a -> [a] -> [a]
: String
ys) Int
n (Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
    | Bool
otherwise = Bool
False
validOrdStr0 (Char
'-' : Char
y : Char
t : String
ys) Int
n Int
m
    | Char
y Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
"ABDFGHIMNPQRTUVW" Bool -> Bool -> Bool
&& Char -> Bool
isDigit Char
t =
        String -> Int -> Int -> Bool
validOrdStr0 ((Char -> Bool) -> ShowS
forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
isDigit String
ys) Int
n Int
m
    | Char
y Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
"-)" Bool -> Bool -> Bool
|| Char -> Bool
isDigit Char
y = Bool
False
    | Bool
otherwise = String -> Int -> Int -> Bool
validOrdStr0 (Char
y Char -> ShowS
forall a. a -> [a] -> [a]
: Char
t Char -> ShowS
forall a. a -> [a] -> [a]
: String
ys) Int
n Int
m
validOrdStr0 (Char
x : Char
y : Char
t : String
ys) Int
n Int
m
    | Char
x Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
"ABDFGHIMNPQRTUVW" Bool -> Bool -> Bool
&& Char -> Bool
isDigit Char
y =
        String -> Int -> Int -> Bool
validOrdStr0 ((Char -> Bool) -> ShowS
forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
isDigit (Char
t Char -> ShowS
forall a. a -> [a] -> [a]
: String
ys)) Int
n Int
m
    | Char
x Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
"ABDFGHIMNPQRTUVW" = Bool
False
    | Bool
otherwise = String -> Int -> Int -> Bool
validOrdStr0 (Char
y Char -> ShowS
forall a. a -> [a] -> [a]
: Char
t Char -> ShowS
forall a. a -> [a] -> [a]
: String
ys) Int
n (Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
validOrdStr0 (Char
x : Char
')' : String
ys) Int
n Int
m
    | Char -> Bool
isDigit Char
x = String -> Int -> Int -> Bool
validOrdStr0 String
ys Int
n (Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
    | Char
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
')' = String -> Int -> Int -> Bool
validOrdStr0 String
ys Int
n (Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2)
    | Bool
otherwise = Bool
False
validOrdStr0 (Char
x : Char
y : String
_) Int
n Int
m
    | Char
x Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
"(ABDFGHIMNQRTUVW" = Bool
False
    | Char
y Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
" -(ABDFGHIMNPQRTUVW" = Bool
False
    | Char
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'P' Bool -> Bool -> Bool
&& Bool -> Bool
not (Char -> Bool
isDigit Char
y) = Bool
False
    | Char
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
')' Bool -> Bool -> Bool
&& Char
y Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'E' = Bool
False
    | Char
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'P' Bool -> Bool -> Bool
&& Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
m = Bool
True
    | Char
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
')' Bool -> Bool -> Bool
&& Char
y Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'E' = Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== (Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
    | (Char
x Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
"E -") Bool -> Bool -> Bool
&& Char
y Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'E' = Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
m
    | Bool
otherwise = Bool
False
validOrdStr0 (Char
x : String
_) Int
n Int
m
    | Char -> Bool
isDigit Char
x Bool -> Bool -> Bool
|| (Char
x Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
")E") = if Char
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
')' then Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== (Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) else Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
m
    | Bool
otherwise = Bool
False
validOrdStr0 String
_ Int
n Int
m = Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
m

{- | An extended predicate to check whether the 'String' is a probably correct representation of the
constraints algebraic expression for 'generalConversion' evaluation.
-}
validOrdStr :: String -> Bool
validOrdStr :: String -> Bool
validOrdStr String
xs = String -> Int -> Int -> Bool
validOrdStr0 String
xs Int
0 Int
0
{-# INLINE validOrdStr #-}

stage1Parsing :: String -> [String]
stage1Parsing :: String -> [String]
stage1Parsing =
    (Char -> Char -> Bool) -> String -> [String]
forall a. (a -> a -> Bool) -> [a] -> [[a]]
groupBy
        ( \Char
x Char
y -> Char
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'(' Bool -> Bool -> Bool
&& Char
y Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'(' Bool -> Bool -> Bool
|| Char -> Bool
isLetter Char
x Bool -> Bool -> Bool
&& Char -> Bool
isDigit Char
y Bool -> Bool -> Bool
|| Char
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
')' Bool -> Bool -> Bool
&& Char
y Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
')'
        )
{-# INLINE stage1Parsing #-}

-- | At the moment is used only for the list of 'String' without any parentheses in each of them.
convertToBools ::
    Int ->
    Array Int Int ->
    [String] ->
    -- | The result is a 'String' that Haskell can evaluate to 'Bool' (some logical expression).
    String
convertToBools :: Int -> Array Int Int -> [String] -> String
convertToBools Int
n Array Int Int
arr (String
"-" : [String]
yss) = String
"not " String -> ShowS
forall a. Monoid a => a -> a -> a
`mappend` (Int -> Array Int Int -> [String] -> String
convertToBools Int
n Array Int Int
arr [String]
yss)
convertToBools Int
n Array Int Int
arr (String
" " : [String]
yss) = String
" || " String -> ShowS
forall a. Monoid a => a -> a -> a
`mappend` (Int -> Array Int Int -> [String] -> String
convertToBools Int
n Array Int Int
arr [String]
yss)
convertToBools Int
n Array Int Int
arr (String
xs : yss :: [String]
yss@(String
ys : [String]
_))
    | String
xs String -> [String] -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` [String
"True", String
"False"] =
        String
xs
            String -> ShowS
forall a. Monoid a => a -> a -> a
`mappend` ( case String
ys of
                            String
" " -> String
" "
                            String
_ -> String
" && "
                      )
            String -> ShowS
forall a. Monoid a => a -> a -> a
`mappend` Int -> Array Int Int -> [String] -> String
convertToBools Int
n Array Int Int
arr [String]
yss
    | Bool
otherwise =
        let cnstrs :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
cnstrs = EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Maybe
     (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a. a -> Maybe a -> a
fromMaybe EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. EncodedContraints a b d
E (Maybe
   (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
 -> EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
-> (String
    -> Maybe
         (EncodedContraints Int (Array Int Int) (Array Int (Int, Int))))
-> String
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> String
-> Maybe
     (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
readMaybeECG Int
n (String
 -> EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
-> String
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b. (a -> b) -> a -> b
$ String
xs
         in Bool -> String
forall a. Show a => a -> String
show (Bool
-> Array Int Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isConstraint1 Bool
True Array Int Int
arr EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
cnstrs)
                String -> ShowS
forall a. Monoid a => a -> a -> a
`mappend` ( case String
ys of
                                String
" " -> String
" "
                                String
_ -> String
" && "
                          )
                String -> ShowS
forall a. Monoid a => a -> a -> a
`mappend` Int -> Array Int Int -> [String] -> String
convertToBools Int
n Array Int Int
arr [String]
yss
convertToBools Int
n Array Int Int
arr (String
xs : [String]
_)
    | String
xs String -> [String] -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` [String
"True", String
"False"] = String
xs
    | Bool
otherwise =
        (Bool -> String
forall a. Show a => a -> String
show (Bool -> String) -> (String -> Bool) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool
-> Array Int Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isConstraint1 Bool
True Array Int Int
arr (EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
 -> Bool)
-> (String
    -> EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
-> String
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Maybe
     (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a. a -> Maybe a -> a
fromMaybe EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. EncodedContraints a b d
E (Maybe
   (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
 -> EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
-> (String
    -> Maybe
         (EncodedContraints Int (Array Int Int) (Array Int (Int, Int))))
-> String
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> String
-> Maybe
     (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
readMaybeECG Int
n ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String
xs)
convertToBools Int
_ Array Int Int
_ [String]
_ = []

splitNoParenAtDisjunction :: [String] -> [[String]]
splitNoParenAtDisjunction :: [String] -> [[String]]
splitNoParenAtDisjunction xss :: [String]
xss@(String
_ : [String]
_)
    | [String] -> Bool
forall a. [a] -> Bool
null [String]
tss = []
    | Bool
otherwise = [String]
tss [String] -> [[String]] -> [[String]]
forall a. a -> [a] -> [a]
: [String] -> [[String]]
splitNoParenAtDisjunction [String]
wss
  where
    ([String]
tss, [String]
uss) = (String -> Bool) -> [String] -> ([String], [String])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"||") [String]
xss
    wss :: [String]
wss = Int -> [String] -> [String]
forall a. Int -> [a] -> [a]
drop Int
1 [String]
uss
splitNoParenAtDisjunction [String]
_ = []

noParenString0 :: [String] -> Bool
noParenString0 :: [String] -> Bool
noParenString0 (String
xs : String
ys : String
ts : [String]
yss)
    | String
xs String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"not" =
        case String
ys of
            String
"True" -> Bool
False
            String
_ -> [String] -> Bool
noParenString0 [String]
yss
    | Bool
otherwise =
        case String
xs of
            String
"True" -> [String] -> Bool
noParenString0 (String
ts String -> [String] -> [String]
forall a. a -> [a] -> [a]
: [String]
yss)
            String
_ -> Bool
False
noParenString0 (String
"not" : String
ys : [String]
_) = if String
ys String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"True" then Bool
False else Bool
True
noParenString0 (String
xs : [String]
_)
    | String
xs String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"True" = Bool
True
    | Bool
otherwise = Bool
False
noParenString0 [String]
_ = Bool
True

noParenString :: [String] -> Bool
noParenString :: [String] -> Bool
noParenString = [Bool] -> Bool
or ([Bool] -> Bool) -> ([String] -> [Bool]) -> [String] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([String] -> Bool) -> [[String]] -> [Bool]
forall a b. (a -> b) -> [a] -> [b]
map [String] -> Bool
noParenString0 ([[String]] -> [Bool])
-> ([String] -> [[String]]) -> [String] -> [Bool]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> [[String]]
splitNoParenAtDisjunction
{-# INLINE noParenString #-}

oneStep :: Int -> Array Int Int -> [String] -> Bool
oneStep :: Int -> Array Int Int -> [String] -> Bool
oneStep Int
m Array Int Int
arr = [String] -> Bool
noParenString ([String] -> Bool) -> ([String] -> [String]) -> [String] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [String]
words (String -> [String])
-> ([String] -> String) -> [String] -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Array Int Int -> [String] -> String
convertToBools Int
m Array Int Int
arr
{-# INLINE oneStep #-}

oneChange :: Int -> Array Int Int -> [String] -> [String]
oneChange :: Int -> Array Int Int -> [String] -> [String]
oneChange Int
m Array Int Int
arr [String]
xss
    | [String] -> Bool
forall a. [a] -> Bool
null [String]
wss = [Bool -> String
forall a. Show a => a -> String
show (Bool -> String) -> ([String] -> Bool) -> [String] -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Array Int Int -> [String] -> Bool
oneStep Int
m Array Int Int
arr ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ [String]
xss]
    | Bool
otherwise =
        ( (\([String]
jss, Integer
_, [String]
qss) -> [String]
jss [String] -> [String] -> [String]
forall a. Monoid a => a -> a -> a
`mappend` [Bool -> String
forall a. Show a => a -> String
show (Bool -> String) -> ([String] -> Bool) -> [String] -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Array Int Int -> [String] -> Bool
oneStep Int
m Array Int Int
arr ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ [String]
qss])
            (([String], Integer, [String]) -> [String])
-> ([String] -> ([String], Integer, [String]))
-> [String]
-> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String
 -> ([String], Integer, [String]) -> ([String], Integer, [String]))
-> ([String], Integer, [String])
-> [String]
-> ([String], Integer, [String])
forall a b. (a -> b -> b) -> b -> [a] -> b
foldr
                ( \String
xs ([String]
tss, Integer
n, [String]
rss) ->
                    if String
xs String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"(" Bool -> Bool -> Bool
&& Integer
n Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
0
                        then ([String]
tss, Integer
1, [String]
rss)
                        else
                            if (Char -> Bool) -> String -> Bool
forall a. (a -> Bool) -> [a] -> Bool
any (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'(') String
xs Bool -> Bool -> Bool
&& Integer
n Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
0
                                then (Int -> ShowS
forall a. Int -> [a] -> [a]
drop Int
1 String
xs String -> [String] -> [String]
forall a. a -> [a] -> [a]
: [String]
tss, Integer
1, [String]
rss)
                                else case Integer
n of
                                    Integer
0 -> ([String]
tss, Integer
0, String
xs String -> [String] -> [String]
forall a. a -> [a] -> [a]
: [String]
rss)
                                    Integer
_ -> (String
xs String -> [String] -> [String]
forall a. a -> [a] -> [a]
: [String]
tss, Integer
1, [String]
rss)
                )
                ([], Integer
0, [])
            ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$ [String]
yss
        )
            [String] -> [String] -> [String]
forall a. Monoid a => a -> a -> a
`mappend` [String]
kss
  where
    ([String]
yss, [String]
wss) = (String -> Bool) -> [String] -> ([String], [String])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break ((Char -> Bool) -> String -> Bool
forall a. (a -> Bool) -> [a] -> Bool
any (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
')')) [String]
xss
    kss :: [String]
kss = case [String]
wss of
        String
")" : [String]
vss -> [String]
vss
        String
ws : [String]
vss -> Int -> ShowS
forall a. Int -> [a] -> [a]
drop Int
1 String
ws String -> [String] -> [String]
forall a. a -> [a] -> [a]
: [String]
vss
        [String]
_ -> []

generalConversion :: Int -> String -> Array Int Int -> Bool
generalConversion :: Int -> String -> Array Int Int -> Bool
generalConversion Int
m String
xs Array Int Int
arr
    | String -> Bool
validOrdStr String
xs =
        (\String
ks -> if String
ks String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"True" Bool -> Bool -> Bool
|| String
ks String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"E" then Bool
True else Bool
False)
            (String -> Bool) -> ShowS -> String -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> String
forall a. HasCallStack => [a] -> a
head
            ([String] -> String) -> (String -> [String]) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[String]] -> [String]
forall a. HasCallStack => [a] -> a
head
            ([[String]] -> [String])
-> (String -> [[String]]) -> String -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([String] -> Bool) -> [[String]] -> [[String]]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile ((Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
1) (Int -> Bool) -> ([String] -> Int) -> [String] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> Int
forall a. [a] -> Int
length)
            ([[String]] -> [[String]])
-> (String -> [[String]]) -> String -> [[String]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [[String]] -> [[String]]
forall a. Int -> [a] -> [a]
drop Int
1
            ([[String]] -> [[String]])
-> (String -> [[String]]) -> String -> [[String]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([String] -> [String]) -> [String] -> [[String]]
forall a. (a -> a) -> a -> [a]
iterate (Int -> Array Int Int -> [String] -> [String]
oneChange Int
m Array Int Int
arr)
            ([String] -> [[String]])
-> (String -> [String]) -> String -> [[String]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [String]
stage1Parsing
            (String -> Bool) -> String -> Bool
forall a b. (a -> b) -> a -> b
$ String
xs
    | Bool
otherwise = Bool
False
{-# INLINE generalConversion #-}

-- | Can be thought of as 'filter' ('generalConversion' ... ) @<arrays>@ but is somewhat more efficient.
filterGeneralConv :: Int -> String -> [Array Int Int] -> [Array Int Int]
filterGeneralConv :: Int -> String -> [Array Int Int] -> [Array Int Int]
filterGeneralConv Int
m String
cnstrns [Array Int Int]
xs
    | String -> Bool
validOrdStr String
cnstrns =
        let !xss :: [String]
xss = String -> [String]
stage1Parsing String
cnstrns
         in (Array Int Int -> Bool) -> [Array Int Int] -> [Array Int Int]
forall a. (a -> Bool) -> [a] -> [a]
filter
                ( \Array Int Int
arr ->
                    (\String
ks -> if String
ks String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"True" Bool -> Bool -> Bool
|| String
ks String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"E" then Bool
True else Bool
False)
                        (String -> Bool) -> ([String] -> String) -> [String] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> String
forall a. HasCallStack => [a] -> a
head
                        ([String] -> String)
-> ([String] -> [String]) -> [String] -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[String]] -> [String]
forall a. HasCallStack => [a] -> a
head
                        ([[String]] -> [String])
-> ([String] -> [[String]]) -> [String] -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([String] -> Bool) -> [[String]] -> [[String]]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile ((Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
1) (Int -> Bool) -> ([String] -> Int) -> [String] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> Int
forall a. [a] -> Int
length)
                        ([[String]] -> [[String]])
-> ([String] -> [[String]]) -> [String] -> [[String]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [[String]] -> [[String]]
forall a. Int -> [a] -> [a]
drop Int
1
                        ([[String]] -> [[String]])
-> ([String] -> [[String]]) -> [String] -> [[String]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([String] -> [String]) -> [String] -> [[String]]
forall a. (a -> a) -> a -> [a]
iterate (Int -> Array Int Int -> [String] -> [String]
oneChange Int
m Array Int Int
arr) ([String] -> Bool) -> [String] -> Bool
forall a b. (a -> b) -> a -> b
$
                        [String]
xss
                )
                [Array Int Int]
xs
    | Bool
otherwise = []
{-# INLINE filterGeneralConv #-}

{- | Inspired by the: https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-Maybe.html
Is provided here as a more general way to read the 'String' into a 'EncodedCnstrs'.
It is up to user to check whether the parameters are in the correct form, the function does
not do the full checking.
-}
readMaybeECG :: Int -> String -> Maybe EncodedCnstrs
readMaybeECG :: Int
-> String
-> Maybe
     (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
readMaybeECG Int
n String
xs
    | String -> Bool
forall a. [a] -> Bool
null String
xs = Maybe
  (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
forall a. Maybe a
Nothing
    | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0 Bool -> Bool -> Bool
&& Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
9 =
        let h :: Char
h = String -> Char
forall a. HasCallStack => [a] -> a
head String
xs
            ts :: String
ts = (Char -> Bool) -> ShowS
forall a. (a -> Bool) -> [a] -> [a]
filter (\Char
x -> Char
x Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'0' Bool -> Bool -> Bool
&& [Char
x] String -> String -> Bool
forall a. Ord a => a -> a -> Bool
<= Int -> String
forall a. Show a => a -> String
show Int
n) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
forall a. HasCallStack => [a] -> [a]
tail ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String
xs
         in case Char
h of
                Char
'E' -> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Maybe
     (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
forall a. a -> Maybe a
Just EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. EncodedContraints a b d
E
                Char
_ -> Int
-> Char
-> String
-> Maybe
     (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
f Int
n Char
h String
ts
    | Bool
otherwise = Maybe
  (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
forall a. Maybe a
Nothing
  where
    f :: Int
-> Char
-> String
-> Maybe
     (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
f Int
n Char
c String
ts
        | Char
c Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
"DFGHIMQRQTUVW" =
            let ys0 :: [Int]
ys0 = [Maybe Int] -> [Int]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe Int] -> [Int])
-> (String -> [Maybe Int]) -> String -> [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Maybe Int) -> String -> [Maybe Int]
forall a b. (a -> b) -> [a] -> [b]
map (\Char
t -> String -> Maybe Int
forall a. Read a => String -> Maybe a
readMaybe [Char
t] :: Maybe Int) (String -> [Int]) -> String -> [Int]
forall a b. (a -> b) -> a -> b
$ String
ts
                ys :: [Int]
ys = [Int] -> [Int]
forall a. Eq a => [a] -> [a]
nub [Int]
ys0
                ([Int]
jjs, [Int]
ps) = Integer -> [Int] -> ([Int], [Int])
forall b (t :: * -> *) a.
(Integral b, InsertLeft t a, Monoid (t a)) =>
b -> t a -> (t a, t a)
splitAtEndG Integer
1 [Int]
ys0
                res :: Maybe (EncodedContraints Int b d)
res
                    | [Int] -> Int
forall a. [a] -> Int
length [Int]
ys0 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
3 Bool -> Bool -> Bool
&& (Char
c Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
"DI") =
                        let qs :: [Int]
qs = Int -> [Int] -> [Int]
forall a. Int -> [a] -> [a]
take Int
2 ([Int] -> [Int]) -> ([Int] -> [Int]) -> [Int] -> [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Int] -> [Int]
forall a. Eq a => [a] -> [a]
nub ([Int] -> [Int]) -> [Int] -> [Int]
forall a b. (a -> b) -> a -> b
$ [Int]
jjs
                            [Int
y, Int
z] = (Int -> Int) -> [Int] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (\Int
rr -> if Int
rr Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Int
9 else Int
rr Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) [Int]
qs
                         in if [Int] -> Int
forall a. [a] -> Int
length [Int]
qs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
2 Bool -> Bool -> Bool
|| [Int]
ps [Int] -> [Int] -> Bool
forall a. Eq a => a -> a -> Bool
== [Int
0] Bool -> Bool -> Bool
|| [Int]
ps [Int] -> [Int] -> Bool
forall a. Ord a => a -> a -> Bool
> [Int
n]
                                then Maybe (EncodedContraints Int b d)
forall a. Maybe a
Nothing
                                else EncodedContraints Int b d -> Maybe (EncodedContraints Int b d)
forall a. a -> Maybe a
Just ((if Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'D' then Int -> Int -> Int -> Int -> EncodedContraints Int b d
forall a b d. a -> a -> a -> a -> EncodedContraints a b d
D else Int -> Int -> Int -> Int -> EncodedContraints Int b d
forall a b d. a -> a -> a -> a -> EncodedContraints a b d
I) Int
n Int
y Int
z ([Int] -> Int
forall a. HasCallStack => [a] -> a
head [Int]
ps))
                    | [Int] -> Int
forall a. [a] -> Int
length [Int]
ys Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Char -> Int
forall {a}. Num a => Char -> a
g Char
c = Maybe (EncodedContraints Int b d)
forall a. Maybe a
Nothing
                   | Char
c Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
"FVW" =
                        let [Int
y, Int
z] = (Int -> Int) -> [Int] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (\Int
rr -> if Int
rr Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Int
9 else Int
rr Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) [Int]
ys
                         in EncodedContraints Int b d -> Maybe (EncodedContraints Int b d)
forall a. a -> Maybe a
Just ((case Char
c of Char
'F' -> Int -> Int -> Int -> EncodedContraints Int b d
forall a b d. a -> a -> a -> EncodedContraints a b d
F; Char
'V' -> Int -> Int -> Int -> EncodedContraints Int b d
forall a b d. a -> a -> a -> EncodedContraints a b d
V; Char
_ -> Int -> Int -> Int -> EncodedContraints Int b d
forall a b d. a -> a -> a -> EncodedContraints a b d
W) Int
n Int
y Int
z)
                    | Char
c Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
"HMT" =
                        let [Int
y, Int
z, Int
u] = (Int -> Int) -> [Int] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (\Int
rr -> if Int
rr Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Int
9 else Int
rr Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) [Int]
ys
                         in EncodedContraints Int b d -> Maybe (EncodedContraints Int b d)
forall a. a -> Maybe a
Just ((case Char
c of Char
'T' -> Int -> Int -> Int -> Int -> EncodedContraints Int b d
forall a b d. a -> a -> a -> a -> EncodedContraints a b d
T; Char
'H' -> Int -> Int -> Int -> Int -> EncodedContraints Int b d
forall a b d. a -> a -> a -> a -> EncodedContraints a b d
H; Char
'M' -> Int -> Int -> Int -> Int -> EncodedContraints Int b d
forall a b d. a -> a -> a -> a -> EncodedContraints a b d
M; Char
_ -> Int -> Int -> Int -> Int -> EncodedContraints Int b d
forall a b d. a -> a -> a -> a -> EncodedContraints a b d
R) Int
n Int
y Int
z Int
u)
                    | Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'G' =
                        let [Int
y0, Int
z0] = (Int -> Int) -> [Int] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (\Int
rr -> if Int
rr Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Int
9 else Int
rr Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) [Int]
ys
                            (Int
y, Int
z) 
                                 | Int
y0 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
z0 = (Int
y0, Int
z0)
                                 | Bool
otherwise = (Int
z0, Int
y0) 
                         in EncodedContraints Int b d -> Maybe (EncodedContraints Int b d)
forall a. a -> Maybe a
Just (Int -> Int -> Int -> EncodedContraints Int b d
forall a b d. a -> a -> a -> EncodedContraints a b d
G Int
n Int
y Int
z)
                    | Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'Q' =
                        let [Int
y, Int
z, Int
u, Int
w] = (Int -> Int) -> [Int] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (\Int
rr -> if Int
rr Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Int
9 else Int
rr Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) [Int]
ys
                         in EncodedContraints Int b d -> Maybe (EncodedContraints Int b d)
forall a. a -> Maybe a
Just (Int -> Int -> Int -> Int -> Int -> EncodedContraints Int b d
forall a b d. a -> a -> a -> a -> a -> EncodedContraints a b d
Q Int
n Int
y Int
z Int
u Int
w)
                    | Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'U' =
                        let [Int
y, Int
z, Int
t, Int
u, Int
w] = (Int -> Int) -> [Int] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (\Int
rr -> if Int
rr Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Int
9 else Int
rr Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) [Int]
ys
                         in EncodedContraints Int b d -> Maybe (EncodedContraints Int b d)
forall a. a -> Maybe a
Just (Int -> Int -> Int -> Int -> Int -> Int -> EncodedContraints Int b d
forall a b d. a -> a -> a -> a -> a -> a -> EncodedContraints a b d
U Int
n Int
y Int
z Int
t Int
u Int
w)
                    | Bool
otherwise = Maybe (EncodedContraints Int b d)
forall a. Maybe a
Nothing
             in Maybe
  (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
forall {b} {d}. Maybe (EncodedContraints Int b d)
res
        | Char
c Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
"AB" =
            let y :: Maybe Int
y = String -> Maybe Int
forall a. Read a => String -> Maybe a
readMaybe (Int -> ShowS
forall a. Int -> [a] -> [a]
take Int
1 String
ts) :: Maybe Int
             in if Maybe Int -> Bool
forall a. Maybe a -> Bool
isJust Maybe Int
y
                    then
                        let y0 :: Int
y0 = Maybe Int -> Int
forall a. HasCallStack => Maybe a -> a
fromJust Maybe Int
y
                            zs :: [Int]
zs =
                                (Int -> Int) -> [Int] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (\Int
rr -> if Int
rr Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Int
9 else Int
rr Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
                                    ([Int] -> [Int]) -> (String -> [Int]) -> String -> [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Bool) -> [Int] -> [Int]
forall a. (a -> Bool) -> [a] -> [a]
filter (Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
y0)
                                    ([Int] -> [Int]) -> (String -> [Int]) -> String -> [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Int] -> [Int]
forall a. Eq a => [a] -> [a]
nub
                                    ([Int] -> [Int]) -> (String -> [Int]) -> String -> [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe Int] -> [Int]
forall a. [Maybe a] -> [a]
catMaybes
                                    ([Maybe Int] -> [Int])
-> (String -> [Maybe Int]) -> String -> [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Maybe Int) -> String -> [Maybe Int]
forall a b. (a -> b) -> [a] -> [b]
map (\Char
t -> String -> Maybe Int
forall a. Read a => String -> Maybe a
readMaybe [Char
t] :: Maybe Int)
                                    (String -> [Maybe Int]) -> ShowS -> String -> [Maybe Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
forall a. Int -> [a] -> [a]
drop Int
1 (String -> [Int]) -> String -> [Int]
forall a b. (a -> b) -> a -> b
$
                                    String
ts
                         in case [Int]
zs of
                                [] -> Maybe
  (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
forall a. Maybe a
Nothing
                                ~[Int]
x2 ->
                                    EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Maybe
     (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
forall a. a -> Maybe a
Just
                                        ( (if Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'A' then Int
-> Int
-> Array Int Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> a -> b -> EncodedContraints a b d
SA else Int
-> Int
-> Array Int Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> a -> b -> EncodedContraints a b d
SB)
                                            Int
n
                                            (if Int
y0 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Int
9 else Int
y0 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
                                            ((Int, Int) -> [Int] -> Array Int Int
forall i e. Ix i => (i, i) -> [e] -> Array i e
listArray (Int
0, [Int] -> Int
forall a. [a] -> Int
length [Int]
x2 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) [Int]
x2)
                                        )
                    else Maybe
  (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
forall a. Maybe a
Nothing
        | Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'P' =
            if String -> Bool
forall a. [a] -> Bool
null String
ts
                then EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Maybe
     (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
forall a. a -> Maybe a
Just EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. EncodedContraints a b d
E
                else
                    EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Maybe
     (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
forall a. a -> Maybe a
Just
                        (EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
 -> Maybe
      (EncodedContraints Int (Array Int Int) (Array Int (Int, Int))))
-> (String
    -> EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
-> String
-> Maybe
     (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> Array Int Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> b -> EncodedContraints a b d
P Int
n
                        (Array Int Int
 -> EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
-> (String -> Array Int Int)
-> String
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, Int) -> [Int] -> Array Int Int
forall i e. Ix i => (i, i) -> [e] -> Array i e
listArray (Int
0, String -> Int
forall a. [a] -> Int
length String
ts Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
                        ([Int] -> Array Int Int)
-> (String -> [Int]) -> String -> Array Int Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Int) -> String -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (\Char
r -> case (Maybe Int -> Int
forall a. HasCallStack => Maybe a -> a
fromJust (String -> Maybe Int
forall a. Read a => String -> Maybe a
readMaybe [Char
r] :: Maybe Int)) of Int
0 -> Int
9; Int
q -> Int
q Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (String
 -> Maybe
      (EncodedContraints Int (Array Int Int) (Array Int (Int, Int))))
-> String
-> Maybe
     (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
forall a b. (a -> b) -> a -> b
$
                        String
ts
        | Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'N' =
            if Int
tl Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
                then EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Maybe
     (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
forall a. a -> Maybe a
Just EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. EncodedContraints a b d
E
                else
                    EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Maybe
     (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
forall a. a -> Maybe a
Just
                        (EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
 -> Maybe
      (EncodedContraints Int (Array Int Int) (Array Int (Int, Int))))
-> ([String]
    -> EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
-> [String]
-> Maybe
     (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> Array Int (Int, Int)
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> d -> EncodedContraints a b d
N Int
n
                        (Array Int (Int, Int)
 -> EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
-> ([String] -> Array Int (Int, Int))
-> [String]
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, Int) -> [(Int, Int)] -> Array Int (Int, Int)
forall i e. Ix i => (i, i) -> [e] -> Array i e
listArray (Int
0, Int
tl Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
                        ([(Int, Int)] -> Array Int (Int, Int))
-> ([String] -> [(Int, Int)]) -> [String] -> Array Int (Int, Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> (Int, Int)) -> [String] -> [(Int, Int)]
forall a b. (a -> b) -> [a] -> [b]
map
                            ( (\[Int
s, Int
w] -> (Int
w, Int
s))
                                ([Int] -> (Int, Int)) -> (String -> [Int]) -> String -> (Int, Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Int) -> String -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (\Char
r -> case (Maybe Int -> Int
forall a. HasCallStack => Maybe a -> a
fromJust (String -> Maybe Int
forall a. Read a => String -> Maybe a
readMaybe [Char
r] :: Maybe Int)) of Int
0 -> Int
9; Int
q -> Int
q Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
                            ) ([String]
 -> Maybe
      (EncodedContraints Int (Array Int Int) (Array Int (Int, Int))))
-> [String]
-> Maybe
     (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
forall a b. (a -> b) -> a -> b
$
                        [String]
h3
        | Bool
otherwise = Maybe
  (EncodedContraints Int (Array Int Int) (Array Int (Int, Int)))
forall a. Maybe a
Nothing
      where
        h1 :: [a] -> [[a]]
h1 (a
b : a
d : [a]
ds) = [a
b, a
d] [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: [a] -> [[a]]
h1 [a]
ds
        h1 [a]
_ = []
        h2 :: [String]
h2 = String -> [String]
forall {a}. [a] -> [[a]]
h1 String
ts
        qqs :: String
qqs = (String -> Char) -> [String] -> String
forall a b. (a -> b) -> [a] -> [b]
map String -> Char
forall a. HasCallStack => [a] -> a
head [String]
h2
        pps :: String
pps = (String -> Char) -> [String] -> String
forall a b. (a -> b) -> [a] -> [b]
map String -> Char
forall a. HasCallStack => [a] -> a
last [String]
h2
        h3 :: [String]
h3
            | String -> Int
forall a. [a] -> Int
length (ShowS
forall a. Eq a => [a] -> [a]
nub String
qqs) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== String -> Int
forall a. [a] -> Int
length String
qqs Bool -> Bool -> Bool
&& String -> Int
forall a. [a] -> Int
length (ShowS
forall a. Eq a => [a] -> [a]
nub String
pps) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== String -> Int
forall a. [a] -> Int
length String
pps = [String]
h2
            | Bool
otherwise = []
        tl :: Int
tl = [String] -> Int
forall a. [a] -> Int
length [String]
h3
    g :: Char -> a
g Char
c
        | Char
c Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
`elem` String
"FGVW" = a
2
        | Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'Q' = a
4
        | Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'U' = a
5
        | Bool
otherwise = a
3

type EncodedCnstrs =
    EncodedContraints Int (Array Int Int) (Array Int (Int, Int))

{- | Must be applied to the correct array of permutation indeces. Otherwise, it gives runtime error (exception). All the integers inside the
'EncodedCnstrs' must be in the range [0..n-1] where @n@ corresponds to the maximum element in the permutation 'Array' 'Int' 'Int'.
-}
decodeConstraint1 ::
    (InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
    EncodedCnstrs ->
    t (Array Int Int) ->
    t (Array Int Int)
decodeConstraint1 :: forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> t (Array Int Int) -> t (Array Int Int)
decodeConstraint1 EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
E = t (Array Int Int) -> t (Array Int Int)
forall a. a -> a
id
decodeConstraint1 (P Int
_ Array Int Int
v) = Array Int Int -> t (Array Int Int) -> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
Array Int Int -> t (Array Int Int) -> t (Array Int Int)
fixedPointsS Array Int Int
v
decodeConstraint1 (Q Int
_ Int
i Int
j Int
k Int
l) = Int -> Int -> Int -> Int -> t (Array Int Int) -> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
Int -> Int -> Int -> Int -> t (Array Int Int) -> t (Array Int Int)
unsafeQuadruples Int
i Int
j Int
k Int
l
decodeConstraint1 (T Int
_ Int
i Int
j Int
k) = Int -> Int -> Int -> t (Array Int Int) -> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
Int -> Int -> Int -> t (Array Int Int) -> t (Array Int Int)
unsafeTriples Int
i Int
j Int
k
decodeConstraint1 (SA Int
_ Int
i Array Int Int
v) = Int -> Array Int Int -> t (Array Int Int) -> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
Int -> Array Int Int -> t (Array Int Int) -> t (Array Int Int)
unsafeSeveralA Int
i Array Int Int
v
decodeConstraint1 (SB Int
_ Int
i Array Int Int
v) = Int -> Array Int Int -> t (Array Int Int) -> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
Int -> Array Int Int -> t (Array Int Int) -> t (Array Int Int)
unsafeSeveralB Int
i Array Int Int
v
decodeConstraint1 (F Int
_ Int
i Int
j) = Int -> Int -> t (Array Int Int) -> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
Int -> Int -> t (Array Int Int) -> t (Array Int Int)
filterOrderIJ Int
i Int
j
decodeConstraint1 (V Int
_ Int
i Int
j) = Int -> Int -> Int -> t (Array Int Int) -> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
Int -> Int -> Int -> t (Array Int Int) -> t (Array Int Int)
filterSignDistanceIJ Int
i Int
j (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i)
decodeConstraint1 (W Int
_ Int
i Int
j) = Int -> Int -> Int -> t (Array Int Int) -> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
Int -> Int -> Int -> t (Array Int Int) -> t (Array Int Int)
filterUnsignDistanceIJ Int
i Int
j (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i)
decodeConstraint1 (H Int
_ Int
i Int
j Int
k) = Int
-> Int
-> Int
-> Int
-> Int
-> t (Array Int Int)
-> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
Int
-> Int
-> Int
-> Int
-> Int
-> t (Array Int Int)
-> t (Array Int Int)
filterSignDistanceIJK3 Int
i Int
j Int
k (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i) (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
j)
decodeConstraint1 (R Int
_ Int
i Int
j Int
k) = Int
-> Int
-> Int
-> Int
-> Int
-> t (Array Int Int)
-> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
Int
-> Int
-> Int
-> Int
-> Int
-> t (Array Int Int)
-> t (Array Int Int)
filterUnsignDistanceIJK3 Int
i Int
j Int
k (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i) (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
j)
decodeConstraint1 (M Int
_ Int
i Int
j Int
k) = Int
-> Int
-> Int
-> Int
-> Int
-> t (Array Int Int)
-> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
Int
-> Int
-> Int
-> Int
-> Int
-> t (Array Int Int)
-> t (Array Int Int)
filterMixedDistanceIJK3 Int
i Int
j Int
k (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i) (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
j)
decodeConstraint1 (N Int
_ Array Int (Int, Int)
v) = Array Int (Int, Int) -> t (Array Int Int) -> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
Array Int (Int, Int) -> t (Array Int Int) -> t (Array Int Int)
fixedPointsG Array Int (Int, Int)
v
decodeConstraint1 (D Int
_ Int
i Int
j Int
d) = Int -> Int -> Int -> t (Array Int Int) -> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
Int -> Int -> Int -> t (Array Int Int) -> t (Array Int Int)
filterSignDistanceIJ Int
i Int
j (Int -> Int
forall a. Num a => a -> a
abs Int
d)
decodeConstraint1 (I Int
_ Int
i Int
j Int
d) = Int -> Int -> Int -> t (Array Int Int) -> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
Int -> Int -> Int -> t (Array Int Int) -> t (Array Int Int)
filterUnsignDistanceIJ Int
i Int
j (Int -> Int
forall a. Num a => a -> a
abs Int
d)
decodeConstraint1 (U Int
_ Int
i Int
j Int
k Int
l Int
m) = Int
-> Int
-> Int
-> Int
-> Int
-> t (Array Int Int)
-> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
Int
-> Int
-> Int
-> Int
-> Int
-> t (Array Int Int)
-> t (Array Int Int)
unsafeQuintuples Int
i Int
j Int
k Int
l Int
m
decodeConstraint1 (G Int
_ Int
i Int
j) = Int -> Int -> t (Array Int Int) -> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
Int -> Int -> t (Array Int Int) -> t (Array Int Int)
filterGrouppedTogether Int
i Int
j
{-# SPECIALIZE decodeConstraint1 ::
    EncodedCnstrs -> [Array Int Int] -> [Array Int Int]
    #-}

{- | Must be applied to the correct array of permutation indeces. Otherwise, it gives runtime error (exception). All the integers inside the
'EncodedCnstrs' must be in the range [0..n-1] where @n@ corresponds to the maximum element in the permutation 'Array' 'Int' 'Int'.
-}
decodeLConstraints ::
    (InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
    [EncodedCnstrs] ->
    t (Array Int Int) ->
    t (Array Int Int)
decodeLConstraints :: forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
[EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
-> t (Array Int Int) -> t (Array Int Int)
decodeLConstraints (EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
x : [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
xs) = [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
-> t (Array Int Int) -> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
[EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
-> t (Array Int Int) -> t (Array Int Int)
decodeLConstraints' [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
ys (t (Array Int Int) -> t (Array Int Int))
-> (t (Array Int Int) -> t (Array Int Int))
-> t (Array Int Int)
-> t (Array Int Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> t (Array Int Int) -> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> t (Array Int Int) -> t (Array Int Int)
decodeConstraint1 EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
y
  where
    y :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
y = [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a. (Ord a, HasCallStack) => [a] -> a
minimum (EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
x EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
-> [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
forall a. a -> [a] -> [a]
: [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
xs)
    ys :: [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
ys = (EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
 -> Bool)
-> [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
-> [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
forall a. (a -> Bool) -> [a] -> [a]
filter (EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
forall a. Eq a => a -> a -> Bool
/= EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
y) ([EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
 -> [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))])
-> ([EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
    -> [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))])
-> [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
-> [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
-> [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
forall {a} {b} {d}.
[EncodedContraints a b d] -> [EncodedContraints a b d]
g ([EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
 -> [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))])
-> [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
-> [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
forall a b. (a -> b) -> a -> b
$ (EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
x EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
-> [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
forall a. a -> [a] -> [a]
: [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
xs)
    g :: [EncodedContraints a b d] -> [EncodedContraints a b d]
g (EncodedContraints a b d
E : [EncodedContraints a b d]
zs) = [EncodedContraints a b d] -> [EncodedContraints a b d]
g [EncodedContraints a b d]
zs
    g (EncodedContraints a b d
z : [EncodedContraints a b d]
zs) = EncodedContraints a b d
z EncodedContraints a b d
-> [EncodedContraints a b d] -> [EncodedContraints a b d]
forall a. a -> [a] -> [a]
: [EncodedContraints a b d] -> [EncodedContraints a b d]
g [EncodedContraints a b d]
zs
    g [EncodedContraints a b d]
_ = []
    decodeLConstraints' :: [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
-> t (Array Int Int) -> t (Array Int Int)
decodeLConstraints' (EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
z : [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
zs) = [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
-> t (Array Int Int) -> t (Array Int Int)
decodeLConstraints' [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
zs (t (Array Int Int) -> t (Array Int Int))
-> (t (Array Int Int) -> t (Array Int Int))
-> t (Array Int Int)
-> t (Array Int Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> t (Array Int Int) -> t (Array Int Int)
forall (t :: * -> *).
(InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) =>
EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> t (Array Int Int) -> t (Array Int Int)
decodeConstraint1 EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
z
    decodeLConstraints' [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
_ = t (Array Int Int) -> t (Array Int Int)
forall a. a -> a
id
decodeLConstraints [EncodedContraints Int (Array Int Int) (Array Int (Int, Int))]
_ = t (Array Int Int) -> t (Array Int Int)
forall a. a -> a
id
{-# SPECIALIZE decodeLConstraints ::
    [EncodedCnstrs] -> [Array Int Int] -> [Array Int Int]
    #-}

isConstraint1 :: Bool -> Array Int Int -> EncodedCnstrs -> Bool
isConstraint1 :: Bool
-> Array Int Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isConstraint1 Bool
bool Array Int Int
_ EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
E = Bool
bool
isConstraint1 Bool
True Array Int Int
arr (F Int
_ Int
i Int
j) = Int -> Int -> Array Int Int -> Bool
unsafeOrderIJ Int
i Int
j Array Int Int
arr
isConstraint1 Bool
True Array Int Int
arr (T Int
_ Int
i Int
j Int
k) = Int -> Int -> Int -> Array Int Int -> Bool
isTripleOrdered Int
i Int
j Int
k Array Int Int
arr
isConstraint1 Bool
True Array Int Int
arr (Q Int
_ Int
i Int
j Int
k Int
l) = Int -> Int -> Int -> Int -> Array Int Int -> Bool
isQuadrupleOrdered Int
i Int
j Int
k Int
l Array Int Int
arr
isConstraint1 Bool
True Array Int Int
arr (SA Int
_ Int
i Array Int Int
arr2) = Int -> Array Int Int -> Array Int Int -> Bool
isSeveralAOrdered Int
i Array Int Int
arr2 Array Int Int
arr
isConstraint1 Bool
True Array Int Int
arr (SB Int
_ Int
i Array Int Int
arr2) = Int -> Array Int Int -> Array Int Int -> Bool
isSeveralBOrdered Int
i Array Int Int
arr2 Array Int Int
arr
isConstraint1 Bool
True Array Int Int
arr (P Int
_ Array Int Int
arr2) = Array Int Int -> Array Int Int -> Bool
isFixedPoint Array Int Int
arr2 Array Int Int
arr
isConstraint1 Bool
True Array Int Int
arr (H Int
_ Int
i Int
j Int
k) = Int -> Int -> Int -> Int -> Int -> Array Int Int -> Bool
isSignDistIJK3 Int
i Int
j Int
k (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i) (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
j) Array Int Int
arr
isConstraint1 Bool
True Array Int Int
arr (M Int
_ Int
i Int
j Int
k) = Int -> Int -> Int -> Int -> Int -> Array Int Int -> Bool
isMixedDistIJK3 Int
i Int
j Int
k (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i) (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
j) Array Int Int
arr
isConstraint1 Bool
True Array Int Int
arr (R Int
_ Int
i Int
j Int
k) = Int -> Int -> Int -> Int -> Int -> Array Int Int -> Bool
isUnsignDistIJK3 Int
i Int
j Int
k (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i) (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
j) Array Int Int
arr
isConstraint1 Bool
True Array Int Int
arr (V Int
_ Int
i Int
j) = Int -> Int -> Int -> Array Int Int -> Bool
unsafeSignDistanceIJ Int
i Int
j (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i) Array Int Int
arr
isConstraint1 Bool
True Array Int Int
arr (W Int
_ Int
i Int
j) = Int -> Int -> Int -> Array Int Int -> Bool
unsafeUnsignDistanceIJ Int
i Int
j (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i) Array Int Int
arr
isConstraint1 Bool
True Array Int Int
arr (N Int
_ Array Int (Int, Int)
arr2) = Array Int (Int, Int) -> Array Int Int -> Bool
isFixedPointTup Array Int (Int, Int)
arr2 Array Int Int
arr
isConstraint1 Bool
True Array Int Int
arr (D Int
_ Int
i Int
j Int
d) = Int -> Int -> Int -> Array Int Int -> Bool
unsafeSignDistanceIJ Int
i Int
j (Int -> Int
forall a. Num a => a -> a
abs Int
d) Array Int Int
arr
isConstraint1 Bool
True Array Int Int
arr (I Int
_ Int
i Int
j Int
d) = Int -> Int -> Int -> Array Int Int -> Bool
unsafeUnsignDistanceIJ Int
i Int
j (Int -> Int
forall a. Num a => a -> a
abs Int
d) Array Int Int
arr
isConstraint1 Bool
True Array Int Int
arr (U Int
_ Int
i Int
j Int
k Int
l Int
m) = Int -> Int -> Int -> Int -> Int -> Array Int Int -> Bool
isQuintupleOrdered Int
i Int
j Int
k Int
l Int
m Array Int Int
arr
isConstraint1 Bool
True Array Int Int
arr (G Int
_ Int
i Int
j) = Int -> Int -> Array Int Int -> Bool
isGrouppedTogether Int
i Int
j Array Int Int
arr
isConstraint1 Bool
False Array Int Int
arr (F Int
_ Int
i Int
j) = Int -> Int -> Array Int Int -> Bool
unsafeOrderIJ Int
j Int
i Array Int Int
arr
isConstraint1 Bool
False Array Int Int
arr (T Int
_ Int
i Int
j Int
k) = Int -> Int -> Int -> Array Int Int -> Bool
notTripleOrdered Int
i Int
j Int
k Array Int Int
arr
isConstraint1 Bool
False Array Int Int
arr (Q Int
_ Int
i Int
j Int
k Int
l) = Int -> Int -> Int -> Int -> Array Int Int -> Bool
notQuadrupleOrdered Int
i Int
j Int
k Int
l Array Int Int
arr
isConstraint1 Bool
False Array Int Int
arr (SA Int
_ Int
i Array Int Int
arr2) = Int -> Array Int Int -> Array Int Int -> Bool
notSeveralAOrdered Int
i Array Int Int
arr2 Array Int Int
arr
isConstraint1 Bool
False Array Int Int
arr (SB Int
_ Int
i Array Int Int
arr2) = Int -> Array Int Int -> Array Int Int -> Bool
notSeveralBOrdered Int
i Array Int Int
arr2 Array Int Int
arr
isConstraint1 Bool
False Array Int Int
arr (P Int
_ Array Int Int
arr2) = Array Int Int -> Array Int Int -> Bool
notFixedPoint Array Int Int
arr2 Array Int Int
arr
isConstraint1 Bool
False Array Int Int
arr (H Int
_ Int
i Int
j Int
k) = Int -> Int -> Int -> Int -> Int -> Array Int Int -> Bool
notSignDistIJK3 Int
i Int
j Int
k (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i) (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
j) Array Int Int
arr
isConstraint1 Bool
False Array Int Int
arr (M Int
_ Int
i Int
j Int
k) = Int -> Int -> Int -> Int -> Int -> Array Int Int -> Bool
notMixedDistIJK3 Int
i Int
j Int
k (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i) (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
j) Array Int Int
arr
isConstraint1 Bool
False Array Int Int
arr (R Int
_ Int
i Int
j Int
k) = Int -> Int -> Int -> Int -> Int -> Array Int Int -> Bool
notUnsignDistIJK3 Int
i Int
j Int
k (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i) (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
j) Array Int Int
arr
isConstraint1 Bool
False Array Int Int
arr (V Int
_ Int
i Int
j) = Int -> Int -> Int -> Array Int Int -> Bool
unsafeSignDistanceIJ Int
j Int
i (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i) Array Int Int
arr
isConstraint1 Bool
False Array Int Int
arr (W Int
_ Int
i Int
j) = Bool -> Bool
not (Bool -> Bool) -> (Array Int Int -> Bool) -> Array Int Int -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Int -> Array Int Int -> Bool
unsafeUnsignDistanceIJ Int
i Int
j (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i) (Array Int Int -> Bool) -> Array Int Int -> Bool
forall a b. (a -> b) -> a -> b
$ Array Int Int
arr
isConstraint1 Bool
False Array Int Int
arr (N Int
_ Array Int (Int, Int)
arr2) = Array Int (Int, Int) -> Array Int Int -> Bool
notFixedPointTup Array Int (Int, Int)
arr2 Array Int Int
arr
isConstraint1 Bool
False Array Int Int
arr (D Int
_ Int
i Int
j Int
d) = Int -> Int -> Int -> Array Int Int -> Bool
unsafeSignDistanceIJ Int
j Int
i (Int -> Int
forall a. Num a => a -> a
abs Int
d) Array Int Int
arr
isConstraint1 Bool
False Array Int Int
arr (I Int
_ Int
i Int
j Int
d) = Bool -> Bool
not (Bool -> Bool) -> (Array Int Int -> Bool) -> Array Int Int -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Int -> Array Int Int -> Bool
unsafeUnsignDistanceIJ Int
i Int
j (Int -> Int
forall a. Num a => a -> a
abs Int
d) (Array Int Int -> Bool) -> Array Int Int -> Bool
forall a b. (a -> b) -> a -> b
$ Array Int Int
arr
isConstraint1 Bool
False Array Int Int
arr (U Int
_ Int
i Int
j Int
k Int
l Int
m) = Int -> Int -> Int -> Int -> Int -> Array Int Int -> Bool
notQuintupleOrdered Int
i Int
j Int
k Int
l Int
m Array Int Int
arr
isConstraint1 Bool
False Array Int Int
arr (G Int
_ Int
i Int
j) = Int -> Int -> Array Int Int -> Bool
notGrouppedTogether Int
i Int
j Array Int Int
arr

isE :: EncodedCnstrs -> Bool
isE :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isE EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
E = Bool
True
isE EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
_ = Bool
False

isP :: EncodedCnstrs -> Bool
isP :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isP (P Int
_ Array Int Int
_) = Bool
True
isP EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
_ = Bool
False

isF :: EncodedCnstrs -> Bool
isF :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isF (F Int
_ Int
_ Int
_) = Bool
True
isF EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
_ = Bool
False

isT :: EncodedCnstrs -> Bool
isT :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isT (T Int
_ Int
_ Int
_ Int
_) = Bool
True
isT EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
_ = Bool
False

isQ :: EncodedCnstrs -> Bool
isQ :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isQ (Q Int
_ Int
_ Int
_ Int
_ Int
_) = Bool
True
isQ EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
_ = Bool
False

isSA :: EncodedCnstrs -> Bool
isSA :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isSA (SA Int
_ Int
_ Array Int Int
_) = Bool
True
isSA EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
_ = Bool
False

isSB :: EncodedCnstrs -> Bool
isSB :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isSB (SB Int
_ Int
_ Array Int Int
_) = Bool
True
isSB EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
_ = Bool
False

isV :: EncodedCnstrs -> Bool
isV :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isV (V Int
_ Int
_ Int
_) = Bool
True
isV EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
_ = Bool
False

isW :: EncodedCnstrs -> Bool
isW :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isW (W Int
_ Int
_ Int
_) = Bool
True
isW EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
_ = Bool
False

isH :: EncodedCnstrs -> Bool
isH :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isH (H Int
_ Int
_ Int
_ Int
_) = Bool
True
isH EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
_ = Bool
False

isR :: EncodedCnstrs -> Bool
isR :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isR (R Int
_ Int
_ Int
_ Int
_) = Bool
True
isR EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
_ = Bool
False

isM :: EncodedCnstrs -> Bool
isM :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isM (M Int
_ Int
_ Int
_ Int
_) = Bool
True
isM EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
_ = Bool
False

isN :: EncodedCnstrs -> Bool
isN :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isN (N Int
_ Array Int (Int, Int)
_) = Bool
True
isN EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
_ = Bool
False

isD :: EncodedCnstrs -> Bool
isD :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isD (D Int
_ Int
_ Int
_ Int
_) = Bool
True
isD EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
_ = Bool
False

isI :: EncodedCnstrs -> Bool
isI :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isI (I Int
_ Int
_ Int
_ Int
_) = Bool
True
isI EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
_ = Bool
False

isU :: EncodedCnstrs -> Bool
isU :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isU (U Int
_ Int
_ Int
_ Int
_ Int
_ Int
_) = Bool
True
isU EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
_ = Bool
False

isG :: EncodedCnstrs -> Bool
isG :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> Bool
isG (G Int
_ Int
_ Int
_) = Bool
True
isG EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
_ = Bool
False

-- | Works only with the correctly defined argument though it is not checked. Use with this caution.
getIEl :: EncodedCnstrs -> Int
getIEl :: EncodedContraints Int (Array Int Int) (Array Int (Int, Int)) -> Int
getIEl EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
E = -Int
1
getIEl (P Int
_ Array Int Int
arr) = Array Int Int -> Int -> Int
forall i e. Array i e -> Int -> e
unsafeAt Array Int Int
arr Int
0
getIEl (Q Int
_ Int
i Int
_ Int
_ Int
_) = Int
i
getIEl (T Int
_ Int
i Int
_ Int
_) = Int
i
getIEl (SA Int
_ Int
i Array Int Int
_) = Int
i
getIEl (SB Int
_ Int
i Array Int Int
_) = Int
i
getIEl (F Int
_ Int
i Int
_) = Int
i
getIEl (V Int
_ Int
i Int
_) = Int
i
getIEl (W Int
_ Int
i Int
_) = Int
i
getIEl (H Int
_ Int
i Int
_ Int
_) = Int
i
getIEl (R Int
_ Int
i Int
_ Int
_) = Int
i
getIEl (M Int
_ Int
i Int
_ Int
_) = Int
i
getIEl (N Int
_ Array Int (Int, Int)
arr) = (Int, Int) -> Int
forall a b. (a, b) -> a
fst ((Int, Int) -> Int) -> (Int -> (Int, Int)) -> Int -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array Int (Int, Int) -> Int -> (Int, Int)
forall i e. Array i e -> Int -> e
unsafeAt Array Int (Int, Int)
arr (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
0
getIEl (D Int
_ Int
i Int
_ Int
_) = Int
i
getIEl (I Int
_ Int
i Int
_ Int
_) = Int
i
getIEl (U Int
_ Int
i Int
_ Int
_ Int
_ Int
_) = Int
i
getIEl (G Int
_ Int
i Int
_) = Int
i

-- | Works only with the correctly defined arguments though it is not checked. Use with this caution.
setIEl :: Int -> EncodedCnstrs -> EncodedCnstrs
setIEl :: Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
setIEl Int
_ EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
E = EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. EncodedContraints a b d
E
setIEl Int
i (P Int
n Array Int Int
arr) = Int
-> Array Int Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> b -> EncodedContraints a b d
P Int
n (Array Int Int
arr Array Int Int -> [(Int, Int)] -> Array Int Int
forall i e. Ix i => Array i e -> [(i, e)] -> Array i e
// [(Int
0, Int
i)])
setIEl Int
i (Q Int
n Int
_ Int
j Int
k Int
l) = Int
-> Int
-> Int
-> Int
-> Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> a -> a -> a -> a -> EncodedContraints a b d
Q Int
n Int
i Int
j Int
k Int
l
setIEl Int
i (T Int
n Int
_ Int
j Int
k) = Int
-> Int
-> Int
-> Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> a -> a -> a -> EncodedContraints a b d
T Int
n Int
i Int
j Int
k
setIEl Int
i (SA Int
n Int
_ Array Int Int
v) = Int
-> Int
-> Array Int Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> a -> b -> EncodedContraints a b d
SA Int
n Int
i Array Int Int
v
setIEl Int
i (SB Int
n Int
_ Array Int Int
v) = Int
-> Int
-> Array Int Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> a -> b -> EncodedContraints a b d
SB Int
n Int
i Array Int Int
v
setIEl Int
i (F Int
n Int
_ Int
j) = Int
-> Int
-> Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> a -> a -> EncodedContraints a b d
F Int
n Int
i Int
j
setIEl Int
i (V Int
n Int
_ Int
j) = Int
-> Int
-> Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> a -> a -> EncodedContraints a b d
V Int
n Int
i Int
j
setIEl Int
i (W Int
n Int
_ Int
j) = Int
-> Int
-> Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> a -> a -> EncodedContraints a b d
W Int
n Int
i Int
j
setIEl Int
i (H Int
n Int
_ Int
j Int
k) = Int
-> Int
-> Int
-> Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> a -> a -> a -> EncodedContraints a b d
H Int
n Int
i Int
j Int
k
setIEl Int
i (R Int
n Int
_ Int
j Int
k) = Int
-> Int
-> Int
-> Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> a -> a -> a -> EncodedContraints a b d
R Int
n Int
i Int
j Int
k
setIEl Int
i (M Int
n Int
_ Int
j Int
k) = Int
-> Int
-> Int
-> Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> a -> a -> a -> EncodedContraints a b d
M Int
n Int
i Int
j Int
k
setIEl Int
_ (N Int
n Array Int (Int, Int)
arr) = Int
-> Array Int (Int, Int)
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> d -> EncodedContraints a b d
N Int
n Array Int (Int, Int)
arr
setIEl Int
i (D Int
n Int
_ Int
j Int
k) = Int
-> Int
-> Int
-> Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> a -> a -> a -> EncodedContraints a b d
D Int
n Int
i Int
j Int
k
setIEl Int
i (I Int
n Int
_ Int
j Int
k) = Int
-> Int
-> Int
-> Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> a -> a -> a -> EncodedContraints a b d
I Int
n Int
i Int
j Int
k
setIEl Int
i (U Int
n Int
_ Int
j Int
k Int
l Int
m) = Int
-> Int
-> Int
-> Int
-> Int
-> Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> a -> a -> a -> a -> a -> EncodedContraints a b d
U Int
n Int
i Int
j Int
k Int
l Int
m
setIEl Int
i (G Int
n Int
_ Int
j) = Int
-> Int
-> Int
-> EncodedContraints Int (Array Int Int) (Array Int (Int, Int))
forall a b d. a -> a -> a -> EncodedContraints a b d
G Int
n Int
i Int
j