Quot/quotient_term.ML
author Christian Urban <urbanc@in.tum.de>
Sat, 26 Dec 2009 07:15:30 +0100
changeset 790 3a48ffcf0f9a
parent 786 d6407afb913c
child 791 fb4bfbb1a291
permissions -rw-r--r--
generalised absrep function; needs consolidation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
signature QUOTIENT_TERM =
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
sig
774
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
     3
   exception LIFT_MATCH of string
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
     4
 
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
     5
   datatype flag = absF | repF
776
d1064fa29424 renamed get_fun to absrep_fun; introduced explicit checked versions of the term functions
Christian Urban <urbanc@in.tum.de>
parents: 775
diff changeset
     6
   
d1064fa29424 renamed get_fun to absrep_fun; introduced explicit checked versions of the term functions
Christian Urban <urbanc@in.tum.de>
parents: 775
diff changeset
     7
   val absrep_fun: flag -> Proof.context -> (typ * typ) -> term
d1064fa29424 renamed get_fun to absrep_fun; introduced explicit checked versions of the term functions
Christian Urban <urbanc@in.tum.de>
parents: 775
diff changeset
     8
   val absrep_fun_chk: flag -> Proof.context -> (typ * typ) -> term
774
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
     9
775
Christian Urban <urbanc@in.tum.de>
parents: 774
diff changeset
    10
   val regularize_trm: Proof.context -> (term * term) -> term
776
d1064fa29424 renamed get_fun to absrep_fun; introduced explicit checked versions of the term functions
Christian Urban <urbanc@in.tum.de>
parents: 775
diff changeset
    11
   val regularize_trm_chk: Proof.context -> (term * term) -> term
d1064fa29424 renamed get_fun to absrep_fun; introduced explicit checked versions of the term functions
Christian Urban <urbanc@in.tum.de>
parents: 775
diff changeset
    12
   
774
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    13
   val inj_repabs_trm: Proof.context -> (term * term) -> term
776
d1064fa29424 renamed get_fun to absrep_fun; introduced explicit checked versions of the term functions
Christian Urban <urbanc@in.tum.de>
parents: 775
diff changeset
    14
   val inj_repabs_trm_chk: Proof.context -> (term * term) -> term
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
end;
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
structure Quotient_Term: QUOTIENT_TERM =
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
struct
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
762
baac4639ecef avoided global "open"s - replaced by local "open"s
Christian Urban <urbanc@in.tum.de>
parents: 761
diff changeset
    20
open Quotient_Info;
774
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    21
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    22
exception LIFT_MATCH of string
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    23
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
    24
(*******************************)
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
    25
(* Aggregate Rep/Abs Functions *)
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
    26
(*******************************)
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
    27
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
    28
(* The flag repF is for types in negative position, while absF is   *) 
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
    29
(* for types in positive position. Because of this, function types  *)
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
    30
(* need to be treated specially, since there the polarity changes.  *)
774
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    31
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    32
datatype flag = absF | repF
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    33
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    34
fun negF absF = repF
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    35
  | negF repF = absF
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    36
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    37
val mk_id = Const (@{const_name "id"}, dummyT)
774
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    38
fun mk_identity ty = Const (@{const_name "id"}, ty --> ty)
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    39
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    40
fun mk_Free (TVar ((x, i), _)) = Free (unprefix "'" x ^ string_of_int i, dummyT)
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    41
774
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    42
fun mk_compose flag (trm1, trm2) = 
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    43
  case flag of
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    44
    absF => Const (@{const_name "comp"}, dummyT) $ trm1 $ trm2
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    45
  | repF => Const (@{const_name "comp"}, dummyT) $ trm2 $ trm1
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    46
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    47
fun get_mapfun ctxt s =
774
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    48
let
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
    49
  val thy = ProofContext.theory_of ctxt
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    50
  val exc = LIFT_MATCH ("No map function for type " ^ (quote s) ^ " found.")
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    51
  val mapfun = #mapfun (maps_lookup thy s) handle NotFound => raise exc
774
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    52
in
784
da75568e7f12 renamed some fields in the info records
Christian Urban <urbanc@in.tum.de>
parents: 783
diff changeset
    53
  Const (mapfun, dummyT)
