Skip to content

Instantly share code, notes, and snippets.

@Alexander-Schiendorfer
Created September 29, 2015 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alexander-Schiendorfer/d0c395b59404ccbc414c to your computer and use it in GitHub Desktop.
Save Alexander-Schiendorfer/d0c395b59404ccbc414c to your computer and use it in GitHub Desktop.
% 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