src/HOL/Tools/Quotient/quotient_term.ML
changeset 80677 6fedd6d3fa41
parent 80675 e9beaa28645d
child 80687 9b29c5d7aae4
equal deleted inserted replaced
80676:32073335a8e9 80677:6fedd6d3fa41
    53 datatype flag = AbsF | RepF
    53 datatype flag = AbsF | RepF
    54 
    54 
    55 fun negF AbsF = RepF
    55 fun negF AbsF = RepF
    56   | negF RepF = AbsF
    56   | negF RepF = AbsF
    57 
    57 
    58 fun is_identity (Const (\<^const_name>\<open>id\<close>, _)) = true
    58 fun is_identity \<^Const_>\<open>id _\<close> = true
    59   | is_identity _ = false
    59   | is_identity _ = false
    60 
       
    61 fun mk_identity ty = Const (\<^const_name>\<open>id\<close>, ty --> ty)
       
    62 
    60 
    63 fun mk_fun_compose flag (trm1, trm2) =
    61 fun mk_fun_compose flag (trm1, trm2) =
    64   case flag of
    62   case flag of
    65     AbsF => Const (\<^const_name>\<open>comp\<close>, dummyT) $ trm1 $ trm2
    63     AbsF => Const (\<^const_name>\<open>comp\<close>, dummyT) $ trm1 $ trm2
    66   | RepF => Const (\<^const_name>\<open>comp\<close>, dummyT) $ trm2 $ trm1
    64   | RepF => Const (\<^const_name>\<open>comp\<close>, dummyT) $ trm2 $ trm1
   189         else 
   187         else 
   190           raise LIFT_MATCH ("No map function for type " ^ quote s ^ " found.")
   188           raise LIFT_MATCH ("No map function for type " ^ quote s ^ " found.")
   191       end
   189       end
   192   in
   190   in
   193     if rty = qty
   191     if rty = qty
   194     then mk_identity rty
   192     then \<^Const>\<open>id rty\<close>
   195     else
   193     else
   196       case (rty, qty) of
   194       case (rty, qty) of
   197         (Type (s, tys), Type (s', tys')) =>
   195         (Type (s, tys), Type (s', tys')) =>
   198           if s = s'
   196           if s = s'
   199           then
   197           then
   233                     end
   231                     end
   234                 end
   232                 end
   235             end
   233             end
   236       | (TFree x, TFree x') =>
   234       | (TFree x, TFree x') =>
   237           if x = x'
   235           if x = x'
   238           then mk_identity rty
   236           then \<^Const>\<open>id rty\<close>
   239           else raise (LIFT_MATCH "absrep_fun (frees)")
   237           else raise (LIFT_MATCH "absrep_fun (frees)")
   240       | (TVar _, TVar _) => raise (LIFT_MATCH "absrep_fun (vars)")
   238       | (TVar _, TVar _) => raise (LIFT_MATCH "absrep_fun (vars)")
   241       | _ => raise (LIFT_MATCH "absrep_fun (default)")
   239       | _ => raise (LIFT_MATCH "absrep_fun (default)")
   242   end
   240   end
   243 
   241 
   262     val ty_inst = Sign.typ_match thy (trm_ty, ty) Vartab.empty
   260     val ty_inst = Sign.typ_match thy (trm_ty, ty) Vartab.empty
   263   in
   261   in
   264     map_types (Envir.subst_type ty_inst) trm
   262     map_types (Envir.subst_type ty_inst) trm
   265   end
   263   end
   266 
   264 
   267 fun is_eq (Const (\<^const_name>\<open>HOL.eq\<close>, _)) = true
   265 fun is_eq \<^Const_>\<open>HOL.eq _\<close> = true
   268   | is_eq _ = false
   266   | is_eq _ = false
   269 
   267 
   270 fun mk_rel_compose (trm1, trm2) =
   268 fun mk_rel_compose (trm1, trm2) =
   271   Const (\<^const_abbrev>\<open>rel_conj\<close>, dummyT) $ trm1 $ trm2
   269   Const (\<^const_abbrev>\<open>rel_conj\<close>, dummyT) $ trm1 $ trm2
   272 
   270