774
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    54
end
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    55
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    56
fun mk_mapfun ctxt vs ty =
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    57
let
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    58
  val vs' = map (mk_Free) vs
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    59
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    60
  fun mk_mapfun_aux ty =
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    61
    case ty of
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    62
      TVar _ => mk_Free ty
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    63
    | Type (_, []) => mk_id
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    64
    | Type (s, tys) => list_comb (get_mapfun ctxt s, map mk_mapfun_aux tys)
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    65
    | _ => raise LIFT_MATCH ("mk_mapfun_aux (default)")
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    66
in
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    67
  fold_rev Term.lambda vs' (mk_mapfun_aux ty)
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    68
end
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    69
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    70
fun get_rty_qty ctxt s =
774
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    71
let
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
    72
  val thy = ProofContext.theory_of ctxt
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    73
  val exc = LIFT_MATCH ("No quotient type " ^ (quote s) ^ " found.")
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    74
  val qdata = (quotdata_lookup thy s) handle NotFound => raise exc
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    75
in
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    76
  (#rtyp qdata, #qtyp qdata)
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    77
end
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    78
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    79
fun double_lookup rtyenv qtyenv v =
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    80
let
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    81
  val v' = fst (dest_TVar v)
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    82
in
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    83
  (snd (the (Vartab.lookup rtyenv v')), snd (the (Vartab.lookup qtyenv v')))
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    84
end
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    85
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    86
fun absrep_const flag ctxt qty_str =
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    87
let
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    88
  val thy = ProofContext.theory_of ctxt
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    89
  val qty_name = Long_Name.base_name qty_str
774
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    90
in
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    91
  case flag of
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    92
    absF => Const (Sign.full_bname thy ("abs_" ^ qty_name), dummyT)
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    93
  | repF => Const (Sign.full_bname thy ("rep_" ^ qty_name), dummyT)
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    94
end
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
    95
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
    96
fun absrep_fun flag ctxt (rty, qty) =
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    97
  if rty = qty  
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    98
  then mk_identity qty
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    99
  else
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   100
    case (rty, qty) of
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   101
      (Type ("fun", [ty1, ty2]), Type ("fun", [ty1', ty2'])) =>
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   102
        let
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   103
          val arg1 = absrep_fun (negF flag) ctxt (ty1, ty1')
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   104
          val arg2 = absrep_fun flag ctxt (ty2, ty2')
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   105
        in
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   106
          list_comb (get_mapfun ctxt "fun", [arg1, arg2])
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   107
        end
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   108
    | (Type (s, tys), Type (s', tys')) =>
774
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
   109
        if s = s'
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   110
        then 
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   111
           let
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   112
             val args = map (absrep_fun flag ctxt) (tys ~~ tys')
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   113
           in
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   114
             list_comb (get_mapfun ctxt s, args)
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   115
           end
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   116
        else
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   117
           let
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   118
             val thy = ProofContext.theory_of ctxt
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   119
             val (rty_pat, qty_pat as Type (_, vs)) = get_rty_qty ctxt s'
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   120
             val rtyenv = Sign.typ_match thy (rty_pat, rty) Vartab.empty
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   121
             val qtyenv = Sign.typ_match thy (qty_pat, qty) Vartab.empty
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   122
             val args_aux = map (double_lookup rtyenv qtyenv) vs            
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   123
             val args = map (absrep_fun flag ctxt) args_aux
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   124
             val map_fun = mk_mapfun ctxt vs rty_pat       
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   125
             val result = list_comb (map_fun, args) 
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   126
           in
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   127
             mk_compose flag (absrep_const flag ctxt s', result)
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   128
           end 
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   129
    | (TFree x, TFree x') =>
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   130
        if x = x'
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   131
        then mk_identity qty
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   132
        else raise (LIFT_MATCH "absrep_fun (frees)")
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   133
    | (TVar _, TVar _) => raise (LIFT_MATCH "absrep_fun (vars)")
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   134
    | _ => 
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   135
         let
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   136
           val rty_str = Syntax.string_of_typ ctxt rty
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   137
           val qty_str = Syntax.string_of_typ ctxt qty
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   138
         in
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   139
           raise (LIFT_MATCH ("absrep_fun (default) " ^ rty_str ^ " " ^ qty_str))
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   140
         end
774
b4ffb8826105 moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents: 762
diff changeset
   141
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   142
fun absrep_fun_chk flag ctxt (rty, qty) =
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   143
let
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   144
  val rty_str = Syntax.string_of_typ ctxt rty
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   145
  val qty_str = Syntax.string_of_typ ctxt qty
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   146
  val _ = tracing "rty / qty"
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   147
  val _ = tracing rty_str
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   148
  val _ = tracing qty_str
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   149
in
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   150
  absrep_fun flag ctxt (rty, qty)
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   151
  |> Syntax.check_term ctxt
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   152
end
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   153
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   154
(* Regularizing an rtrm means:
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
 
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   156
 - Quantifiers over types that need lifting are replaced 
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
   by bounded quantifiers, for example:
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   159
      All P  ----> All (Respects R) P
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   161
   where the aggregate relation R is given by the rty and qty;
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
 
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   163
 - Abstractions over types that need lifting are replaced
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   164
   by bounded abstractions, for example:
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
      
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   166
      %x. P  ----> Ball (Respects R) %x. P
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   168
 - Equalities over types that need lifting are replaced by
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   169
   corresponding equivalence relations, for example:
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   171
      A = B  ----> R A B
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
   or 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   175
      A = B  ----> (R ===> R) A B
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
   for more complicated types of A and B
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
*)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
783
06e17083e90b modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents: 782
diff changeset
   180
(* instantiates TVars so that the term is of type ty *)
06e17083e90b modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents: 782
diff changeset
   181
fun force_typ thy trm ty =
06e17083e90b modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents: 782
diff changeset
   182
let
06e17083e90b modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents: 782
diff changeset
   183
  val trm_ty = fastype_of trm
06e17083e90b modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents: 782
diff changeset
   184
  val ty_inst = Sign.typ_match thy (trm_ty, ty) Vartab.empty
06e17083e90b modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents: 782
diff changeset
   185
in
06e17083e90b modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents: 782
diff changeset
   186
  map_types (Envir.subst_type ty_inst) trm
06e17083e90b modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents: 782
diff changeset
   187
end
06e17083e90b modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents: 782
diff changeset
   188
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   189
(* builds the aggregate equivalence relation *)
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   190
(* that will be the argument of Respects     *)
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   191
fun mk_resp_arg ctxt (rty, qty) =
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
let
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   193
  val thy = ProofContext.theory_of ctxt
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
in  
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
  if rty = qty
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
  then HOLogic.eq_const rty
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
  else
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
    case (rty, qty) of
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
      (Type (s, tys), Type (s', tys')) =>
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
       if s = s' 
761
e2ac18492c68 small tuning
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
   201
       then 
e2ac18492c68 small tuning
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
   202
         let
785
Christian Urban <urbanc@in.tum.de>
parents: 784
diff changeset
   203
           val exc = LIFT_MATCH ("mk_resp_arg (no relation map function found for type " ^ s ^ ")") 
784
da75568e7f12 renamed some fields in the info records
Christian Urban <urbanc@in.tum.de>
parents: 783
diff changeset
   204
           val relmap = #relmap (maps_lookup thy s) handle NotFound => raise exc
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   205
           val args = map (mk_resp_arg ctxt) (tys ~~ tys')
761
e2ac18492c68 small tuning
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
   206
         in
784
da75568e7f12 renamed some fields in the info records
Christian Urban <urbanc@in.tum.de>
parents: 783
diff changeset
   207
           list_comb (Const (relmap, dummyT), args) 
761
e2ac18492c68 small tuning
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
   208
         end  
e2ac18492c68 small tuning
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
   209
       else 
784
da75568e7f12 renamed some fields in the info records
Christian Urban <urbanc@in.tum.de>
parents: 783
diff changeset
   210
         let
da75568e7f12 renamed some fields in the info records
Christian Urban <urbanc@in.tum.de>
parents: 783
diff changeset
   211
           val exc = LIFT_MATCH ("mk_resp_arg (no quotient found for type " ^ s ^ ")") 
786
d6407afb913c used Local_Theory.declaration for storing quotdata
Christian Urban <urbanc@in.tum.de>
parents: 785
diff changeset
   212
           val equiv_rel = #equiv_rel (quotdata_lookup thy s') handle NotFound => raise exc
761
e2ac18492c68 small tuning
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
   213
           (* FIXME: check in this case that the rty and qty *)
e2ac18492c68 small tuning
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
   214
           (* FIXME: correspond to each other *)
783
06e17083e90b modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents: 782
diff changeset
   215
06e17083e90b modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents: 782
diff changeset
   216
           (* we need to instantiate the TVars in the relation *)
06e17083e90b modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents: 782
diff changeset
   217
           val thy = ProofContext.theory_of ctxt 
784
da75568e7f12 renamed some fields in the info records
Christian Urban <urbanc@in.tum.de>
parents: 783
diff changeset
   218
           val forced_equiv_rel = force_typ thy equiv_rel (rty --> rty --> @{typ bool})
761
e2ac18492c68 small tuning
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
   219
         in
784
da75568e7f12 renamed some fields in the info records
Christian Urban <urbanc@in.tum.de>
parents: 783
diff changeset
   220
           forced_equiv_rel
761
e2ac18492c68 small tuning
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
   221
         end
783
06e17083e90b modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents: 782
diff changeset
   222
      | _ => HOLogic.eq_const rty
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
             (* FIXME: check that the types correspond to each other? *)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
end
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
val mk_babs = Const (@{const_name Babs}, dummyT)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
val mk_ball = Const (@{const_name Ball}, dummyT)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
val mk_bex  = Const (@{const_name Bex}, dummyT)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
val mk_resp = Const (@{const_name Respects}, dummyT)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
(* - applies f to the subterm of an abstraction,   *)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
(*   otherwise to the given term,                  *)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
(* - used by regularize, therefore abstracted      *)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
(*   variables do not have to be treated specially *)
775
Christian Urban <urbanc@in.tum.de>
parents: 774
diff changeset
   235
fun apply_subt f (trm1, trm2) =
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
  case (trm1, trm2) of
775
Christian Urban <urbanc@in.tum.de>
parents: 774
diff changeset
   237
    (Abs (x, T, t), Abs (_ , _, t')) => Abs (x, T, f (t, t'))
Christian Urban <urbanc@in.tum.de>
parents: 774
diff changeset
   238
  | _ => f (trm1, trm2)
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
(* the major type of All and Ex quantifiers *)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
fun qnt_typ ty = domain_type (domain_type ty)  
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
(* produces a regularized version of rtrm       *)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
(*                                              *)
785
Christian Urban <urbanc@in.tum.de>
parents: 784
diff changeset
   246
(* - the result might contain dummyTs           *)
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
(*                                              *)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
(* - for regularisation we do not need any      *)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
(*   special treatment of bound variables       *)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   251
fun regularize_trm ctxt (rtrm, qtrm) =
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   252
  case (rtrm, qtrm) of
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   253
    (Abs (x, ty, t), Abs (_, ty', t')) =>
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
       let
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   255
         val subtrm = Abs(x, ty, regularize_trm ctxt (t, t'))
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
       in
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   257
         if ty = ty' then subtrm
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   258
         else mk_babs $ (mk_resp $ mk_resp_arg ctxt (ty, ty')) $ subtrm
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
       end
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   260
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   261
  | (Const (@{const_name "All"}, ty) $ t, Const (@{const_name "All"}, ty') $ t') =>
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   262
       let
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   263
         val subtrm = apply_subt (regularize_trm ctxt) (t, t')
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   264
       in
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
         if ty = ty' then Const (@{const_name "All"}, ty) $ subtrm
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   266
         else mk_ball $ (mk_resp $ mk_resp_arg ctxt (qnt_typ ty, qnt_typ ty')) $ subtrm
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   267
       end
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   269
  | (Const (@{const_name "Ex"}, ty) $ t, Const (@{const_name "Ex"}, ty') $ t') =>
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   270
       let
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   271
         val subtrm = apply_subt (regularize_trm ctxt) (t, t')
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   272
       in
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
         if ty = ty' then Const (@{const_name "Ex"}, ty) $ subtrm
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   274
         else mk_bex $ (mk_resp $ mk_resp_arg ctxt (qnt_typ ty, qnt_typ ty')) $ subtrm
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   275
       end
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   276
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
  | (* equalities need to be replaced by appropriate equivalence relations *) 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   278
    (Const (@{const_name "op ="}, ty), Const (@{const_name "op ="}, ty')) =>
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   279
         if ty = ty' then rtrm
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   280
         else mk_resp_arg ctxt (domain_type ty, domain_type ty') 
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   282
  | (* in this case we just check whether the given equivalence relation is correct *) 
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   283
    (rel, Const (@{const_name "op ="}, ty')) =>
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   284
       let 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
         val exc = LIFT_MATCH "regularise (relation mismatch)"
785
Christian Urban <urbanc@in.tum.de>
parents: 784
diff changeset
   286
         val rel_ty = fastype_of rel
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   287
         val rel' = mk_resp_arg ctxt (domain_type rel_ty, domain_type ty') 
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   288
       in 
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   289
         if rel' aconv rel then rtrm else raise exc
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   290
       end  
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   291
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   292
  | (_, Const _) =>
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   293
       let 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   294
         fun same_name (Const (s, T)) (Const (s', T')) = (s = s') (*andalso (T = T')*)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   295
           | same_name _ _ = false
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   296
          (* TODO/FIXME: This test is not enough. *) 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   297
          (*             Why?                     *)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   298
          (* Because constants can have the same name but not be the same
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   299
             constant.  All overloaded constants have the same name but because
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   300
             of different types they do differ.
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   301
        
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   302
             This code will let one write a theorem where plus on nat is
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   303
             matched to plus on int, even if the latter is defined differently.
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   304
    
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   305
             This would result in hard to understand failures in injection and
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   306
             cleaning. *)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   307
           (* cu: if I also test the type, then something else breaks *)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   308
       in
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   309
         if same_name rtrm qtrm then rtrm
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   310
         else 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   311
           let 
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   312
             val thy = ProofContext.theory_of ctxt
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   313
             val qtrm_str = Syntax.string_of_term ctxt qtrm
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   314
             val exc1 = LIFT_MATCH ("regularize (constant " ^ qtrm_str ^ " not found)")
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   315
             val exc2 = LIFT_MATCH ("regularize (constant " ^ qtrm_str ^ " mismatch)")
785
Christian Urban <urbanc@in.tum.de>
parents: 784
diff changeset
   316
             val rtrm' = #rconst (qconsts_lookup thy qtrm) handle NotFound => raise exc1
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   317
           in 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   318
             if Pattern.matches thy (rtrm', rtrm) 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   319
             then rtrm else raise exc2
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   320
           end
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   321
       end 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   322
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   323
  | (t1 $ t2, t1' $ t2') =>
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   324
       (regularize_trm ctxt (t1, t1')) $ (regularize_trm ctxt (t2, t2'))
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   325
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   326
  | (Bound i, Bound i') =>
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   327
       if i = i' then rtrm 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   328
       else raise (LIFT_MATCH "regularize (bounds mismatch)")
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   329
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   330
  | _ =>
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   331
       let 
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   332
         val rtrm_str = Syntax.string_of_term ctxt rtrm
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   333
         val qtrm_str = Syntax.string_of_term ctxt qtrm
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   334
       in
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   335
         raise (LIFT_MATCH ("regularize failed (default: " ^ rtrm_str ^ "," ^ qtrm_str ^ ")"))
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   336
       end
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   337
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   338
fun regularize_trm_chk ctxt (rtrm, qtrm) =
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   339
  regularize_trm ctxt (rtrm, qtrm) 
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   340
  |> Syntax.check_term ctxt
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   341
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   342
(*
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   343
Injection of Rep/Abs means:
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
  For abstractions
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   346
:
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   347
  * If the type of the abstraction needs lifting, then we add Rep/Abs 
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   348
    around the abstraction; otherwise we leave it unchanged.
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   349
 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   350
  For applications:
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   351
  
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   352
  * If the application involves a bounded quantifier, we recurse on 
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   353
    the second argument. If the application is a bounded abstraction,
782
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 779
diff changeset
   354
    we always put an Rep/Abs around it (since bounded abstractions
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 779
diff changeset
   355
    are assumed to always need lifting). Otherwise we recurse on both 
86c7ed9f354f cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents: 779
diff changeset
   356
    arguments.
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   357
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   358
  For constants:
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   359
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   360
  * If the constant is (op =), we leave it always unchanged. 
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   361
    Otherwise the type of the constant needs lifting, we put
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   362
    and Rep/Abs around it. 
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   363
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   364
  For free variables:
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   365
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   366
  * We put aRep/Abs around it if the type needs lifting.
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   367
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   368
  Vars case cannot occur.
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   369
*)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   370
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   371
fun mk_repabs ctxt (T, T') trm = 
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   372
  absrep_fun repF ctxt (T, T') $ (absrep_fun absF ctxt (T, T') $ trm)
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   373
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   374
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   375
(* bound variables need to be treated properly,     *)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   376
(* as the type of subterms needs to be calculated   *)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   377
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   378
fun inj_repabs_trm ctxt (rtrm, qtrm) =
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   379
 case (rtrm, qtrm) of
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   380
    (Const (@{const_name "Ball"}, T) $ r $ t, Const (@{const_name "All"}, _) $ t') =>
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   381
       Const (@{const_name "Ball"}, T) $ r $ (inj_repabs_trm ctxt (t, t'))
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   382
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   383
  | (Const (@{const_name "Bex"}, T) $ r $ t, Const (@{const_name "Ex"}, _) $ t') =>
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   384
       Const (@{const_name "Bex"}, T) $ r $ (inj_repabs_trm ctxt (t, t'))
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   385
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   386
  | (Const (@{const_name "Babs"}, T) $ r $ t, t' as (Abs _)) =>
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   387
      let
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   388
        val rty = fastype_of rtrm
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   389
        val qty = fastype_of qtrm
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   390
      in
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   391
        mk_repabs ctxt (rty, qty) (Const (@{const_name "Babs"}, T) $ r $ (inj_repabs_trm ctxt (t, t')))
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   392
      end
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   393
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   394
  | (Abs (x, T, t), Abs (x', T', t')) =>
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   395
      let
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   396
        val rty = fastype_of rtrm
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   397
        val qty = fastype_of qtrm
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   398
        val (y, s) = Term.dest_abs (x, T, t)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   399
        val (_, s') = Term.dest_abs (x', T', t')
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   400
        val yvar = Free (y, T)
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   401
        val result = Term.lambda_name (y, yvar) (inj_repabs_trm ctxt (s, s'))
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   402
      in
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   403
        if rty = qty then result
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   404
        else mk_repabs ctxt (rty, qty) result
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   405
      end
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   406
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   407
  | (t $ s, t' $ s') =>  
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   408
       (inj_repabs_trm ctxt (t, t')) $ (inj_repabs_trm ctxt (s, s'))
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   409
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   410
  | (Free (_, T), Free (_, T')) => 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   411
        if T = T' then rtrm 
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   412
        else mk_repabs ctxt (T, T') rtrm
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   413
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   414
  | (_, Const (@{const_name "op ="}, _)) => rtrm
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   415
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   416
  | (_, Const (_, T')) =>
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   417
      let
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   418
        val rty = fastype_of rtrm
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   419
      in 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   420
        if rty = T' then rtrm
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   421
        else mk_repabs ctxt (rty, T') rtrm
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   422
      end   
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   423
  
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   424
  | _ => raise (LIFT_MATCH "injection (default)")
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   425
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   426
fun inj_repabs_trm_chk ctxt (rtrm, qtrm) =
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   427
  inj_repabs_trm ctxt (rtrm, qtrm) 
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 776
diff changeset
   428
  |> Syntax.check_term ctxt
776
d1064fa29424 renamed get_fun to absrep_fun; introduced explicit checked versions of the term functions
Christian Urban <urbanc@in.tum.de>
parents: 775
diff changeset
   429
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   430
end; (* structure *)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   431
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   432
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   433