2014-11-30 21:16:01 -08:00
|
|
|
|
prelude
|
2014-08-24 19:58:48 -07:00
|
|
|
|
import logic
|
2014-11-22 17:34:05 -08:00
|
|
|
|
namespace experiment
|
2014-07-05 17:41:08 -07:00
|
|
|
|
inductive nat : Type :=
|
2014-08-22 15:46:10 -07:00
|
|
|
|
zero : nat,
|
|
|
|
|
succ : nat → nat
|
2014-07-05 17:41:08 -07:00
|
|
|
|
|
2014-09-04 18:41:06 -07:00
|
|
|
|
open eq
|
2014-09-04 16:36:06 -07:00
|
|
|
|
|
|
|
|
|
namespace nat
|
2014-07-05 17:41:08 -07:00
|
|
|
|
definition add (x y : nat)
|
2014-09-04 15:03:59 -07:00
|
|
|
|
:= nat.rec x (λ n r, succ r) y
|
2014-07-05 17:41:08 -07:00
|
|
|
|
|
2014-10-21 15:27:45 -07:00
|
|
|
|
infixl `+` := add
|
2014-07-05 17:41:08 -07:00
|
|
|
|
|
2014-12-23 17:34:16 -05:00
|
|
|
|
theorem add.left_id (x : nat) : x + zero = x
|
2014-07-05 17:41:08 -07:00
|
|
|
|
:= refl _
|
|
|
|
|
|
2014-12-23 17:34:16 -05:00
|
|
|
|
theorem succ_add (x y : nat) : x + (succ y) = succ (x + y)
|
2014-07-05 17:41:08 -07:00
|
|
|
|
:= refl _
|
|
|
|
|
|
|
|
|
|
definition is_zero (x : nat)
|
2014-09-04 15:03:59 -07:00
|
|
|
|
:= nat.rec true (λ n r, false) x
|
2014-07-05 17:41:08 -07:00
|
|
|
|
|
|
|
|
|
theorem is_zero_zero : is_zero zero
|
2014-12-12 13:50:53 -08:00
|
|
|
|
:= of_eq_true (refl _)
|
2014-07-05 17:41:08 -07:00
|
|
|
|
|
|
|
|
|
theorem not_is_zero_succ (x : nat) : ¬ is_zero (succ x)
|
2014-12-12 13:50:53 -08:00
|
|
|
|
:= not_of_eq_false (refl _)
|
2014-07-05 17:41:08 -07:00
|
|
|
|
|
|
|
|
|
theorem dichotomy (m : nat) : m = zero ∨ (∃ n, m = succ n)
|
2014-09-04 15:03:59 -07:00
|
|
|
|
:= nat.rec
|
2014-09-04 16:36:06 -07:00
|
|
|
|
(or.intro_left _ (refl zero))
|
2014-12-15 19:05:03 -08:00
|
|
|
|
(λ m H, or.intro_right _ (exists.intro m (refl (succ m))))
|
2014-07-05 17:41:08 -07:00
|
|
|
|
m
|
|
|
|
|
|
|
|
|
|
theorem is_zero_to_eq (x : nat) (H : is_zero x) : x = zero
|
2014-09-04 21:25:21 -07:00
|
|
|
|
:= or.elim (dichotomy x)
|
2014-07-05 17:41:08 -07:00
|
|
|
|
(assume Hz : x = zero, Hz)
|
|
|
|
|
(assume Hs : (∃ n, x = succ n),
|
2014-12-15 19:05:03 -08:00
|
|
|
|
exists.elim Hs (λ (w : nat) (Hw : x = succ w),
|
2014-09-04 18:41:06 -07:00
|
|
|
|
absurd H (eq.subst (symm Hw) (not_is_zero_succ w))))
|
2014-07-05 17:41:08 -07:00
|
|
|
|
|
|
|
|
|
theorem is_not_zero_to_eq {x : nat} (H : ¬ is_zero x) : ∃ n, x = succ n
|
2014-09-04 21:25:21 -07:00
|
|
|
|
:= or.elim (dichotomy x)
|
2014-07-05 17:41:08 -07:00
|
|
|
|
(assume Hz : x = zero,
|
2014-09-04 18:41:06 -07:00
|
|
|
|
absurd (eq.subst (symm Hz) is_zero_zero) H)
|
2014-07-05 17:41:08 -07:00
|
|
|
|
(assume Hs, Hs)
|
|
|
|
|
|
|
|
|
|
theorem not_zero_add (x y : nat) (H : ¬ is_zero y) : ¬ is_zero (x + y)
|
2014-12-15 19:05:03 -08:00
|
|
|
|
:= exists.elim (is_not_zero_to_eq H)
|
2014-07-05 17:41:08 -07:00
|
|
|
|
(λ (w : nat) (Hw : y = succ w),
|
|
|
|
|
have H1 : x + y = succ (x + w), from
|
|
|
|
|
calc x + y = x + succ w : {Hw}
|
|
|
|
|
... = succ (x + w) : refl _,
|
|
|
|
|
have H2 : ¬ is_zero (succ (x + w)), from
|
|
|
|
|
not_is_zero_succ (x+w),
|
|
|
|
|
subst (symm H1) H2)
|
|
|
|
|
|
2014-10-07 18:02:15 -07:00
|
|
|
|
inductive not_zero [class] (x : nat) : Prop :=
|
2014-09-04 16:36:06 -07:00
|
|
|
|
intro : ¬ is_zero x → not_zero x
|
2014-07-05 17:41:08 -07:00
|
|
|
|
|
|
|
|
|
theorem not_zero_not_is_zero {x : nat} (H : not_zero x) : ¬ is_zero x
|
2014-09-04 15:03:59 -07:00
|
|
|
|
:= not_zero.rec (λ H1, H1) H
|
2014-07-05 17:41:08 -07:00
|
|
|
|
|
|
|
|
|
theorem not_zero_add_right [instance] (x y : nat) (H : not_zero y) : not_zero (x + y)
|
2014-09-04 16:36:06 -07:00
|
|
|
|
:= not_zero.intro (not_zero_add x y (not_zero_not_is_zero H))
|
2014-07-05 17:41:08 -07:00
|
|
|
|
|
|
|
|
|
theorem not_zero_succ [instance] (x : nat) : not_zero (succ x)
|
2014-09-04 16:36:06 -07:00
|
|
|
|
:= not_zero.intro (not_is_zero_succ x)
|
2014-07-05 17:41:08 -07:00
|
|
|
|
|
2014-10-02 16:20:52 -07:00
|
|
|
|
constant dvd : Π (x y : nat) {H : not_zero y}, nat
|
2014-07-05 17:41:08 -07:00
|
|
|
|
|
2014-10-02 16:20:52 -07:00
|
|
|
|
constants a b : nat
|
2014-07-05 17:41:08 -07:00
|
|
|
|
|
2014-07-27 12:01:06 -07:00
|
|
|
|
set_option pp.implicit true
|
2015-01-24 20:23:21 -08:00
|
|
|
|
attribute add [reducible]
|
2014-08-22 16:36:47 -07:00
|
|
|
|
check dvd a (succ b)
|
|
|
|
|
check (λ H : not_zero b, dvd a b)
|
2014-07-05 17:41:08 -07:00
|
|
|
|
check (succ zero)
|
|
|
|
|
check a + (succ zero)
|
2014-08-22 16:36:47 -07:00
|
|
|
|
check dvd a (a + (succ b))
|
2014-07-05 17:41:08 -07:00
|
|
|
|
|
2015-01-24 20:23:21 -08:00
|
|
|
|
attribute add [irreducible]
|
2014-08-22 16:36:47 -07:00
|
|
|
|
check dvd a (a + (succ b))
|
2014-07-05 17:41:08 -07:00
|
|
|
|
|
2015-01-24 20:23:21 -08:00
|
|
|
|
attribute add [reducible]
|
2014-08-22 16:36:47 -07:00
|
|
|
|
check dvd a (a + (succ b))
|
2014-07-05 17:41:08 -07:00
|
|
|
|
|
2015-01-24 20:23:21 -08:00
|
|
|
|
attribute add [irreducible]
|
2014-08-22 16:36:47 -07:00
|
|
|
|
check dvd a (a + (succ b))
|
2014-09-04 16:36:06 -07:00
|
|
|
|
|
|
|
|
|
end nat
|
2014-11-22 17:34:05 -08:00
|
|
|
|
end experiment
|