1 (* Title: ProgLang/Program.thy
2 Author: Walther Neuper, Sep.2019
3 (c) due to copyright terms
7 imports "$ISABELLE_ISAC/BaseDefinitions/BaseDefinitions"
11 Theorems required by Isac's rewrite engine for evaluating assumptions of theorems/rules.
12 Basic functions for Isac programs and theorems
15 subsection \<open>General constants: TODO shift to appropriate files\<close>
18 Undef :: "real" (* WN190823 probably an outdated design for DiffApp *)
21 subsection \<open>Theorems specific for evaluation of assumptions of theorems/rules\<close>
23 rle_refl: "(n::real) <= n" and
24 not_true: "(~ True) = False" and
25 not_false: "(~ False) = True" and
26 and_true: "(a & True) = a" and
27 and_false: "(a & False) = False" and
28 or_true: "(a | True) = True" and
29 or_false: "(a | False) = a" and
30 and_commute: "(a & b) = (b & a)" and
31 or_commute: "(a | b) = (b | a)"
33 subsection \<open>TODO\<close>
39 datatype leaf = Expr of term | Tac of term
40 val rep_stacexpr: leaf -> term
41 val prep_program : thm -> term (*ren prepare*)
42 val get_fun_id: term -> string * typ (*ren fun_id*)
43 val formal_args : term -> term list
44 val body_of : term -> term (*ren body*)
46 val to_string: Rule_Def.program -> string
54 structure Program(**): PROGRAM(**) =
60 datatype leaf = Tac of term | Expr of term
61 fun rep_stacexpr (Tac t ) = t
62 | rep_stacexpr (Expr t) =
63 raise ERROR ("rep_stacexpr called with t= " ^ UnparseC.term t);
65 (* the lucas-interpreter LI requires programs in this specific format *)
66 fun prep_program thm = (thm
68 |> HOLogic.dest_Trueprop
69 |> Logic.unvarify_global
71 handle TERM _ => raise TERM ("prep_program", [Thm.prop_of thm])
73 (* get identifier of partial_function *)
74 fun get_fun_id (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ fun_and_args $ _) =
75 fun_and_args |> strip_comb |> fst |> dest_Const
76 | get_fun_id t = raise TERM ("get_fun_id", [t])
78 (* get the arguments of the script out of the scripts parsetree *)
79 fun formal_args tm = (tm
84 handle TERM _ => raise TERM ("formal_args", [tm])
86 (* get the body of a program *)
90 handle TERM _ => raise TERM ("body_of", [tm])
92 fun to_string Rule_Def.Empty_Prog = "Empty_Prog"
93 | to_string (Rule_Def.Prog s) = "Prog " ^ UnparseC.term s
94 | to_string (Rule_Def.Rfuns _) = "Rfuns";