src/Tools/isac/ProgLang/Program.thy
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--
cleanup after "eliminate ThmC.numerals_to_Free"
     1 (* Title:  ProgLang/Program.thy
     2    Author: Walther Neuper, Sep.2019
     3    (c) due to copyright terms
     4 *)
     5 
     6 theory Program
     7   imports "$ISABELLE_ISAC/BaseDefinitions/BaseDefinitions"
     8 begin
     9 
    10 text \<open>Abstract:
    11   Theorems required by Isac's rewrite engine for evaluating assumptions of theorems/rules.
    12   Basic functions for Isac programs and theorems
    13 \<close>
    14 
    15 subsection \<open>General constants: TODO shift to appropriate files\<close>
    16 consts
    17   Arbfix :: "real"
    18   Undef :: "real"  (* WN190823 probably an outdated design for DiffApp *)
    19   bool_undef :: "bool"
    20 
    21 subsection \<open>Theorems specific for evaluation of assumptions of theorems/rules\<close>
    22 axiomatization where
    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)" 
    32 
    33 subsection \<open>TODO\<close>
    34 ML \<open>
    35 \<close> ML \<open>
    36 signature PROGRAM =
    37 sig
    38   type T
    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*)
    45 
    46   val to_string: Rule_Def.program -> string
    47 end
    48 \<close> ML \<open>
    49 \<close> ML \<open>
    50 \<close> 
    51 ML \<open>
    52 \<close> ML \<open>
    53 (**)
    54 structure Program(**): PROGRAM(**) =
    55 struct
    56 (**)
    57 
    58 type T = Rule.program
    59 
    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);
    64 
    65 (* the lucas-interpreter LI requires programs in this specific format *)
    66 fun prep_program thm = (thm
    67   |> Thm.prop_of
    68   |> HOLogic.dest_Trueprop
    69   |> Logic.unvarify_global
    70   |> TermC.inst_abs)
    71   handle TERM _ => raise TERM ("prep_program", [Thm.prop_of thm])
    72 
    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])
    77 
    78 (* get the arguments of the script out of the scripts parsetree *)
    79 fun formal_args tm = (tm
    80   |> HOLogic.dest_eq
    81   |> fst
    82   |> strip_comb
    83   |> snd)
    84   handle TERM _ => raise TERM ("formal_args", [tm])
    85 
    86 (* get the body of a program *)
    87 fun body_of tm = (tm
    88   |> HOLogic.dest_eq
    89   |> snd)
    90   handle TERM _ => raise TERM ("body_of", [tm])
    91 
    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";
    95 
    96 
    97 (**)end(**)
    98 \<close> ML \<open>
    99 \<close> ML \<open>
   100 \<close>
   101 
   102 end