(************************************************************************) (* v * The Coq Proof Assistant / The Coq Development Team *) (* y" := (BigQ.lt y x)(only parsing) : bigQ_scope. Notation "x >= y" := (BigQ.le y x)(only parsing) : bigQ_scope. Notation "[ q ]" := (BigQ.to_Q q) : bigQ_scope. Open Scope bigQ_scope. (** [BigQ] is a setoid *) Add Relation BigQ.t BigQ.eq reflexivity proved by (fun x => Qeq_refl [x]) symmetry proved by (fun x y => Qeq_sym [x] [y]) transitivity proved by (fun x y z => Qeq_trans [x] [y] [z]) as BigQeq_rel. Add Morphism BigQ.add with signature BigQ.eq ==> BigQ.eq ==> BigQ.eq as BigQadd_wd. Proof. unfold BigQ.eq; intros; rewrite !BigQ.spec_add; rewrite H, H0; apply Qeq_refl. Qed. Add Morphism BigQ.opp with signature BigQ.eq ==> BigQ.eq as BigQopp_wd. Proof. unfold BigQ.eq; intros; rewrite !BigQ.spec_opp; rewrite H; apply Qeq_refl. Qed. Add Morphism BigQ.sub with signature BigQ.eq ==> BigQ.eq ==> BigQ.eq as BigQsub_wd. Proof. unfold BigQ.eq; intros; rewrite !BigQ.spec_sub; rewrite H, H0; apply Qeq_refl. Qed. Add Morphism BigQ.mul with signature BigQ.eq ==> BigQ.eq ==> BigQ.eq as BigQmul_wd. Proof. unfold BigQ.eq; intros; rewrite !BigQ.spec_mul; rewrite H, H0; apply Qeq_refl. Qed. Add Morphism BigQ.inv with signature BigQ.eq ==> BigQ.eq as BigQinv_wd. Proof. unfold BigQ.eq; intros; rewrite !BigQ.spec_inv; rewrite H; apply Qeq_refl. Qed. Add Morphism BigQ.div with signature BigQ.eq ==> BigQ.eq ==> BigQ.eq as BigQdiv_wd. Proof. unfold BigQ.eq; intros; rewrite !BigQ.spec_div; rewrite H, H0; apply Qeq_refl. Qed. (* TODO : fix this. For the moment it's useless (horribly slow) Hint Rewrite BigQ.spec_0 BigQ.spec_1 BigQ.spec_m1 BigQ.spec_compare BigQ.spec_red BigQ.spec_add BigQ.spec_sub BigQ.spec_opp BigQ.spec_mul BigQ.spec_inv BigQ.spec_div BigQ.spec_power_pos BigQ.spec_square : bigq. *) (** [BigQ] is a field *) Lemma BigQfieldth : field_theory BigQ.zero BigQ.one BigQ.add BigQ.mul BigQ.sub BigQ.opp BigQ.div BigQ.inv BigQ.eq. Proof. constructor. constructor; intros; red. rewrite BigQ.spec_add, BigQ.spec_0; ring. rewrite ! BigQ.spec_add; ring. rewrite ! BigQ.spec_add; ring. rewrite BigQ.spec_mul, BigQ.spec_1; ring. rewrite ! BigQ.spec_mul; ring. rewrite ! BigQ.spec_mul; ring. rewrite BigQ.spec_add, ! BigQ.spec_mul, BigQ.spec_add; ring. unfold BigQ.sub; apply Qeq_refl. rewrite BigQ.spec_add, BigQ.spec_0, BigQ.spec_opp; ring. compute; discriminate. intros; red. unfold BigQ.div; apply Qeq_refl. intros; red. rewrite BigQ.spec_mul, BigQ.spec_inv, BigQ.spec_1; field. rewrite <- BigQ.spec_0; auto. Qed. Lemma BigQpowerth : power_theory BigQ.one BigQ.mul BigQ.eq Z_of_N BigQ.power. Proof. constructor. intros; red. rewrite BigQ.spec_power. replace ([r] ^ Z_of_N n)%Q with (pow_N 1 Qmult [r] n)%Q. destruct n. simpl; compute; auto. induction p; simpl; auto; try rewrite !BigQ.spec_mul, !IHp; apply Qeq_refl. destruct n; reflexivity. Qed. Lemma BigQ_eq_bool_correct : forall x y, BigQ.eq_bool x y = true -> x==y. Proof. intros; generalize (BigQ.spec_eq_bool x y); rewrite H; auto. Qed. Lemma BigQ_eq_bool_complete : forall x y, x==y -> BigQ.eq_bool x y = true. Proof. intros; generalize (BigQ.spec_eq_bool x y). destruct BigQ.eq_bool; auto. Qed. (* TODO : improve later the detection of constants ... *) Ltac BigQcst t := match t with | BigQ.zero => BigQ.zero | BigQ.one => BigQ.one | BigQ.minus_one => BigQ.minus_one | _ => NotConstant end. Add Field BigQfield : BigQfieldth (decidable BigQ_eq_bool_correct, completeness BigQ_eq_bool_complete, constants [BigQcst], power_tac BigQpowerth [Qpow_tac]). Section Examples. Let ex1 : forall x y z, (x+y)*z == (x*z)+(y*z). intros. ring. Qed. Let ex8 : forall x, x ^ 1 == x. intro. ring. Qed. Let ex10 : forall x y, ~(y==BigQ.zero) -> (x/y)*y == x. intros. field. auto. Qed. End Examples.