author | Walther Neuper <walther.neuper@jku.at> |
Wed, 15 Jan 2020 11:47:38 +0100 | |
changeset 59767 | c4acd312bd53 |
parent 59751 | fa26464c66bf |
child 59784 | 9800556c5cfe |
permissions | -rw-r--r-- |
wneuper@59577 | 1 |
(* Title: ../contextC.sml |
wneuper@59577 | 2 |
Author: Walther Neuper, Mathias Lehnfeld |
wneuper@59577 | 3 |
(c) due to copyright terms |
wneuper@59577 | 4 |
*) |
wneuper@59577 | 5 |
(* Extension to Isabelle's naming conventions: "C" indicates Isac add-ons to an Isabelle module *) |
wneuper@59577 | 6 |
signature CONTEXT_C = |
wneuper@59577 | 7 |
sig |
wneuper@59581 | 8 |
val e_ctxt : Proof.context |
walther@59719 | 9 |
val is_e_ctxt : Proof.context -> bool |
wneuper@59597 | 10 |
val isac_ctxt : 'a -> Proof.context |
wneuper@59580 | 11 |
val initialise : string -> term list -> Proof.context |
wneuper@59580 | 12 |
val initialise' : theory -> string list -> Proof.context |
wneuper@59577 | 13 |
val get_assumptions : Proof.context -> term list |
wneuper@59577 | 14 |
val insert_assumptions : term list -> Proof.context -> Proof.context |
wneuper@59577 | 15 |
val from_subpbl_to_caller : Proof.context -> term -> Proof.context -> Proof.context |
walther@59767 | 16 |
(*val subpbl_to_caller .. rename according to naming convention TODO*) |
wneuper@59577 | 17 |
(* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *) |
wneuper@59577 | 18 |
(*NONE*) |
walther@59702 | 19 |
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* ) |
wneuper@59577 | 20 |
val transfer_asms_from_to : Proof.context -> Proof.context -> Proof.context |
walther@59702 | 21 |
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*) |
wneuper@59577 | 22 |
end |
wneuper@59577 | 23 |
|
wneuper@59577 | 24 |
structure ContextC(**) : CONTEXT_C(**) = |
wneuper@59577 | 25 |
struct |
wneuper@59577 | 26 |
|
walther@59723 | 27 |
val e_ctxt = Proof_Context.init_global @{theory "Pure"}; |
walther@59719 | 28 |
(* ATTENTION: does _not_ recognise Variable.declare_constraints, etc...*) |
walther@59723 | 29 |
fun is_e_ctxt ctxt = Context.eq_thy (Proof_Context.theory_of ctxt, @{theory "Pure"}); |
wneuper@59597 | 30 |
fun isac_ctxt xxx = Proof_Context.init_global (Rule.Isac xxx) |
wneuper@59581 | 31 |
|
walther@59677 | 32 |
(* in Subproblem take respective actual arguments from program *) |
walther@59677 | 33 |
fun initialise thy' ts = |
walther@59677 | 34 |
let |
walther@59677 | 35 |
val ctxt = Rule.Thy_Info_get_theory thy' |> Proof_Context.init_global |
walther@59677 | 36 |
val frees = map TermC.vars ts |> flat |> distinct |
walther@59677 | 37 |
val _ = TermC.raise_type_conflicts frees |
walther@59677 | 38 |
in |
walther@59677 | 39 |
fold Variable.declare_constraints frees ctxt |
walther@59677 | 40 |
end |
wneuper@59582 | 41 |
(* in root-problem take respective formalisation *) |
wneuper@59582 | 42 |
fun initialise' thy fmz = |
wneuper@59582 | 43 |
let |
wneuper@59582 | 44 |
val ctxt = thy |> Proof_Context.init_global |
wneuper@59582 | 45 |
val frees = map (TermC.parseNEW' ctxt) fmz |> map TermC.vars |> flat |> distinct |
wneuper@59582 | 46 |
val _ = TermC.raise_type_conflicts frees |
wneuper@59582 | 47 |
in |
wneuper@59582 | 48 |
fold Variable.declare_constraints frees ctxt |
wneuper@59582 | 49 |
end |
wneuper@59580 | 50 |
|
wneuper@59577 | 51 |
structure Context_Data = Proof_Data (type T = term list fun init _ = []); |
wneuper@59577 | 52 |
fun get_assumptions ctxt = Context_Data.get ctxt |
wneuper@59577 | 53 |
fun insert_assumptions asms = Context_Data.map (fn xs => distinct (asms @ xs)) |
wneuper@59577 | 54 |
|
wneuper@59577 | 55 |
(* transfer assumptions from one to another ctxt. |
wneuper@59577 | 56 |
does NOT respect scope: in a calculation identifiers are unique. |
wneuper@59577 | 57 |
but environments are scoped as usual in Luacs-interpretation. |
wneuper@59577 | 58 |
WN110520 redo (1) take declare_constraints (2) with combinators*) |
wneuper@59577 | 59 |
fun transfer_asms_from_to from_ctxt to_ctxt = |
wneuper@59577 | 60 |
let |
wneuper@59577 | 61 |
val to_vars = get_assumptions to_ctxt |> map TermC.vars |> flat |
wneuper@59577 | 62 |
fun transfer [] to_ctxt = to_ctxt |
wneuper@59577 | 63 |
| transfer (from_asm :: fas) to_ctxt = |
wneuper@59577 | 64 |
if inter op = (TermC.vars from_asm) to_vars = [] |
wneuper@59577 | 65 |
then transfer fas to_ctxt |
wneuper@59577 | 66 |
else transfer fas (insert_assumptions [from_asm] to_ctxt) |
wneuper@59577 | 67 |
in transfer (get_assumptions from_ctxt) to_ctxt end |
wneuper@59577 | 68 |
|
wneuper@59577 | 69 |
(* exported from a subproblem to the context of the calling method: |
wneuper@59577 | 70 |
# 'scrval': the result of script interpretation and |
wneuper@59577 | 71 |
# those assumptions in the subproblem wich contain a variable known |
wneuper@59577 | 72 |
in the calling method. *) |
wneuper@59577 | 73 |
fun from_subpbl_to_caller sub_ctxt scrval caller_ctxt = |
wneuper@59577 | 74 |
let |
wneuper@59577 | 75 |
val caller_ctxt = (scrval |> TermC.dest_list' |> insert_assumptions) caller_ctxt |
wneuper@59577 | 76 |
in transfer_asms_from_to sub_ctxt caller_ctxt end; |
wneuper@59577 | 77 |
|
wneuper@59577 | 78 |
end |