2014-08-25 02:58:48 +00:00
|
|
|
import logic
|
2014-07-04 17:10:05 +00:00
|
|
|
|
|
|
|
inductive nat : Type :=
|
2014-08-22 22:46:10 +00:00
|
|
|
zero : nat,
|
|
|
|
succ : nat → nat
|
2014-07-04 17:10:05 +00:00
|
|
|
|
2014-09-04 23:36:06 +00:00
|
|
|
namespace nat
|
2014-09-17 21:39:05 +00:00
|
|
|
definition add (a b : nat) : nat
|
2014-09-04 22:03:59 +00:00
|
|
|
:= nat.rec a (λ n r, succ r) b
|
2014-10-21 22:27:45 +00:00
|
|
|
infixl `+` := add
|
2014-07-04 17:10:05 +00:00
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
definition one := succ zero
|
2014-07-04 17:10:05 +00:00
|
|
|
|
|
|
|
-- Define coercion from num -> nat
|
|
|
|
-- By default the parser converts numerals into a binary representation num
|
2014-09-17 21:39:05 +00:00
|
|
|
definition pos_num_to_nat (n : pos_num) : nat
|
2014-09-04 22:03:59 +00:00
|
|
|
:= pos_num.rec one (λ n r, r + r) (λ n r, r + r + one) n
|
2014-09-17 21:39:05 +00:00
|
|
|
definition num_to_nat (n : num) : nat
|
2014-09-04 22:03:59 +00:00
|
|
|
:= num.rec zero (λ n, pos_num_to_nat n) n
|
2014-07-04 17:10:05 +00:00
|
|
|
coercion num_to_nat
|
|
|
|
|
|
|
|
-- Now we can write 2 + 3, the coercion will be applied
|
|
|
|
check 2 + 3
|
|
|
|
|
|
|
|
-- Define an assump as an alias for the eassumption tactic
|
2014-10-23 17:24:03 +00:00
|
|
|
definition assump : tactic := tactic.eassumption
|
2014-07-04 17:10:05 +00:00
|
|
|
|
2014-07-22 16:43:18 +00:00
|
|
|
theorem T1 {p : nat → Prop} {a : nat } (H : p (a+2)) : ∃ x, p (succ x)
|
2014-07-04 17:10:05 +00:00
|
|
|
:= by apply exists_intro; assump
|
2014-07-04 17:32:01 +00:00
|
|
|
|
2014-07-05 07:43:10 +00:00
|
|
|
definition is_zero (n : nat)
|
2014-09-04 22:03:59 +00:00
|
|
|
:= nat.rec true (λ n r, false) n
|
2014-07-04 17:32:01 +00:00
|
|
|
|
2014-07-05 22:52:40 +00:00
|
|
|
theorem T2 : ∃ a, (is_zero a) = true
|
2014-09-04 23:36:06 +00:00
|
|
|
:= by apply exists_intro; apply eq.refl
|
|
|
|
|
|
|
|
end nat
|