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