src/HOL/Tools/transfer.ML
changeset 47635 ebb79474262c
parent 47618 1568dadd598a
child 47658 7631f6f7873d
equal deleted inserted replaced
47634:091bcd569441 47635:ebb79474262c
    10   val prep_conv: conv
    10   val prep_conv: conv
    11   val get_relator_eq: Proof.context -> thm list
    11   val get_relator_eq: Proof.context -> thm list
    12   val transfer_add: attribute
    12   val transfer_add: attribute
    13   val transfer_del: attribute
    13   val transfer_del: attribute
    14   val transfer_tac: Proof.context -> int -> tactic
    14   val transfer_tac: Proof.context -> int -> tactic
    15   val correspondence_tac: Proof.context -> int -> tactic
    15   val transfer_prover_tac: Proof.context -> int -> tactic
    16   val setup: theory -> theory
    16   val setup: theory -> theory
    17   val abs_tac: int -> tactic
    17   val abs_tac: int -> tactic
    18 end
    18 end
    19 
    19 
    20 structure Transfer : TRANSFER =
    20 structure Transfer : TRANSFER =
    21 struct
    21 struct
    22 
    22 
    23 structure Data = Named_Thms
    23 structure Data = Named_Thms
    24 (
    24 (
    25   val name = @{binding transfer_raw}
    25   val name = @{binding transfer_raw}
    26   val description = "raw correspondence rule for transfer method"
    26   val description = "raw transfer rule for transfer method"
    27 )
    27 )
    28 
    28 
    29 structure Relator_Eq = Named_Thms
    29 structure Relator_Eq = Named_Thms
    30 (
    30 (
    31   val name = @{binding relator_eq}
    31   val name = @{binding relator_eq}
    69       else_conv
    69       else_conv
    70       Conv.abs_conv (fo_conv o snd) ctxt then_conv Abs_conv
    70       Conv.abs_conv (fo_conv o snd) ctxt then_conv Abs_conv
    71       else_conv
    71       else_conv
    72       Conv.all_conv) ct
    72       Conv.all_conv) ct
    73 
    73 
    74 (* Conversion to preprocess a correspondence rule *)
    74 (* Conversion to preprocess a transfer rule *)
    75 fun prep_conv ct = (
    75 fun prep_conv ct = (
    76       Conv.implies_conv Conv.all_conv prep_conv
    76       Conv.implies_conv Conv.all_conv prep_conv
    77       else_conv
    77       else_conv
    78       Trueprop_conv (Conv.fun_conv (Conv.fun_conv Rel_conv))
    78       Trueprop_conv (Conv.fun_conv (Conv.fun_conv Rel_conv))
    79       else_conv
    79       else_conv
    80       Conv.all_conv) ct
    80       Conv.all_conv) ct
    81 
    81 
    82 (* Conversion to prep a proof goal containing a correspondence rule *)
    82 (* Conversion to prep a proof goal containing a transfer rule *)
    83 fun correspond_conv ctxt ct = (
    83 fun transfer_goal_conv ctxt ct = (
    84       Conv.forall_conv (correspond_conv o snd) ctxt
    84       Conv.forall_conv (transfer_goal_conv o snd) ctxt
    85       else_conv
    85       else_conv
    86       Conv.implies_conv Conv.all_conv (correspond_conv ctxt)
    86       Conv.implies_conv Conv.all_conv (transfer_goal_conv ctxt)
    87       else_conv
    87       else_conv
    88       Trueprop_conv
    88       Trueprop_conv
    89       (Conv.combination_conv (Conv.fun_conv Rel_conv) (fo_conv ctxt))
    89       (Conv.combination_conv (Conv.fun_conv Rel_conv) (fo_conv ctxt))
    90       else_conv
    90       else_conv
    91       Conv.all_conv) ct
    91       Conv.all_conv) ct
   147        (* FIXME: rewrite_goal_tac does unwanted eta-contraction *)
   147        (* FIXME: rewrite_goal_tac does unwanted eta-contraction *)
   148        rewrite_goal_tac post_simps i,
   148        rewrite_goal_tac post_simps i,
   149        rtac @{thm _} i]
   149        rtac @{thm _} i]
   150   end)
   150   end)
   151 
   151 
   152 fun correspondence_tac ctxt i =
   152 fun transfer_prover_tac ctxt i =
   153   let
   153   let
   154     val rules = @{thms Rel_App Rel_Abs} @ Data.get ctxt
   154     val rules = @{thms Rel_App Rel_Abs} @ Data.get ctxt
   155   in
   155   in
   156     EVERY
   156     EVERY
   157       [CONVERSION (correspond_conv ctxt) i,
   157       [CONVERSION (transfer_goal_conv ctxt) i,
   158        rtac @{thm correspondence_start} i,
   158        rtac @{thm transfer_prover_start} i,
   159        REPEAT_ALL_NEW
   159        REPEAT_ALL_NEW
   160          (resolve_tac rules ORELSE' atac ORELSE' eq_tac ctxt) (i+1),
   160          (resolve_tac rules ORELSE' atac ORELSE' eq_tac ctxt) (i+1),
   161        rewrite_goal_tac @{thms App_def Abs_def} i,
   161        rewrite_goal_tac @{thms App_def Abs_def} i,
   162        rtac @{thm refl} i]
   162        rtac @{thm refl} i]
   163   end
   163   end
   170 
   170 
   171 val transfer_method : (Proof.context -> Method.method) context_parser =
   171 val transfer_method : (Proof.context -> Method.method) context_parser =
   172   fixing >> (fn vs => fn ctxt =>
   172   fixing >> (fn vs => fn ctxt =>
   173     SIMPLE_METHOD' (gen_frees_tac vs ctxt THEN' transfer_tac ctxt))
   173     SIMPLE_METHOD' (gen_frees_tac vs ctxt THEN' transfer_tac ctxt))
   174 
   174 
   175 val correspondence_method : (Proof.context -> Method.method) context_parser =
   175 val transfer_prover_method : (Proof.context -> Method.method) context_parser =
   176   Scan.succeed (fn ctxt => SIMPLE_METHOD' (correspondence_tac ctxt))
   176   Scan.succeed (fn ctxt => SIMPLE_METHOD' (transfer_prover_tac ctxt))
   177 
   177 
   178 (* Attribute for correspondence rules *)
   178 (* Attribute for transfer rules *)
   179 
   179 
   180 val prep_rule = Conv.fconv_rule prep_conv
   180 val prep_rule = Conv.fconv_rule prep_conv
   181 
   181 
   182 val transfer_add =
   182 val transfer_add =
   183   Thm.declaration_attribute (Data.add_thm o prep_rule)
   183   Thm.declaration_attribute (Data.add_thm o prep_rule)
   192 
   192 
   193 val setup =
   193 val setup =
   194   Data.setup
   194   Data.setup
   195   #> Relator_Eq.setup
   195   #> Relator_Eq.setup
   196   #> Attrib.setup @{binding transfer_rule} transfer_attribute
   196   #> Attrib.setup @{binding transfer_rule} transfer_attribute
   197      "correspondence rule for transfer method"
   197      "transfer rule for transfer method"
   198   #> Method.setup @{binding transfer} transfer_method
   198   #> Method.setup @{binding transfer} transfer_method
   199      "generic theorem transfer method"
   199      "generic theorem transfer method"
   200   #> Method.setup @{binding correspondence} correspondence_method
   200   #> Method.setup @{binding transfer_prover} transfer_prover_method
   201      "for proving correspondence rules"
   201      "for proving transfer rules"
   202 
   202 
   203 end
   203 end