Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for issue #456 regression on <=lex #474

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions src/Conjure/UI/Model.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1938,14 +1938,7 @@ rule_DotLtLeq = "generic-DotLtLeq" `namedRule` theRule where
rule_Flatten_Lex :: Rule
rule_Flatten_Lex = "flatten-lex" `namedRule` theRule where
theRule [essence| &a <lex &b |] = do
ta <- typeOf a
tb <- typeOf b
case (ta, tb) of
(TypeList TypeInt{}, TypeList TypeInt{}) ->
na "rule_Flatten_Lex"
(TypeMatrix TypeInt{} TypeInt{}, TypeMatrix TypeInt{} TypeInt{}) ->
na "rule_Flatten_Lex"
_ -> return ()
reject_flat a b
fa <- flatten a
fb <- flatten b
tfa <- typeOf fa
Expand All @@ -1958,14 +1951,7 @@ rule_Flatten_Lex = "flatten-lex" `namedRule` theRule where
, return [essence| &fa <lex &fb |]
)
theRule [essence| &a <=lex &b |] = do
ta <- typeOf a
tb <- typeOf b
case (ta, tb) of
(TypeList TypeInt{}, TypeList TypeInt{}) ->
na "rule_Flatten_Lex"
(TypeMatrix TypeInt{} TypeInt{}, TypeMatrix TypeInt{} TypeInt{}) ->
na "rule_Flatten_Lex"
_ -> return ()
reject_flat a b
fa <- flatten a
fb <- flatten b
tfa <- typeOf fa
Expand All @@ -1978,6 +1964,24 @@ rule_Flatten_Lex = "flatten-lex" `namedRule` theRule where
, return [essence| &fa <=lex &fb |]
)
theRule _ = na "rule_Flatten_Lex"
reject_flat a b = do
ta <- typeOf a
tb <- typeOf b
case (ta, tb) of
(TypeMatrix TypeBool TypeInt{}, _) ->
na "rule_Flatten_Lex"
(TypeMatrix TypeBool TypeBool, _) ->
na "rule_Flatten_Lex"
(TypeList TypeInt{}, _) ->
na "rule_Flatten_Lex"
(TypeMatrix TypeInt{} TypeInt{}, _) ->
na "rule_Flatten_Lex"
(TypeList TypeBool, _) ->
na "rule_Flatten_Lex"
(TypeMatrix TypeInt{} TypeBool, _) ->
na "rule_Flatten_Lex"
_ -> return ()

