lean2/src/builtin/Int.lean
Leonardo de Moura 2179e57db3 refactor(builtin): move if_then_else to its own module
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2014-01-09 14:08:39 -08:00

69 lines
No EOL
1.3 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Nat
import if_then_else
variable Int : Type
alias : Int
builtin nat_to_int : Nat → Int
coercion nat_to_int
namespace Int
builtin numeral
builtin add : Int → Int → Int
infixl 65 + : add
builtin mul : Int → Int → Int
infixl 70 * : mul
builtin div : Int → Int → Int
infixl 70 div : div
builtin le : Int → Int → Bool
infix 50 <= : le
infix 50 ≤ : le
definition ge (a b : Int) : Bool := b ≤ a
infix 50 >= : ge
infix 50 ≥ : ge
definition lt (a b : Int) : Bool := ¬ (a ≥ b)
infix 50 < : lt
definition gt (a b : Int) : Bool := ¬ (a ≤ b)
infix 50 > : gt
definition sub (a b : Int) : Int := a + -1 * b
infixl 65 - : sub
definition neg (a : Int) : Int := -1 * a
notation 75 - _ : neg
definition mod (a b : Int) : Int := a - b * (a div b)
infixl 70 mod : mod
definition divides (a b : Int) : Bool := (b mod a) = 0
infix 50 | : divides
definition abs (a : Int) : Int := if (0 ≤ a) then a else (- a)
notation 55 | _ | : abs
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
end
namespace Nat
definition sub (a b : Nat) : Int := nat_to_int a - nat_to_int b
infixl 65 - : sub
definition neg (a : Nat) : Int := - (nat_to_int a)
notation 75 - _ : neg
set_opaque sub true
set_opaque neg true
end