Skip to content

Commit 4c9d0be

Browse files
committed
Prepare move of micromega_eval.v to Corelib
1 parent 8d8cd91 commit 4c9d0be

File tree

9 files changed

+1941
-1760
lines changed

9 files changed

+1941
-1760
lines changed

test-suite/output/MExtraction.out

Lines changed: 1709 additions & 1597 deletions
Large diffs are not rendered by default.

test-suite/output/MExtraction.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Don't forget to update it in Rocq core when editing this MExtraction.v file
1919
or MExtraction.out *)
2020

21-
From Stdlib Require Import micromega_checker.
21+
From Stdlib Require Import micromega_eval micromega_checker.
2222
From Stdlib Require Extraction.
2323
From Stdlib Require Import ZMicromega.
2424
From Stdlib Require Import QMicromega.
@@ -57,7 +57,7 @@ Extract Constant Rinv => "fun x -> 1 / x".
5757
(** In order to avoid annoying build dependencies the actual
5858
extraction is only performed as a test in the test suite. *)
5959
Recursive Extraction
60-
Tauto.mapX Tauto.foldA Tauto.collect_annot Tauto.ids_of_formula Tauto.map_bformula
60+
Tauto.mapX Tauto.foldA Tauto.collect_annot Tauto.ids_of_formula GFmap
6161
Tauto.abst_form
6262
ZMicromega.cnfZ ZMicromega.Zeval_const QMicromega.cnfQ
6363
List.map simpl_cone (*map_cone indexes*)

theories/micromega/EnvRing.v

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
For big polynomials, this is inefficient -- linear access.
1212
I have modified the code to use binary trees -- logarithmic access. *)
1313

14-
From Stdlib Require Export micromega_formula micromega_witness.
14+
From Stdlib Require Export micromega_formula micromega_witness micromega_eval.
1515
From Stdlib Require Export micromega_checker.
1616
From Stdlib Require Import Setoid Morphisms Env BinPos BinNat BinInt.
1717
From Stdlib Require Export Ring_theory.
@@ -681,16 +681,8 @@ Qed.
681681

682682
(** evaluation of polynomial expressions towards R *)
683683

684-
Fixpoint PEeval (l:Env R) (pe:PExpr) : R :=
685-
match pe with
686-
| PEc c => phi c
687-
| PEX j => nth j l
688-
| PEadd pe1 pe2 => (PEeval l pe1) + (PEeval l pe2)
689-
| PEsub pe1 pe2 => (PEeval l pe1) - (PEeval l pe2)
690-
| PEmul pe1 pe2 => (PEeval l pe1) * (PEeval l pe2)
691-
| PEopp pe1 => - (PEeval l pe1)
692-
| PEpow pe1 n => rpow (PEeval l pe1) (Cp_phi n)
693-
end.
684+
#[local] Notation PEeval := (PEeval
685+
radd rmul rsub ropp phi Cp_phi rpow (@nth R)).
694686

695687
(** Correctness proofs *)
696688

@@ -794,3 +786,6 @@ Section POWER.
794786
End NORM_SUBST_REC.
795787

796788
End MakeRingPol.
789+
790+
Notation PEeval := (fun add mul sub opp phi pow_phi pow => PEeval
791+
add mul sub opp phi pow_phi pow (@Env.nth _)).

theories/micromega/QMicromega.v

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,31 +64,8 @@ Qed.
6464
(*Definition Zeval_expr := eval_pexpr 0 Z.add Z.mul Z.sub Z.opp (fun x => x) (fun x => Z.of_N x) (Z.pow).*)
6565
From Stdlib Require Import EnvRing.
6666

67-
Fixpoint Qeval_expr (env: PolEnv Q) (e: PExpr Q) : Q :=
68-
match e with
69-
| PEc c => c
70-
| PEX j => env j
71-
| PEadd pe1 pe2 => (Qeval_expr env pe1) + (Qeval_expr env pe2)
72-
| PEsub pe1 pe2 => (Qeval_expr env pe1) - (Qeval_expr env pe2)
73-
| PEmul pe1 pe2 => (Qeval_expr env pe1) * (Qeval_expr env pe2)
74-
| PEopp pe1 => - (Qeval_expr env pe1)
75-
| PEpow pe1 n => Qpower (Qeval_expr env pe1) (Z.of_N n)
76-
end.
77-
78-
Lemma Qeval_expr_simpl : forall env e,
79-
Qeval_expr env e =
80-
match e with
81-
| PEc c => c
82-
| PEX j => env j
83-
| PEadd pe1 pe2 => (Qeval_expr env pe1) + (Qeval_expr env pe2)
84-
| PEsub pe1 pe2 => (Qeval_expr env pe1) - (Qeval_expr env pe2)
85-
| PEmul pe1 pe2 => (Qeval_expr env pe1) * (Qeval_expr env pe2)
86-
| PEopp pe1 => - (Qeval_expr env pe1)
87-
| PEpow pe1 n => Qpower (Qeval_expr env pe1) (Z.of_N n)
88-
end.
89-
Proof.
90-
destruct e ; reflexivity.
91-
Qed.
67+
#[local] Notation Qeval_expr := (PEeval
68+
Qplus Qmult Qminus Qopp id Z.of_N Qpower).
9269

