mirror of
https://github.com/GaloisInc/cryptol.git
synced 2024-11-24 06:52:44 +03:00
25 lines
583 B
Plaintext
25 lines
583 B
Plaintext
type Q = (Integer, Integer)
|
|
|
|
toQ : Integer -> Integer -> Q
|
|
toQ a b =
|
|
if b == 0 then error "divide by 0" else
|
|
if b < 0 then (negate a, negate b) else (a, b)
|
|
|
|
leQ : Q -> Q -> Bit
|
|
leQ (a,b) (c,d) = a*d <= b*c
|
|
|
|
intToQ : Integer -> Q
|
|
intToQ x = (x, 1)
|
|
|
|
abs : Integer -> Integer
|
|
abs x = if x < 0 then negate x else x
|
|
|
|
property divRoundsDown (x : Integer) (y : Integer) =
|
|
y == 0 \/ leQ (intToQ ( x / y )) (toQ x y)
|
|
|
|
property divEuclidean (x : Integer) (y : Integer) =
|
|
y == 0 \/ y * (x / y) + x % y == x
|
|
|
|
property modAbs (x : Integer) (y : Integer) =
|
|
y == 0 \/ abs (x % y) < abs y
|