src/HOL/BNF/Tools/bnf_fp_rec_sugar_util.ML
changeset 53731 aed1ee95cdfe
parent 53729 b9d727a767ea
child 53732 e2c0d0426d2b
equal deleted inserted replaced
53730:f2f6874893df 53731:aed1ee95cdfe
    57     term
    57     term
    58   val massage_indirect_corec_call: Proof.context -> (term -> bool) ->
    58   val massage_indirect_corec_call: Proof.context -> (term -> bool) ->
    59     (typ -> typ -> term -> term) -> typ list -> typ -> term -> term
    59     (typ -> typ -> term -> term) -> typ list -> typ -> term -> term
    60   val expand_corec_code_rhs: Proof.context -> (term -> bool) -> typ list -> term -> term
    60   val expand_corec_code_rhs: Proof.context -> (term -> bool) -> typ list -> term -> term
    61   val massage_corec_code_rhs: Proof.context -> (term -> term list -> term) -> typ -> term -> term
    61   val massage_corec_code_rhs: Proof.context -> (term -> term list -> term) -> typ -> term -> term
       
    62   val fold_rev_corec_code_rhs: (term -> term list -> 'a -> 'a) -> term -> 'a -> 'a
    62   val simplify_bool_ifs: theory -> term -> term list
    63   val simplify_bool_ifs: theory -> term -> term list
    63   val rec_specs_of: binding list -> typ list -> typ list -> (term -> int list) ->
    64   val rec_specs_of: binding list -> typ list -> typ list -> (term -> int list) ->
    64     ((term * term list list) list) list -> local_theory ->
    65     ((term * term list list) list) list -> local_theory ->
    65     (bool * rec_spec list * typ list * thm * thm list) * local_theory
    66     (bool * rec_spec list * typ list * thm * thm list) * local_theory
    66   val corec_specs_of: binding list -> typ list -> typ list -> (term -> int list) ->
    67   val corec_specs_of: binding list -> typ list -> typ list -> (term -> int list) ->
   205       | (Const (@{const_name If}, _), arg :: args) =>
   206       | (Const (@{const_name If}, _), arg :: args) =>
   206         list_comb (If_const U $ tap check_cond arg, map massage_rec args)
   207         list_comb (If_const U $ tap check_cond arg, map massage_rec args)
   207       | _ => massage_leaf t)
   208       | _ => massage_leaf t)
   208   in
   209   in
   209     massage_rec
   210     massage_rec
       
   211   end;
       
   212 
       
   213 fun fold_rev_let_and_if f =
       
   214   let
       
   215     fun fld t =
       
   216       (case Term.strip_comb t of
       
   217         (Const (@{const_name Let}, _), [arg1, arg2]) => fld (betapply (arg2, arg1))
       
   218       | (Const (@{const_name If}, _), _ :: args) => fold_rev fld args
       
   219       | _ => f t)
       
   220   in
       
   221     fld
   210   end;
   222   end;
   211 
   223 
   212 fun massage_direct_corec_call ctxt has_call massage_direct_call U t =
   224 fun massage_direct_corec_call ctxt has_call massage_direct_call U t =
   213   massage_let_and_if ctxt has_call massage_direct_call U t;
   225   massage_let_and_if ctxt has_call massage_direct_call U t;
   214 
   226 
   296   | _ => raise Fail "expand_corec_code_rhs");
   308   | _ => raise Fail "expand_corec_code_rhs");
   297 
   309 
   298 fun massage_corec_code_rhs ctxt massage_ctr =
   310 fun massage_corec_code_rhs ctxt massage_ctr =
   299   massage_let_and_if ctxt (K false) (uncurry massage_ctr o Term.strip_comb);
   311   massage_let_and_if ctxt (K false) (uncurry massage_ctr o Term.strip_comb);
   300 
   312 
       
   313 fun fold_rev_corec_code_rhs f = fold_rev_let_and_if (uncurry f o Term.strip_comb);
       
   314 
   301 fun add_conjuncts (Const (@{const_name conj}, _) $ t $ t') = add_conjuncts t o add_conjuncts t'
   315 fun add_conjuncts (Const (@{const_name conj}, _) $ t $ t') = add_conjuncts t o add_conjuncts t'
   302   | add_conjuncts t = cons t;
   316   | add_conjuncts t = cons t;
   303 
   317 
   304 fun conjuncts t = add_conjuncts t [];
   318 fun conjuncts t = add_conjuncts t [];
   305 
   319