--- /dev/null
+(**************************************************************************)
+(* ___ *)
+(* ||M|| *)
+(* ||A|| A project by Andrea Asperti *)
+(* ||T|| *)
+(* ||I|| Developers: *)
+(* ||T|| The HELM team. *)
+(* ||A|| http://helm.cs.unibo.it *)
+(* \ / *)
+(* \ / This file is distributed under the terms of the *)
+(* v GNU General Public License Version 2 *)
+(* *)
+(**************************************************************************)
+
+include "Q/q/q.ma".
+include "list/list.ma".
+include "cprop_connectives.ma".
+
+notation "\rationals" non associative with precedence 99 for @{'q}.
+interpretation "Q" 'q = Q.
+
+record q_f : Type ≝ {
+ start : ℚ;
+ bars: list (ℚ × ℚ) (* base, height *)
+}.
+
+axiom qp : ℚ → ℚ → ℚ.
+
+interpretation "Q plus" 'plus x y = (qp x y).
+
+axiom qm : ℚ → ℚ → ℚ.
+
+interpretation "Q minus" 'minus x y = (qm x y).
+
+axiom qlt : ℚ → ℚ → CProp.
+
+interpretation "Q less than" 'lt x y = (qlt x y).
+
+inductive q_comparison (a,b:ℚ) : CProp ≝
+ | q_eq : a = b → q_comparison a b
+ | q_lt : a < b → q_comparison a b
+ | q_gt : b < a → q_comparison a b.
+
+axiom q_cmp:∀a,b:ℚ.q_comparison a b.
+
+definition qle ≝ λa,b:ℚ.a = b ∨ a < b.
+
+interpretation "Q less or equal than" 'le x y = (qle x y).
+
+notation "'nth'" left associative with precedence 70 for @{'nth}.
+notation < "\nth \nbsp l \nbsp d \nbsp i" left associative with precedence 70 for @{'nth_appl $l $d $i}.
+interpretation "list nth" 'nth = (cic:/matita/list/list/nth.con _).
+interpretation "list nth" 'nth_appl l d i = (cic:/matita/list/list/nth.con _ l d i).
+
+notation < "\rationals \sup 2" non associative with precedence 40 for @{'q2}.
+interpretation "Q x Q" 'q2 = (product Q Q).
+
+let rec mk_list (A:Type) (def:nat→A) (n:nat) on n ≝
+ match n with
+ [ O ⇒ []
+ | S m ⇒ def m :: mk_list A def m].
+
+interpretation "mk_list appl" 'mk_list f n = (mk_list f n).
+interpretation "mk_list" 'mk_list = mk_list.
+notation < "\mk_list \nbsp f \nbsp n" left associative with precedence 70 for @{'mk_list_appl $f $n}.
+notation "'mk_list'" left associative with precedence 70 for @{'mk_list}.
+
+alias symbol "pair" = "pair".
+definition q00 : ℚ × ℚ ≝ 〈OQ,OQ〉.
+
+alias symbol "pi2" = "pair pi2".
+alias symbol "pi1" = "pair pi1".
+alias symbol "pair" = "pair".
+definition rebase:
+ q_f → q_f →
+ ∃p:q_f × q_f.∀i.
+ fst (nth (bars (fst p)) q00 i) =
+ fst (nth (bars (snd p)) q00 i).
+intros (f1 f2); cases f1 (s1 l1); cases f2 (s2 l2); clear f1 f2;
+letin aux ≝ (
+let rec aux (l1,l2:list (ℚ × ℚ)) on l1 : (list (ℚ × ℚ)) × (list (ℚ × ℚ)) ≝
+ match l1 with
+ [ nil ⇒ 〈mk_list (λi.〈fst (nth l2 q00 i),OQ〉) (length ? l2),l2〉
+ | cons he tl ⇒ 〈[],[]〉] in aux);
+
+cases (q_cmp s1 s2);
+[1: apply (mk_q_f s1);
+|2: apply (mk_q_f s1); cases l2;
+ [1: letin l2' ≝ (
+[1: (* offset: the smallest one *)
+ cases