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