author | wneuper <walther.neuper@jku.at> |
Mon, 19 Jul 2021 18:29:46 +0200 | |
changeset 60337 | cbad4e18e91b |
parent 60309 | 70a1d102660d |
child 60436 | 1c8263e775d4 |
permissions | -rw-r--r-- |
walther@59618 | 1 |
(* Title: ProgLang/Program.thy |
walther@59618 | 2 |
Author: Walther Neuper, Sep.2019 |
walther@59618 | 3 |
(c) due to copyright terms |
walther@59618 | 4 |
*) |
walther@59618 | 5 |
|
walther@59618 | 6 |
theory Program |
wenzelm@60192 | 7 |
imports "$ISABELLE_ISAC/BaseDefinitions/BaseDefinitions" |
walther@59618 | 8 |
begin |
walther@59618 | 9 |
|
walther@59618 | 10 |
text \<open>Abstract: |
walther@59619 | 11 |
Theorems required by Isac's rewrite engine for evaluating assumptions of theorems/rules. |
walther@59619 | 12 |
Basic functions for Isac programs and theorems |
walther@59618 | 13 |
\<close> |
walther@59618 | 14 |
|
walther@59619 | 15 |
subsection \<open>General constants: TODO shift to appropriate files\<close> |
walther@59619 | 16 |
consts |
walther@59619 | 17 |
Arbfix :: "real" |
walther@59619 | 18 |
Undef :: "real" (* WN190823 probably an outdated design for DiffApp *) |
walther@59842 | 19 |
bool_undef :: "bool" |
walther@59619 | 20 |
|
walther@59619 | 21 |
subsection \<open>Theorems specific for evaluation of assumptions of theorems/rules\<close> |
walther@59619 | 22 |
axiomatization where |
walther@59619 | 23 |
rle_refl: "(n::real) <= n" and |
walther@59619 | 24 |
not_true: "(~ True) = False" and |
walther@59619 | 25 |
not_false: "(~ False) = True" and |
walther@59619 | 26 |
and_true: "(a & True) = a" and |
walther@59619 | 27 |
and_false: "(a & False) = False" and |
walther@59619 | 28 |
or_true: "(a | True) = True" and |
walther@59619 | 29 |
or_false: "(a | False) = a" and |
walther@59619 | 30 |
and_commute: "(a & b) = (b & a)" and |
walther@59619 | 31 |
or_commute: "(a | b) = (b | a)" |
walther@59619 | 32 |
|
walther@59619 | 33 |
subsection \<open>TODO\<close> |
walther@59618 | 34 |
ML \<open> |
walther@59618 | 35 |
\<close> ML \<open> |
walther@59618 | 36 |
signature PROGRAM = |
walther@59861 | 37 |
sig |
walther@59861 | 38 |
type T |
walther@59861 | 39 |
datatype leaf = Expr of term | Tac of term |
walther@59861 | 40 |
val rep_stacexpr: leaf -> term |
walther@59861 | 41 |
val prep_program : thm -> term (*ren prepare*) |
walther@59861 | 42 |
val get_fun_id: term -> string * typ (*ren fun_id*) |
walther@59861 | 43 |
val formal_args : term -> term list |
walther@59861 | 44 |
val body_of : term -> term (*ren body*) |
walther@59861 | 45 |
|
walther@59861 | 46 |
val to_string: Rule_Def.program -> string |
walther@59861 | 47 |
end |
walther@59618 | 48 |
\<close> ML \<open> |
walther@59618 | 49 |
\<close> ML \<open> |
walther@59618 | 50 |
\<close> |
walther@59618 | 51 |
ML \<open> |
walther@59618 | 52 |
\<close> ML \<open> |
walther@59618 | 53 |
(**) |
walther@59618 | 54 |
structure Program(**): PROGRAM(**) = |
walther@59618 | 55 |
struct |
walther@59618 | 56 |
(**) |
walther@59618 | 57 |
|
walther@59773 | 58 |
type T = Rule.program |
walther@59773 | 59 |
|
walther@59717 | 60 |
datatype leaf = Tac of term | Expr of term |
walther@59717 | 61 |
fun rep_stacexpr (Tac t ) = t |
walther@59717 | 62 |
| rep_stacexpr (Expr t) = |
walther@59962 | 63 |
raise ERROR ("rep_stacexpr called with t= " ^ UnparseC.term t); |
walther@59717 | 64 |
|
walther@59816 | 65 |
(* the lucas-interpreter LI requires programs in this specific format *) |
walther@59618 | 66 |
fun prep_program thm = (thm |
walther@59618 | 67 |
|> Thm.prop_of |
walther@59618 | 68 |
|> HOLogic.dest_Trueprop |
walther@59618 | 69 |
|> Logic.unvarify_global |
walther@60337 | 70 |
|> TermC.inst_abs) |
walther@59618 | 71 |
handle TERM _ => raise TERM ("prep_program", [Thm.prop_of thm]) |
walther@59618 | 72 |
|
walther@59618 | 73 |
(* get identifier of partial_function *) |
wenzelm@60309 | 74 |
fun get_fun_id (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ fun_and_args $ _) = |
walther@59618 | 75 |
fun_and_args |> strip_comb |> fst |> dest_Const |
walther@59618 | 76 |
| get_fun_id t = raise TERM ("get_fun_id", [t]) |
walther@59618 | 77 |
|
walther@59618 | 78 |
(* get the arguments of the script out of the scripts parsetree *) |
walther@59618 | 79 |
fun formal_args tm = (tm |
walther@59618 | 80 |
|> HOLogic.dest_eq |
walther@59618 | 81 |
|> fst |
walther@59618 | 82 |
|> strip_comb |
walther@59618 | 83 |
|> snd) |
walther@59618 | 84 |
handle TERM _ => raise TERM ("formal_args", [tm]) |
walther@59618 | 85 |
|
walther@59618 | 86 |
(* get the body of a program *) |
walther@59618 | 87 |
fun body_of tm = (tm |
walther@59618 | 88 |
|> HOLogic.dest_eq |
walther@59618 | 89 |
|> snd) |
walther@59618 | 90 |
handle TERM _ => raise TERM ("body_of", [tm]) |
walther@59618 | 91 |
|
walther@59878 | 92 |
fun to_string Rule_Def.Empty_Prog = "Empty_Prog" |
walther@59868 | 93 |
| to_string (Rule_Def.Prog s) = "Prog " ^ UnparseC.term s |
walther@59861 | 94 |
| to_string (Rule_Def.Rfuns _) = "Rfuns"; |
walther@59861 | 95 |
|
walther@59618 | 96 |
|
walther@59717 | 97 |
(**)end(**) |
walther@59618 | 98 |
\<close> ML \<open> |
walther@59618 | 99 |
\<close> ML \<open> |
walther@59618 | 100 |
\<close> |
walther@59618 | 101 |
|
walther@59618 | 102 |
end |