]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/tests/fguidi.ma
lapply improved
[helm.git] / helm / matita / tests / fguidi.ma
1 alias id "O" = "cic:/Coq/Init/Datatypes/nat.ind#xpointer(1/1/1)".
2 alias id "nat" = "cic:/Coq/Init/Datatypes/nat.ind#xpointer(1/1)".
3 alias id "S" = "cic:/Coq/Init/Datatypes/nat.ind#xpointer(1/1/2)".
4 alias id "le" = "cic:/matita/fguidi/le.ind#xpointer(1/1)".
5 alias id "False_ind" = "cic:/Coq/Init/Logic/False_ind.con".
6 alias id "I" = "cic:/Coq/Init/Logic/True.ind#xpointer(1/1/1)". 
7 alias id "ex_intro" = "cic:/Coq/Init/Logic/ex.ind#xpointer(1/1/1)".
8
9 alias symbol "and" (instance 0) = "logical and".
10 alias symbol "eq" (instance 0) = "leibnitz's equality".
11 alias symbol "exists" (instance 0) = "exists".
12 alias id "False" = "cic:/Coq/Init/Logic/False.ind#xpointer(1/1)".
13 alias id "True" = "cic:/Coq/Init/Logic/True.ind#xpointer(1/1)".
14
15 definition is_S: nat \to Prop \def
16    \lambda n. match n with 
17       [ O     \Rightarrow False
18       | (S n) \Rightarrow True
19       ].
20
21 definition pred: nat \to nat \def
22    \lambda n. match n with
23       [ O     \Rightarrow O
24       | (S n) \Rightarrow n
25       ]. 
26
27 theorem eq_gen_S_O: \forall x. (S x = O) \to \forall P:Prop. P.
28 intros. apply False_ind. cut (is_S O). auto. elim H. exact I.
29 qed.
30
31 theorem eq_gen_S_O_cc: (\forall P:Prop. P) \to \forall x. (S x = O).
32 intros. auto.
33 qed.
34
35 theorem eq_gen_S_S: \forall m,n. (S m) = (S n) \to m = n. 
36 intros. cut (pred (S m)) = (pred (S n)). 
37 assumption. elim H. auto.
38 qed.
39
40 theorem eq_gen_S_S_cc: \forall m,n. m = n \to (S m) = (S n).
41 intros. elim H. auto.
42 qed.
43
44 inductive le: nat \to nat \to Prop \def
45      le_zero: \forall n. (le O n)
46    | le_succ: \forall m, n. (le m n) \to (le (S m) (S n)).
47
48 theorem le_refl: \forall x. (le x x).
49 intros. elim x. auto. auto.
50 qed.
51
52 theorem le_gen_x_O_aux: \forall x, y. (le x y) \to (y =O) \to 
53                         (x = O).
54 intros 3. elim H. auto. apply eq_gen_S_O. exact x2. auto.
55 qed.
56
57 theorem le_gen_x_O: \forall x. (le x O) \to (x = O).
58 intros. apply le_gen_x_O_aux. exact O. auto. auto.
59 qed.
60
61 theorem le_gen_x_O_cc: \forall x. (x = O) \to (le x O).
62 intros. elim H. auto.
63 qed.
64
65 theorem le_gen_S_x_aux: \forall m,x,y. (le y x) \to (y = S m) \to 
66                         (\exists n. x = (S n) \land (le m n)).
67 intros 4. elim H. 
68 apply eq_gen_S_O. exact m. elim H1. auto. 
69 cut x1 = m. elim Hcut. apply ex_intro. exact x2. auto. auto.
70 qed.
71
72 theorem le_gen_S_x: \forall m,x. (le (S m) x) \to 
73                     (\exists n. x = (S n) \land (le m n)).
74 intros. apply le_gen_S_x_aux. exact (S m). auto. auto.
75 qed.
76
77 theorem le_gen_S_x_cc: \forall m,x. (\exists n. x = (S n) \land (le m n)) \to
78                        (le (S m) x).
79 intros. elim H. elim H1. cut (S x1) = x. elim Hcut. auto. elim H2. auto.
80 qed.
81
82 theorem le_gen_S_S: \forall m,n. (le (S m) (S n)) \to (le m n).
83 intros. cut (\exists p. (S n) = (S p) \land (le m p)).
84 elim Hcut. elim H1. cut x = n. 
85 elim Hcut1. auto. symmetry. auto. auto.
86 qed.
87
88 theorem le_gen_S_S_cc: \forall m,n. (le m n) \to (le (S m) (S n)).
89 intros. auto.
90 qed.
91
92 (* teorema di prova che non compila per via del let *)
93 theorem le_gen_S_x_2: \forall m,x. (le (S m) x) \to let k \def (S O) in
94                       (\exists n. x = (S n) \land (le m n) \land k = k).
95 intros.
96 lapply le_gen_S_x to H using H0. elim H0. elim H1.
97 exists. exact x1. auto.
98 qed.
99
100 (* proof of le_gen_S_S with lapply *)
101 theorem le_gen_S_S_2: \forall m,n. (le (S m) (S n)) \to (le m n).
102 intros.
103 lapply le_gen_S_x_2 to H using H0. elim H0. elim H1. 
104 lapply eq_gen_S_S to H2 using H4. rewrite left H4. assumption.
105 qed.