26 val read_typ: context -> string -> typ |
26 val read_typ: context -> string -> typ |
27 val cert_typ: context -> typ -> typ |
27 val cert_typ: context -> typ -> typ |
28 val read_termTs: context -> (string * typ) list -> term list * (indexname * typ) list |
28 val read_termTs: context -> (string * typ) list -> term list * (indexname * typ) list |
29 val read_term: context -> string -> term |
29 val read_term: context -> string -> term |
30 val read_prop: context -> string -> term |
30 val read_prop: context -> string -> term |
31 val read_pat: context -> string -> term |
31 val read_term_pat: context -> string -> term |
|
32 val read_prop_pat: context -> string -> term |
32 val cert_term: context -> term -> term |
33 val cert_term: context -> term -> term |
33 val cert_prop: context -> term -> term |
34 val cert_prop: context -> term -> term |
34 val declare_term: term -> context -> context |
35 val declare_term: term -> context -> context |
35 val declare_terms: term list -> context -> context |
36 val declare_terms: term list -> context -> context |
36 val declare_thm: thm -> context -> context |
37 val declare_thm: thm -> context -> context |
37 val add_binds: (indexname * string) list -> context -> context |
38 val add_binds: (indexname * string) list -> context -> context |
38 val add_binds_i: (indexname * term) list -> context -> context |
39 val add_binds_i: (indexname * term) list -> context -> context |
39 val match_binds: (string * string) list -> context -> context |
40 val match_binds: (string list * string) list -> context -> context |
40 val match_binds_i: (term * term) list -> context -> context |
41 val match_binds_i: (term list * term) list -> context -> context |
|
42 val bind_propp: context * (string * string list) -> context * term |
|
43 val bind_propp_i: context * (term * term list) -> context * term |
41 val thms_closure: context -> xstring -> tthm list option |
44 val thms_closure: context -> xstring -> tthm list option |
42 val get_tthm: context -> string -> tthm |
45 val get_tthm: context -> string -> tthm |
43 val get_tthms: context -> string -> tthm list |
46 val get_tthms: context -> string -> tthm list |
44 val get_tthmss: context -> string list -> tthm list |
47 val get_tthmss: context -> string list -> tthm list |
45 val put_tthm: string * tthm -> context -> context |
48 val put_tthm: string * tthm -> context -> context |
47 val put_tthmss: (string * tthm list) list -> context -> context |
50 val put_tthmss: (string * tthm list) list -> context -> context |
48 val have_tthmss: string -> context attribute list |
51 val have_tthmss: string -> context attribute list |
49 -> (tthm list * context attribute list) list -> context -> context * (string * tthm list) |
52 -> (tthm list * context attribute list) list -> context -> context * (string * tthm list) |
50 val assumptions: context -> tthm list |
53 val assumptions: context -> tthm list |
51 val fixed_names: context -> string list |
54 val fixed_names: context -> string list |
52 val assume: string -> context attribute list -> string list -> context |
55 val assume: string -> context attribute list -> (string * string list) list -> context |
53 -> context * (string * tthm list) |
56 -> context * (string * tthm list) |
54 val assume_i: string -> context attribute list -> term list -> context |
57 val assume_i: string -> context attribute list -> (term * term list) list -> context |
55 -> context * (string * tthm list) |
58 -> context * (string * tthm list) |
56 val fix: (string * string option) list -> context -> context |
59 val fix: (string * string option) list -> context -> context |
57 val fix_i: (string * typ) list -> context -> context |
60 val fix_i: (string * typ) list -> context -> context |
58 val setup: (theory -> theory) list |
61 val setup: (theory -> theory) list |
59 end; |
62 end; |
412 |> intern_skolem ctxt false |
416 |> intern_skolem ctxt false |
413 |> (if is_pat then I else norm_term ctxt); |
417 |> (if is_pat then I else norm_term ctxt); |
414 |
418 |
415 val cert_term = gen_cert cert_term_sg false; |
419 val cert_term = gen_cert cert_term_sg false; |
416 val cert_prop = gen_cert cert_prop_sg false; |
420 val cert_prop = gen_cert cert_prop_sg false; |
417 val cert_pat = gen_cert cert_term_sg true; |
421 val cert_term_pat = gen_cert cert_term_sg true; |
|
422 val cert_prop_pat = gen_cert cert_prop_sg true; |
418 |
423 |
419 |
424 |
420 (* declare terms *) |
425 (* declare terms *) |
421 |
426 |
422 val ins_types = foldl_aterms |
427 val ins_types = foldl_aterms |
490 val add_binds_i = gen_binds cert_term; |
491 val add_binds_i = gen_binds cert_term; |
491 |
492 |
492 |
493 |
493 (* match_binds(_i) -- parallel *) |
494 (* match_binds(_i) -- parallel *) |
494 |
495 |
495 fun prep_pair prep_pat prep (ctxt, (raw_pat, raw_t)) = |
496 fun prep_declare_match (prep_pat, prep) (ctxt, (raw_pats, raw_t)) = |
496 let |
497 let |
497 val pat = prep_pat ctxt raw_pat; |
498 val pats = map (prep_pat ctxt) raw_pats; (* FIXME seq / par / simult (??) *) |
498 val (ctxt', t) = prep_declare prep (ctxt, raw_t); |
499 val t = prep ctxt raw_t; |
499 in (ctxt', (pat, t)) end; |
500 in (ctxt |> declare_term t, (map (rpair t) pats, t)) end; |
500 |
501 |
501 fun gen_match_binds prep_pat prep raw_pairs ctxt = |
502 fun gen_match_binds _ [] ctxt = ctxt |
502 let |
503 | gen_match_binds prepp raw_pairs ctxt = |
503 val (ctxt', pairs) = foldl_map (prep_pair prep_pat prep) (ctxt, raw_pairs); |
504 let |
504 val Context {defs = (_, _, maxidx, _), ...} = ctxt'; |
505 val (ctxt', matches) = foldl_map (prep_declare_match prepp) (ctxt, raw_pairs); |
505 val envs = Unify.smash_unifiers (sign_of ctxt', Envir.empty maxidx, pairs); |
506 val pairs = flat (map #1 matches); |
506 val env = |
507 val Context {defs = (_, _, maxidx, _), ...} = ctxt'; |
507 (case Seq.pull envs of |
508 val envs = Unify.smash_unifiers (sign_of ctxt', Envir.empty maxidx, pairs); |
508 None => raise CONTEXT ("Pattern match failed!", ctxt') |
509 val env = |
509 | Some (env, _) => env); |
510 (case Seq.pull envs of |
510 in ctxt' |> update_binds_env env end; |
511 None => raise CONTEXT ("Pattern match failed!", ctxt') |
511 |
512 | Some (env, _) => env); |
512 val match_binds = gen_match_binds read_pat read_term; |
513 in ctxt' |> update_binds_env env end; |
513 val match_binds_i = gen_match_binds cert_pat cert_term; |
514 |
|
515 val match_binds = gen_match_binds (read_term_pat, read_term); |
|
516 val match_binds_i = gen_match_binds (cert_term_pat, cert_term); |
|
517 |
|
518 |
|
519 (* bind proposition patterns *) |
|
520 |
|
521 fun gen_bind_propp prepp (ctxt, (raw_prop, raw_pats)) = |
|
522 let val (ctxt', (pairs, prop)) = prep_declare_match prepp (ctxt, (raw_pats, raw_prop)) |
|
523 in (ctxt' |> match_binds_i (map (apfst single) pairs), prop) end; |
|
524 |
|
525 val bind_propp = gen_bind_propp (read_prop_pat, read_prop); |
|
526 val bind_propp_i = gen_bind_propp (cert_prop_pat, cert_prop); |
514 |
527 |
515 |
528 |
516 |
529 |
517 (** theorems **) |
530 (** theorems **) |
518 |
531 |
577 fun fixed_names (Context {asms = (_, (fixes, _)), ...}) = map #2 fixes; |
590 fun fixed_names (Context {asms = (_, (fixes, _)), ...}) = map #2 fixes; |
578 |
591 |
579 |
592 |
580 (* assume *) |
593 (* assume *) |
581 |
594 |
582 fun gen_assume prep name attrs raw_props ctxt = |
595 fun gen_assume prepp name attrs raw_prop_pats ctxt = |
583 let |
596 let |
584 val (ctxt', props) = foldl_map prep (ctxt, raw_props); |
597 val (ctxt', props) = foldl_map prepp (ctxt, raw_prop_pats); |
585 val sign = sign_of ctxt'; |
598 val sign = sign_of ctxt'; |
586 |
599 |
587 val asms = map (Attribute.tthm_of o Thm.assume o Thm.cterm_of sign) props; |
600 val asms = map (Attribute.tthm_of o Thm.assume o Thm.cterm_of sign) props; |
588 |
601 |
589 val ths = map (fn th => ([th], [])) asms; |
602 val ths = map (fn th => ([th], [])) asms; |
595 ctxt'' |
608 ctxt'' |
596 |> map_context (fn (thy, data, (assumes, fixes), binds, thms, defs) => |
609 |> map_context (fn (thy, data, (assumes, fixes), binds, thms, defs) => |
597 (thy, data, (assumes @ [(name, asms)], fixes), binds, thms, defs)); |
610 (thy, data, (assumes @ [(name, asms)], fixes), binds, thms, defs)); |
598 in (ctxt''', (name, tthms)) end; |
611 in (ctxt''', (name, tthms)) end; |
599 |
612 |
600 val assume = gen_assume (prep_declare read_prop); |
613 val assume = gen_assume bind_propp; |
601 val assume_i = gen_assume (prep_declare cert_prop); |
614 val assume_i = gen_assume bind_propp_i; |
602 |
615 |
603 |
616 |
604 (* fix *) |
617 (* fix *) |
605 |
618 |
606 fun read_skolemT (Context {defs = (_, _, _, used), ...}) None = Type.param used ("'z", logicS) |
619 fun read_skolemT (Context {defs = (_, _, _, used), ...}) None = Type.param used ("'z", logicS) |