flatten a = do
ta <- typeOf a
case ta of
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
find A : matrix indexed by [int(0..1)] of (bool,bool)
find B : matrix indexed by [int(0..1)] of (bool,bool)
such that A .< B
3 changes: 3 additions & 0 deletions tests/custom/flatten_lex/find_v_find/matrix_2_bools/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
conjure modelling *.essence
cat conjure-output/*.eprime
rm -r conjure-output
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
language ESSENCE' 1.0

find A_1: matrix indexed by [int(0..1)] of bool
find A_2: matrix indexed by [int(0..1)] of bool
find B_1: matrix indexed by [int(0..1)] of bool
find B_2: matrix indexed by [int(0..1)] of bool
branching on [A_1, A_2, B_1, B_2]
such that
flatten([flatten([[-toInt(A_1[q3]); int(1)], [-toInt(A_2[q3]); int(1)]; int(1..2)]) | q3 : int(0..1)]) <lex
flatten([flatten([[-toInt(B_1[q4]); int(1)], [-toInt(B_2[q4]); int(1)]; int(1..2)]) | q4 : int(0..1)])

$ Conjure's
$ {"finds": [{"Name": "A"}, {"Name": "B"}],
$ "givens": [],
$ "enumGivens": [],
$ "enumLettings": [],
$ "lettings": [],
$ "unnameds": [],
$ "strategyQ": {"PickFirst": []},
$ "strategyA": {"Auto": {"Interactive": []}},
$ "trailCompact":
$ [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]],
$ "trailVerbose": [],
$ "trailRewrites": [],
$ "nameGenState": [["q", 5]],
$ "nbExtraGivens": 0,
$ "representations":
$ [[{"Name": "A"},
$ {"DomainMatrix":
$ [{"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 0]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 1]}}]}]]},
$ {"DomainTuple": [{"DomainBool": []}, {"DomainBool": []}]}]}],
$ [{"Name": "B"},
$ {"DomainMatrix":
$ [{"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 0]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 1]}}]}]]},
$ {"DomainTuple": [{"DomainBool": []}, {"DomainBool": []}]}]}]],
$ "representationsTree":
$ [[{"Name": "A"},
$ [{"rootLabel": null,
$ "subForest":
$ [{"rootLabel": null,
$ "subForest":
$ [{"rootLabel": null,
$ "subForest": []},
$ {"rootLabel": null,
$ "subForest": []}]}]}]],
$ [{"Name": "B"},
$ [{"rootLabel": null,
$ "subForest":
$ [{"rootLabel": null,
$ "subForest":
$ [{"rootLabel": null,
$ "subForest": []},
$ {"rootLabel": null,
$ "subForest": []}]}]}]]],
$ "originalDomains":
$ [[{"Name": "A"},
$ {"DomainMatrix":
$ [{"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 0]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 1]}}]}]]},
$ {"DomainTuple": [{"DomainBool": []}, {"DomainBool": []}]}]}],
$ [{"Name": "B"},
$ {"DomainMatrix":
$ [{"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 0]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 1]}}]}]]},
$ {"DomainTuple": [{"DomainBool": []}, {"DomainBool": []}]}]}]]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
find A : matrix indexed by [int(0..1)] of (bool,int(5..7))
find B : matrix indexed by [int(0..1)] of (bool,int(2..7))
such that A .< B
3 changes: 3 additions & 0 deletions tests/custom/flatten_lex/find_v_find/matrix_2_mixed/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
conjure modelling *.essence
cat conjure-output/*.eprime
rm -r conjure-output
103 changes: 103 additions & 0 deletions tests/custom/flatten_lex/find_v_find/matrix_2_mixed/stdout.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
language ESSENCE' 1.0

find A_1: matrix indexed by [int(0..1)] of bool
find A_2: matrix indexed by [int(0..1)] of int(5..7)
find B_1: matrix indexed by [int(0..1)] of bool
find B_2: matrix indexed by [int(0..1)] of int(2..7)
branching on [A_1, A_2, B_1, B_2]
such that
flatten([flatten([[-toInt(A_1[q3]); int(1)], [A_2[q3]; int(1)]; int(1..2)]) | q3 : int(0..1)]) <lex
flatten([flatten([[-toInt(B_1[q4]); int(1)], [B_2[q4]; int(1)]; int(1..2)]) | q4 : int(0..1)])

$ Conjure's
$ {"finds": [{"Name": "A"}, {"Name": "B"}],
$ "givens": [],
$ "enumGivens": [],
$ "enumLettings": [],
$ "lettings": [],
$ "unnameds": [],
$ "strategyQ": {"PickFirst": []},
$ "strategyA": {"Auto": {"Interactive": []}},
$ "trailCompact":
$ [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]],
$ "trailVerbose": [],
$ "trailRewrites": [],
$ "nameGenState": [["q", 5]],
$ "nbExtraGivens": 0,
$ "representations":
$ [[{"Name": "A"},
$ {"DomainMatrix":
$ [{"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 0]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 1]}}]}]]},
$ {"DomainTuple":
$ [{"DomainBool": []},
$ {"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 5]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 7]}}]}]]}]}]}],
$ [{"Name": "B"},
$ {"DomainMatrix":
$ [{"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 0]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 1]}}]}]]},
$ {"DomainTuple":
$ [{"DomainBool": []},
$ {"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 2]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 7]}}]}]]}]}]}]],
$ "representationsTree":
$ [[{"Name": "A"},
$ [{"rootLabel": null,
$ "subForest":
$ [{"rootLabel": null,
$ "subForest":
$ [{"rootLabel": null,
$ "subForest": []},
$ {"rootLabel": null,
$ "subForest": []}]}]}]],
$ [{"Name": "B"},
$ [{"rootLabel": null,
$ "subForest":
$ [{"rootLabel": null,
$ "subForest":
$ [{"rootLabel": null,
$ "subForest": []},
$ {"rootLabel": null,
$ "subForest": []}]}]}]]],
$ "originalDomains":
$ [[{"Name": "A"},
$ {"DomainMatrix":
$ [{"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 0]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 1]}}]}]]},
$ {"DomainTuple":
$ [{"DomainBool": []},
$ {"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 5]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 7]}}]}]]}]}]}],
$ [{"Name": "B"},
$ {"DomainMatrix":
$ [{"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 0]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 1]}}]}]]},
$ {"DomainTuple":
$ [{"DomainBool": []},
$ {"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 2]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 7]}}]}]]}]}]}]]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
find A : matrix indexed by [int(0..1)] of matrix indexed by [int(0..2)] of (bool,int(5..7))
find B : matrix indexed by [int(0..1)] of matrix indexed by [int(0..2)] of (bool,int(5..7))
such that A .< B
3 changes: 3 additions & 0 deletions tests/custom/flatten_lex/find_v_find/matrix_of_matrix/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
conjure modelling *.essence
cat conjure-output/*.eprime
rm -r conjure-output
Loading