src/Pure/Isar/proof_context.ML
author wenzelm
Wed, 25 Jan 2006 00:21:43 +0100
changeset 18785 5ae1f1c1b764
parent 18770 434f660d3068
child 18809 95b4a51781aa
permissions -rw-r--r--
renamed export to export_standard (again!), because it includes Drule.local_standard'; added abs_def (from locale.ML);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/proof_context.ML
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
     4
15758
07e382399a96 binds/thms: do not store options, but delete from table;
wenzelm
parents: 15750
diff changeset
     5
The key concept of Isar proof contexts.
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
     6
*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
     7
14707
2d6350d7b9b7 show_structs option;
wenzelm
parents: 14697
diff changeset
     8
val show_structs = ref false;
2d6350d7b9b7 show_structs option;
wenzelm
parents: 14697
diff changeset
     9
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    10
signature PROOF_CONTEXT =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    11
sig
17756
d4a35f82fbb4 minor tweaks for Poplog/ML;
wenzelm
parents: 17496
diff changeset
    12
  type context (*= Context.proof*)
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
    13
  type export
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    14
  val theory_of: context -> theory
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
    15
  val init: theory -> context
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
    16
  val set_body: bool -> context -> context
18743
7ff2934480c9 added restore_body;
wenzelm
parents: 18728
diff changeset
    17
  val restore_body: context -> context -> context
17451
cfa8b1ebfc9a added auto_fix (from proof.ML);
wenzelm
parents: 17412
diff changeset
    18
  val assms_of: context -> term list
7557
1b977741f530 export prems_of;
wenzelm
parents: 7505
diff changeset
    19
  val prems_of: context -> thm list
16031
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
    20
  val fact_index_of: context -> FactIndex.T
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
    21
  val is_fixed: context -> string -> bool
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
    22
  val is_known: context -> string -> bool
17072
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
    23
  val transfer: theory -> context -> context
14828
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
    24
  val pretty_term: context -> term -> Pretty.T
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
    25
  val pretty_typ: context -> typ -> Pretty.T
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
    26
  val pretty_sort: context -> sort -> Pretty.T
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
    27
  val pp: context -> Pretty.pp
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
    28
  val pretty_thm: context -> thm -> Pretty.T
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
    29
  val pretty_thms: context -> thm list -> Pretty.T
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
    30
  val pretty_fact: context -> string * thm list -> Pretty.T
17072
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
    31
  val pretty_proof: context -> Proofterm.proof -> Pretty.T
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
    32
  val pretty_proof_of: context -> bool -> thm -> Pretty.T
17360
fa1f262dbc4e added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents: 17221
diff changeset
    33
  val string_of_typ: context -> typ -> string
14828
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
    34
  val string_of_term: context -> term -> string
17860
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
    35
  val string_of_thm: context -> thm -> string
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
    36
  val used_types: context -> string list
12414
61e1681b0b5d added default_type;
wenzelm
parents: 12309
diff changeset
    37
  val default_type: context -> string -> typ option
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    38
  val read_typ: context -> string -> typ
16348
7504fe04170f renamed extern to extern_thm;
wenzelm
parents: 16147
diff changeset
    39
  val read_typ_syntax: context -> string -> typ
7504fe04170f renamed extern to extern_thm;
wenzelm
parents: 16147
diff changeset
    40
  val read_typ_abbrev: context -> string -> typ
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    41
  val cert_typ: context -> typ -> typ
16348
7504fe04170f renamed extern to extern_thm;
wenzelm
parents: 16147
diff changeset
    42
  val cert_typ_syntax: context -> typ -> typ
7504fe04170f renamed extern to extern_thm;
wenzelm
parents: 16147
diff changeset
    43
  val cert_typ_abbrev: context -> typ -> typ
10583
f2d9f4fd370b export get_skolem;
wenzelm
parents: 10554
diff changeset
    44
  val get_skolem: context -> string -> string
18255
5ef79b75a002 revert_skolem: fall back on Syntax.deskolem;
wenzelm
parents: 18211
diff changeset
    45
  val revert_skolem: context -> string -> string
9133
bc3742f62b80 added extern_skolem;
wenzelm
parents: 9007
diff changeset
    46
  val extern_skolem: context -> term -> term
14720
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
    47
  val read_termTs: context -> (string -> bool) -> (indexname -> typ option)
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
    48
    -> (indexname -> sort option) -> string list -> (string * typ) list
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
    49
    -> term list * (indexname * typ) list
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
    50
  val read_termTs_schematic: context -> (string -> bool) -> (indexname -> typ option)
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
    51
    -> (indexname -> sort option) -> string list -> (string * typ) list
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
    52
    -> term list * (indexname * typ) list
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
    53
  val read_term_legacy: context -> string -> term
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    54
  val read_term: context -> string -> term
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    55
  val read_prop: context -> string -> term
11925
4747b4b84093 added read_prop_schematic;
wenzelm
parents: 11918
diff changeset
    56
  val read_prop_schematic: context -> string -> term
10465
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
    57
  val read_terms: context -> string list -> term list
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
    58
  val read_term_pats: typ -> context -> string list -> term list
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
    59
  val read_prop_pats: context -> string list -> term list
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    60
  val cert_term: context -> term -> term
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    61
  val cert_prop: context -> term -> term
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
    62
  val cert_term_pats: typ -> context -> term list -> term list
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
    63
  val cert_prop_pats: context -> term list -> term list
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    64
  val declare_term: term -> context -> context
18770
434f660d3068 renamed inferred_type to inferred_param;
wenzelm
parents: 18743
diff changeset
    65
  val infer_type: context -> string -> typ
434f660d3068 renamed inferred_type to inferred_param;
wenzelm
parents: 18743
diff changeset
    66
  val inferred_param: string -> context -> (string * typ) * context
434f660d3068 renamed inferred_type to inferred_param;
wenzelm
parents: 18743
diff changeset
    67
  val inferred_fixes: context -> (string * typ) list * context
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
    68
  val read_tyname: context -> string -> typ
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
    69
  val read_const: context -> string -> term
7925
8c50b68b890b warn_extra_tfrees (after declare_term);
wenzelm
parents: 7679
diff changeset
    70
  val warn_extra_tfrees: context -> context -> context
12550
32843ad8160a generalize type variables properly: start with occurrences in objects
wenzelm
parents: 12530
diff changeset
    71
  val generalize: context -> context -> term list -> term list
18785
5ae1f1c1b764 renamed export to export_standard (again!), because it includes Drule.local_standard';
wenzelm
parents: 18770
diff changeset
    72
  val export_standard: context -> context -> thm -> thm
18042
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
    73
  val exports: context -> context -> thm -> thm Seq.seq
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
    74
  val goal_exports: context -> context -> thm -> thm Seq.seq
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
    75
  val drop_schematic: indexname * term option -> indexname * term option
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
    76
  val add_binds: (indexname * string option) list -> context -> context
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
    77
  val add_binds_i: (indexname * term option) list -> context -> context
12147
64e69a8a945f adapted auto_bind_goal, auto_bind_facts;
wenzelm
parents: 12130
diff changeset
    78
  val auto_bind_goal: term list -> context -> context
64e69a8a945f adapted auto_bind_goal, auto_bind_facts;
wenzelm
parents: 12130
diff changeset
    79
  val auto_bind_facts: term list -> context -> context
18310
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
    80
  val match_bind: bool -> (string list * string) list -> context -> term list * context
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
    81
  val match_bind_i: bool -> (term list * term) list -> context -> term list * context
10465
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
    82
  val read_propp: context * (string * (string list * string list)) list list
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
    83
    -> context * (term * (term list * term list)) list list
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
    84
  val cert_propp: context * (term * (term list * term list)) list list
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
    85
    -> context * (term * (term list * term list)) list list
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
    86
  val read_propp_schematic: context * (string * (string list * string list)) list list
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
    87
    -> context * (term * (term list * term list)) list list
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
    88
  val cert_propp_schematic: context * (term * (term list * term list)) list list
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
    89
    -> context * (term * (term list * term list)) list list
10465
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
    90
  val bind_propp: context * (string * (string list * string list)) list list
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
    91
    -> context * (term list list * (context -> context))
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
    92
  val bind_propp_i: context * (term * (term list * term list)) list list
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
    93
    -> context * (term list list * (context -> context))
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
    94
  val bind_propp_schematic: context * (string * (string list * string list)) list list
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
    95
    -> context * (term list list * (context -> context))
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
    96
  val bind_propp_schematic_i: context * (term * (term list * term list)) list list
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
    97
    -> context * (term list list * (context -> context))
18042
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
    98
  val fact_tac: thm list -> int -> tactic
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
    99
  val some_fact_tac: context -> int -> tactic
15456
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15452
diff changeset
   100
  val get_thm: context -> thmref -> thm
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15452
diff changeset
   101
  val get_thm_closure: context -> thmref -> thm
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15452
diff changeset
   102
  val get_thms: context -> thmref -> thm list
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15452
diff changeset
   103
  val get_thms_closure: context -> thmref -> thm list
16031
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   104
  val valid_thms: context -> string * thm list -> bool
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   105
  val lthms_containing: context -> FactIndex.spec -> (string * thm list) list
16348
7504fe04170f renamed extern to extern_thm;
wenzelm
parents: 16147
diff changeset
   106
  val extern_thm: context -> string -> xstring
16147
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
   107
  val qualified_names: context -> context
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
   108
  val no_base_names: context -> context
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
   109
  val custom_accesses: (string list -> string list list) -> context -> context
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
   110
  val restore_naming: context -> context -> context
13425
119ae829ad9b support for split assumptions in cases (hyps vs. prems);
wenzelm
parents: 13415
diff changeset
   111
  val hide_thms: bool -> string list -> context -> context
17360
fa1f262dbc4e added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents: 17221
diff changeset
   112
  val put_thms: string * thm list option -> context -> context
14564
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14508
diff changeset
   113
  val note_thmss:
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   114
    ((bstring * attribute list) * (thmref * attribute list) list) list ->
17860
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
   115
      context -> (bstring * thm list) list * context
14564
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14508
diff changeset
   116
  val note_thmss_i:
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   117
    ((bstring * attribute list) * (thm list * attribute list) list) list ->
17860
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
   118
      context -> (bstring * thm list) list * context
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   119
  val read_vars: (string * string option * mixfix) list -> context ->
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   120
    (string * typ option * mixfix) list * context
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   121
  val cert_vars: (string * typ option * mixfix) list -> context ->
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   122
    (string * typ option * mixfix) list * context
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   123
  val read_vars_legacy: (string * string option * mixfix) list -> context ->
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   124
    (string * typ option * mixfix) list * context
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   125
  val cert_vars_legacy: (string * typ option * mixfix) list -> context ->
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   126
    (string * typ option * mixfix) list * context
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   127
  val add_fixes: (string * string option * mixfix) list -> context -> string list * context
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   128
  val add_fixes_i: (string * typ option * mixfix) list -> context -> string list * context
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   129
  val add_fixes_legacy: (string * typ option * mixfix) list -> context -> string list * context
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   130
  val fix_frees: term -> context -> context
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   131
  val auto_fixes: context * (term list list * 'a) -> context * (term list list * 'a)
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   132
  val bind_fixes: string list -> context -> (term -> term) * context
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   133
  val add_assms: export ->
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   134
    ((string * attribute list) * (string * (string list * string list)) list) list ->
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   135
    context -> (bstring * thm list) list * context
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   136
  val add_assms_i: export ->
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   137
    ((string * attribute list) * (term * (term list * term list)) list) list ->
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   138
    context -> (bstring * thm list) list * context
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   139
  val assume_export: export
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   140
  val presume_export: export
17360
fa1f262dbc4e added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents: 17221
diff changeset
   141
  val add_view: context -> cterm list -> context -> context
18042
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   142
  val export_view: cterm list -> context -> context -> thm -> thm
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   143
  val mk_def: context -> (string * term) list -> term list
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   144
  val cert_def: context -> term -> string * term
18785
5ae1f1c1b764 renamed export to export_standard (again!), because it includes Drule.local_standard';
wenzelm
parents: 18770
diff changeset
   145
  val abs_def: term -> (string * typ) * term
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   146
  val def_export: export
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   147
  val add_def: string * term -> context -> ((string * typ) * thm) * context
18609
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
   148
  val add_cases: bool -> (string * RuleCases.T option) list -> context -> context
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
   149
  val apply_case: RuleCases.T -> context -> (string * term list) list * context
16147
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
   150
  val get_case: context -> string -> string option list -> RuleCases.T
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
   151
  val verbose: bool ref
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
   152
  val setmp_verbose: ('a -> 'b) -> 'a -> 'b
12072
4281198fb8cd local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents: 12066
diff changeset
   153
  val print_syntax: context -> unit
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
   154
  val print_binds: context -> unit
12057
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
   155
  val print_lthms: context -> unit
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
   156
  val print_cases: context -> unit
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
   157
  val prems_limit: int ref
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   158
  val pretty_ctxt: context -> Pretty.T list
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
   159
  val pretty_context: context -> Pretty.T list
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   160
end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   161
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   162
structure ProofContext: PROOF_CONTEXT =
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   163
struct
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   164
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   165
type context = Context.proof;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   166
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   167
val theory_of = Context.theory_of_proof;
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   168
val init = Context.init_proof;
12057
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
   169
