]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambda/preamble.ma
eb0f409a5d1f2f59090750bf179e05051053977f
[helm.git] / matita / matita / contribs / lambda / 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/star.ma".
16 include "basics/lists/list.ma".
17 include "arithmetics/exp.ma".
18
19 include "xoa_notation.ma".
20 include "xoa.ma".
21
22 (* logic *)
23
24 (* Note: For some reason this cannot be in the standard library *) 
25 interpretation "logical false" 'false = False.
26
27 notation "⊥"
28   non associative with precedence 90
29   for @{'false}.
30
31 lemma ex2_1_commute: ∀A0. ∀P0,P1:A0→Prop. (∃∃x0. P0 x0 & P1 x0) → ∃∃x0. P1 x0 & P0 x0.
32 #A0 #P0 #P1 * /2 width=3/
33 qed.
34
35 (* relations *)
36
37 definition confluent1: ∀A. relation A → predicate A ≝ λA,R,a0.
38                        ∀a1. R a0 a1 → ∀a2. R a0 a2 →
39                        ∃∃a. R a1 a & R a2 a. 
40
41 (* Note: confluent1 would be redundant if \Pi-reduction where enabled *)                       
42 definition confluent: ∀A. predicate (relation A) ≝ λA,R.
43                       ∀a0. confluent1 … R a0.
44
45 (* booleans *)
46
47 definition is_false: predicate bool ≝ λb.
48                      false = b.
49
50 (* arithmetics *)
51
52 lemma lt_refl_false: ∀n. n < n → ⊥.
53 #n #H elim (lt_to_not_eq … H) -H /2 width=1/
54 qed-.
55
56 lemma lt_zero_false: ∀n. n < 0 → ⊥.
57 #n #H elim (lt_to_not_le … H) -H /2 width=1/
58 qed-.
59
60 lemma plus_lt_false: ∀m,n. m + n < m → ⊥.
61 #m #n #H elim (lt_to_not_le … H) -H /2 width=1/
62 qed-.
63
64 lemma lt_or_eq_or_gt: ∀m,n. ∨∨ m < n | n = m | n < m.
65 #m #n elim (lt_or_ge m n) /2 width=1/
66 #H elim H -m /2 width=1/
67 #m #Hm * #H /2 width=1/ /3 width=1/
68 qed-.
69
70 (* trichotomy operator *)
71
72 (* Note: this is "if eqb n1 n2 then a2 else if leb n1 n2 then a1 else a3" *)
73 let rec tri (A:Type[0]) n1 n2 a1 a2 a3 on n1 : A ≝
74   match n1 with 
75   [ O    ⇒ match n2 with [ O ⇒ a2 | S n2 ⇒ a1 ]
76   | S n1 ⇒ match n2 with [ O ⇒ a3 | S n2 ⇒ tri A n1 n2 a1 a2 a3 ]
77   ].
78
79 lemma tri_lt: ∀A,a1,a2,a3,n2,n1. n1 < n2 → tri A n1 n2 a1 a2 a3 = a1.
80 #A #a1 #a2 #a3 #n2 elim n2 -n2
81 [ #n1 #H elim (lt_zero_false … H)
82 | #n2 #IH #n1 elim n1 -n1 // /3 width=1/
83 ]
84 qed.
85
86 lemma tri_eq: ∀A,a1,a2,a3,n. tri A n n a1 a2 a3 = a2.
87 #A #a1 #a2 #a3 #n elim n -n normalize //
88 qed.
89
90 lemma tri_gt: ∀A,a1,a2,a3,n1,n2. n2 < n1 → tri A n1 n2 a1 a2 a3 = a3.
91 #A #a1 #a2 #a3 #n1 elim n1 -n1
92 [ #n2 #H elim (lt_zero_false … H)
93 | #n1 #IH #n2 elim n2 -n2 // /3 width=1/
94 ]
95 qed.
96
97 (* lists *)
98
99 (* Note: notation for nil not involving brackets *)
100 notation > "◊"
101   non associative with precedence 90
102   for @{'nil}.
103
104 let rec Allr (A:Type[0]) (R:relation A) (l:list A) on l : Prop ≝
105 match l with
106 [ nil       ⇒ True
107 | cons a1 l ⇒ match l with [ nil ⇒ True | cons a2 _ ⇒ R a1 a2 ∧ Allr A R l ]
108 ].