6
$\begingroup$

After solving a differential equation I obtain a pure function which I wish to simplify.

I am able to simplify the corresponding expression

expr = Cos[x] Cot[g] / Sqrt[-Cos[a]^2 Cot[g]^2 + Sin[a]^2]

according to the relationship k == Sin[a] / Cos[g] using a replacement followed by simplification with assumptions:

expr /. a -> ArcSin[k Cos[g]] // FullSimplify[#, 0 < g < Pi/2] &
(* Cos[x] / Sqrt[-1 + k^2] *) (* hooray *)

However if I attempt the same thing with the pure function (which is the output of some DSolve command)

fun = Function[{x}, Cos[x] Cot[g] / Sqrt[-Cos[a]^2 Cot[g]^2 + Sin[a]^2]]

it doesn't work:

fun  /. a -> ArcSin[k Cos[g]] // FullSimplify[#, 0 < g < Pi/2] &
(* Function[{x}, Cos[x] Cot[g] / Sqrt[-Cos[ArcSin[k Cos[g]]]^2 Cot[g]^2 + Sin[ArcSin[k Cos[g]]]^2]] *)

How do I get the body of the pure function to simplify in the same way as it does with the expression? (i.e. desired output is Function[{x}, Cos[x] / Sqrt[-1 + k^2]] )

$\endgroup$
6
$\begingroup$
fun = Function[{x}, Cos[x] Cot[g]/Sqrt[-Cos[a]^2 Cot[g]^2 + Sin[a]^2]];

fun[[2]] = 
  FullSimplify[fun[[2]] /. a -> ArcSin[k Cos[g]], 0 < g < Pi/2];

fun

enter image description here

$\endgroup$
2
$\begingroup$
simp = FullSimplify[#, 0 < g < Pi/2] &;
rule = a -> ArcSin[k Cos[g]];
(*Method 1*)
Function[x, #] &@simp[fun@x /. rule]
(*Method 2*)
Replace[fun /. rule, expr_ :> RuleCondition@simp@expr, {1}]
(*Method 3*)
fun /. f : Function :> Hold@f /. rule // simp // ReleaseHold
(*Method 4*)
simp[fun /. Function -> func /. rule] /. func -> Function
$\endgroup$
2
$\begingroup$

Try this:

fun /. {
 Verbatim[Function][args_,expr_]:> 
  Function[args, Evaluate@FullSimplify[expr/. a -> ArcSin[k Cos[g]], 0 < g < Pi/2 ]]
 }

Of course you can do this with any command you want to apply to the pure function.

$\endgroup$
  • 2
    $\begingroup$ I think the body FullSimplify[...] needs // Evaluate; otherwise good. $\endgroup$ – lastresort Jul 6 '17 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.