ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 07 Sep 2016 18:16:13 +0200Replacing mathematical functions of expressions with different mathematical functions of the same expressionhttps://ask.sagemath.org/question/34767/replacing-mathematical-functions-of-expressions-with-different-mathematical-functions-of-the-same-expression/Hello!
I am trying to replace hyperbolic trig with it's expanded form. As a concrete example I would like to replace
arcsinh(z) = ln( z + sqrt(z^2 + 1) )
Now I can do this if I knew that it was actually arcsinh(z) using subs, specifically using the command;
test = arcsinh(z)
test2 = test.subs_expr(arcsinh(z) == (log (z + sqrt((z^2 + 1))) )
The problem is that this seems to work only if it's an exact string match. Meaning if I tried;
test = arcsinh(1/3*x + 1/3)
test2 = test.subs_expr(arcsinh(z) == (log (z + sqrt((z^2 + 1))) )
I get
test2 = arcsinh(1/3*x + 1/3)
Is there a way to replace anything of the form
arcsinh(stuff) -> log (stuff + sqrt((stuff)^2 + 1))
Or does sage have this built in somewhere? I want to ideally make a sage function that I can pass a (randomly generated) mathematical expression to and have it expand the hyperbolic pieces for me. Thus I won't know the argument of the hyperbolic beforehand most of the time.
To give a concrete example, I would like to have something along the following:
a = random(1,1000)
b = random(1,1000)
f = a*arcsinh(b*x + a^2) - b
f2 = f.magicsimplifyfunction()
and get out
f2 = a*log (b*x + a^2 + sqrt((b*x + a^2)^2 + 1)) - b
Where the magicsimplifyfunction is the function that will work on any such f, not tailored to that specific f.
Thanks!
Edit for clarity:
I need a solution that doesn't require me to know the argument of arcsinh beforehand. So the magicsimplyfunction would work something like this:
f = 5*arcsinh(3*x + 1) - 2*e^x + 6*x*arcsinh(x^2)
Applying the simplify function would then "capture" the arguments 3*x+1 and x^2 as dummy variable z1 and z2 respectively and replace them so it would look like the following:
f = 5*arcsinh(z1) - 2*e^x + 6*x*arcsinh(z2)
z1 = 3*x + 1
z2 = x^2
Then I would apply subs_expr to get the following:
f = 5*(log(z1 + sqrt(z1^2 + 1))) - 2*e^x +6*x*(log(z2 + sqrt(z2^2 + 1)))
Then compose back in (or more accurately use another subs_expr) z1 and z2 to finally get
f = 5*(log(3*x+1 + sqrt((3*x+1)^2 + 1))) - 2*e^x +6*x*(log(x^2 + sqrt(x^4 + 1)))
The important thing here is nowhere in the process of executing the "magicsimplifyfunction" command did I specify 3x+1 or x^2. Because in most cases I won't know that's the argument before I am trying to expand it.Jason021Wed, 07 Sep 2016 18:16:13 +0200https://ask.sagemath.org/question/34767/