]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/dama/dama/models/q_function.ma
a1ed8fa00941eb1952955cc9480375a852342c4e
[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 = (product 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 alias symbol "pair" = "pair".
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 (product Q Q)).
77 notation < "[ \rationals \sup 2] \sup 2" with precedence 90 for @{'lq22}.
78 interpretation "lq22" 'lq22 = (product (list (product Q Q)) (list (product 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 alias symbol "pi1" = "exT fst".
87 definition eject ≝
88   λP.λp:∃x:(list (ℚ × ℚ)) × (list (ℚ × ℚ)).P x.match p with [ex_introT p _ ⇒ p].
89 coercion cic:/matita/dama/models/q_function/eject.con.
90 definition inject ≝
91   λP.λp:(list (ℚ × ℚ)) × (list (ℚ × ℚ)).λh:P p. ex_introT ? P p h.
92 coercion cic:/matita/dama/models/q_function/inject.con 0 1 nocomposites.
93
94 alias symbol "pi2" = "pair pi2".
95 alias symbol "pi1" = "pair pi1".
96 alias symbol "pair" = "pair".
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 aux ≝ (
104 let rec aux (l1,l2:list (ℚ × ℚ)) (n:nat) on n : (list (ℚ × ℚ)) × (list (ℚ × ℚ)) ≝
105 match n with
106 [ O ⇒ 〈[],[]〉
107 | S m ⇒
108   match l1 with
109   [ nil ⇒ 
110      let copy_l2_with_0 ≝ mk_list (λi.〈fst (nth l2 q0 i),OQ〉) (length ? l2) in
111      〈copy_l2_with_0, l2〉
112   | cons he1 tl1 ⇒〈[],[]〉 (*
113      match l2 with
114      [ nil ⇒ 
115          let copy_l1_with_0 ≝ mk_list (λi.〈fst (nth l1 q0 i),OQ〉) (length ? l1) in
116          〈l1, copy_l1_with_0〉
117      | cons he2 tl2 ⇒ 
118          let base1 ≝ fst he1 in
119          let base2 ≝ fst he2 in
120          let height1 ≝ snd he1 in
121          let height2 ≝ snd he2 in
122          match q_cmp base1 base2 with
123          [ q_eq _ ⇒
124              let rc ≝ aux tl1 tl2 m in 
125              〈he1 :: fst rc,he2 :: snd rc〉
126          | q_lt _ ⇒ 
127              let rest ≝ base2 - base1 in
128              let rc ≝ aux tl1 (〈rest,height2〉 :: tl2) m in
129              〈〈base1,height1〉 :: fst rc,〈base1,height2〉 :: snd rc〉
130          | q_gt _ ⇒ 
131              let rest ≝ base1 - base2 in
132              let rc ≝ aux (〈rest,height1〉 :: tl1) tl2 m in
133              〈〈base2,height1〉 :: fst rc,〈base2,height2〉 :: snd rc〉
134 ]]*)]]
135 in aux : ∀l1,l2,m.∃p.True); 
136   
137 cases (q_cmp s1 s2);
138 [1: apply (mk_q_f s1);
139 |2: apply (mk_q_f s1); cases l2;
140     [1: letin l2' ≝ (
141 [1: (* offset: the smallest one *)
142     cases