2014-01-05 20:05:08 +00:00
|
|
|
|
import Nat
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-05 20:05:08 +00:00
|
|
|
|
variable Int : Type
|
|
|
|
|
alias ℤ : Int
|
|
|
|
|
builtin nat_to_int : Nat → Int
|
|
|
|
|
coercion nat_to_int
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-05 20:05:08 +00:00
|
|
|
|
namespace Int
|
|
|
|
|
builtin numeral
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-05 20:05:08 +00:00
|
|
|
|
builtin add : Int → Int → Int
|
|
|
|
|
infixl 65 + : add
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-05 20:05:08 +00:00
|
|
|
|
builtin mul : Int → Int → Int
|
|
|
|
|
infixl 70 * : mul
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-05 20:05:08 +00:00
|
|
|
|
builtin div : Int → Int → Int
|
|
|
|
|
infixl 70 div : div
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-05 20:05:08 +00:00
|
|
|
|
builtin le : Int → Int → Bool
|
|
|
|
|
infix 50 <= : le
|
|
|
|
|
infix 50 ≤ : le
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-05 20:05:08 +00:00
|
|
|
|
definition ge (a b : Int) : Bool := b ≤ a
|
|
|
|
|
infix 50 >= : ge
|
|
|
|
|
infix 50 ≥ : ge
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-05 20:05:08 +00:00
|
|
|
|
definition lt (a b : Int) : Bool := ¬ (a ≥ b)
|
|
|
|
|
infix 50 < : lt
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-05 20:05:08 +00:00
|
|
|
|
definition gt (a b : Int) : Bool := ¬ (a ≤ b)
|
|
|
|
|
infix 50 > : gt
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-05 20:05:08 +00:00
|
|
|
|
definition sub (a b : Int) : Int := a + -1 * b
|
|
|
|
|
infixl 65 - : sub
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-05 20:05:08 +00:00
|
|
|
|
definition neg (a : Int) : Int := -1 * a
|
|
|
|
|
notation 75 - _ : neg
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-05 20:05:08 +00:00
|
|
|
|
definition mod (a b : Int) : Int := a - b * (a div b)
|
|
|
|
|
infixl 70 mod : mod
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-05 20:05:08 +00:00
|
|
|
|
definition divides (a b : Int) : Bool := (b mod a) = 0
|
|
|
|
|
infix 50 | : divides
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-09 22:06:23 +00:00
|
|
|
|
definition abs (a : Int) : Int := if (0 ≤ a) then a else (- a)
|
2014-01-05 20:05:08 +00:00
|
|
|
|
notation 55 | _ | : abs
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-09 16:33:52 +00:00
|
|
|
|
set_opaque sub true
|
|
|
|
|
set_opaque neg true
|
|
|
|
|
set_opaque mod true
|
|
|
|
|
set_opaque divides true
|
|
|
|
|
set_opaque abs true
|
|
|
|
|
set_opaque ge true
|
|
|
|
|
set_opaque lt true
|
|
|
|
|
set_opaque gt true
|
2014-01-05 20:05:08 +00:00
|
|
|
|
end
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-05 20:05:08 +00:00
|
|
|
|
namespace Nat
|
|
|
|
|
definition sub (a b : Nat) : Int := nat_to_int a - nat_to_int b
|
|
|
|
|
infixl 65 - : sub
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-05 20:05:08 +00:00
|
|
|
|
definition neg (a : Nat) : Int := - (nat_to_int a)
|
|
|
|
|
notation 75 - _ : neg
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-09 16:33:52 +00:00
|
|
|
|
set_opaque sub true
|
|
|
|
|
set_opaque neg true
|
2014-01-05 20:05:08 +00:00
|
|
|
|
end
|