1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 include "basics/star1.ma".
16 include "basics/lists/lstar.ma".
17 include "arithmetics/exp.ma".
19 include "lambda/notation/xoa/false_0.ma".
20 include "lambda/notation/xoa/true_0.ma".
21 include "lambda/xoa/or_3.ma".
22 include "lambda/xoa/ex_1_2.ma".
23 include "lambda/xoa/ex_3_2.ma".
24 include "lambda/xoa/ex_3_3.ma".
26 include "lambda/notation/functions/nil_0.ma".
27 include "lambda/notation/functions/hocons_2.ma".
31 (* Note: For some reason this cannot be in the standard library *)
32 interpretation "logical false" 'false = False.
36 (* Note: For some reason this cannot be in the standard library *)
37 interpretation "boolean false" 'false = false.
39 (* Note: For some reason this cannot be in the standard library *)
40 interpretation "boolean true" 'true = true.
44 lemma lt_refl_false: ∀n. n < n → ⊥.
45 #n #H elim (lt_to_not_eq … H) -H /2 width=1/
48 lemma lt_zero_false: ∀n. n < 0 → ⊥.
49 #n #H elim (lt_to_not_le … H) -H /2 width=1/
52 lemma plus_lt_false: ∀m,n. m + n < m → ⊥.
53 #m #n #H elim (lt_to_not_le … H) -H /2 width=1/
56 lemma lt_or_eq_or_gt: ∀m,n. ∨∨ m < n | n = m | n < m.
57 #m #n elim (lt_or_ge m n) /2 width=1/
58 #H elim H -m /2 width=1/
59 #m #Hm * #H /2 width=1/ /3 width=1/
62 (* trichotomy operator *)
64 (* Note: this is "if eqb n1 n2 then a2 else if leb n1 n2 then a1 else a3" *)
65 let rec tri (A:Type[0]) n1 n2 a1 a2 a3 on n1 : A ≝
67 [ O ⇒ match n2 with [ O ⇒ a2 | S n2 ⇒ a1 ]
68 | S n1 ⇒ match n2 with [ O ⇒ a3 | S n2 ⇒ tri A n1 n2 a1 a2 a3 ]
71 lemma tri_lt: ∀A,a1,a2,a3,n2,n1. n1 < n2 → tri A n1 n2 a1 a2 a3 = a1.
72 #A #a1 #a2 #a3 #n2 elim n2 -n2
73 [ #n1 #H elim (lt_zero_false … H)
74 | #n2 #IH #n1 elim n1 -n1 // /3 width=1/
78 lemma tri_eq: ∀A,a1,a2,a3,n. tri A n n a1 a2 a3 = a2.
79 #A #a1 #a2 #a3 #n elim n -n normalize //
82 lemma tri_gt: ∀A,a1,a2,a3,n1,n2. n2 < n1 → tri A n1 n2 a1 a2 a3 = a3.
83 #A #a1 #a2 #a3 #n1 elim n1 -n1
84 [ #n2 #H elim (lt_zero_false … H)
85 | #n1 #IH #n2 elim n2 -n2 // /3 width=1/
91 lemma list_inv: ∀A. ∀l:list A. ◊ = l ∨ ∃∃a0,l0. a0 :: l0 = l.
92 #A * /2 width=1/ /3 width=3/
95 definition map_cons: ∀A. A → list (list A) → list (list A) ≝ λA,a.
98 interpretation "map_cons" 'ho_cons a l = (map_cons ? a l).
100 lemma map_cons_inv_nil: ∀A,a,l1. map_cons A a l1 = ◊ → ◊ = l1.
101 #A #a * // normalize #a1 #l1 #H destruct
104 lemma map_cons_inv_cons: ∀A,a,a2,l2,l1. map_cons A a l1 = a2::l2 →
105 ∃∃a1,l. a::a1 = a2 & a:::l = l2 & a1::l = l1.
106 #A #a #a2 #l2 * normalize
108 | #a1 #l1 #H destruct /2 width=5/
112 lemma map_cons_append: ∀A,a,l1,l2. map_cons A a (l1@l2) =
113 map_cons A a l1 @ map_cons A a l2.
114 #A #a #l1 elim l1 -l1 // normalize /2 width=1/
119 (* Note: this cannot be in lib because of the missing xoa quantifier *)
120 lemma lstar_inv_pos: ∀A,B,R,l,b1,b2. lstar A B R l b1 b2 → 0 < |l| →
121 ∃∃a,ll,b. a::ll = l & R a b1 b & lstar A B R ll b b2.
122 #A #B #R #l #b1 #b2 #H @(lstar_ind_l … l b1 H) -l -b1
123 [ #H elim (lt_refl_false … H)
124 | #a #ll #b1 #b #Hb1 #Hb2 #_ #_ /2 width=6/ (**) (* auto fail if we do not remove the inductive premise *)