7270
2b64729d9acb warn_vars;
wenzelm
parents: 7200
diff changeset
   170
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   171
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   172
(** Isar proof context information **)
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   173
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   174
type export = bool -> cterm list -> thm -> thm Seq.seq;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   175
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   176
datatype ctxt =
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   177
  Ctxt of
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   178
   {syntax:                                      (*global/local syntax, structs, mixfixed*)
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   179
      (Syntax.syntax * Syntax.syntax * (Syntax.syntax -> Syntax.syntax)) *
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   180
      string list * string list,
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   181
    fixes: bool * (string * string) list,        (*fixes: !!x. _ with proof body flag*)
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   182
    assms:
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   183
      ((cterm list * export) list *              (*assumes and views: A ==> _*)
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   184
        (string * thm list) list),               (*prems: A |- A*)
18476
49dde7b7b14a cases: main is_proper flag;
wenzelm
parents: 18428
diff changeset
   185
    binds: (term * typ) Vartab.table,            (*term bindings*)
49dde7b7b14a cases: main is_proper flag;
wenzelm
parents: 18428
diff changeset
   186
    thms: NameSpace.naming *                     (*local thms*)
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   187
      thm list NameSpace.table * FactIndex.T,
18476
49dde7b7b14a cases: main is_proper flag;
wenzelm
parents: 18428
diff changeset
   188
    cases: (string * (RuleCases.T * bool)) list, (*local contexts*)
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   189
    defaults:
18476
49dde7b7b14a cases: main is_proper flag;
wenzelm
parents: 18428
diff changeset
   190
      typ Vartab.table *                         (*type constraints*)
49dde7b7b14a cases: main is_proper flag;
wenzelm
parents: 18428
diff changeset
   191
      sort Vartab.table *                        (*default sorts*)
49dde7b7b14a cases: main is_proper flag;
wenzelm
parents: 18428
diff changeset
   192
      string list *                              (*used type variables*)
49dde7b7b14a cases: main is_proper flag;
wenzelm
parents: 18428
diff changeset
   193
      term list Symtab.table};                   (*type variable occurrences*)
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   194
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   195
fun make_ctxt (syntax, fixes, assms, binds, thms, cases, defaults) =
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   196
  Ctxt {syntax = syntax, fixes = fixes, assms = assms, binds = binds,
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   197
    thms = thms, cases = cases, defaults = defaults};
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   198
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   199
structure ContextData = ProofDataFun
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   200
(
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   201
  val name = "Isar/context";
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   202
  type T = ctxt;
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   203
  fun init thy =
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   204
    make_ctxt (((Sign.syn_of thy, Sign.syn_of thy, I), [], []), (false, []), ([], []),
17072
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   205
      Vartab.empty, (NameSpace.default_naming, NameSpace.empty_table, FactIndex.empty), [],
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   206
      (Vartab.empty, Vartab.empty, [], Symtab.empty));
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   207
  fun print _ _ = ();
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   208
);
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   209
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18699
diff changeset
   210
val _ = Context.add_setup ContextData.init;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   211
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   212
fun rep_context ctxt = ContextData.get ctxt |> (fn Ctxt args => args);
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   213
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   214
fun map_context f =
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   215
  ContextData.map (fn Ctxt {syntax, fixes, assms, binds, thms, cases, defaults} =>
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   216
    make_ctxt (f (syntax, fixes, assms, binds, thms, cases, defaults)));
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   217
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   218
fun map_syntax f = map_context (fn (syntax, fixes, assms, binds, thms, cases, defaults) =>
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   219
  (f syntax, fixes, assms, binds, thms, cases, defaults));
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   220
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   221
fun map_fixes f = map_context (fn (syntax, fixes, assms, binds, thms, cases, defaults) =>
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   222
  (syntax, f fixes, assms, binds, thms, cases, defaults));
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   223
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   224
fun map_assms f = map_context (fn (syntax, fixes, assms, binds, thms, cases, defaults) =>
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   225
  (syntax, fixes, f assms, binds, thms, cases, defaults));
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   226
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   227
fun map_binds f = map_context (fn (syntax, fixes, assms, binds, thms, cases, defaults) =>
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   228
  (syntax, fixes, assms, f binds, thms, cases, defaults));
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   229
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   230
fun map_thms f = map_context (fn (syntax, fixes, assms, binds, thms, cases, defaults) =>
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   231
  (syntax, fixes, assms, binds, f thms, cases, defaults));
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   232
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   233
fun map_naming f = map_thms (fn (naming, table, index) => (f naming, table, index));
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   234
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   235
fun map_cases f = map_context (fn (syntax, fixes, assms, binds, thms, cases, defaults) =>
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   236
  (syntax, fixes, assms, binds, thms, f cases, defaults));
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   237
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   238
fun map_defaults f = map_context (fn (syntax, fixes, assms, binds, thms, cases, defaults) =>
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   239
  (syntax, fixes, assms, binds, thms, cases, f defaults));
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   240
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   241
val syntax_of = #syntax o rep_context;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   242
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   243
val is_body = #1 o #fixes o rep_context;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   244
fun set_body b = map_fixes (fn (_, fixes) => (b, fixes));
18743
7ff2934480c9 added restore_body;
wenzelm
parents: 18728
diff changeset
   245
fun restore_body ctxt = set_body (is_body ctxt);
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   246
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   247
val fixes_of = #2 o #fixes o rep_context;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   248
val fixed_names_of = map #2 o fixes_of;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   249
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   250
val assumptions_of = #1 o #assms o rep_context;
17451
cfa8b1ebfc9a added auto_fix (from proof.ML);
wenzelm
parents: 17412
diff changeset
   251
val assms_of = map Thm.term_of o List.concat o map #1 o assumptions_of;
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   252
val prems_of = List.concat o map #2 o #2 o #assms o rep_context;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   253
17860
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
   254
