]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/lib/lambda/background/preamble.ma
6a087e3aa8f470878f61ec1a86ccbdee9ef11088
[helm.git] / matita / matita / lib / lambda / background / preamble.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "basics/star1.ma".
16 include "basics/lists/lstar.ma".
17 include "arithmetics/exp.ma".
18
19 include "lambda/background/xoa_notation.ma".
20 include "lambda/background/xoa.ma".
21 include "lambda/background/notation.ma".
22
23 (* logic *)
24
25 (* Note: For some reason this cannot be in the standard library *) 
26 interpretation "logical false" 'false = False.
27
28 (* booleans *)
29
30 (* Note: For some reason this cannot be in the standard library *) 
31 interpretation "boolean false" 'false = false.
32
33 (* Note: For some reason this cannot be in the standard library *) 
34 interpretation "boolean true" 'true = true.
35
36 (* arithmetics *)
37
38 lemma lt_refl_false: ∀n. n < n → ⊥.
39 #n #H elim (lt_to_not_eq … H) -H /2 width=1/
40 qed-.
41
42 lemma lt_zero_false: ∀n. n < 0 → ⊥.
43 #n #H elim (lt_to_not_le … H) -H /2 width=1/
44 qed-.
45
46 lemma plus_lt_false: ∀m,n. m + n < m → ⊥.
47 #m #n #H elim (lt_to_not_le … H) -H /2 width=1/
48 qed-.
49
50 lemma lt_or_eq_or_gt: ∀m,n. ∨∨ m < n | n = m | n < m.
51 #m #n elim (lt_or_ge m n) /2 width=1/
52 #H elim H -m /2 width=1/
53 #m #Hm * #H /2 width=1/ /3 width=1/
54 qed-.
55
56 (* trichotomy operator *)
57
58 (* Note: this is "if eqb n1 n2 then a2 else if leb n1 n2 then a1 else a3" *)
59 let rec tri (A:Type[0]) n1 n2 a1 a2 a3 on n1 : A ≝
60   match n1 with 
61   [ O    ⇒ match n2 with [ O ⇒ a2 | S n2 ⇒ a1 ]
62   | S n1 ⇒ match n2 with [ O ⇒ a3 | S n2 ⇒ tri A n1 n2 a1 a2 a3 ]
63   ].
64
65 lemma tri_lt: ∀A,a1,a2,a3,n2,n1. n1 < n2 → tri A n1 n2 a1 a2 a3 = a1.
66 #A #a1 #a2 #a3 #n2 elim n2 -n2
67 [ #n1 #H elim (lt_zero_false … H)
68 | #n2 #IH #n1 elim n1 -n1 // /3 width=1/
69 ]
70 qed.
71
72 lemma tri_eq: ∀A,a1,a2,a3,n. tri A n n a1 a2 a3 = a2.
73 #A #a1 #a2 #a3 #n elim n -n normalize //
74 qed.
75
76 lemma tri_gt: ∀A,a1,a2,a3,n1,n2. n2 < n1 → tri A n1 n2 a1 a2 a3 = a3.
77 #A #a1 #a2 #a3 #n1 elim n1 -n1
78 [ #n2 #H elim (lt_zero_false … H)
79 | #n1 #IH #n2 elim n2 -n2 // /3 width=1/
80 ]
81 qed.
82
83 (* lists *)
84
85 (* Note: notation for nil not involving brackets *)
86 notation > "◊"
87   non associative with precedence 90
88   for @{'nil}.
89
90 lemma list_inv: ∀A. ∀l:list A. ◊ = l ∨ ∃∃a0,l0. a0 :: l0 = l.
91 #A * /2 width=1/ /3 width=3/
92 qed-.
93
94 definition map_cons: ∀A. A → list (list A) → list (list A) ≝ λA,a.
95                      map … (cons … a).
96
97 interpretation "map_cons" 'ho_cons a l = (map_cons ? a l).
98
99 notation "hvbox(a ::: break l)"
100   right associative with precedence 47
101   for @{'ho_cons $a $l}.
102
103 lemma map_cons_inv_nil: ∀A,a,l1. map_cons A a l1 = ◊ → ◊ = l1.
104 #A #a * // normalize #a1 #l1 #H destruct
105 qed-.
106
107 lemma map_cons_inv_cons: ∀A,a,a2,l2,l1. map_cons A a l1 = a2::l2 →
108                          ∃∃a1,l. a::a1 = a2 & a:::l = l2 & a1::l = l1.
109 #A #a #a2 #l2 * normalize
110 [ #H destruct
111 | #a1 #l1 #H destruct /2 width=5/
112 ]
113 qed-.
114
115 lemma map_cons_append: ∀A,a,l1,l2. map_cons A a (l1@l2) =
116                        map_cons A a l1 @ map_cons A a l2.
117 #A #a #l1 elim l1 -l1 // normalize /2 width=1/
118 qed.
119
120 (* lstar *)
121
122 (* Note: this cannot be in lib because of the missing xoa quantifier *)
123 lemma lstar_inv_pos: ∀A,B,R,l,b1,b2. lstar A B R l b1 b2 → 0 < |l| →
124                      ∃∃a,ll,b. a::ll = l & R a b1 b & lstar A B R ll b b2.
125 #A #B #R #l #b1 #b2 #H @(lstar_ind_l … l b1 H) -l -b1
126 [ #H elim (lt_refl_false … H)
127 | #a #ll #b1 #b #Hb1 #Hb2 #_ #_ /2 width=6/ (**) (* auto fail if we do not remove the inductive premise *)
128 ]
129 qed-.