Commit dd226fbe authored by Nikita Zyuzin's avatar Nikita Zyuzin

Remove old deterministic semantics files

parent c7fc112c
(**
Formalization of the Abstract Syntax Tree of a subset used in the Flover framework
**)
Require Import Coq.Reals.Reals Coq.QArith.QArith.
Require Export Flover.Commands.
Require Export Flover.Infra.ExpressionAbbrevs Flover.Infra.NatSet.
(**
Define big step semantics for the Flover language, terminating on a "returned"
result value
**)
Inductive bstep_det DeltaMap: cmd R -> env -> (expr R -> option mType) -> R -> mType -> Prop :=
| let_b_det m m' x e s E v res defVars:
eval_expr_det E defVars DeltaMap e v m ->
bstep_det DeltaMap s (updEnv x v E) defVars res m' ->
bstep_det DeltaMap (Let m x e s) E defVars res m'
| ret_b_det m e E v defVars:
eval_expr_det E defVars DeltaMap e v m ->
bstep_det DeltaMap (Ret e) E defVars v m.
Lemma bstep_eq_env_det f DeltaMap:
forall E1 E2 Gamma v m,
(forall x, E1 x = E2 x) ->
bstep_det DeltaMap f E1 Gamma v m ->
bstep_det DeltaMap f E2 Gamma v m.
Proof.
induction f; intros * eq_envs bstep_E1;
inversion bstep_E1; subst; simpl in *.
- eapply eval_eq_env_det in H7; eauto. eapply let_b_det; eauto.
eapply IHf. instantiate (1:=(updEnv n v0 E1)).
+ intros; unfold updEnv.
destruct (x=? n); auto.
+ auto.
- apply ret_b_det. eapply eval_eq_env_det; eauto.
Qed.
Lemma swap_Gamma_bstep_det f DeltaMap E vR m Gamma1 Gamma2 :
(forall n, Gamma1 n = Gamma2 n) ->
bstep_det DeltaMap f E Gamma1 vR m ->
bstep_det DeltaMap f E Gamma2 vR m.
Proof.
revert E Gamma1 Gamma2;
induction f; intros * Gamma_eq eval_f.
all: inversion eval_f; subst.
all: econstructor; try eauto.
all: eapply swap_Gamma_eval_expr_det; eauto.
Qed.
Lemma bstep_Gamma_det_det f DeltaMap:
forall E1 E2 Gamma v1 v2 m1 m2,
bstep_det DeltaMap f E1 Gamma v1 m1 ->
bstep_det DeltaMap f E2 Gamma v2 m2 ->
m1 = m2.
Proof.
induction f; intros * eval_f1 eval_f2;
inversion eval_f1; subst;
inversion eval_f2; subst; try auto.
- eapply IHf; eauto.
- eapply Gamma_det_det; eauto.
Qed.
Lemma bstep_det_functional f DeltaMap:
forall E Gamma v1 v2 m,
bstep_det DeltaMap f E Gamma v1 m ->
bstep_det DeltaMap f E Gamma v2 m ->
v1 = v2.
Proof.
induction f; intros * eval_f1 eval_f2;
inversion eval_f1; subst;
inversion eval_f2; subst; try auto.
- erewrite eval_expr_det_functional with (v1 := v) (v2 := v0) in *; eauto.
- eapply eval_expr_det_functional; eauto.
Qed.
From Coq
Require Import Reals.Reals.
From Flover.Infra
Require Import RealRationalProps RationalSimps Ltacs.
From Flover
Require Import ExpressionSemantics ssaPrgs.
From Flover.Infra
Require Export ExpressionAbbrevs.
(**
Define expression evaluation relation parametric by an "error" epsilon.
The result value exprresses float computations according to the IEEE standard,
using a perturbation of the real valued computation by (1 + delta), where
|delta| <= machine epsilon.
**)
Open Scope R_scope.
Inductive eval_expr_det (E: env)
(Gamma: expr R -> option mType)
(DeltaMap: expr R -> mType -> option R)
:(expr R) -> R -> mType -> Prop :=
| Var_load_det m x v:
Gamma (Var R x) = Some m ->
E x = Some v ->
eval_expr_det E Gamma DeltaMap (Var R x) v m
| Const_dist_det m n delta:
DeltaMap (Const m n) m = Some delta ->
Rabs delta <= mTypeToR m ->
eval_expr_det E Gamma DeltaMap (Const m n) (perturb n m delta) m
| Unop_neg_det m mN f1 v1:
Gamma (Unop Neg f1) = Some mN ->
isCompat m mN = true ->
eval_expr_det E Gamma DeltaMap f1 v1 m ->
eval_expr_det E Gamma DeltaMap (Unop Neg f1) (evalUnop Neg v1) mN
| Unop_inv_det m mN f1 v1 delta:
Gamma (Unop Inv f1) = Some mN ->
DeltaMap (Unop Inv f1) mN = Some delta ->
isCompat m mN = true ->
Rabs delta <= mTypeToR mN ->
eval_expr_det E Gamma DeltaMap f1 v1 m ->
(~ v1 = 0)%R ->
eval_expr_det E Gamma DeltaMap (Unop Inv f1) (perturb (evalUnop Inv v1) mN delta) mN
| Downcast_dist_det m m1 f1 v1 delta:
Gamma (Downcast m f1) = Some m ->
DeltaMap (Downcast m f1) m = Some delta ->
isMorePrecise m1 m = true ->
Rabs delta <= mTypeToR m ->
eval_expr_det E Gamma DeltaMap f1 v1 m1 ->
eval_expr_det E Gamma DeltaMap (Downcast m f1) (perturb v1 m delta) m
| Binop_dist_det m1 m2 op f1 f2 v1 v2 delta m:
Gamma (Binop op f1 f2) = Some m ->
DeltaMap (Binop op f1 f2) m = Some delta ->
isJoin m1 m2 m = true ->
Rabs delta <= mTypeToR m ->
eval_expr_det E Gamma DeltaMap f1 v1 m1 ->
eval_expr_det E Gamma DeltaMap f2 v2 m2 ->
((op = Div) -> (~ v2 = 0)%R) ->
eval_expr_det E Gamma DeltaMap (Binop op f1 f2) (perturb (evalBinop op v1 v2) m delta) m
| Fma_dist_det m1 m2 m3 m f1 f2 f3 v1 v2 v3 delta:
Gamma (Fma f1 f2 f3) = Some m ->
DeltaMap (Fma f1 f2 f3) m = Some delta ->
isJoin3 m1 m2 m3 m = true ->
Rabs delta <= mTypeToR m ->
eval_expr_det E Gamma DeltaMap f1 v1 m1 ->
eval_expr_det E Gamma DeltaMap f2 v2 m2 ->
eval_expr_det E Gamma DeltaMap f3 v3 m3 ->
eval_expr_det E Gamma DeltaMap (Fma f1 f2 f3) (perturb (evalFma v1 v2 v3) m delta) m.
Close Scope R_scope.
Hint Constructors eval_expr_det.
(** *)
(* Show some simpler (more general) rule lemmata *)
(* **)
Lemma Const_dist_det' DeltaMap m n delta v m' E Gamma:
Rle (Rabs delta) (mTypeToR m') ->
DeltaMap (Const m n) m = Some delta ->
v = perturb n m delta ->
m' = m ->
eval_expr_det E Gamma DeltaMap (Const m n) v m'.
Proof.
intros; subst; auto.
Qed.
Hint Resolve Const_dist_det'.
Lemma Unop_neg_det' DeltaMap m mN f1 v1 v m' E Gamma:
eval_expr_det E Gamma DeltaMap f1 v1 m ->
v = evalUnop Neg v1 ->
Gamma (Unop Neg f1) = Some mN ->
isCompat m mN = true ->
m' = mN ->
eval_expr_det E Gamma DeltaMap (Unop Neg f1) v m'.
Proof.
intros; subst; eauto.
Qed.
Hint Resolve Unop_neg_det'.
Lemma Unop_inv_det' DeltaMap m mN f1 v1 delta v m' E Gamma:
Rle (Rabs delta) (mTypeToR m') ->
eval_expr_det E Gamma DeltaMap f1 v1 m ->
DeltaMap (Unop Inv f1) m' = Some delta ->
(~ v1 = 0)%R ->
v = perturb (evalUnop Inv v1) mN delta ->
Gamma (Unop Inv f1) = Some mN ->
isCompat m mN = true ->
m' = mN ->
eval_expr_det E Gamma DeltaMap (Unop Inv f1) v m'.
Proof.
intros; subst; eauto.
Qed.
Hint Resolve Unop_inv_det'.
Lemma Downcast_dist_det' DeltaMap m m1 f1 v1 delta v m' E Gamma:
isMorePrecise m1 m = true ->
Rle (Rabs delta) (mTypeToR m') ->
eval_expr_det E Gamma DeltaMap f1 v1 m1 ->
DeltaMap (Downcast m f1) m' = Some delta ->
v = (perturb v1 m delta) ->
Gamma (Downcast m f1) = Some m ->
m' = m ->
eval_expr_det E Gamma DeltaMap (Downcast m f1) v m'.
Proof.
intros; subst; eauto.
Qed.
Hint Resolve Downcast_dist_det'.
Lemma Binop_dist_det' DeltaMap m1 m2 op f1 f2 v1 v2 delta v m m' E Gamma:
Rle (Rabs delta) (mTypeToR m') ->
eval_expr_det E Gamma DeltaMap f1 v1 m1 ->
eval_expr_det E Gamma DeltaMap f2 v2 m2 ->
DeltaMap (Binop op f1 f2) m' = Some delta ->
((op = Div) -> (~ v2 = 0)%R) ->
v = perturb (evalBinop op v1 v2) m' delta ->
Gamma (Binop op f1 f2) = Some m ->
isJoin m1 m2 m = true ->
m = m' ->
eval_expr_det E Gamma DeltaMap (Binop op f1 f2) v m'.
Proof.
intros; subst; eauto.
Qed.
Hint Resolve Binop_dist_det'.
Lemma Fma_dist_det' DeltaMap m1 m2 m3 f1 f2 f3 v1 v2 v3 delta v m' E Gamma m:
Rle (Rabs delta) (mTypeToR m') ->
eval_expr_det E Gamma DeltaMap f1 v1 m1 ->
eval_expr_det E Gamma DeltaMap f2 v2 m2 ->
eval_expr_det E Gamma DeltaMap f3 v3 m3 ->
DeltaMap (Fma f1 f2 f3) m' = Some delta ->
v = perturb (evalFma v1 v2 v3) m' delta ->
Gamma (Fma f1 f2 f3) = Some m ->
isJoin3 m1 m2 m3 m = true ->
m = m' ->
eval_expr_det E Gamma DeltaMap (Fma f1 f2 f3) v m'.
Proof.
intros; subst; eauto.
Qed.
Hint Resolve Fma_dist_det'.
Lemma Gamma_det_det e E1 E2 Gamma DeltaMap DeltaMap' v1 v2 m1 m2:
eval_expr_det E1 Gamma DeltaMap e v1 m1 ->
eval_expr_det E2 Gamma DeltaMap' e v2 m2 ->
m1 = m2.
Proof.
induction e; intros * eval_e1 eval_e2;
inversion eval_e1; subst;
inversion eval_e2; subst; try auto;
match goal with
| [H1: Gamma ?e = Some ?m1, H2: Gamma ?e = Some ?m2 |- _ ] =>
rewrite H1 in H2; inversion H2; subst
end;
auto.
Qed.
Lemma toRTMap_eval_REAL_det f:
forall v E Gamma DeltaMap m,
eval_expr_det E (toRTMap Gamma) DeltaMap (toREval f) v m -> m = REAL.
Proof.
induction f; intros * eval_f; inversion eval_f; subst.
repeat
match goal with
| H: context[toRTMap _ _] |- _ => unfold toRTMap in H
| H: context[match ?Gamma ?v with | _ => _ end ] |- _ => destruct (Gamma v) eqn:?
| H: Some ?m1 = Some ?m2 |- _ => inversion H; try auto
| H: None = Some ?m |- _ => inversion H
end; try auto.
- auto.
- rewrite (IHf _ _ _ _ _ H5) in H2.
unfold isCompat in H2.
destruct m; type_conv; subst; try congruence; auto.
- rewrite (IHf _ _ _ _ _ H5) in H3.
unfold isCompat in H3.
destruct m; type_conv; subst; try congruence; auto.
- rewrite (IHf1 _ _ _ _ _ H6) in H4.
rewrite (IHf2 _ _ _ _ _ H9) in H4.
unfold isJoin in H4; simpl in H4.
destruct m; try congruence; auto.
- rewrite (IHf1 _ _ _ _ _ H6) in H4.
rewrite (IHf2 _ _ _ _ _ H9) in H4.
rewrite (IHf3 _ _ _ _ _ H10) in H4.
unfold isJoin3 in H4; simpl in H4.
destruct m; try congruence; auto.
- auto.
Qed.
(**
Evaluation with 0 as machine epsilon is deterministic
**)
Lemma meps_0_deterministic_det (f:expr R) (E:env) Gamma DeltaMap DeltaMap':
forall v1 v2,
eval_expr_det E (toRTMap Gamma) DeltaMap (toREval f) v1 REAL ->
eval_expr_det E (toRTMap Gamma) DeltaMap' (toREval f) v2 REAL ->
v1 = v2.
Proof.
induction f;
intros v1 v2 ev1 ev2.
- inversion ev1; inversion ev2; subst.
rewrite H1 in H6.
inversion H6; auto.
- inversion ev1; inversion ev2; subst.
simpl in *; subst; auto.
- inversion ev1; inversion ev2; subst; try congruence.
+ erewrite (IHf v0 v3); [ auto | |];
destruct m, m0; cbn in *; eauto; congruence.
+ cbn in *.
Flover_compute; erewrite (IHf v0 v3); [auto | | ];
destruct m, m0; cbn in *; eauto; congruence.
- inversion ev1; inversion ev2; subst.
assert (m0 = REAL) by (eapply toRTMap_eval_REAL_det; eauto).
assert (m3 = REAL) by (eapply toRTMap_eval_REAL_det; eauto).
assert (m1 = REAL) by (eapply toRTMap_eval_REAL_det; eauto).
assert (m2 = REAL) by (eapply toRTMap_eval_REAL_det; eauto).
subst.
erewrite (IHf1 v0 v4); eauto.
erewrite (IHf2 v3 v5); eauto.
- inversion ev1; inversion ev2; subst.
assert (m0 = REAL) by (eapply toRTMap_eval_REAL_det; eauto).
assert (m1 = REAL) by (eapply toRTMap_eval_REAL_det; eauto).
assert (m2 = REAL) by (eapply toRTMap_eval_REAL_det; eauto).
assert (m3 = REAL) by (eapply toRTMap_eval_REAL_det; eauto).
assert (m4 = REAL) by (eapply toRTMap_eval_REAL_det; eauto).
assert (m5 = REAL) by (eapply toRTMap_eval_REAL_det; eauto).
subst.
erewrite (IHf1 v0 v5); eauto.
erewrite (IHf2 v3 v6); eauto.
erewrite (IHf3 v4 v7); eauto.
- inversion ev1; inversion ev2; subst.
apply REAL_least_precision in H3;
apply REAL_least_precision in H11; subst.
erewrite (IHf v0 v3); eauto.
Qed.
(**
Helping lemmas. Needed in soundness proof.
For each evaluation of using an arbitrary epsilon, we can replace it by
evaluating the subexprressions and then binding the result values to different
variables in the Environment.
**)
Lemma binary_unfolding_det b f1 f2 E v1 v2 m1 m2 m DeltaMap Gamma delta:
(b = Div -> ~(v2 = 0 )%R) ->
(Rabs delta <= mTypeToR m)%R ->
eval_expr_det E Gamma DeltaMap f1 v1 m1 ->
eval_expr_det E Gamma DeltaMap f2 v2 m2 ->
eval_expr_det E Gamma DeltaMap (Binop b f1 f2) (perturb (evalBinop b v1 v2) m delta) m ->
eval_expr_det (updEnv 2 v2 (updEnv 1 v1 emptyEnv))
(updDefVars (Binop b (Var R 1) (Var R 2)) m
(updDefVars (Var R 2) m2 (updDefVars (Var R 1) m1 Gamma)))
(fun x m => if R_orderedExps.eq_dec x (Binop b (Var R 1) (Var R 2))
then Some delta else None)
(Binop b (Var R 1) (Var R 2)) (perturb (evalBinop b v1 v2) m delta) m.
Proof.
intros no_div_zero err_v eval_f1 eval_f2 eval_float.
inversion eval_float; subst.
rewrite H2 in *.
repeat
(match goal with
| [H1: eval_expr_det ?E ?Gamma ?DeltaMap1 ?f ?v1 ?m1,
H2: eval_expr_det ?E ?Gamma ?DeltaMap1' ?f ?v2 ?m2 |- _] =>
assert (m1 = m2)
by (eapply Gamma_det_det; eauto);
revert H1 H2
end); intros; subst.
eapply Binop_dist_det' with (v1:=v1) (v2:=v2) (delta:=delta); eauto.
- eapply Var_load_det; eauto.
- eapply Var_load_det; eauto.
- destruct R_orderedExps.eq_dec as [?|H]; auto.
exfalso; apply H; apply R_orderedExps.eq_refl.
- unfold updDefVars.
unfold R_orderedExps.compare; rewrite R_orderedExps.exprCompare_refl; auto.
Qed.
Lemma fma_unfolding_det f1 f2 f3 E v1 v2 v3 m1 m2 m3 m DeltaMap Gamma delta:
(Rabs delta <= mTypeToR m)%R ->
eval_expr_det E Gamma DeltaMap f1 v1 m1 ->
eval_expr_det E Gamma DeltaMap f2 v2 m2 ->
eval_expr_det E Gamma DeltaMap f3 v3 m3 ->
eval_expr_det E Gamma DeltaMap (Fma f1 f2 f3) (perturb (evalFma v1 v2 v3) m delta) m ->
eval_expr_det (updEnv 3 v3 (updEnv 2 v2 (updEnv 1 v1 emptyEnv)))
(updDefVars (Fma (Var R 1) (Var R 2) (Var R 3) ) m
(updDefVars (Var R 3) m3 (updDefVars (Var R 2) m2
(updDefVars (Var R 1) m1 Gamma))))
(fun x m => if R_orderedExps.eq_dec x (Fma (Var R 1) (Var R 2) (Var R 3))
then Some delta else None)
(Fma (Var R 1) (Var R 2) (Var R 3)) (perturb (evalFma v1 v2 v3) m delta) m.
Proof.
intros err_v eval_f1 eval_f2 eval_f3 eval_float.
inversion eval_float; subst.
repeat
(match goal with
| [H1: eval_expr_det ?E ?Gamma ?DeltaMap1 ?f ?v1 ?m1,
H2: eval_expr_det ?E ?Gamma ?DeltaMap1' ?f ?v2 ?m2 |- _] =>
assert (m1 = m2)
by (eapply Gamma_det_det; eauto);
revert H1 H2
end).
intros; subst.
rewrite H2.
eapply Fma_dist_det' with (v1:=v1) (v2:=v2) (v3:=v3) (delta:=delta); try eauto.
- eapply Var_load_det; eauto.
- eapply Var_load_det; eauto.
- eapply Var_load_det; eauto.
- trivial.
Qed.
Lemma eval_eq_env_det e:
forall E1 E2 Gamma DeltaMap v m,
(forall x, E1 x = E2 x) ->
eval_expr_det E1 DeltaMap Gamma e v m ->
eval_expr_det E2 DeltaMap Gamma e v m.
Proof.
induction e; intros;
(match_pat (eval_expr_det _ _ _ _ _ _) (fun H => inversion H; subst; simpl in H));
try eauto.
eapply Var_load_det; auto.
rewrite <- (H n); auto.
Qed.
Lemma eval_expr_det_ignore_bind e:
forall x v m Gamma E DeltaMap,
eval_expr_det E Gamma DeltaMap e v m ->
~ NatSet.In x (usedVars e) ->
forall v_new,
eval_expr_det (updEnv x v_new E) Gamma DeltaMap e v m.
Proof.
induction e; intros * eval_e no_usedVar *; cbn in *;
inversion eval_e; subst; try eauto.
- assert (n <> x).
{ hnf. intros. subst. apply no_usedVar; set_tac. }
rewrite <- Nat.eqb_neq in H.
eapply Var_load_det.
+ unfold updDefVars.
cbn.
apply beq_nat_false in H.
destruct (n ?= x)%nat eqn:?; try auto.
+ unfold updEnv.
rewrite H; auto.
- eapply Binop_dist_det'; eauto;
[ eapply IHe1 | eapply IHe2];
eauto;
hnf; intros; eapply no_usedVar;
set_tac.
- eapply Fma_dist_det'; eauto;
[eapply IHe1 | eapply IHe2 | eapply IHe3];
eauto;
hnf; intros; eapply no_usedVar;
set_tac.
Qed.
Lemma eval_expr_det_ignore_bind2 e:
forall x v v_new m Gamma E DeltaMap,
eval_expr_det (updEnv x v_new E) Gamma DeltaMap e v m ->
~ NatSet.In x (usedVars e) ->
eval_expr_det E Gamma DeltaMap e v m.
Proof.
induction e; intros * eval_e no_usedVar *; cbn in *;
inversion eval_e; subst; try eauto.
- assert (n <> x).
{ hnf. intros. subst. apply no_usedVar; set_tac. }
rewrite <- Nat.eqb_neq in H.
eapply Var_load_det.
+ unfold updDefVars.
cbn.
apply beq_nat_false in H.
destruct (n ?= x)%nat eqn:?; try auto.
+ unfold updEnv.
rewrite <- H1.
unfold updEnv.
now rewrite H.
- eapply Binop_dist_det'; eauto;
[ eapply IHe1 | eapply IHe2];
eauto;
hnf; intros; eapply no_usedVar;
set_tac.
- eapply Fma_dist_det'; eauto;
[eapply IHe1 | eapply IHe2 | eapply IHe3];
eauto;
hnf; intros; eapply no_usedVar;
set_tac.
Qed.
Lemma swap_Gamma_eval_expr_det e E vR m Gamma1 Gamma2 DeltaMap:
(forall e, Gamma1 e = Gamma2 e) ->
eval_expr_det E Gamma1 DeltaMap e vR m ->
eval_expr_det E Gamma2 DeltaMap e vR m.
Proof.
revert E vR Gamma1 Gamma2 DeltaMap m;
induction e; intros * Gamma_eq eval_e;
inversion eval_e; subst; simpl in *;
[ eapply Var_load_det
| eapply Const_dist_det'
| eapply Unop_neg_det'
| eapply Unop_inv_det'
| eapply Binop_dist_det'
| eapply Fma_dist_det'
| eapply Downcast_dist_det' ]; try eauto;
rewrite <- Gamma_eq; auto.
Qed.
Lemma eval_expr_det_functional E Gamma DeltaMap e v1 v2 m:
eval_expr_det E Gamma DeltaMap e v1 m ->
eval_expr_det E Gamma DeltaMap e v2 m ->
v1 = v2.
Proof.
revert v1 v2 m.
induction e; intros v1 v2 m__FP Heval1 Heval2.
- inversion Heval1; inversion Heval2; subst.
now replace v1 with v2 by congruence.
- inversion Heval1; inversion Heval2; subst.
now replace delta with delta0 by congruence.
- destruct u; inversion Heval1; inversion Heval2; subst.
+ f_equal; eapply IHe; eauto.
erewrite Gamma_det_det; eauto.
+ replace delta with delta0 by congruence.
f_equal; f_equal; eapply IHe; eauto.
erewrite Gamma_det_det; eauto.
- inversion Heval1; inversion Heval2; subst.
replace delta with delta0 by congruence.
f_equal; f_equal; [eapply IHe1 | eapply IHe2]; eauto;
erewrite Gamma_det_det; eauto.
- inversion Heval1; inversion Heval2; subst.
replace delta with delta0 by congruence.
f_equal; f_equal; [eapply IHe1 | eapply IHe2 | eapply IHe3]; eauto;
erewrite Gamma_det_det; eauto.
- inversion Heval1; inversion Heval2; subst.
replace delta with delta0 by congruence.
f_equal; f_equal; eapply IHe; eauto;
erewrite Gamma_det_det; eauto.
Qed.
Theorem eval_det_eval_nondet E Gamma DeltaMap e v m:
eval_expr_det E Gamma DeltaMap e v m ->
eval_expr E Gamma e v m.
Proof.
revert E v Gamma DeltaMap m;
induction e; intros * Hdet;
inversion Hdet; subst; simpl in *;
[ eapply Var_load
| eapply Const_dist'
| eapply Unop_neg'
| eapply Unop_inv'
| eapply Binop_dist'
| eapply Fma_dist'
| eapply Downcast_dist' ]; try eauto;
rewrite <- Gamma_eq; auto.
Qed.
Lemma real_eval_det_ignores_delta_map (f:expr R) (E:env) Gamma:
forall v1 DeltaMap,
eval_expr_det E (toRTMap Gamma) DeltaMap (toREval f) v1 REAL ->
eval_expr_det E (toRTMap Gamma) DeltaMapR (toREval f) v1 REAL.
Proof.
induction f;
intros v1 DeltaMap ev1.
- inversion ev1; subst.
constructor; auto.
- inversion ev1; subst.
simpl in *; subst; auto.
eapply Const_dist_det'; eauto.
apply Rabs_0_impl_eq in H3; f_equal; now symmetry.
- inversion ev1; subst; try congruence.
+ unfold isCompat in H2; destruct m; cbn in H2; try congruence; clear H2.
specialize (IHf _ _ H5).
eapply Unop_neg_det'; eauto.
+ unfold isCompat in H3; destruct m; cbn in H3; try congruence; clear H3.
specialize (IHf _ _ H5).
eapply Unop_inv_det'; eauto.
apply Rabs_0_impl_eq in H4; f_equal; now symmetry.
- inversion ev1; subst.
assert (m1 = REAL) by (eapply toRTMap_eval_REAL_det; eauto).
assert (m2 = REAL) by (eapply toRTMap_eval_REAL_det; eauto).
subst.
specialize (IHf1 _ _ H6).
specialize (IHf2 _ _ H9).
eapply Binop_dist_det'; eauto.
apply Rabs_0_impl_eq in H5; f_equal; now symmetry.
- inversion ev1; subst.
assert (m1 = REAL) by (eapply toRTMap_eval_REAL_det; eauto).
assert (m2 = REAL) by (eapply toRTMap_eval_REAL_det; eauto).
assert (m3 = REAL) by (eapply toRTMap_eval_REAL_det; eauto).
subst.
specialize (IHf1 _ _ H6).
specialize (IHf2 _ _ H9).
specialize (IHf3 _ _ H10).
eapply Fma_dist_det'; eauto.
apply Rabs_0_impl_eq in H5; f_equal; now symmetry.
- inversion ev1; subst.
apply REAL_least_precision in H3; subst.
specialize (IHf _ _ H6).
eapply Downcast_dist_det'; eauto.
+ trivial.
+ apply Rabs_0_impl_eq in H4; f_equal; now symmetry.
Qed.
Theorem eval_expr_REAL_det_nondet E Gamma e v:
eval_expr_det E (toRTMap Gamma) DeltaMapR (toREval e) v REAL <->
eval_expr E (toRTMap Gamma) (toREval e) v REAL.
Proof.
split; [eapply eval_det_eval_nondet; eauto|].
revert v.
induction e; intros * Heval.
- inversion Heval; subst.
constructor; auto.