2014-01-01 21:52:25 +00:00
|
|
|
|
Import Nat.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
|
|
|
|
Variable Int : Type.
|
|
|
|
|
Alias ℤ : Int.
|
2014-01-01 20:40:54 +00:00
|
|
|
|
Builtin nat_to_int : Nat → Int.
|
|
|
|
|
Coercion nat_to_int.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
Namespace Int.
|
|
|
|
|
Builtin numeral.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
Builtin add : Int → Int → Int.
|
|
|
|
|
Infixl 65 + : add.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
Builtin mul : Int → Int → Int.
|
|
|
|
|
Infixl 70 * : mul.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
Builtin div : Int → Int → Int.
|
|
|
|
|
Infixl 70 div : div.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
Builtin le : Int → Int → Bool.
|
|
|
|
|
Infix 50 <= : le.
|
|
|
|
|
Infix 50 ≤ : le.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +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-01 20:40:54 +00:00
|
|
|
|
Definition lt (a b : Int) : Bool := ¬ (a ≥ b).
|
|
|
|
|
Infix 50 < : lt.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
Definition gt (a b : Int) : Bool := ¬ (a ≤ b).
|
|
|
|
|
Infix 50 > : gt.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
Definition sub (a b : Int) : Int := a + -1 * b.
|
|
|
|
|
Infixl 65 - : sub.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
Definition neg (a : Int) : Int := -1 * a.
|
|
|
|
|
Notation 75 - _ : neg.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +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-01 20:40:54 +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-01 20:40:54 +00:00
|
|
|
|
Definition abs (a : Int) : Int := if (0 ≤ a) a (- a).
|
|
|
|
|
Notation 55 | _ | : abs.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
SetOpaque sub true.
|
|
|
|
|
SetOpaque neg true.
|
|
|
|
|
SetOpaque mod true.
|
|
|
|
|
SetOpaque divides true.
|
|
|
|
|
SetOpaque abs true.
|
|
|
|
|
SetOpaque ge true.
|
|
|
|
|
SetOpaque lt true.
|
|
|
|
|
SetOpaque gt true.
|
|
|
|
|
EndNamespace.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +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-01 20:40:54 +00:00
|
|
|
|
Definition neg (a : Nat) : Int := - (nat_to_int a).
|
|
|
|
|
Notation 75 - _ : neg.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
SetOpaque sub true.
|
|
|
|
|
SetOpaque neg true.
|
|
|
|
|
EndNamespace.
|