src/Pure/Isar/object_logic.ML
author wenzelm
Sat Jan 12 16:37:58 2002 +0100 (2002-01-12)
changeset 12725 7ede865e1fe5
parent 12479 ed46612ad7ec
child 12729 46808b5ec985
permissions -rw-r--r--
renamed forall_elim_vars_safe to gen_all;
wenzelm@11897
     1
(*  Title:      Pure/Isar/object_logic.ML
wenzelm@11897
     2
    ID:         $Id$
wenzelm@11897
     3
    Author:     Markus Wenzel, TU Muenchen
wenzelm@11897
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
wenzelm@11897
     5
wenzelm@11897
     6
Specifics about common object-logics.
wenzelm@11897
     7
*)
wenzelm@11897
     8
wenzelm@11897
     9
signature OBJECT_LOGIC =
wenzelm@11897
    10
sig
wenzelm@11897
    11
  val add_judgment: bstring * string * mixfix -> theory -> theory
wenzelm@11897
    12
  val add_judgment_i: bstring * typ * mixfix -> theory -> theory
wenzelm@11897
    13
  val judgment_name: Sign.sg -> string
wenzelm@11897
    14
  val is_judgment: Sign.sg -> term -> bool
wenzelm@11897
    15
  val drop_judgment: Sign.sg -> term -> term
wenzelm@11897
    16
  val fixed_judgment: Sign.sg -> string -> term
wenzelm@11897
    17
  val declare_atomize: theory attribute
wenzelm@11897
    18
  val declare_rulify: theory attribute
wenzelm@11897
    19
  val atomize_tac: int -> tactic
wenzelm@11897
    20
  val atomize_goal: int -> thm -> thm
wenzelm@11897
    21
  val rulify: thm -> thm
wenzelm@11897
    22
  val rulify_no_asm: thm -> thm
wenzelm@11897
    23
  val rule_format: 'a attribute
wenzelm@11897
    24
  val rule_format_no_asm: 'a attribute
wenzelm@11897
    25
  val setup: (theory -> theory) list
wenzelm@11897
    26
end;
wenzelm@11897
    27
wenzelm@11897
    28
structure ObjectLogic: OBJECT_LOGIC =
wenzelm@11897
    29
struct
wenzelm@11897
    30
wenzelm@11897
    31
wenzelm@11897
    32
(** object-logic theory data **)
wenzelm@11897
    33
wenzelm@11897
    34
(* data kind 'Pure/object-logic' *)
wenzelm@11897
    35
wenzelm@11897
    36
structure ObjectLogicDataArgs =
wenzelm@11897
    37
struct
wenzelm@11897
    38
  val name = "Pure/object-logic";
wenzelm@11897
    39
  type T = string option * (thm list * thm list);
wenzelm@11897
    40
wenzelm@11897
    41
  val empty = (None, ([], [Drule.norm_hhf_eq]));
wenzelm@11897
    42
  val copy = I;
wenzelm@11897
    43
  val prep_ext = I;
wenzelm@11897
    44
wenzelm@11897
    45
  fun merge_judgment (Some x, Some y) =
wenzelm@11897
    46
        if x = y then Some x else error "Attempt to merge different object-logics"
wenzelm@11897
    47
    | merge_judgment (j1, j2) = if is_some j1 then j1 else j2;
wenzelm@11897
    48
wenzelm@11897
    49
  fun merge ((judgment1, (atomize1, rulify1)), (judgment2, (atomize2, rulify2))) =
wenzelm@11897
    50
    (merge_judgment (judgment1, judgment2),
wenzelm@11897
    51
      (Drule.merge_rules (atomize1, atomize2), Drule.merge_rules (rulify1, rulify2)));
wenzelm@11897
    52
wenzelm@11897
    53
  fun print _ _ = ();
wenzelm@11897
    54
end;
wenzelm@11897
    55
wenzelm@11897
    56
structure ObjectLogicData = TheoryDataFun(ObjectLogicDataArgs);
wenzelm@11897
    57
wenzelm@11897
    58
wenzelm@11897
    59
(** generic treatment of judgments -- with a single argument only **)
wenzelm@11897
    60
wenzelm@11897
    61
(* add_judgment(_i) *)
wenzelm@11897
    62
wenzelm@11897
    63
local
wenzelm@11897
    64
wenzelm@11897
    65
fun new_judgment name (None, rules) = (Some name, rules)
wenzelm@11897
    66
  | new_judgment _ (Some _, _) = error "Attempt to redeclare object-logic judgment";
wenzelm@11897
    67
wenzelm@11897
    68
fun gen_add_judgment add_consts (name, T, syn) thy =
wenzelm@11897
    69
  thy
wenzelm@11897
    70
  |> add_consts [(name, T, syn)]
wenzelm@11897
    71
  |> ObjectLogicData.map (new_judgment (Sign.full_name (Theory.sign_of thy) name));
wenzelm@11897
    72
wenzelm@11897
    73
in
wenzelm@11897
    74
wenzelm@11897
    75
val add_judgment = gen_add_judgment Theory.add_consts;
wenzelm@11897
    76
val add_judgment_i = gen_add_judgment Theory.add_consts_i;
wenzelm@11897
    77
wenzelm@11897
    78
