src/Tools/isac/Interpret/thy-read.sml
author Walther Neuper <walther.neuper@jku.at>
Tue, 28 Apr 2020 16:51:36 +0200
changeset 59916 2c0c34b18050
child 59919 3a7fb975af9d
permissions -rw-r--r--
separate struct.Thy_Read
walther@59916
     1
(* Interpret/thy-read.sml
walther@59916
     2
   authors: Walther Neuper 2002, 2006
walther@59916
     3
  (c) due to copyright terms
walther@59916
     4
walther@59916
     5
tools for rewriting, reverse rewriting, context to thy concerning rewriting
walther@59916
     6
*)
walther@59916
     7
walther@59916
     8
signature THEORY_STORE_READ =
walther@59916
     9
sig
walther@59916
    10
  val thy_containing_thm : string -> string * string
walther@59916
    11
  val thy_containing_rls : ThyC.id -> Rule_Set.id -> string * ThyC.id
walther@59916
    12
  val thy_containing_cal : ThyC.id -> Exec_Def.prog_calcID -> string * string
walther@59916
    13
walther@59916
    14
(* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
walther@59916
    15
  (*  NONE *)
walther@59916
    16
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
walther@59916
    17
  val isabthys: unit -> theory list
walther@59916
    18
  val knowthys: unit -> theory list
walther@59916
    19
  val partID': ThyC.id -> string
walther@59916
    20
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
walther@59916
    21
end 
walther@59916
    22
(**)
walther@59916
    23
structure Thy_Read(**): THEORY_STORE_READ(**) =
walther@59916
    24
struct
walther@59916
    25
(**)
walther@59916
    26
walther@59916
    27
(* group the theories defined in Isac, compare Build_Thydata:
walther@59916
    28
  section "Get and group the theories defined in Isac" *) 
walther@59916
    29
fun isabthys () = (*["Complex_Main", "Taylor", .., "Pure"]*)
walther@59916
    30
  let
walther@59916
    31
    val allthys = Theory.ancestors_of (ThyC.get_theory "Build_Thydata")
walther@59916
    32
  in
walther@59916
    33
    drop ((find_index (curry Context.eq_thy (Thy_Info.get_theory "Complex_Main")) allthys), allthys)
walther@59916
    34
  end
walther@59916
    35
fun knowthys () = (*["Isac_Knowledge", .., "Descript"]*)
walther@59916
    36
  let
walther@59916
    37
    fun isacthys () = (* ["Isac_Knowledge", .., "Know_Store"] without Build_Isac thys: "Interpret" etc *)
walther@59916
    38
      let
walther@59916
    39
        val allthys = filter_out (member Context.eq_thy
walther@59916
    40
          [(*Thy_Info_get_theory "ProgLang",*) ThyC.get_theory "Interpret", 
walther@59916
    41
            ThyC.get_theory "MathEngine", ThyC.get_theory "BridgeLibisabelle"]) 
walther@59916
    42
          (Theory.ancestors_of (ThyC.get_theory "Build_Thydata"))
walther@59916
    43
      in
walther@59916
    44
        take ((find_index (curry Context.eq_thy (Thy_Info.get_theory "Complex_Main")) allthys), 
walther@59916
    45
        allthys)
walther@59916
    46
      end
walther@59916
    47
    val isacthys' = isacthys ()
walther@59916
    48
    val proglang_parent = ThyC.get_theory "ProgLang"
walther@59916
    49
  in
walther@59916
    50
    take ((find_index (curry Context.eq_thy proglang_parent) isacthys'), isacthys')
walther@59916
    51
  end
walther@59916
    52
fun progthys () = (*["Isac_Knowledge", .., "Descript"]*)
walther@59916
    53
  let
walther@59916
    54
    fun isacthys () = (* ["Isac_Knowledge", .., "Know_Store"] without Build_Isac thys: "Interpret" etc *)
walther@59916
    55
      let                                                        
walther@59916
    56
        val allthys = filter_out (member Context.eq_thy
walther@59916
    57
          [(*Thy_Info_get_theory "ProgLang",*) ThyC.get_theory "Interpret", 
walther@59916
    58
            ThyC.get_theory "MathEngine", ThyC.get_theory "BridgeLibisabelle"]) 
walther@59916
    59
          (Theory.ancestors_of (ThyC.get_theory "Build_Thydata"))
walther@59916
    60
      in
walther@59916
    61
        take ((find_index (curry Context.eq_thy (Thy_Info.get_theory "Complex_Main")) allthys), 
walther@59916
    62
        allthys)
walther@59916
    63
      end
walther@59916
    64
    val isacthys' = isacthys ()
walther@59916
    65
    val proglang_parent = ThyC.get_theory "ProgLang"
walther@59916
    66
  in
walther@59916
    67
    drop ((find_index (curry Context.eq_thy proglang_parent) isacthys') + 1(*ProgLang*), isacthys')
walther@59916
    68
  end
walther@59916
    69
fun partID thy = 
walther@59916
    70
  if member Context.eq_thy (knowthys ()) thy then "IsacKnowledge"
walther@59916
    71
  else if member Context.eq_thy (progthys ()) thy then "IsacScripts"
walther@59916
    72
  else if member Context.eq_thy (isabthys ()) thy then "Isabelle"
walther@59916
    73
  else error ("closure of thys in Isac is broken by " ^ Context.theory_name thy)
walther@59916
    74
fun partID' thy' = partID (ThyC.get_theory thy')
walther@59916
    75
walther@59916
    76
fun thy_containing_thm thmDeriv =
walther@59916
    77
  let
walther@59916
    78
    val isabthys' = map Context.theory_name (isabthys ());
walther@59916
    79
  in
walther@59916
    80
    if member op= isabthys' (ThyC.cut_id thmDeriv)
walther@59916
    81
    then ("Isabelle", ThyC.cut_id thmDeriv)
walther@59916
    82
    else ("IsacKnowledge", ThyC.cut_id thmDeriv)
walther@59916
    83
  end
walther@59916
    84
walther@59916
    85
(* which theory in ancestors of thy' contains a ruleset *)
walther@59916
    86
fun thy_containing_rls thy' rls' =
walther@59916
    87
  let
walther@59916
    88
    val thy = ThyC.get_theory thy'
walther@59916
    89
  in
walther@59916
    90
    case AList.lookup op= (KEStore_Elems.get_rlss thy) rls' of
walther@59916
    91
      SOME (thy'', _) => (partID' thy'', thy'')
walther@59916
    92
    | _ => error ("thy_containing_rls : rls '" ^ rls' ^ "' not in ancestors of thy '" ^ thy' ^ "'")
walther@59916
    93
  end
walther@59916
    94
walther@59916
    95
(* this function cannot work as long as the datastructure does not contain thy' *)
walther@59916
    96
fun thy_containing_cal thy' sop =
walther@59916
    97
  let
walther@59916
    98
    val thy = ThyC.get_theory thy'
walther@59916
    99
  in
walther@59916
   100
    case AList.lookup op= (KEStore_Elems.get_calcs thy) sop of
walther@59916
   101
      SOME (_(*"Groups.plus_class.plus"*), _) => ("IsacKnowledge", "Base_Tools")
walther@59916
   102
    | _ => error ("thy_containing_cal : rls '" ^ sop ^ "' not in ancestors of thy '" ^ thy' ^ "'")
walther@59916
   103
  end
walther@59916
   104
walther@59916
   105
(**)end(**)