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".
20 notation "\rationals" non associative with precedence 99 for @{'q}.
21 interpretation "Q" 'q = Q.
25 bars: list (ℚ × ℚ) (* base, height *)
30 interpretation "Q plus" 'plus x y = (qp x y).
34 interpretation "Q minus" 'minus x y = (qm x y).
36 axiom qlt : ℚ → ℚ → CProp.
38 interpretation "Q less than" 'lt x y = (qlt x y).
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.
45 axiom q_cmp:∀a,b:ℚ.q_comparison a b.
47 definition qle ≝ λa,b:ℚ.a = b ∨ a < b.
49 interpretation "Q less or equal than" 'le x y = (qle x y).
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).
57 notation < "\rationals \sup 2" non associative with precedence 90 for @{'q2}.
58 interpretation "Q x Q" 'q2 = (Prod Q Q).
60 let rec make_list (A:Type) (def:nat→A) (n:nat) on n ≝
63 | S m ⇒ def m :: make_list A def m].
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).
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 (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))).
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).
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.
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.
94 definition cb0h ≝ (λl.mk_list (λi.〈\fst (nth l q0 i),OQ〉) (length ? l)).
96 alias symbol "pi2" = "pair pi2".
97 alias symbol "pi1" = "pair pi1".
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);
106 let rec aux (l1,l2:list (ℚ × ℚ)) (n:nat) on n : (list (ℚ × ℚ)) × (list (ℚ × ℚ)) ≝
108 [ O ⇒ 〈 nil ? , nil ? 〉
111 [ nil ⇒ 〈cb0h l2, l2〉
114 [ nil ⇒ 〈l1, cb0h l1〉
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
122 let rc ≝ aux tl1 tl2 m in
123 〈he1 :: \fst rc,he2 :: \snd rc〉
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〉
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〉
133 in aux : ∀l1,l2,m.∃z.spec l1 l2 m z);