#6956 closed defect (fixed)
[with patch, positive review] cannot differentiate cotangent
Reported by: | burcin | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-4.1.2 |
Component: | symbolics | Keywords: | |
Cc: | jason, kcrisman | Merged in: | Sage 4.1.2.alpha4 |
Authors: | Tim Dumol | Reviewers: | Burcin Erocal |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
From sage-support:
On Fri, 18 Sep 2009 13:15:46 -0500 Jason Grout <jason-sage@creativetrax.com> wrote: > On alpha.sagenb.org, I get the following: > > sage: t=var('t') > sage: diff(cot(t),t) > D[0](cot)(t) > sage: diff(cos(t)/sin(t),t) > -cos(t)^2/sin(t)^2 - 1 > > > Does Sage not know that cot(t) is cos(t)/sin(t)?
Unfortunately it doesn't.
GiNaC doesn't define the function cot
. Sage defines it in the file
sage/functions/trig.py
starting at line 184. I suppose it was written quickly by Mike during the symbolics switch.
Defining a custom derivative function (named _derivative_
) in that
class should fix this.
Here is the thread:
http://groups.google.com/group/sage-support/browse_thread/thread/752de34c876720cc
Attachments (2)
Change History (11)
Changed 7 years ago by
comment:1 Changed 7 years ago by
- Summary changed from cannot differentiate cotangent to [with patch, needs review] cannot differentiate cotangent
This should do the trick.
comment:2 Changed 7 years ago by
- Cc jason kcrisman added
- Reviewers set to Burcin Erocal
- Summary changed from [with patch, needs review] cannot differentiate cotangent to [with patch, needs work] cannot differentiate cotangent
Thanks for the quick patch.
Here is my review:
- the keyword argument
diff_param
is only useful for multivariate functions. In this case since all these functions are univariate, so we know the argument isargs[0]
. You can safely drop the first two lines of the_derivative_()
methods and replace the third withx = args[0]
. - continuing the previous item, we should tell these functions they are univariate. ATM, they silently drop the second argument:
sage: arccsc(a,b) arccsc(a)
You can do this by givingnargs=1
as a parameter to the base class constructor. - It is better to give the variable as an argument to
diff
in the doctests, for examplediff(asech(x), x)
. I actually preferasech(x).derivative(x)
, but this is your patch. :) - The formula for the derivative of
asech(x)
you use is only true for x real. You need-1/(x * (x+1) * sqrt( (1-x)/(1+x) ))
. - Similarly, the derivative of
acsch(x)
is-1/(x^2 * sqrt(1 + 1/x^2) )
Can someone else check the derivatives to make sure there is no mistake?
Changed 7 years ago by
Added _derivative_()
functions to all functions in trig.py and hyperbolic.py. Rev 2. Apply this patch only.
comment:3 follow-up: ↓ 5 Changed 7 years ago by
Functions that inherit from PrimitiveFunction
are automatically given nargs = 1
on L800 of symbolic/function.pyx
. So the silent dropping of arguments is more of a usability problem on the Symbolic side.
I've made the changes for the derivatives of asech(x)
and acsch(x)
. I've also generalized the derivatives for asec(x)
and acsc(x)
.
Anyone who wants to review the derivatives can check: http://mathworld.wolfram.com/Derivative.html, http://mathworld.wolfram.com/InverseHyperbolicFunctions.html and http://mathworld.wolfram.com/InverseTrigonometricFunctions.html
comment:4 Changed 7 years ago by
- Summary changed from [with patch, needs work] cannot differentiate cotangent to [with patch, needs review] cannot differentiate cotangent
comment:5 in reply to: ↑ 3 Changed 7 years ago by
- Summary changed from [with patch, needs review] cannot differentiate cotangent to [with patch, positive review] cannot differentiate cotangent
Replying to timdumol:
Functions that inherit from
PrimitiveFunction
are automatically givennargs = 1
on L800 ofsymbolic/function.pyx
. So the silent dropping of arguments is more of a usability problem on the Symbolic side.
You're right. I fixed this and many other things about symbolic functions last weekend, by rewriting sage/symbolic/function.pyx. Unfortunately I don't think I'll be able to clean up my changes and submit them any time soon... oh, well...
I'm giving your patch a positive review. It applies cleanly, and passes all tests on my 4.1.1.alpha. Great job! Many thanks.
comment:6 Changed 7 years ago by
burcin: it seems that there are several people interested in helping with symbolics, so maybe if you just posted what you had, people could clean it up for you, if that would be easier for your time situation?
comment:7 Changed 7 years ago by
- Merged in set to Sage 4.1.2.alpha3
- Resolution set to fixed
- Status changed from new to closed
Merged trac_6956-derivatives.2.patch
.
comment:8 Changed 7 years ago by
- Merged in changed from Sage 4.1.2.alpha3 to Sage 4.1.2.alpha4
There is no 4.1.2.alpha3. Sage 4.1.2.alpha3 was William Stein's release for working on making the notebook a standalone package.
comment:9 Changed 12 days ago by
- Report Upstream set to N/A
Added _derivative() functions to all functions in
trig.py
andhyperbolic.py