src/HOL/HOLCF/Tools/cpodef.ML
changeset 49833 1d80798e8d8a
parent 49759 ecf1d5d87e5e
child 49835 31f32ec4d766
equal deleted inserted replaced
49832:2af09163cba1 49833:1d80798e8d8a
    56 fun adm_const T = Const (@{const_name adm}, (T --> HOLogic.boolT) --> HOLogic.boolT)
    56 fun adm_const T = Const (@{const_name adm}, (T --> HOLogic.boolT) --> HOLogic.boolT)
    57 fun mk_adm (x, T, P) = adm_const T $ absfree (x, T) P
    57 fun mk_adm (x, T, P) = adm_const T $ absfree (x, T) P
    58 
    58 
    59 fun below_const T = Const (@{const_name below}, T --> T --> HOLogic.boolT)
    59 fun below_const T = Const (@{const_name below}, T --> T --> HOLogic.boolT)
    60 
    60 
    61 (* manipulating theorems *)
       
    62 
       
    63 fun fold_adm_mem thm NONE = thm
       
    64   | fold_adm_mem thm (SOME set_def) =
       
    65     let val rule = @{lemma "A == B ==> adm (%x. x : B) ==> adm (%x. x : A)" by simp}
       
    66     in rule OF [set_def, thm] end
       
    67 
       
    68 fun fold_bottom_mem thm NONE = thm
       
    69   | fold_bottom_mem thm (SOME set_def) =
       
    70     let val rule = @{lemma "A == B ==> bottom : B ==> bottom : A" by simp}
       
    71     in rule OF [set_def, thm] end
       
    72 
       
    73 (* proving class instances *)
    61 (* proving class instances *)
    74 
    62 
    75 fun prove_cpo
    63 fun prove_cpo
    76       (name: binding)
    64       (name: binding)
    77       (newT: typ)
    65       (newT: typ)
    78       (Rep_name: binding, Abs_name: binding)
    66       (Rep_name: binding, Abs_name: binding)
    79       (type_definition: thm)  (* type_definition Rep Abs A *)
    67       (type_definition: thm)  (* type_definition Rep Abs A *)
    80       (set_def: thm option)   (* A == set *)
       
    81       (below_def: thm)        (* op << == %x y. Rep x << Rep y *)
    68       (below_def: thm)        (* op << == %x y. Rep x << Rep y *)
    82       (admissible: thm)       (* adm (%x. x : set) *)
    69       (admissible: thm)       (* adm (%x. x : set) *)
    83       (thy: theory)
    70       (thy: theory)
    84     =
    71     =
    85   let
    72   let
    86     val admissible' = fold_adm_mem admissible set_def
    73     val cpo_thms = map (Thm.transfer thy) [type_definition, below_def, admissible]
    87     val cpo_thms = map (Thm.transfer thy) [type_definition, below_def, admissible']
       
    88     val (full_tname, Ts) = dest_Type newT
    74     val (full_tname, Ts) = dest_Type newT
    89     val lhs_sorts = map (snd o dest_TFree) Ts
    75     val lhs_sorts = map (snd o dest_TFree) Ts
    90     val tac = Tactic.rtac (@{thm typedef_cpo} OF cpo_thms) 1
    76     val tac = Tactic.rtac (@{thm typedef_cpo} OF cpo_thms) 1
    91     val thy = AxClass.prove_arity (full_tname, lhs_sorts, @{sort cpo}) tac thy
    77     val thy = AxClass.prove_arity (full_tname, lhs_sorts, @{sort cpo}) tac thy
    92     (* transfer thms so that they will know about the new cpo instance *)
    78     (* transfer thms so that they will know about the new cpo instance *)
    98     val compact = make @{thm typedef_compact}
    84     val compact = make @{thm typedef_compact}
    99     val (_, thy) =
    85     val (_, thy) =
   100       thy
    86       thy
   101       |> Sign.add_path (Binding.name_of name)
    87       |> Sign.add_path (Binding.name_of name)
   102       |> Global_Theory.add_thms
    88       |> Global_Theory.add_thms
   103         ([((Binding.prefix_name "adm_"      name, admissible'), []),
    89         ([((Binding.prefix_name "adm_"      name, admissible), []),
   104           ((Binding.prefix_name "cont_" Rep_name, cont_Rep   ), []),
    90           ((Binding.prefix_name "cont_" Rep_name, cont_Rep  ), []),
   105           ((Binding.prefix_name "cont_" Abs_name, cont_Abs   ), []),
    91           ((Binding.prefix_name "cont_" Abs_name, cont_Abs  ), []),
   106           ((Binding.prefix_name "lub_"      name, lub        ), []),
    92           ((Binding.prefix_name "lub_"      name, lub       ), []),
   107           ((Binding.prefix_name "compact_"  name, compact    ), [])])
    93           ((Binding.prefix_name "compact_"  name, compact   ), [])])
   108       ||> Sign.parent_path
    94       ||> Sign.parent_path
   109     val cpo_info : cpo_info =
    95     val cpo_info : cpo_info =
   110       { below_def = below_def, adm = admissible', cont_Rep = cont_Rep,
    96       { below_def = below_def, adm = admissible, cont_Rep = cont_Rep,
   111         cont_Abs = cont_Abs, lub = lub, compact = compact }
    97         cont_Abs = cont_Abs, lub = lub, compact = compact }
   112   in
    98   in
   113     (cpo_info, thy)
    99     (cpo_info, thy)
   114   end
   100   end
   115 
   101 
   116 fun prove_pcpo
   102 fun prove_pcpo
   117       (name: binding)
   103       (name: binding)
   118       (newT: typ)
   104       (newT: typ)
   119       (Rep_name: binding, Abs_name: binding)
   105       (Rep_name: binding, Abs_name: binding)
   120       (type_definition: thm)  (* type_definition Rep Abs A *)
   106       (type_definition: thm)  (* type_definition Rep Abs A *)
   121       (set_def: thm option)   (* A == set *)
       
   122       (below_def: thm)        (* op << == %x y. Rep x << Rep y *)
   107       (below_def: thm)        (* op << == %x y. Rep x << Rep y *)
   123       (bottom_mem: thm)       (* bottom : set *)
   108       (bottom_mem: thm)       (* bottom : set *)
   124       (thy: theory)
   109       (thy: theory)
   125     =
   110     =
   126   let
   111   let
   127     val bottom_mem' = fold_bottom_mem bottom_mem set_def
   112     val pcpo_thms = map (Thm.transfer thy) [type_definition, below_def, bottom_mem]
   128     val pcpo_thms = map (Thm.transfer thy) [type_definition, below_def, bottom_mem']
       
   129     val (full_tname, Ts) = dest_Type newT
   113     val (full_tname, Ts) = dest_Type newT
   130     val lhs_sorts = map (snd o dest_TFree) Ts
   114     val lhs_sorts = map (snd o dest_TFree) Ts
   131     val tac = Tactic.rtac (@{thm typedef_pcpo} OF pcpo_thms) 1
   115     val tac = Tactic.rtac (@{thm typedef_pcpo} OF pcpo_thms) 1
   132     val thy = AxClass.prove_arity (full_tname, lhs_sorts, @{sort pcpo}) tac thy
   116     val thy = AxClass.prove_arity (full_tname, lhs_sorts, @{sort pcpo}) tac thy
   133     val pcpo_thms' = map (Thm.transfer thy) pcpo_thms
   117     val pcpo_thms' = map (Thm.transfer thy) pcpo_thms
   182 
   166 
   183 fun add_podef typ set opt_morphs tac thy =
   167 fun add_podef typ set opt_morphs tac thy =
   184   let
   168   let
   185     val name = #1 typ
   169     val name = #1 typ
   186     val ((full_tname, info as ({Rep_name, ...}, {type_definition, ...})), thy) = thy
   170     val ((full_tname, info as ({Rep_name, ...}, {type_definition, ...})), thy) = thy
   187       |> Typedef.add_typedef_global false NONE typ set opt_morphs tac
   171       |> Typedef.add_typedef_global NONE typ set opt_morphs tac
   188     val oldT = #rep_type (#1 info)
   172     val oldT = #rep_type (#1 info)
   189     val newT = #abs_type (#1 info)
   173     val newT = #abs_type (#1 info)
   190     val lhs_tfrees = map dest_TFree (snd (dest_Type newT))
   174     val lhs_tfrees = map dest_TFree (snd (dest_Type newT))
   191 
   175 
   192     val RepC = Const (Rep_name, newT --> oldT)
   176     val RepC = Const (Rep_name, newT --> oldT)
   220     val goal_admissible =
   204     val goal_admissible =
   221       HOLogic.mk_Trueprop (mk_adm ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set)))
   205       HOLogic.mk_Trueprop (mk_adm ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set)))
   222 
   206 
   223     fun cpodef_result nonempty admissible thy =
   207     fun cpodef_result nonempty admissible thy =
   224       let
   208       let
   225         val ((info as (_, {type_definition, set_def, ...}), below_def), thy) = thy
   209         val ((info as (_, {type_definition, ...}), below_def), thy) = thy
   226           |> add_podef typ set opt_morphs (Tactic.rtac nonempty 1)
   210           |> add_podef typ set opt_morphs (Tactic.rtac nonempty 1)
   227         val (cpo_info, thy) = thy
   211         val (cpo_info, thy) = thy
   228           |> prove_cpo name newT morphs type_definition set_def below_def admissible
   212           |> prove_cpo name newT morphs type_definition below_def admissible
   229       in
   213       in
   230         ((info, cpo_info), thy)
   214         ((info, cpo_info), thy)
   231       end
   215       end
   232   in
   216   in
   233     (goal_nonempty, goal_admissible, cpodef_result)
   217     (goal_nonempty, goal_admissible, cpodef_result)
   254       HOLogic.mk_Trueprop (mk_adm ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set)))
   238       HOLogic.mk_Trueprop (mk_adm ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set)))
   255 
   239 
   256     fun pcpodef_result bottom_mem admissible thy =
   240     fun pcpodef_result bottom_mem admissible thy =
   257       let
   241       let
   258         val tac = Tactic.rtac exI 1 THEN Tactic.rtac bottom_mem 1
   242         val tac = Tactic.rtac exI 1 THEN Tactic.rtac bottom_mem 1
   259         val ((info as (_, {type_definition, set_def, ...}), below_def), thy) = thy
   243         val ((info as (_, {type_definition, ...}), below_def), thy) = thy
   260           |> add_podef typ set opt_morphs tac
   244           |> add_podef typ set opt_morphs tac
   261         val (cpo_info, thy) = thy
   245         val (cpo_info, thy) = thy
   262           |> prove_cpo name newT morphs type_definition set_def below_def admissible
   246           |> prove_cpo name newT morphs type_definition below_def admissible
   263         val (pcpo_info, thy) = thy
   247         val (pcpo_info, thy) = thy
   264           |> prove_pcpo name newT morphs type_definition set_def below_def bottom_mem
   248           |> prove_pcpo name newT morphs type_definition below_def bottom_mem
   265       in
   249       in
   266         ((info, cpo_info, pcpo_info), thy)
   250         ((info, cpo_info, pcpo_info), thy)
   267       end
   251       end
   268   in
   252   in
   269     (goal_bottom_mem, goal_admissible, pcpodef_result)
   253     (goal_bottom_mem, goal_admissible, pcpodef_result)