Skip to content

Commit 121d8a8

Browse files
committed
Add a syntactic criterion to simplify proving side conditions
1 parent 5ba0ac4 commit 121d8a8

File tree

3 files changed

+313
-60
lines changed

3 files changed

+313
-60
lines changed

icing/examples/exampleLib.sml

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -616,10 +616,10 @@ fun write_to_file prog_def = let
616616
val _ = print ("Program pretty printed to " ^ filename ^ "\n")
617617
in () end
618618
619-
val _ = intermediate_prog_prefix := "rigidBody_unopt_";
619+
val _ = intermediate_prog_prefix := "test03_unopt_";
620620
val backend_config_def = arm7_backend_config_def
621621
val cbv_to_bytes = cbv_to_bytes_arm7
622-
val name = "rigidBodyUnoptProg"
622+
val name = "test03UnoptProg"
623623
val prog_def = (Parse.Term ‘
624624
APPEND ^(reader_def |> concl |> rhs)
625625
(APPEND ^(intToFP_def |> concl |> rhs)
@@ -638,7 +638,7 @@ val data_prog_def = definition(mk_abbrev_name data_prog_name)
638638
Overload monad_unitbind[local] = ``data_monad$bind``
639639
Overload return[local] = ``data_monad$return``
640640
val _ = monadsyntax.temp_add_monadsyntax()
641-
val _ = install_naming_overloads "scratch";
641+
val _ = install_naming_overloads "test01_sum3ProgComp";
642642
643643
val _ = write_to_file data_prog_def;
644644
**)
@@ -835,15 +835,17 @@ 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’
846-
val _ = computeLib.add_funs [list_result_rw, list_result_cond_rw]
845+
[^body] = (st2, Rval [FP_WordTree fp])) ∧ (compress_word fp = w))’
846+
val body_doubleExpPlan = store_thm ("body_doubleExpPlan",
847+
Parse.Term ‘isDoubleExpPlan ^body no_fp_opt_conf (HD theAST_plan)’,
848+
EVAL_TAC);
847849
val freeVars_list_body = store_thm ("freeVars_list_body",
848850
Parse.Term ‘
849851
∀ (st1:unit semanticPrimitives$state) st2.
@@ -853,26 +855,9 @@ val _ = write_to_file data_prog_def;
853855
no_fp_opt_conf
854856
(HD theAST_plan)
855857
^body’,
856-
rpt strip_tac
857-
\\ gs[theAST_plan_result, freeVars_plan_bound_def, freeVars_arithExp_bound_def, EVERYi_def]
858-
\\ rpt conj_tac
859-
(* Non-let goals automatically solved *)
860-
\\ rpt (
861-
gs[freeVars_fp_bound_def, extend_env_with_vars_def, EVERYi_def]
862-
\\ qmatch_goalsub_abbrev_tac ‘freeVars_arithExp_bound st1 st2 theAST_env_new _ _ rewrittenExp’
863-
\\ qpat_x_assum ‘Abbrev(rewrittenExp = _)’ (assume_tac o EVAL_RULE)
864-
\\ unabbrev_all_tac \\ gs[freeVars_arithExp_bound_def]
865-
\\ rpt strip_tac \\ gs[freeVars_fp_bound_def, EVERYi_def]
866-
\\ rpt (qpat_x_assum `evaluate _ _ _ = _` (fn th => mp_tac (EVAL_RULE th)) )
867-
\\ rpt strip_tac \\ rveq
868-
\\ gs[freeVars_fp_bound_def, extend_env_with_vars_def])
869-
\\ rpt strip_tac \\ gs[freeVars_arithExp_bound_def, freeVars_fp_bound_def, EVERYi_def]
870-
\\ rpt (qpat_x_assum `_ = (_, Rval _)` (fn th => mp_tac (EVAL_RULE th)) )
871-
\\ rpt strip_tac \\ rveq
872-
\\ gs[freeVars_fp_bound_def, namespaceTheory.nsOptBind_def, NULL, listTheory.REV_DEF,
873-
semanticPrimitivesTheory.fp_translate_def,
874-
ml_progTheory.nsLookup_nsBind_compute,extend_env_with_vars_def, list_result_cond_rw]
875-
\\ rveq \\ gs[])
858+
irule isDoubleExpPlan_freeVars_plan_bound_def \\ conj_tac
859+
\\ gs[body_doubleExpPlan, freeVars_fp_bound_def, extend_env_with_vars_def]
860+
\\ rpt strip_tac \\ gs[])
876861
val freeVars_real_list_body = store_thm ("freeVars_real_list_body",
877862
Parse.Term ‘
878863
∀ (st1:unit semanticPrimitives$state) st2.
@@ -881,28 +866,9 @@ val _ = write_to_file data_prog_def;
881866
toRspace (extend_env_with_vars (REVERSE ^fvars) (REVERSE ^argList) (theAST_env).v))
882867
no_fp_opt_conf (HD theAST_plan)
883868
^body’,
884-
rpt strip_tac
885-
\\ gs[theAST_plan_result, freeVars_realPlan_bound_def,
886-
freeVars_realExp_bound_def, EVERYi_def, toRspace_def, extend_env_with_vars_def]
887-
\\ rpt conj_tac
888-
(* Non-let goals automatically solved *)
889-
\\ rpt (gs[freeVars_real_bound_def, extend_env_with_vars_def, EVERYi_def,
890-
nsMap_nsBind]
891-
\\ qmatch_goalsub_abbrev_tac ‘freeVars_realExp_bound _ _ theAST_env_new _ _ rewrittenExp’
892-
\\ qpat_x_assum ‘Abbrev(rewrittenExp = _)’ (assume_tac o EVAL_RULE)
893-
\\ unabbrev_all_tac \\ gs[freeVars_realExp_bound_def]
894-
\\ rpt strip_tac \\ gs[freeVars_real_bound_def, EVERYi_def]
895-
\\ rpt (qpat_x_assum `evaluate _ _ _ = _` (fn th => mp_tac (EVAL_RULE th)) )
896-
\\ rpt (COND_CASES_TAC \\ gs[semanticPrimitivesTheory.do_app_def])
897-
\\ rpt strip_tac \\ rveq
898-
\\ gs[freeVars_realExp_bound_def, freeVars_real_bound_def, extend_env_with_vars_def])
899-
\\ rpt strip_tac \\ gs[freeVars_real_bound_def, EVERYi_def]
900-
\\ rpt (qpat_x_assum `evaluate _ _ _ = _` (fn th => mp_tac (EVAL_RULE th)) )
901-
\\ rpt (COND_CASES_TAC \\ gs[semanticPrimitivesTheory.do_app_def])
902-
\\ rpt strip_tac \\ rveq
903-
\\ rpt strip_tac \\ gs[freeVars_real_bound_def,
904-
ml_progTheory.nsLookup_nsBind_compute, namespaceTheory.nsOptBind_def,
905-
toRspace_def, nsMap_nsBind])
869+
irule isDoubleExpPlan_freeVars_realPlan_bound_def \\ conj_tac
870+
\\ gs[body_doubleExpPlan, freeVars_real_bound_def, extend_env_with_vars_def, toRspace_def]
871+
\\ rpt strip_tac \\ gs[nsMap_nsBind])
906872
val theAST_opt_backward_sim = store_thm ("theAST_opt_backward_sim",
907873
Parse.Term ‘theAST_opt_float_option_noopt ^args = SOME w ⇒
908874
theAST_float_returns ^args (compress_word w)’,

icing/icing_rewriterProofsScript.sml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,25 @@ Proof
277277
\\ rpt strip_tac \\ res_tac \\ fs[]
278278
QED
279279

280+
Theorem rewrite_preserves_FV:
281+
∀ rws e eNew P.
282+
(∀ x. x IN FV e ⇒ P x) ∧
283+
rewriteFPexp rws e = eNew ⇒
284+
∀ x. x IN FV eNew ⇒ P x
285+
Proof
286+
Induct_on ‘rws’ \\ gs[rewriteFPexp_def]
287+
\\ rpt strip_tac \\ Cases_on ‘h’ \\ gs[rewriteFPexp_def]
288+
\\ pop_assum mp_tac \\ COND_CASES_TAC \\ gs[]
289+
\\ TOP_CASE_TAC \\ gs[]
290+
>- (first_x_assum $ qspecl_then [‘e’, ‘P’] mp_tac \\ impl_tac \\ gs[])
291+
\\ TOP_CASE_TAC \\ gs[]
292+
>- (first_x_assum $ qspecl_then [‘e’, ‘P’] mp_tac \\ impl_tac \\ gs[])
293+
\\ strip_tac
294+
\\ first_x_assum $ qspecl_then [‘x''’, ‘P’] mp_tac \\ impl_tac \\ gs[]
295+
\\ qspecl_then [‘r’, ‘q’, ‘e’, ‘x''’, ‘x'’, ‘[]’, ‘P’] mp_tac match_preserves_FV
296+
\\ impl_tac \\ gs[substLookup_def]
297+
QED
298+
280299
Theorem isFpArithExp_match_preserved:
281300
∀ rhs lhs e subst eNew.
282301
isFpArithExp e ∧

0 commit comments

Comments
 (0)