9370
Definition Qeval_expr' := eval_pexpr Qplus Qmult Qminus Qopp (fun x => x) (fun x => x) (pow_N 1 Qmult).
9471

@@ -100,10 +77,9 @@ Qed.
10077

10178
Lemma Qeval_expr_compat : forall env e, Qeval_expr env e = Qeval_expr' env e.
10279
Proof.
103-
induction e ; simpl ; subst ; try congruence.
104-
- reflexivity.
105-
- rewrite IHe.
106-
apply QNpower.
80+
induction e ; simpl ; subst ; try congruence; try reflexivity.
81+
rewrite IHe.
82+
apply QNpower.
10783
Qed.
10884

10985
Definition Qeval_pop2 (o : Op2) : Q -> Q -> Prop :=

theories/micromega/RMicromega.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ Definition Reval_formula' :=
440440

441441
Lemma Reval_pop2_eval_op2 : forall o e1 e2,
442442
Reval_pop2 o e1 e2 <->
443-
eval_op2 eq Rle Rlt o e1 e2.
443+
eval_op2 isProp eq (fun x y => x <> y) Rle Rlt o e1 e2.
444444
Proof.
445445
destruct o ; simpl ; try tauto.
446446
split.
@@ -512,15 +512,15 @@ From Stdlib.micromega Require Import Tauto.
512512
Q0 Q1 Qplus Qmult Qminus Qopp Qeq_bool Qle_bool).
513513

514514
Definition RTautoChecker (f : BFormula (Formula Rcst) isProp) (w: list RWitness) : bool :=
515-
micromega_checker.tauto_checker (fun cl => RWeakChecker (List.map fst cl)) (Qcnf_of_GFormula (map_bformula (map_Formula Q_of_Rcst) f)) w.
515+
micromega_checker.tauto_checker (fun cl => RWeakChecker (List.map fst cl)) (Qcnf_of_GFormula (GFmap (Fmap Q_of_Rcst) f)) w.
516516

517517
Lemma RTautoChecker_sound : forall f w, RTautoChecker f w = true -> forall env, eval_bf (Reval_formula env) f.
518518
Proof.
519519
intros f w.
520520
unfold RTautoChecker.
521521
intros TC env.
522522
apply tauto_checker_sound with (eval:=QReval_formula) (eval':= Qeval_nformula) (env := env) in TC.
523-
- change (eval_f e_eKind (QReval_formula env))
523+
- change (GFeval eqb e_eKind (QReval_formula env))
524524
with
525525
(eval_bf (QReval_formula env)) in TC.
526526
rewrite eval_bf_map in TC.

theories/micromega/RingMicromega.v

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -490,22 +490,15 @@ Qed.
490490

491491
(** Normalisation of formulae **)
492492

493-
Definition eval_op2 (o : Op2) : R -> R -> Prop :=
494-
match o with
495-
| OpEq => req
496-
| OpNEq => fun x y : R => x ~= y
497-
| OpLe => rle
498-
| OpGe => fun x y : R => y <= x
499-
| OpLt => fun x y : R => x < y
500-
| OpGt => fun x y : R => y < x
501-
end.
493+
#[local] Notation eval_op2 := (eval_op2
494+
isProp req (fun x y => ~ req x y) rle rlt).
502495

503496
Definition eval_pexpr : PolEnv -> PExpr C -> R :=
504-
PEeval rplus rtimes rminus ropp phi pow_phi rpow.
497+
PEeval rplus rtimes rminus ropp phi pow_phi rpow (@Env.nth R).
505498

