Skip to content

Commit 68c06c5

Browse files
committed
Update proofs to latest state
1 parent 121d8a8 commit 68c06c5

File tree

3 files changed

+98
-99
lines changed

3 files changed

+98
-99
lines changed

icing/examples/exampleLib.sml

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ structure exampleLib =
55
struct
66
open astTheory cfTacticsLib ml_translatorLib;
77
open basis_ffiTheory cfHeapsBaseTheory basis;
8-
open data_monadTheory compilationLib;
8+
(* open data_monadTheory compilationLib;*)
99
open FloverMapTheory RealIntervalInferenceTheory ErrorIntervalInferenceTheory
1010
CertificateCheckerTheory;
1111
open floatToRealProofsTheory source_to_sourceTheory CakeMLtoFloVerTheory
@@ -835,14 +835,14 @@ val _ = write_to_file data_prog_def;
835835
val theAST_float_returns_def =
836836
Define ‘
837837
theAST_float_returns ^args w ⇔
838-
(∃ fpOpts st2 fp.
838+
∃ fpOpts st2 fp.
839839
let theOpts = FLAT (MAP (λ x. case x of |Apply (_, rws) => rws |_ => []) (HD theAST_plan)) in
840-
(evaluate (empty_state with fp_state :=
840+
evaluate (empty_state with fp_state :=
841841
empty_state.fp_state with
842842
<| rws := theOpts ; opts := fpOpts; canOpt := FPScope NoOpt |>)
843843
(theAST_env with v :=
844844
extend_env_with_vars (REVERSE ^fvars) (REVERSE ^argList) (theAST_env).v)
845-
[^body] = (st2, Rval [FP_WordTree fp]))(compress_word fp = w))
845+
[^body] = (st2, Rval [FP_WordTree fp]) ∧ compress_word fp = w’
846846
val body_doubleExpPlan = store_thm ("body_doubleExpPlan",
847847
Parse.Term ‘isDoubleExpPlan ^body no_fp_opt_conf (HD theAST_plan)’,
848848
EVAL_TAC);
@@ -921,7 +921,8 @@ val _ = write_to_file data_prog_def;
921921
is_Double (w1::ws) (d1::ds) = (DOUBLE (Fp_const w1) d1 ∧ is_Double ws ds)’
922922
(* Load the necessary constants from the state *)
923923
val theAST_v = fetch_v (stringSyntax.fromHOLstring fname) st
924-
val theAST_v_def = DB.find ((term_to_string theAST_v)^"_def") |> hd |> #2 |> #1
924+
val theAST_v_def = DB.find_in ((term_to_string theAST_v)^"_def")
925+
(DB.thy (Theory.current_theory()))|> hd |> #2 |> #1
925926
val theAST_spec = store_thm ("theAST_spec",
926927
Parse.Term ‘
927928
theAST_side ^args ∧

icing/examples/prettyScript.sml

+49-12
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,11 @@ Definition noStrictExecution_def:
130130
End
131131

132132
Definition appendOptsAndOracle_def:
133-
appendOptsAndOracle fps rws fpOpts choices = fps with <| rws := fps.rws ++ rws; opts := fpOpts; choices := choices |>
133+
appendOptsAndOracle st rws fpOpts choices = st with fp_state := st.fp_state with <| rws := st.fp_state.rws ++ rws; opts := fpOpts; choices := choices |>
134134
End
135135

136136
Overload is_rewrite_correct = “is_rewriteFPexp_correct”
137+
Overload freeVarsBound = “freeVars_fp_bound”
137138

138139
Theorem rewrite_correct_def:
139140
K T ^(is_rewriteFPexp_correct_def
@@ -143,8 +144,21 @@ Proof
143144
simp[K_DEF]
144145
QED
145146

147+
Definition freeVars_fine_exp_def:
148+
freeVars_fine_exp canOpt (st1:'a semanticPrimitives$state) e env path =
149+
∀ (st1:'a semanticPrimitives$state) st2. freeVars_arithExp_bound st1 st2 env canOpt path e
150+
End
151+
152+
Overload freeVarsPathBound = “freeVars_fine_exp canOpt”
153+
146154
Overload is_performRewrites_correct = “is_perform_rewrites_correct”
147155

156+
Overload performRewrites = “perform_rewrites”
157+
Overload rewrite = “rewriteFPexp”
158+
159+
Overload is_optimiseWithPlan_correct = “is_optimise_with_plan_correct”
160+
161+
148162
Definition notInStrictMode_def:
149163
notInStrictMode fps = (fps.canOpt ≠ Strict)
150164
End
@@ -153,34 +167,43 @@ Definition flagAndScopeAgree_def:
153167
flagAndScopeAgree flag fps = (flag.canOpt <=> fps.canOpt = FPScope Opt)
154168
End
155169

156-
157170
Theorem performRewrites_correct_def:
158171
K T ^(is_perform_rewrites_correct_def
159172
|> SIMP_RULE (srw_ss()) [GSYM noRealsAllowed_def, GSYM canOptimize_def,
160173
GSYM appendOptsAndOracle_def, GSYM notInStrictMode_def,
161-
GSYM flagAndScopeAgree_def]
174+
GSYM flagAndScopeAgree_def,
175+
GSYM freeVars_fine_exp_def]
176+
|> REWRITE_RULE [GSYM freeVars_fine_exp_def]
162177
|> SPEC_ALL
163178
|> GEN “cfg:source_to_source$config” |> SPEC “canOpt:source_to_source$config” |> concl |> rhs)
164179
Proof
165180
simp[K_DEF]
166181
QED
167182

168-
Overload optimiseWithPlan = “optimise_with_plan”
169-
170-
Definition optimiseWithPlan_def:
171-
optimiseWithPlan cfg plan exps = MAP (λ e. FST (optimise_with_plan cfg plan e)) exps
183+
Definition optimizeWithPlan_def:
184+
optimizeWithPlan cfg plan exps = MAP (λ e. FST (optimise_with_plan cfg plan e)) exps
172185
End
173186

174187
Definition getRws_def:
175188
getRws plan = FLAT (MAP (λ x. case x of |Apply (_, rws) => rws |_ => []) plan)
176189
End
177190

191+
Definition freeVars_fine_def:
192+
freeVars_fine canOpt (st1:'a semanticPrimitives$state) exps env plan =
193+
(∀ e. MEM e exps ⇒ ∀ (st1:'a semanticPrimitives$state) st2. freeVars_plan_bound st1 st2 env canOpt plan e)
194+
End
195+
196+
Overload freeVarsPlanBound = “freeVars_fine canOpt”
197+
178198
Theorem optimize_with_plan_correct:
179199
K T ^(is_optimise_with_plan_correct_def
180200
|> SIMP_RULE (srw_ss()) [GSYM noRealsAllowed_def, GSYM canOptimize_def,
181201
GSYM appendOptsAndOracle_def, GSYM notInStrictMode_def,
182-
GSYM flagAndScopeAgree_def, GSYM optimiseWithPlan_def,
183-
GSYM getRws_def, LET_THM]
202+
GSYM flagAndScopeAgree_def, GSYM optimizeWithPlan_def,
203+
GSYM getRws_def, LET_THM,
204+
GSYM freeVars_fine_def]
205+
|> REWRITE_RULE [GSYM freeVars_fine_def]
206+
|> SIMP_RULE (srw_ss()) []
184207
|> SPEC_ALL
185208
|> GEN “cfg:source_to_source$config” |> SPEC “canOpt:source_to_source$config”
186209
|> concl |> rhs)
@@ -193,11 +216,25 @@ Theorem rewrite_correct_chaining =
193216

194217
Overload is_rewrite_correct = “is_rewriteFPexp_list_correct”
195218

196-
Theorem optimize_with_plan_correct_lift =
197-
is_optimise_with_plan_correct_lift |> GEN_ALL |> SIMP_RULE std_ss [];
219+
Definition elemOfPlan_def:
220+
elemOfPlan (path,opts) plan = MEM (Apply (path, opts)) plan
221+
End
222+
223+
Theorem optimize_with_plan_correct_lift:
224+
∀plan.
225+
(∀ path opts.
226+
elemOfPlan (path,opts) plan ⇒
227+
∀ (st1:'a semanticPrimitives$state) st2 env cfg e r.
228+
is_performRewrites_correct opts st1 st2 env cfg e r path) ⇒
229+
∀ (st1:'a semanticPrimitives$state) st2 env cfg exps r.
230+
is_optimise_with_plan_correct plan st1 st2 env cfg exps r
231+
Proof
232+
simp[elemOfPlan_def] \\ rpt strip_tac \\ irule is_optimise_with_plan_correct_lift
233+
\\ rpt strip_tac \\ gs[]
234+
QED
198235

199236
Theorem perform_rewrites_correct_lift =
200-
is_rewriteFPexp_correct_lift_perform_rewrites |> GEN_ALL |> SIMP_RULE std_ss [];
237+
is_rewriteFPexp_correct_lift_perform_rewrites |> GEN_ALL |> SPEC “opts:(fp_pat # fp_pat) list” |> GEN_ALL |> SIMP_RULE std_ss [];
201238

202239
Overload noOpts = “no_optimisations cfg”
203240

icing/icing_optimisationProofsScript.sml

+43-82
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,6 @@ Theorem fp_add_sub_correct:
635635
∀ st1 st2 env e r.
636636
is_rewriteFPexp_correct [fp_add_sub] st1 st2 env e r
637637
Proof
638-
cheat (*
639638
rw[is_rewriteFPexp_correct_def]
640639
\\ qspecl_then [`e`] strip_assume_tac
641640
(ONCE_REWRITE_RULE [DISJ_COMM] fp_add_sub_cases)
@@ -650,114 +649,76 @@ Proof
650649
\\ qpat_x_assum `_ = (_, _)` (mp_tac o SIMP_RULE std_ss [evaluate_def])
651650
\\ simp[REVERSE_DEF, astTheory.getOpClass_def, astTheory.isFpBool_def,
652651
Once evaluate_cons, evaluate_case_case]
653-
\\ disch_then (mp_tac o (SIMP_RULE std_ss [evaluate_def]))
654-
\\ simp[REVERSE_DEF, astTheory.getOpClass_def, astTheory.isFpBool_def,
655-
Once evaluate_cons, evaluate_case_case]
656-
\\ ntac 2 (TOP_CASE_TAC \\ fs[])
657-
\\ rename1 ‘evaluate st1 env [e2] = (st1N, Rval v2)’
652+
\\ ntac 4 (TOP_CASE_TAC \\ fs[])
658653
\\ imp_res_tac evaluate_sing \\ rveq \\ fs[]
659-
\\ ‘st1N.fp_state.canOpt = FPScope Opt’ by fp_inv_tac
660-
\\ fs[]
661-
\\ simp[do_app_def, CaseEq"option", CaseEq"v", CaseEq"prod", CaseEq"result"]
654+
\\ simp[do_app_def, CaseEq"option", CaseEq"v", CaseEq"prod"]
662655
\\ rpt strip_tac \\ rveq \\ fs[] \\ rveq
663-
\\ ntac 2 (pop_assum mp_tac)
664-
\\ imp_res_tac evaluate_sing \\ rveq \\ fs[]
665-
\\ rveq
666-
\\ simp[CaseEq"option",CaseEq"v"]
667-
\\ rename [‘evaluate
668-
(shift_fp_opts st1N with <| refs := st1N.refs; ffi:=st1N.ffi|>)
669-
env [e1] = (st2N, Rval [v1])’,
670-
‘evaluate st1 env [e2] = (st1N, Rval [v2])’]
671-
\\ rpt strip_tac \\ rveq \\ fs[]
672-
\\ ‘st2N.fp_state.canOpt = FPScope Opt’ by (fp_inv_tac \\ fs[shift_fp_opts_def])
656+
\\ rename [‘evaluate st1 env [e1] = (st2, Rval [v1])’,
657+
‘evaluate st2 env [e2] = (st3, Rval [v2])’]
658+
\\ ‘st3.fp_state.canOpt = FPScope Opt’ by fp_inv_tac
673659
\\ fs[]
674-
\\ ‘st1N = st1 with fp_state := st1N.fp_state’
660+
\\ ‘st2 = st1 with fp_state := st2.fp_state ∧
661+
st3 = st1 with fp_state := st3.fp_state’
675662
by (imp_res_tac isPureExp_same_ffi \\ fs[isPureExp_def]
676663
\\ res_tac \\ fs[state_component_equality])
677-
\\ ‘st2N = st1 with fp_state := st2N.fp_state’
678-
by (imp_res_tac isPureExp_same_ffi \\ fs[isPureExp_def]
679-
\\ res_tac \\ fs[state_component_equality, shift_fp_opts_def])
680-
\\ qpat_assum ‘evaluate _ _ [e1] = _’
681-
(mp_then Any mp_tac isPureExp_evaluate_change_oracle)
664+
\\ qpat_assum `evaluate _ _ [e2] = _`
665+
(mp_then Any mp_tac isPureExp_evaluate_change_oracle)
666+
\\ fs[isPureExp_def]
682667
\\ disch_then (
683668
qspecl_then [
684669
‘fp_add_sub’,
685-
‘st1 with fp_state := st1.fp_state with
686-
<| opts := st1N.fp_state.opts;
687-
choices := st1.fp_state.choices + (st1N.fp_state.choices - st1.fp_state.choices) |>’,
688-
‘λ x. if (x = 0) then
689-
[RewriteApp Here (LENGTH st1.fp_state.rws + 1)] ++
690-
(case
691-
do_fprw (Rval (FP_WordTree (fp_uop FP_Neg w1)))
692-
(st1N.fp_state.opts 0) st1N.fp_state.rws
693-
of
694-
NONE => []
695-
| SOME r_opt =>
696-
(MAP (λ x. case x of |RewriteApp p id => RewriteApp (Right p) id) ((st1N.fp_state.opts 0)))) ++
697-
(case do_fprw (Rval (FP_WordTree (fp_bop FP_Add w1' w2)))
698-
(st2N.fp_state.opts 0) st2N.fp_state.rws of
699-
| NONE => []
700-
| SOME r_opt => st2N.fp_state.opts x)
701-
else []’]
702-
mp_tac)
703-
\\ fs[isPureExp_def]
704-
\\ impl_tac >- (fp_inv_tac \\ fs[shift_fp_opts_def])
670+
‘st1 with fp_state := st1.fp_state with choices :=
671+
st1.fp_state.choices + (st3.fp_state.choices - st2.fp_state.choices)’,
672+
‘λ x. if (x = 0)
673+
then [RewriteApp Here (LENGTH st1.fp_state.rws + 1)] ++
674+
(case do_fprw (Rval (FP_WordTree (fp_bop FP_Sub w1 w2)))
675+
(st3.fp_state.opts 0) st3.fp_state.rws of
676+
| NONE => [] | SOME r_opt => st3.fp_state.opts x)
677+
else []’] mp_tac)
678+
\\ impl_tac >- fp_inv_tac
705679
\\ strip_tac
706-
\\ qpat_assum `evaluate _ _ [e2] = _`
680+
\\ qpat_assum `evaluate _ _ [e1] = _`
707681
(mp_then Any mp_tac isPureExp_evaluate_change_oracle)
682+
\\ fs[isPureExp_def]
708683
\\ disch_then (
709684
qspecl_then [
710685
‘fp_add_sub’,
711-
‘st1’,
712-
‘oracle’] mp_tac)
713-
\\ fs[isPureExp_def]
686+
‘st1’, ‘λ x . if x = 0 then [] else oracle (x-1)’] mp_tac)
687+
\\ impl_tac >- fp_inv_tac
714688
\\ strip_tac
715-
\\ pop_assum (mp_then Any (qspec_then ‘st1.fp_state.choices’ assume_tac) (CONJUNCT1 evaluate_add_choices))
689+
\\ ‘st2.fp_state.rws = st1.fp_state.rws’ by fp_inv_tac
690+
\\ pop_assum (fs o single)
691+
\\ pop_assum (mp_then Any mp_tac (CONJUNCT1 evaluate_add_choices))
692+
\\ disch_then (qspec_then ‘st1.fp_state.choices’ assume_tac)
716693
\\ qexists_tac ‘oracle'’ \\ qexists_tac ‘st1.fp_state.choices’
717694
\\ simp[evaluate_def]
718695
\\ simp[REVERSE_DEF, astTheory.getOpClass_def, astTheory.isFpBool_def,
719696
Once evaluate_cons, evaluate_case_case]
720-
\\ fs (shift_fp_opts_def :: state_eqs)
721-
\\ ‘st1.fp_state.rws = st1N.fp_state.rws’ by fp_inv_tac
722-
\\ pop_assum (fs o single)
723-
\\ simp[do_app_def]
724697
\\ fs state_eqs
698+
\\ simp([do_app_def, shift_fp_opts_def] @ state_eqs)
699+
\\ simp[Once do_fprw_def, rwAllWordTree_def]
700+
\\ qpat_x_assum `evaluate _ _ [e2] = _` $ mp_then Any mp_tac (CONJUNCT1 evaluate_add_choices)
701+
\\ disch_then $ qspec_then ‘st1.fp_state.choices + (st2.fp_state.choices - st1.fp_state.choices) + 1’ assume_tac
702+
\\ gs state_eqs \\ pop_assum mp_tac
703+
\\ qmatch_goalsub_abbrev_tac ‘evaluate st1Upd _ _ = _’ \\ rpt strip_tac
704+
\\ qmatch_goalsub_abbrev_tac ‘evaluate st1New _ _’
705+
\\ ‘st1Upd = st1New’ by (unabbrev_all_tac \\ gs (FUN_EQ_THM :: state_eqs))
706+
\\ pop_assum $ gs o single
707+
\\ gs (fp_translate_def :: state_eqs) \\ unabbrev_all_tac
725708
\\ rpt conj_tac
726709
>- fp_inv_tac
727710
>- (fp_inv_tac \\ fs[FUN_EQ_THM])
728711
>- fp_inv_tac
729712
\\ qpat_x_assum `_ = Rval _` (fs o single o GSYM)
730713
\\ simp[do_fprw_def, rwAllWordTree_def, nth_len]
731-
\\ simp[EVAL ``rwFp_pathWordTree fp_add_sub Here (fp_bop FP_Sub w1' w1)``,
714+
\\ simp[EVAL ``rwFp_pathWordTree (fp_add_sub) Here (fp_bop FP_Add w1 (fp_uop FP_Neg w2))``,
732715
instWordTree_def, substLookup_def]
733-
\\ Cases_on `rwAllWordTree (st1N.fp_state.opts 0) st1N.fp_state.rws (fp_uop FP_Neg w1)`
734-
\\ fs[rwAllWordTree_def, fpValTreeTheory.fp_uop_def]
735-
>- (
736-
fs[do_fprw_def] \\ rveq
737-
\\ fs[fp_translate_def] \\ rveq
738-
\\ Cases_on ‘rwAllWordTree (st2N.fp_state.opts 0) st2N.fp_state.rws
739-
(fp_bop FP_Add w1' (Fp_uop FP_Neg w1))’
740-
\\ fs[rwAllWordTree_def, fpValTreeTheory.fp_bop_def]
741-
\\ imp_res_tac rwAllWordTree_append_opt
742-
\\ first_x_assum (qspec_then `[fp_add_sub]` assume_tac)
743-
\\ `st1N.fp_state.rws = st2N.fp_state.rws` by fp_inv_tac
744-
\\ fs[])
745-
\\ imp_res_tac rwAllWordTree_comp_right
746-
\\ first_x_assum (qspecl_then [‘w1'’, ‘FP_Add’] assume_tac)
747-
\\ first_x_assum (mp_then Any assume_tac rwAllWordTree_append_opt)
748-
\\ first_x_assum (qspec_then `[fp_add_sub]` assume_tac)
749-
\\ fs[do_fprw_def] \\ rveq
750-
\\ fs[fp_translate_def] \\ rveq
751-
\\ Cases_on ‘rwAllWordTree (st2N.fp_state.opts 0) st2N.fp_state.rws
752-
(fp_bop FP_Add w1' w2)’
716+
\\ Cases_on `rwAllWordTree (st3.fp_state.opts 0) st3.fp_state.rws (fp_bop FP_Sub w1 w2)`
753717
\\ fs[rwAllWordTree_def, fpValTreeTheory.fp_bop_def]
754-
\\ pop_assum (mp_then Any mp_tac rwAllWordTree_append_opt)
755-
\\ disch_then (qspec_then ‘[fp_add_sub]’ mp_tac)
756-
\\ `st1N.fp_state.rws = st2N.fp_state.rws` by fp_inv_tac
757-
\\ pop_assum (fs o single)
758-
\\ first_x_assum (mp_then Any assume_tac rwAllWordTree_chaining_exact)
759-
\\ disch_then (fn th => first_x_assum (fn ithm => mp_then Any assume_tac ithm th))
760-
\\ fs[] *)
718+
\\ imp_res_tac rwAllWordTree_append_opt
719+
\\ first_x_assum (qspec_then `[fp_add_sub]` assume_tac)
720+
\\ `st3.fp_state.rws = st1.fp_state.rws` by fp_inv_tac
721+
\\ fs[]
761722
QED
762723

763724
Theorem fp_add_sub_correct_unfold =

0 commit comments

Comments
 (0)