6 *) |
6 *) |
7 |
7 |
8 signature ELEMENT = |
8 signature ELEMENT = |
9 sig |
9 sig |
10 datatype ('typ, 'term) stmt = |
10 datatype ('typ, 'term) stmt = |
11 Shows of ((string * Attrib.src list) * ('term * ('term list * 'term list)) list) list | |
11 Shows of ((string * Attrib.src list) * ('term * 'term list) list) list | |
12 Obtains of (string * ((string * 'typ option) list * 'term list)) list |
12 Obtains of (string * ((string * 'typ option) list * 'term list)) list |
13 type statement (*= (string, string) stmt*) |
13 type statement (*= (string, string) stmt*) |
14 type statement_i (*= (typ, term) stmt*) |
14 type statement_i (*= (typ, term) stmt*) |
15 datatype ('typ, 'term, 'fact) ctxt = |
15 datatype ('typ, 'term, 'fact) ctxt = |
16 Fixes of (string * 'typ option * mixfix) list | |
16 Fixes of (string * 'typ option * mixfix) list | |
17 Constrains of (string * 'typ) list | |
17 Constrains of (string * 'typ) list | |
18 Assumes of ((string * Attrib.src list) * ('term * ('term list * 'term list)) list) list | |
18 Assumes of ((string * Attrib.src list) * ('term * 'term list) list) list | |
19 Defines of ((string * Attrib.src list) * ('term * 'term list)) list | |
19 Defines of ((string * Attrib.src list) * ('term * 'term list)) list | |
20 Notes of ((string * Attrib.src list) * ('fact * Attrib.src list) list) list |
20 Notes of ((string * Attrib.src list) * ('fact * Attrib.src list) list) list |
21 type context (*= (string, string, thmref) ctxt*) |
21 type context (*= (string, string, thmref) ctxt*) |
22 type context_i (*= (typ, term, thm list) ctxt*) |
22 type context_i (*= (typ, term, thm list) ctxt*) |
23 val map_ctxt: {name: string -> string, |
23 val map_ctxt: {name: string -> string, |
47 |
47 |
48 |
48 |
49 (** conclusions **) |
49 (** conclusions **) |
50 |
50 |
51 datatype ('typ, 'term) stmt = |
51 datatype ('typ, 'term) stmt = |
52 Shows of ((string * Attrib.src list) * ('term * ('term list * 'term list)) list) list | |
52 Shows of ((string * Attrib.src list) * ('term * 'term list) list) list | |
53 Obtains of (string * ((string * 'typ option) list * 'term list)) list; |
53 Obtains of (string * ((string * 'typ option) list * 'term list)) list; |
54 |
54 |
55 type statement = (string, string) stmt; |
55 type statement = (string, string) stmt; |
56 type statement_i = (typ, term) stmt; |
56 type statement_i = (typ, term) stmt; |
57 |
57 |
62 (* datatype ctxt *) |
62 (* datatype ctxt *) |
63 |
63 |
64 datatype ('typ, 'term, 'fact) ctxt = |
64 datatype ('typ, 'term, 'fact) ctxt = |
65 Fixes of (string * 'typ option * mixfix) list | |
65 Fixes of (string * 'typ option * mixfix) list | |
66 Constrains of (string * 'typ) list | |
66 Constrains of (string * 'typ) list | |
67 Assumes of ((string * Attrib.src list) * ('term * ('term list * 'term list)) list) list | |
67 Assumes of ((string * Attrib.src list) * ('term * 'term list) list) list | |
68 Defines of ((string * Attrib.src list) * ('term * 'term list)) list | |
68 Defines of ((string * Attrib.src list) * ('term * 'term list)) list | |
69 Notes of ((string * Attrib.src list) * ('fact * Attrib.src list) list) list; |
69 Notes of ((string * Attrib.src list) * ('fact * Attrib.src list) list) list; |
70 |
70 |
71 type context = (string, string, thmref) ctxt; |
71 type context = (string, string, thmref) ctxt; |
72 type context_i = (typ, term, thm list) ctxt; |
72 type context_i = (typ, term, thm list) ctxt; |
74 fun map_ctxt {name, var, typ, term, fact, attrib} = |
74 fun map_ctxt {name, var, typ, term, fact, attrib} = |
75 fn Fixes fixes => Fixes (fixes |> map (fn (x, T, mx) => |
75 fn Fixes fixes => Fixes (fixes |> map (fn (x, T, mx) => |
76 let val (x', mx') = var (x, mx) in (x', Option.map typ T, mx') end)) |
76 let val (x', mx') = var (x, mx) in (x', Option.map typ T, mx') end)) |
77 | Constrains xs => Constrains (xs |> map (fn (x, T) => (#1 (var (x, NoSyn)), typ T))) |
77 | Constrains xs => Constrains (xs |> map (fn (x, T) => (#1 (var (x, NoSyn)), typ T))) |
78 | Assumes asms => Assumes (asms |> map (fn ((a, atts), propps) => |
78 | Assumes asms => Assumes (asms |> map (fn ((a, atts), propps) => |
79 ((name a, map attrib atts), propps |> map (fn (t, (ps, qs)) => |
79 ((name a, map attrib atts), propps |> map (fn (t, ps) => (term t, map term ps))))) |
80 (term t, (map term ps, map term qs)))))) |
|
81 | Defines defs => Defines (defs |> map (fn ((a, atts), (t, ps)) => |
80 | Defines defs => Defines (defs |> map (fn ((a, atts), (t, ps)) => |
82 ((name a, map attrib atts), (term t, map term ps)))) |
81 ((name a, map attrib atts), (term t, map term ps)))) |
83 | Notes facts => Notes (facts |> map (fn ((a, atts), bs) => |
82 | Notes facts => Notes (facts |> map (fn ((a, atts), bs) => |
84 ((name a, map attrib atts), bs |> map (fn (ths, btts) => (fact ths, map attrib btts))))); |
83 ((name a, map attrib atts), bs |> map (fn (ths, btts) => (fact ths, map attrib btts))))); |
85 |
84 |
253 fun prt_show (a, ts) = |
252 fun prt_show (a, ts) = |
254 Pretty.block (Pretty.breaks (prt_name_atts a ":" @ prt_terms (map fst ts))); |
253 Pretty.block (Pretty.breaks (prt_name_atts a ":" @ prt_terms (map fst ts))); |
255 |
254 |
256 fun prt_var (x, SOME T) = Pretty.block [Pretty.str (x ^ " ::"), Pretty.brk 1, prt_typ T] |
255 fun prt_var (x, SOME T) = Pretty.block [Pretty.str (x ^ " ::"), Pretty.brk 1, prt_typ T] |
257 | prt_var (x, NONE) = Pretty.str x; |
256 | prt_var (x, NONE) = Pretty.str x; |
|
257 val prt_vars = separate (Pretty.keyword "and") o map prt_var; |
258 |
258 |
259 fun prt_obtain (_, ([], ts)) = Pretty.block (Pretty.breaks (prt_terms ts)) |
259 fun prt_obtain (_, ([], ts)) = Pretty.block (Pretty.breaks (prt_terms ts)) |
260 | prt_obtain (_, (xs, ts)) = Pretty.block (Pretty.breaks |
260 | prt_obtain (_, (xs, ts)) = Pretty.block (Pretty.breaks |
261 (map prt_var xs @ [Pretty.keyword "where"] @ prt_terms ts)); |
261 (prt_vars xs @ [Pretty.keyword "where"] @ prt_terms ts)); |
262 in |
262 in |
263 fn Shows shows => pretty_items "shows" "and" (map prt_show shows) |
263 fn Shows shows => pretty_items "shows" "and" (map prt_show shows) |
264 | Obtains obtains => pretty_items "obtains" "|" (map prt_obtain obtains) |
264 | Obtains obtains => pretty_items "obtains" "|" (map prt_obtain obtains) |
265 end; |
265 end; |
266 |
266 |
347 val (prems, concl) = Logic.strip_horn prop; |
347 val (prems, concl) = Logic.strip_horn prop; |
348 val thesis = ObjectLogic.fixed_judgment thy AutoBind.thesisN; |
348 val thesis = ObjectLogic.fixed_judgment thy AutoBind.thesisN; |
349 val (asms, cases) = take_suffix (fn prem => thesis aconv Logic.strip_assums_concl prem) prems; |
349 val (asms, cases) = take_suffix (fn prem => thesis aconv Logic.strip_assums_concl prem) prems; |
350 in |
350 in |
351 pretty_ctxt ctxt (Fixes (map (fn (x, T) => (x, SOME T, NoSyn)) fixes)) @ |
351 pretty_ctxt ctxt (Fixes (map (fn (x, T) => (x, SOME T, NoSyn)) fixes)) @ |
352 pretty_ctxt ctxt (Assumes (map (fn t => (("", []), [(t, ([], []))])) asms)) @ |
352 pretty_ctxt ctxt (Assumes (map (fn t => (("", []), [(t, [])])) asms)) @ |
353 pretty_stmt ctxt |
353 pretty_stmt ctxt |
354 (if null cases then Shows [(("", []), [(concl, ([], []))])] |
354 (if null cases then Shows [(("", []), [(concl, [])])] |
355 else Obtains (#1 (fold_map obtain cases (ctxt |> ProofContext.declare_term prop)))) |
355 else Obtains (#1 (fold_map obtain cases (ctxt |> ProofContext.declare_term prop)))) |
356 end |> thm_name kind raw_th; |
356 end |> thm_name kind raw_th; |
357 |
357 |
358 end; |
358 end; |
359 |
359 |