506-
Definition eval_formula (env : PolEnv) (f : Formula C) : Prop :=
507-
let (lhs, op, rhs) := f in
508-
(eval_op2 op) (eval_pexpr env lhs) (eval_pexpr env rhs).
499+
#[local] Notation eval_formula := (Feval
500+
rplus rtimes rminus ropp isProp req (fun x y => ~ req x y) rle rlt
501+
phi pow_phi rpow (@Env.nth R)).
509502

510503
(* We normalize Formulas by moving terms to one side *)
511504

@@ -812,30 +805,14 @@ Variable phiS : S -> R.
812805

813806
Variable phi_C_of_S : forall c, phiS c = phi (C_of_S c).
814807

815-
Fixpoint map_PExpr (e : PExpr S) : PExpr C :=
816-
match e with
817-
| PEc c => PEc (C_of_S c)
818-
| PEX p => PEX p
819-
| PEadd e1 e2 => PEadd (map_PExpr e1) (map_PExpr e2)
820-
| PEsub e1 e2 => PEsub (map_PExpr e1) (map_PExpr e2)
821-
| PEmul e1 e2 => PEmul (map_PExpr e1) (map_PExpr e2)
822-
| PEopp e => PEopp (map_PExpr e)
823-
| PEpow e n => PEpow (map_PExpr e) n
824-
end.
825-
826-
Definition map_Formula (f : Formula S) : Formula C :=
827-
let (l,o,r) := f in
828-
Build_Formula (map_PExpr l) o (map_PExpr r).
829-
830-
831808
Definition eval_sexpr : PolEnv -> PExpr S -> R :=
832-
PEeval rplus rtimes rminus ropp phiS pow_phi rpow.
809+
PEeval rplus rtimes rminus ropp phiS pow_phi rpow (@Env.nth R).
833810

834811
Definition eval_sformula (env : PolEnv) (f : Formula S) : Prop :=
835812
let (lhs, op, rhs) := f in
836813
(eval_op2 op) (eval_sexpr env lhs) (eval_sexpr env rhs).
837814

838-
Lemma eval_pexprSC : forall env s, eval_sexpr env s = eval_pexpr env (map_PExpr s).
815+
Lemma eval_pexprSC : forall env s, eval_sexpr env s = eval_pexpr env (PEmap C_of_S s).
839816
Proof.
840817
unfold eval_pexpr, eval_sexpr.
841818
intros env s;
@@ -847,7 +824,7 @@ Proof.
847824
Qed.
848825

849826
(** equality might be (too) strong *)
850-
Lemma eval_formulaSC : forall env f, eval_sformula env f = eval_formula env (map_Formula f).
827+
Lemma eval_formulaSC : forall env f, eval_sformula env f = eval_formula env (Fmap C_of_S f).
851828
Proof.
852829
intros env f; destruct f.
853830
simpl.
@@ -901,6 +878,11 @@ Notation padd := Padd (only parsing).
901878
Notation pmul := Pmul (only parsing).
902879
Notation popp := Popp (only parsing).
903880

881+
Notation eval_formula :=
882+
(fun add mul sub opp eqProp le lt phi pow_phi pow => Feval
883+
add mul sub opp isProp eqProp (fun x y => ~ eqProp x y) le lt
884+
phi pow_phi pow (@Env.nth _)).
885+
904886
(* Local Variables: *)
905887
(* coding: utf-8 *)
906888
(* End: *)

theories/micromega/Tauto.v

Lines changed: 10 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
(* *)
1515
(************************************************************************)
1616

17-
From Stdlib Require Export micromega_formula micromega_witness.
17+
From Stdlib Require Export micromega_formula micromega_witness micromega_eval.
1818
From Stdlib Require Export micromega_checker.
1919
From Stdlib Require Import List.
2020
From Stdlib Require Import Refl.
@@ -29,6 +29,9 @@ Inductive Trace (A : Type) :=
2929
| merge : Trace A -> Trace A -> Trace A
3030
.
3131

32+
#[local] Notation eIFF := (eIFF eqb).
33+
#[local] Notation eval_f := (GFeval eqb).
34+
3235
Section S.
3336
Context {TA : Type}. (* type of interpreted atoms *)
3437
Context {TX : kind -> Type}. (* type of uninterpreted terms (Prop) *)
@@ -105,45 +108,7 @@ Section S.
105108

106109
Variable ea : forall (k: kind), TA -> eKind k.
107110

