src/Pure/Isar/object_logic.ML
author wenzelm
Wed Nov 28 00:46:26 2001 +0100 (2001-11-28)
changeset 12311 ce5f9e61c037
parent 12123 739eba13e2cd
child 12371 80ca9058db95
permissions -rw-r--r--
theory data: removed obsolete finish method;
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@11897
    92
  | drop_judgment sg (tm as (Const (c, _) $ t)) = if c = judgment_name sg then t else tm
wenzelm@11897
    93
  | drop_judgment _ tm = tm;
wenzelm@11897
    94
wenzelm@11897
    95
fun fixed_judgment sg x =
wenzelm@11897
    96
  let  (*be robust wrt. low-level errors*)
wenzelm@11897
    97
    val c = judgment_name sg;
wenzelm@11897
    98
    val aT = TFree ("'a", logicS);
wenzelm@11897
    99
    val T =
wenzelm@11897
   100
      if_none (Sign.const_type sg c) (aT --> propT)
wenzelm@11897
   101
      |> Term.map_type_tvar (fn ((x, _), S) => TFree (x, S));
wenzelm@11897
   102
    val U = Term.domain_type T handle Match => aT;
wenzelm@11897
   103
  in Const (c, T) $ Free (x, U) end;
wenzelm@11897
   104
wenzelm@11897
   105
wenzelm@11897
   106
wenzelm@11897
   107
(** treatment of meta-level connectives **)
wenzelm@11897
   108
wenzelm@11897
   109
(* maintain rules *)
wenzelm@11897
   110
wenzelm@11897
   111
val get_atomize = #1 o #2 o ObjectLogicData.get_sg;
wenzelm@11897
   112
val get_rulify = #2 o #2 o ObjectLogicData.get_sg;
wenzelm@11897
   113
wenzelm@11897
   114
val add_atomize = ObjectLogicData.map o Library.apsnd o Library.apfst o Drule.add_rules;
wenzelm@11897
   115
val add_rulify = ObjectLogicData.map o Library.apsnd o Library.apsnd o Drule.add_rules;
wenzelm@11897
   116
wenzelm@11897
   117
fun declare_atomize (thy, th) = (add_atomize [th] thy, th);
wenzelm@11897
   118
fun declare_rulify (thy, th) = (add_rulify [th] thy, th);
wenzelm@11897
   119
wenzelm@11897
   120
wenzelm@11897
   121
(* atomize *)
wenzelm@11897
   122
wenzelm@11897
   123
fun rewrite_prems_tac rews i = PRIMITIVE (MetaSimplifier.fconv_rule
wenzelm@11897
   124
  (MetaSimplifier.goals_conv (Library.equal i)
wenzelm@11897
   125
    (MetaSimplifier.forall_conv
wenzelm@11897
   126
      (MetaSimplifier.goals_conv (K true) (Tactic.rewrite true rews)))));
wenzelm@11897
   127
wenzelm@11897
   128
fun atomize_tac i st =
wenzelm@11897
   129
  if Logic.has_meta_prems (#prop (Thm.rep_thm st)) i then
wenzelm@11897
   130
    (rewrite_prems_tac (get_atomize (Thm.sign_of_thm st)) i) st
wenzelm@11897
   131
  else all_tac st;
wenzelm@11897
   132
wenzelm@11897
   133
fun atomize_goal i st =
wenzelm@11897
   134
  (case Seq.pull (atomize_tac i st) of None => st | Some (st', _) => st');
wenzelm@11897
   135
wenzelm@11897
   136
wenzelm@11897
   137
(* rulify *)
wenzelm@11897
   138
wenzelm@11897
   139
fun gen_rulify full thm =
wenzelm@11897
   140
  Tactic.simplify full (get_rulify (Thm.sign_of_thm thm)) thm
wenzelm@11897
   141
  |> Drule.forall_elim_vars_safe |> Drule.strip_shyps_warning |> Drule.zero_var_indexes;
wenzelm@11897
   142
wenzelm@11897
   143
val rulify = gen_rulify true;
wenzelm@11897
   144
val rulify_no_asm = gen_rulify false;
wenzelm@11897
   145
wenzelm@11897
   146
fun rule_format x = Drule.rule_attribute (fn _ => rulify) x;
wenzelm@11897
   147
fun rule_format_no_asm x = Drule.rule_attribute (fn _ => rulify_no_asm) x;
wenzelm@11897
   148
wenzelm@11897
   149
wenzelm@11897
   150
wenzelm@11897
   151
(** theory setup **)
wenzelm@11897
   152
wenzelm@11897
   153
val setup = [ObjectLogicData.init];
wenzelm@11897
   154
wenzelm@11897
   155
wenzelm@11897
   156
end;