src/Tools/isac/BaseDefinitions/thmC-def.sml
author Walther Neuper <walther.neuper@jku.at>
Tue, 14 Apr 2020 12:39:26 +0200
changeset 59874 820bf0840029
parent 59872 cea2815f65ed
child 59875 995177b6d786
permissions -rw-r--r--
reorganise struct. ThmC, part 3 end
walther@59866
     1
(* Title:  BaseDefinitions/thmC-def.sml
walther@59858
     2
   Author: Walther Neuper
walther@59858
     3
   (c) due to copyright terms
walther@59858
     4
walther@59865
     5
Probably this structure can be dropped due to improved reflection in Isabelle.
walther@59858
     6
*)
walther@59865
     7
signature THEOREM_ISAC_DEF =
walther@59858
     8
sig
walther@59874
     9
  type T
walther@59874
    10
  eqtype id
walther@59861
    11
walther@59865
    12
  val string_of_thmI: thm -> string
walther@59874
    13
  val thms2str : thm list -> string
walther@59861
    14
walther@59874
    15
(* required for ProgLang/ListC BEFORE definition in ------vvv   *)
walther@59874
    16
  val int_of_str_opt: string -> int option  (* belongs to TermC *)
walther@59871
    17
  val numerals_to_Free: thm -> thm          (* belongs to ThmC  *)
walther@59871
    18
  val numbers_to_string: term -> term       (* belongs to TermC *)
walther@59871
    19
  val uminus_to_string: term -> term        (* belongs to TermC *)
walther@59871
    20
walther@59874
    21
  val make_thm: theory -> term -> thm
walther@59874
    22
walther@59858
    23
(* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
walther@59874
    24
  (*NONE*)
walther@59858
    25
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
walther@59874
    26
  (*NONE*)
walther@59858
    27
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
walther@59858
    28
end
walther@59858
    29
walther@59858
    30
(**)
walther@59865
    31
structure ThmC_Def(**): THEOREM_ISAC_DEF(**) =
walther@59858
    32
struct
walther@59858
    33
(**)
walther@59858
    34
walther@59874
    35
type id = string; (* key into KEStore, without point *)
walther@59874
    36
type T = id * Thm.thm;
walther@59861
    37
walther@59858
    38
walther@59874
    39
fun string_of_thm thm = UnparseC.term_in_ctxt (ThyC.thy2ctxt' "Isac_Knowledge") (Thm.prop_of thm)
walther@59858
    40
(*check for [.] as caused by "fun assoc_thm'"*)
walther@59858
    41
fun string_of_thmI thm =
walther@59858
    42
  let 
walther@59858
    43
    val str = (de_quote o string_of_thm) thm
walther@59858
    44
    val (a, b) = split_nlast (5, Symbol.explode str)
walther@59858
    45
  in 
walther@59858
    46
    case b of
walther@59858
    47
      [" ", " ","[", ".", "]"] => implode a
walther@59858
    48
    | _ => str
walther@59858
    49
  end
walther@59858
    50
walther@59874
    51
fun thm2str thm =
walther@59874
    52
  let
walther@59874
    53
    val t = Thm.prop_of thm
walther@59874
    54
    val ctxt = Proof_Context.init_global (Thy_Info.get_theory ("Isac.Isac_Knowledge"))
walther@59874
    55
    val ctxt' = Config.put show_markup false ctxt
walther@59874
    56
  in Print_Mode.setmp [] (Syntax.string_of_term ctxt') t end;
walther@59874
    57
fun thms2str thms = (strs2str o (map thm2str)) thms
walther@59861
    58
walther@59871
    59
fun int_of_str_opt str = 
walther@59871
    60
  let
walther@59871
    61
    val ss = Symbol.explode str
walther@59871
    62
    val ss' = case ss of "(" :: s => drop_last s | _ => ss
walther@59871
    63
    val (sign, istr) = case ss' of "-" :: istr => (~1, istr) | _ => (1, ss')
walther@59871
    64
  in
walther@59871
    65
    case Library.read_int istr of (i, []) => SOME (sign * i) | _ => NONE
walther@59871
    66
  end;
walther@59871
    67
walther@59871
    68
walther@59874
    69
(** transform Isabelle's binary numerals to "Free (string, T)" **)
walther@59874
    70
walther@59874
    71
val numbers_to_string = (* Makarius 100308 *)
walther@59871
    72
  let
walther@59871
    73
    fun dest_num t =
walther@59871
    74
      (case try HOLogic.dest_number t of
walther@59872
    75
        SOME (T, i) => SOME (Free (signed_string_of_int i, T))
walther@59871
    76
      | NONE => NONE);
walther@59871
    77
    fun to_str (Abs (x, T, b)) = Abs (x, T, to_str b)
walther@59871
    78
      | to_str (t as (u1 $ u2)) =
walther@59872
    79
          (case dest_num t of SOME t' => t' | NONE => to_str u1 $ to_str u2)
walther@59871
    80
      | to_str t = perhaps dest_num t;
walther@59871
    81
  in to_str end
walther@59871
    82
val uminus_to_string =
walther@59871
    83
  let
walther@59871
    84
	  fun dest_num t =
walther@59871
    85
	    case t of
walther@59871
    86
	      (Const ("Groups.uminus_class.uminus", _) $ Free (s, T)) => 
walther@59871
    87
	        (case int_of_str_opt s of
walther@59871
    88
	          SOME i => SOME (Free (signed_string_of_int (~1 * i), T))
walther@59871
    89
	        | NONE => NONE)
walther@59871
    90
	    | _ => NONE;
walther@59871
    91
    fun to_str (Abs (x, T, b)) = Abs (x, T, to_str b)
walther@59871
    92
      | to_str (t as (u1 $ u2)) =
walther@59871
    93
          (case dest_num t of SOME t' => t' | NONE => to_str u1 $ to_str u2)
walther@59871
    94
      | to_str t = perhaps dest_num t;
walther@59871
    95
  in to_str end;
walther@59871
    96
fun numerals_to_Free thm =
walther@59871
    97
  let
walther@59871
    98
    val (deriv, 
walther@59871
    99
	   {cert = cert, tags = tags, maxidx = maxidx, shyps = shyps, 
walther@59871
   100
	    hyps = hyps, tpairs = tpairs, prop = prop}) = Thm.rep_thm_G thm
walther@59871
   101
    val prop' = numbers_to_string prop;
walther@59871
   102
  in Thm.assbl_thm deriv cert tags maxidx shyps hyps tpairs prop' end;
walther@59871
   103
walther@59874
   104
fun make_thm thy t = Thm.make_thm (Thm.global_cterm_of thy t);
walther@59874
   105
walther@59858
   106
(**)end(**)