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