-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
functions: Implemented an _eval_expand_trig method for tanh #21380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
functions: Implemented an _eval_expand_trig method for tanh #21380
Conversation
expand_trig now works to expand tanh. tanh(coeff*x) will be expanded to coeff*tanh(x). Additionally, tanh now detects double and half angle formulas, so if coeff is 2 or .5, it will be epanded into the formulas below. tanh half angle formula: tanh(.5*x) = (cosh(x)-1)/sinh(x) tanh double angle formula: tanh(2x) = 2*tanh(x)/(1+tanh^2(x)) Finally _eval_expand_trig also expands tanh(x+y) using the sum of arguments identity below. tanh(x+y) = (tanh(x)+tanh(y))/(1+tanh(x)*tanh(y)) Example: >>> from sympy import * >>> x = Symbol('x') >>> y = Symbol('y') >>> expand_trig(tanh(x + y)) (tanh(x) + tanh(y))/(tanh(x)*tanh(y) + 1) >>> expand_trig(tanh(2*x)) 2*tanh(x)/(tanh(x)**2 + 1) >>> expand_trig(tanh(3*x)) 3*tanh(x) >>> expand_trig(tanh(y*x)) tanh(x*y) >>> expand_trig(tanh((1/2)*x)) (cosh(x) - 1)/sinh(x)
✅ Hi, I am the SymPy bot (v161). I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like: This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.9. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
-removed unused code: *(1)**((i % 4)//2) -cleaned up logic accordingly
Does this also work with n-ary addition? |
Yes it does work with n-ary addition.
|
Half angle formula wasn't used for expanding |
This may need some tests at |
OP could be updated to reflect that half angle recognition is not included. |
I wonder if |
The unconditional tanh(5), tanh(5*Symbol('1')) -> (tanh(1)**5 + 5*tanh(1) + 10*tanh(1)**3)/(1 + 5*tanh(1)**4 + 10*tanh(1)**2) |
The imaginary unit
It could be avoided by elementary plane trigonometric arguments but it simplifies the mathematics.
|
Is there anything else that needs to be done for this PR to be merged? Should I add some tests for this anywhere? Where would I note that half angle recognition is not included @smichr? |
please address this comment |
… treated as such. If argument is not addition or multiplication, original argument is returned.
Originally we had this with the unconditional else:
After making the unconditional else into: I get: Also I wanted to note that the reason, I made that else unconditional was because that is how it's done in tan's
However, I agree that it doesn't make sense to treat all expansions as multiplications if they are not additions. Might be something to change in tan's Is this the type of fix you were looking for? |
yes -- I am not an expert in trig expression wrangling, but the expansion doesn't seem profitable (and the user can use the symbolic number to expand a certain factor of the numeric arg if they desire, e.g. I think it would be ok to make this change in the regular |
Are you willing to do that? If so, I'll wait until that change is present before starting tests. |
This is in, thanks. Will watch for #21440 to finish up, too. |
References to other Issues or PRs
Fixes #21365
Brief description of what is fixed or changed
Release Notes
Example: