(***************************************************************************)
(* Formalization of the Chou, Gao and Zhang's decision procedure.          *)
(* Julien Narboux (Julien@narboux.fr)                                      *)
(* LIX/INRIA FUTURS 2004-2006                                              *)
(* University of Strasbourg 2008                                           *)
(***************************************************************************)
Require Export field_general_properties.
(** We define our own field tactic based on the new ring *)
(** This tactic is geared toward automation because it does not generate non nullity conditions but it assumes that we know that the denominators of the input are not zero (syntactically !) *)
(** This tactic is also used to reduce a term to a unique fraction *)
(** This tactic is not reflexive, it is basically a reduction to the same denominators but even using the legacy ring it is quicker than the legacy field tactic on our examples *)
Ltac assumption_or_ax := assumption || apply chara_not_2.
Ltac solve_conds :=
repeat split;
repeat (assumption_or_ax ||
apply nonzeromult ||
apply nonzerodiv ||
apply nonzeroinv).
Ltac smart_field := field; solve_conds.
Ltac smart_field_simplify_eq := field_simplify_eq;solve_conds.
Hint Rewrite
simp_1 simp_2 simp_3 simp_4 simp_5
simp_6 simp_7 simp_8 simp_9 simp_10
simp_11 simp_12 simp_13 simp_14 simp_15
: ring_simplification.
Hint Rewrite
same_denom_add_1
same_denom_add_2
same_denom_add_3
same_denom_min_1
same_denom_min_2
same_denom_min_3
same_denom_mul_1
same_denom_mul_2
same_denom_mul_3
same_denom_div_1
same_denom_div_2
same_denom_div_3
: same_denom.
Hint Rewrite
simp_frac_1
simp_frac_2
simp_frac_3
simp_frac_4
simp_frac_5
simp_frac_6
simp_frac_7
simp_frac_8
simp_frac_9
simp_frac_10
simp_frac_11
simp_frac_12
simp_frac_13
simp_frac_14
simp_frac_15
simp_frac_16
: field_simplification.
Ltac basic_field_simpl_goal :=
repeat
match goal with
| H:?X1<>0 |- context [?X1 / ?X1] =>
rewrite (simp_frac_1 X1 H) in *
| H:?X1<>0 |- context [(- ?X1) / ?X1] =>
rewrite (simp_frac_5 X1 H) in *
| H:- ?X1<>0 |- context [?X1 / - ?X1] =>
rewrite (simp_frac_6 X1 H) in *
| H:- ?X1<>0 |- context [(-?X1) / - ?X1] =>
rewrite (simp_frac_7 X1 H) in *
| H: ?X1<>0 |- context [0 / ?X1] =>
rewrite (simp_frac_10 X1 H) in *
| H: ?X1<>0 |- context [?X1 * (1 / ?X1)] =>
rewrite (simp_frac_11 X1 H) in *
| H: ?X2<>0 |- context [(?X1 * ?X2) / ?X2] =>
rewrite (simp_frac_12 X1 X2 H) in *
| H: ?X1<>0 |- context [(?X1 * ?X2) / ?X1] =>
rewrite (simp_frac_13 X1 X2 H) in *
| H: ?X2<>0 |- context [(- ?X1) / ?X2] =>
rewrite (simp_frac_14 X1 X2 H) in *
| H: - ?X2<>0 |- context [ ?X1 / (- ?X2)] =>
rewrite (simp_frac_16 X1 X2 H) in *;
let T:=fresh in
assert (T:= simp_frac_16_inv X2 H)
| H:_ |- context [?X1 / 1] =>
rewrite (simp_frac_15 X1) in *
end.
Ltac basic_field_simpl_hyps :=
repeat
match goal with
| H:?X1<>0, Hc: context [?X1 / ?X1] |- _ =>
rewrite (simp_frac_1 X1 H) in *|-
| H:?X1<>0, Hc: context [(- ?X1) / ?X1] |- _ =>
rewrite (simp_frac_5 X1 H) in *|-
| H:- ?X1<>0, Hc: context [?X1 / - ?X1] |- _ =>
rewrite (simp_frac_6 X1 H) in *|-
| H:- ?X1<>0, Hc: context [(- ?X1) / - ?X1] |- _ =>
rewrite (simp_frac_7 X1 H) in *|-
| H: ?X1<>0, Hc: context [0 / ?X1] |- _ =>
rewrite (simp_frac_10 X1 H) in *|-
| H: ?X1<>0, Hc: context [?X1 * (1 / ?X1)] |- _ =>
rewrite (simp_frac_11 X1 H) in *|-
| H: ?X2<>0, Hc: context [(?X1 * ?X2) / ?X2] |- _ =>
rewrite (simp_frac_12 X1 X2 H) in *|-
| H: ?X1<>0, Hc: context [(?X1 * ?X2) / ?X1] |- _ =>
rewrite (simp_frac_13 X1 X2 H) in *|-
| H: ?X2<>0, Hc: context [(-?X1) / ?X2] |- _ =>
rewrite (simp_frac_14 X1 X2 H) in *|-
| H: - ?X2<>0, Hc: context [ ?X1 / (- ?X2)] |- _ =>
rewrite (simp_frac_16 X1 X2 H) in *|-;
let T:=fresh in
assert (T:= simp_frac_16_inv X2 H)
| Hc: context [?X1 / 1] |- _ =>
rewrite (simp_frac_15 X1) in *|-
end.
Ltac basic_field_simpl := basic_field_simpl_goal;basic_field_simpl_hyps.
Goal forall a b , a<>0 -> b<>0 -> -a<>0 -> -b<>0 ->
a/a + (-a)/a + a/(-a) + (-a)/(-a) + 0/a + a*(1/a) + (a*b)/a +(a*b)/b -a/1 +a/(-b)= 1  ->
b/b + (-b)/b + b/(-b) + (-b)/(-b) +0/b + b*(1/b) +(b*a)/b + (b*a)/a -b/1 + (-a)/1 = 1.

Lemma same_denom_conclude_3 : forall a c d :F,
a*d = c ->
d<>0 ->
a = c/d.