|
| 1 | +(** |
| 2 | + This file contains the HOL4 implementation of the certificate checker as well |
| 3 | + as its soundness proof. The checker is a composition of the range analysis |
| 4 | + validator and the error bound validator. Running this function on the encoded |
| 5 | + analysis result gives the desired theorem as shown in the soundness theorem. |
| 6 | +**) |
| 7 | +open simpLib realTheory realLib RealArith RealSimpsTheory; |
| 8 | +open AbbrevsTheory ExpressionsTheory FloverTactics ExpressionAbbrevsTheory |
| 9 | + ExpressionSemanticsTheory ErrorBoundsTheory IntervalArithTheory |
| 10 | + RealRangeArithTheory IntervalValidationTheory ErrorValidationTheory |
| 11 | + ssaPrgsTheory FPRangeValidatorTheory TypeValidatorTheory FloverMapTheory; |
| 12 | + |
| 13 | +open preambleFloVer; |
| 14 | + |
| 15 | +val _ = new_theory "CertificateChecker"; |
| 16 | +val _ = temp_overload_on("abs",``real$abs``); |
| 17 | + |
| 18 | +(** Certificate checking function **) |
| 19 | +Definition CertificateChecker_def: |
| 20 | + CertificateChecker (e:real expr) (A:analysisResult) (P:precond) |
| 21 | + (defVars: typeMap)= |
| 22 | + (case getValidMap defVars e FloverMapTree_empty of |
| 23 | + | Fail s => NONE |
| 24 | + | FailDet _ _ => NONE |
| 25 | + | Succes Gamma => |
| 26 | + if (validIntervalbounds e A P LN /\ |
| 27 | + FPRangeValidator e A Gamma LN) |
| 28 | + then |
| 29 | + if validErrorbound e Gamma A LN |
| 30 | + then SOME Gamma |
| 31 | + else NONE |
| 32 | + else NONE) |
| 33 | +End |
| 34 | + |
| 35 | +(** |
| 36 | + Soundness proof for the certificate checker. |
| 37 | + Apart from assuming two executions, one in R and one on floats, we assume that |
| 38 | + the real valued execution respects the precondition. |
| 39 | +**) |
| 40 | +Theorem Certificate_checking_is_sound: |
| 41 | + !(e:real expr) (A:analysisResult) (P:precond) (E1 E2:env) defVars fVars Gamma. |
| 42 | + (!v. |
| 43 | + v IN (domain fVars) ==> |
| 44 | + ?vR. |
| 45 | + (E1 v = SOME vR) /\ |
| 46 | + FST (P v) <= vR /\ vR <= SND (P v)) /\ |
| 47 | + (domain (usedVars e)) SUBSET (domain fVars) /\ |
| 48 | + CertificateChecker e A P defVars = SOME Gamma /\ |
| 49 | + approxEnv E1 (toRExpMap Gamma) A fVars LN E2 ==> |
| 50 | + ?iv err vR vF m. |
| 51 | + FloverMapTree_find e A = SOME (iv,err) /\ |
| 52 | + eval_expr E1 (toRTMap (toRExpMap Gamma)) (toREval e) vR REAL /\ |
| 53 | + eval_expr E2 (toRExpMap Gamma) e vF m /\ |
| 54 | + (!vF m. |
| 55 | + eval_expr E2 (toRExpMap Gamma) e vF m ==> |
| 56 | + abs (vR - vF) <= err /\ validFloatValue vF m) |
| 57 | +Proof |
| 58 | +(** |
| 59 | + The proofs is a simple composition of the soundness proofs for the range |
| 60 | + validator and the error bound validator. |
| 61 | +**) |
| 62 | + simp [CertificateChecker_def] |
| 63 | + \\ rpt strip_tac |
| 64 | + \\ Cases_on `getValidMap defVars e FloverMapTree_empty` \\ fs[] |
| 65 | + \\ IMP_RES_TAC getValidMap_top_correct |
| 66 | + \\ rveq |
| 67 | + \\ `validTypes e Gamma` |
| 68 | + by (first_x_assum irule |
| 69 | + \\ fs[FloverMapTree_empty_def, FloverMapTree_mem_def, FloverMapTree_find_def]) |
| 70 | + \\ drule validIntervalbounds_sound |
| 71 | + \\ rpt (disch_then drule) |
| 72 | + \\ disch_then (qspecl_then [`fVars`,`E1`, `Gamma`] destruct) |
| 73 | + \\ fs[dVars_range_valid_def, fVars_P_sound_def] |
| 74 | + \\ drule validErrorbound_sound |
| 75 | + \\ rpt (disch_then drule) |
| 76 | + \\ IMP_RES_TAC validRanges_single |
| 77 | + \\ disch_then (qspecl_then [`vR`, `err`, `FST iv`, `SND iv`] destruct) |
| 78 | + \\ fs[] |
| 79 | + \\ rpt (find_exists_tac \\ fs[]) |
| 80 | + \\ rpt strip_tac |
| 81 | + >- (first_x_assum irule \\ fs[] |
| 82 | + \\ asm_exists_tac \\ fs[]) |
| 83 | + \\ drule FPRangeValidator_sound |
| 84 | + \\ rpt (disch_then drule) |
| 85 | + \\ disch_then irule \\ fs[] |
| 86 | +QED |
| 87 | + |
| 88 | +Definition CertificateCheckerCmd_def: |
| 89 | + CertificateCheckerCmd (f:real cmd) (absenv:analysisResult) (P:precond) |
| 90 | + defVars = |
| 91 | + (case getValidMapCmd defVars f FloverMapTree_empty of |
| 92 | + | Fail _ => NONE |
| 93 | + | FailDet _ _ => NONE |
| 94 | + | Succes Gamma => |
| 95 | + if (validSSA f (freeVars f)) |
| 96 | + then |
| 97 | + if ((validIntervalboundsCmd f absenv P LN) /\ |
| 98 | + FPRangeValidatorCmd f absenv Gamma LN) |
| 99 | + then |
| 100 | + if validErrorboundCmd f Gamma absenv LN |
| 101 | + then SOME Gamma |
| 102 | + else NONE |
| 103 | + else NONE |
| 104 | + else NONE) |
| 105 | +End |
| 106 | + |
| 107 | +Theorem CertificateCmd_checking_is_sound: |
| 108 | + !(f:real cmd) (A:analysisResult) (P:precond) defVars |
| 109 | + (E1 E2:env) (fVars:num_set) Gamma. |
| 110 | + (!v. |
| 111 | + v IN (domain (freeVars f)) ==> |
| 112 | + ?vR. |
| 113 | + (E1 v = SOME vR) /\ |
| 114 | + FST (P v) <= vR /\ vR <= SND (P v)) /\ |
| 115 | + domain (freeVars f) SUBSET (domain fVars) /\ |
| 116 | + CertificateCheckerCmd f A P defVars = SOME Gamma /\ |
| 117 | + approxEnv E1 (toRExpMap Gamma) A (freeVars f) LN E2 ==> |
| 118 | + ?iv err vR vF m. |
| 119 | + FloverMapTree_find (getRetExp f) A = SOME (iv, err) /\ |
| 120 | + bstep (toREvalCmd f) E1 (toRTMap (toRExpMap Gamma)) vR REAL /\ |
| 121 | + bstep f E2 (toRExpMap Gamma) vF m /\ |
| 122 | + (!vF m. bstep f E2 (toRExpMap Gamma) vF m ==> abs (vR - vF) <= err) |
| 123 | +Proof |
| 124 | + simp [CertificateCheckerCmd_def] |
| 125 | + \\ rpt strip_tac |
| 126 | + \\ Cases_on `getValidMapCmd defVars f FloverMapTree_empty` \\ fs[] |
| 127 | + \\ rveq \\ imp_res_tac getValidMapCmd_correct |
| 128 | + \\ `validTypesCmd f Gamma` |
| 129 | + by (first_x_assum irule |
| 130 | + \\ fs[FloverMapTree_empty_def, FloverMapTree_mem_def, FloverMapTree_find_def]) |
| 131 | + \\ `?outVars. ssa f (freeVars f) outVars` by (match_mp_tac validSSA_sound \\ fs[]) |
| 132 | + \\ qspecl_then |
| 133 | + [`f`, `A`, `E1`, `freeVars f`, `LN`, `outVars`, `P`, `Gamma`] |
| 134 | + destruct validIntervalboundsCmd_sound |
| 135 | + \\ fs[dVars_range_valid_def, fVars_P_sound_def] |
| 136 | + \\ IMP_RES_TAC validRangesCmd_single |
| 137 | + \\ qspecl_then |
| 138 | + [`f`, `A`, `E1`, `E2`, `outVars`, `freeVars f`, `LN`, `vR`, `FST iv_e`, |
| 139 | + `SND iv_e`, `err_e`, `m`, `Gamma`] |
| 140 | + destruct validErrorboundCmd_gives_eval |
| 141 | + \\ fs[] |
| 142 | + \\ rpt (find_exists_tac \\ fs[]) |
| 143 | + \\ rpt strip_tac |
| 144 | + \\ drule validErrorboundCmd_sound |
| 145 | + \\ rpt (disch_then drule) |
| 146 | + \\ rename1 `bstep f E2 _ vF2 m2` |
| 147 | + \\ disch_then |
| 148 | + (qspecl_then |
| 149 | + [`outVars`, `vR`, `vF2`, `FST iv_e`, `SND iv_e`, `err_e`, `m2`] destruct) |
| 150 | + \\ fs[] |
| 151 | +QED |
| 152 | + |
| 153 | +Theorem CertificateCheckerCmd_Gamma_is_getValidMapCmd: |
| 154 | + CertificateCheckerCmd f A P dVars = SOME Gamma ⇒ |
| 155 | + getValidMapCmd dVars f FloverMapTree_empty = Succes Gamma |
| 156 | +Proof |
| 157 | + fs[CertificateCheckerCmd_def] |
| 158 | + \\ rpt (TOP_CASE_TAC \\ fs[]) |
| 159 | +QED |
| 160 | + |
| 161 | +val _ = export_theory(); |
0 commit comments