end;
wenzelm@11897
    79
wenzelm@11897
    80
wenzelm@11897
    81
(* term operations *)
wenzelm@11897
    82
wenzelm@11897
    83
fun judgment_name sg =
wenzelm@11897
    84
  (case ObjectLogicData.get_sg sg of
wenzelm@11897
    85
    (Some name, _) => name
wenzelm@11897
    86
  | _ => raise TERM ("Unknown object-logic judgment", []));
wenzelm@11897
    87
wenzelm@11897
    88
fun is_judgment sg (Const (c, _) $ _) = c = judgment_name sg
wenzelm@11897
    89
  | is_judgment _ _ = false;
wenzelm@11897
    90
wenzelm@11897
    91
fun drop_judgment sg (Abs (x, T, t)) = Abs (x, T, drop_judgment sg t)
wenzelm@12479
    92
  | drop_judgment sg (tm as (Const (c, _) $ t)) =
wenzelm@12479
    93
      if (c = judgment_name sg handle TERM _ => false) then t else tm
wenzelm@11897
    94
  | drop_judgment _ tm = tm;
wenzelm@11897
    95
wenzelm@11897
    96
fun fixed_judgment sg x =
wenzelm@11897
    97
  let  (*be robust wrt. low-level errors*)
wenzelm@11897
    98
    val c = judgment_name sg;
wenzelm@11897
    99
    val aT = TFree ("'a", logicS);
wenzelm@11897
   100
    val T =
wenzelm@11897
   101
      if_none (Sign.const_type sg c) (aT --> propT)
wenzelm@11897
   102
      |> Term.map_type_tvar (fn ((x, _), S) => TFree (x, S));
wenzelm@11897
   103
    val U = Term.domain_type T handle Match => aT;
wenzelm@11897
   104
  in Const (c, T) $ Free (x, U) end;
wenzelm@11897
   105
wenzelm@11897
   106
wenzelm@11897
   107
wenzelm@11897
   108
(** treatment of meta-level connectives **)
wenzelm@11897
   109
wenzelm@11897
   110
(* maintain rules *)
wenzelm@11897
   111
wenzelm@11897
   112
val get_atomize = #1 o #2 o ObjectLogicData.get_sg;
wenzelm@11897
   113
val get_rulify = #2 o #2 o ObjectLogicData.get_sg;
wenzelm@11897
   114
wenzelm@12371
   115
val add_atomize = ObjectLogicData.map o Library.apsnd o Library.apfst o Drule.add_rule;
wenzelm@12371
   116
val add_rulify = ObjectLogicData.map o Library.apsnd o Library.apsnd o Drule.add_rule;
wenzelm@11897
   117
wenzelm@12371
   118
fun declare_atomize (thy, th) = (add_atomize th thy, th);
wenzelm@12371
   119
fun declare_rulify (thy, th) = (add_rulify th thy, th);
wenzelm@11897
   120
wenzelm@11897
   121
wenzelm@11897
   122
(* atomize *)
wenzelm@11897
   123
wenzelm@11897
   124
fun rewrite_prems_tac rews i = PRIMITIVE (MetaSimplifier.fconv_rule
wenzelm@11897
   125
  (MetaSimplifier.goals_conv (Library.equal i)
wenzelm@11897
   126
    (MetaSimplifier.forall_conv
wenzelm@11897
   127
      (MetaSimplifier.goals_conv (K true) (Tactic.rewrite true rews)))));
wenzelm@11897
   128
wenzelm@11897
   129
fun atomize_tac i st =
wenzelm@11897
   130
  if Logic.has_meta_prems (#prop (Thm.rep_thm st)) i then
wenzelm@11897
   131
    (rewrite_prems_tac (get_atomize (Thm.sign_of_thm st)) i) st
wenzelm@11897
   132
  else all_tac st;
wenzelm@11897
   133
wenzelm@11897
   134
fun atomize_goal i st =
wenzelm@11897
   135
  (case Seq.pull (atomize_tac i st) of None => st | Some (st', _) => st');
wenzelm@11897
   136
wenzelm@11897
   137
wenzelm@11897
   138
(* rulify *)
wenzelm@11897
   139
wenzelm@11897
   140
fun gen_rulify full thm =
wenzelm@11897
   141
  Tactic.simplify full (get_rulify (Thm.sign_of_thm thm)) thm
wenzelm@12725
   142
  |> Drule.gen_all |> Drule.strip_shyps_warning |> Drule.zero_var_indexes;
wenzelm@11897
   143
wenzelm@11897
   144
val rulify = gen_rulify true;
wenzelm@11897
   145
val rulify_no_asm = gen_rulify false;
wenzelm@11897
   146
wenzelm@11897
   147
fun rule_format x = Drule.rule_attribute (fn _ => rulify) x;
wenzelm@11897
   148
fun rule_format_no_asm x = Drule.rule_attribute (fn _ => rulify_no_asm) x;
wenzelm@11897
   149
wenzelm@11897
   150
wenzelm@11897
   151
wenzelm@11897
   152
(** theory setup **)
wenzelm@11897
   153
wenzelm@11897
   154
val setup = [ObjectLogicData.init];
wenzelm@11897
   155
wenzelm@11897
   156
wenzelm@11897
   157
end;