108-
Definition eTT (k: kind) : eKind k :=
109-
if k as k' return eKind k' then True else true.
110-
111-
Definition eFF (k: kind) : eKind k :=
112-
if k as k' return eKind k' then False else false.
113-
114-
Definition eAND (k: kind) : eKind k -> eKind k -> eKind k :=
115-
if k as k' return eKind k' -> eKind k' -> eKind k'
116-
then and else andb.
117-
118-
Definition eOR (k: kind) : eKind k -> eKind k -> eKind k :=
119-
if k as k' return eKind k' -> eKind k' -> eKind k'
120-
then or else orb.
121-
122-
Definition eIMPL (k: kind) : eKind k -> eKind k -> eKind k :=
123-
if k as k' return eKind k' -> eKind k' -> eKind k'
124-
then (fun x y => x -> y) else implb.
125-
126-
Definition eIFF (k: kind) : eKind k -> eKind k -> eKind k :=
127-
if k as k' return eKind k' -> eKind k' -> eKind k'
128-
then iff else eqb.
129-
130-
Definition eNOT (k: kind) : eKind k -> eKind k :=
131-
if k as k' return eKind k' -> eKind k'
132-
then not else negb.
133-
134-
Fixpoint eval_f (k: kind) (f:GFormula k) {struct f}: eKind k :=
135-
match f in micromega_formula.GFormula k' return eKind k' with
136-
| TT tk => eTT tk
137-
| FF tk => eFF tk
138-
| A k a _ => ea k a
139-
| X k p => ex p
140-
| @AND _ _ _ _ k e1 e2 => eAND k (eval_f e1) (eval_f e2)
141-
| @OR _ _ _ _ k e1 e2 => eOR k (eval_f e1) (eval_f e2)
142-
| @NOT _ _ _ _ k e => eNOT k (eval_f e)
143-
| @IMPL _ _ _ _ k f1 _ f2 => eIMPL k (eval_f f1) (eval_f f2)
144-
| @IFF _ _ _ _ k f1 f2 => eIFF k (eval_f f1) (eval_f f2)
145-
| EQ f1 f2 => (eval_f f1) = (eval_f f2)
146-
end.
111+
#[local] Notation eval_f := (eval_f ex ea).
147112

148113
Lemma eval_f_rew : forall k (f:GFormula k),
149114
eval_f f =
@@ -164,7 +129,7 @@ Section S.
164129
Qed.
165130

166131
End EVAL.
167-
132+
#[local] Notation eval_f := (eval_f ex).
168133

169134
Definition hold (k: kind) : eKind k -> Prop :=
170135
if k as k0 return (eKind k0 -> Prop) then fun x => x else is_true.
@@ -259,37 +224,6 @@ Section S.
259224

260225
End S.
261226

