Skip to content

Commit 8f782f6

Browse files
committed
Remove val ... = save_thm( automatically
import os import re import sys def match_comment_parens(s, start_idx): if s[start_idx:start_idx + 2] == '(*': paren_count = 0 comment_content = "" for i, char in enumerate(s[start_idx:], start=start_idx): if char == '(' and s[i + 1] == '*': paren_count += 1 elif char == '*' and i + 1 < len(s) and s[i + 1] == ')': paren_count -= 1 comment_content += char if paren_count == 0: comment_content += ")" i += 1 while i + 1 < len(s) and s[i + 1].isspace(): i += 1 comment_content += s[i] return comment_content, i + 1 comment_content += char return None return "", start_idx def transform_definition(s): done_before = 0 pattern = re.compile(r"\nval[ \t]+(?:[a-zA-Z0-9][a-zA-Z0-9_']*|_)\s*=\s*save_thm\s*") match = pattern.search(s, done_before) while match: re_start, re_end = match.span() comment_parens, comment_end = match_comment_parens(s, re_end) if s[comment_end] == '(': paren_count = 0 paren_content = "" for i, char in enumerate(s[comment_end:]): if char == '(': paren_count += 1 elif char == ')': paren_count -= 1 paren_content += char if paren_count == 0: break paren_length = len(paren_content) paren_content = paren_content[1:paren_length-1] match2 = re.search(r"\"\s*(.*)\s*\",\s*(.*)\s*", paren_content, re.DOTALL) if comment_parens == "": replacement = f"\nTheorem {match2.group(1)} =\n {match2.group(2)}" else: replacement = f"\n{comment_parens}\nTheorem {match2.group(1)} =\n {match2.group(2)}" if comment_end + paren_length < len(s) and s[comment_end + paren_length] == ';': s = s[:re_start] + replacement + s[comment_end+paren_length+1:] else: s = s[:re_start] + replacement + s[comment_end+paren_length:] done_before = re_start + len(replacement) else: done_before = comment_end match = pattern.search(s, done_before) return s def process_sml_file(filepath): with open(filepath, 'r') as file: content = file.read() transformed_content = transform_definition(content) with open(filepath, 'w') as file: file.write(transformed_content) def find_and_transform_sml_files(directory): for root, _, files in os.walk(directory): for file in files: if (file.endswith("Script.sml")): filepath = os.path.join(root, file) print(f"Processing file: {filepath}") process_sml_file(filepath) if __name__ == "__main__": if len(sys.argv) != 2: print("Usage: python script.py <directory>") sys.exit(1) directory_to_search = sys.argv[1] if not os.path.isdir(directory_to_search): print(f"Error: {directory_to_search} is not a valid directory.") sys.exit(1) find_and_transform_sml_files(directory_to_search)
1 parent 103027a commit 8f782f6

File tree

119 files changed

+702
-619
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+702
-619
lines changed

basis/IntProgScript.sml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ val result = translate padLen_DEC_eq;
7878
val result = translate maxSmall_DEC_def;
7979

8080
val _ = add_preferred_thy "-";
81-
val _ = save_thm("fromChars_unsafe_ind",
82-
fromChars_unsafe_ind |> REWRITE_RULE[maxSmall_DEC_def,padLen_DEC_eq]);
81+
Theorem fromChars_unsafe_ind =
82+
fromChars_unsafe_ind |> REWRITE_RULE[maxSmall_DEC_def,padLen_DEC_eq]
8383
val result = translate (fromChars_unsafe_def
8484
|> REWRITE_RULE[maxSmall_DEC_def,padLen_DEC_eq]);
8585

@@ -117,8 +117,8 @@ QED
117117
val result = translate fromChar_thm;
118118
val result = translate fromChars_range_def;
119119

120-
val _ = save_thm("fromChars_ind",
121-
fromChars_ind |> REWRITE_RULE[maxSmall_DEC_def,padLen_DEC_eq]);
120+
Theorem fromChars_ind =
121+
fromChars_ind |> REWRITE_RULE[maxSmall_DEC_def,padLen_DEC_eq]
122122
val result = translate (fromChars_def
123123
|> REWRITE_RULE[maxSmall_DEC_def,padLen_DEC_eq]);
124124

basis/ListProgScript.sml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ val res = translate flat_rev_def;
4545

4646
(* New list-append translation *)
4747
val append_v_thm = trans "@" listSyntax.append_tm;
48-
val _ = save_thm("append_v_thm[allow_rebind]",append_v_thm);
48+
Theorem append_v_thm[allow_rebind] =
49+
append_v_thm
4950

5051
(* Old list-append translation *)
5152
(*val append_v_thm = translate APPEND;*)

basis/basis_ffiScript.sml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,16 +623,16 @@ Proof
623623
\\ metis_tac[]
624624
QED
625625

626-
val basis_ffi_length_thms = save_thm("basis_ffi_length_thms",
626+
Theorem basis_ffi_length_thms =
627627
LIST_CONJ
628628
[ffi_write_length,ffi_read_length,ffi_open_in_length,ffi_open_out_length,
629629
ffi_close_length, clFFITheory.ffi_get_arg_count_length,
630630
clFFITheory.ffi_get_arg_length_length, clFFITheory.ffi_get_arg_length,
631-
ffi_exit_length]);
631+
ffi_exit_length]
632632