val binds_of = #binds o rep_context;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   255
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   256
val thms_of = #thms o rep_context;
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   257
val fact_index_of = #3 o thms_of;
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   258
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   259
val cases_of = #cases o rep_context;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   260
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   261
val defaults_of = #defaults o rep_context;
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   262
val type_occs_of = #4 o defaults_of;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   263
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   264
fun is_fixed ctxt x = exists (equal x o #2) (fixes_of ctxt);
16894
40f80823b451 Inttab.defined;
wenzelm
parents: 16861
diff changeset
   265
fun is_known ctxt x = Vartab.defined (#1 (defaults_of ctxt)) (x, ~1) orelse is_fixed ctxt x;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   266
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   267
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   268
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   269
(** syntax **)
12093
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
   270
14697
5ad13d05049b improved indexed syntax / implicit structures;
wenzelm
parents: 14665
diff changeset
   271
(* translation functions *)
14665
d2e5df3d1201 index syntax: support for general expressions (input only);
wenzelm
parents: 14643
diff changeset
   272
12100
bb10ac677955 proper syntax for structs;
wenzelm
parents: 12093
diff changeset
   273
fun context_tr' ctxt =
bb10ac677955 proper syntax for structs;
wenzelm
parents: 12093
diff changeset
   274
  let
bb10ac677955 proper syntax for structs;
wenzelm
parents: 12093
diff changeset
   275
    val (_, structs, mixfixed) = syntax_of ctxt;
bb10ac677955 proper syntax for structs;
wenzelm
parents: 12093
diff changeset
   276
bb10ac677955 proper syntax for structs;
wenzelm
parents: 12093
diff changeset
   277
    fun tr' (t $ u) = tr' t $ tr' u
bb10ac677955 proper syntax for structs;
wenzelm
parents: 12093
diff changeset
   278
      | tr' (Abs (x, T, t)) = Abs (x, T, tr' t)
bb10ac677955 proper syntax for structs;
wenzelm
parents: 12093
diff changeset
   279
      | tr' (t as Free (x, T)) =
14697
5ad13d05049b improved indexed syntax / implicit structures;
wenzelm
parents: 14665
diff changeset
   280
          let val i = Library.find_index_eq x structs + 1 in
18340
3fdff270aa04 removed fixed_tr: now handled in syntax module;
wenzelm
parents: 18310
diff changeset
   281
            if i = 0 andalso member (op =) mixfixed x then Const (Syntax.fixedN ^ x, T)
14707
2d6350d7b9b7 show_structs option;
wenzelm
parents: 14697
diff changeset
   282
            else if i = 1 andalso not (! show_structs) then
2d6350d7b9b7 show_structs option;
wenzelm
parents: 14697
diff changeset
   283
              Syntax.const "_struct" $ Syntax.const "_indexdefault"
12100
bb10ac677955 proper syntax for structs;
wenzelm
parents: 12093
diff changeset
   284
            else t
bb10ac677955 proper syntax for structs;
wenzelm
parents: 12093
diff changeset
   285
          end
bb10ac677955 proper syntax for structs;
wenzelm
parents: 12093
diff changeset
   286
      | tr' a = a;
bb10ac677955 proper syntax for structs;
wenzelm
parents: 12093
diff changeset
   287
  in tr' end;
bb10ac677955 proper syntax for structs;
wenzelm
parents: 12093
diff changeset
   288
bb10ac677955 proper syntax for structs;
wenzelm
parents: 12093
diff changeset
   289
12576
9fd10052c3f7 added add_fixes: derives mssing type scheme from mixfix;
wenzelm
parents: 12550
diff changeset
   290
(* add syntax *)
9fd10052c3f7 added add_fixes: derives mssing type scheme from mixfix;
wenzelm
parents: 12550
diff changeset
   291
12093
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
   292
local
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
   293
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   294
fun check_mixfix (x, _, mx) =
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   295
  if mx <> NoSyn andalso mx <> Structure andalso
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   296
      (can Syntax.dest_internal x orelse can Syntax.dest_skolem x) then
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   297
    error ("Illegal mixfix syntax for internal/skolem constant " ^ quote x)
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   298
  else ();
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   299
18340
3fdff270aa04 removed fixed_tr: now handled in syntax module;
wenzelm
parents: 18310
diff changeset
   300
fun mixfix x NONE mx = (Syntax.fixedN ^ x, TypeInfer.mixfixT mx, Syntax.fix_mixfix x mx)
3fdff270aa04 removed fixed_tr: now handled in syntax module;
wenzelm
parents: 18310
diff changeset
   301
  | mixfix x (SOME T) mx = (Syntax.fixedN ^ x, T, Syntax.fix_mixfix x mx);
12093
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
   302
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   303
fun prep_mixfix (_, _, Structure) = NONE
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   304
  | prep_mixfix (x, opt_T, mx) = SOME (mixfix x opt_T mx);
12093
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
   305
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   306
fun prep_mixfix' (_, _, Structure) = NONE
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   307
  | prep_mixfix' (x, _, NoSyn) = NONE
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   308
  | prep_mixfix' (x, opt_T, _) = SOME (x, mixfix x opt_T (Syntax.literal x));
12093
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
   309
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   310
fun prep_struct (x, _, Structure) = SOME x
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   311
  | prep_struct _ = NONE;
12093
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
   312
15750
860c282e6ca6 Syntax.mk_trfun;
wenzelm
parents: 15735
diff changeset
   313
fun mk trs = map Syntax.mk_trfun trs;
860c282e6ca6 Syntax.mk_trfun;
wenzelm
parents: 15735
diff changeset
   314
17072
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   315
fun extend_syntax thy extend (global_syn, syn, mk_syn) =
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   316
  let
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   317
    val thy_syn = Sign.syn_of thy;
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   318
    val mk_syn' = extend o mk_syn;
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   319
    val (global_syn', syn') =
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   320
      if Syntax.eq_syntax (global_syn, thy_syn)
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   321
      then (global_syn, extend syn)
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   322
      else (thy_syn, mk_syn' thy_syn);    (*potentially expensive*)
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   323
  in (global_syn', syn', mk_syn') end;
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   324
12093
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
   325
in
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
   326
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   327
fun add_syntax decls ctxt = ctxt |> map_syntax (fn syntax =>
17072
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   328
  let
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   329
    val (syns, structs, mixfixed) = syntax;
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   330
    val thy = theory_of ctxt;
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   331
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   332
    val is_logtype = Sign.is_logtype thy;
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   333
    val structs' = structs @ List.mapPartial prep_struct decls;
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   334
    val mxs = List.mapPartial (tap check_mixfix #> prep_mixfix) decls;
17072
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   335
    val (fixed, mxs_output) = Library.split_list (List.mapPartial prep_mixfix' decls);
12093
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
   336
17072
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   337
    val extend =
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   338
      Syntax.extend_const_gram is_logtype ("", false) mxs_output
18340
3fdff270aa04 removed fixed_tr: now handled in syntax module;
wenzelm
parents: 18310
diff changeset
   339
      #> Syntax.extend_const_gram is_logtype ("", true) mxs;
17072
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   340
    val syns' = extend_syntax thy extend syns;
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   341
  in (syns', structs', fixed @ mixfixed) end);
17072
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   342
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   343
fun syn_of' thy ctxt =
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   344
  let
17072
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   345
    val (syns, structs, _) = syntax_of ctxt;
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   346
    val (atrs, trs, trs', atrs') = Syntax.struct_trfuns structs;
17072
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   347
    val extend = Syntax.extend_trfuns (mk atrs, mk trs, mk trs', mk atrs');
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   348
  in #2 (extend_syntax thy extend syns) end;
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   349
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   350
fun syn_of ctxt = syn_of' (theory_of ctxt) ctxt;
14697
5ad13d05049b improved indexed syntax / implicit structures;
wenzelm
parents: 14665
diff changeset
   351
12093
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
   352
end;
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
   353
17072
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   354
fun transfer thy = add_syntax [] o Context.transfer_proof thy;
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   355
12093
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
   356
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
   357
14828
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
   358
(** pretty printing **)
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
   359
17072
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   360
fun pretty_term' thy ctxt t = Sign.pretty_term' (syn_of' thy ctxt) thy (context_tr' ctxt t);
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   361
fun pretty_term ctxt t = pretty_term' (theory_of ctxt) ctxt (context_tr' ctxt t);
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16348
diff changeset
   362
fun pretty_typ ctxt T = Sign.pretty_typ (theory_of ctxt) T;
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16348
diff changeset
   363
fun pretty_sort ctxt S = Sign.pretty_sort (theory_of ctxt) S;
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16348
diff changeset
   364
fun pretty_classrel ctxt cs = Sign.pretty_classrel (theory_of ctxt) cs;
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16348
diff changeset
   365
fun pretty_arity ctxt ar = Sign.pretty_arity (theory_of ctxt) ar;
14828
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
   366
14974
b1ecb7859c99 avoid premature evaluation of syn_of (wastes time in conjunction with pp);
wenzelm
parents: 14901
diff changeset
   367
fun pp ctxt = Pretty.pp (pretty_term ctxt, pretty_typ ctxt, pretty_sort ctxt,
b1ecb7859c99 avoid premature evaluation of syn_of (wastes time in conjunction with pp);
wenzelm
parents: 14901
diff changeset
   368
  pretty_classrel ctxt, pretty_arity ctxt);
14828
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
   369
17451
cfa8b1ebfc9a added auto_fix (from proof.ML);
wenzelm
parents: 17412
diff changeset
   370
fun pretty_thm ctxt th =
cfa8b1ebfc9a added auto_fix (from proof.ML);
wenzelm
parents: 17412
diff changeset
   371
  Display.pretty_thm_aux (pp ctxt) false true (assms_of ctxt) th;
14828
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
   372
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
   373
fun pretty_thms ctxt [th] = pretty_thm ctxt th
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
   374
  | pretty_thms ctxt ths = Pretty.blk (0, Pretty.fbreaks (map (pretty_thm ctxt) ths));
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
   375
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
   376
fun pretty_fact ctxt ("", ths) = pretty_thms ctxt ths
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
   377
  | pretty_fact ctxt (a, [th]) =
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
   378
      Pretty.block [Pretty.str (a ^ ":"), Pretty.brk 1, pretty_thm ctxt th]
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
   379
  | pretty_fact ctxt (a, ths) =
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
   380
      Pretty.block (Pretty.fbreaks (Pretty.str (a ^ ":") :: map (pretty_thm ctxt) ths));
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
   381
17072
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   382
fun pretty_proof ctxt prf =
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   383
  pretty_term' (ProofSyntax.proof_syntax prf (theory_of ctxt)) ctxt
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   384
    (ProofSyntax.term_of_proof prf);
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   385
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   386
fun pretty_proof_of ctxt full th =
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   387
  pretty_proof ctxt (ProofSyntax.proof_of full th);
501c28052aea added transfer;
wenzelm
parents: 16992
diff changeset
   388
17860
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
   389
val string_of_typ = Pretty.string_of oo pretty_typ;
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
   390
val string_of_term = Pretty.string_of oo pretty_term;
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
   391
val string_of_thm = Pretty.string_of oo pretty_thm;
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
   392
14828
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
   393
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
   394
7663
460fedf14b09 export def_sort, def_type;
wenzelm
parents: 7606
diff changeset
   395
(** default sorts and types **)
460fedf14b09 export def_sort, def_type;
wenzelm
parents: 7606
diff changeset
   396
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17384
diff changeset
   397
val def_sort = Vartab.lookup o #2 o defaults_of;
7663
460fedf14b09 export def_sort, def_type;
wenzelm
parents: 7606
diff changeset
   398
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   399
fun def_type ctxt pattern xi =
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   400
  let val {binds, defaults = (types, _, _, _), ...} = rep_context ctxt in
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17384
diff changeset
   401
    (case Vartab.lookup types xi of
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   402
      NONE =>
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   403
        if pattern then NONE
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17384
diff changeset
   404
        else Vartab.lookup binds xi |> Option.map (TypeInfer.polymorphicT o #2)
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   405
    | some => some)
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   406
  end;
7663
460fedf14b09 export def_sort, def_type;
wenzelm
parents: 7606
diff changeset
   407
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   408
val used_types = #3 o defaults_of;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   409
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17384
diff changeset
   410
fun default_type ctxt x = Vartab.lookup (#1 (defaults_of ctxt)) (x, ~1);
12414
61e1681b0b5d added default_type;
wenzelm
parents: 12309
diff changeset
   411
7663
460fedf14b09 export def_sort, def_type;
wenzelm
parents: 7606
diff changeset
   412
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   413
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   414
(** prepare types **)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   415
9504
8168600e88a5 typ_no_norm;
wenzelm
parents: 9470
diff changeset
   416
local
8168600e88a5 typ_no_norm;
wenzelm
parents: 9470
diff changeset
   417
8168600e88a5 typ_no_norm;
wenzelm
parents: 9470
diff changeset
   418
fun read_typ_aux read ctxt s =
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   419
  read (syn_of ctxt) (theory_of ctxt, def_sort ctxt) s;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   420
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   421
fun cert_typ_aux cert ctxt raw_T =
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   422
  cert (theory_of ctxt) raw_T handle TYPE (msg, _, _) => error msg;
9504
8168600e88a5 typ_no_norm;
wenzelm
parents: 9470
diff changeset
   423
8168600e88a5 typ_no_norm;
wenzelm
parents: 9470
diff changeset
   424
in
8168600e88a5 typ_no_norm;
wenzelm
parents: 9470
diff changeset
   425
16348
7504fe04170f renamed extern to extern_thm;
wenzelm
parents: 16147
diff changeset
   426
val read_typ        = read_typ_aux Sign.read_typ';
7504fe04170f renamed extern to extern_thm;
wenzelm
parents: 16147
diff changeset
   427
val read_typ_syntax = read_typ_aux Sign.read_typ_syntax';
7504fe04170f renamed extern to extern_thm;
wenzelm
parents: 16147
diff changeset
   428
val read_typ_abbrev = read_typ_aux Sign.read_typ_abbrev';
7504fe04170f renamed extern to extern_thm;
wenzelm
parents: 16147
diff changeset
   429
val cert_typ        = cert_typ_aux Sign.certify_typ;
7504fe04170f renamed extern to extern_thm;
wenzelm
parents: 16147
diff changeset
   430
val cert_typ_syntax = cert_typ_aux Sign.certify_typ_syntax;
7504fe04170f renamed extern to extern_thm;
wenzelm
parents: 16147
diff changeset
   431
val cert_typ_abbrev = cert_typ_aux Sign.certify_typ_abbrev;
9504
8168600e88a5 typ_no_norm;
wenzelm
parents: 9470
diff changeset
   432
8168600e88a5 typ_no_norm;
wenzelm
parents: 9470
diff changeset
   433
end;
8168600e88a5 typ_no_norm;
wenzelm
parents: 9470
diff changeset
   434
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   435
7679
99912beb8fa0 improved 'fix' / Skolem interfaces;
wenzelm
parents: 7670
diff changeset
   436
(* internalize Skolem constants *)
99912beb8fa0 improved 'fix' / Skolem interfaces;
wenzelm
parents: 7670
diff changeset
   437
17184
3d80209e9a53 use AList operations;
wenzelm
parents: 17072
diff changeset
   438
val lookup_skolem = AList.lookup (op =) o fixes_of;
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
   439
fun get_skolem ctxt x = the_default x (lookup_skolem ctxt x);
7679
99912beb8fa0 improved 'fix' / Skolem interfaces;
wenzelm
parents: 7670
diff changeset
   440
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   441
fun no_skolem internal x =
9291
23705d14be8f "_i" arguments now expected to have skolems already internalized;
wenzelm
parents: 9274
diff changeset
   442
  if can Syntax.dest_skolem x then
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   443
    error ("Illegal reference to internal Skolem constant: " ^ quote x)
12504
5b46173df7ad export used_types;
wenzelm
parents: 12414
diff changeset
   444
  else if not internal andalso can Syntax.dest_internal x then
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   445
    error ("Illegal reference to internal variable: " ^ quote x)
7679
99912beb8fa0 improved 'fix' / Skolem interfaces;
wenzelm
parents: 7670
diff changeset
   446
  else x;
99912beb8fa0 improved 'fix' / Skolem interfaces;
wenzelm
parents: 7670
diff changeset
   447
14720
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
   448
fun intern_skolem ctxt internal =
7679
99912beb8fa0 improved 'fix' / Skolem interfaces;
wenzelm
parents: 7670
diff changeset
   449
  let
99912beb8fa0 improved 'fix' / Skolem interfaces;
wenzelm
parents: 7670
diff changeset
   450
    fun intern (t as Free (x, T)) =
14720
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
   451
          if internal x then t
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
   452
          else
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   453
            (case lookup_skolem ctxt (no_skolem false x) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   454
              SOME x' => Free (x', T)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   455
            | NONE => t)
7679
99912beb8fa0 improved 'fix' / Skolem interfaces;
wenzelm
parents: 7670
diff changeset
   456
      | intern (t $ u) = intern t $ intern u
99912beb8fa0 improved 'fix' / Skolem interfaces;
wenzelm
parents: 7670
diff changeset
   457
      | intern (Abs (x, T, t)) = Abs (x, T, intern t)
99912beb8fa0 improved 'fix' / Skolem interfaces;
wenzelm
parents: 7670
diff changeset
   458
      | intern a = a;
99912beb8fa0 improved 'fix' / Skolem interfaces;
wenzelm
parents: 7670
diff changeset
   459
  in intern end;
99912beb8fa0 improved 'fix' / Skolem interfaces;
wenzelm
parents: 7670
diff changeset
   460
99912beb8fa0 improved 'fix' / Skolem interfaces;
wenzelm
parents: 7670
diff changeset
   461
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
   462
(* externalize Skolem constants -- approximation only! *)
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
   463
18255
5ef79b75a002 revert_skolem: fall back on Syntax.deskolem;
wenzelm
parents: 18211
diff changeset
   464
fun rev_skolem ctxt =
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
   465
  let val rev_fixes = map Library.swap (fixes_of ctxt)
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
   466
  in AList.lookup (op =) rev_fixes end;
9133
bc3742f62b80 added extern_skolem;
wenzelm
parents: 9007
diff changeset
   467
18255
5ef79b75a002 revert_skolem: fall back on Syntax.deskolem;
wenzelm
parents: 18211
diff changeset
   468
fun revert_skolem ctxt x =
5ef79b75a002 revert_skolem: fall back on Syntax.deskolem;
wenzelm
parents: 18211
diff changeset
   469
  (case rev_skolem ctxt x of
5ef79b75a002 revert_skolem: fall back on Syntax.deskolem;
wenzelm
parents: 18211
diff changeset
   470
    SOME x' => x'
18375
99deeed095ae removed Syntax.deskolem;
wenzelm
parents: 18340
diff changeset
   471
  | NONE => perhaps (try Syntax.dest_skolem) x);
18255
5ef79b75a002 revert_skolem: fall back on Syntax.deskolem;
wenzelm
parents: 18211
diff changeset
   472
9133
bc3742f62b80 added extern_skolem;
wenzelm
parents: 9007
diff changeset
   473
fun extern_skolem ctxt =
bc3742f62b80 added extern_skolem;
wenzelm
parents: 9007
diff changeset
   474
  let
18255
5ef79b75a002 revert_skolem: fall back on Syntax.deskolem;
wenzelm
parents: 18211
diff changeset
   475
    val revert = rev_skolem ctxt;
9133
bc3742f62b80 added extern_skolem;
wenzelm
parents: 9007
diff changeset
   476
    fun extern (t as Free (x, T)) =
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
   477
        (case revert x of
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
   478
          SOME x' => Free (if lookup_skolem ctxt x' = SOME x then x' else NameSpace.hidden x', T)
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
   479
        | NONE => t)
9133
bc3742f62b80 added extern_skolem;
wenzelm
parents: 9007
diff changeset
   480
      | extern (t $ u) = extern t $ extern u
bc3742f62b80 added extern_skolem;
wenzelm
parents: 9007
diff changeset
   481
      | extern (Abs (x, T, t)) = Abs (x, T, extern t)
bc3742f62b80 added extern_skolem;
wenzelm
parents: 9007
diff changeset
   482
      | extern a = a;
bc3742f62b80 added extern_skolem;
wenzelm
parents: 9007
diff changeset
   483
  in extern end
bc3742f62b80 added extern_skolem;
wenzelm
parents: 9007
diff changeset
   484
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   485
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
   486
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   487
(** prepare terms and propositions **)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   488
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   489
(*
16501
fec0cf020bad thmref: Name vs. NameSelection;
wenzelm
parents: 16458
diff changeset
   490
  (1) read / certify wrt. theory of context
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   491
  (2) intern Skolem constants
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   492
  (3) expand term bindings
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   493
*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   494
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   495
16501
fec0cf020bad thmref: Name vs. NameSelection;
wenzelm
parents: 16458
diff changeset
   496
(* read wrt. theory *)     (*exception ERROR*)
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   497
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16348
diff changeset
   498
fun read_def_termTs freeze pp syn thy (types, sorts, used) sTs =
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16348
diff changeset
   499
  Sign.read_def_terms' pp (Sign.is_logtype thy) syn (thy, types, sorts) used freeze sTs;
5874
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   500
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   501
fun read_def_termT freeze pp syn thy defaults sT =
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   502
  apfst hd (read_def_termTs freeze pp syn thy defaults [sT]);
14828
15d12761ba54 improved output; refer to Pretty.pp;
wenzelm
parents: 14780
diff changeset
   503
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   504
fun read_term_thy freeze pp syn thy defaults s =
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   505
  #1 (read_def_termT freeze pp syn thy defaults (s, TypeInfer.logicT));
5874
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   506
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   507
fun read_prop_thy freeze pp syn thy defaults s =
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   508
  #1 (read_def_termT freeze pp syn thy defaults (s, propT));
12072
4281198fb8cd local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents: 12066
diff changeset
   509
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   510
fun read_terms_thy freeze pp syn thy defaults =
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   511
  #1 o read_def_termTs freeze pp syn thy defaults o map (rpair TypeInfer.logicT);
12072
4281198fb8cd local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents: 12066
diff changeset
   512
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   513
fun read_props_thy freeze pp syn thy defaults =
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   514
  #1 o read_def_termTs freeze pp syn thy defaults o map (rpair propT);
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   515
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   516
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   517
(* norm_term *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   518
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   519
(*beta normal form for terms (not eta normal form), chase variables in
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   520
  bindings environment (code taken from Pure/envir.ML)*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   521
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   522
fun unifyT ctxt (T, U) =
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   523
  let val maxidx = Int.max (Term.maxidx_of_typ T, Term.maxidx_of_typ U)
16948
3aef68881781 Sign.typ_unify;
wenzelm
parents: 16894
diff changeset
   524
  in #1 (Sign.typ_unify (theory_of ctxt) (T, U) (Vartab.empty, maxidx)) end;
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   525
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   526
fun norm_term ctxt schematic =
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   527
  let
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   528
    (*raised when norm has no effect on a term, to do sharing instead of copying*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   529
    exception SAME;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   530
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   531
    val binds = binds_of ctxt;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   532
    fun norm (t as Var (xi, T)) =
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17384
diff changeset
   533
          (case Vartab.lookup binds xi of
15758
07e382399a96 binds/thms: do not store options, but delete from table;
wenzelm
parents: 15750
diff changeset
   534
            SOME (u, U) =>
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   535
              let
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   536
                val env = unifyT ctxt (T, U) handle Type.TUNIFY =>
14174
f3cafd2929d5 Methods rule_tac etc support static (Isar) contexts.
ballarin
parents: 13629
diff changeset
   537
                  raise TYPE ("norm_term: ill-typed variable assignment", [T, U], [t, u]);
15798
016f3be5a5ec Adapted to new interface of instantiation and unification / matching functions.
berghofe
parents: 15758
diff changeset
   538
                val u' = Envir.subst_TVars env u;
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   539
              in norm u' handle SAME => u' end
15758
07e382399a96 binds/thms: do not store options, but delete from table;
wenzelm
parents: 15750
diff changeset
   540
          | NONE =>
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   541
            if schematic then raise SAME
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   542
            else error ("Unbound schematic variable: " ^ Syntax.string_of_vname xi))
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   543
      | norm (Abs (a, T, body)) =  Abs (a, T, norm body)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   544
      | norm (Abs (_, _, body) $ t) = normh (subst_bound (t, body))
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   545
      | norm (f $ t) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   546
          ((case norm f of
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   547
            Abs (_, _, body) => normh (subst_bound (t, body))
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   548
          | nf => nf $ (norm t handle SAME => t)) handle SAME => f $ norm t)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   549
      | norm _ =  raise SAME
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   550
    and normh t = norm t handle SAME => t
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   551
  in normh end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   552
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   553
6550
68f950b1a664 dummy patterns;
wenzelm
parents: 6528
diff changeset
   554
(* dummy patterns *)
68f950b1a664 dummy patterns;
wenzelm
parents: 6528
diff changeset
   555
18310
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
   556
val prepare_dummies =
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
   557
  let val next = ref 1 in
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
   558
    fn t =>
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
   559
      let val (i, u) = Term.replace_dummy_patterns (! next, t)
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
   560
      in next := i; u end
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
   561
  end;
6762
a9a515a43ae0 read_term/prop_pat: do not freeze;
wenzelm
parents: 6721
diff changeset
   562
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   563
fun reject_dummies t = Term.no_dummy_patterns t
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   564
  handle TERM _ => error "Illegal dummy pattern(s) in term";
6550
68f950b1a664 dummy patterns;
wenzelm
parents: 6528
diff changeset
   565
68f950b1a664 dummy patterns;
wenzelm
parents: 6528
diff changeset
   566
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   567
(* read terms *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   568
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   569
local
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   570
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   571
fun append_env e1 e2 x = (case e2 x of NONE => e1 x | some => some);
14720
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
   572
16031
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   573
fun gen_read' read app pattern schematic
14720
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
   574
    ctxt internal more_types more_sorts more_used s =
14174
f3cafd2929d5 Methods rule_tac etc support static (Isar) contexts.
ballarin
parents: 13629
diff changeset
   575
  let
14720
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
   576
    val types = append_env (def_type ctxt pattern) more_types;
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
   577
    val sorts = append_env (def_sort ctxt) more_sorts;
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
   578
    val used = used_types ctxt @ more_used;
14174
f3cafd2929d5 Methods rule_tac etc support static (Isar) contexts.
ballarin
parents: 13629
diff changeset
   579
  in
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   580
    (read (pp ctxt) (syn_of ctxt) (theory_of ctxt) (types, sorts, used) s
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   581
      handle TERM (msg, _) => error msg)
14720
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
   582
    |> app (intern_skolem ctxt internal)
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
   583
    |> app (if pattern then I else norm_term ctxt schematic)
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   584
    |> app (if pattern then prepare_dummies else reject_dummies)
14720
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
   585
  end;
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
   586
16031
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   587
fun gen_read read app pattern schematic ctxt =
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   588
  gen_read' read app pattern schematic ctxt (K false) (K NONE) (K NONE) [];
14720
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
   589
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   590
in
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   591
16031
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   592
val read_termTs           = gen_read' (read_def_termTs false) (apfst o map) false false;
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   593
val read_termTs_schematic = gen_read' (read_def_termTs false) (apfst o map) false true;
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   594
14720
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
   595
fun read_term_pats T ctxt =
16031
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   596
  #1 o gen_read (read_def_termTs false) (apfst o map) true false ctxt o map (rpair T);
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   597
val read_prop_pats = read_term_pats propT;
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   598
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   599
fun read_term_legacy ctxt =
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16348
diff changeset
   600
  gen_read' (read_term_thy true) I false false ctxt (K true) (K NONE) (K NONE) [];
14720
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
   601
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16348
diff changeset
   602
val read_term              = gen_read (read_term_thy true) I false false;
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16348
diff changeset
   603
val read_prop              = gen_read (read_prop_thy true) I false false;
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16348
diff changeset
   604
val read_prop_schematic    = gen_read (read_prop_thy true) I false true;
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16348
diff changeset
   605
val read_terms             = gen_read (read_terms_thy true) map false false;
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16348
diff changeset
   606
fun read_props schematic   = gen_read (read_props_thy true) map false schematic;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   607
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   608
end;
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   609
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   610
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   611
(* certify terms *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   612
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   613
local
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   614
14720
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
   615
fun gen_cert cert pattern schematic ctxt t = t
ceff6d4fb836 cleanup up read functions, include liberal versions;
wenzelm
parents: 14707
diff changeset
   616
  |> (if pattern then I else norm_term ctxt schematic)
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16348
diff changeset
   617
  |> (fn t' => cert (pp ctxt) (theory_of ctxt) t'
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   618
    handle TYPE (msg, _, _) => error msg
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   619
      | TERM (msg, _) => error msg);
16501
fec0cf020bad thmref: Name vs. NameSelection;
wenzelm
parents: 16458
diff changeset
   620
fec0cf020bad thmref: Name vs. NameSelection;
wenzelm
parents: 16458
diff changeset
   621
val certify_term = #1 ooo Sign.certify_term;
fec0cf020bad thmref: Name vs. NameSelection;
wenzelm
parents: 16458
diff changeset
   622
val certify_prop = #1 ooo Sign.certify_prop;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   623
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   624
in
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   625
16501
fec0cf020bad thmref: Name vs. NameSelection;
wenzelm
parents: 16458
diff changeset
   626
val cert_term = gen_cert certify_term false false;
fec0cf020bad thmref: Name vs. NameSelection;
wenzelm
parents: 16458
diff changeset
   627
val cert_prop = gen_cert certify_prop false false;
fec0cf020bad thmref: Name vs. NameSelection;
wenzelm
parents: 16458
diff changeset
   628
val cert_props = map oo gen_cert certify_prop false;
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   629
16501
fec0cf020bad thmref: Name vs. NameSelection;
wenzelm
parents: 16458
diff changeset
   630
fun cert_term_pats _ = map o gen_cert certify_term true false;
fec0cf020bad thmref: Name vs. NameSelection;
wenzelm
parents: 16458
diff changeset
   631
val cert_prop_pats = map o gen_cert certify_prop true false;
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   632
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   633
end;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   634
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   635
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   636
(* declare terms *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   637
10381
4dfbcad19bfb fixed two obscurities of "fix": predeclare_terms;
wenzelm
parents: 9733
diff changeset
   638
local
4dfbcad19bfb fixed two obscurities of "fix": predeclare_terms;
wenzelm
parents: 9733
diff changeset
   639
16861
7446b4be013b tuned fold on terms;
wenzelm
parents: 16850
diff changeset
   640
val ins_types = fold_aterms
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17384
diff changeset
   641
  (fn Free (x, T) => Vartab.update ((x, ~1), T)
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17384
diff changeset
   642
    | Var v => Vartab.update v
16861
7446b4be013b tuned fold on terms;
wenzelm
parents: 16850
diff changeset
   643
    | _ => I);
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   644
16861
7446b4be013b tuned fold on terms;
wenzelm
parents: 16850
diff changeset
   645
val ins_sorts = fold_types (fold_atyps
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17384
diff changeset
   646
  (fn TFree (x, S) => Vartab.update ((x, ~1), S)
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17384
diff changeset
   647
    | TVar v => Vartab.update v
16861
7446b4be013b tuned fold on terms;
wenzelm
parents: 16850
diff changeset
   648
    | _ => I));
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   649
16861
7446b4be013b tuned fold on terms;
wenzelm
parents: 16850
diff changeset
   650
val ins_used = fold_term_types (fn t =>
7446b4be013b tuned fold on terms;
wenzelm
parents: 16850
diff changeset
   651
  fold_atyps (fn TFree (x, _) => insert (op =) x | _ => I));
12291
43f37745b600 type variables: clarified "used" vs. "occ";
wenzelm
parents: 12213
diff changeset
   652
16861
7446b4be013b tuned fold on terms;
wenzelm
parents: 16850
diff changeset
   653
val ins_occs = fold_term_types (fn t =>
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17384
diff changeset
   654
  fold_atyps (fn TFree (x, _) => Symtab.update_multi (x, t) | _ => I));
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   655
16861
7446b4be013b tuned fold on terms;
wenzelm
parents: 16850
diff changeset
   656
fun ins_skolem def_ty = fold_rev (fn (x, x') =>
7446b4be013b tuned fold on terms;
wenzelm
parents: 16850
diff changeset
   657
  (case def_ty x' of
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17384
diff changeset
   658
    SOME T => Vartab.update ((x, ~1), T)
16861
7446b4be013b tuned fold on terms;
wenzelm
parents: 16850
diff changeset
   659
  | NONE => I));
5994
7b84677315ed fixed declatation of patterns and skolem;
wenzelm
parents: 5935
diff changeset
   660
16031
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   661
in
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   662
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   663
fun declare_syntax t =
18340
3fdff270aa04 removed fixed_tr: now handled in syntax module;
wenzelm
parents: 18310
diff changeset
   664
  map_defaults (fn (types, sorts, used, occ) => (ins_types t types, sorts, used, occ))
3fdff270aa04 removed fixed_tr: now handled in syntax module;
wenzelm
parents: 18310
diff changeset
   665
  #> map_defaults (fn (types, sorts, used, occ) => (types, ins_sorts t sorts, used, occ))
3fdff270aa04 removed fixed_tr: now handled in syntax module;
wenzelm
parents: 18310
diff changeset
   666
  #> map_defaults (fn (types, sorts, used, occ) => (types, sorts, ins_used t used, occ));
10381
4dfbcad19bfb fixed two obscurities of "fix": predeclare_terms;
wenzelm
parents: 9733
diff changeset
   667
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   668
fun declare_var (x, opt_T, mx) =
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   669
  declare_syntax (Free (x, case opt_T of SOME T => T | NONE => TypeInfer.mixfixT mx));
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   670
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   671
fun declare_term t ctxt =
16031
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   672
  ctxt
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   673
  |> declare_syntax t
16861
7446b4be013b tuned fold on terms;
wenzelm
parents: 16850
diff changeset
   674
  |> map_defaults (fn (types, sorts, used, occ) => (types, sorts, used, ins_occs t occ))
12291
43f37745b600 type variables: clarified "used" vs. "occ";
wenzelm
parents: 12213
diff changeset
   675
  |> map_defaults (fn (types, sorts, used, occ) =>
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   676
      (ins_skolem (fn x => Vartab.lookup types (x, ~1)) (fixes_of ctxt) types, sorts, used, occ));
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   677
18770
434f660d3068 renamed inferred_type to inferred_param;
wenzelm
parents: 18743
diff changeset
   678
end;
434f660d3068 renamed inferred_type to inferred_param;
wenzelm
parents: 18743
diff changeset
   679
434f660d3068 renamed inferred_type to inferred_param;
wenzelm
parents: 18743
diff changeset
   680
434f660d3068 renamed inferred_type to inferred_param;
wenzelm
parents: 18743
diff changeset
   681
(* inferred types of parameters *)
434f660d3068 renamed inferred_type to inferred_param;
wenzelm
parents: 18743
diff changeset
   682
434f660d3068 renamed inferred_type to inferred_param;
wenzelm
parents: 18743
diff changeset
   683
fun infer_type ctxt x =
434f660d3068 renamed inferred_type to inferred_param;
wenzelm
parents: 18743
diff changeset
   684
  (case try (fn () =>
434f660d3068 renamed inferred_type to inferred_param;
wenzelm
parents: 18743
diff changeset
   685
      Sign.infer_types (pp ctxt) (theory_of ctxt) (def_type ctxt false) (def_sort ctxt)
434f660d3068 renamed inferred_type to inferred_param;
wenzelm
parents: 18743
diff changeset
   686
        (used_types ctxt) true ([Free (x, dummyT)], TypeInfer.logicT)) () of
434f660d3068 renamed inferred_type to inferred_param;
wenzelm
parents: 18743
diff changeset
   687
    SOME (Free (_, T), _) => T
434f660d3068 renamed inferred_type to inferred_param;
wenzelm
parents: 18743
diff changeset
   688
  | _ => error ("Failed to infer type of fixed variable " ^ quote x));
434f660d3068 renamed inferred_type to inferred_param;
wenzelm
parents: 18743
diff changeset
   689
434f660d3068 renamed inferred_type to inferred_param;
wenzelm
parents: 18743
diff changeset
   690
fun inferred_param x ctxt =
18619
fa61df848dea added infer_type, declared_type;
wenzelm
parents: 18609
diff changeset
   691
  let val T = infer_type ctxt x
fa61df848dea added infer_type, declared_type;
wenzelm
parents: 18609
diff changeset
   692
  in ((x, T), ctxt |> declare_term (Free (x, T))) end;
fa61df848dea added infer_type, declared_type;
wenzelm
parents: 18609
diff changeset
   693
18770
434f660d3068 renamed inferred_type to inferred_param;
wenzelm
parents: 18743
diff changeset
   694
fun inferred_fixes ctxt =
434f660d3068 renamed inferred_type to inferred_param;
wenzelm
parents: 18743
diff changeset
   695
  fold_map inferred_param (rev (fixed_names_of ctxt)) ctxt;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   696
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   697
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   698
(* type and constant names *)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   699
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   700
fun read_tyname ctxt c =
18340
3fdff270aa04 removed fixed_tr: now handled in syntax module;
wenzelm
parents: 18310
diff changeset
   701
  if member (op =) (used_types ctxt) c then
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
   702
    TFree (c, the_default (Sign.defaultS (theory_of ctxt)) (def_sort ctxt (c, ~1)))
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16348
diff changeset
   703
  else Sign.read_tyname (theory_of ctxt) c;
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   704
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   705
fun read_const ctxt c =
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   706
  (case lookup_skolem ctxt c of
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   707
    SOME c' => Free (c', dummyT)
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16348
diff changeset
   708
  | NONE => Sign.read_const (theory_of ctxt) c);
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   709
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   710
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   711
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   712
(** Hindley-Milner polymorphism **)
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   713
7925
8c50b68b890b warn_extra_tfrees (after declare_term);
wenzelm
parents: 7679
diff changeset
   714
(* warn_extra_tfrees *)
8c50b68b890b warn_extra_tfrees (after declare_term);
wenzelm
parents: 7679
diff changeset
   715
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   716
fun warn_extra_tfrees ctxt1 ctxt2 =
12130
30d9143aff7e syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents: 12123
diff changeset
   717
  let
17451
cfa8b1ebfc9a added auto_fix (from proof.ML);
wenzelm
parents: 17412
diff changeset
   718
    fun occs_typ a (Type (_, Ts)) = exists (occs_typ a) Ts
cfa8b1ebfc9a added auto_fix (from proof.ML);
wenzelm
parents: 17412
diff changeset
   719
      | occs_typ a (TFree (b, _)) = a = b
cfa8b1ebfc9a added auto_fix (from proof.ML);
wenzelm
parents: 17412
diff changeset
   720
      | occs_typ _ (TVar _) = false;
cfa8b1ebfc9a added auto_fix (from proof.ML);
wenzelm
parents: 17412
diff changeset
   721
    fun occs_free a (Free (x, _)) =
cfa8b1ebfc9a added auto_fix (from proof.ML);
wenzelm
parents: 17412
diff changeset
   722
          (case def_type ctxt1 false (x, ~1) of
cfa8b1ebfc9a added auto_fix (from proof.ML);
wenzelm
parents: 17412
diff changeset
   723
            SOME T => if occs_typ a T then I else cons (a, x)
cfa8b1ebfc9a added auto_fix (from proof.ML);
wenzelm
parents: 17412
diff changeset
   724
          | NONE => cons (a, x))
cfa8b1ebfc9a added auto_fix (from proof.ML);
wenzelm
parents: 17412
diff changeset
   725
      | occs_free _ _ = I;
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   726
17451
cfa8b1ebfc9a added auto_fix (from proof.ML);
wenzelm
parents: 17412
diff changeset
   727
    val occs1 = type_occs_of ctxt1 and occs2 = type_occs_of ctxt2;
cfa8b1ebfc9a added auto_fix (from proof.ML);
wenzelm
parents: 17412
diff changeset
   728
    val extras = Symtab.fold (fn (a, ts) =>
cfa8b1ebfc9a added auto_fix (from proof.ML);
wenzelm
parents: 17412
diff changeset
   729
      if Symtab.defined occs1 a then I else fold (occs_free a) ts) occs2 [];
18428
4059413acbc1 sort_distinct;
wenzelm
parents: 18418
diff changeset
   730
    val tfrees = map #1 extras |> sort_distinct string_ord;
4059413acbc1 sort_distinct;
wenzelm
parents: 18418
diff changeset
   731
    val frees = map #2 extras |> sort_distinct string_ord;
12130
30d9143aff7e syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents: 12123
diff changeset
   732
  in
30d9143aff7e syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents: 12123
diff changeset
   733
    if null extras then ()
17451
cfa8b1ebfc9a added auto_fix (from proof.ML);
wenzelm
parents: 17412
diff changeset
   734
    else warning ("Introduced fixed type variable(s): " ^ commas tfrees ^ " in " ^
17860
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
   735
      space_implode " or " (map (string_of_term ctxt2 o Syntax.free) frees));
12130
30d9143aff7e syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents: 12123
diff changeset
   736
    ctxt2
30d9143aff7e syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents: 12123
diff changeset
   737
  end;
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   738
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   739
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   740
(* generalize type variables *)
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   741
12550
32843ad8160a generalize type variables properly: start with occurrences in objects
wenzelm
parents: 12530
diff changeset
   742
fun generalize_tfrees inner outer =
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   743
  let
12057
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
   744
    val extra_fixes = fixed_names_of inner \\ fixed_names_of outer;
18340
3fdff270aa04 removed fixed_tr: now handled in syntax module;
wenzelm
parents: 18310
diff changeset
   745
    fun still_fixed (Free (x, _)) = not (member (op =) extra_fixes x)
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   746
      | still_fixed _ = false;
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   747
    val occs_inner = type_occs_of inner;
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   748
    val occs_outer = type_occs_of outer;
16031
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   749
    fun add a gen =
16894
40f80823b451 Inttab.defined;
wenzelm
parents: 16861
diff changeset
   750
      if Symtab.defined occs_outer a orelse
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17384
diff changeset
   751
        exists still_fixed (Symtab.lookup_multi occs_inner a)
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   752
      then gen else a :: gen;
16031
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   753
  in fn tfrees => fold add tfrees [] end;
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   754
12550
32843ad8160a generalize type variables properly: start with occurrences in objects
wenzelm
parents: 12530
diff changeset
   755
fun generalize inner outer ts =
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   756
  let
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
   757
    val tfrees = generalize_tfrees inner outer (map #1 (fold Term.add_tfrees ts []));
18340
3fdff270aa04 removed fixed_tr: now handled in syntax module;
wenzelm
parents: 18310
diff changeset
   758
    fun gen (x, S) = if member (op =) tfrees x then TVar ((x, 0), S) else TFree (x, S);
12550
32843ad8160a generalize type variables properly: start with occurrences in objects
wenzelm
parents: 12530
diff changeset
   759
  in map (Term.map_term_types (Term.map_type_tfree gen)) ts end;
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   760
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   761
9553
c2e3773475b6 norm_hhf results;
wenzelm
parents: 9540
diff changeset
   762
c2e3773475b6 norm_hhf results;
wenzelm
parents: 9540
diff changeset
   763
(** export theorems **)
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   764
18042
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   765
fun common_exports is_goal inner outer =
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   766
  let
12550
32843ad8160a generalize type variables properly: start with occurrences in objects
wenzelm
parents: 12530
diff changeset
   767
    val gen = generalize_tfrees inner outer;
12057
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
   768
    val fixes = fixed_names_of inner \\ fixed_names_of outer;
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
   769
    val asms = Library.drop (length (assumptions_of outer), assumptions_of inner);
11816
545aab7410ac simplified exporter interface;
wenzelm
parents: 11793
diff changeset
   770
    val exp_asms = map (fn (cprops, exp) => exp is_goal cprops) asms;
16948
3aef68881781 Sign.typ_unify;
wenzelm
parents: 16894
diff changeset
   771
  in
18255
5ef79b75a002 revert_skolem: fall back on Syntax.deskolem;
wenzelm
parents: 18211
diff changeset
   772
    Goal.norm_hhf_protect
16948
3aef68881781 Sign.typ_unify;
wenzelm
parents: 16894
diff changeset
   773
    #> Seq.EVERY (rev exp_asms)
3aef68881781 Sign.typ_unify;
wenzelm
parents: 16894
diff changeset
   774
    #> Seq.map (fn rule =>
11816
545aab7410ac simplified exporter interface;
wenzelm
parents: 11793
diff changeset
   775
      let
16992
38bb4f03a887 Thm.full_prop_of;
wenzelm
parents: 16948
diff changeset
   776
        val thy = Thm.theory_of_thm rule;
38bb4f03a887 Thm.full_prop_of;
wenzelm
parents: 16948
diff changeset
   777
        val prop = Thm.full_prop_of rule;
18152
1d1cc715a9e5 moved find_free to term.ML;
wenzelm
parents: 18138
diff changeset
   778
        val frees = map (Thm.cterm_of thy) (List.mapPartial (Term.find_free prop) fixes);
12550
32843ad8160a generalize type variables properly: start with occurrences in objects
wenzelm
parents: 12530
diff changeset
   779
        val tfrees = gen (Term.add_term_tfree_names (prop, []));
11816
545aab7410ac simplified exporter interface;
wenzelm
parents: 11793
diff changeset
   780
      in
545aab7410ac simplified exporter interface;
wenzelm
parents: 11793
diff changeset
   781
        rule
545aab7410ac simplified exporter interface;
wenzelm
parents: 11793
diff changeset
   782
        |> Drule.forall_intr_list frees
18255
5ef79b75a002 revert_skolem: fall back on Syntax.deskolem;
wenzelm
parents: 18211
diff changeset
   783
        |> Goal.norm_hhf_protect
18138
04f0e4ca1451 tvars_intr_list: natural argument order;
wenzelm
parents: 18122
diff changeset
   784
        |> Drule.tvars_intr_list tfrees |> #2
11816
545aab7410ac simplified exporter interface;
wenzelm
parents: 11793
diff changeset
   785
      end)
545aab7410ac simplified exporter interface;
wenzelm
parents: 11793
diff changeset
   786
  end;
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   787
18785
5ae1f1c1b764 renamed export to export_standard (again!), because it includes Drule.local_standard';
wenzelm
parents: 18770
diff changeset
   788
fun export_standard inner outer =
18122
d5a876195499 removed export_plain;
wenzelm
parents: 18043
diff changeset
   789
  let val exp = common_exports false inner outer in
13378
b261d9cdd6b2 export_standard supercedes export_single;
wenzelm
parents: 13284
diff changeset
   790
    fn th =>
18122
d5a876195499 removed export_plain;
wenzelm
parents: 18043
diff changeset
   791
      (case Seq.pull (exp th) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   792
        SOME (th', _) => th' |> Drule.local_standard
16850
35e07087aba2 sys_error;
wenzelm
parents: 16790
diff changeset
   793
      | NONE => sys_error "Failed to export theorem")
13378
b261d9cdd6b2 export_standard supercedes export_single;
wenzelm
parents: 13284
diff changeset
   794
  end;
12704
7bffaadc581e export_single;
wenzelm
parents: 12576
diff changeset
   795
18122
d5a876195499 removed export_plain;
wenzelm
parents: 18043
diff changeset
   796
val exports = common_exports false;
d5a876195499 removed export_plain;
wenzelm
parents: 18043
diff changeset
   797
val goal_exports = common_exports true;
7925
8c50b68b890b warn_extra_tfrees (after declare_term);
wenzelm
parents: 7679
diff changeset
   798
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   799
15758
07e382399a96 binds/thms: do not store options, but delete from table;
wenzelm
parents: 15750
diff changeset
   800
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   801
(** bindings **)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   802
15758
07e382399a96 binds/thms: do not store options, but delete from table;
wenzelm
parents: 15750
diff changeset
   803
(* delete_update_binds *)
07e382399a96 binds/thms: do not store options, but delete from table;
wenzelm
parents: 15750
diff changeset
   804
07e382399a96 binds/thms: do not store options, but delete from table;
wenzelm
parents: 15750
diff changeset
   805
local
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   806
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   807
val del_bind = map_binds o Vartab.delete_safe;
7606
7905a74eb068 added reset_thms;
wenzelm
parents: 7575
diff changeset
   808
15758
07e382399a96 binds/thms: do not store options, but delete from table;
wenzelm
parents: 15750
diff changeset
   809
fun upd_bind ((x, i), t) =
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   810
  let
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   811
    val T = Term.fastype_of t;
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   812
    val t' =
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   813
      if null (Term.term_tvars t \\ Term.typ_tvars T) then t
8637
wenzelm
parents: 8616
diff changeset
   814
      else Var ((x ^ "_has_extra_type_vars_on_rhs", i), T);
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
   815
  in declare_term t' #> map_binds (Vartab.update ((x, i), (t', T))) end;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   816
15758
07e382399a96 binds/thms: do not store options, but delete from table;
wenzelm
parents: 15750
diff changeset
   817
fun del_upd_bind (xi, NONE) = del_bind xi
07e382399a96 binds/thms: do not store options, but delete from table;
wenzelm
parents: 15750
diff changeset
   818
  | del_upd_bind (xi, SOME t) = upd_bind (xi, t);
7606
7905a74eb068 added reset_thms;
wenzelm
parents: 7575
diff changeset
   819
15758
07e382399a96 binds/thms: do not store options, but delete from table;
wenzelm
parents: 15750
diff changeset
   820
in
07e382399a96 binds/thms: do not store options, but delete from table;
wenzelm
parents: 15750
diff changeset
   821
07e382399a96 binds/thms: do not store options, but delete from table;
wenzelm
parents: 15750
diff changeset
   822
val delete_update_binds = fold del_upd_bind;
07e382399a96 binds/thms: do not store options, but delete from table;
wenzelm
parents: 15750
diff changeset
   823
07e382399a96 binds/thms: do not store options, but delete from table;
wenzelm
parents: 15750
diff changeset
   824
end;
7606
7905a74eb068 added reset_thms;
wenzelm
parents: 7575
diff changeset
   825
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   826
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   827
(* simult_matches *)
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   828
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   829
fun simult_matches ctxt [] = []
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   830
  | simult_matches ctxt pairs =
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   831
      let
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   832
        fun fail () = error "Pattern match failed!";
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   833
16031
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   834
        val maxidx = fold (fn (t1, t2) => fn i =>
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   835
          Int.max (Int.max (Term.maxidx_of_term t1, Term.maxidx_of_term t2), i)) pairs ~1;
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16348
diff changeset
   836
        val envs = Unify.smash_unifiers (theory_of ctxt, Envir.empty maxidx,
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   837
          map swap pairs);    (*prefer assignment of variables from patterns*)
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   838
        val env =
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   839
          (case Seq.pull envs of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   840
            NONE => fail ()
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   841
          | SOME (env, _) => env);    (*ignore further results*)
12309
03e9287be350 name space for local thms (export cond_extern, qualified);
wenzelm
parents: 12291
diff changeset
   842
        val domain =
03e9287be350 name space for local thms (export cond_extern, qualified);
wenzelm
parents: 12291
diff changeset
   843
          filter_out Term.is_replaced_dummy_pattern (map #1 (Drule.vars_of_terms (map #1 pairs)));
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   844
        val _ =    (*may not assign variables from text*)
12309
03e9287be350 name space for local thms (export cond_extern, qualified);
wenzelm
parents: 12291
diff changeset
   845
          if null (map #1 (Envir.alist_of env) inter (map #1 (Drule.vars_of_terms (map #2 pairs))))
03e9287be350 name space for local thms (export cond_extern, qualified);
wenzelm
parents: 12291
diff changeset
   846
          then () else fail ();
16948
3aef68881781 Sign.typ_unify;
wenzelm
parents: 16894
diff changeset
   847
        fun norm_bind (xi, (_, t)) =
18310
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
   848
          if member (op =) domain xi then SOME (xi, Envir.norm_term env t) else NONE;
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   849
      in List.mapPartial norm_bind (Envir.alist_of env) end;
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   850
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   851
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   852
(* add_binds(_i) *)
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   853
7925
8c50b68b890b warn_extra_tfrees (after declare_term);
wenzelm
parents: 7679
diff changeset
   854
local
8c50b68b890b warn_extra_tfrees (after declare_term);
wenzelm
parents: 7679
diff changeset
   855
16031
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   856
fun gen_bind prep (xi as (x, _), raw_t) ctxt =
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   857
  ctxt |> delete_update_binds [(xi, Option.map (prep ctxt) raw_t)];
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   858
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
   859
in
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
   860
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   861
fun drop_schematic (b as (xi, SOME t)) = if null (Term.term_vars t) then b else (xi, NONE)
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   862
  | drop_schematic b = b;
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   863
16031
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   864
val add_binds = fold (gen_bind read_term);
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   865
val add_binds_i = fold (gen_bind cert_term);
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   866
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16348
diff changeset
   867
fun auto_bind f ts ctxt = ctxt |> add_binds_i (map drop_schematic (f (theory_of ctxt) ts));
12147
64e69a8a945f adapted auto_bind_goal, auto_bind_facts;
wenzelm
parents: 12130
diff changeset
   868
val auto_bind_goal = auto_bind AutoBind.goal;
64e69a8a945f adapted auto_bind_goal, auto_bind_facts;
wenzelm
parents: 12130
diff changeset
   869
val auto_bind_facts = auto_bind AutoBind.facts;
7925
8c50b68b890b warn_extra_tfrees (after declare_term);
wenzelm
parents: 7679
diff changeset
   870
8c50b68b890b warn_extra_tfrees (after declare_term);
wenzelm
parents: 7679
diff changeset
   871
end;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   872
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   873
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   874
(* match_bind(_i) *)
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   875
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   876
local
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   877
17860
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
   878
fun prep_bind prep_pats (raw_pats, t) ctxt =
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   879
  let
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   880
    val ctxt' = declare_term t ctxt;
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   881
    val pats = prep_pats (fastype_of t) ctxt' raw_pats;
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   882
    val binds = simult_matches ctxt' (map (rpair t) pats);
17860
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
   883
  in (binds, ctxt') end;
7670
e302e4269087 added cert_skolem;
wenzelm
parents: 7663
diff changeset
   884
10465
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   885
fun gen_binds prep_terms prep_pats gen raw_binds ctxt =
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   886
  let
10465
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   887
    val ts = prep_terms ctxt (map snd raw_binds);
17860
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
   888
    val (binds, ctxt') =
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
   889
      apfst List.concat (fold_map (prep_bind prep_pats) (map fst raw_binds ~~ ts) ctxt);
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   890
    val binds' =
12550
32843ad8160a generalize type variables properly: start with occurrences in objects
wenzelm
parents: 12530
diff changeset
   891
      if gen then map #1 binds ~~ generalize ctxt' ctxt (map #2 binds)
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   892
      else binds;
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   893
    val binds'' = map (apsnd SOME) binds';
18310
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
   894
    val ctxt'' =
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
   895
      warn_extra_tfrees ctxt
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
   896
       (if gen then
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
   897
          ctxt (*sic!*) |> fold declare_term (map #2 binds') |> add_binds_i binds''
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
   898
        else ctxt' |> add_binds_i binds'');
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
   899
  in (ts, ctxt'') end;
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   900
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   901
in
5935
6a82c8a1808f term_pat vs. prop_pat;
wenzelm
parents: 5919
diff changeset
   902
10465
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   903
val match_bind = gen_binds read_terms read_term_pats;
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   904
val match_bind_i = gen_binds (map o cert_term) cert_term_pats;
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   905
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   906
end;
5935
6a82c8a1808f term_pat vs. prop_pat;
wenzelm
parents: 5919
diff changeset
   907
6a82c8a1808f term_pat vs. prop_pat;
wenzelm
parents: 5919
diff changeset
   908
10465
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   909
(* propositions with patterns *)
5935
6a82c8a1808f term_pat vs. prop_pat;
wenzelm
parents: 5919
diff changeset
   910
10465
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   911
local
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   912
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   913
fun prep_propp schematic prep_props prep_pats (context, args) =
10465
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   914
  let
17860
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
   915
    fun prep (_, (raw_pats1, raw_pats2)) (ctxt, prop :: props) =
10465
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   916
          let
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   917
            val ctxt' = declare_term prop ctxt;
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   918
            val pats = prep_pats ctxt' (raw_pats1 @ raw_pats2);    (*simultaneous type inference!*)
17860
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
   919
          in ((prop, splitAt (length raw_pats1, pats)), (ctxt', props)) end
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
   920
      | prep _ _ = sys_error "prep_propp";
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
   921
    val (propp, (context', _)) = (fold_map o fold_map) prep args
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
   922
      (context, prep_props schematic context (List.concat (map (map fst) args)));
10465
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   923
  in (context', propp) end;
5935
6a82c8a1808f term_pat vs. prop_pat;
wenzelm
parents: 5919
diff changeset
   924
10465
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   925
fun matches ctxt (prop, (pats1, pats2)) =
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   926
  simult_matches ctxt (map (rpair prop) pats1 @ map (rpair (Logic.strip_imp_concl prop)) pats2);
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   927
10465
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   928
fun gen_bind_propp prepp (ctxt, raw_args) =
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   929
  let
10465
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   930
    val (ctxt', args) = prepp (ctxt, raw_args);
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   931
    val binds = List.concat (List.concat (map (map (matches ctxt')) args));
10465
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   932
    val propss = map (map #1) args;
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   933
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   934
    (*generalize result: context evaluated now, binds added later*)
8616
90d2fed59be1 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8462
diff changeset
   935
    val gen = generalize ctxt' ctxt;
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   936
    fun gen_binds c = c |> add_binds_i (map #1 binds ~~ map SOME (gen (map #2 binds)));
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   937
  in (ctxt' |> add_binds_i (map (apsnd SOME) binds), (propss, gen_binds)) end;
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
   938
10465
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   939
in
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   940
11925
4747b4b84093 added read_prop_schematic;
wenzelm
parents: 11918
diff changeset
   941
val read_propp = prep_propp false read_props read_prop_pats;
4747b4b84093 added read_prop_schematic;
wenzelm
parents: 11918
diff changeset
   942
val cert_propp = prep_propp false cert_props cert_prop_pats;
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   943
val read_propp_schematic = prep_propp true read_props read_prop_pats;
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   944
val cert_propp_schematic = prep_propp true cert_props cert_prop_pats;
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   945
11925
4747b4b84093 added read_prop_schematic;
wenzelm
parents: 11918
diff changeset
   946
val bind_propp = gen_bind_propp read_propp;
4747b4b84093 added read_prop_schematic;
wenzelm
parents: 11918
diff changeset
   947
val bind_propp_i = gen_bind_propp cert_propp;
4747b4b84093 added read_prop_schematic;
wenzelm
parents: 11918
diff changeset
   948
val bind_propp_schematic = gen_bind_propp read_propp_schematic;
10554
81edb1d201ab schematic props;
wenzelm
parents: 10465
diff changeset
   949
val bind_propp_schematic_i = gen_bind_propp cert_propp_schematic;
6789
0e5a965de17a auto_bind_goal, auto_bind_facts;
wenzelm
parents: 6762
diff changeset
   950
10465
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   951
end;
4aa6f8b5cdc4 added read_terms, read_props (simulataneous type-inference);
wenzelm
parents: 10381
diff changeset
   952
6789
0e5a965de17a auto_bind_goal, auto_bind_facts;
wenzelm
parents: 6762
diff changeset
   953
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   954
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   955
(** theorems **)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   956
18042
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   957
(* fact_tac *)
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   958
18122
d5a876195499 removed export_plain;
wenzelm
parents: 18043
diff changeset
   959
fun comp_incr_tac [] _ st = no_tac st
d5a876195499 removed export_plain;
wenzelm
parents: 18043
diff changeset
   960
  | comp_incr_tac (th :: ths) i st =
d5a876195499 removed export_plain;
wenzelm
parents: 18043
diff changeset
   961
      (Goal.compose_hhf_tac (Drule.incr_indexes st th) i APPEND comp_incr_tac ths i) st;
18042
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   962
18122
d5a876195499 removed export_plain;
wenzelm
parents: 18043
diff changeset
   963
fun fact_tac facts = Tactic.norm_hhf_tac THEN' comp_incr_tac facts;
d5a876195499 removed export_plain;
wenzelm
parents: 18043
diff changeset
   964
d5a876195499 removed export_plain;
wenzelm
parents: 18043
diff changeset
   965
fun some_fact_tac ctxt = SUBGOAL (fn (goal, i) =>
18042
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   966
  let
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   967
    val (_, _, index) = thms_of ctxt;
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   968
    val facts = FactIndex.could_unify index (Term.strip_all_body goal);
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   969
  in fact_tac facts i end);
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   970
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   971
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 5994
diff changeset
   972
(* get_thm(s) *)
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   973
18042
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   974
fun retrieve_thms _ pick ctxt (Fact s) =
16501
fec0cf020bad thmref: Name vs. NameSelection;
wenzelm
parents: 16458
diff changeset
   975
      let
18042
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   976
        val thy = theory_of ctxt;
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   977
        val th = Goal.prove thy [] [] (read_prop ctxt s) (K (ALLGOALS (some_fact_tac ctxt)))
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
   978
          handle ERROR msg => cat_error msg "Failed to retrieve literal fact.";
18042
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   979
      in pick "" [th] end
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   980
  | retrieve_thms from_thy pick ctxt xthmref =
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   981
      let
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   982
        val thy = theory_of ctxt;
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   983
        val (_, (space, tab), _) = thms_of ctxt;
16501
fec0cf020bad thmref: Name vs. NameSelection;
wenzelm
parents: 16458
diff changeset
   984
        val thmref = PureThy.map_name_of_thmref (NameSpace.intern space) xthmref;
fec0cf020bad thmref: Name vs. NameSelection;
wenzelm
parents: 16458
diff changeset
   985
        val name = PureThy.name_of_thmref thmref;
fec0cf020bad thmref: Name vs. NameSelection;
wenzelm
parents: 16458
diff changeset
   986
      in
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17384
diff changeset
   987
        (case Symtab.lookup tab name of
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   988
          SOME ths => map (Thm.transfer thy) (PureThy.select_thm thmref ths)
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
   989
        | NONE => from_thy thy xthmref) |> pick name
18042
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
   990
      end;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   991
9566
0874bf3a909d thms closure;
wenzelm
parents: 9553
diff changeset
   992
val get_thm = retrieve_thms PureThy.get_thms PureThy.single_thm;
0874bf3a909d thms closure;
wenzelm
parents: 9553
diff changeset
   993
val get_thm_closure = retrieve_thms PureThy.get_thms_closure PureThy.single_thm;
0874bf3a909d thms closure;
wenzelm
parents: 9553
diff changeset
   994
val get_thms = retrieve_thms PureThy.get_thms (K I);
0874bf3a909d thms closure;
wenzelm
parents: 9553
diff changeset
   995
val get_thms_closure = retrieve_thms PureThy.get_thms_closure (K I);
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   996
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   997
16031
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   998
(* valid_thms *)
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
   999
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
  1000
fun valid_thms ctxt (name, ths) =
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
  1001
  (case try (fn () => get_thms ctxt (Name name)) () of
16031
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
  1002
    NONE => false
16147
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
  1003
  | SOME ths' => Thm.eq_thms (ths, ths'));
16031
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
  1004
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
  1005
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
  1006
(* lthms_containing *)
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
  1007
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
  1008
fun lthms_containing ctxt spec =
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
  1009
  FactIndex.find (fact_index_of ctxt) spec
18043
2427edb2e8a2 lthms_containing: not o valid_thms;
wenzelm
parents: 18042
diff changeset
  1010
  |> map ((not o valid_thms ctxt) ? apfst (fn name =>
18042
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
  1011
    NameSpace.hidden (if name = "" then "unnamed" else name)));
16031
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
  1012
fbf3471214d6 moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents: 15979
diff changeset
  1013
13425
119ae829ad9b support for split assumptions in cases (hyps vs. prems);
wenzelm
parents: 13415
diff changeset
  1014
(* name space operations *)
12309
03e9287be350 name space for local thms (export cond_extern, qualified);
wenzelm
parents: 12291
diff changeset
  1015
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
  1016
val extern_thm = NameSpace.extern o #1 o #2 o thms_of;
12309
03e9287be350 name space for local thms (export cond_extern, qualified);
wenzelm
parents: 12291
diff changeset
  1017
16147
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
  1018
val qualified_names = map_naming NameSpace.qualified_names;
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
  1019
val no_base_names = map_naming NameSpace.no_base_names;
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
  1020
val custom_accesses = map_naming o NameSpace.custom_accesses;
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
  1021
val restore_naming = map_naming o K o #1 o thms_of;
12309
03e9287be350 name space for local thms (export cond_extern, qualified);
wenzelm
parents: 12291
diff changeset
  1022
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1023
fun hide_thms fully names = map_thms (fn (naming, (space, tab), index) =>
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1024
  (naming, (fold (NameSpace.hide fully) names space, tab), index));
13425
119ae829ad9b support for split assumptions in cases (hyps vs. prems);
wenzelm
parents: 13415
diff changeset
  1025
12309
03e9287be350 name space for local thms (export cond_extern, qualified);
wenzelm
parents: 12291
diff changeset
  1026
17360
fa1f262dbc4e added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents: 17221
diff changeset
  1027
(* put_thms *)
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
  1028
18042
f9890c615c0e added fact_tac, some_fact_tac;
wenzelm
parents: 17977
diff changeset
  1029
fun put_thms ("", NONE) ctxt = ctxt
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1030
  | put_thms ("", SOME ths) ctxt = ctxt |> map_thms (fn (naming, facts, index) =>
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1031
      let
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1032
        val index' = FactIndex.add_local (is_known ctxt) ("", ths) index;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1033
      in (naming, facts, index') end)
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1034
  | put_thms (bname, NONE) ctxt = ctxt |> map_thms (fn (naming, (space, tab), index) =>
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1035
      let
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1036
        val name = NameSpace.full naming bname;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1037
        val tab' = Symtab.delete_safe name tab;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1038
      in (naming, (space, tab'), index) end)
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1039
  | put_thms (bname, SOME ths) ctxt = ctxt |> map_thms (fn (naming, (space, tab), index) =>
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1040
      let
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1041
        val name = NameSpace.full naming bname;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1042
        val space' = NameSpace.declare naming name space;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1043
        val tab' = Symtab.update (name, ths) tab;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1044
        val index' = FactIndex.add_local (is_known ctxt) (name, ths) index;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1045
      in (naming, (space', tab'), index') end);
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
  1046
7606
7905a74eb068 added reset_thms;
wenzelm
parents: 7575
diff changeset
  1047
14564
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14508
diff changeset
  1048
(* note_thmss *)
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
  1049
12711
6a9412dd7d24 have_thmss vs. have_thmss_i;
wenzelm
parents: 12704
diff changeset
  1050
local
16147
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
  1051
17860
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
  1052
fun gen_note_thmss get = fold_map (fn ((name, more_attrs), ths_attrs) => fn ctxt =>
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
  1053
  let
17360
fa1f262dbc4e added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents: 17221
diff changeset
  1054
    fun app (th, attrs) (ct, ths) =
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
  1055
      let val (ct', th') = foldl_map (Thm.proof_attributes (attrs @ more_attrs)) (ct, get ctxt th)
12711
6a9412dd7d24 have_thmss vs. have_thmss_i;
wenzelm
parents: 12704
diff changeset
  1056
      in (ct', th' :: ths) end;
17360
fa1f262dbc4e added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents: 17221
diff changeset
  1057
    val (ctxt', rev_thms) = fold app ths_attrs (ctxt, []);
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
  1058
    val thms = List.concat (rev rev_thms);
17860
b4cf247ea0d2 note_thmss, read/cert_vars etc.: natural argument order;
wenzelm
parents: 17756
diff changeset
  1059
  in ((name, thms), ctxt' |> put_thms (name, SOME thms)) end);
12711
6a9412dd7d24 have_thmss vs. have_thmss_i;
wenzelm
parents: 12704
diff changeset
  1060
6a9412dd7d24 have_thmss vs. have_thmss_i;
wenzelm
parents: 12704
diff changeset
  1061
in
6a9412dd7d24 have_thmss vs. have_thmss_i;
wenzelm
parents: 12704
diff changeset
  1062
16147
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
  1063
val note_thmss = gen_note_thmss get_thms;
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
  1064
val note_thmss_i = gen_note_thmss (K I);
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
  1065
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
  1066
val note_thmss_accesses = gen_note_thmss get_thms;
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
  1067
val note_thmss_accesses_i = gen_note_thmss (K I);
12711
6a9412dd7d24 have_thmss vs. have_thmss_i;
wenzelm
parents: 12704
diff changeset
  1068
6a9412dd7d24 have_thmss vs. have_thmss_i;
wenzelm
parents: 12704
diff changeset
  1069
end;
9196
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 9133
diff changeset
  1070
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
  1071
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
  1072
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1073
(** parameters **)
17360
fa1f262dbc4e added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents: 17221
diff changeset
  1074
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
  1075
(* variables *)
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
  1076
10381
4dfbcad19bfb fixed two obscurities of "fix": predeclare_terms;
wenzelm
parents: 9733
diff changeset
  1077
local
4dfbcad19bfb fixed two obscurities of "fix": predeclare_terms;
wenzelm
parents: 9733
diff changeset
  1078
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1079
fun prep_vars prep_typ internal legacy =
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1080
  fold_map (fn (raw_x, raw_T, raw_mx) => fn ctxt =>
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1081
    let
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1082
      val x = Syntax.const_name raw_x raw_mx;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1083
      val mx = Syntax.fix_mixfix raw_x raw_mx;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1084
      val _ =
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
  1085
        if not legacy andalso not (Syntax.is_identifier (no_skolem internal x)) then
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
  1086
          error ("Illegal variable name: " ^ quote x)
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1087
        else ();
12504
5b46173df7ad export used_types;
wenzelm
parents: 12414
diff changeset
  1088
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1089
      fun cond_tvars T =
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1090
        if internal then T
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
  1091
        else Type.no_tvars T handle TYPE (msg, _, _) => error msg;
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1092
      val opt_T = Option.map (cond_tvars o prep_typ ctxt) raw_T;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1093
      val var = (x, opt_T, mx);
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1094
    in (var, ctxt |> declare_var var) end);
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
  1095
10381
4dfbcad19bfb fixed two obscurities of "fix": predeclare_terms;
wenzelm
parents: 9733
diff changeset
  1096
in
4dfbcad19bfb fixed two obscurities of "fix": predeclare_terms;
wenzelm
parents: 9733
diff changeset
  1097
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1098
val read_vars        = prep_vars read_typ false false;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1099
val cert_vars        = prep_vars cert_typ true false;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1100
val read_vars_legacy = prep_vars read_typ true true;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1101
val cert_vars_legacy = prep_vars cert_typ true true;
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
  1102
10381
4dfbcad19bfb fixed two obscurities of "fix": predeclare_terms;
wenzelm
parents: 9733
diff changeset
  1103
end;
4dfbcad19bfb fixed two obscurities of "fix": predeclare_terms;
wenzelm
parents: 9733
diff changeset
  1104
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
  1105
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1106
(* fixes *)
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
  1107
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
  1108
local
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
  1109
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1110
fun no_dups _ [] = ()
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
  1111
  | no_dups ctxt dups = error ("Duplicate variable(s): " ^ commas_quote dups);
11925
4747b4b84093 added read_prop_schematic;
wenzelm
parents: 11918
diff changeset
  1112
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1113
fun gen_fixes prep raw_vars ctxt =
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
  1114
  let
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1115
    val (ys, zs) = split_list (fixes_of ctxt);
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1116
    val (vars, ctxt') = prep raw_vars ctxt;
12130
30d9143aff7e syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents: 12123
diff changeset
  1117
    val xs = map #1 vars;
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1118
    val _ = no_dups ctxt (duplicates xs);
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1119
    val xs' =
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1120
      if is_body ctxt then Term.variantlist (map Syntax.skolem xs, zs)
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1121
      else (no_dups ctxt (xs inter_string ys); no_dups ctxt (xs inter_string zs); xs);
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1122
    val vars' = map2 (fn x' => fn (_, T, mx) => (x', T, mx)) xs' vars;
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
  1123
  in
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1124
    ctxt'
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1125
    |> map_fixes (fn (b, fixes) => (b, rev (xs ~~ xs') @ fixes))
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1126
    |> add_syntax vars'
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1127
    |> fold declare_var vars'
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1128
    |> pair xs'
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
  1129
  end;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
  1130
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
  1131
in
7679
99912beb8fa0 improved 'fix' / Skolem interfaces;
wenzelm
parents: 7670
diff changeset
  1132
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1133
val add_fixes = gen_fixes read_vars;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1134
val add_fixes_i = gen_fixes cert_vars;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1135
val add_fixes_legacy = gen_fixes cert_vars_legacy;
8096
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
  1136
4da940d100f5 TypeInfer.logicT;
wenzelm
parents: 7928
diff changeset
  1137
end;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
  1138
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1139
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1140
(* fixes vs. frees *)
12016
425289df84d3 fix_frees;
wenzelm
parents: 12008
diff changeset
  1141
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1142
fun fix_frees t ctxt =
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1143
  let
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1144
    fun add (Free (x, T)) = if is_fixed ctxt x then I else insert (op =) (x, SOME T, NoSyn)
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1145
      | add _ = I;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1146
    val fixes = rev (fold_aterms add t []);
18785
5ae1f1c1b764 renamed export to export_standard (again!), because it includes Drule.local_standard';
wenzelm
parents: 18770
diff changeset
  1147
  in ctxt |> set_body false |> add_fixes_i fixes |> snd |> restore_body ctxt end;
6895
450b1f67f099 added transfer_used_names;
wenzelm
parents: 6875
diff changeset
  1148
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1149
fun auto_fixes (arg as (ctxt, (propss, x))) =
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1150
  if is_body ctxt then arg
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1151
  else ((fold o fold) fix_frees propss ctxt, (propss, x));
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1152
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1153
fun bind_fixes xs ctxt =
9291
23705d14be8f "_i" arguments now expected to have skolems already internalized;
wenzelm
parents: 9274
diff changeset
  1154
  let
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1155
    val (_, ctxt') = ctxt |> add_fixes_i (map (fn x => (x, NONE, NoSyn)) xs);
9291
23705d14be8f "_i" arguments now expected to have skolems already internalized;
wenzelm
parents: 9274
diff changeset
  1156
    fun bind (t as Free (x, T)) =
18340
3fdff270aa04 removed fixed_tr: now handled in syntax module;
wenzelm
parents: 18310
diff changeset
  1157
          if member (op =) xs x then
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
  1158
            (case lookup_skolem ctxt' x of SOME x' => Free (x', T) | NONE => t)
9291
23705d14be8f "_i" arguments now expected to have skolems already internalized;
wenzelm
parents: 9274
diff changeset
  1159
          else t
23705d14be8f "_i" arguments now expected to have skolems already internalized;
wenzelm
parents: 9274
diff changeset
  1160
      | bind (t $ u) = bind t $ bind u
23705d14be8f "_i" arguments now expected to have skolems already internalized;
wenzelm
parents: 9274
diff changeset
  1161
      | bind (Abs (x, T, t)) = Abs (x, T, bind t)
23705d14be8f "_i" arguments now expected to have skolems already internalized;
wenzelm
parents: 9274
diff changeset
  1162
      | bind a = a;
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1163
  in (bind, ctxt') end;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1164
9291
23705d14be8f "_i" arguments now expected to have skolems already internalized;
wenzelm
parents: 9274
diff changeset
  1165
23705d14be8f "_i" arguments now expected to have skolems already internalized;
wenzelm
parents: 9274
diff changeset
  1166
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1167
(** assumptions **)
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1168
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1169
(* generic assms *)
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1170
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1171
local
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1172
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1173
fun gen_assm ((name, attrs), props) ctxt =
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1174
  let
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1175
    val cprops = map (Thm.cterm_of (theory_of ctxt)) props;
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1176
    val asms = map (Goal.norm_hhf o Thm.assume) cprops;
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1177
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1178
    val ths = map (fn th => ([th], [])) asms;
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1179
    val ([(_, thms)], ctxt') =
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1180
      ctxt
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1181
      |> auto_bind_facts props
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1182
      |> note_thmss_i [((name, attrs), ths)];
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1183
  in ((cprops, (name, asms), (name, thms)), ctxt') end;
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1184
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1185
fun gen_assms prepp exp args ctxt =
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1186
  let
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1187
    val (propss, ctxt1) = swap (prepp (ctxt, map snd args));
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1188
    val (results, ctxt2) = fold_map gen_assm (map fst args ~~ propss) ctxt1;
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1189
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1190
    val new_asms = List.concat (map #1 results);
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1191
    val new_prems = map #2 results;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1192
    val ctxt3 = ctxt2 |> map_assms (fn (asms, prems) => (asms @ [(new_asms, exp)], prems @ new_prems))
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1193
    val ctxt4 = ctxt3 |> put_thms ("prems", SOME (prems_of ctxt3));
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1194
  in (map #3 results, warn_extra_tfrees ctxt ctxt4) end;
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1195
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1196
in
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1197
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1198
val add_assms = gen_assms (apsnd #1 o bind_propp);
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1199
val add_assms_i = gen_assms (apsnd #1 o bind_propp_i);
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1200
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1201
end;
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1202
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1203
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1204
(* basic assumptions *)
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1205
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1206
fun assume_export true = Seq.single oo Drule.implies_intr_protected
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1207
  | assume_export false = Seq.single oo Drule.implies_intr_list;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1208
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1209
fun presume_export _ = assume_export false;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1210
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1211
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1212
(* additional views *)
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1213
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1214
fun add_view outer view = map_assms (fn (asms, prems) =>
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1215
  let
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1216
    val (asms1, asms2) = splitAt (length (assumptions_of outer), asms);
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1217
    val asms' = asms1 @ [(view, assume_export)] @ asms2;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1218
  in (asms', prems) end);
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1219
18785
5ae1f1c1b764 renamed export to export_standard (again!), because it includes Drule.local_standard';
wenzelm
parents: 18770
diff changeset
  1220
fun export_view view inner outer = export_standard (add_view outer view inner) outer;
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1221
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1222
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1223
(* definitions *)
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1224
18310
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
  1225
fun mk_def ctxt args =
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
  1226
  let
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
  1227
    val (xs, rhss) = split_list args;
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1228
    val (bind, _) = bind_fixes xs ctxt;
18310
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
  1229
    val lhss = map (fn (x, rhs) => bind (Free (x, Term.fastype_of rhs))) args;
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
  1230
  in map Logic.mk_equals (lhss ~~ rhss) end;
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1231
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1232
fun cert_def ctxt eq =
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1233
  let
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
  1234
    fun err msg = cat_error msg
18785
5ae1f1c1b764 renamed export to export_standard (again!), because it includes Drule.local_standard';
wenzelm
parents: 18770
diff changeset
  1235
      ("The error(s) above occurred in definition: " ^ string_of_term ctxt eq);
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1236
    val (lhs, rhs) = Logic.dest_equals (Term.strip_all_body eq)
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1237
      handle TERM _ => err "Not a meta-equality (==)";
18340
3fdff270aa04 removed fixed_tr: now handled in syntax module;
wenzelm
parents: 18310
diff changeset
  1238
    val (f, xs) = Term.strip_comb (Pattern.beta_eta_contract lhs);
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1239
    val (c, _) = Term.dest_Free f handle TERM _ =>
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1240
      err "Head of lhs must be a free/fixed variable";
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1241
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1242
    fun is_free (Free (x, _)) = not (is_fixed ctxt x)
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1243
      | is_free _ = false;
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1244
    val extra_frees = List.filter is_free (term_frees rhs) \\ xs;
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1245
  in
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1246
    conditional (not (forall (is_Bound orf is_free) xs andalso null (duplicates xs))) (fn () =>
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1247
      err "Arguments of lhs must be distinct free/bound variables");
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1248
    conditional (f mem Term.term_frees rhs) (fn () =>
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1249
      err "Element to be defined occurs on rhs");
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1250
    conditional (not (null extra_frees)) (fn () =>
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1251
      err ("Extra free variables on rhs: " ^ commas_quote (map (#1 o dest_Free) extra_frees)));
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1252
    (c, Term.list_all_free (List.mapPartial (try Term.dest_Free) xs, eq))
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1253
  end;
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1254
18785
5ae1f1c1b764 renamed export to export_standard (again!), because it includes Drule.local_standard';
wenzelm
parents: 18770
diff changeset
  1255
fun abs_def eq =
5ae1f1c1b764 renamed export to export_standard (again!), because it includes Drule.local_standard';
wenzelm
parents: 18770
diff changeset
  1256
  let
5ae1f1c1b764 renamed export to export_standard (again!), because it includes Drule.local_standard';
wenzelm
parents: 18770
diff changeset
  1257
    val body = Term.strip_all_body eq;
5ae1f1c1b764 renamed export to export_standard (again!), because it includes Drule.local_standard';
wenzelm
parents: 18770
diff changeset
  1258
    val vars = map Free (Term.rename_wrt_term body (Term.strip_all_vars eq));
5ae1f1c1b764 renamed export to export_standard (again!), because it includes Drule.local_standard';
wenzelm
parents: 18770
diff changeset
  1259
    val (lhs, rhs) = Logic.dest_equals (Term.subst_bounds (vars, body));
5ae1f1c1b764 renamed export to export_standard (again!), because it includes Drule.local_standard';
wenzelm
parents: 18770
diff changeset
  1260
    val (f, xs) = Term.strip_comb (Pattern.beta_eta_contract lhs);
5ae1f1c1b764 renamed export to export_standard (again!), because it includes Drule.local_standard';
wenzelm
parents: 18770
diff changeset
  1261
    val eq' = Term.list_abs_free (map Term.dest_Free xs, rhs);
5ae1f1c1b764 renamed export to export_standard (again!), because it includes Drule.local_standard';
wenzelm
parents: 18770
diff changeset
  1262
  in (Term.dest_Free f, eq') end;
5ae1f1c1b764 renamed export to export_standard (again!), because it includes Drule.local_standard';
wenzelm
parents: 18770
diff changeset
  1263
5ae1f1c1b764 renamed export to export_standard (again!), because it includes Drule.local_standard';
wenzelm
parents: 18770
diff changeset
  1264
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1265
fun head_of_def cprop =
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1266
  #1 (Term.strip_comb (#1 (Logic.dest_equals (Term.strip_all_body (Thm.term_of cprop)))))
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1267
  |> Thm.cterm_of (Thm.theory_of_cterm cprop);
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1268
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1269
fun def_export _ cprops thm =
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1270
  thm
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1271
  |> Drule.implies_intr_list cprops
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1272
  |> Drule.forall_intr_list (map head_of_def cprops)
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1273
  |> Drule.forall_elim_vars 0
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1274
  |> RANGE (replicate (length cprops) (Tactic.rtac Drule.reflexive_thm)) 1;
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1275
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1276
fun add_def (x, t) ctxt =
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1277
  let
18310
b00c9120f6bd match_bind(_i): return terms;
wenzelm
parents: 18255
diff changeset
  1278
    val [eq] = mk_def ctxt [(x, t)];
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1279
    val x' = Term.dest_Free (fst (Logic.dest_equals eq));
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1280
  in
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1281
    ctxt
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1282
    |> add_fixes_i [(x, NONE, NoSyn)] |> snd
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1283
    |> add_assms_i def_export [(("", []), [(eq, ([], []))])]
18187
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1284
    |>> (fn [(_, [th])] => (x', th))
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1285
  end;
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1286
ec44df8ffd21 added revert_skolem, mk_def, add_def;
wenzelm
parents: 18152
diff changeset
  1287
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
  1288
8373
e7237c8fe29e handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents: 8186
diff changeset
  1289
(** cases **)
e7237c8fe29e handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents: 8186
diff changeset
  1290
16147
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
  1291
local
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
  1292
16668
fdb4992cf1d2 avoid polyeq;
wenzelm
parents: 16540
diff changeset
  1293
fun rem_case name = remove (fn (x: string, (y, _)) => x = y) name;
16147
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
  1294
18476
49dde7b7b14a cases: main is_proper flag;
wenzelm
parents: 18428
diff changeset
  1295
fun add_case _ ("", _) cases = cases
49dde7b7b14a cases: main is_proper flag;
wenzelm
parents: 18428
diff changeset
  1296
  | add_case _ (name, NONE) cases = rem_case name cases
49dde7b7b14a cases: main is_proper flag;
wenzelm
parents: 18428
diff changeset
  1297
  | add_case is_proper (name, SOME c) cases = (name, (c, is_proper)) :: rem_case name cases;
16147
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
  1298
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
  1299
fun prep_case name fxs c =
18609
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1300
  let
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1301
    fun replace (opt_x :: xs) ((y, T) :: ys) = (the_default y opt_x, T) :: replace xs ys
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1302
      | replace [] ys = ys
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
  1303
      | replace (_ :: _) [] = error ("Too many parameters for case " ^ quote name);
18609
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1304
    val RuleCases.Case {fixes, assumes, binds, cases} = c;
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1305
    val fixes' = replace fxs fixes;
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1306
    val binds' = map drop_schematic binds;
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1307
  in
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1308
    if null (fold (Term.add_tvarsT o snd) fixes []) andalso
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1309
      null (fold (fold Term.add_vars o snd) assumes []) then
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1310
        RuleCases.Case {fixes = fixes', assumes = assumes, binds = binds', cases = cases}
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
  1311
    else error ("Illegal schematic variable(s) in case " ^ quote name)
18609
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1312
  end;
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1313
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1314
fun fix (x, T) ctxt =
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1315
  let
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1316
    val (bind, ctxt') = bind_fixes [x] ctxt;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1317
    val t = bind (Free (x, T));
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1318
  in (t, ctxt' |> declare_syntax t) end;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1319
16147
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
  1320
in
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
  1321
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1322
fun add_cases is_proper = map_cases o fold (add_case is_proper);
18609
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1323
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1324
fun case_result c ctxt =
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1325
  let
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1326
    val RuleCases.Case {fixes, ...} = c;
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1327
    val (ts, ctxt') = ctxt |> fold_map fix fixes;
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1328
    val RuleCases.Case {assumes, binds, cases, ...} = RuleCases.apply ts c;
18609
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1329
  in
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1330
    ctxt'
18699
f3bfe81b6e58 case_result: drop_schematic, i.e. be permissive about illegal binds;
wenzelm
parents: 18678
diff changeset
  1331
    |> add_binds_i (map drop_schematic binds)
18609
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1332
    |> add_cases true (map (apsnd SOME) cases)
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1333
    |> pair (assumes, (binds, cases))
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1334
  end;
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1335
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1336
val apply_case = apfst fst oo case_result;
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1337
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
  1338
fun get_case ctxt name xs =
17184
3d80209e9a53 use AList operations;
wenzelm
parents: 17072
diff changeset
  1339
  (case AList.lookup (op =) (cases_of ctxt) name of
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
  1340
    NONE => error ("Unknown case: " ^ quote name)
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18672
diff changeset
  1341
  | SOME (c, _) => prep_case name xs c);
8373
e7237c8fe29e handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents: 8186
diff changeset
  1342
16147
59177d5bcb6f renamed cond_extern to extern;
wenzelm
parents: 16031
diff changeset
  1343
end;
8373
e7237c8fe29e handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents: 8186
diff changeset
  1344
e7237c8fe29e handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents: 8186
diff changeset
  1345
e7237c8fe29e handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents: 8186
diff changeset
  1346
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1347
(** print context information **)
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1348
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1349
val verbose = ref false;
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1350
fun verb f x = if ! verbose then f (x ()) else [];
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1351
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1352
fun setmp_verbose f x = Library.setmp verbose true f x;
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1353
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1354
fun pretty_items prt name items =
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1355
  let
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1356
    fun prt_itms (name, [x]) = Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 1, prt x]
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1357
      | prt_itms (name, xs) = Pretty.big_list (name ^ ":") (map prt xs);
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1358
  in
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1359
    if null items andalso not (! verbose) then []
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1360
    else [Pretty.big_list name (map prt_itms items)]
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1361
  end;
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1362
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1363
12072
4281198fb8cd local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents: 12066
diff changeset
  1364
(* local syntax *)
4281198fb8cd local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents: 12066
diff changeset
  1365
12093
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
  1366
val print_syntax = Syntax.print_syntax o syn_of;
12072
4281198fb8cd local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents: 12066
diff changeset
  1367
4281198fb8cd local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents: 12066
diff changeset
  1368
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1369
(* term bindings *)
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1370
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
  1371
fun pretty_binds ctxt =
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1372
  let
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
  1373
    val binds = binds_of ctxt;
12057
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
  1374
    fun prt_bind (xi, (t, T)) = pretty_term ctxt (Logic.mk_equals (Var (xi, T), t));
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1375
  in
15758
07e382399a96 binds/thms: do not store options, but delete from table;
wenzelm
parents: 15750
diff changeset
  1376
    if Vartab.is_empty binds andalso not (! verbose) then []
07e382399a96 binds/thms: do not store options, but delete from table;
wenzelm
parents: 15750
diff changeset
  1377
    else [Pretty.big_list "term bindings:" (map prt_bind (Vartab.dest binds))]
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1378
  end;
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1379
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1380
val print_binds = Pretty.writeln o Pretty.chunks o pretty_binds;
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1381
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1382
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1383
(* local theorems *)
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1384
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
  1385
fun pretty_lthms ctxt =
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
  1386
  pretty_items (pretty_thm ctxt) "facts:" (NameSpace.extern_table (#2 (thms_of ctxt)));
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1387
12057
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
  1388
val print_lthms = Pretty.writeln o Pretty.chunks o pretty_lthms;
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1389
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1390
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1391
(* local contexts *)
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1392
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
  1393
fun pretty_cases ctxt =
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1394
  let
12057
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
  1395
    val prt_term = pretty_term ctxt;
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
  1396
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1397
    fun prt_let (xi, t) = Pretty.block
10818
37fa05a12459 tuned output;
wenzelm
parents: 10810
diff changeset
  1398
      [Pretty.quote (prt_term (Var (xi, Term.fastype_of t))), Pretty.str " =", Pretty.brk 1,
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1399
        Pretty.quote (prt_term t)];
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1400
13425
119ae829ad9b support for split assumptions in cases (hyps vs. prems);
wenzelm
parents: 13415
diff changeset
  1401
    fun prt_asm (a, ts) = Pretty.block (Pretty.breaks
119ae829ad9b support for split assumptions in cases (hyps vs. prems);
wenzelm
parents: 13415
diff changeset
  1402
      ((if a = "" then [] else [Pretty.str (a ^ ":")]) @ map (Pretty.quote o prt_term) ts));
119ae829ad9b support for split assumptions in cases (hyps vs. prems);
wenzelm
parents: 13415
diff changeset
  1403
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1404
    fun prt_sect _ _ _ [] = []
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1405
      | prt_sect s sep prt xs = [Pretty.block (Pretty.breaks (Pretty.str s ::
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
  1406
            List.concat (Library.separate sep (map (Library.single o prt) xs))))];
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1407
18609
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1408
    fun prt_case (name, (fixes, (asms, (lets, cs)))) = Pretty.block (Pretty.fbreaks
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1409
      (Pretty.str (name ^ ":") ::
11915
df030220a2a8 print fixed names as plain strings;
wenzelm
parents: 11816
diff changeset
  1410
        prt_sect "fix" [] (Pretty.str o fst) fixes @
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1411
        prt_sect "let" [Pretty.str "and"] prt_let
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
  1412
          (List.mapPartial (fn (xi, SOME t) => SOME (xi, t) | _ => NONE) lets) @
13425
119ae829ad9b support for split assumptions in cases (hyps vs. prems);
wenzelm
parents: 13415
diff changeset
  1413
        (if forall (null o #2) asms then []
18609
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1414
          else prt_sect "assume" [Pretty.str "and"] prt_asm asms) @
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1415
        prt_sect "subcases:" [] (Pretty.str o fst) cs));
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
  1416
18476
49dde7b7b14a cases: main is_proper flag;
wenzelm
parents: 18428
diff changeset
  1417
    fun add_case (_, (_, false)) = I
18609
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1418
      | add_case (name, (c as RuleCases.Case {fixes, ...}, true)) =
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1419
          cons (name, (fixes, #1 (case_result c ctxt)));
18476
49dde7b7b14a cases: main is_proper flag;
wenzelm
parents: 18428
diff changeset
  1420
    val cases = fold add_case (cases_of ctxt) [];
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1421
  in
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1422
    if null cases andalso not (! verbose) then []
18476
49dde7b7b14a cases: main is_proper flag;
wenzelm
parents: 18428
diff changeset
  1423
    else [Pretty.big_list "cases:" (map prt_case cases)]
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1424
  end;
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1425
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1426
val print_cases = Pretty.writeln o Pretty.chunks o pretty_cases;
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1427
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1428
12057
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
  1429
(* core context *)
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1430
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1431
val prems_limit = ref 10;
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1432
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1433
fun pretty_ctxt ctxt =
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1434
  let
12057
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
  1435
    val prt_term = pretty_term ctxt;
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
  1436
12093
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
  1437
    (*structures*)
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
  1438
    val (_, structs, _) = syntax_of ctxt;
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
  1439
    val prt_structs = if null structs then []
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
  1440
      else [Pretty.block (Pretty.str "structures:" :: Pretty.brk 1 ::
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
  1441
        Pretty.commas (map Pretty.str structs))];
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
  1442
12057
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
  1443
    (*fixes*)
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
  1444
    fun prt_fix (x, x') =
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
  1445
      if x = x' then Pretty.str x
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
  1446
      else Pretty.block [Pretty.str x, Pretty.str " =", Pretty.brk 1, prt_term (Syntax.free x')];
18340
3fdff270aa04 removed fixed_tr: now handled in syntax module;
wenzelm
parents: 18310
diff changeset
  1447
    val fixes =
3fdff270aa04 removed fixed_tr: now handled in syntax module;
wenzelm
parents: 18310
diff changeset
  1448
      rev (filter_out ((can Syntax.dest_internal orf member (op =) structs) o #1) (fixes_of ctxt));
12093
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
  1449
    val prt_fixes = if null fixes then []
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
  1450
      else [Pretty.block (Pretty.str "fixed variables:" :: Pretty.brk 1 ::
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
  1451
        Pretty.commas (map prt_fix fixes))];
12057
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
  1452
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
  1453
    (*prems*)
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1454
    val limit = ! prems_limit;
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1455
    val prems = prems_of ctxt;
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1456
    val len = length prems;
12093
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
  1457
    val prt_prems = if null prems then []
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
  1458
      else [Pretty.big_list "prems:" ((if len <= limit then [] else [Pretty.str "..."]) @
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
  1459
        map (pretty_thm ctxt) (Library.drop (len - limit, prems)))];
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
  1460
1b890f1e0b4d syntax for structures;
wenzelm
parents: 12086
diff changeset
  1461
  in prt_structs @ prt_fixes @ prt_prems end;
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1462
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1463
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1464
(* main context *)
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1465
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
  1466
fun pretty_context ctxt =
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1467
  let
12057
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
  1468
    val prt_term = pretty_term ctxt;
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
  1469
    val prt_typ = pretty_typ ctxt;
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
  1470
    val prt_sort = pretty_sort ctxt;
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1471
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1472
    (*theory*)
12057
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
  1473
    val pretty_thy = Pretty.block
17384
wenzelm
parents: 17360
diff changeset
  1474
      [Pretty.str "theory:", Pretty.brk 1, Context.pretty_thy (theory_of ctxt)];
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1475
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1476
    (*defaults*)
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1477
    fun prt_atom prt prtT (x, X) = Pretty.block
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1478
      [prt x, Pretty.str " ::", Pretty.brk 1, prtT X];
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1479
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1480
    fun prt_var (x, ~1) = prt_term (Syntax.free x)
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1481
      | prt_var xi = prt_term (Syntax.var xi);
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1482
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1483
    fun prt_varT (x, ~1) = prt_typ (TFree (x, []))
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1484
      | prt_varT xi = prt_typ (TVar (xi, []));
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1485
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1486
    val prt_defT = prt_atom prt_var prt_typ;
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1487
    val prt_defS = prt_atom prt_varT prt_sort;
16540
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
  1488
e3d61eff7c12 removed proof data (see Pure/context.ML);
wenzelm
parents: 16501
diff changeset
  1489
    val (types, sorts, used, _) = defaults_of ctxt;
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1490
  in
18609
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1491
    verb single (K pretty_thy) @
18672
ac1a048ca7dd uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents: 18619
diff changeset
  1492
    pretty_ctxt ctxt @
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1493
    verb pretty_binds (K ctxt) @
12057
9b1e67278f07 added pretty/print functions with context;
wenzelm
parents: 12048
diff changeset
  1494
    verb pretty_lthms (K ctxt) @
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1495
    verb pretty_cases (K ctxt) @
18609
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1496
    verb single (fn () => Pretty.big_list "type constraints:" (map prt_defT (Vartab.dest types))) @
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1497
    verb single (fn () => Pretty.big_list "default sorts:" (map prt_defS (Vartab.dest sorts))) @
b026652ede90 support nested cases;
wenzelm
parents: 18476
diff changeset
  1498
    verb single (fn () => Pretty.strs ("used type variable names:" :: used))
10810
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1499
  end;
619586bd854b apply_case: more robust handling of bounds;
wenzelm
parents: 10583
diff changeset
  1500
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
  1501
end;