262-
Section MAPATOMS.
263-
Context {TA TA':Type}.
264-
Context {TX : kind -> Type}.
265-
Context {AA : Type}.
266-
Context {AF : Type}.
267-
268-
Fixpoint map_bformula (k: kind)(fct : TA -> TA') (f : @GFormula TA TX AA AF k) : @GFormula TA' TX AA AF k:=
269-
match f with
270-
| TT k => TT k
271-
| FF k => FF k
272-
| X k p => X k p
273-
| A k a t => A k (fct a) t
274-
| AND f1 f2 => AND (map_bformula fct f1) (map_bformula fct f2)
275-
| OR f1 f2 => OR (map_bformula fct f1) (map_bformula fct f2)
276-
| NOT f => NOT (map_bformula fct f)
277-
| IMPL f1 a f2 => IMPL (map_bformula fct f1) a (map_bformula fct f2)
278-
| IFF f1 f2 => IFF (map_bformula fct f1) (map_bformula fct f2)
279-
| EQ f1 f2 => EQ (map_bformula fct f1) (map_bformula fct f2)
280-
end.
281-
282-
End MAPATOMS.
283-
284-
Lemma map_simpl : forall A B f l, @map A B f l = match l with
285-
| nil => nil
286-
| a :: l=> (f a) :: (@map A B f l)
287-
end.
288-
Proof.
289-
intros A B f l; destruct l ; reflexivity.
290-
Qed.
291-
292-
293227
Section S.
294228
(** A cnf tracking annotations of atoms. *)
295229

@@ -1871,7 +1805,7 @@ Section S.
18711805
tauto.
18721806
Qed.
18731807

1874-
Lemma tauto_checker_sound : forall t w, tauto_checker (@xcnf true isProp t) w = true -> forall env, @eval_f _ _ _ unit e_eKind (eval env) _ t.
1808+
Lemma tauto_checker_sound : forall t w, tauto_checker (@xcnf true isProp t) w = true -> forall env, @GFeval eqb _ _ _ unit e_eKind (eval env) _ t.
18751809
Proof.
18761810
unfold tauto_checker.
18771811
intros t w H env.
@@ -1880,10 +1814,10 @@ Section S.
18801814
eapply cnf_checker_sound ; eauto.
18811815
Qed.
18821816

1883-
Definition eval_bf {A : Type} (ea : forall (k: kind), A -> eKind k) (k: kind) (f: BFormula A k) := eval_f e_eKind ea f.
1817+
#[local] Notation eval_bf := (BFeval eqb).
18841818

18851819
Lemma eval_bf_map : forall T U (fct: T-> U) env (k: kind) (f:BFormula T k) ,
1886-
eval_bf env (map_bformula fct f) = eval_bf (fun b x => env b (fct x)) f.
1820+
eval_bf env (GFmap fct f) = eval_bf (fun b x => env b (fct x)) f.
18871821
Proof.
18881822
intros T U fct env k f;
18891823
induction f as [| | | |? ? IHf1 ? IHf2|? ? IHf1 ? IHf2|? ? IHf
@@ -1894,6 +1828,7 @@ Section S.
18941828

18951829

18961830
End S.
1831+
Notation eval_bf := (BFeval eqb).
18971832

18981833
Notation tauto_checker :=
18991834
(fun term term' annot unsat deduce normalise negate witness check f =>

theories/micromega/ZMicromega.v

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,11 @@ Proof.
218218
destruct f as [Flhs Fop Frhs].
219219
repeat rewrite Zeval_expr_compat.
220220
unfold Zeval_formula' ; simpl.
221-
unfold eval_expr.
222-
generalize (eval_pexpr Z.add Z.mul Z.sub Z.opp (fun x : Z => x)
223-
(fun x : N => x) (pow_N 1 Z.mul) env Flhs).
224-
generalize ((eval_pexpr Z.add Z.mul Z.sub Z.opp (fun x : Z => x)
225-
(fun x : N => x) (pow_N 1 Z.mul) env Frhs)).
221+
unfold eval_expr, eval_pexpr.
222+
generalize (micromega_eval.PEeval Z.add Z.mul Z.sub Z.opp (fun x : Z => x)
223+
(fun x : N => x) (pow_N 1 Z.mul) (@Env.nth Z) env Flhs).
224+
generalize (micromega_eval.PEeval Z.add Z.mul Z.sub Z.opp (fun x : Z => x)
225+
(fun x : N => x) (pow_N 1 Z.mul) (@Env.nth Z) env Frhs).
226226
destruct Fop ; simpl; intros;
227227
intuition auto using Z.le_ge, Z.ge_le, Z.lt_gt, Z.gt_lt.
228228
Qed.
@@ -340,11 +340,11 @@ Proof.
340340
destruct f as [lhs o rhs].
341341
destruct o eqn:O ; cbn ; rewrite ?eval_pol_sub;
342342
rewrite <- !eval_pol_norm ; simpl in *;
343-
unfold eval_expr;
344-
generalize ( eval_pexpr Z.add Z.mul Z.sub Z.opp (fun x : Z => x)
345-
(fun x : N => x) (pow_N 1 Z.mul) env lhs);
346-
generalize (eval_pexpr Z.add Z.mul Z.sub Z.opp (fun x : Z => x)
347-
(fun x : N => x) (pow_N 1 Z.mul) env rhs); intros z z0.
343+
unfold eval_expr, eval_pexpr;
344+
generalize (micromega_eval.PEeval Z.add Z.mul Z.sub Z.opp (fun x : Z => x)
345+
(fun x : N => x) (pow_N 1 Z.mul) (@Env.nth Z) env lhs);
346+
generalize (micromega_eval.PEeval Z.add Z.mul Z.sub Z.opp (fun x : Z => x)
347+
(fun x : N => x) (pow_N 1 Z.mul) (@Env.nth Z) env rhs); intros z z0.
348348
- split ; intros.
349349
+ assert (z0 + (z - z0) = z0 + 0) as H0 by congruence.
350350
rewrite Z.add_0_r in H0.
@@ -1781,7 +1781,7 @@ Definition leaf := @VarMap.Elt Z.
17811781

17821782
Definition coneMember := ZWitness.
17831783

1784-
Definition eval := eval_formula.
1784+
Definition eval := Feval.
17851785

17861786
#[deprecated(note="Use [prod positive nat]", since="9.0")]
17871787
Definition prod_pos_nat := prod positive nat.

0 commit comments

Comments
 (0)