src/Pure/logic.ML
author nipkow
Tue, 05 Nov 2019 14:57:41 +0100
changeset 71033 c1b63124245c
parent 70821 37062fe19175
child 74281 7829d6435c60
permissions -rw-r--r--
tuned
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
     1
(*  Title:      Pure/logic.ML
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
29276
94b1ffec9201 qualified Term.rename_wrt_term;
wenzelm
parents: 28856
diff changeset
     3
    Author:     Makarius
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
     5
Abstract syntax operations of the Pure meta-logic.
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
     8
signature LOGIC =
4345
7e9436ffb813 tuned term order;
wenzelm
parents: 4318
diff changeset
     9
sig
46217
7b19666f0e3d renamed Term.all to Logic.all_const, in accordance to HOLogic.all_const;
wenzelm
parents: 46215
diff changeset
    10
  val all_const: typ -> term
27334
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
    11
  val all: term -> term -> term
61655
f217bbe4e93e avoid vacuous quantification, as usual for shared variable scope;
wenzelm
parents: 61654
diff changeset
    12
  val dependent_all_name: string * term -> term -> term
27334
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
    13
  val is_all: term -> bool
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
    14
  val dest_all: term -> (string * typ) * term
46218
ecf6375e2abb renamed Term.list_all to Logic.list_all, in accordance to HOLogic.list_all;
wenzelm
parents: 46217
diff changeset
    15
  val list_all: (string * typ) list * term -> term
60454
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
    16
  val all_constraint: (string -> typ option) -> string * string -> term -> term
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
    17
  val dependent_all_constraint: (string -> typ option) -> string * string -> term -> term
18181
wenzelm
parents: 18029
diff changeset
    18
  val mk_equals: term * term -> term
wenzelm
parents: 18029
diff changeset
    19
  val dest_equals: term -> term * term
27334
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
    20
  val implies: term
18181
wenzelm
parents: 18029
diff changeset
    21
  val mk_implies: term * term -> term
wenzelm
parents: 18029
diff changeset
    22
  val dest_implies: term -> term * term
wenzelm
parents: 18029
diff changeset
    23
  val list_implies: term list * term -> term
wenzelm
parents: 18029
diff changeset
    24
  val strip_imp_prems: term -> term list
wenzelm
parents: 18029
diff changeset
    25
  val strip_imp_concl: term -> term
wenzelm
parents: 18029
diff changeset
    26
  val strip_prems: int * term list * term -> term list * term
21576
8c11b1ce2f05 simplified Logic.count_prems;
wenzelm
parents: 21520
diff changeset
    27
  val count_prems: term -> int
18181
wenzelm
parents: 18029
diff changeset
    28
  val nth_prem: int * term -> term
63056
9b95ae9ec671 defs are closed, which leads to proper auto_bind_facts;
wenzelm
parents: 61655
diff changeset
    29
  val close_term: (string * term) list -> term -> term
9b95ae9ec671 defs are closed, which leads to proper auto_bind_facts;
wenzelm
parents: 61655
diff changeset
    30
  val close_prop: (string * term) list -> term list -> term -> term
63063
wenzelm
parents: 63056
diff changeset
    31
  val close_prop_constraint: (string -> typ option) ->
wenzelm
parents: 63056
diff changeset
    32
    (string * string) list -> term list -> term -> term
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
    33
  val true_prop: term
19125
59b26248547b simplified Pure conjunction, based on actual const;
wenzelm
parents: 19103
diff changeset
    34
  val conjunction: term
18181
wenzelm
parents: 18029
diff changeset
    35
  val mk_conjunction: term * term -> term
12757
b76a4376cfcb added mk_conjunction_list;
wenzelm
parents: 12137
diff changeset
    36
  val mk_conjunction_list: term list -> term
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
    37
  val mk_conjunction_balanced: term list -> term
18469
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
    38
  val dest_conjunction: term -> term * term
19425
e0d7d9373faf added dest_conjunction_list;
wenzelm
parents: 19406
diff changeset
    39
  val dest_conjunction_list: term -> term list
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
    40
  val dest_conjunction_balanced: int -> term -> term list
18469
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
    41
  val dest_conjunctions: term -> term list
18181
wenzelm
parents: 18029
diff changeset
    42
  val strip_horn: term -> term list * term
21520
63c73f461eec added type_map;
wenzelm
parents: 21016
diff changeset
    43
  val mk_type: typ -> term
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
    44
  val dest_type: term -> typ
21520
63c73f461eec added type_map;
wenzelm
parents: 21016
diff changeset
    45
  val type_map: (term -> term) -> typ -> typ
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
    46
  val const_of_class: class -> string
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
    47
  val class_of_const: string -> class
31943
5e960a0780a2 renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
wenzelm
parents: 30554
diff changeset
    48
  val mk_of_class: typ * class -> term
5e960a0780a2 renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
wenzelm
parents: 30554
diff changeset
    49
  val dest_of_class: term -> typ * class
35854
d452abc96459 Logic.mk_of_sort convenience;
wenzelm
parents: 35845
diff changeset
    50
  val mk_of_sort: typ * sort -> term list
20630
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
    51
  val name_classrel: string * string -> string
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
    52
  val mk_classrel: class * class -> term
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
    53
  val dest_classrel: term -> class * class
20630
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
    54
  val name_arities: arity -> string list
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
    55
  val name_arity: string * sort list * class -> string
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
    56
  val mk_arities: arity -> term list
70384
8ce08b154aa1 clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents: 69023
diff changeset
    57
  val mk_arity: string * sort list * class -> term
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
    58
  val dest_arity: term -> string * sort list * class
70811
785a2112f861 clarified signature -- some operations to support fully explicit proof terms;
wenzelm
parents: 70438
diff changeset
    59
  val dummy_tfree: sort -> typ
70436
251f1fb44ccd clarified signature;
wenzelm
parents: 70435
diff changeset
    60
  type unconstrain_context =
251f1fb44ccd clarified signature;
wenzelm
parents: 70435
diff changeset
    61
   {present_map: (typ * typ) list,
70438
99024c9c83f6 proper constrains_map -- for shyps that are covered by present variables (amending 251f1fb44ccd);
wenzelm
parents: 70437
diff changeset
    62
    constraints_map: (sort * typ) list,
70436
251f1fb44ccd clarified signature;
wenzelm
parents: 70435
diff changeset
    63
    atyp_map: typ -> typ,
70437
fdbb0c2e0162 tuned signature;
wenzelm
parents: 70436
diff changeset
    64
    map_atyps: typ -> typ,
70435
52fbcf7a61f8 tuned signature;
wenzelm
parents: 70384
diff changeset
    65
    constraints: ((typ * class) * term) list,
70436
251f1fb44ccd clarified signature;
wenzelm
parents: 70435
diff changeset
    66
    outer_constraints: (typ * class) list};
251f1fb44ccd clarified signature;
wenzelm
parents: 70435
diff changeset
    67
  val unconstrainT: sort list -> term -> unconstrain_context * term
18181
wenzelm
parents: 18029
diff changeset
    68
  val protectC: term
wenzelm
parents: 18029
diff changeset
    69
  val protect: term -> term
wenzelm
parents: 18029
diff changeset
    70
  val unprotect: term -> term
19775
06cb6743adf6 support embedded terms;
wenzelm
parents: 19425
diff changeset
    71
  val mk_term: term -> term
06cb6743adf6 support embedded terms;
wenzelm
parents: 19425
diff changeset
    72
  val dest_term: term -> term
18181
wenzelm
parents: 18029
diff changeset
    73
  val occs: term * term -> bool
wenzelm
parents: 18029
diff changeset
    74
  val close_form: term -> term
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
    75
  val combound: term * int * int -> term
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
    76
  val rlist_abs: (string * typ) list * term -> term
32023
2d071ac5032f export incr_tvar_same;
wenzelm
parents: 32020
diff changeset
    77
  val incr_tvar_same: int -> typ Same.operation
2d071ac5032f export incr_tvar_same;
wenzelm
parents: 32020
diff changeset
    78
  val incr_tvar: int -> typ -> typ
59787
6e2a20486897 local fixes may depend on goal params;
wenzelm
parents: 56245
diff changeset
    79
  val incr_indexes_same: string list * typ list * int -> term Same.operation
6e2a20486897 local fixes may depend on goal params;
wenzelm
parents: 56245
diff changeset
    80
  val incr_indexes: string list * typ list * int -> term -> term
18181
wenzelm
parents: 18029
diff changeset
    81
  val lift_abs: int -> term -> term -> term
wenzelm
parents: 18029
diff changeset
    82
  val lift_all: int -> term -> term -> term
wenzelm
parents: 18029
diff changeset
    83
  val strip_assums_hyp: term -> term list
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
    84
  val strip_assums_concl: term -> term
18181
wenzelm
parents: 18029
diff changeset
    85
  val strip_params: term -> (string * typ) list
23597
ab67175ca8a5 simplified has_meta_prems;
wenzelm
parents: 23418
diff changeset
    86
  val has_meta_prems: term -> bool
18181
wenzelm
parents: 18029
diff changeset
    87
  val flatten_params: int -> term -> term
45328
e5b33eecbf6e tuned signature;
wenzelm
parents: 43329
diff changeset
    88
  val list_rename_params: string list -> term -> term
e5b33eecbf6e tuned signature;
wenzelm
parents: 43329
diff changeset
    89
  val assum_pairs: int * term -> (term * term) list
30554
73f8bd5f0af8 substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
wenzelm
parents: 30364
diff changeset
    90
  val assum_problems: int * term -> (term -> term) * term list * term
69023
cef000855cf4 clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents: 67721
diff changeset
    91
  val bad_schematic: indexname -> string
cef000855cf4 clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents: 67721
diff changeset
    92
  val bad_fixed: string -> string
35845
e5980f0ad025 renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents: 32784
diff changeset
    93
  val varifyT_global: typ -> typ
e5980f0ad025 renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents: 32784
diff changeset
    94
  val unvarifyT_global: typ -> typ
45344
e209da839ff4 added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents: 45328
diff changeset
    95
  val varify_types_global: term -> term
e209da839ff4 added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents: 45328
diff changeset
    96
  val unvarify_types_global: term -> term
35845
e5980f0ad025 renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents: 32784
diff changeset
    97
  val varify_global: term -> term
e5980f0ad025 renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents: 32784
diff changeset
    98
  val unvarify_global: term -> term
18181
wenzelm
parents: 18029
diff changeset
    99
  val get_goal: term -> int -> term
wenzelm
parents: 18029
diff changeset
   100
  val goal_params: term -> int -> term * term list
wenzelm
parents: 18029
diff changeset
   101
  val prems_of_goal: term -> int -> term list
wenzelm
parents: 18029
diff changeset
   102
  val concl_of_goal: term -> int -> term
4345
7e9436ffb813 tuned term order;
wenzelm
parents: 4318
diff changeset
   103
end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   104
1500
b2de3b3277b8 Elimination of fully-functorial style.
paulson
parents: 1460
diff changeset
   105
structure Logic : LOGIC =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   106
struct
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   107
4345
7e9436ffb813 tuned term order;
wenzelm
parents: 4318
diff changeset
   108
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   109
(*** Abstract syntax operations on the meta-connectives ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   110
23238
3de6e253efc4 added is_atomic;
wenzelm
parents: 22893
diff changeset
   111
(** all **)
5041
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
   112
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   113
fun all_const T = Const ("Pure.all", (T --> propT) --> propT);
46217
7b19666f0e3d renamed Term.all to Logic.all_const, in accordance to HOLogic.all_const;
wenzelm
parents: 46215
diff changeset
   114
7b19666f0e3d renamed Term.all to Logic.all_const, in accordance to HOLogic.all_const;
wenzelm
parents: 46215
diff changeset
   115
fun all v t = all_const (Term.fastype_of v) $ lambda v t;
61655
f217bbe4e93e avoid vacuous quantification, as usual for shared variable scope;
wenzelm
parents: 61654
diff changeset
   116
f217bbe4e93e avoid vacuous quantification, as usual for shared variable scope;
wenzelm
parents: 61654
diff changeset
   117
fun dependent_all_name (x, v) t =
f217bbe4e93e avoid vacuous quantification, as usual for shared variable scope;
wenzelm
parents: 61654
diff changeset
   118
  let
f217bbe4e93e avoid vacuous quantification, as usual for shared variable scope;
wenzelm
parents: 61654
diff changeset
   119
    val x' = if x = "" then Term.term_name v else x;
f217bbe4e93e avoid vacuous quantification, as usual for shared variable scope;
wenzelm
parents: 61654
diff changeset
   120
    val T = Term.fastype_of v;
f217bbe4e93e avoid vacuous quantification, as usual for shared variable scope;
wenzelm
parents: 61654
diff changeset
   121
    val t' = Term.abstract_over (v, t);
f217bbe4e93e avoid vacuous quantification, as usual for shared variable scope;
wenzelm
parents: 61654
diff changeset
   122
  in if Term.is_dependent t' then all_const T $ Abs (x', T, t') else t end;
27334
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
   123
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   124
fun is_all (Const ("Pure.all", _) $ Abs _) = true
27334
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
   125
  | is_all _ = false;
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
   126
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   127
fun dest_all (Const ("Pure.all", _) $ Abs (abs as (_, T, _))) =
27334
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
   128
      let val (x, b) = Term.dest_abs abs  (*potentially slow*)
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
   129
      in ((x, T), b) end
18762
9098c92a945f added dest_all;
wenzelm
parents: 18499
diff changeset
   130
  | dest_all t = raise TERM ("dest_all", [t]);
9098c92a945f added dest_all;
wenzelm
parents: 18499
diff changeset
   131
46218
ecf6375e2abb renamed Term.list_all to Logic.list_all, in accordance to HOLogic.list_all;
wenzelm
parents: 46217
diff changeset
   132
fun list_all ([], t) = t
ecf6375e2abb renamed Term.list_all to Logic.list_all, in accordance to HOLogic.list_all;
wenzelm
parents: 46217
diff changeset
   133
  | list_all ((a, T) :: vars, t) = all_const T $ Abs (a, T, list_all (vars, t));
ecf6375e2abb renamed Term.list_all to Logic.list_all, in accordance to HOLogic.list_all;
wenzelm
parents: 46217
diff changeset
   134
18762
9098c92a945f added dest_all;
wenzelm
parents: 18499
diff changeset
   135
60454
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   136
(* operations before type-inference *)
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   137
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   138
local
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   139
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   140
fun abs_body default_type z tm =
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   141
  let
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   142
    fun abs lev (Abs (x, T, b)) = Abs (x, T, abs (lev + 1) b)
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   143
      | abs lev (t $ u) = abs lev t $ abs lev u
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   144
      | abs lev (a as Free (x, T)) =
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   145
          if x = z then
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   146
            Type.constraint (the_default dummyT (default_type x))
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   147
              (Type.constraint T (Bound lev))
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   148
          else a
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   149
      | abs _ a = a;
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   150
  in abs 0 (Term.incr_boundvars 1 tm) end;
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   151
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   152
in
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   153
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   154
fun all_constraint default_type (y, z) t =
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   155
  all_const dummyT $ Abs (y, dummyT, abs_body default_type z t);
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   156
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   157
fun dependent_all_constraint default_type (y, z) t =
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   158
  let val t' = abs_body default_type z t
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   159
  in if Term.is_dependent t' then all_const dummyT $ Abs (y, dummyT, t') else t end;
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   160
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   161
end;
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   162
a4c6b278f3a7 eliminated slightly odd Element.close_form: toplevel specifications have different policies than proof text elements;
wenzelm
parents: 59787
diff changeset
   163
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   164
(** equality **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   165
27334
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
   166
fun mk_equals (t, u) =
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
   167
  let val T = Term.fastype_of t
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   168
  in Const ("Pure.eq", T --> T --> propT) $ t $ u end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   169
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   170
fun dest_equals (Const ("Pure.eq", _) $ t $ u) = (t, u)
20883
b432f20a47ca removed is_equals, is_implies;
wenzelm
parents: 20630
diff changeset
   171
  | dest_equals t = raise TERM ("dest_equals", [t]);
637
b344bf624143 added is_equals: term -> bool;
wenzelm
parents: 585
diff changeset
   172
b344bf624143 added is_equals: term -> bool;
wenzelm
parents: 585
diff changeset
   173
70811
785a2112f861 clarified signature -- some operations to support fully explicit proof terms;
wenzelm
parents: 70438
diff changeset
   174
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   175
(** implies **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   176
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   177
val implies = Const ("Pure.imp", propT --> propT --> propT);
27334
3f17273766f2 added all, is_all;
wenzelm
parents: 26424
diff changeset
   178
20883
b432f20a47ca removed is_equals, is_implies;
wenzelm
parents: 20630
diff changeset
   179
fun mk_implies (A, B) = implies $ A $ B;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   180
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   181
fun dest_implies (Const ("Pure.imp", _) $ A $ B) = (A, B)
20883
b432f20a47ca removed is_equals, is_implies;
wenzelm
parents: 20630
diff changeset
   182
  | dest_implies A = raise TERM ("dest_implies", [A]);
5041
a1d0a6d555cd Goals may now contain assumptions, which are not returned.
nipkow
parents: 4822
diff changeset
   183
4822
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   184
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   185
(** nested implications **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   186
67721
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 63063
diff changeset
   187
(* [A1,...,An], B  goes to  A1\<Longrightarrow>...An\<Longrightarrow>B  *)
18181
wenzelm
parents: 18029
diff changeset
   188
fun list_implies ([], B) = B
wenzelm
parents: 18029
diff changeset
   189
  | list_implies (A::As, B) = implies $ A $ list_implies(As,B);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   190
67721
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 63063
diff changeset
   191
(* A1\<Longrightarrow>...An\<Longrightarrow>B  goes to  [A1,...,An], where B is not an implication *)
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   192
fun strip_imp_prems (Const("Pure.imp", _) $ A $ B) = A :: strip_imp_prems B
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   193
  | strip_imp_prems _ = [];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   194
67721
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 63063
diff changeset
   195
(* A1\<Longrightarrow>...An\<Longrightarrow>B  goes to B, where B is not an implication *)
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   196
fun strip_imp_concl (Const("Pure.imp", _) $ A $ B) = strip_imp_concl B
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   197
  | strip_imp_concl A = A : term;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   198
67721
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 63063
diff changeset
   199
(*Strip and return premises: (i, [], A1\<Longrightarrow>...Ai\<Longrightarrow>B)
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   200
    goes to   ([Ai, A(i-1),...,A1] , B)         (REVERSED)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   201
  if  i<0 or else i too big then raises  TERM*)
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   202
fun strip_prems (0, As, B) = (As, B)
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   203
  | strip_prems (i, As, Const("Pure.imp", _) $ A $ B) =
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   204
        strip_prems (i-1, A::As, B)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   205
  | strip_prems (_, As, A) = raise TERM("strip_prems", A::As);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   206
16130
38b111451155 added nth_prem;
wenzelm
parents: 15596
diff changeset
   207
(*Count premises -- quicker than (length o strip_prems) *)
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   208
fun count_prems (Const ("Pure.imp", _) $ _ $ B) = 1 + count_prems B
21576
8c11b1ce2f05 simplified Logic.count_prems;
wenzelm
parents: 21520
diff changeset
   209
  | count_prems _ = 0;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   210
67721
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 63063
diff changeset
   211
(*Select Ai from A1\<Longrightarrow>...Ai\<Longrightarrow>B*)
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   212
fun nth_prem (1, Const ("Pure.imp", _) $ A $ _) = A
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   213
  | nth_prem (i, Const ("Pure.imp", _) $ _ $ B) = nth_prem (i - 1, B)
16130
38b111451155 added nth_prem;
wenzelm
parents: 15596
diff changeset
   214
  | nth_prem (_, A) = raise TERM ("nth_prem", [A]);
38b111451155 added nth_prem;
wenzelm
parents: 15596
diff changeset
   215
13659
3cf622f6b0b2 Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents: 12902
diff changeset
   216
(*strip a proof state (Horn clause):
67721
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 63063
diff changeset
   217
  B1 \<Longrightarrow> ... Bn \<Longrightarrow> C   goes to   ([B1, ..., Bn], C) *)
13659
3cf622f6b0b2 Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents: 12902
diff changeset
   218
fun strip_horn A = (strip_imp_prems A, strip_imp_concl A);
3cf622f6b0b2 Removed obsolete functions dealing with flex-flex constraints.
berghofe
parents: 12902
diff changeset
   219
4822
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   220
63063
wenzelm
parents: 63056
diff changeset
   221
(* close -- omit vacuous quantifiers *)
63056
9b95ae9ec671 defs are closed, which leads to proper auto_bind_facts;
wenzelm
parents: 61655
diff changeset
   222
9b95ae9ec671 defs are closed, which leads to proper auto_bind_facts;
wenzelm
parents: 61655
diff changeset
   223
val close_term = fold_rev Term.dependent_lambda_name;
63063
wenzelm
parents: 63056
diff changeset
   224
wenzelm
parents: 63056
diff changeset
   225
fun close_prop xs As B =
wenzelm
parents: 63056
diff changeset
   226
  fold_rev dependent_all_name xs (list_implies (As, B));
wenzelm
parents: 63056
diff changeset
   227
wenzelm
parents: 63056
diff changeset
   228
fun close_prop_constraint default_type xs As B =
wenzelm
parents: 63056
diff changeset
   229
  fold_rev (dependent_all_constraint default_type) xs (list_implies (As, B));
63056
9b95ae9ec671 defs are closed, which leads to proper auto_bind_facts;
wenzelm
parents: 61655
diff changeset
   230
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   231
12137
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   232
(** conjunction **)
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   233
46217
7b19666f0e3d renamed Term.all to Logic.all_const, in accordance to HOLogic.all_const;
wenzelm
parents: 46215
diff changeset
   234
val true_prop = all_const propT $ Abs ("dummy", propT, mk_implies (Bound 0, Bound 0));
26424
a6cad32a27b0 eliminated theory ProtoPure;
wenzelm
parents: 25939
diff changeset
   235
val conjunction = Const ("Pure.conjunction", propT --> propT --> propT);
19125
59b26248547b simplified Pure conjunction, based on actual const;
wenzelm
parents: 19103
diff changeset
   236
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   237
28856
5e009a80fe6d Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents: 28448
diff changeset
   238
(*A &&& B*)
19125
59b26248547b simplified Pure conjunction, based on actual const;
wenzelm
parents: 19103
diff changeset
   239
fun mk_conjunction (A, B) = conjunction $ A $ B;
12137
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   240
28856
5e009a80fe6d Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents: 28448
diff changeset
   241
(*A &&& B &&& C -- improper*)
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   242
fun mk_conjunction_list [] = true_prop
12757
b76a4376cfcb added mk_conjunction_list;
wenzelm
parents: 12137
diff changeset
   243
  | mk_conjunction_list ts = foldr1 mk_conjunction ts;
12137
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   244
28856
5e009a80fe6d Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents: 28448
diff changeset
   245
(*(A &&& B) &&& (C &&& D) -- balanced*)
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   246
fun mk_conjunction_balanced [] = true_prop
32765
3032c0308019 modernized Balanced_Tree;
wenzelm
parents: 32026
diff changeset
   247
  | mk_conjunction_balanced ts = Balanced_Tree.make mk_conjunction ts;
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   248
18499
567370efb6d7 added mk_conjunction_list2;
wenzelm
parents: 18469
diff changeset
   249
28856
5e009a80fe6d Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents: 28448
diff changeset
   250
(*A &&& B*)
26424
a6cad32a27b0 eliminated theory ProtoPure;
wenzelm
parents: 25939
diff changeset
   251
fun dest_conjunction (Const ("Pure.conjunction", _) $ A $ B) = (A, B)
18469
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   252
  | dest_conjunction t = raise TERM ("dest_conjunction", [t]);
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   253
28856
5e009a80fe6d Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents: 28448
diff changeset
   254
(*A &&& B &&& C -- improper*)
19425
e0d7d9373faf added dest_conjunction_list;
wenzelm
parents: 19406
diff changeset
   255
fun dest_conjunction_list t =
e0d7d9373faf added dest_conjunction_list;
wenzelm
parents: 19406
diff changeset
   256
  (case try dest_conjunction t of
e0d7d9373faf added dest_conjunction_list;
wenzelm
parents: 19406
diff changeset
   257
    NONE => [t]
e0d7d9373faf added dest_conjunction_list;
wenzelm
parents: 19406
diff changeset
   258
  | SOME (A, B) => A :: dest_conjunction_list B);
e0d7d9373faf added dest_conjunction_list;
wenzelm
parents: 19406
diff changeset
   259
28856
5e009a80fe6d Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents: 28448
diff changeset
   260
(*(A &&& B) &&& (C &&& D) -- balanced*)
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   261
fun dest_conjunction_balanced 0 _ = []
32765
3032c0308019 modernized Balanced_Tree;
wenzelm
parents: 32026
diff changeset
   262
  | dest_conjunction_balanced n t = Balanced_Tree.dest dest_conjunction n t;
23418
c195f6f13769 balanced conjunctions;
wenzelm
parents: 23357
diff changeset
   263
28856
5e009a80fe6d Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents: 28448
diff changeset
   264
(*((A &&& B) &&& C) &&& D &&& E -- flat*)
18469
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   265
fun dest_conjunctions t =
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   266
  (case try dest_conjunction t of
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   267
    NONE => [t]
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   268
  | SOME (A, B) => dest_conjunctions A @ dest_conjunctions B);
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   269
324245a561b5 mk_conjunction: proper treatment of bounds;
wenzelm
parents: 18248
diff changeset
   270
12137
6123958975b8 added mk_conjunction;
wenzelm
parents: 10816
diff changeset
   271
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   272
(** types as terms **)
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   273
56243
2e10a36b8d46 more qualified names;
wenzelm
parents: 49865
diff changeset
   274
fun mk_type ty = Const ("Pure.type", Term.itselfT ty);
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   275
56243
2e10a36b8d46 more qualified names;
wenzelm
parents: 49865
diff changeset
   276
fun dest_type (Const ("Pure.type", Type ("itself", [ty]))) = ty
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   277
  | dest_type t = raise TERM ("dest_type", [t]);
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   278
21520
63c73f461eec added type_map;
wenzelm
parents: 21016
diff changeset
   279
fun type_map f = dest_type o f o mk_type;
63c73f461eec added type_map;
wenzelm
parents: 21016
diff changeset
   280
4822
2733e21814fe added mk_cond_defpair, mk_defpair;
wenzelm
parents: 4693
diff changeset
   281
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   282
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   283
(** type classes **)
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   284
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   285
(* const names *)
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   286
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   287
val classN = "_class";
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   288
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   289
val const_of_class = suffix classN;
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   290
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   291
fun class_of_const c = unsuffix classN c
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   292
  handle Fail _ => raise TERM ("class_of_const: bad name " ^ quote c, []);
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   293
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   294
35854
d452abc96459 Logic.mk_of_sort convenience;
wenzelm
parents: 35845
diff changeset
   295
(* class/sort membership *)
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   296
31943
5e960a0780a2 renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
wenzelm
parents: 30554
diff changeset
   297
fun mk_of_class (ty, c) =
19391
4812d28c90a6 Term.itselfT;
wenzelm
parents: 19125
diff changeset
   298
  Const (const_of_class c, Term.itselfT ty --> propT) $ mk_type ty;
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   299
32784
1a5dde5079ac eliminated redundant bindings;
wenzelm
parents: 32765
diff changeset
   300
fun dest_of_class (Const (c_class, _) $ ty) = (dest_type ty, class_of_const c_class)
31943
5e960a0780a2 renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
wenzelm
parents: 30554
diff changeset
   301
  | dest_of_class t = raise TERM ("dest_of_class", [t]);
398
41f279b477e2 added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
wenzelm
parents: 210
diff changeset
   302
35854
d452abc96459 Logic.mk_of_sort convenience;
wenzelm
parents: 35845
diff changeset
   303
fun mk_of_sort (ty, S) = map (fn c => mk_of_class (ty, c)) S;
d452abc96459 Logic.mk_of_sort convenience;
wenzelm
parents: 35845
diff changeset
   304
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   305
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   306
(* class relations *)
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   307
20630
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
   308
fun name_classrel (c1, c2) =
30364
577edc39b501 moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents: 30280
diff changeset
   309
  Long_Name.base_name c1 ^ "_" ^ Long_Name.base_name c2;
20630
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
   310
31943
5e960a0780a2 renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
wenzelm
parents: 30554
diff changeset
   311
fun mk_classrel (c1, c2) = mk_of_class (Term.aT [c1], c2);
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   312
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   313
fun dest_classrel tm =
31943
5e960a0780a2 renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
wenzelm
parents: 30554
diff changeset
   314
  (case dest_of_class tm of
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   315
    (TVar (_, [c1]), c2) => (c1, c2)
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   316
  | _ => raise TERM ("dest_classrel", [tm]));
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   317
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   318
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   319
(* type arities *)
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   320
20630
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
   321
fun name_arities (t, _, S) =
30364
577edc39b501 moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents: 30280
diff changeset
   322
  let val b = Long_Name.base_name t
577edc39b501 moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents: 30280
diff changeset
   323
  in S |> map (fn c => Long_Name.base_name c ^ "_" ^ b) end;
20630
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
   324
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
   325
fun name_arity (t, dom, c) = hd (name_arities (t, dom, [c]));
2010cbb1a941 added name_classrel/arities/arity;
wenzelm
parents: 20548
diff changeset
   326
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   327
fun mk_arities (t, Ss, S) =
43329
84472e198515 tuned signature: Name.invent and Name.invent_names;
wenzelm
parents: 37230
diff changeset
   328
  let val T = Type (t, ListPair.map TFree (Name.invent Name.context Name.aT (length Ss), Ss))
31943
5e960a0780a2 renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
wenzelm
parents: 30554
diff changeset
   329
  in map (fn c => mk_of_class (T, c)) S end;
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   330
70384
8ce08b154aa1 clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents: 69023
diff changeset
   331
fun mk_arity (t, Ss, c) = the_single (mk_arities (t, Ss, [c]));
8ce08b154aa1 clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents: 69023
diff changeset
   332
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   333
fun dest_arity tm =
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   334
  let
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   335
    fun err () = raise TERM ("dest_arity", [tm]);
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   336
31943
5e960a0780a2 renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
wenzelm
parents: 30554
diff changeset
   337
    val (ty, c) = dest_of_class tm;
19406
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   338
    val (t, tvars) =
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   339
      (case ty of
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   340
        Type (t, tys) => (t, map dest_TVar tys handle TYPE _ => err ())
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   341
      | _ => err ());
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   342
    val Ss =
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   343
      if has_duplicates (eq_fst (op =)) tvars then err ()
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   344
      else map snd tvars;
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   345
  in (t, Ss, c) end;
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   346
410b9d9bf9a1 added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
wenzelm
parents: 19391
diff changeset
   347
36767
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   348
(* internalized sort constraints *)
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   349
70811
785a2112f861 clarified signature -- some operations to support fully explicit proof terms;
wenzelm
parents: 70438
diff changeset
   350
fun dummy_tfree S = TFree ("'dummy", S);
785a2112f861 clarified signature -- some operations to support fully explicit proof terms;
wenzelm
parents: 70438
diff changeset
   351
70436
251f1fb44ccd clarified signature;
wenzelm
parents: 70435
diff changeset
   352
type unconstrain_context =
251f1fb44ccd clarified signature;
wenzelm
parents: 70435
diff changeset
   353
 {present_map: (typ * typ) list,
70438
99024c9c83f6 proper constrains_map -- for shyps that are covered by present variables (amending 251f1fb44ccd);
wenzelm
parents: 70437
diff changeset
   354
  constraints_map: (sort * typ) list,
70436
251f1fb44ccd clarified signature;
wenzelm
parents: 70435
diff changeset
   355
  atyp_map: typ -> typ,
70437
fdbb0c2e0162 tuned signature;
wenzelm
parents: 70436
diff changeset
   356
  map_atyps: typ -> typ,
70436
251f1fb44ccd clarified signature;
wenzelm
parents: 70435
diff changeset
   357
  constraints: ((typ * class) * term) list,
251f1fb44ccd clarified signature;
wenzelm
parents: 70435
diff changeset
   358
  outer_constraints: (typ * class) list};
251f1fb44ccd clarified signature;
wenzelm
parents: 70435
diff changeset
   359
36768
46be86127972 just one version of Thm.unconstrainT, which affects all variables;
wenzelm
parents: 36767
diff changeset
   360
fun unconstrainT shyps prop =
36767
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   361
  let
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   362
    val present = rev ((fold_types o fold_atyps_sorts) (insert (eq_fst op =)) prop []);
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   363
    val extra = fold (Sorts.remove_sort o #2) present shyps;
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   364
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   365
    val n = length present;
43329
84472e198515 tuned signature: Name.invent and Name.invent_names;
wenzelm
parents: 37230
diff changeset
   366
    val (names1, names2) = Name.invent Name.context Name.aT (n + length extra) |> chop n;
36767
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   367
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   368
    val present_map =
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   369
      map2 (fn (T, S) => fn a => (T, TVar ((a, 0), S))) present names1;
70438
99024c9c83f6 proper constrains_map -- for shyps that are covered by present variables (amending 251f1fb44ccd);
wenzelm
parents: 70437
diff changeset
   370
    val constraints_map =
99024c9c83f6 proper constrains_map -- for shyps that are covered by present variables (amending 251f1fb44ccd);
wenzelm
parents: 70437
diff changeset
   371
      map2 (fn (_, S) => fn a => (S, TVar ((a, 0), S))) present names1 @
36767
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   372
      map2 (fn S => fn a => (S, TVar ((a, 0), S))) extra names2;
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   373
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   374
    fun atyp_map T =
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   375
      (case AList.lookup (op =) present_map T of
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   376
        SOME U => U
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   377
      | NONE =>
70438
99024c9c83f6 proper constrains_map -- for shyps that are covered by present variables (amending 251f1fb44ccd);
wenzelm
parents: 70437
diff changeset
   378
          (case AList.lookup (op =) constraints_map (Type.sort_of_atyp T) of
36767
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   379
            SOME U => U
70811
785a2112f861 clarified signature -- some operations to support fully explicit proof terms;
wenzelm
parents: 70438
diff changeset
   380
          | NONE => raise TYPE ("Dangling type variable ", [T], [prop])));
785a2112f861 clarified signature -- some operations to support fully explicit proof terms;
wenzelm
parents: 70438
diff changeset
   381
785a2112f861 clarified signature -- some operations to support fully explicit proof terms;
wenzelm
parents: 70438
diff changeset
   382
    val map_atyps = Term.map_atyps (Type.strip_sorts o atyp_map);
36767
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   383
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   384
    val constraints =
70436
251f1fb44ccd clarified signature;
wenzelm
parents: 70435
diff changeset
   385
      constraints_map |> maps (fn (_, T as TVar (ai, S)) =>
251f1fb44ccd clarified signature;
wenzelm
parents: 70435
diff changeset
   386
        map (fn c => ((T, c), mk_of_class (TVar (ai, []), c))) S);
36767
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   387
37230
7b548f137276 outer_constraints with original variable names, to ensure that argsP is consistent with args
berghofe
parents: 36768
diff changeset
   388
    val outer_constraints =
70811
785a2112f861 clarified signature -- some operations to support fully explicit proof terms;
wenzelm
parents: 70438
diff changeset
   389
      maps (fn (T, S) => map (pair T) S) (present @ map (`dummy_tfree) extra);
37230
7b548f137276 outer_constraints with original variable names, to ensure that argsP is consistent with args
berghofe
parents: 36768
diff changeset
   390
70437
fdbb0c2e0162 tuned signature;
wenzelm
parents: 70436
diff changeset
   391
    val ucontext =
70436
251f1fb44ccd clarified signature;
wenzelm
parents: 70435
diff changeset
   392
     {present_map = present_map,
70438
99024c9c83f6 proper constrains_map -- for shyps that are covered by present variables (amending 251f1fb44ccd);
wenzelm
parents: 70437
diff changeset
   393
      constraints_map = constraints_map,
70436
251f1fb44ccd clarified signature;
wenzelm
parents: 70435
diff changeset
   394
      atyp_map = atyp_map,
70437
fdbb0c2e0162 tuned signature;
wenzelm
parents: 70436
diff changeset
   395
      map_atyps = map_atyps,
70436
251f1fb44ccd clarified signature;
wenzelm
parents: 70435
diff changeset
   396
      constraints = constraints,
251f1fb44ccd clarified signature;
wenzelm
parents: 70435
diff changeset
   397
      outer_constraints = outer_constraints};
251f1fb44ccd clarified signature;
wenzelm
parents: 70435
diff changeset
   398
    val prop' = prop
70437
fdbb0c2e0162 tuned signature;
wenzelm
parents: 70436
diff changeset
   399
      |> Term.map_types map_atyps
fdbb0c2e0162 tuned signature;
wenzelm
parents: 70436
diff changeset
   400
      |> curry list_implies (map #2 constraints);
fdbb0c2e0162 tuned signature;
wenzelm
parents: 70436
diff changeset
   401
  in (ucontext, prop') end;
36767
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   402
d0095729e1f1 added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
wenzelm
parents: 35854
diff changeset
   403
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   404
28448
31a59d7d2168 tuned comments;
wenzelm
parents: 27334
diff changeset
   405
(** protected propositions and embedded terms **)
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   406
56244
3298b7a2795a more qualified names;
wenzelm
parents: 56243
diff changeset
   407
val protectC = Const ("Pure.prop", propT --> propT);
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   408
fun protect t = protectC $ t;
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   409
56244
3298b7a2795a more qualified names;
wenzelm
parents: 56243
diff changeset
   410
fun unprotect (Const ("Pure.prop", _) $ t) = t
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   411
  | unprotect t = raise TERM ("unprotect", [t]);
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   412
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   413
26424
a6cad32a27b0 eliminated theory ProtoPure;
wenzelm
parents: 25939
diff changeset
   414
fun mk_term t = Const ("Pure.term", Term.fastype_of t --> propT) $ t;
19775
06cb6743adf6 support embedded terms;
wenzelm
parents: 19425
diff changeset
   415
26424
a6cad32a27b0 eliminated theory ProtoPure;
wenzelm
parents: 25939
diff changeset
   416
fun dest_term (Const ("Pure.term", _) $ t) = t
19775
06cb6743adf6 support embedded terms;
wenzelm
parents: 19425
diff changeset
   417
  | dest_term t = raise TERM ("dest_term", [t]);
06cb6743adf6 support embedded terms;
wenzelm
parents: 19425
diff changeset
   418
06cb6743adf6 support embedded terms;
wenzelm
parents: 19425
diff changeset
   419
18181
wenzelm
parents: 18029
diff changeset
   420
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   421
(*** Low-level term operations ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   422
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   423
(*Does t occur in u?  Or is alpha-convertible to u?
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   424
  The term t must contain no loose bound variables*)
16846
bbebc68a7faf occs no longer infix (structure not open);
wenzelm
parents: 16130
diff changeset
   425
fun occs (t, u) = exists_subterm (fn s => t aconv s) u;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   426
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   427
(*Close up a formula over all free variables by quantification*)
46215
0da9433f959e discontinued old-style Term.list_all_free in favour of plain Logic.all;
wenzelm
parents: 45344
diff changeset
   428
fun close_form A = fold (all o Free) (Term.add_frees A []) A;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   429
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   430
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   431
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   432
(*** Specialized operations for resolution... ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   433
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   434
(*computes t(Bound(n+k-1),...,Bound(n))  *)
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   435
fun combound (t, n, k) =
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   436
    if  k>0  then  combound (t,n+1,k-1) $ (Bound n)  else  t;
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   437
67721
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 63063
diff changeset
   438
(* ([xn,...,x1], t)   goes to   \<lambda>x1 ... xn. t *)
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   439
fun rlist_abs ([], body) = body
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   440
  | rlist_abs ((a,T)::pairs, body) = rlist_abs(pairs, Abs(a, T, body));
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   441
32026
9898880061df tuned incr_tvar_same;
wenzelm
parents: 32023
diff changeset
   442
fun incr_tvar_same 0 = Same.same
9898880061df tuned incr_tvar_same;
wenzelm
parents: 32023
diff changeset
   443
  | incr_tvar_same k = Term_Subst.map_atypsT_same
9898880061df tuned incr_tvar_same;
wenzelm
parents: 32023
diff changeset
   444
      (fn TVar ((a, i), S) => TVar ((a, i + k), S)
9898880061df tuned incr_tvar_same;
wenzelm
parents: 32023
diff changeset
   445
        | _ => raise Same.SAME);
16879
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   446
32026
9898880061df tuned incr_tvar_same;
wenzelm
parents: 32023
diff changeset
   447
fun incr_tvar k T = incr_tvar_same k T handle Same.SAME => T;
32023
2d071ac5032f export incr_tvar_same;
wenzelm
parents: 32020
diff changeset
   448
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   449
(*For all variables in the term, increment indexnames and lift over the Us
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   450
    result is ?Gidx(B.(lev+n-1),...,B.lev) where lev is abstraction level *)
59787
6e2a20486897 local fixes may depend on goal params;
wenzelm
parents: 56245
diff changeset
   451
fun incr_indexes_same ([], [], 0) = Same.same
6e2a20486897 local fixes may depend on goal params;
wenzelm
parents: 56245
diff changeset
   452
  | incr_indexes_same (fixed, Ts, k) =
32020
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   453
      let
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   454
        val n = length Ts;
32026
9898880061df tuned incr_tvar_same;
wenzelm
parents: 32023
diff changeset
   455
        val incrT = incr_tvar_same k;
16879
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   456
32020
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   457
        fun incr lev (Var ((x, i), T)) =
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   458
              combound (Var ((x, i + k), Ts ---> Same.commit incrT T), lev, n)
59787
6e2a20486897 local fixes may depend on goal params;
wenzelm
parents: 56245
diff changeset
   459
          | incr lev (Free (x, T)) =
6e2a20486897 local fixes may depend on goal params;
wenzelm
parents: 56245
diff changeset
   460
              if member (op =) fixed x then
6e2a20486897 local fixes may depend on goal params;
wenzelm
parents: 56245
diff changeset
   461
                combound (Free (x, Ts ---> Same.commit incrT T), lev, n)
6e2a20486897 local fixes may depend on goal params;
wenzelm
parents: 56245
diff changeset
   462
              else Free (x, incrT T)
32020
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   463
          | incr lev (Abs (x, T, body)) =
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   464
              (Abs (x, incrT T, incr (lev + 1) body handle Same.SAME => body)
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   465
                handle Same.SAME => Abs (x, T, incr (lev + 1) body))
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   466
          | incr lev (t $ u) =
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   467
              (incr lev t $ (incr lev u handle Same.SAME => u)
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   468
                handle Same.SAME => t $ incr lev u)
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   469
          | incr _ (Const (c, T)) = Const (c, incrT T)
32026
9898880061df tuned incr_tvar_same;
wenzelm
parents: 32023
diff changeset
   470
          | incr _ (Bound _) = raise Same.SAME;
9898880061df tuned incr_tvar_same;
wenzelm
parents: 32023
diff changeset
   471
      in incr 0 end;
9898880061df tuned incr_tvar_same;
wenzelm
parents: 32023
diff changeset
   472
9898880061df tuned incr_tvar_same;
wenzelm
parents: 32023
diff changeset
   473
fun incr_indexes arg t = incr_indexes_same arg t handle Same.SAME => t;
16879
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   474
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   475
18248
wenzelm
parents: 18181
diff changeset
   476
(* Lifting functions from subgoal and increment:
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   477
    lift_abs operates on terms
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   478
    lift_all operates on propositions *)
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   479
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   480
fun lift_abs inc =
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   481
  let
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   482
    fun lift Ts (Const ("Pure.imp", _) $ _ $ B) t = lift Ts B t
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   483
      | lift Ts (Const ("Pure.all", _) $ Abs (a, T, B)) t = Abs (a, T, lift (T :: Ts) B t)
59787
6e2a20486897 local fixes may depend on goal params;
wenzelm
parents: 56245
diff changeset
   484
      | lift Ts _ t = incr_indexes ([], rev Ts, inc) t;
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   485
  in lift [] end;
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   486
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   487
fun lift_all inc =
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   488
  let
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   489
    fun lift Ts ((c as Const ("Pure.imp", _)) $ A $ B) t = c $ A $ lift Ts B t
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   490
      | lift Ts ((c as Const ("Pure.all", _)) $ Abs (a, T, B)) t = c $ Abs (a, T, lift (T :: Ts) B t)
59787
6e2a20486897 local fixes may depend on goal params;
wenzelm
parents: 56245
diff changeset
   491
      | lift Ts _ t = incr_indexes ([], rev Ts, inc) t;
18029
19f1ad18bece renamed Goal constant to prop, more general protect/unprotect interfaces;
wenzelm
parents: 17120
diff changeset
   492
  in lift [] end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   493
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   494
(*Strips assumptions in goal, yielding list of hypotheses.   *)
21016
430b35c9cd27 Repaired strip_assums_hyp (now also works for goals not
berghofe
parents: 20883
diff changeset
   495
fun strip_assums_hyp B =
430b35c9cd27 Repaired strip_assums_hyp (now also works for goals not
berghofe
parents: 20883
diff changeset
   496
  let
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   497
    fun strip Hs (Const ("Pure.imp", _) $ H $ B) = strip (H :: Hs) B
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   498
      | strip Hs (Const ("Pure.all", _) $ Abs (a, T, t)) =
21016
430b35c9cd27 Repaired strip_assums_hyp (now also works for goals not
berghofe
parents: 20883
diff changeset
   499
          strip (map (incr_boundvars 1) Hs) t
430b35c9cd27 Repaired strip_assums_hyp (now also works for goals not
berghofe
parents: 20883
diff changeset
   500
      | strip Hs B = rev Hs
430b35c9cd27 Repaired strip_assums_hyp (now also works for goals not
berghofe
parents: 20883
diff changeset
   501
  in strip [] B end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   502
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   503
(*Strips assumptions in goal, yielding conclusion.   *)
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   504
fun strip_assums_concl (Const("Pure.imp", _) $ H $ B) = strip_assums_concl B
60705
6cc14cf3acff tuned whitespace;
wenzelm
parents: 60454
diff changeset
   505
  | strip_assums_concl (Const("Pure.all", _) $ Abs (a, T, t)) = strip_assums_concl t
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   506
  | strip_assums_concl B = B;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   507
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   508
(*Make a list of all the parameters in a subgoal, even if nested*)
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   509
fun strip_params (Const("Pure.imp", _) $ H $ B) = strip_params B
60705
6cc14cf3acff tuned whitespace;
wenzelm
parents: 60454
diff changeset
   510
  | strip_params (Const("Pure.all", _) $ Abs (a, T, t)) = (a, T) :: strip_params t
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   511
  | strip_params B = [];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   512
23597
ab67175ca8a5 simplified has_meta_prems;
wenzelm
parents: 23418
diff changeset
   513
(*test for nested meta connectives in prems*)
ab67175ca8a5 simplified has_meta_prems;
wenzelm
parents: 23418
diff changeset
   514
val has_meta_prems =
9667
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   515
  let
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   516
    fun is_meta (Const ("Pure.eq", _) $ _ $ _) = true
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   517
      | is_meta (Const ("Pure.imp", _) $ _ $ _) = true
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   518
      | is_meta (Const ("Pure.all", _) $ _) = true
9667
48cefe2daf32 fixed has_meta_prems: strip_assums_hyp;
wenzelm
parents: 9483
diff changeset
   519
      | is_meta _ = false;
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   520
    fun ex_meta (Const ("Pure.imp", _) $ A $ B) = is_meta A orelse ex_meta B
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   521
      | ex_meta (Const ("Pure.all", _) $ Abs (_, _, B)) = ex_meta B
23597
ab67175ca8a5 simplified has_meta_prems;
wenzelm
parents: 23418
diff changeset
   522
      | ex_meta _ = false;
ab67175ca8a5 simplified has_meta_prems;
wenzelm
parents: 23418
diff changeset
   523
  in ex_meta end;
9483
708a8a05497d added has_meta_prems;
wenzelm
parents: 9460
diff changeset
   524
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   525
(*Removes the parameters from a subgoal and renumber bvars in hypotheses,
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   526
    where j is the total number of parameters (precomputed)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   527
  If n>0 then deletes assumption n. *)
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   528
fun remove_params j n A =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   529
    if j=0 andalso n<=0 then A  (*nothing left to do...*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   530
    else case A of
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   531
        Const("Pure.imp", _) $ H $ B =>
9460
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   532
          if n=1 then                           (remove_params j (n-1) B)
53d7ad5bec39 Logic.goal_const;
wenzelm
parents: 5041
diff changeset
   533
          else implies $ (incr_boundvars j H) $ (remove_params j (n-1) B)
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   534
      | Const("Pure.all",_)$Abs(a,T,t) => remove_params (j-1) n t
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   535
      | _ => if n>0 then raise TERM("remove_params", [A])
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   536
             else A;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   537
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   538
(*Move all parameters to the front of the subgoal, renaming them apart;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   539
  if n>0 then deletes assumption n. *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   540
fun flatten_params n A =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   541
    let val params = strip_params A;
25939
ddea202704b4 Removed Logic.auto_rename.
berghofe
parents: 24848
diff changeset
   542
        val vars = ListPair.zip (Name.variant_list [] (map #1 params),
ddea202704b4 Removed Logic.auto_rename.
berghofe
parents: 24848
diff changeset
   543
                                 map #2 params)
46218
ecf6375e2abb renamed Term.list_all to Logic.list_all, in accordance to HOLogic.list_all;
wenzelm
parents: 46217
diff changeset
   544
    in list_all (vars, remove_params (length vars) n A) end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   545
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   546
(*Makes parameters in a goal have the names supplied by the list cs.*)
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   547
fun list_rename_params cs (Const ("Pure.imp", _) $ A $ B) =
45328
e5b33eecbf6e tuned signature;
wenzelm
parents: 43329
diff changeset
   548
      implies $ A $ list_rename_params cs B
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   549
  | list_rename_params (c :: cs) ((a as Const ("Pure.all", _)) $ Abs (_, T, t)) =
45328
e5b33eecbf6e tuned signature;
wenzelm
parents: 43329
diff changeset
   550
      a $ Abs (c, T, list_rename_params cs t)
e5b33eecbf6e tuned signature;
wenzelm
parents: 43329
diff changeset
   551
  | list_rename_params cs B = B;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   552
32008
fa0cc3c8f73d tuned comment;
wenzelm
parents: 32004
diff changeset
   553
fa0cc3c8f73d tuned comment;
wenzelm
parents: 32004
diff changeset
   554
19806
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   555
(*** Treatment of "assume", "erule", etc. ***)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   556
16879
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   557
(*Strips assumptions in goal yielding
15451
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   558
   HS = [Hn,...,H1],   params = [xm,...,x1], and B,
16879
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   559
  where x1...xm are the parameters. This version (21.1.2005) REQUIRES
b81d3f2ee565 incr_tvar (from term.ML), incr_indexes: avoid garbage;
wenzelm
parents: 16862
diff changeset
   560
  the the parameters to be flattened, but it allows erule to work on
67721
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 63063
diff changeset
   561
  assumptions of the form \<And>x. phi. Any \<And> after the outermost string
15451
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   562
  will be regarded as belonging to the conclusion, and left untouched.
15454
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   563
  Used ONLY by assum_pairs.
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   564
      Unless nasms<0, it can terminate the recursion early; that allows
67721
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 63063
diff changeset
   565
  erule to work on assumptions of the form P\<Longrightarrow>Q.*)
15454
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   566
fun strip_assums_imp (0, Hs, B) = (Hs, B)  (*recursion terminated by nasms*)
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   567
  | strip_assums_imp (nasms, Hs, Const("Pure.imp", _) $ H $ B) =
15454
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   568
      strip_assums_imp (nasms-1, H::Hs, B)
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   569
  | strip_assums_imp (_, Hs, B) = (Hs, B); (*recursion terminated by B*)
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   570
32008
fa0cc3c8f73d tuned comment;
wenzelm
parents: 32004
diff changeset
   571
(*Strips OUTER parameters only.*)
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 56244
diff changeset
   572
fun strip_assums_all (params, Const("Pure.all",_)$Abs(a,T,t)) =
15451
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   573
      strip_assums_all ((a,T)::params, t)
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   574
  | strip_assums_all (params, B) = (params, B);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   575
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   576
(*Produces disagreement pairs, one for each assumption proof, in order.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   577
  A is the first premise of the lifted rule, and thus has the form
67721
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 63063
diff changeset
   578
    H1 \<Longrightarrow> ... Hk \<Longrightarrow> B   and the pairs are (H1,B),...,(Hk,B).
15454
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   579
  nasms is the number of assumptions in the original subgoal, needed when B
67721
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 63063
diff changeset
   580
    has the form B1 \<Longrightarrow> B2: it stops B1 from being taken as an assumption. *)
15454
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   581
fun assum_pairs(nasms,A) =
15451
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   582
  let val (params, A') = strip_assums_all ([],A)
15454
4b339d3907a0 thin_tac now works on P==>Q
paulson
parents: 15451
diff changeset
   583
      val (Hs,B) = strip_assums_imp (nasms,[],A')
18938
b401ee1cda14 added generic dest_def (mostly from theory.ML);
wenzelm
parents: 18762
diff changeset
   584
      fun abspar t = rlist_abs(params, t)
15451
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   585
      val D = abspar B
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   586
      fun pairrev ([], pairs) = pairs
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   587
        | pairrev (H::Hs, pairs) = pairrev(Hs,  (abspar H, D) :: pairs)
c6c8786b9921 fixed thin_tac with higher-level assumptions by removing the old code to
paulson
parents: 14137
diff changeset
   588
  in  pairrev (Hs,[])
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   589
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   590
30554
73f8bd5f0af8 substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
wenzelm
parents: 30364
diff changeset
   591
fun assum_problems (nasms, A) =
73f8bd5f0af8 substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
wenzelm
parents: 30364
diff changeset
   592
  let
73f8bd5f0af8 substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
wenzelm
parents: 30364
diff changeset
   593
    val (params, A') = strip_assums_all ([], A)
73f8bd5f0af8 substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
wenzelm
parents: 30364
diff changeset
   594
    val (Hs, B) = strip_assums_imp (nasms, [], A')
73f8bd5f0af8 substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
wenzelm
parents: 30364
diff changeset
   595
    fun abspar t = rlist_abs (params, t)
73f8bd5f0af8 substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
wenzelm
parents: 30364
diff changeset
   596
  in (abspar, rev Hs, B) end;
73f8bd5f0af8 substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
wenzelm
parents: 30364
diff changeset
   597
19806
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   598
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   599
(* global schematic variables *)
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   600
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   601
fun bad_schematic xi = "Illegal schematic variable: " ^ quote (Term.string_of_vname xi);
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   602
fun bad_fixed x = "Illegal fixed variable: " ^ quote x;
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   603
35845
e5980f0ad025 renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents: 32784
diff changeset
   604
fun varifyT_global_same ty = ty
32020
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   605
  |> Term_Subst.map_atypsT_same
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   606
    (fn TFree (a, S) => TVar ((a, 0), S)
31981
9c59cbb9c5a2 tuned varify/unvarify: use Term_Subst.map_XXX combinators;
wenzelm
parents: 31943
diff changeset
   607
      | TVar (ai, _) => raise TYPE (bad_schematic ai, [ty], []));
19806
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   608
35845
e5980f0ad025 renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents: 32784
diff changeset
   609
fun unvarifyT_global_same ty = ty
32020
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   610
  |> Term_Subst.map_atypsT_same
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   611
    (fn TVar ((a, 0), S) => TFree (a, S)
31981
9c59cbb9c5a2 tuned varify/unvarify: use Term_Subst.map_XXX combinators;
wenzelm
parents: 31943
diff changeset
   612
      | TVar (ai, _) => raise TYPE (bad_schematic ai, [ty], [])
9c59cbb9c5a2 tuned varify/unvarify: use Term_Subst.map_XXX combinators;
wenzelm
parents: 31943
diff changeset
   613
      | TFree (a, _) => raise TYPE (bad_fixed a, [ty], []));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   614
35845
e5980f0ad025 renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents: 32784
diff changeset
   615
val varifyT_global = Same.commit varifyT_global_same;
e5980f0ad025 renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents: 32784
diff changeset
   616
val unvarifyT_global = Same.commit unvarifyT_global_same;
31981
9c59cbb9c5a2 tuned varify/unvarify: use Term_Subst.map_XXX combinators;
wenzelm
parents: 31943
diff changeset
   617
45344
e209da839ff4 added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents: 45328
diff changeset
   618
fun varify_types_global tm = tm
e209da839ff4 added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents: 45328
diff changeset
   619
  |> Same.commit (Term_Subst.map_types_same varifyT_global_same)
e209da839ff4 added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents: 45328
diff changeset
   620
  handle TYPE (msg, _, _) => raise TERM (msg, [tm]);
e209da839ff4 added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents: 45328
diff changeset
   621
e209da839ff4 added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents: 45328
diff changeset
   622
fun unvarify_types_global tm = tm
e209da839ff4 added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents: 45328
diff changeset
   623
  |> Same.commit (Term_Subst.map_types_same unvarifyT_global_same)
e209da839ff4 added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents: 45328
diff changeset
   624
  handle TYPE (msg, _, _) => raise TERM (msg, [tm]);
e209da839ff4 added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents: 45328
diff changeset
   625
35845
e5980f0ad025 renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents: 32784
diff changeset
   626
fun varify_global tm = tm
32020
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   627
  |> Same.commit (Term_Subst.map_aterms_same
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   628
    (fn Free (x, T) => Var ((x, 0), T)
19806
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   629
      | Var (xi, _) => raise TERM (bad_schematic xi, [tm])
32020
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   630
      | _ => raise Same.SAME))
45344
e209da839ff4 added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents: 45328
diff changeset
   631
  |> varify_types_global;
19806
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   632
35845
e5980f0ad025 renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents: 32784
diff changeset
   633
fun unvarify_global tm = tm
32020
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   634
  |> Same.commit (Term_Subst.map_aterms_same
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   635
    (fn Var ((x, 0), T) => Free (x, T)
19806
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   636
      | Var (xi, _) => raise TERM (bad_schematic xi, [tm])
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   637
      | Free (x, _) => raise TERM (bad_fixed x, [tm])
32020
9abf5d66606e use structure Same;
wenzelm
parents: 32014
diff changeset
   638
      | _ => raise Same.SAME))
45344
e209da839ff4 added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
wenzelm
parents: 45328
diff changeset
   639
  |> unvarify_types_global;
19806
f860b7a98445 renamed Type.(un)varifyT to Logic.(un)varifyT;
wenzelm
parents: 19775
diff changeset
   640
13799
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   641
16862
wenzelm
parents: 16846
diff changeset
   642
(* goal states *)
wenzelm
parents: 16846
diff changeset
   643
49865
eeaf1ec7eac2 clarified defer/prefer: more specific errors;
wenzelm
parents: 46218
diff changeset
   644
fun get_goal st i =
eeaf1ec7eac2 clarified defer/prefer: more specific errors;
wenzelm
parents: 46218
diff changeset
   645
  nth_prem (i, st) handle TERM _ =>
eeaf1ec7eac2 clarified defer/prefer: more specific errors;
wenzelm
parents: 46218
diff changeset
   646
    error ("Subgoal number " ^ string_of_int i ^ " out of range (a total of " ^
eeaf1ec7eac2 clarified defer/prefer: more specific errors;
wenzelm
parents: 46218
diff changeset
   647
      string_of_int (count_prems st)  ^ " subgoals)");
13799
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   648
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   649
(*reverses parameters for substitution*)
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   650
fun goal_params st i =
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   651
  let val gi = get_goal st i
29276
94b1ffec9201 qualified Term.rename_wrt_term;
wenzelm
parents: 28856
diff changeset
   652
      val rfrees = map Free (Term.rename_wrt_term gi (strip_params gi))
13799
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   653
  in (gi, rfrees) end;
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   654
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   655
fun concl_of_goal st i =
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   656
  let val (gi, rfrees) = goal_params st i
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   657
      val B = strip_assums_concl gi
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   658
  in subst_bounds (rfrees, B) end;
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   659
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   660
fun prems_of_goal st i =
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   661
  let val (gi, rfrees) = goal_params st i
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   662
      val As = strip_assums_hyp gi
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   663
  in map (fn A => subst_bounds (rfrees, A)) As end;
77614fe09362 Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
berghofe
parents: 13659
diff changeset
   664
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   665
end;