Quot/quotient_term.ML
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Fri, 05 Feb 2010 11:37:18 +0100
changeset 1072 6deecec6795f
parent 1071 dde8ad700c5b
child 1075 b2f32114e8a6
permissions -rw-r--r--
A procedure that properly instantiates the types too.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
952
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
     1
(*  Title:      quotient_term.thy
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
     2
    Author:     Cezary Kaliszyk and Christian Urban
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
     3
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
     4
    Constructs terms corresponding to goals from
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
     5
    lifting theorems to quotient types.
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
     6
*)
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
     7
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
signature QUOTIENT_TERM =
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
sig
853
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 849
diff changeset
    10
  exception LIFT_MATCH of string
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 849
diff changeset
    11
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 849
diff changeset
    12
  datatype flag = absF | repF
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 849
diff changeset
    13
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 849
diff changeset
    14
  val absrep_fun: flag -> Proof.context -> typ * typ -> term
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 849
diff changeset
    15
  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
    16
974
d44fda0cf393 Recommited the changes for nitpick
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 959
diff changeset
    17
  (* Allows Nitpick to represent quotient types as single elements from raw type *)
d44fda0cf393 Recommited the changes for nitpick
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 959
diff changeset
    18
  val absrep_const_chk: flag -> Proof.context -> string -> term
d44fda0cf393 Recommited the changes for nitpick
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 959
diff changeset
    19
853
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 849
diff changeset
    20
  val equiv_relation: Proof.context -> typ * typ -> term
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 849
diff changeset
    21
  val equiv_relation_chk: Proof.context -> typ * typ -> term
795
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
    22
853
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 849
diff changeset
    23
  val regularize_trm: Proof.context -> term * term -> term
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 849
diff changeset
    24
  val regularize_trm_chk: Proof.context -> term * term -> term
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 849
diff changeset
    25
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 849
diff changeset
    26
  val inj_repabs_trm: Proof.context -> term * term -> term
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 849
diff changeset
    27
  val inj_repabs_trm_chk: Proof.context -> term * term -> term
1065
3664eafcad09 The automatic lifting translation function, still with dummy types,
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1000
diff changeset
    28
3664eafcad09 The automatic lifting translation function, still with dummy types,
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1000
diff changeset
    29
  val quotient_lift_all: Proof.context -> term -> term
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
end;
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
structure Quotient_Term: QUOTIENT_TERM =
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
struct
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
762
baac4639ecef avoided global "open"s - replaced by local "open"s
Christian Urban <urbanc@in.tum.de>
parents: 761
diff changeset
    35
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
    36
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
    37
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
    38
849
fa2b4b7af755 modifying comments/indentation in quotient_term.ml
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 836
diff changeset
    39
fa2b4b7af755 modifying comments/indentation in quotient_term.ml
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 836
diff changeset
    40
fa2b4b7af755 modifying comments/indentation in quotient_term.ml
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 836
diff changeset
    41
(*** Aggregate Rep/Abs Function ***)
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
    42
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
    43
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
    44
(* The flag repF is for types in negative position; absF is for types 
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
    45
   in positive position. Because of this, function types need to be   
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
    46
   treated specially, since there the polarity changes.               
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
    47
*)
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
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
    49
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
    50
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
    51
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
    52
  | 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
    53
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
    54
fun is_identity (Const (@{const_name "id"}, _)) = true
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
    55
  | is_identity _ = false
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
    56
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
    57
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
    58
807
a5495a323b49 added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
    59
fun mk_fun_compose flag (trm1, trm2) = 
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
    60
  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
    61
    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
    62
  | 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
    63
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    64
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
    65
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
    66
  val thy = ProofContext.theory_of ctxt
853
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 849
diff changeset
    67
  val exc = LIFT_MATCH ("No map function for type " ^ quote s ^ " found.")
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    68
  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
    69
in
784
da75568e7f12 renamed some fields in the info records
Christian Urban <urbanc@in.tum.de>
parents: 783
diff changeset
    70
  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
    71
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
    72
800
71225f4a4635 some slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 797
diff changeset
    73
(* makes a Free out of a TVar *)
71225f4a4635 some slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 797
diff changeset
    74
fun mk_Free (TVar ((x, i), _)) = Free (unprefix "'" x ^ string_of_int i, dummyT)
71225f4a4635 some slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 797
diff changeset
    75
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
    76
(* produces an aggregate map function for the       
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
    77
   rty-part of a quotient definition; abstracts     
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
    78
   over all variables listed in vs (these variables 
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
    79
   correspond to the type variables in rty)         
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
    80
                                                    
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
    81
   for example for: (?'a list * ?'b)                
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
    82
   it produces:     %a b. prod_map (map a) b 
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
    83
*)
803
6f6ee78c7357 a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents: 801
diff changeset
    84
fun mk_mapfun ctxt vs rty =
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    85
let
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    86
  val vs' = map (mk_Free) vs
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    87
803
6f6ee78c7357 a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents: 801
diff changeset
    88
  fun mk_mapfun_aux rty =
6f6ee78c7357 a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents: 801
diff changeset
    89
    case rty of
6f6ee78c7357 a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents: 801
diff changeset
    90
      TVar _ => mk_Free rty
6f6ee78c7357 a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents: 801
diff changeset
    91
    | Type (_, []) => mk_identity rty
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    92
    | Type (s, tys) => list_comb (get_mapfun ctxt s, map mk_mapfun_aux tys)
804
Christian Urban <urbanc@in.tum.de>
parents: 803
diff changeset
    93
    | _ => raise LIFT_MATCH ("mk_mapfun (default)")
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    94
in
803
6f6ee78c7357 a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents: 801
diff changeset
    95
  fold_rev Term.lambda vs' (mk_mapfun_aux rty)
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    96
end
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
    97
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
    98
(* looks up the (varified) rty and qty for 
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
    99
   a quotient definition                   
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   100
*)
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   101
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
   102
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
   103
  val thy = ProofContext.theory_of ctxt
853
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 849
diff changeset
   104
  val exc = LIFT_MATCH ("No quotient type " ^ quote s ^ " found.")
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   105
  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
   106