633-
val basis_ffi_part_defs = save_thm("basis_ffi_part_defs",
633+
Theorem basis_ffi_part_defs =
634634
LIST_CONJ
635-
[fs_ffi_part_def,clFFITheory.cl_ffi_part_def,runtime_ffi_part_def]);
635+
[fs_ffi_part_def,clFFITheory.cl_ffi_part_def,runtime_ffi_part_def]
636636

637637
(* This is used to show to show one of the parts of parts_ok for the state after a spec *)
638638
Theorem oracle_parts:

basis/pure/mlintScript.sml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ Proof
380380
\\ metis_tac[fromChars_range_lemma,EVERY_DEF]
381381
QED
382382

383-
val fromString_eq_unsafe = save_thm("fromString_eq_unsafe",
384-
fromString_thm |> SIMP_RULE std_ss [GSYM fromString_unsafe_thm]);
383+
Theorem fromString_eq_unsafe =
384+
fromString_thm |> SIMP_RULE std_ss [GSYM fromString_unsafe_thm]
385385

386386
Theorem fromString_toString_Num:
387387
0 ≤ n ⇒ fromString (strlit (num_to_dec_string (Num n))) = SOME n

basis/pure/mllistScript.sml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ Theorem LENGTH_AUX_THM = Q.prove(`
247247
Induct THEN ASM_SIMP_TAC std_ss [LENGTH_AUX_def,LENGTH,ADD1,AC ADD_COMM ADD_ASSOC])
248248
|> Q.SPECL [`xs`,`0`] |> GSYM |> SIMP_RULE std_ss [];
249249

250-
val _ = save_thm("list_compare_def",
251-
ternaryComparisonsTheory.list_compare_def);
250+
Theorem list_compare_def =
251+
ternaryComparisonsTheory.list_compare_def
252252

253253
(* tail-recursive MAP *)
254254

basis/pure/mlstringScript.sml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,11 @@ Theorem TOKENS_eq_tokens_sym
483483
\\ simp[MAP_MAP_o,INJ_DEF,explode_11,o_DEF,explode_implode,TOKENS_eq_tokens]
484484
*)
485485

486-
val TOKENS_eq_tokens_sym = save_thm("TOKENS_eq_tokens_sym",
487-
TOKENS_eq_tokens
486+
Theorem TOKENS_eq_tokens_sym =
487+
TOKENS_eq_tokens
488488
|> SPEC_ALL
489489
|> Q.AP_TERM`MAP implode`
490-
|> SIMP_RULE(srw_ss())[MAP_MAP_o,implode_explode,o_DEF]);
490+
|> SIMP_RULE(srw_ss())[MAP_MAP_o,implode_explode,o_DEF]
491491

492492

493493
Theorem tokens_append:

basis/pure/mlvectorScript.sml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ val _ = new_theory"mlvector"
88

99
val _ = set_grammar_ancestry ["mllist", "regexp_compiler"]
1010

11-
val vector_nchotomy = save_thm("vector_nchotomy",regexp_compilerTheory.vector_nchotomy);
11+
Theorem vector_nchotomy =
12+
regexp_compilerTheory.vector_nchotomy
1213

13-
val sub_def = save_thm("sub_def",regexp_compilerTheory.sub_def);
14+
Theorem sub_def =
15+
regexp_compilerTheory.sub_def
1416

15-
val length_def = save_thm("length_def",regexp_compilerTheory.length_def);
17+
Theorem length_def =
18+
regexp_compilerTheory.length_def
1619

1720
Definition tabulate_def:
1821
tabulate n f = Vector (GENLIST f n)

candle/overloading/ml_kernel/ml_hol_kernel_funsProgScript.sml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ val type_cmp_thm = Q.prove(
347347
|> CONJUNCT1;
348348

349349
val _ = add_preferred_thy "-";
350-
val _ = save_thm("type_cmp_ind",
351-
(fetch "-" "type_compare_ind") |> RW [GSYM type_cmp_thm]);
350+
Theorem type_cmp_ind =
351+
(fetch "-" "type_compare_ind") |> RW [GSYM type_cmp_thm]
352352
val res = translate (type_compare_def |> RW [GSYM type_cmp_thm]);
353353

354354
Definition term_compare_def:
@@ -401,8 +401,8 @@ Proof
401401
QED
402402

403403
val _ = add_preferred_thy "-";
404-
val _ = save_thm("term_cmp_ind",
405-
(fetch "-" "term_compare_ind") |> RW [GSYM term_cmp_thm]);
404+
Theorem term_cmp_ind =
405+
(fetch "-" "term_compare_ind") |> RW [GSYM term_cmp_thm]
406406
val res = translate (term_compare_def |> RW [GSYM term_cmp_thm]);
407407

408408
val res = translate (check [‘ty’] holKernelPmatchTheory.codomain_def);
@@ -458,7 +458,8 @@ val _ = ml_prog_update open_local_block;
458458

459459
val fdM_def = new_definition("fdM_def",``fdM = first_dup``)
460460
val fdM_intro = SYM fdM_def
461-
val fdM_ind = save_thm("fdM_ind",REWRITE_RULE[MEMBER_INTRO]first_dup_ind)
461+
Theorem fdM_ind =
462+
REWRITE_RULE[MEMBER_INTRO]first_dup_ind
462463
val fdM_eqs = REWRITE_RULE[MEMBER_INTRO,fdM_intro]first_dup_def
463464
val def = fdM_eqs |> translate
464465
val def = REWRITE_RULE[fdM_intro]add_constants_def |> m_translate

candle/overloading/syntax/holSyntaxExtraScript.sml

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -701,15 +701,15 @@ End
701701

702702
val _ = Parse.add_infix("subtype",401,Parse.NONASSOC)
703703
Overload subtype =``RTC subtype1``
704-
val subtype_Tyvar = save_thm("subtype_Tyvar",
704+
Theorem subtype_Tyvar =
705705
``ty subtype (Tyvar x)``
706706
|> SIMP_CONV(srw_ss()++boolSimps.DNF_ss)
707-
[Once relationTheory.RTC_CASES2,subtype1_cases])
707+
[Once relationTheory.RTC_CASES2,subtype1_cases]
708708
val _ = export_rewrites["subtype_Tyvar"]
709-
val subtype_Tyapp = save_thm("subtype_Tyapp",
709+
Theorem subtype_Tyapp =
710710
``ty subtype (Tyapp name args)``
711711
|> SIMP_CONV(srw_ss()++boolSimps.DNF_ss)
712-
[Once relationTheory.RTC_CASES2,subtype1_cases])
712+
[Once relationTheory.RTC_CASES2,subtype1_cases]
713713

714714
Theorem subtype_trans:
715715
!x y z. x subtype y /\ y subtype z ==> x subtype z
@@ -869,33 +869,33 @@ End
869869

870870
val _ = Parse.add_infix("subterm",401,Parse.NONASSOC)
871871
Overload subterm = ``RTC subterm1``
872-
val subterm_Var = save_thm("subterm_Var",
872+
Theorem subterm_Var =
873873
``tm subterm (Var x ty)``
874874
|> SIMP_CONV(srw_ss()++boolSimps.DNF_ss)
875-
[Once relationTheory.RTC_CASES2,subterm1_cases])
876-
val subterm_Const = save_thm("subterm_Const",
875+
[Once relationTheory.RTC_CASES2,subterm1_cases]
876+
Theorem subterm_Const =
877877
``tm subterm (Const x ty)``
878878
|> SIMP_CONV(srw_ss()++boolSimps.DNF_ss)
879-
[Once relationTheory.RTC_CASES2,subterm1_cases])
879+
[Once relationTheory.RTC_CASES2,subterm1_cases]
880880
val _ = export_rewrites["subterm_Var","subterm_Const"]
881-
val subterm_Comb = save_thm("subterm_Comb",
881+
Theorem subterm_Comb =
882882
``tm subterm (Comb t1 t2)``
883883
|> SIMP_CONV(srw_ss()++boolSimps.DNF_ss)
884-
[Once relationTheory.RTC_CASES2,subterm1_cases])
885-
val subterm_Abs = save_thm("subterm_Abs",
884+
[Once relationTheory.RTC_CASES2,subterm1_cases]
885+
Theorem subterm_Abs =
886886
``tm subterm (Abs v t)``
887887
|> SIMP_CONV(srw_ss()++boolSimps.DNF_ss)
888-
[Once relationTheory.RTC_CASES2,subterm1_cases])
888+
[Once relationTheory.RTC_CASES2,subterm1_cases]
889889

890-
val subterm_welltyped = save_thm("subterm_welltyped",
890+
Theorem subterm_welltyped =
891891
let val th =
892892
Q.prove(`∀tm ty. tm has_type ty ⇒ ∀t. t subterm tm ⇒ welltyped t`,
893893
ho_match_mp_tac has_type_strongind >>
894894
simp[subterm_Comb,subterm_Abs] >> rw[] >>
895895
rw[] >> imp_res_tac WELLTYPED_LEMMA >> simp[])
896896
in METIS_PROVE[th,welltyped_def]
897897
``∀t tm. welltyped tm ∧ t subterm tm ⇒ welltyped t``
898-
end)
898+
end
899899

900900
(* term ordering *)
901901

@@ -1598,13 +1598,13 @@ Proof
15981598
transitive_alpha_lt, antisymmetric_alpha_lt]
15991599
QED
16001600

1601-
val hypset_ok_append = save_thm("hypset_ok_append",
1601+
Theorem hypset_ok_append =
16021602
Q.ISPEC`alpha_lt` sortingTheory.SORTED_APPEND_GEN
1603-
|> REWRITE_RULE[GSYM hypset_ok_def])
1603+
|> REWRITE_RULE[GSYM hypset_ok_def]
16041604

1605-
val hypset_ok_el_less = save_thm("hypset_ok_el_less",
1605+
Theorem hypset_ok_el_less =
16061606
MATCH_MP sortingTheory.SORTED_EL_LESS transitive_alpha_lt
1607-
|> REWRITE_RULE[GSYM hypset_ok_def])
1607+
|> REWRITE_RULE[GSYM hypset_ok_def]
16081608

16091609
(* term_union lemmas *)
16101610

@@ -3484,7 +3484,8 @@ End
34843484

34853485
val variant_ind = fetch "-" "variant_ind"
34863486

3487-
val variant_vsubst_thm = save_thm("variant_vsubst_thm",prove(
3487+
Theorem variant_vsubst_thm =
3488+
prove(
34883489
``!xs v x name.
34893490
(xs = [x]) /\ (v = (Var name ty)) ==>
34903491
(variant xs (Var name ty) =
@@ -3518,10 +3519,10 @@ val variant_vsubst_thm = save_thm("variant_vsubst_thm",prove(
35183519
\\ `VARIANT_PRIMES x (STRCAT (explode name) "'") ty < n \/
35193520
n < VARIANT_PRIMES x (STRCAT (explode name) "'") ty` by DECIDE_TAC
35203521
\\ RES_TAC \\ FULL_SIMP_TAC std_ss [])
3521-
|> SIMP_RULE std_ss [] |> SPEC_ALL);
3522+
|> SIMP_RULE std_ss [] |> SPEC_ALL
35223523

3523-
val VSUBST_thm = save_thm("VSUBST_thm",
3524-
REWRITE_RULE[SYM variant_vsubst_thm] VSUBST_def)
3524+
Theorem VSUBST_thm =
3525+
REWRITE_RULE[SYM variant_vsubst_thm] VSUBST_def
35253526

35263527
Definition subtract_def:
35273528
subtract l1 l2 = FILTER (\t. ~(MEM t l2)) l1
@@ -3577,7 +3578,8 @@ Proof
35773578
\\ REPEAT STRIP_TAC \\ EQ_TAC \\ REPEAT STRIP_TAC \\ METIS_TAC []
35783579
QED
35793580

3580-
val variant_inst_thm = save_thm("variant_inst_thm",prove(
3581+
Theorem variant_inst_thm =
3582+
prove(
35813583
``!xs v x name a.
35823584
welltyped a ∧
35833585
(xs = frees a) /\
@@ -3624,7 +3626,7 @@ val variant_inst_thm = save_thm("variant_inst_thm",prove(
36243626
\\ REPEAT STRIP_TAC
36253627
\\ `k < n \/ n < k` by DECIDE_TAC
36263628
\\ RES_TAC \\ FULL_SIMP_TAC std_ss [])
3627-
|> SIMP_RULE std_ss [] |> SPEC_ALL);
3629+
|> SIMP_RULE std_ss [] |> SPEC_ALL
36283630

36293631
Theorem INST_CORE_Abs_thm:
36303632
∀v t env tyin. welltyped (Abs v t) ⇒
@@ -3734,16 +3736,16 @@ QED
37343736
(* some derived rules *)
37353737

37363738
val assume = proves_rules |> CONJUNCTS |> el 2
3737-
val deductAntisym_equation = save_thm("deductAntisym_equation",
3738-
proves_rules |> CONJUNCTS |> el 4)
3739-
val eqMp_equation = save_thm("eqMp_equation",
3739+
Theorem deductAntisym_equation =
3740+
proves_rules |> CONJUNCTS |> el 4
3741+
Theorem eqMp_equation =
37403742
proves_rules |> CONJUNCTS |> el 5
3741-
|> REWRITE_RULE[GSYM AND_IMP_INTRO])
3742-
val refl_equation = save_thm("refl_equation",
3743-
proves_rules |> CONJUNCTS |> el 9)
3744-
val appThm_equation = save_thm("appThm_equation",
3743+
|> REWRITE_RULE[GSYM AND_IMP_INTRO]
3744+
Theorem refl_equation =
3745+
proves_rules |> CONJUNCTS |> el 9
3746+
Theorem appThm_equation =
37453747
proves_rules |> CONJUNCTS |> el 8
3746-
|> REWRITE_RULE[GSYM AND_IMP_INTRO])
3748+
|> REWRITE_RULE[GSYM AND_IMP_INTRO]
37473749

37483750
Theorem addAssum:
37493751
∀thy h c a. (thy,h) |- c ∧ term_ok (sigof thy) a ∧ (a has_type Bool) ⇒

candle/overloading/syntax/holSyntaxScript.sml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ Proof
3636
REPEAT STRIP_TAC \\ EVAL_TAC
3737
QED
3838

39-
val _ = save_thm("domain_raw[allow_rebind]",domain_raw);
40-
val _ = save_thm("codomain_raw[allow_rebind]",codomain_raw);
39+
Theorem domain_raw[allow_rebind] =
40+
domain_raw
41+
Theorem codomain_raw[allow_rebind] =
42+
codomain_raw
4143

4244
fun type_rec_tac proj =
4345
(WF_REL_TAC(`measure (type_size o `@[QUOTE proj]@`)`) >> simp[] >>

0 commit comments

Comments
 (0)