Commit 55c0ef90 authored by Nikita Zyuzin's avatar Nikita Zyuzin

[WIP] Change FloVer to use only deterministic semantics

parent 4614ca0c
......@@ -491,11 +491,11 @@ Lemma validAffineBounds_validRanges e (A: analysisResult) E Gamma:
(exists map af vR aiv aerr,
FloverMap.find e A = Some (aiv, aerr) /\
isSupersetIntv (toIntv af) aiv = true /\
eval_expr E (toRTMap (toRExpMap Gamma)) (toREval (toRExp e)) vR REAL /\
eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR (toREval (toRExp e)) vR REAL /\
af_evals (afQ2R af) vR map) ->
exists iv err vR,
FloverMap.find e A = Some (iv, err) /\
eval_expr E (toRTMap (toRExpMap Gamma)) (toREval (toRExp e)) vR REAL /\
eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR (toREval (toRExp e)) vR REAL /\
(Q2R (fst iv) <= vR <= Q2R (snd iv))%R.
Proof.
intros sound_affine.
......@@ -524,7 +524,7 @@ Definition checked_expressions (A: analysisResult) E Gamma fVars dVars e iexpmap
FloverMap.find e iexpmap = Some af /\
fresh inoise af /\
(forall n, (n >= inoise)%nat -> map1 n = None) /\
eval_expr E (toRTMap (toRExpMap Gamma)) (toREval (toRExp e)) vR REAL /\
eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR (toREval (toRExp e)) vR REAL /\
validRanges e A E (toRTMap (toRExpMap Gamma)) /\
af_evals (afQ2R af) vR map1.
......@@ -685,7 +685,7 @@ Lemma validAffineBounds_sound_var A P E Gamma fVars dVars n:
affine_dVars_range_valid dVars E A inoise iexpmap map1 ->
NatSet.Subset (usedVars (Var Q n) -- dVars) fVars ->
fVars_P_sound fVars E P ->
validTypes (Var Q n) Gamma ->
validTypes (Var Q n) Gamma DeltaMapR ->
exists (map2 : noise_mapping) (af : affine_form Q) (vR : R) (aiv : intv)
(aerr : error),
contained_map map1 map2 /\
......@@ -696,7 +696,7 @@ Lemma validAffineBounds_sound_var A P E Gamma fVars dVars n:
fresh noise af /\
(forall n0 : nat, (n0 >= noise)%nat -> map2 n0 = None) /\
(noise >= inoise)%nat /\
eval_expr E (toRTMap (toRExpMap Gamma)) (toREval (toRExp (Var Q n))) vR REAL /\
eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR (toREval (toRExp (Var Q n))) vR REAL /\
validRanges (Var Q n) A E (toRTMap (toRExpMap Gamma)) /\
af_evals (afQ2R af) vR map2 /\
(forall e : FloverMap.key,
......@@ -745,7 +745,8 @@ Proof.
specialize (fVarsSound H') as [vR [eMap interval_containment]].
assert (FloverMap.find (Var Q n) (FloverMap.add (Var Q n) (fromIntv (P n) inoise) iexpmap) = Some (fromIntv (P n) inoise)) as Hfind
by (rewrite FloverMapFacts.P.F.add_eq_o; try auto; apply Q_orderedExps.exprCompare_refl).
assert (eval_expr E (toRTMap (toRExpMap Gamma)) (toREval (toRExp (Var Q n))) vR REAL) as Heeval.
assert (eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR
(toREval (toRExp (Var Q n))) vR REAL) as Heeval.
{ eapply Var_load; try eauto.
unfold toRTMap.
assert (exists m, toRExpMap Gamma (Var R n) = Some m) as t_var.
......@@ -873,7 +874,7 @@ Lemma validAffineBounds_sound_const A P E Gamma fVars dVars m v:
affine_dVars_range_valid dVars E A inoise iexpmap map1 ->
NatSet.Subset (usedVars (Const m v) -- dVars) fVars ->
fVars_P_sound fVars E P ->
validTypes (Const m v) Gamma ->
validTypes (Const m v) Gamma DeltaMapR ->
exists (map2 : noise_mapping) (af : affine_form Q) (vR : R) (aiv : intv)
(aerr : error),
contained_map map1 map2 /\
......@@ -884,7 +885,7 @@ Lemma validAffineBounds_sound_const A P E Gamma fVars dVars m v:
fresh noise af /\
(forall n : nat, (n >= noise)%nat -> map2 n = None) /\
(noise >= inoise)%nat /\
eval_expr E (toRTMap (toRExpMap Gamma)) (toREval (toRExp (Const m v))) vR REAL /\
eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR (toREval (toRExp (Const m v))) vR REAL /\
validRanges (Const m v) A E (toRTMap (toRExpMap Gamma)) /\
af_evals (afQ2R af) vR map2 /\
(forall e : FloverMap.key,
......@@ -949,9 +950,9 @@ Proof.
assert (FloverMap.find (elt:=affine_form Q) (Const m v) (FloverMap.add (Const m v) (fromIntv (v, v) noise) iexpmap) = Some (fromIntv (v, v) noise))
by (rewrite FloverMapFacts.P.F.add_eq_o; try auto;
apply Q_orderedExps.exprCompare_refl).
assert (eval_expr E (toRTMap (toRExpMap Gamma)) (toREval (toRExp (Const m v)))
assert (eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR (toREval (toRExp (Const m v)))
(perturb (Q2R v) REAL 0) REAL)
by (constructor; simpl; rewrite Rabs_R0; lra).
by (unfold DeltaMapR; constructor; simpl; auto; rewrite Rabs_R0; lra).
exists map1, (fromIntv (v, v) noise), (perturb (Q2R v) REAL 0), i, e.
repeat split; auto.
- reflexivity.
......@@ -997,7 +998,7 @@ Definition validAffineBounds_IH_e A P E Gamma fVars dVars e :=
affine_dVars_range_valid dVars E A inoise iexpmap map1 ->
NatSet.Subset (usedVars e -- dVars) fVars ->
fVars_P_sound fVars E P ->
validTypes e Gamma ->
validTypes e Gamma DeltaMapR ->
exists (map2 : noise_mapping) (af : affine_form Q) (vR : R) (aiv : intv)
(aerr : error),
contained_map map1 map2 /\
......@@ -1008,7 +1009,7 @@ Definition validAffineBounds_IH_e A P E Gamma fVars dVars e :=
fresh noise af /\
(forall n : nat, (n >= noise)%nat -> map2 n = None) /\
(noise >= inoise)%nat /\
eval_expr E (toRTMap (toRExpMap Gamma)) (toREval (toRExp e)) vR REAL /\
eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR (toREval (toRExp e)) vR REAL /\
validRanges e A E (toRTMap (toRExpMap Gamma)) /\
af_evals (afQ2R af) vR map2 /\
(forall e : FloverMap.key,
......@@ -1029,7 +1030,7 @@ Lemma validAffineBounds_sound_unop A P E Gamma fVars dVars u e:
affine_dVars_range_valid dVars E A inoise iexpmap map1 ->
NatSet.Subset (usedVars (Unop u e) -- dVars) fVars ->
fVars_P_sound fVars E P ->
validTypes (Unop u e) Gamma ->
validTypes (Unop u e) Gamma DeltaMapR ->
exists (map2 : noise_mapping) (af : affine_form Q) (vR : R) (aiv : intv)
(aerr : error),
contained_map map1 map2 /\
......@@ -1040,7 +1041,7 @@ Lemma validAffineBounds_sound_unop A P E Gamma fVars dVars u e:
fresh noise af /\
(forall n : nat, (n >= noise)%nat -> map2 n = None) /\
(noise >= inoise)%nat /\
eval_expr E (toRTMap (toRExpMap Gamma)) (toREval (toRExp (Unop u e))) vR REAL /\
eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR (toREval (toRExp (Unop u e))) vR REAL /\
validRanges (Unop u e) A E (toRTMap (toRExpMap Gamma)) /\
af_evals (afQ2R af) vR map2 /\
(forall e0 : FloverMap.key,
......@@ -1080,9 +1081,10 @@ Proof.
rewrite plus_0_r.
assert (fresh subnoise (AffineArithQ.negate_aff af)) by
(unfold AffineArithQ.negate_aff; now apply AffineArithQ.mult_aff_const_fresh_compat).
assert (eval_expr E (toRTMap (toRExpMap Gamma)) (toREval (toRExp (Unop Neg e))) (- vR) REAL)
assert (eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR
(toREval (toRExp (Unop Neg e))) (- vR) REAL)
as eval_real.
{ eapply Unop_neg'; try eauto.
{eapply Unop_neg'; try eauto.
destruct varsTyped as (mt & find_t & ? & valid_exec).
- eapply toRExpMap_some in find_t; eauto.
- auto. }
......@@ -1154,7 +1156,8 @@ Proof.
by (rewrite FloverMapFacts.P.F.add_eq_o; try auto; apply Q_orderedExps.exprCompare_refl).
exists (updMap ihmap subnoise qInv), (AffineArithQ.inverse_aff af subnoise),
(perturb (evalUnop Inv vR) REAL 0)%R, aiv, aerr.
assert (eval_expr E (toRTMap (toRExpMap Gamma)) (toREval (toRExp (Unop Inv e))) (/ vR) REAL)
assert (eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR
(toREval (toRExp (Unop Inv e))) (/ vR) REAL)
as eval_real.
{ eapply Unop_inv' with (delta:=0%R); try eauto.
- rewrite Rabs_R0; cbn; lra.
......@@ -1218,7 +1221,7 @@ Lemma validAffineBounds_sound_binop A P E Gamma fVars dVars b e1 e2:
affine_dVars_range_valid dVars E A inoise iexpmap map1 ->
NatSet.Subset (usedVars (Binop b e1 e2) -- dVars) fVars ->
fVars_P_sound fVars E P ->
validTypes (Binop b e1 e2) Gamma ->
validTypes (Binop b e1 e2) Gamma DeltaMapR ->
exists (map2 : noise_mapping) (af : affine_form Q) (vR : R) (aiv : intv)
(aerr : error),
contained_map map1 map2 /\
......@@ -1229,7 +1232,7 @@ Lemma validAffineBounds_sound_binop A P E Gamma fVars dVars b e1 e2:
fresh noise af /\
(forall n : nat, (n >= noise)%nat -> map2 n = None) /\
(noise >= inoise)%nat /\
eval_expr E (toRTMap (toRExpMap Gamma)) (toREval (toRExp (Binop b e1 e2))) vR REAL /\
eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR (toREval (toRExp (Binop b e1 e2))) vR REAL /\
validRanges (Binop b e1 e2) A E (toRTMap (toRExpMap Gamma)) /\
af_evals (afQ2R af) vR map2 /\
(forall e : FloverMap.key,
......@@ -1312,7 +1315,7 @@ Proof.
apply plus_aff_sound; auto.
eauto using af_evals_map_extension.
}
assert (eval_expr E (toRTMap (toRExpMap Gamma)) (toREval (toRExp (Binop Plus e1 e2)))
assert (eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR (toREval (toRExp (Binop Plus e1 e2)))
(perturb (evalBinop Plus vR1 vR2) REAL 0) REAL).
{ eapply Binop_dist' with (delta := 0%R); eauto; try congruence.
- rewrite Rabs_R0; cbn; lra.
......@@ -1402,7 +1405,7 @@ Proof.
unfold AffineArithQ.negate_aff.
now apply AffineArithQ.mult_aff_const_fresh_compat.
}
assert (eval_expr E (toRTMap (toRExpMap Gamma))
assert (eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR
(toREval (toRExp (Binop Sub e1 e2)))
(perturb (evalBinop Sub vR1 vR2) REAL 0) REAL).
{ eapply Binop_dist' with (delta := 0%R); eauto; try congruence.
......@@ -1502,7 +1505,7 @@ Proof.
apply AffineArithQ.mult_aff_aux_fresh_compat;
apply fresh_inc; now rewrite afQ2R_fresh.
}
assert (eval_expr E (toRTMap (toRExpMap Gamma))
assert (eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR
(toREval (toRExp (Binop Mult e1 e2)))
(perturb (evalBinop Mult vR1 vR2) REAL 0) REAL).
{ eapply Binop_dist' with (delta := 0%R); eauto; try congruence.
......@@ -1662,7 +1665,7 @@ Proof.
apply Hsubvalidmap2.
lia.
}
assert (eval_expr E (toRTMap (toRExpMap Gamma))
assert (eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR
(toREval (toRExp (Binop Div e1 e2)))
(perturb (evalBinop Div vR1 vR2) REAL 0) REAL).
{ eapply Binop_dist' with (delta := 0%R); eauto; try congruence.
......@@ -1794,7 +1797,7 @@ Lemma validAffineBounds_sound_fma A P E Gamma fVars dVars e1 e2 e3:
affine_dVars_range_valid dVars E A inoise iexpmap map1 ->
NatSet.Subset (usedVars (Fma e1 e2 e3) -- dVars) fVars ->
fVars_P_sound fVars E P ->
validTypes (Fma e1 e2 e3) Gamma ->
validTypes (Fma e1 e2 e3) Gamma DeltaMapR ->
exists (map2 : noise_mapping) (af : affine_form Q) (vR : R) (aiv : intv)
(aerr : error),
contained_map map1 map2 /\
......@@ -1805,7 +1808,7 @@ Lemma validAffineBounds_sound_fma A P E Gamma fVars dVars e1 e2 e3:
fresh noise af /\
(forall n : nat, (n >= noise)%nat -> map2 n = None) /\
(noise >= inoise)%nat /\
eval_expr E (toRTMap (toRExpMap Gamma)) (toREval (toRExp (Fma e1 e2 e3))) vR REAL /\
eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR (toREval (toRExp (Fma e1 e2 e3))) vR REAL /\
validRanges (Fma e1 e2 e3) A E (toRTMap (toRExpMap Gamma)) /\
af_evals (afQ2R af) vR map2 /\
(forall e : FloverMap.key,
......@@ -1951,12 +1954,13 @@ Proof.
apply Hsubmapvalid3.
lia.
}
assert (eval_expr E (toRTMap (toRExpMap Gamma))
assert (eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR
(toREval (toRExp (Fma e1 e2 e3)))
(perturb (evalFma vR1 vR2 vR3)REAL 0) REAL).
{ eapply Fma_dist'; eauto; try congruence.
- rewrite Rabs_R0; cbn; lra.
- auto.
- auto.
- auto. }
assert (af_evals (afQ2R (AffineArithQ.plus_aff af1 (AffineArithQ.mult_aff af2 af3 subnoise3))) (perturb (evalFma vR1 vR2 vR3) REAL 0) (updMap ihmap3 subnoise3 qMult)).
{
......@@ -2082,7 +2086,7 @@ Lemma validAffineBounds_sound_downcast A P E Gamma fVars dVars m e:
affine_dVars_range_valid dVars E A inoise iexpmap map1 ->
NatSet.Subset (usedVars (Downcast m e) -- dVars) fVars ->
fVars_P_sound fVars E P ->
validTypes (Downcast m e) Gamma ->
validTypes (Downcast m e) Gamma DeltaMapR ->
exists (map2 : noise_mapping) (af : affine_form Q) (vR : R) (aiv : intv)
(aerr : error),
contained_map map1 map2 /\
......@@ -2093,7 +2097,7 @@ Lemma validAffineBounds_sound_downcast A P E Gamma fVars dVars m e:
fresh noise af /\
(forall n : nat, (n >= noise)%nat -> map2 n = None) /\
(noise >= inoise)%nat /\
eval_expr E (toRTMap (toRExpMap Gamma)) (toREval (toRExp (Downcast m e))) vR REAL /\
eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR (toREval (toRExp (Downcast m e))) vR REAL /\
validRanges (Downcast m e) A E (toRTMap (toRExpMap Gamma)) /\
af_evals (afQ2R af) vR map2 /\
(forall e0 : FloverMap.key,
......@@ -2191,7 +2195,7 @@ Lemma validAffineBounds_sound (e: expr Q) (A: analysisResult) (P: precond)
affine_dVars_range_valid dVars E A inoise iexpmap map1 ->
NatSet.Subset (NatSet.diff (Expressions.usedVars e) dVars) fVars ->
fVars_P_sound fVars E P ->
validTypes e Gamma ->
validTypes e Gamma DeltaMapR ->
exists map2 af vR aiv aerr,
contained_map map1 map2 /\
contained_flover_map iexpmap exprAfs /\
......@@ -2201,7 +2205,7 @@ Lemma validAffineBounds_sound (e: expr Q) (A: analysisResult) (P: precond)
fresh noise af /\
(forall n, (n >= noise)%nat -> map2 n = None) /\
(noise >= inoise)%nat /\
eval_expr E (toRTMap (toRExpMap Gamma)) (toREval (toRExp e)) vR REAL /\
eval_expr E (toRTMap (toRExpMap Gamma)) DeltaMapR (toREval (toRExp e)) vR REAL /\
validRanges e A E (toRTMap (toRExpMap Gamma)) /\
af_evals (afQ2R af) vR map2 /\
(forall e, FloverMap.find e iexpmap = None ->
......@@ -2245,7 +2249,7 @@ Lemma validAffineBoundsCmd_sound (c: cmd Q) (A: analysisResult) (P: precond)
affine_dVars_range_valid dVars E A inoise iexpmap map1 ->
NatSet.Subset (NatSet.diff (Commands.freeVars c) dVars) fVars ->
fVars_P_sound fVars E P ->
validTypesCmd c Gamma ->
validTypesCmd c Gamma DeltaMapR ->
exists map2 af vR aiv aerr,
contained_map map1 map2 /\
contained_flover_map iexpmap exprAfs /\
......@@ -2255,7 +2259,7 @@ Lemma validAffineBoundsCmd_sound (c: cmd Q) (A: analysisResult) (P: precond)
fresh noise af /\
(forall n, (n >= noise)%nat -> map2 n = None) /\
(noise >= inoise)%nat /\
bstep (toREvalCmd (toRCmd c)) E (toRTMap (toRExpMap Gamma)) vR REAL /\
bstep (toREvalCmd (toRCmd c)) E (toRTMap (toRExpMap Gamma)) DeltaMapR vR REAL /\
validRangesCmd c A E (toRTMap (toRExpMap Gamma)) /\
af_evals (afQ2R af) vR map2 /\
(forall e, FloverMap.find e iexpmap = None ->
......
......@@ -77,11 +77,17 @@ Proof.
destruct valid_single as [iv_e [ err_e [vR [ map_e [eval_real real_bounds_e]]]]].
destruct iv_e as [elo ehi].
exists Gamma; intros approxE1E2.
edestruct (RoundoffErrorValidator_sound e H approxE1E2 H1 eval_real R
valid_e map_e)
as [[vF [mF eval_float]] err_bounded]; auto.
exists (elo, ehi), err_e, vR, vF, mF; repeat split; auto.
Qed.
rewrite <- eval_expr_REAL_det_nondet in eval_real.
assert (forall (e' : expr Rdefinitions.R) (m' : mType),
exists d, (fun e m => Some 0%R) e' m' = Some d /\ (Rabs d <= mTypeToR m')%R) as Htmp by admit.
assert (dVars_contained NatSet.empty (FloverMap.empty (affine_form Q))) as Hdvars
by (unfold dVars_contained; intros * Hset; clear - Hset; set_tac).
pose proof (RoundoffErrorValidator_sound e _ Htmp H approxE1E2 H1 eval_real R
valid_e map_e Hdvars) as Hsound.
unfold validErrorBounds in Hsound.
(* destruct Hsound as [[vF [mF eval_float]] err_bounded]; auto. *)
(* exists (elo, ehi), err_e, vR, vF, mF; repeat split; auto. *)
Admitted.
Definition CertificateCheckerCmd (f:cmd Q) (absenv:analysisResult) (P:precond)
defVars :=
......
......@@ -48,14 +48,15 @@ Inductive sstep : cmd R -> env -> R -> cmd R -> env -> Prop :=
Define big step semantics for the Flover language, terminating on a "returned"
result value
**)
Inductive bstep : cmd R -> env -> (expr R -> option mType) -> R -> mType -> Prop :=
let_b m m' x e s E v res defVars:
eval_expr E defVars e v m ->
bstep s (updEnv x v E) defVars res m' -> (* (updDefVars (Var R x) m defVars) res m' -> *)
bstep (Let m x e s) E defVars res m'
|ret_b m e E v defVars:
eval_expr E defVars e v m ->
bstep (Ret e) E defVars v m.
Inductive bstep : cmd R -> env -> (expr R -> option mType) -> (expr R -> mType -> option R) ->
R -> mType -> Prop :=
let_b m m' x e s E v res defVars DeltaMap:
eval_expr E defVars DeltaMap e v m ->
bstep s (updEnv x v E) defVars DeltaMap res m' -> (* (updDefVars (Var R x) m defVars) res m' -> *)
bstep (Let m x e s) E defVars DeltaMap res m'
|ret_b m e E v defVars DeltaMap:
eval_expr E defVars DeltaMap e v m ->
bstep (Ret e) E defVars DeltaMap v m.
(**
The free variables of a command are all used variables of exprressions
......@@ -87,14 +88,14 @@ Fixpoint liveVars V (f:cmd V) :NatSet.t :=
end.
Lemma bstep_eq_env f:
forall E1 E2 Gamma v m,
forall E1 E2 Gamma DeltaMap v m,
(forall x, E1 x = E2 x) ->
bstep f E1 Gamma v m ->
bstep f E2 Gamma v m.
bstep f E1 Gamma DeltaMap v m ->
bstep f E2 Gamma DeltaMap v m.
Proof.
induction f; intros * eq_envs bstep_E1;
inversion bstep_E1; subst; simpl in *.
- eapply eval_eq_env in H7; eauto. eapply let_b; eauto.
- eapply eval_eq_env in H8; eauto. eapply let_b; eauto.
eapply IHf. instantiate (1:=(updEnv n v0 E1)).
+ intros; unfold updEnv.
destruct (x=? n); auto.
......@@ -102,12 +103,12 @@ Proof.
- apply ret_b. eapply eval_eq_env; eauto.
Qed.
Lemma swap_Gamma_bstep f E vR m Gamma1 Gamma2 :
Lemma swap_Gamma_bstep f E vR m Gamma1 Gamma2 DeltaMap:
(forall n, Gamma1 n = Gamma2 n) ->
bstep f E Gamma1 vR m ->
bstep f E Gamma2 vR m.
bstep f E Gamma1 DeltaMap vR m ->
bstep f E Gamma2 DeltaMap vR m.
Proof.
revert E Gamma1 Gamma2;
revert E Gamma1 Gamma2 DeltaMap;
induction f; intros * Gamma_eq eval_f.
- inversion eval_f; subst.
econstructor; try eauto.
......@@ -118,9 +119,9 @@ Proof.
Qed.
Lemma bstep_Gamma_det f:
forall E1 E2 Gamma v1 v2 m1 m2,
bstep f E1 Gamma v1 m1 ->
bstep f E2 Gamma v2 m2 ->
forall E1 E2 Gamma DeltaMap v1 v2 m1 m2,
bstep f E1 Gamma DeltaMap v1 m1 ->
bstep f E2 Gamma DeltaMap v2 m2 ->
m1 = m2.
Proof.
induction f; intros * eval_f1 eval_f2;
......@@ -128,4 +129,4 @@ Proof.
inversion eval_f2; subst; try auto.
- eapply IHf; eauto.
- eapply Gamma_det; eauto.
Qed.
\ No newline at end of file
Qed.
......@@ -2,7 +2,7 @@ From Coq
Require Import Reals.Reals QArith.Qreals.
From Flover
Require Import ExpressionSemanticsDeterministic Environments RealRangeArith TypeValidator.
Require Import ExpressionSemantics Environments RealRangeArith TypeValidator.
Fixpoint validErrorBounds (e:expr Q) E1 E2 A Gamma DeltaMap :Prop :=
(match e with
......@@ -18,23 +18,23 @@ Fixpoint validErrorBounds (e:expr Q) E1 E2 A Gamma DeltaMap :Prop :=
| _ => True
end) /\
forall v__R (iv: intv) (err: error),
eval_expr_det E1 (toRTMap (toRExpMap Gamma)) (fun x m => Some 0%R) (toREval (toRExp e)) v__R REAL ->
eval_expr E1 (toRTMap (toRExpMap Gamma)) DeltaMapR (toREval (toRExp e)) v__R REAL ->
FloverMap.find e A = Some (iv, err) ->
(exists v__FP m__FP,
eval_expr_det E2 (toRExpMap Gamma) DeltaMap (toRExp e) v__FP m__FP) /\
eval_expr E2 (toRExpMap Gamma) DeltaMap (toRExp e) v__FP m__FP) /\
(forall v__FP m__FP,
eval_expr_det E2 (toRExpMap Gamma) DeltaMap (toRExp e) v__FP m__FP ->
eval_expr E2 (toRExpMap Gamma) DeltaMap (toRExp e) v__FP m__FP ->
(Rabs (v__R - v__FP) <= (Q2R err))%R).
Lemma validErrorBounds_single e E1 E2 A Gamma DeltaMap:
validErrorBounds e E1 E2 A Gamma DeltaMap ->
forall v__R iv err,
eval_expr_det E1 (toRTMap (toRExpMap Gamma)) (fun x m => Some 0%R) (toREval (toRExp e)) v__R REAL ->
eval_expr E1 (toRTMap (toRExpMap Gamma)) (fun x m => Some 0%R) (toREval (toRExp e)) v__R REAL ->
FloverMap.find e A = Some (iv, err) ->
(exists v__FP m__FP,
eval_expr_det E2 (toRExpMap Gamma) DeltaMap (toRExp e) v__FP m__FP) /\
eval_expr E2 (toRExpMap Gamma) DeltaMap (toRExp e) v__FP m__FP) /\
(forall v__FP m__FP,
eval_expr_det E2 (toRExpMap Gamma) DeltaMap (toRExp e) v__FP m__FP ->
eval_expr E2 (toRExpMap Gamma) DeltaMap (toRExp e) v__FP m__FP ->
(Rabs (v__R - v__FP) <= (Q2R err))%R).
Proof.
intros validError_e;
......
......@@ -11,9 +11,9 @@ From Flover
Infra.RealRationalProps Environments Infra.ExpressionAbbrevs
ExpressionSemantics.
Lemma const_abs_err_bounded (n:R) (nR:R) (nF:R) (E1 E2:env) (m:mType) defVars:
eval_expr E1 (toRTMap defVars) (Const REAL n) nR REAL ->
eval_expr E2 defVars (Const m n) nF m ->
Lemma const_abs_err_bounded (n:R) (nR:R) (nF:R) (E1 E2:env) (m:mType) defVars DeltaMap:
eval_expr E1 (toRTMap defVars) DeltaMapR (Const REAL n) nR REAL ->
eval_expr E2 defVars DeltaMap (Const m n) nF m ->
(Rabs (nR - nF) <= computeErrorR n m)%R.
Proof.
intros eval_real eval_float.
......@@ -34,16 +34,17 @@ Proof.
Qed.
Lemma add_abs_err_bounded (e1:expr Q) (e1R:R) (e1F:R) (e2:expr Q) (e2R:R) (e2F:R)
(vR:R) (vF:R) (E1 E2:env) (err1 err2 :Q) (m m1 m2:mType) defVars:
eval_expr E1 (toRTMap defVars) (toREval (toRExp e1)) e1R REAL ->
eval_expr E2 defVars (toRExp e1) e1F m1->
eval_expr E1 (toRTMap defVars) (toREval (toRExp e2)) e2R REAL ->
eval_expr E2 defVars (toRExp e2) e2F m2 ->
eval_expr E1 (toRTMap defVars) (toREval (Binop Plus (toRExp e1) (toRExp e2))) vR REAL ->
(vR:R) (vF:R) (E1 E2:env) (err1 err2 :Q) (m m1 m2:mType) defVars DeltaMap:
eval_expr E1 (toRTMap defVars) DeltaMapR (toREval (toRExp e1)) e1R REAL ->
eval_expr E2 defVars DeltaMap (toRExp e1) e1F m1->
eval_expr E1 (toRTMap defVars) DeltaMapR (toREval (toRExp e2)) e2R REAL ->
eval_expr E2 defVars DeltaMap (toRExp e2) e2F m2 ->
eval_expr E1 (toRTMap defVars) DeltaMapR (toREval (Binop Plus (toRExp e1) (toRExp e2))) vR REAL ->
eval_expr (updEnv 2 e2F (updEnv 1 e1F emptyEnv))
(updDefVars (Binop Plus (Var R 1) (Var R 2)) m
(updDefVars (Var R 2) m2 (updDefVars (Var R 1) m1 defVars)))
(Binop Plus (Var R 1) (Var R 2)) vF m ->
DeltaMap
(Binop Plus (Var R 1) (Var R 2)) vF m ->
(Rabs (e1R - e1F) <= Q2R err1)%R ->
(Rabs (e2R - e2F) <= Q2R err2)%R ->
(Rabs (vR - vF) <= Q2R err1 + Q2R err2 + computeErrorR (e1F + e2F) m)%R.
......@@ -57,17 +58,17 @@ Proof.
rewrite delta_0_deterministic in plus_real; auto.
rewrite (delta_0_deterministic (evalBinop Plus v1 v2) REAL delta); auto.
unfold evalBinop in *; simpl in *.
rewrite (meps_0_deterministic (toRExp e1) H5 e1_real);
rewrite (meps_0_deterministic (toRExp e2) H8 e2_real).
rewrite (meps_0_deterministic (toRExp e1) H5 e1_real) in plus_real.
rewrite (meps_0_deterministic (toRExp e2) H8 e2_real) in plus_real.
rewrite (meps_0_deterministic (toRExp e1) H6 e1_real);
rewrite (meps_0_deterministic (toRExp e2) H9 e2_real).
rewrite (meps_0_deterministic (toRExp e1) H6 e1_real) in plus_real.
rewrite (meps_0_deterministic (toRExp e2) H9 e2_real) in plus_real.
(* Now unfold the float valued evaluation to get the deltas we need for the inequality *)
inversion plus_float; subst.
unfold perturb; simpl.
inversion H11; subst; inversion H14; subst.
unfold updEnv in H1, H13; simpl in *.
symmetry in H1,H13.
inversion H1; inversion H13; subst.
inversion H13; subst; inversion H16; subst.
unfold updEnv in H1, H15; simpl in *.
symmetry in H1,H15.
inversion H1; inversion H15; subst.
(* We have now obtained all necessary values from the evaluations --> remove them for readability *)
clear plus_float H4 H7 plus_real e1_real e1_float e2_real e2_float H8 H6 H1.
repeat rewrite Rmult_plus_distr_l.
......@@ -104,16 +105,17 @@ Qed.
Copy-Paste proof with minor differences, was easier then manipulating the evaluations and then applying the lemma
**)
Lemma subtract_abs_err_bounded (e1:expr Q) (e1R:R) (e1F:R) (e2:expr Q) (e2R:R)
(e2F:R) (vR:R) (vF:R) (E1 E2:env) err1 err2 (m m1 m2:mType) defVars:
eval_expr E1 (toRTMap defVars) (toREval (toRExp e1)) e1R REAL ->
eval_expr E2 defVars (toRExp e1) e1F m1 ->
eval_expr E1 (toRTMap defVars) (toREval (toRExp e2)) e2R REAL ->
eval_expr E2 defVars (toRExp e2) e2F m2 ->
eval_expr E1 (toRTMap defVars) (toREval (Binop Sub (toRExp e1) (toRExp e2))) vR REAL ->
(e2F:R) (vR:R) (vF:R) (E1 E2:env) err1 err2 (m m1 m2:mType) defVars DeltaMap:
eval_expr E1 (toRTMap defVars) DeltaMapR (toREval (toRExp e1)) e1R REAL ->
eval_expr E2 defVars DeltaMap (toRExp e1) e1F m1 ->
eval_expr E1 (toRTMap defVars) DeltaMapR (toREval (toRExp e2)) e2R REAL ->
eval_expr E2 defVars DeltaMap (toRExp e2) e2F m2 ->
eval_expr E1 (toRTMap defVars) DeltaMapR (toREval (Binop Sub (toRExp e1) (toRExp e2))) vR REAL ->
eval_expr (updEnv 2 e2F (updEnv 1 e1F emptyEnv))
(updDefVars (Binop Sub (Var R 1) (Var R 2)) m
(updDefVars (Var R 2) m2 (updDefVars (Var R 1) m1 defVars)))
(Binop Sub (Var R 1) (Var R 2)) vF m ->
(updDefVars (Var R 2) m2 (updDefVars (Var R 1) m1 defVars)))
DeltaMap
(Binop Sub (Var R 1) (Var R 2)) vF m ->
(Rabs (e1R - e1F) <= Q2R err1)%R ->
(Rabs (e2R - e2F) <= Q2R err2)%R ->
(Rabs (vR - vF) <= Q2R err1 + Q2R err2 + computeErrorR (e1F - e2F) m)%R.
......@@ -127,17 +129,17 @@ Proof.
rewrite delta_0_deterministic in sub_real; auto.
rewrite (delta_0_deterministic (evalBinop Sub v1 v2) REAL delta); auto.
unfold evalBinop in *; simpl in *.
rewrite (meps_0_deterministic (toRExp e1) H5 e1_real);
rewrite (meps_0_deterministic (toRExp e2) H8 e2_real).
rewrite (meps_0_deterministic (toRExp e1) H5 e1_real) in sub_real.
rewrite (meps_0_deterministic (toRExp e2) H8 e2_real) in sub_real.
rewrite (meps_0_deterministic (toRExp e1) H6 e1_real);
rewrite (meps_0_deterministic (toRExp e2) H9 e2_real).
rewrite (meps_0_deterministic (toRExp e1) H6 e1_real) in sub_real.
rewrite (meps_0_deterministic (toRExp e2) H9 e2_real) in sub_real.
(* Now unfold the float valued evaluation to get the deltas we need for the inequality *)
inversion sub_float; subst.
unfold perturb; simpl.
inversion H11; subst; inversion H14; subst.
unfold updEnv in H1,H13; simpl in *.
symmetry in H1,H13.
inversion H1; inversion H13; subst.
inversion H13; subst; inversion H16; subst.
unfold updEnv in H1,H15; simpl in *.
symmetry in H1,H15.
inversion H1; inversion H15; subst.
(* We have now obtained all necessary values from the evaluations --> remove them for readability *)
clear sub_float H4 H7 sub_real e1_real e1_float e2_real e2_float H8 H6 H1.
repeat rewrite Rmult_plus_distr_l.
......@@ -179,16 +181,17 @@ Proof.
Qed.
Lemma mult_abs_err_bounded (e1:expr Q) (e1R:R) (e1F:R) (e2:expr Q) (e2R:R) (e2F:R)
(vR:R) (vF:R) (E1 E2:env) (m m1 m2:mType) defVars:
eval_expr E1 (toRTMap defVars) (toREval (toRExp e1)) e1R REAL ->
eval_expr E2 defVars (toRExp e1) e1F m1 ->
eval_expr E1 (toRTMap defVars) (toREval (toRExp e2)) e2R REAL ->
eval_expr E2 defVars (toRExp e2) e2F m2 ->
eval_expr E1 (toRTMap defVars) (toREval (Binop Mult (toRExp e1) (toRExp e2))) vR REAL ->
(vR:R) (vF:R) (E1 E2:env) (m m1 m2:mType) defVars DeltaMap:
eval_expr E1 (toRTMap defVars) DeltaMapR (toREval (toRExp e1)) e1R REAL ->
eval_expr E2 defVars DeltaMap (toRExp e1) e1F m1 ->
eval_expr E1 (toRTMap defVars) DeltaMapR (toREval (toRExp e2)) e2R REAL ->
eval_expr E2 defVars DeltaMap (toRExp e2) e2F m2 ->
eval_expr E1 (toRTMap defVars) DeltaMapR (toREval (Binop Mult (toRExp e1) (toRExp e2))) vR REAL ->
eval_expr (updEnv 2 e2F (updEnv 1 e1F emptyEnv))
(updDefVars (Binop Mult (Var R 1) (Var R 2)) m
(updDefVars (Var R 2) m2 (updDefVars (Var R 1) m1 defVars)))
(Binop Mult (Var R 1) (Var R 2)) vF m ->
(updDefVars (Var R 2) m2 (updDefVars (Var R 1) m1 defVars)))
DeltaMap
(Binop Mult (Var R 1) (Var R 2)) vF m ->
(Rabs (vR - vF) <= Rabs (e1R * e2R - e1F * e2F) + computeErrorR (e1F * e2F) m)%R.
Proof.
intros e1_real e1_float e2_real e2_float mult_real mult_float.
......@@ -200,17 +203,17 @@ Proof.
rewrite delta_0_deterministic in mult_real; auto.
rewrite delta_0_deterministic; auto.
unfold evalBinop in *; simpl in *.
rewrite (meps_0_deterministic (toRExp e1) H5 e1_real);
rewrite (meps_0_deterministic (toRExp e2) H8 e2_real).
rewrite (meps_0_deterministic (toRExp e1) H5 e1_real) in mult_real.
rewrite (meps_0_deterministic (toRExp e2) H8 e2_real) in mult_real.
rewrite (meps_0_deterministic (toRExp e1) H6 e1_real);
rewrite (meps_0_deterministic (toRExp e2) H9 e2_real).
rewrite (meps_0_deterministic (toRExp e1) H6 e1_real) in mult_real.
rewrite (meps_0_deterministic (toRExp e2) H9 e2_real) in mult_real.
(* Now unfold the float valued evaluation to get the deltas we need for the inequality *)
inversion mult_float; subst.
unfold perturb; simpl.
inversion H11; subst; inversion H14; subst.
unfold updEnv in H1,H13; simpl in *.
symmetry in H1,H13.
inversion H1; inversion H13; subst.
inversion H13; subst; inversion H16; subst.