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 (**************************************************************************)
16 include "list/list.ma".
17 include "cprop_connectives.ma".
19 notation "\rationals" non associative with precedence 99 for @{'q}.
20 interpretation "Q" 'q = Q.
24 bars: list (ℚ × ℚ) (* base, height *)
29 interpretation "Q plus" 'plus x y = (qp x y).
33 interpretation "Q minus" 'minus x y = (qm x y).
35 axiom qlt : ℚ → ℚ → CProp.
37 interpretation "Q less than" 'lt x y = (qlt x y).
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.
44 axiom q_cmp:∀a,b:ℚ.q_comparison a b.
46 definition qle ≝ λa,b:ℚ.a = b ∨ a < b.
48 interpretation "Q less or equal than" 'le x y = (qle x y).
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).
56 notation < "\rationals \sup 2" non associative with precedence 90 for @{'q2}.
57 interpretation "Q x Q" 'q2 = (product Q Q).
59 let rec make_list (A:Type) (def:nat→A) (n:nat) on n ≝
62 | S m ⇒ def m :: make_list A def m].
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).
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.
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))).
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).
86 alias symbol "pi1" = "exT fst".
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.
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.
94 alias symbol "pi2" = "pair pi2".
95 alias symbol "pi1" = "pair pi1".
96 alias symbol "pair" = "pair".
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;
104 let rec aux (l1,l2:list (ℚ × ℚ)) (n:nat) on n : (list (ℚ × ℚ)) × (list (ℚ × ℚ)) ≝
110 let copy_l2_with_0 ≝ mk_list (λi.〈fst (nth l2 q0 i),OQ〉) (length ? l2) in
112 | cons he1 tl1 ⇒〈[],[]〉 (*
115 let copy_l1_with_0 ≝ mk_list (λi.〈fst (nth l1 q0 i),OQ〉) (length ? l1) in
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
124 let rc ≝ aux tl1 tl2 m in
125 〈he1 :: fst rc,he2 :: snd rc〉
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〉
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〉
135 in aux : ∀l1,l2,m.∃p.True);
138 [1: apply (mk_q_f s1);
139 |2: apply (mk_q_f s1); cases l2;
141 [1: (* offset: the smallest one *)