in
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   107
  (#rtyp qdata, #qtyp qdata)
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   108
end
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   109
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   110
(* takes two type-environments and looks    
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   111
   up in both of them the variable v, which 
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   112
   must be listed in the environment        
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   113
*)
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   114
fun double_lookup rtyenv qtyenv v =
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   115
let
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   116
  val v' = fst (dest_TVar v)
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   117
in
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   118
  (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
   119
end
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   120
832
b3bb2bad952f introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents: 831
diff changeset
   121
(* matches a type pattern with a type *)
b3bb2bad952f introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents: 831
diff changeset
   122
fun match ctxt err ty_pat ty =
b3bb2bad952f introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents: 831
diff changeset
   123
let
b3bb2bad952f introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents: 831
diff changeset
   124
  val thy = ProofContext.theory_of ctxt
b3bb2bad952f introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents: 831
diff changeset
   125
in
b3bb2bad952f introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents: 831
diff changeset
   126
  Sign.typ_match thy (ty_pat, ty) Vartab.empty
b3bb2bad952f introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents: 831
diff changeset
   127
  handle MATCH_TYPE => err ctxt ty_pat ty
b3bb2bad952f introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents: 831
diff changeset
   128
end
b3bb2bad952f introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents: 831
diff changeset
   129
800
71225f4a4635 some slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 797
diff changeset
   130
(* produces the rep or abs constant for a qty *)
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   131
fun absrep_const flag ctxt qty_str =
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   132
let
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   133
  val thy = ProofContext.theory_of ctxt
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   134
  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
   135
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
   136
  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
   137
    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
   138
  | 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
   139
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
   140
974
d44fda0cf393 Recommited the changes for nitpick
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 959
diff changeset
   141
(* Lets Nitpick represent elements of quotient types as elements of the raw type *)
d44fda0cf393 Recommited the changes for nitpick
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 959
diff changeset
   142
fun absrep_const_chk flag ctxt qty_str =
d44fda0cf393 Recommited the changes for nitpick
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 959
diff changeset
   143
  Syntax.check_term ctxt (absrep_const flag ctxt qty_str)
d44fda0cf393 Recommited the changes for nitpick
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 959
diff changeset
   144
795
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   145
fun absrep_match_err ctxt ty_pat ty =
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   146
let
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   147
  val ty_pat_str = Syntax.string_of_typ ctxt ty_pat
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   148
  val ty_str = Syntax.string_of_typ ctxt ty 
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   149
in
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   150
  raise LIFT_MATCH (space_implode " " 
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   151
    ["absrep_fun (Types ", quote ty_pat_str, "and", quote ty_str, " do not match.)"])
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   152
end
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   153
849
fa2b4b7af755 modifying comments/indentation in quotient_term.ml
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 836
diff changeset
   154
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   155
(** generation of an aggregate absrep function **)
791
fb4bfbb1a291 commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents: 790
diff changeset
   156
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   157
(* - In case of equal types we just return the identity.           
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   158
     
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   159
   - In case of TFrees we also return the identity.
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   160
                                                             
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   161
   - In case of function types we recurse taking   
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   162
     the polarity change into account.              
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   163
                                                                   
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   164
   - If the type constructors are equal, we recurse for the        
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   165
     arguments and build the appropriate map function.             
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   166
                                                                   
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   167
   - If the type constructors are unequal, there must be an        
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   168
     instance of quotient types:         
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   169
                          
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   170
       - we first look up the corresponding rty_pat and qty_pat    
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   171
         from the quotient definition; the arguments of qty_pat    
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   172
         must be some distinct TVars                               
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   173
       - we then match the rty_pat with rty and qty_pat with qty;  
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   174
         if matching fails the types do not correspond -> error                  
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   175
       - the matching produces two environments; we look up the    
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   176
         assignments for the qty_pat variables and recurse on the  
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   177
         assignments                                               
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   178
       - we prefix the aggregate map function for the rty_pat,     
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   179
         which is an abstraction over all type variables           
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   180
       - finally we compose the result with the appropriate        
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   181
         absrep function in case at least one argument produced
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   182
         a non-identity function /
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   183
         otherwise we just return the appropriate absrep
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   184
         function                                          
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   185
                                                                   
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   186
     The composition is necessary for types like                   
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   187
                                                                 
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   188
        ('a list) list / ('a foo) foo                              
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   189
                                                                 
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   190
     The matching is necessary for types like                      
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   191
                                                                 
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   192
        ('a * 'a) list / 'a bar   
849
fa2b4b7af755 modifying comments/indentation in quotient_term.ml
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 836
diff changeset
   193
858
Christian Urban <urbanc@in.tum.de>
parents: 856
diff changeset
   194
     The test is necessary in order to eliminate superfluous
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   195
     identity maps.                                 
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   196
*)  
849
fa2b4b7af755 modifying comments/indentation in quotient_term.ml
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 836
diff changeset
   197
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
   198
fun absrep_fun flag ctxt (rty, qty) =
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   199
  if rty = qty  
803
6f6ee78c7357 a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents: 801
diff changeset
   200
  then mk_identity rty
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   201
  else
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   202
    case (rty, qty) of
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   203
      (Type ("fun", [ty1, ty2]), Type ("fun", [ty1', ty2'])) =>
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   204
        let
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   205
          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
   206
          val arg2 = absrep_fun flag ctxt (ty2, ty2')
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   207
        in
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   208
          list_comb (get_mapfun ctxt "fun", [arg1, arg2])
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   209
        end
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   210
    | (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
   211
        if s = s'
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   212
        then 
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   213
           let
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   214
             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
   215
           in
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   216
             list_comb (get_mapfun ctxt s, args)
832
b3bb2bad952f introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents: 831
diff changeset
   217
           end 
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   218
        else
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   219
           let
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   220
             val (rty_pat, qty_pat as Type (_, vs)) = get_rty_qty ctxt s'
832
b3bb2bad952f introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents: 831
diff changeset
   221
             val rtyenv = match ctxt absrep_match_err rty_pat rty
b3bb2bad952f introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents: 831
diff changeset
   222
             val qtyenv = match ctxt absrep_match_err qty_pat qty
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   223
             val args_aux = map (double_lookup rtyenv qtyenv) vs
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   224
             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
   225
             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
   226
             val result = list_comb (map_fun, args) 
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   227
           in
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   228
             if forall is_identity args
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   229
             then absrep_const flag ctxt s'
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   230
             else mk_fun_compose flag (absrep_const flag ctxt s', result)
830
89d772dae4d4 New_relations, all works again including concat examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 826
diff changeset
   231
           end
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   232
    | (TFree x, TFree x') =>
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   233
        if x = x'
803
6f6ee78c7357 a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents: 801
diff changeset
   234
        then mk_identity rty
790
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   235
        else raise (LIFT_MATCH "absrep_fun (frees)")
3a48ffcf0f9a generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents: 786
diff changeset
   236
    | (TVar _, TVar _) => raise (LIFT_MATCH "absrep_fun (vars)")
791
fb4bfbb1a291 commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents: 790
diff changeset
   237
    | _ => raise (LIFT_MATCH "absrep_fun (default)")
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
   238
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
   239
fun absrep_fun_chk 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
   240
  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
   241
  |> Syntax.check_term ctxt
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   242
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
   243
849
fa2b4b7af755 modifying comments/indentation in quotient_term.ml
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 836
diff changeset
   244
fa2b4b7af755 modifying comments/indentation in quotient_term.ml
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 836
diff changeset
   245
fa2b4b7af755 modifying comments/indentation in quotient_term.ml
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 836
diff changeset
   246
(*** Aggregate Equivalence Relation ***)
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   248
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   249
(* works very similar to the absrep generation,
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   250
   except there is no need for polarities
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   251
*)
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   252
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
   253
(* instantiates TVars so that the term is of type ty *)
792
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   254
fun force_typ ctxt trm ty =
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
   255
let
792
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   256
  val thy = ProofContext.theory_of ctxt 
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
   257
  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
   258
  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
   259
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
   260
  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
   261
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
   262
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   263
fun is_eq (Const (@{const_name "op ="}, _)) = true
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   264
  | is_eq _ = false
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   265
825
970e86082cd7 Modifictaions for new_relation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 808
diff changeset
   266
fun mk_rel_compose (trm1, trm2) =
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   267
  Const (@{const_name "rel_conj"}, dummyT) $ trm1 $ trm2
807
a5495a323b49 added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   268
792
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   269
fun get_relmap ctxt s =
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   270
let
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   271
  val thy = ProofContext.theory_of ctxt
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   272
  val exc =  LIFT_MATCH ("get_relmap (no relation map function found for type " ^ s ^ ")") 
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   273
  val relmap =  #relmap (maps_lookup thy s) handle NotFound => raise exc
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   274
in
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   275
  Const (relmap, dummyT)
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   276
end
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   277
807
a5495a323b49 added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   278
fun mk_relmap ctxt vs rty =
a5495a323b49 added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   279
let
a5495a323b49 added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   280
  val vs' = map (mk_Free) vs
a5495a323b49 added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   281
a5495a323b49 added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   282
  fun mk_relmap_aux rty =
a5495a323b49 added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   283
    case rty of
a5495a323b49 added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   284
      TVar _ => mk_Free rty
a5495a323b49 added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   285
    | Type (_, []) => HOLogic.eq_const rty
a5495a323b49 added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   286
    | Type (s, tys) => list_comb (get_relmap ctxt s, map mk_relmap_aux tys)
a5495a323b49 added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   287
    | _ => raise LIFT_MATCH ("mk_relmap (default)")
a5495a323b49 added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   288
in
a5495a323b49 added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   289
  fold_rev Term.lambda vs' (mk_relmap_aux rty)
a5495a323b49 added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   290
end
a5495a323b49 added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents: 804
diff changeset
   291
792
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   292
fun get_equiv_rel ctxt s =
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   293
let
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   294
  val thy = ProofContext.theory_of ctxt
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   295
  val exc = LIFT_MATCH ("get_quotdata (no quotient found for type " ^ s ^ ")") 
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   296
in
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   297
  #equiv_rel (quotdata_lookup thy s) handle NotFound => raise exc
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   298
end
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   299
808
90bde96f5dd1 proper handling of error messages (code copy - maybe this can be avoided)
Christian Urban <urbanc@in.tum.de>
parents: 807
diff changeset
   300
fun equiv_match_err ctxt ty_pat ty =
90bde96f5dd1 proper handling of error messages (code copy - maybe this can be avoided)
Christian Urban <urbanc@in.tum.de>
parents: 807
diff changeset
   301
let
90bde96f5dd1 proper handling of error messages (code copy - maybe this can be avoided)
Christian Urban <urbanc@in.tum.de>
parents: 807
diff changeset
   302
  val ty_pat_str = Syntax.string_of_typ ctxt ty_pat
90bde96f5dd1 proper handling of error messages (code copy - maybe this can be avoided)
Christian Urban <urbanc@in.tum.de>
parents: 807
diff changeset
   303
  val ty_str = Syntax.string_of_typ ctxt ty 
90bde96f5dd1 proper handling of error messages (code copy - maybe this can be avoided)
Christian Urban <urbanc@in.tum.de>
parents: 807
diff changeset
   304
in
90bde96f5dd1 proper handling of error messages (code copy - maybe this can be avoided)
Christian Urban <urbanc@in.tum.de>
parents: 807
diff changeset
   305
  raise LIFT_MATCH (space_implode " " 
90bde96f5dd1 proper handling of error messages (code copy - maybe this can be avoided)
Christian Urban <urbanc@in.tum.de>
parents: 807
diff changeset
   306
    ["equiv_relation (Types ", quote ty_pat_str, "and", quote ty_str, " do not match.)"])
90bde96f5dd1 proper handling of error messages (code copy - maybe this can be avoided)
Christian Urban <urbanc@in.tum.de>
parents: 807
diff changeset
   307
end
90bde96f5dd1 proper handling of error messages (code copy - maybe this can be avoided)
Christian Urban <urbanc@in.tum.de>
parents: 807
diff changeset
   308
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   309
(* builds the aggregate equivalence relation 
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   310
   that will be the argument of Respects     
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   311
*)
795
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   312
fun equiv_relation ctxt (rty, qty) =
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   313
  if rty = qty
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   314
  then HOLogic.eq_const rty
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   315
  else
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   316
    case (rty, qty) of
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   317
      (Type (s, tys), Type (s', tys')) =>
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   318
       if s = s' 
761
e2ac18492c68 small tuning
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
   319
       then 
e2ac18492c68 small tuning
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
   320
         let
795
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   321
           val args = map (equiv_relation ctxt) (tys ~~ tys')
761
e2ac18492c68 small tuning
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
   322
         in
792
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   323
           list_comb (get_relmap ctxt s, args) 
761
e2ac18492c68 small tuning
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
   324
         end  
e2ac18492c68 small tuning
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
   325
       else 
784
da75568e7f12 renamed some fields in the info records
Christian Urban <urbanc@in.tum.de>
parents: 783
diff changeset
   326
         let
831
224909b9399f removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents: 830
diff changeset
   327
           val (rty_pat, qty_pat as Type (_, vs)) = get_rty_qty ctxt s'
832
b3bb2bad952f introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents: 831
diff changeset
   328
           val rtyenv = match ctxt equiv_match_err rty_pat rty
b3bb2bad952f introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents: 831
diff changeset
   329
           val qtyenv = match ctxt equiv_match_err qty_pat qty
831
224909b9399f removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents: 830
diff changeset
   330
           val args_aux = map (double_lookup rtyenv qtyenv) vs 
224909b9399f removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents: 830
diff changeset
   331
           val args = map (equiv_relation ctxt) args_aux
224909b9399f removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents: 830
diff changeset
   332
           val rel_map = mk_relmap ctxt vs rty_pat       
224909b9399f removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents: 830
diff changeset
   333
           val result = list_comb (rel_map, args)
792
Christian Urban <urbanc@in.tum.de>
parents: 791
diff changeset
   334
           val eqv_rel = get_equiv_rel ctxt s'
831
224909b9399f removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents: 830
diff changeset
   335
           val eqv_rel' = force_typ ctxt eqv_rel ([rty, rty] ---> @{typ bool})
761
e2ac18492c68 small tuning
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
   336
         in
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   337
           if forall is_eq args 
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   338
           then eqv_rel'
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   339
           else mk_rel_compose (result, eqv_rel')
761
e2ac18492c68 small tuning
Christian Urban <urbanc@in.tum.de>
parents: 760
diff changeset
   340
         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
   341
      | _ => HOLogic.eq_const rty
795
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   342
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   343
fun equiv_relation_chk ctxt (rty, qty) =
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   344
  equiv_relation ctxt (rty, qty)
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   345
  |> Syntax.check_term ctxt
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   346
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   347
849
fa2b4b7af755 modifying comments/indentation in quotient_term.ml
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 836
diff changeset
   348
fa2b4b7af755 modifying comments/indentation in quotient_term.ml
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 836
diff changeset
   349
(*** Regularization ***)
795
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   350
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   351
(* Regularizing an rtrm means:
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   352
 
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   353
 - Quantifiers over types that need lifting are replaced 
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   354
   by bounded quantifiers, for example:
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   355
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   356
      All P  ----> All (Respects R) P
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   357
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   358
   where the aggregate relation R is given by the rty and qty;
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   359
 
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   360
 - Abstractions over types that need lifting are replaced
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   361
   by bounded abstractions, for example:
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   362
      
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   363
      %x. P  ----> Ball (Respects R) %x. P
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   364
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   365
 - Equalities over types that need lifting are replaced by
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   366
   corresponding equivalence relations, for example:
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   367
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   368
      A = B  ----> R A B
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   369
853
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 849
diff changeset
   370
   or
795
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   371
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   372
      A = B  ----> (R ===> R) A B
853
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 849
diff changeset
   373
795
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   374
   for more complicated types of A and B
955
da270d122965 Commenting regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   375
da270d122965 Commenting regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   376
da270d122965 Commenting regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   377
 The regularize_trm accepts raw theorems in which equalities
da270d122965 Commenting regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   378
 and quantifiers match exactly the ones in the lifted theorem
da270d122965 Commenting regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   379
 but also accepts partially regularized terms.
da270d122965 Commenting regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   380
da270d122965 Commenting regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   381
 This means that the raw theorems can have:
982
54faefa53745 End of renaming.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 974
diff changeset
   382
   Ball (Respects R),  Bex (Respects R), Bex1_rel (Respects R), Babs, R
955
da270d122965 Commenting regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   383
 in the places where:
959
1786aa86e52b When commenting discovered a missing case of Babs->Abs regularization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 956
diff changeset
   384
   All, Ex, Ex1, %, (op =)
955
da270d122965 Commenting regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   385
 is required the lifted theorem.
da270d122965 Commenting regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 952
diff changeset
   386
795
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   387
*)
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   388
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   389
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
   390
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
   391
val mk_bex  = Const (@{const_name Bex}, dummyT)
906
a394c7337966 Ex1 -> Bex1 Regularization, Preparing Exeq.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 904
diff changeset
   392
val mk_bex1 = Const (@{const_name Bex1}, dummyT)
999
64874975f087 renamed function according to the name of the constant
Christian Urban <urbanc@in.tum.de>
parents: 982
diff changeset
   393
val mk_bex1_rel = Const (@{const_name Bex1_rel}, dummyT)
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   394
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
   395
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   396
(* - applies f to the subterm of an abstraction, 
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   397
     otherwise to the given term,                
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   398
   - used by regularize, therefore abstracted    
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   399
     variables do not have to be treated specially 
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   400
*)
775
Christian Urban <urbanc@in.tum.de>
parents: 774
diff changeset
   401
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
   402
  case (trm1, trm2) of
775
Christian Urban <urbanc@in.tum.de>
parents: 774
diff changeset
   403
    (Abs (x, T, t), Abs (_ , _, t')) => Abs (x, T, f (t, t'))
Christian Urban <urbanc@in.tum.de>
parents: 774
diff changeset
   404
  | _ => f (trm1, trm2)
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   405
891
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   406
fun term_mismatch str ctxt t1 t2 =
865
5c6d76c3ba5c Put relation_error as a separate function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 858
diff changeset
   407
let
891
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   408
  val t1_str = Syntax.string_of_term ctxt t1
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   409
  val t2_str = Syntax.string_of_term ctxt t2
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   410
  val t1_ty_str = Syntax.string_of_typ ctxt (fastype_of t1)
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   411
  val t2_ty_str = Syntax.string_of_typ ctxt (fastype_of t2)
865
5c6d76c3ba5c Put relation_error as a separate function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 858
diff changeset
   412
in
891
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   413
  raise LIFT_MATCH (cat_lines [str, t1_str ^ "::" ^ t1_ty_str, t2_str ^ "::" ^ t2_ty_str])
865
5c6d76c3ba5c Put relation_error as a separate function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 858
diff changeset
   414
end
5c6d76c3ba5c Put relation_error as a separate function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 858
diff changeset
   415
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   416
(* the major type of All and Ex quantifiers *)
853
3fd1365f5729 More indenting, bracket removing and comment restructuring.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 849
diff changeset
   417
fun qnt_typ ty = domain_type (domain_type ty)
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   418
867
9e247b9505f0 Moved the matches_typ function outside a?d simplified it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 865
diff changeset
   419
(* Checks that two types match, for example:
9e247b9505f0 Moved the matches_typ function outside a?d simplified it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 865
diff changeset
   420
     rty -> rty   matches   qty -> qty *)
875
cc951743c5e2 Simplified matches_typ.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 867
diff changeset
   421
fun matches_typ thy rT qT =
cc951743c5e2 Simplified matches_typ.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 867
diff changeset
   422
  if rT = qT then true else
cc951743c5e2 Simplified matches_typ.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 867
diff changeset
   423
  case (rT, qT) of
cc951743c5e2 Simplified matches_typ.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 867
diff changeset
   424
    (Type (rs, rtys), Type (qs, qtys)) =>
cc951743c5e2 Simplified matches_typ.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 867
diff changeset
   425
      if rs = qs then
cc951743c5e2 Simplified matches_typ.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 867
diff changeset
   426
        if length rtys <> length qtys then false else
cc951743c5e2 Simplified matches_typ.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 867
diff changeset
   427
        forall (fn x => x = true) (map2 (matches_typ thy) rtys qtys)
cc951743c5e2 Simplified matches_typ.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 867
diff changeset
   428
      else
cc951743c5e2 Simplified matches_typ.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 867
diff changeset
   429
        (case Quotient_Info.quotdata_lookup_raw thy qs of
cc951743c5e2 Simplified matches_typ.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 867
diff changeset
   430
          SOME quotinfo => Sign.typ_instance thy (rT, #rtyp quotinfo)
cc951743c5e2 Simplified matches_typ.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 867
diff changeset
   431
        | NONE => false)
867
9e247b9505f0 Moved the matches_typ function outside a?d simplified it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 865
diff changeset
   432
  | _ => false
9e247b9505f0 Moved the matches_typ function outside a?d simplified it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 865
diff changeset
   433
9e247b9505f0 Moved the matches_typ function outside a?d simplified it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 865
diff changeset
   434
856
Christian Urban <urbanc@in.tum.de>
parents: 854 853
diff changeset
   435
(* produces a regularized version of rtrm
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   436
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   437
   - the result might contain dummyTs           
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   438
854
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   439
   - for regularisation we do not need any      
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   440
     special treatment of bound variables       
5961edda27d7 absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 836
diff changeset
   441
*)
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
   442
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
   443
  case (rtrm, qtrm) of
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   444
    (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
   445
       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
   446
         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
   447
       in
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   448
         if ty = ty' then subtrm
831
224909b9399f removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents: 830
diff changeset
   449
         else mk_babs $ (mk_resp $ equiv_relation ctxt (ty, ty')) $ subtrm
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   450
       end
1000
1893316b9ef8 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 999
diff changeset
   451
  | (Const (@{const_name "Babs"}, T) $ resrel $ (t as (Abs (_, ty, _))), t' as (Abs (_, ty', _))) =>
959
1786aa86e52b When commenting discovered a missing case of Babs->Abs regularization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 956
diff changeset
   452
       let
1786aa86e52b When commenting discovered a missing case of Babs->Abs regularization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 956
diff changeset
   453
         val subtrm = regularize_trm ctxt (t, t')
1786aa86e52b When commenting discovered a missing case of Babs->Abs regularization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 956
diff changeset
   454
         val needres = mk_resp $ equiv_relation_chk ctxt (ty, ty')
1786aa86e52b When commenting discovered a missing case of Babs->Abs regularization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 956
diff changeset
   455
       in
1000
1893316b9ef8 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 999
diff changeset
   456
         if resrel <> needres
1893316b9ef8 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 999
diff changeset
   457
         then term_mismatch "regularize (Babs)" ctxt resrel needres
1893316b9ef8 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 999
diff changeset
   458
         else mk_babs $ resrel $ subtrm
959
1786aa86e52b When commenting discovered a missing case of Babs->Abs regularization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 956
diff changeset
   459
       end
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   460
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   461
  | (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
   462
       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
   463
         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
   464
       in
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   465
         if ty = ty' then Const (@{const_name "All"}, ty) $ subtrm
831
224909b9399f removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents: 830
diff changeset
   466
         else mk_ball $ (mk_resp $ equiv_relation 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
   467
       end
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   468
953
1235336f4661 reordered cases in regularize (will be merged into two cases)
Christian Urban <urbanc@in.tum.de>
parents: 952
diff changeset
   469
  | (Const (@{const_name "Ex"}, ty) $ t, Const (@{const_name "Ex"}, ty') $ t') =>
1235336f4661 reordered cases in regularize (will be merged into two cases)
Christian Urban <urbanc@in.tum.de>
parents: 952
diff changeset
   470
       let
1235336f4661 reordered cases in regularize (will be merged into two cases)
Christian Urban <urbanc@in.tum.de>
parents: 952
diff changeset
   471
         val subtrm = apply_subt (regularize_trm ctxt) (t, t')
1235336f4661 reordered cases in regularize (will be merged into two cases)
Christian Urban <urbanc@in.tum.de>
parents: 952
diff changeset
   472
       in
1235336f4661 reordered cases in regularize (will be merged into two cases)
Christian Urban <urbanc@in.tum.de>
parents: 952
diff changeset
   473
         if ty = ty' then Const (@{const_name "Ex"}, ty) $ subtrm
1235336f4661 reordered cases in regularize (will be merged into two cases)
Christian Urban <urbanc@in.tum.de>
parents: 952
diff changeset
   474
         else mk_bex $ (mk_resp $ equiv_relation ctxt (qnt_typ ty, qnt_typ ty')) $ subtrm
1235336f4661 reordered cases in regularize (will be merged into two cases)
Christian Urban <urbanc@in.tum.de>
parents: 952
diff changeset
   475
       end
1235336f4661 reordered cases in regularize (will be merged into two cases)
Christian Urban <urbanc@in.tum.de>
parents: 952
diff changeset
   476
1235336f4661 reordered cases in regularize (will be merged into two cases)
Christian Urban <urbanc@in.tum.de>
parents: 952
diff changeset
   477
  | (Const (@{const_name "Ex1"}, ty) $ t, Const (@{const_name "Ex1"}, ty') $ t') =>
1235336f4661 reordered cases in regularize (will be merged into two cases)
Christian Urban <urbanc@in.tum.de>
parents: 952
diff changeset
   478
       let
1235336f4661 reordered cases in regularize (will be merged into two cases)
Christian Urban <urbanc@in.tum.de>
parents: 952
diff changeset
   479
         val subtrm = apply_subt (regularize_trm ctxt) (t, t')
1235336f4661 reordered cases in regularize (will be merged into two cases)
Christian Urban <urbanc@in.tum.de>
parents: 952
diff changeset
   480
       in
1235336f4661 reordered cases in regularize (will be merged into two cases)
Christian Urban <urbanc@in.tum.de>
parents: 952
diff changeset
   481
         if ty = ty' then Const (@{const_name "Ex1"}, ty) $ subtrm
999
64874975f087 renamed function according to the name of the constant
Christian Urban <urbanc@in.tum.de>
parents: 982
diff changeset
   482
         else mk_bex1_rel $ (equiv_relation ctxt (qnt_typ ty, qnt_typ ty')) $ subtrm
953
1235336f4661 reordered cases in regularize (will be merged into two cases)
Christian Urban <urbanc@in.tum.de>
parents: 952
diff changeset
   483
       end
1235336f4661 reordered cases in regularize (will be merged into two cases)
Christian Urban <urbanc@in.tum.de>
parents: 952
diff changeset
   484
952
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
   485
  | (Const (@{const_name "Ball"}, ty) $ (Const (@{const_name "Respects"}, _) $ resrel) $ t, 
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
   486
     Const (@{const_name "All"}, ty') $ t') =>
891
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   487
       let
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   488
         val subtrm = apply_subt (regularize_trm ctxt) (t, t')
952
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
   489
         val needrel = equiv_relation_chk ctxt (qnt_typ ty, qnt_typ ty')
891
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   490
       in
904
4f5512569468 Better error messages for non matching quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 891
diff changeset
   491
         if resrel <> needrel
952
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
   492
         then term_mismatch "regularize (Ball)" ctxt resrel needrel
891
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   493
         else mk_ball $ (mk_resp $ resrel) $ subtrm
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   494
       end
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   495
952
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
   496
  | (Const (@{const_name "Bex"}, ty) $ (Const (@{const_name "Respects"}, _) $ resrel) $ t, 
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
   497
     Const (@{const_name "Ex"}, ty') $ t') =>
891
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   498
       let
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   499
         val subtrm = apply_subt (regularize_trm ctxt) (t, t')
952
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
   500
         val needrel = equiv_relation_chk ctxt (qnt_typ ty, qnt_typ ty')
891
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   501
       in
904
4f5512569468 Better error messages for non matching quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 891
diff changeset
   502
         if resrel <> needrel
952
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
   503
         then term_mismatch "regularize (Bex)" ctxt resrel needrel
891
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   504
         else mk_bex $ (mk_resp $ resrel) $ subtrm
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   505
       end
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   506
982
54faefa53745 End of renaming.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 974
diff changeset
   507
  | (Const (@{const_name "Bex1_rel"}, ty) $ resrel $ t, Const (@{const_name "Ex1"}, ty') $ t') =>
906
a394c7337966 Ex1 -> Bex1 Regularization, Preparing Exeq.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 904
diff changeset
   508
       let
a394c7337966 Ex1 -> Bex1 Regularization, Preparing Exeq.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 904
diff changeset
   509
         val subtrm = apply_subt (regularize_trm ctxt) (t, t')
952
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
   510
         val needrel = equiv_relation_chk ctxt (qnt_typ ty, qnt_typ ty')
906
a394c7337966 Ex1 -> Bex1 Regularization, Preparing Exeq.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 904
diff changeset
   511
       in
a394c7337966 Ex1 -> Bex1 Regularization, Preparing Exeq.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 904
diff changeset
   512
         if resrel <> needrel
952
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
   513
         then term_mismatch "regularize (Bex1_res)" ctxt resrel needrel
999
64874975f087 renamed function according to the name of the constant
Christian Urban <urbanc@in.tum.de>
parents: 982
diff changeset
   514
         else mk_bex1_rel $ resrel $ subtrm
946
46cc6708c3b3 Bex1_Bexeq_regular.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 944
diff changeset
   515
       end
46cc6708c3b3 Bex1_Bexeq_regular.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 944
diff changeset
   516
952
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
   517
  | (Const (@{const_name "Bex1"}, ty) $ (Const (@{const_name "Respects"}, _) $ resrel) $ t, 
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
   518
     Const (@{const_name "Ex1"}, ty') $ t') =>
946
46cc6708c3b3 Bex1_Bexeq_regular.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 944
diff changeset
   519
       let
46cc6708c3b3 Bex1_Bexeq_regular.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 944
diff changeset
   520
         val subtrm = apply_subt (regularize_trm ctxt) (t, t')
952
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
   521
         val needrel = equiv_relation_chk ctxt (qnt_typ ty, qnt_typ ty')
946
46cc6708c3b3 Bex1_Bexeq_regular.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 944
diff changeset
   522
       in
46cc6708c3b3 Bex1_Bexeq_regular.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 944
diff changeset
   523
         if resrel <> needrel
952
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
   524
         then term_mismatch "regularize (Bex1)" ctxt resrel needrel
999
64874975f087 renamed function according to the name of the constant
Christian Urban <urbanc@in.tum.de>
parents: 982
diff changeset
   525
         else mk_bex1_rel $ resrel $ subtrm
906
a394c7337966 Ex1 -> Bex1 Regularization, Preparing Exeq.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 904
diff changeset
   526
       end
a394c7337966 Ex1 -> Bex1 Regularization, Preparing Exeq.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 904
diff changeset
   527
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   528
  | (* 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
   529
    (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
   530
         if ty = ty' then rtrm
831
224909b9399f removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents: 830
diff changeset
   531
         else equiv_relation 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
   532
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   533
  | (* 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
   534
    (rel, Const (@{const_name "op ="}, ty')) =>
865
5c6d76c3ba5c Put relation_error as a separate function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 858
diff changeset
   535
       let
785
Christian Urban <urbanc@in.tum.de>
parents: 784
diff changeset
   536
         val rel_ty = fastype_of rel
831
224909b9399f removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents: 830
diff changeset
   537
         val rel' = equiv_relation_chk ctxt (domain_type rel_ty, domain_type ty') 
865
5c6d76c3ba5c Put relation_error as a separate function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 858
diff changeset
   538
       in
952
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
   539
         if rel' aconv rel then rtrm 
9c3b3eaecaff use of equiv_relation_chk in quotient_term
Christian Urban <urbanc@in.tum.de>
parents: 946
diff changeset
   540
         else term_mismatch "regularise (relation mismatch)" ctxt rel rel'
865
5c6d76c3ba5c Put relation_error as a separate function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 858
diff changeset
   541
       end
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   542
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   543
  | (_, Const _) =>
835
c4fa87dd0208 Fix for testing matching constants in regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 834
diff changeset
   544
       let
c4fa87dd0208 Fix for testing matching constants in regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 834
diff changeset
   545
         val thy = ProofContext.theory_of ctxt
867
9e247b9505f0 Moved the matches_typ function outside a?d simplified it.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 865
diff changeset
   546
         fun same_const (Const (s, T)) (Const (s', T')) = (s = s') andalso matches_typ thy T T'
835
c4fa87dd0208 Fix for testing matching constants in regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 834
diff changeset
   547
           | same_const _ _ = false
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   548
       in
835
c4fa87dd0208 Fix for testing matching constants in regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 834
diff changeset
   549
         if same_const rtrm qtrm then rtrm
c4fa87dd0208 Fix for testing matching constants in regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 834
diff changeset
   550
         else
c4fa87dd0208 Fix for testing matching constants in regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 834
diff changeset
   551
           let
891
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   552
             val rtrm' = #rconst (qconsts_lookup thy qtrm)
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   553
               handle NotFound => term_mismatch "regularize(constant notfound)" ctxt rtrm qtrm
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   554
           in
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   555
             if Pattern.matches thy (rtrm', rtrm)
7bac7dffadeb hom lifted to hom', so it is true. Infrastructure for partially regularized quantifiers. Nicer errors for regularize.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 890
diff changeset
   556
             then rtrm else term_mismatch "regularize(constant mismatch)" ctxt rtrm qtrm
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   557
           end
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   558
       end 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   559
1000
1893316b9ef8 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 999
diff changeset
   560
  | (((t1 as Const (@{const_name "split"}, _)) $ Abs (v1, ty, Abs(v1', ty', s1))),
1893316b9ef8 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 999
diff changeset
   561
     ((t2 as Const (@{const_name "split"}, _)) $ Abs (v2, _ , Abs(v2', _  , s2)))) =>
1893316b9ef8 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 999
diff changeset
   562
       regularize_trm ctxt (t1, t2) $ Abs (v1, ty, Abs (v1', ty', regularize_trm ctxt (s1, s2)))
944
6267ad688ea8 2 cases for regularize with split, lemmas with split now lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 909
diff changeset
   563
1000
1893316b9ef8 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 999
diff changeset
   564
  | (((t1 as Const (@{const_name "split"}, _)) $ Abs (v1, ty, s1)),
1893316b9ef8 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 999
diff changeset
   565
     ((t2 as Const (@{const_name "split"}, _)) $ Abs (v2, _ , s2))) =>
1893316b9ef8 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 999
diff changeset
   566
       regularize_trm ctxt (t1, t2) $ Abs (v1, ty, regularize_trm ctxt (s1, s2))
944
6267ad688ea8 2 cases for regularize with split, lemmas with split now lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 909
diff changeset
   567
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   568
  | (t1 $ t2, t1' $ t2') =>
1000
1893316b9ef8 slight tuning
Christian Urban <urbanc@in.tum.de>
parents: 999
diff changeset
   569
       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
   570
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   571
  | (Bound i, Bound i') =>
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   572
       if i = i' then rtrm 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   573
       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
   574
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   575
  | _ =>
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   576
       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
   577
         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
   578
         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
   579
       in
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   580
         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
   581
       end
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   582
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
   583
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
   584
  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
   585
  |> Syntax.check_term ctxt
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   586
797
35436401f00d added a functor that allows checking what is added to the theorem lists
Christian Urban <urbanc@in.tum.de>
parents: 796
diff changeset
   587
849
fa2b4b7af755 modifying comments/indentation in quotient_term.ml
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 836
diff changeset
   588
fa2b4b7af755 modifying comments/indentation in quotient_term.ml
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 836
diff changeset
   589
(*** Rep/Abs Injection ***)
795
a28f805df355 renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents: 792
diff changeset
   590
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   591
(*
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   592
Injection of Rep/Abs means:
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   593
849
fa2b4b7af755 modifying comments/indentation in quotient_term.ml
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 836
diff changeset
   594
  For abstractions:
fa2b4b7af755 modifying comments/indentation in quotient_term.ml
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 836
diff changeset
   595
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   596
  * 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
   597
    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
   598
 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   599
  For applications:
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   600
  
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   601
  * 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
   602
    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
   603
    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
   604
    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
   605
    arguments.
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   606
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   607
  For constants:
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   608
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   609
  * 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
   610
    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
   611
    and Rep/Abs around it. 
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   612
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   613
  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
   614
797
35436401f00d added a functor that allows checking what is added to the theorem lists
Christian Urban <urbanc@in.tum.de>
parents: 796
diff changeset
   615
  * We put a Rep/Abs around it if the type needs lifting.
760
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   616
c1989de100b4 various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents: 758
diff changeset
   617
  Vars case cannot occur.
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   618
*)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   619
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
   620
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
   621
  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
   622
833
129caba33c03 the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 832
diff changeset
   623
fun inj_repabs_err ctxt msg rtrm qtrm =
129caba33c03 the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 832
diff changeset
   624
let
129caba33c03 the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 832
diff changeset
   625
  val rtrm_str = Syntax.string_of_term ctxt rtrm
129caba33c03 the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 832
diff changeset
   626
  val qtrm_str = Syntax.string_of_term ctxt qtrm 
129caba33c03 the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 832
diff changeset
   627
in
129caba33c03 the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 832
diff changeset
   628
  raise LIFT_MATCH (space_implode " " [msg, quote rtrm_str, "and", quote qtrm_str])
129caba33c03 the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 832
diff changeset
   629
end
129caba33c03 the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 832
diff changeset
   630
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   631
849
fa2b4b7af755 modifying comments/indentation in quotient_term.ml
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 836
diff changeset
   632
(* bound variables need to be treated properly,
fa2b4b7af755 modifying comments/indentation in quotient_term.ml
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 836
diff changeset
   633
   as the type of subterms needs to be calculated   *)
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
   634
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
   635
 case (rtrm, qtrm) of
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   636
    (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
   637
       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
   638
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   639
  | (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
   640
       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
   641
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   642
  | (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
   643
      let
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   644
        val rty = fastype_of rtrm
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   645
        val qty = fastype_of qtrm
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   646
      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
   647
        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
   648
      end
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   649
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   650
  | (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
   651
      let
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   652
        val rty = fastype_of rtrm
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   653
        val qty = fastype_of qtrm
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   654
        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
   655
        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
   656
        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
   657
        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
   658
      in
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   659
        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
   660
        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
   661
      end
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   662
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   663
  | (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
   664
       (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
   665
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   666
  | (Free (_, T), Free (_, T')) => 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   667
        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
   668
        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
   669
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   670
  | (_, Const (@{const_name "op ="}, _)) => rtrm
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   671
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   672
  | (_, Const (_, T')) =>
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   673
      let
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   674
        val rty = fastype_of rtrm
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   675
      in 
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   676
        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
   677
        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
   678
      end   
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   679
  
833
129caba33c03 the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents: 832
diff changeset
   680
  | _ => inj_repabs_err ctxt "injection (default):" rtrm qtrm
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   681
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
   682
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
   683
  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
   684
  |> 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
   685
1072
6deecec6795f A procedure that properly instantiates the types too.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1071
diff changeset
   686
(*** Translating the goal automatically
6deecec6795f A procedure that properly instantiates the types too.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1071
diff changeset
   687
6deecec6795f A procedure that properly instantiates the types too.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1071
diff changeset
   688
Finds subterms of a term that can be lifted and:
6deecec6795f A procedure that properly instantiates the types too.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1071
diff changeset
   689
* replaces subterms matching lifted constants by the lifted constants
6deecec6795f A procedure that properly instantiates the types too.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1071
diff changeset
   690
* replaces equivalence relations by equalities
6deecec6795f A procedure that properly instantiates the types too.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1071
diff changeset
   691
* In constants, frees and schematic variables replaces
6deecec6795f A procedure that properly instantiates the types too.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1071
diff changeset
   692
  subtypes matching lifted types by those types *)
6deecec6795f A procedure that properly instantiates the types too.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1071
diff changeset
   693
1070
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   694
fun subst_ty thy ty (rty, qty) r =
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   695
  if r <> NONE then r else
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   696
  case try (Sign.typ_match thy (ty, rty)) Vartab.empty of
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   697
    SOME inst => SOME (Envir.subst_type inst qty)
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   698
  | NONE => NONE
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   699
fun subst_tys thy substs ty =
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   700
  case fold (subst_ty thy ty) substs NONE of
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   701
    SOME ty => ty
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   702
  | NONE =>
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   703
      (case ty of
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   704
        Type (s, tys) => Type (s, map (subst_tys thy substs) tys)
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   705
      | x => x)
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   706
1071
dde8ad700c5b More code abstracted away
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1070
diff changeset
   707
fun subst_trm thy t (rt, qt) s =
dde8ad700c5b More code abstracted away
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1070
diff changeset
   708
  if s <> NONE then s else
dde8ad700c5b More code abstracted away
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1070
diff changeset
   709
    case try (Pattern.match thy (t, rt)) (Vartab.empty, Vartab.empty) of
dde8ad700c5b More code abstracted away
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1070
diff changeset
   710
      SOME inst => SOME (Envir.subst_term inst qt)
dde8ad700c5b More code abstracted away
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1070
diff changeset
   711
    | NONE => NONE;
dde8ad700c5b More code abstracted away
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1070
diff changeset
   712
fun subst_trms thy substs t = fold (subst_trm thy t) substs NONE
dde8ad700c5b More code abstracted away
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1070
diff changeset
   713
1070
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   714
fun get_ty_trm_substs ctxt =
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   715
let
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   716
  val thy = ProofContext.theory_of ctxt
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   717
  val quot_infos = Quotient_Info.quotdata_dest ctxt
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   718
  val ty_substs = map (fn ri => (#rtyp ri, #qtyp ri)) quot_infos
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   719
  val const_infos = Quotient_Info.qconsts_dest ctxt
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   720
  val const_substs = map (fn ci => (#rconst ci, #qconst ci)) const_infos
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   721
  fun rel_eq rel = HOLogic.eq_const (subst_tys thy ty_substs (domain_type (fastype_of rel)))
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   722
  val rel_substs = map (fn ri => (#equiv_rel ri, rel_eq (#equiv_rel ri))) quot_infos
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   723
in
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   724
  (ty_substs, (const_substs @ rel_substs))
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   725
end
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   726
1065
3664eafcad09 The automatic lifting translation function, still with dummy types,
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1000
diff changeset
   727
fun quotient_lift_all ctxt t =
3664eafcad09 The automatic lifting translation function, still with dummy types,
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1000
diff changeset
   728
let
3664eafcad09 The automatic lifting translation function, still with dummy types,
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1000
diff changeset
   729
  val thy = ProofContext.theory_of ctxt
1070
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   730
  val (ty_substs, substs) = get_ty_trm_substs ctxt
1065
3664eafcad09 The automatic lifting translation function, still with dummy types,
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1000
diff changeset
   731
  fun lift_aux t =
1071
dde8ad700c5b More code abstracted away
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1070
diff changeset
   732
    case subst_trms thy substs t of
1065
3664eafcad09 The automatic lifting translation function, still with dummy types,
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1000
diff changeset
   733
      SOME x => x
3664eafcad09 The automatic lifting translation function, still with dummy types,
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1000
diff changeset
   734
    | NONE =>
1070
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   735
      (case t of
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   736
        a $ b => lift_aux a $ lift_aux b
1072
6deecec6795f A procedure that properly instantiates the types too.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1071
diff changeset
   737
      | Abs(a, ty, s) =>
6deecec6795f A procedure that properly instantiates the types too.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1071
diff changeset
   738
          let
6deecec6795f A procedure that properly instantiates the types too.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1071
diff changeset
   739
            val (y, s') = Term.dest_abs (a, ty, s)
6deecec6795f A procedure that properly instantiates the types too.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1071
diff changeset
   740
            val nty = subst_tys thy ty_substs ty
6deecec6795f A procedure that properly instantiates the types too.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1071
diff changeset
   741
          in
6deecec6795f A procedure that properly instantiates the types too.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1071
diff changeset
   742
          Abs(y, nty, abstract_over (Free (y, nty), (lift_aux s')))
1070
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   743
          end
1072
6deecec6795f A procedure that properly instantiates the types too.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1071
diff changeset
   744
      | Free(n, ty) => Free(n, subst_tys thy ty_substs ty)
6deecec6795f A procedure that properly instantiates the types too.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1071
diff changeset
   745
      | Var(n, ty) => Var(n, subst_tys thy ty_substs ty)
1070
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   746
      | Bound i => Bound i
1072
6deecec6795f A procedure that properly instantiates the types too.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1071
diff changeset
   747
      | Const(s, ty) => Const(s, subst_tys thy ty_substs ty))
1065
3664eafcad09 The automatic lifting translation function, still with dummy types,
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1000
diff changeset
   748
in
3664eafcad09 The automatic lifting translation function, still with dummy types,
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1000
diff changeset
   749
  lift_aux t
3664eafcad09 The automatic lifting translation function, still with dummy types,
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1000
diff changeset
   750
end
3664eafcad09 The automatic lifting translation function, still with dummy types,
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1000
diff changeset
   751
1070
a8518879ee20 A bit more intelligent and cleaner code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1065
diff changeset
   752
1072
6deecec6795f A procedure that properly instantiates the types too.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1071
diff changeset
   753
758
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   754
end; (* structure *)
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   755
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   756
3104d62e7a16 moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   757