Created
September 29, 2015 12:56
-
-
Save Alexander-Schiendorfer/d0c395b59404ccbc414c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% try to define mydiv as integer division with partiality | |
function var int:mydiv(var int: x, var int: y) = | |
assert(lb(x) >= 0 /\ lb(y) >= 0, | |
"Mydiv got wrong arguments", | |
let {constraint y != 0 } in | |
safediv(x, y) | |
); | |
function var int: safediv(var int: x, var int: y) :: promise_total = | |
let { | |
var 0..ub(x): q; | |
var 0..ub(y)-1: r; | |
constraint q*y + r = x; | |
constraint r < y; | |
} in q; | |
var int: x; | |
var int: y; | |
var int: z; | |
constraint x = 7; | |
constraint y = 1; | |
constraint z = mydiv(x,y); | |
% should return z = 7 | |
solve satisfy; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment