UnusedQuotMain.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Tue, 01 Dec 2009 12:16:45 +0100
changeset 466 42082fc00903
parent 399 646bfe5905b3
child 467 5ca4a927d7f0
permissions -rw-r--r--
Cleaning 'aps'.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
466
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
     1
(* Code for getting the goal *)
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
     2
apply (tactic {* (ObjectLogic.full_atomize_tac THEN' gen_frees_tac @{context}) 1 *})
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
     3
ML_prf {* val qtm = #concl (fst (Subgoal.focus @{context} 1 (#goal (Isar.goal ())))) *}
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
     4
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
     5
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
     6
ML {*
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
     7
fun repeat_eqsubst_thm ctxt thms thm =
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
     8
  repeat_eqsubst_thm ctxt thms (eqsubst_thm ctxt thms thm)
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
     9
  handle _ => thm
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    10
*}
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    11
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    12
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    13
ML {*
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    14
fun eqsubst_prop ctxt thms t =
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    15
  let
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    16
    val goalstate = Goal.init (cterm_of (ProofContext.theory_of ctxt) t)
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    17
    val a' = case (SINGLE (EqSubst.eqsubst_tac ctxt [0] thms 1) goalstate) of
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    18
      NONE => error "eqsubst_prop"
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    19
    | SOME th => cprem_of th 1
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    20
  in term_of a' end
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    21
*}
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    22
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    23
ML {*
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    24
  fun repeat_eqsubst_prop ctxt thms t =
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    25
    repeat_eqsubst_prop ctxt thms (eqsubst_prop ctxt thms t)
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    26
    handle _ => t
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    27
*}
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
    28
379
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    29
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    30
text {* tyRel takes a type and builds a relation that a quantifier over this
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    31
  type needs to respect. *}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    32
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    33
fun tyRel ty rty rel lthy =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    34
  if Sign.typ_instance (ProofContext.theory_of lthy) (ty, rty)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    35
  then rel
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    36
  else (case ty of
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    37
          Type (s, tys) =>
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    38
            let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    39
              val tys_rel = map (fn ty => ty --> ty --> @{typ bool}) tys;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    40
              val ty_out = ty --> ty --> @{typ bool};
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    41
              val tys_out = tys_rel ---> ty_out;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    42
            in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    43
            (case (maps_lookup (ProofContext.theory_of lthy) s) of
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    44
               SOME (info) => list_comb (Const (#relfun info, tys_out),
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    45
                              map (fn ty => tyRel ty rty rel lthy) tys)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    46
             | NONE  => HOLogic.eq_const ty
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    47
            )
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    48
            end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    49
        | _ => HOLogic.eq_const ty)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    50
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    51
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    52
(* 
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    53
ML {* cterm_of @{theory} 
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    54
  (tyRel @{typ "'a \<Rightarrow> 'a list \<Rightarrow> 't \<Rightarrow> 't"} (Logic.varifyT @{typ "'a list"}) 
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    55
         @{term "f::('a list \<Rightarrow> 'a list \<Rightarrow> bool)"} @{context}) 
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    56
*} 
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    57
*)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    58
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    59
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    60
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    61
fun mk_babs ty ty' = Const (@{const_name "Babs"}, [ty' --> @{typ bool}, ty] ---> ty)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    62
fun mk_ball ty = Const (@{const_name "Ball"}, [ty, ty] ---> @{typ bool})
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    63
fun mk_bex ty = Const (@{const_name "Bex"}, [ty, ty] ---> @{typ bool})
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    64
fun mk_resp ty = Const (@{const_name Respects}, [[ty, ty] ---> @{typ bool}, ty] ---> @{typ bool})
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    65
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    66
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    67
(* applies f to the subterm of an abstractions, otherwise to the given term *)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    68
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    69
fun apply_subt f trm =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    70
  case trm of
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    71
    Abs (x, T, t) => 
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    72
       let 
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    73
         val (x', t') = Term.dest_abs (x, T, t)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    74
       in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    75
         Term.absfree (x', T, f t') 
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    76
       end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    77
  | _ => f trm
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    78
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    79
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    80
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    81
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    82
(* FIXME: if there are more than one quotient, then you have to look up the relation *)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    83
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    84
fun my_reg lthy rel rty trm =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    85
  case trm of
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    86
    Abs (x, T, t) =>
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    87
       if (needs_lift rty T) then
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    88
         let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    89
            val rrel = tyRel T rty rel lthy
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    90
         in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    91
           (mk_babs (fastype_of trm) T) $ (mk_resp T $ rrel) $ (apply_subt (my_reg lthy rel rty) trm)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    92
         end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    93
       else
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    94
         Abs(x, T, (apply_subt (my_reg lthy rel rty) t))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    95
  | Const (@{const_name "All"}, ty) $ (t as Abs (x, T, _)) =>
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    96
       let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    97
          val ty1 = domain_type ty
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    98
          val ty2 = domain_type ty1
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    99
          val rrel = tyRel T rty rel lthy
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   100
       in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   101
         if (needs_lift rty T) then
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   102
           (mk_ball ty1) $ (mk_resp ty2 $ rrel) $ (apply_subt (my_reg lthy rel rty) t)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   103
         else
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   104
           Const (@{const_name "All"}, ty) $ apply_subt (my_reg lthy rel rty) t
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   105
       end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   106
  | Const (@{const_name "Ex"}, ty) $ (t as Abs (x, T, _)) =>
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   107
       let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   108
          val ty1 = domain_type ty
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   109
          val ty2 = domain_type ty1
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   110
          val rrel = tyRel T rty rel lthy
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   111
       in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   112
         if (needs_lift rty T) then
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   113
           (mk_bex ty1) $ (mk_resp ty2 $ rrel) $ (apply_subt (my_reg lthy rel rty) t)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   114
         else
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   115
           Const (@{const_name "Ex"}, ty) $ apply_subt (my_reg lthy rel rty) t
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   116
       end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   117
  | Const (@{const_name "op ="}, ty) $ t =>
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   118
      if needs_lift rty (fastype_of t) then
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   119
        (tyRel (fastype_of t) rty rel lthy) $ t   (* FIXME: t should be regularised too *)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   120
      else Const (@{const_name "op ="}, ty) $ (my_reg lthy rel rty t)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   121
  | t1 $ t2 => (my_reg lthy rel rty t1) $ (my_reg lthy rel rty t2)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   122
  | _ => trm
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   123
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   124
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   125
(* For polymorphic types we need to find the type of the Relation term. *)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   126
(* TODO: we assume that the relation is a Constant. Is this always true? *)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   127
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   128
fun my_reg_inst lthy rel rty trm =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   129
  case rel of
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   130
    Const (n, _) => Syntax.check_term lthy
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   131
      (my_reg lthy (Const (n, dummyT)) (Logic.varifyT rty) trm)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   132
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   133
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   134
(*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   135
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   136
  val r = Free ("R", dummyT);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   137
  val t = (my_reg_inst @{context} r @{typ "'a list"} @{term "\<forall>(x::'b list). P x"});
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   138
  val t2 = Syntax.check_term @{context} t;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   139
  cterm_of @{theory} t2
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   140
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   141
*)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   142
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   143
text {* Assumes that the given theorem is atomized *}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   144
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   145
  fun build_regularize_goal thm rty rel lthy =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   146
     Logic.mk_implies
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   147
       ((prop_of thm),
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   148
       (my_reg_inst lthy rel rty (prop_of thm)))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   149
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   150
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   151
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   152
fun regularize thm rty rel rel_eqv rel_refl lthy =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   153
  let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   154
    val goal = build_regularize_goal thm rty rel lthy;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   155
    fun tac ctxt =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   156
      (ObjectLogic.full_atomize_tac) THEN'
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   157
      REPEAT_ALL_NEW (FIRST' [
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   158
        rtac rel_refl,
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   159
        atac,
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   160
        rtac @{thm universal_twice},
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   161
        (rtac @{thm impI} THEN' atac),
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   162
        rtac @{thm implication_twice},
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   163
        EqSubst.eqsubst_tac ctxt [0]
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   164
          [(@{thm equiv_res_forall} OF [rel_eqv]),
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   165
           (@{thm equiv_res_exists} OF [rel_eqv])],
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   166
        (* For a = b \<longrightarrow> a \<approx> b *)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   167
        (rtac @{thm impI} THEN' (asm_full_simp_tac HOL_ss) THEN' rtac rel_refl),
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   168
        (rtac @{thm RIGHT_RES_FORALL_REGULAR})
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   169
      ]);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   170
    val cthm = Goal.prove lthy [] [] goal
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   171
      (fn {context, ...} => tac context 1);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   172
  in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   173
    cthm OF [thm]
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   174
  end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   175
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   176
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   177
(*consts Rl :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   178
axioms Rl_eq: "EQUIV Rl"
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   179
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   180
quotient ql = "'a list" / "Rl"
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   181
  by (rule Rl_eq)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   182
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   183
  ctyp_of @{theory} (exchange_ty @{context} (Logic.varifyT @{typ "'a list"}) (Logic.varifyT @{typ "'a ql"}) @{typ "nat list \<Rightarrow> (nat \<times> nat) list"});
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   184
  ctyp_of @{theory} (exchange_ty @{context} (Logic.varifyT @{typ "nat \<times> nat"}) (Logic.varifyT @{typ "int"}) @{typ "nat list \<Rightarrow> (nat \<times> nat) list"})
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   185
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   186
*)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   187
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   188
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   189
(* returns all subterms where two types differ *)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   190
fun diff (T, S) Ds =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   191
  case (T, S) of
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   192
    (TVar v, TVar u) => if v = u then Ds else (T, S)::Ds 
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   193
  | (TFree x, TFree y) => if x = y then Ds else (T, S)::Ds
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   194
  | (Type (a, Ts), Type (b, Us)) => 
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   195
      if a = b then diffs (Ts, Us) Ds else (T, S)::Ds
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   196
  | _ => (T, S)::Ds
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   197
and diffs (T::Ts, U::Us) Ds = diffs (Ts, Us) (diff (T, U) Ds)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   198
  | diffs ([], []) Ds = Ds
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   199
  | diffs _ _ = error "Unequal length of type arguments"
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   200
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   201
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   202
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   203
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   204
fun build_repabs_term lthy thm consts rty qty =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   205
  let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   206
    (* TODO: The rty and qty stored in the quotient_info should
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   207
       be varified, so this will soon not be needed *)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   208
    val rty = Logic.varifyT rty;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   209
    val qty = Logic.varifyT qty;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   210
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   211
  fun mk_abs tm =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   212
    let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   213
      val ty = fastype_of tm
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   214
    in Syntax.check_term lthy ((get_fun_OLD absF (rty, qty) lthy ty) $ tm) end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   215
  fun mk_repabs tm =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   216
    let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   217
      val ty = fastype_of tm
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   218
    in Syntax.check_term lthy ((get_fun_OLD repF (rty, qty) lthy ty) $ (mk_abs tm)) end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   219
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   220
    fun is_lifted_const (Const (x, _)) = member (op =) consts x
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   221
      | is_lifted_const _ = false;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   222
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   223
    fun build_aux lthy tm =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   224
      case tm of
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   225
        Abs (a as (_, vty, _)) =>
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   226
          let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   227
            val (vs, t) = Term.dest_abs a;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   228
            val v = Free(vs, vty);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   229
            val t' = lambda v (build_aux lthy t)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   230
          in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   231
            if (not (needs_lift rty (fastype_of tm))) then t'
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   232
            else mk_repabs (
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   233
              if not (needs_lift rty vty) then t'
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   234
              else
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   235
                let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   236
                  val v' = mk_repabs v;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   237
                  (* TODO: I believe 'beta' is not needed any more *)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   238
                  val t1 = (* Envir.beta_norm *) (t' $ v')
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   239
                in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   240
                  lambda v t1
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   241
                end)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   242
          end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   243
      | x =>
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   244
        case Term.strip_comb tm of
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   245
          (Const(@{const_name Respects}, _), _) => tm
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   246
        | (opp, tms0) =>
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   247
          let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   248
            val tms = map (build_aux lthy) tms0
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   249
            val ty = fastype_of tm
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   250
          in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   251
            if (is_lifted_const opp andalso needs_lift rty ty) then
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   252
            mk_repabs (list_comb (opp, tms))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   253
            else if ((Term.is_Free opp) andalso (length tms > 0) andalso (needs_lift rty ty)) then
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   254
              mk_repabs (list_comb (opp, tms))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   255
            else if tms = [] then opp
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   256
            else list_comb(opp, tms)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   257
          end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   258
  in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   259
    repeat_eqsubst_prop lthy @{thms id_def_sym}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   260
      (build_aux lthy (Thm.prop_of thm))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   261
  end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   262
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   263
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   264
text {* Builds provable goals for regularized theorems *}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   265
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   266
fun build_repabs_goal ctxt thm cons rty qty =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   267
  Logic.mk_equals ((Thm.prop_of thm), (build_repabs_term ctxt thm cons rty qty))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   268
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   269
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   270
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   271
fun repabs lthy thm consts rty qty quot_thm reflex_thm trans_thm rsp_thms =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   272
  let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   273
    val rt = build_repabs_term lthy thm consts rty qty;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   274
    val rg = Logic.mk_equals ((Thm.prop_of thm), rt);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   275
    fun tac ctxt = (ObjectLogic.full_atomize_tac) THEN'
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   276
      (REPEAT_ALL_NEW (r_mk_comb_tac ctxt rty quot_thm reflex_thm trans_thm rsp_thms));
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   277
    val cthm = Goal.prove lthy [] [] rg (fn x => tac (#context x) 1);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   278
  in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   279
    @{thm Pure.equal_elim_rule1} OF [cthm, thm]
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   280
  end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   281
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   282
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   283
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   284
(* TODO: Check if it behaves properly with varifyed rty *)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   285
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   286
fun findabs_all rty tm =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   287
  case tm of
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   288
    Abs(_, T, b) =>
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   289
      let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   290
        val b' = subst_bound ((Free ("x", T)), b);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   291
        val tys = findabs_all rty b'
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   292
        val ty = fastype_of tm
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   293
      in if needs_lift rty ty then (ty :: tys) else tys
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   294
      end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   295
  | f $ a => (findabs_all rty f) @ (findabs_all rty a)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   296
  | _ => [];
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   297
fun findabs rty tm = distinct (op =) (findabs_all rty tm)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   298
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   299
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   300
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   301
(* Currently useful only for LAMBDA_PRS *)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   302
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   303
fun make_simp_prs_thm lthy quot_thm thm typ =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   304
  let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   305
    val (_, [lty, rty]) = dest_Type typ;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   306
    val thy = ProofContext.theory_of lthy;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   307
    val (lcty, rcty) = (ctyp_of thy lty, ctyp_of thy rty)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   308
    val inst = [SOME lcty, NONE, SOME rcty];
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   309
    val lpi = Drule.instantiate' inst [] thm;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   310
    val tac =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   311
      (compose_tac (false, lpi, 2)) THEN_ALL_NEW
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   312
      (quotient_tac quot_thm);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   313
    val gc = Drule.strip_imp_concl (cprop_of lpi);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   314
    val t = Goal.prove_internal [] gc (fn _ => tac 1)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   315
  in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   316
    MetaSimplifier.rewrite_rule [@{thm eq_reflection} OF @{thms id_apply}] t
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   317
  end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   318
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   319
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   320
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   321
fun findallex_all rty qty tm =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   322
  case tm of
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   323
    Const (@{const_name All}, T) $ (s as (Abs(_, _, b))) =>
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   324
      let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   325
        val (tya, tye) = findallex_all rty qty s
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   326
      in if needs_lift rty T then
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   327
        ((T :: tya), tye)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   328
      else (tya, tye) end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   329
  | Const (@{const_name Ex}, T) $ (s as (Abs(_, _, b))) =>
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   330
      let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   331
        val (tya, tye) = findallex_all rty qty s
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   332
      in if needs_lift rty T then
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   333
        (tya, (T :: tye))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   334
      else (tya, tye) end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   335
  | Abs(_, T, b) =>
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   336
      findallex_all rty qty (subst_bound ((Free ("x", T)), b))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   337
  | f $ a =>
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   338
      let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   339
        val (a1, e1) = findallex_all rty qty f;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   340
        val (a2, e2) = findallex_all rty qty a;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   341
      in (a1 @ a2, e1 @ e2) end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   342
  | _ => ([], []);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   343
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   344
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   345
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   346
fun findallex lthy rty qty tm =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   347
  let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   348
    val (a, e) = findallex_all rty qty tm;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   349
    val (ad, ed) = (map domain_type a, map domain_type e);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   350
    val (au, eu) = (distinct (op =) ad, distinct (op =) ed);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   351
    val (rty, qty) = (Logic.varifyT rty, Logic.varifyT qty)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   352
  in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   353
    (map (exchange_ty lthy rty qty) au, map (exchange_ty lthy rty qty) eu)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   354
  end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   355
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   356
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   357
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   358
fun make_allex_prs_thm lthy quot_thm thm typ =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   359
  let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   360
    val (_, [lty, rty]) = dest_Type typ;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   361
    val thy = ProofContext.theory_of lthy;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   362
    val (lcty, rcty) = (ctyp_of thy lty, ctyp_of thy rty)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   363
    val inst = [NONE, SOME lcty];
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   364
    val lpi = Drule.instantiate' inst [] thm;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   365
    val tac =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   366
      (compose_tac (false, lpi, 1)) THEN_ALL_NEW
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   367
      (quotient_tac quot_thm);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   368
    val gc = Drule.strip_imp_concl (cprop_of lpi);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   369
    val t = Goal.prove_internal [] gc (fn _ => tac 1)
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   370
    val t_noid = MetaSimplifier.rewrite_rule
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   371
      [@{thm eq_reflection} OF @{thms id_apply}] t;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   372
    val t_sym = @{thm "HOL.sym"} OF [t_noid];
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   373
    val t_eq = @{thm "eq_reflection"} OF [t_sym]
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   374
  in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   375
    t_eq
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   376
  end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   377
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   378
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   379
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   380
fun lift_thm lthy qty qty_name rsp_thms defs rthm = 
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   381
let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   382
  val _ = tracing ("raw theorem:\n" ^ Syntax.string_of_term lthy (prop_of rthm))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   383
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   384
  val (rty, rel, rel_refl, rel_eqv) = lookup_quot_data lthy qty;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   385
  val (trans2, reps_same, absrep, quot) = lookup_quot_thms lthy qty_name;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   386
  val consts = lookup_quot_consts defs;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   387
  val t_a = atomize_thm rthm;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   388
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   389
  val _ = tracing ("raw atomized theorem:\n" ^ Syntax.string_of_term lthy (prop_of t_a))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   390
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   391
  val t_r = regularize t_a rty rel rel_eqv rel_refl lthy;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   392
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   393
  val _ = tracing ("regularised theorem:\n" ^ Syntax.string_of_term lthy (prop_of t_r))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   394
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   395
  val t_t = repabs lthy t_r consts rty qty quot rel_refl trans2 rsp_thms;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   396
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   397
  val _ = tracing ("rep/abs injected theorem:\n" ^ Syntax.string_of_term lthy (prop_of t_t))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   398
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   399
  val (alls, exs) = findallex lthy rty qty (prop_of t_a);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   400
  val allthms = map (make_allex_prs_thm lthy quot @{thm FORALL_PRS}) alls
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   401
  val exthms = map (make_allex_prs_thm lthy quot @{thm EXISTS_PRS}) exs
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   402
  val t_a = MetaSimplifier.rewrite_rule (allthms @ exthms) t_t
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   403
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   404
  val _ = tracing ("??:\n" ^ Syntax.string_of_term lthy (prop_of t_a))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   405
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   406
  val abs = findabs rty (prop_of t_a);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   407
  val aps = findaps rty (prop_of t_a);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   408
  val app_prs_thms = map (applic_prs lthy rty qty absrep) aps;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   409
  val lam_prs_thms = map (make_simp_prs_thm lthy quot @{thm LAMBDA_PRS}) abs;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   410
  val t_l = repeat_eqsubst_thm lthy (lam_prs_thms @ app_prs_thms) t_a;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   411
  
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   412
  val _ = tracing ("??:\n" ^ Syntax.string_of_term lthy (prop_of t_l))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   413
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   414
  val defs_sym = flat (map (add_lower_defs lthy) defs);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   415
  val defs_sym_eq = map (fn x => eq_reflection OF [x]) defs_sym;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   416
  val t_id = simp_ids lthy t_l;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   417
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   418
  val _ = tracing ("??:\n" ^ Syntax.string_of_term lthy (prop_of t_id))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   419
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   420
  val t_d0 = MetaSimplifier.rewrite_rule defs_sym_eq t_id;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   421
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   422
  val _ = tracing ("??:\n" ^ Syntax.string_of_term lthy (prop_of t_d0))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   423
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   424
  val t_d = repeat_eqsubst_thm lthy defs_sym t_d0;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   425
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   426
  val _ = tracing ("??:\n" ^ Syntax.string_of_term lthy (prop_of t_d))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   427
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   428
  val t_r = MetaSimplifier.rewrite_rule [reps_same] t_d;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   429
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   430
  val _ = tracing ("??:\n" ^ Syntax.string_of_term lthy (prop_of t_r))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   431
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   432
  val t_rv = ObjectLogic.rulify t_r
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   433
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   434
  val _ = tracing ("lifted theorem:\n" ^ Syntax.string_of_term lthy (prop_of t_rv))
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   435
in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   436
  Thm.varifyT t_rv
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   437
end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   438
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   439
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   440
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   441
fun lift_thm_note qty qty_name rsp_thms defs thm name lthy =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   442
  let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   443
    val lifted_thm = lift_thm lthy qty qty_name rsp_thms defs thm;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   444
    val (_, lthy2) = note (name, lifted_thm) lthy;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   445
  in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   446
    lthy2
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   447
  end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   448
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   449
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   450
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   451
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   452
fun regularize_goal lthy thm rel_eqv rel_refl qtrm =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   453
  let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   454
    val reg_trm = mk_REGULARIZE_goal lthy (prop_of thm) qtrm;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   455
    fun tac lthy = regularize_tac lthy rel_eqv rel_refl;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   456
    val cthm = Goal.prove lthy [] [] reg_trm
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   457
      (fn {context, ...} => tac context 1);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   458
  in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   459
    cthm OF [thm]
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   460
  end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   461
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   462
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   463
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   464
fun repabs_goal lthy thm rty quot_thm reflex_thm trans_thm rsp_thms qtrm =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   465
  let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   466
    val rg = Syntax.check_term lthy (mk_inj_REPABS_goal lthy ((prop_of thm), qtrm));
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   467
    fun tac ctxt = (ObjectLogic.full_atomize_tac) THEN'
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   468
      (REPEAT_ALL_NEW (r_mk_comb_tac ctxt rty quot_thm reflex_thm trans_thm rsp_thms));
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   469
    val cthm = Goal.prove lthy [] [] rg (fn x => tac (#context x) 1);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   470
  in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   471
    @{thm Pure.equal_elim_rule1} OF [cthm, thm]
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   472
  end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   473
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   474
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   475
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   476
ML {*
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   477
fun atomize_goal thy gl =
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   478
  let
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   479
    val vars = map Free (Term.add_frees gl []);
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   480
    val all = if fastype_of gl = @{typ bool} then HOLogic.all_const else Term.all;
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   481
    fun lambda_all (var as Free(_, T)) trm = (all T) $ lambda var trm;
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   482
    val glv = fold lambda_all vars gl
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   483
    val gla = (term_of o snd o Thm.dest_equals o cprop_of) (ObjectLogic.atomize (cterm_of thy glv))
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   484
    val glf = Type.legacy_freeze gla
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   485
  in
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   486
    if fastype_of gl = @{typ bool} then @{term Trueprop} $ glf else glf
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   487
  end
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   488
*}
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   489
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   490
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   491
ML {* atomize_goal @{theory} @{term "x memb [] = False"} *}
399
646bfe5905b3 tuned comments
Christian Urban <urbanc@in.tum.de>
parents: 381
diff changeset
   492
ML {* atomize_goal @{theory} @{term "x = xa ? a # x = a # xa"} *}
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   493
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   494
466
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   495
ML {*
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   496
fun applic_prs lthy absrep (rty, qty) =
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   497
  let
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   498
    fun mk_rep (T, T') tm = (Quotient_Def.get_fun repF lthy (T, T')) $ tm;
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   499
    fun mk_abs (T, T') tm = (Quotient_Def.get_fun absF lthy (T, T')) $ tm;
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   500
    val (raty, rgty) = Term.strip_type rty;
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   501
    val (qaty, qgty) = Term.strip_type qty;
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   502
    val vs = map (fn _ => "x") qaty;
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   503
    val ((fname :: vfs), lthy') = Variable.variant_fixes ("f" :: vs) lthy;
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   504
    val f = Free (fname, qaty ---> qgty);
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   505
    val args = map Free (vfs ~~ qaty);
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   506
    val rhs = list_comb(f, args);
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   507
    val largs = map2 mk_rep (raty ~~ qaty) args;
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   508
    val lhs = mk_abs (rgty, qgty) (list_comb((mk_rep (raty ---> rgty, qaty ---> qgty) f), largs));
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   509
    val llhs = Syntax.check_term lthy lhs;
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   510
    val eq = Logic.mk_equals (llhs, rhs);
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   511
    val ceq = cterm_of (ProofContext.theory_of lthy') eq;
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   512
    val sctxt = HOL_ss addsimps (@{thms fun_map.simps id_simps} @ absrep);
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   513
    val t = Goal.prove_internal [] ceq (fn _ => simp_tac sctxt 1)
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   514
    val t_id = MetaSimplifier.rewrite_rule @{thms id_simps} t;
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   515
  in
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   516
    singleton (ProofContext.export lthy' lthy) t_id
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   517
  end
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   518
*}
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   519
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   520
ML {*
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   521
fun find_aps_all rtm qtm =
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   522
  case (rtm, qtm) of
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   523
    (Abs(_, T1, s1), Abs(_, T2, s2)) =>
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   524
      find_aps_all (subst_bound ((Free ("x", T1)), s1)) (subst_bound ((Free ("x", T2)), s2))
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   525
  | (((f1 as (Free (_, T1))) $ a1), ((f2 as (Free (_, T2))) $ a2)) =>
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   526
      let
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   527
        val sub = (find_aps_all f1 f2) @ (find_aps_all a1 a2)
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   528
      in
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   529
        if T1 = T2 then sub else (T1, T2) :: sub
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   530
      end
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   531
  | ((f1 $ a1), (f2 $ a2)) => (find_aps_all f1 f2) @ (find_aps_all a1 a2)
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   532
  | _ => [];
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   533
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   534
fun find_aps rtm qtm = distinct (op =) (find_aps_all rtm qtm)
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   535
*}
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   536
42082fc00903 Cleaning 'aps'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 399
diff changeset
   537
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   538
379
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   539
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   540
fun lift_thm_goal lthy qty qty_name rsp_thms defs rthm goal =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   541
let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   542
  val (rty, rel, rel_refl, rel_eqv) = lookup_quot_data lthy qty;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   543
  val (trans2, reps_same, absrep, quot) = lookup_quot_thms lthy qty_name;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   544
  val t_a = atomize_thm rthm;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   545
  val goal_a = atomize_goal (ProofContext.theory_of lthy) goal;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   546
  val t_r = regularize_goal lthy t_a rel_eqv rel_refl goal_a;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   547
  val t_t = repabs_goal lthy t_r rty quot rel_refl trans2 rsp_thms goal_a;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   548
  val (alls, exs) = findallex lthy rty qty (prop_of t_a);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   549
  val allthms = map (make_allex_prs_thm lthy quot @{thm FORALL_PRS}) alls
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   550
  val exthms = map (make_allex_prs_thm lthy quot @{thm EXISTS_PRS}) exs
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   551
  val t_a = MetaSimplifier.rewrite_rule (allthms @ exthms) t_t
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   552
  val abs = findabs rty (prop_of t_a);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   553
  val aps = findaps rty (prop_of t_a);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   554
  val app_prs_thms = map (applic_prs lthy rty qty absrep) aps;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   555
  val lam_prs_thms = map (make_simp_prs_thm lthy quot @{thm LAMBDA_PRS}) abs;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   556
  val t_l = repeat_eqsubst_thm lthy (lam_prs_thms @ app_prs_thms) t_a;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   557
  val defs_sym = flat (map (add_lower_defs lthy) defs);
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   558
  val defs_sym_eq = map (fn x => eq_reflection OF [x]) defs_sym;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   559
  val t_id = simp_ids lthy t_l;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   560
  val t_d0 = MetaSimplifier.rewrite_rule defs_sym_eq t_id;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   561
  val t_d = repeat_eqsubst_thm lthy defs_sym t_d0;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   562
  val t_r = MetaSimplifier.rewrite_rule [reps_same] t_d;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   563
  val t_rv = ObjectLogic.rulify t_r
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   564
in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   565
  Thm.varifyT t_rv
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   566
end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   567
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   568
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   569
ML {*
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   570
fun lift_thm_goal_note lthy qty qty_name rsp_thms defs thm name goal =
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   571
  let
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   572
    val lifted_thm = lift_thm_goal lthy qty qty_name rsp_thms defs thm goal;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   573
    val (_, lthy2) = note (name, lifted_thm) lthy;
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   574
  in
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   575
    lthy2
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   576
  end
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   577
*}
57bde65f6eb2 Removed unused things from QuotMain.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   578
381
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   579
ML {*
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   580
fun simp_ids_trm trm =
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   581
  trm |>
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   582
  MetaSimplifier.rewrite false @{thms eq_reflection[OF FUN_MAP_I] eq_reflection[OF id_apply] id_def_sym prod_fun_id map_id}
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   583
  |> cprop_of |> Thm.dest_equals |> snd
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   584
991db758a72d More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 379
diff changeset
   585
*}