src/Pure/Isar/object_logic.ML
changeset 11897 b9f2028f53bd
child 12123 739eba13e2cd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Pure/Isar/object_logic.ML	Mon Oct 22 18:07:53 2001 +0200
     1.3 @@ -0,0 +1,156 @@
     1.4 +(*  Title:      Pure/Isar/object_logic.ML
     1.5 +    ID:         $Id$
     1.6 +    Author:     Markus Wenzel, TU Muenchen
     1.7 +    License:    GPL (GNU GENERAL PUBLIC LICENSE)
     1.8 +
     1.9 +Specifics about common object-logics.
    1.10 +*)
    1.11 +
    1.12 +signature OBJECT_LOGIC =
    1.13 +sig
    1.14 +  val add_judgment: bstring * string * mixfix -> theory -> theory
    1.15 +  val add_judgment_i: bstring * typ * mixfix -> theory -> theory
    1.16 +  val judgment_name: Sign.sg -> string
    1.17 +  val is_judgment: Sign.sg -> term -> bool
    1.18 +  val drop_judgment: Sign.sg -> term -> term
    1.19 +  val fixed_judgment: Sign.sg -> string -> term
    1.20 +  val declare_atomize: theory attribute
    1.21 +  val declare_rulify: theory attribute
    1.22 +  val atomize_tac: int -> tactic
    1.23 +  val atomize_goal: int -> thm -> thm
    1.24 +  val rulify: thm -> thm
    1.25 +  val rulify_no_asm: thm -> thm
    1.26 +  val rule_format: 'a attribute
    1.27 +  val rule_format_no_asm: 'a attribute
    1.28 +  val setup: (theory -> theory) list
    1.29 +end;
    1.30 +
    1.31 +structure ObjectLogic: OBJECT_LOGIC =
    1.32 +struct
    1.33 +
    1.34 +
    1.35 +(** object-logic theory data **)
    1.36 +
    1.37 +(* data kind 'Pure/object-logic' *)
    1.38 +
    1.39 +structure ObjectLogicDataArgs =
    1.40 +struct
    1.41 +  val name = "Pure/object-logic";
    1.42 +  type T = string option * (thm list * thm list);
    1.43 +
    1.44 +  val empty = (None, ([], [Drule.norm_hhf_eq]));
    1.45 +  val copy = I;
    1.46 +  val prep_ext = I;
    1.47 +
    1.48 +  fun merge_judgment (Some x, Some y) =
    1.49 +        if x = y then Some x else error "Attempt to merge different object-logics"
    1.50 +    | merge_judgment (j1, j2) = if is_some j1 then j1 else j2;
    1.51 +
    1.52 +  fun merge ((judgment1, (atomize1, rulify1)), (judgment2, (atomize2, rulify2))) =
    1.53 +    (merge_judgment (judgment1, judgment2),
    1.54 +      (Drule.merge_rules (atomize1, atomize2), Drule.merge_rules (rulify1, rulify2)));
    1.55 +
    1.56 +  fun print _ _ = ();
    1.57 +end;
    1.58 +
    1.59 +structure ObjectLogicData = TheoryDataFun(ObjectLogicDataArgs);
    1.60 +
    1.61 +
    1.62 +(** generic treatment of judgments -- with a single argument only **)
    1.63 +
    1.64 +(* add_judgment(_i) *)
    1.65 +
    1.66 +local
    1.67 +
    1.68 +fun new_judgment name (None, rules) = (Some name, rules)
    1.69 +  | new_judgment _ (Some _, _) = error "Attempt to redeclare object-logic judgment";
    1.70 +
    1.71 +fun gen_add_judgment add_consts (name, T, syn) thy =
    1.72 +  thy
    1.73 +  |> add_consts [(name, T, syn)]
    1.74 +  |> ObjectLogicData.map (new_judgment (Sign.full_name (Theory.sign_of thy) name));
    1.75 +
    1.76 +in
    1.77 +
    1.78 +val add_judgment = gen_add_judgment Theory.add_consts;
    1.79 +val add_judgment_i = gen_add_judgment Theory.add_consts_i;
    1.80 +
    1.81 +end;
    1.82 +
    1.83 +
    1.84 +(* term operations *)
    1.85 +
    1.86 +fun judgment_name sg =
    1.87 +  (case ObjectLogicData.get_sg sg of
    1.88 +    (Some name, _) => name
    1.89 +  | _ => raise TERM ("Unknown object-logic judgment", []));
    1.90 +
    1.91 +fun is_judgment sg (Const (c, _) $ _) = c = judgment_name sg
    1.92 +  | is_judgment _ _ = false;
    1.93 +
    1.94 +fun drop_judgment sg (Abs (x, T, t)) = Abs (x, T, drop_judgment sg t)
    1.95 +  | drop_judgment sg (tm as (Const (c, _) $ t)) = if c = judgment_name sg then t else tm
    1.96 +  | drop_judgment _ tm = tm;
    1.97 +
    1.98 +fun fixed_judgment sg x =
    1.99 +  let  (*be robust wrt. low-level errors*)
   1.100 +    val c = judgment_name sg;
   1.101 +    val aT = TFree ("'a", logicS);
   1.102 +    val T =
   1.103 +      if_none (Sign.const_type sg c) (aT --> propT)
   1.104 +      |> Term.map_type_tvar (fn ((x, _), S) => TFree (x, S));
   1.105 +    val U = Term.domain_type T handle Match => aT;
   1.106 +  in Const (c, T) $ Free (x, U) end;
   1.107 +
   1.108 +
   1.109 +
   1.110 +(** treatment of meta-level connectives **)
   1.111 +
   1.112 +(* maintain rules *)
   1.113 +
   1.114 +val get_atomize = #1 o #2 o ObjectLogicData.get_sg;
   1.115 +val get_rulify = #2 o #2 o ObjectLogicData.get_sg;
   1.116 +
   1.117 +val add_atomize = ObjectLogicData.map o Library.apsnd o Library.apfst o Drule.add_rules;
   1.118 +val add_rulify = ObjectLogicData.map o Library.apsnd o Library.apsnd o Drule.add_rules;
   1.119 +
   1.120 +fun declare_atomize (thy, th) = (add_atomize [th] thy, th);
   1.121 +fun declare_rulify (thy, th) = (add_rulify [th] thy, th);
   1.122 +
   1.123 +
   1.124 +(* atomize *)
   1.125 +
   1.126 +fun rewrite_prems_tac rews i = PRIMITIVE (MetaSimplifier.fconv_rule
   1.127 +  (MetaSimplifier.goals_conv (Library.equal i)
   1.128 +    (MetaSimplifier.forall_conv
   1.129 +      (MetaSimplifier.goals_conv (K true) (Tactic.rewrite true rews)))));
   1.130 +
   1.131 +fun atomize_tac i st =
   1.132 +  if Logic.has_meta_prems (#prop (Thm.rep_thm st)) i then
   1.133 +    (rewrite_prems_tac (get_atomize (Thm.sign_of_thm st)) i) st
   1.134 +  else all_tac st;
   1.135 +
   1.136 +fun atomize_goal i st =
   1.137 +  (case Seq.pull (atomize_tac i st) of None => st | Some (st', _) => st');
   1.138 +
   1.139 +
   1.140 +(* rulify *)
   1.141 +
   1.142 +fun gen_rulify full thm =
   1.143 +  Tactic.simplify full (get_rulify (Thm.sign_of_thm thm)) thm
   1.144 +  |> Drule.forall_elim_vars_safe |> Drule.strip_shyps_warning |> Drule.zero_var_indexes;
   1.145 +
   1.146 +val rulify = gen_rulify true;
   1.147 +val rulify_no_asm = gen_rulify false;
   1.148 +
   1.149 +fun rule_format x = Drule.rule_attribute (fn _ => rulify) x;
   1.150 +fun rule_format_no_asm x = Drule.rule_attribute (fn _ => rulify_no_asm) x;
   1.151 +
   1.152 +
   1.153 +
   1.154 +(** theory setup **)
   1.155 +
   1.156 +val setup = [ObjectLogicData.init];
   1.157 +
   1.158 +
   1.159 +end;