Skip to content

Commit

Permalink
rules(minion): add modulo
Browse files Browse the repository at this point in the history
Add modulo expressions, parsing, and conversion rules to Minion.

The undefinedness semantics for modulo are similar to those for
division: it requires a bubble rule, asserting that for x % y, y!=0, to
make it safe.

Due to their similarity, the test cases for modulo in this patch are
based on the division ones.

See also: conjure-cp#454 (implementation of division rules)

Closes: conjure-cp#456
  • Loading branch information
niklasdewally committed Nov 16, 2024
1 parent 0ca861f commit 7579a40
Show file tree
Hide file tree
Showing 56 changed files with 5,324 additions and 31 deletions.
3 changes: 3 additions & 0 deletions conjure_oxide/tests/generated_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ fn assert_vector_operators_have_partially_evaluated(model: &conjure_core::Model)
WatchedLiteral(_, _, _) => (),
Reify(_, _, _) => (),
AuxDeclaration(_, _, _) => (),
UnsafeMod(_, _, _) => (),
SafeMod(_, _, _) => (),
ModEq(_, _, _, _) => (),
};
x.clone()
}));
Expand Down
2 changes: 2 additions & 0 deletions conjure_oxide/tests/integration/basic/mod/01/input.essence
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
find a,b : int(0..3)
such that a % b = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"a": 1,
"b": 2
},
{
"a": 1,
"b": 3
},
{
"a": 3,
"b": 2
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"constraints": {
"Eq": [
{
"clean": false,
"etype": null
},
{
"UnsafeMod": [
{
"clean": false,
"etype": null
},
{
"Atomic": [
{
"clean": false,
"etype": null
},
{
"Reference": {
"UserName": "a"
}
}
]
},
{
"Atomic": [
{
"clean": false,
"etype": null
},
{
"Reference": {
"UserName": "b"
}
}
]
}
]
},
{
"Atomic": [
{
"clean": false,
"etype": null
},
{
"Literal": {
"Int": 1
}
}
]
}
]
},
"next_var": 0,
"variables": [
[
{
"UserName": "a"
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
0,
3
]
}
]
}
}
],
[
{
"UserName": "b"
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
0,
3
]
}
]
}
}
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"constraints": {
"And": [
{
"clean": false,
"etype": null
},
[
{
"ModEq": [
{
"clean": false,
"etype": null
},
{
"Reference": {
"UserName": "a"
}
},
{
"Reference": {
"UserName": "b"
}
},
{
"Literal": {
"Int": 1
}
}
]
},
{
"Neq": [
{
"clean": false,
"etype": null
},
{
"Atomic": [
{
"clean": false,
"etype": null
},
{
"Reference": {
"UserName": "b"
}
}
]
},
{
"Atomic": [
{
"clean": false,
"etype": null
},
{
"Literal": {
"Int": 0
}
}
]
}
]
}
]
]
},
"next_var": 0,
"variables": [
[
{
"UserName": "a"
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
0,
3
]
}
]
}
}
],
[
{
"UserName": "b"
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
0,
3
]
}
]
}
}
]
]
}
2 changes: 2 additions & 0 deletions conjure_oxide/tests/integration/basic/mod/02/input.essence
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
find a : int(0..3)
such that a >= 4 % 2 $ should be simplified to constant
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"a": 0
},
{
"a": 1
},
{
"a": 2
},
{
"a": 3
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"constraints": {
"Geq": [
{
"clean": false,
"etype": null
},
{
"Atomic": [
{
"clean": false,
"etype": null
},
{
"Reference": {
"UserName": "a"
}
}
]
},
{
"UnsafeMod": [
{
"clean": false,
"etype": null
},
{
"Atomic": [
{
"clean": false,
"etype": null
},
{
"Literal": {
"Int": 4
}
}
]
},
{
"Atomic": [
{
"clean": false,
"etype": null
},
{
"Literal": {
"Int": 2
}
}
]
}
]
}
]
},
"next_var": 0,
"variables": [
[
{
"UserName": "a"
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
0,
3
]
}
]
}
}
]
]
}
Loading

0 comments on commit 7579a40

Please sign in to comment.