]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/dama/dama/models/q_function.ma
48d3012ec66974d8c8993e5db02bd72e3b488229
[helm.git] / helm / software / matita / contribs / dama / dama / models / q_function.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 "Q/q/q.ma".
16 include "list/list.ma".
17 include "cprop_connectives.ma". 
18
19
20 notation "\rationals" non associative with precedence 99 for @{'q}.
21 interpretation "Q" 'q = Q. 
22
23 record q_f : Type ≝ {
24  start : ℚ;
25  bars: list (ℚ × ℚ) (* base, height *)
26 }.
27
28 axiom qp : ℚ → ℚ → ℚ.
29
30 interpretation "Q plus" 'plus x y = (qp x y).
31
32 axiom qm : ℚ → ℚ → ℚ.
33
34 interpretation "Q minus" 'minus x y = (qm x y).
35
36 axiom qlt : ℚ → ℚ → CProp.
37
38 interpretation "Q less than" 'lt x y = (qlt x y).
39
40 inductive q_comparison (a,b:ℚ) : CProp ≝
41  | q_eq : a = b → q_comparison a b 
42  | q_lt : a < b → q_comparison a b
43  | q_gt : b < a → q_comparison a b.
44
45 axiom q_cmp:∀a,b:ℚ.q_comparison a b.
46
47 definition qle ≝ λa,b:ℚ.a = b ∨ a < b.
48
49 interpretation "Q less or equal than" 'le x y = (qle x y).
50
51 notation "'nth'" with precedence 90 for @{'nth}.
52 notation < "'nth' \nbsp l \nbsp d \nbsp i" with precedence 71 
53 for @{'nth_appl $l $d $i}.
54 interpretation "list nth" 'nth = (cic:/matita/list/list/nth.con _).
55 interpretation "list nth" 'nth_appl l d i = (cic:/matita/list/list/nth.con _ l d i).
56
57 notation < "\rationals \sup 2" non associative with precedence 90 for @{'q2}.
58 interpretation "Q x Q" 'q2 = (Prod Q Q).
59
60 let rec make_list (A:Type) (def:nat→A) (n:nat) on n ≝
61   match n with
62   [ O ⇒ nil ?
63   | S m ⇒ def m :: make_list A def m].
64
65 notation "'mk_list'" with precedence 90 for @{'mk_list}.
66 interpretation "'mk_list'" 'mk_list = (make_list _).   
67 notation < "'mk_list' \nbsp f \nbsp n" 
68 with precedence 71 for @{'mk_list_appl $f $n}.
69 interpretation "'mk_list' appl" 'mk_list_appl f n = (make_list _ f n).
70
71 definition q0 : ℚ × ℚ ≝ 〈OQ,OQ〉.
72 notation < "0 \sub \rationals" with precedence 90 for @{'q0}.
73 interpretation "q0" 'q0 = q0.
74
75 notation < "[ \rationals \sup 2]" with precedence 90 for @{'lq2}.
76 interpretation "lq2" 'lq2 = (list (Prod Q Q)).
77 notation < "[ \rationals \sup 2] \sup 2" with precedence 90 for @{'lq22}.
78 interpretation "lq22" 'lq22 = (Prod (list (Prod Q Q)) (list (Prod Q Q))).
79
80
81 notation "'len'" with precedence 90 for @{'len}.
82 interpretation "len" 'len = length.
83 notation < "'len' \nbsp l" with precedence 70 for @{'len_appl $l}.
84 interpretation "len appl" 'len_appl l = (length _ l).
85
86 definition eject ≝
87   λP.λp:∃x:(list (ℚ × ℚ)) × (list (ℚ × ℚ)).P x.match p with [ex_introT p _ ⇒ p].
88 coercion cic:/matita/dama/models/q_function/eject.con.
89 definition inject ≝
90   λP.λp:(list (ℚ × ℚ)) × (list (ℚ × ℚ)).λh:P p. ex_introT ? P p h.
91 (*coercion inject with 0 1 nocomposites.*)
92 coercion cic:/matita/dama/models/q_function/inject.con 0 1 nocomposites.
93
94 definition cb0h ≝ (λl.mk_list (λi.〈\fst (nth l q0 i),OQ〉) (length ? l)).
95
96 alias symbol "pi2" = "pair pi2".
97 alias symbol "pi1" = "pair pi1".
98 definition rebase: 
99   q_f → q_f → 
100     ∃p:q_f × q_f.∀i.
101      \fst (nth (bars (\fst p)) q0 i) = 
102      \fst (nth (bars (\snd p)) q0 i).
103 intros (f1 f2); cases f1 (s1 l1); cases f2 (s2 l2); clear f1 f2;
104 letin spec ≝ (λl1,l2:list (ℚ × ℚ).λm:nat.λz:(list (ℚ × ℚ)) × (list (ℚ × ℚ)).True);
105 letin aux ≝ ( 
106 let rec aux (l1,l2:list (ℚ × ℚ)) (n:nat) on n : (list (ℚ × ℚ)) × (list (ℚ × ℚ)) ≝
107 match n with
108 [ O ⇒ 〈 nil ? , nil ? 〉
109 | S m ⇒ 
110   match l1 with
111   [ nil ⇒ 〈cb0h l2, l2〉
112   | cons he1 tl1 ⇒
113      match l2 with
114      [ nil ⇒ 〈l1, cb0h l1〉
115      | cons he2 tl2 ⇒  
116          let base1 ≝ (\fst he1) in
117          let base2 ≝ (\fst he2) in
118          let height1 ≝ (\snd he1) in
119          let height2 ≝ (\snd he2) in
120          match q_cmp base1 base2 with
121          [ q_eq _ ⇒
122              let rc ≝ aux tl1 tl2 m in 
123              〈he1 :: \fst rc,he2 :: \snd rc〉
124          | q_lt _ ⇒ 
125              let rest ≝ base2 - base1 in
126              let rc ≝ aux tl1 (〈rest,height2〉 :: tl2) m in
127              〈〈base1,height1〉 :: \fst rc,〈base1,height2〉 :: \snd rc〉
128          | q_gt _ ⇒ 
129              let rest ≝ base1 - base2 in
130              let rc ≝ aux (〈rest,height1〉 :: tl1) tl2 m in
131              〈〈base2,height1〉 :: \fst rc,〈base2,height2〉 :: \snd rc〉
132 ]]]]
133 in aux : ∀l1,l2,m.∃z.spec l1 l2 m z); 
134 qed.