Ask Your Question

Problem with trig_simplify()

asked 2017-12-21 18:52:35 +0200

ceiar gravatar image

updated 2017-12-21 21:16:56 +0200

I am testing Sage with basic simbolic expressions appliying derivatives to some functions f(t). When I try to simplify the trigonometric final expressión Sage Notebook does not recognize the partial derivative symbol. I do not understand the new variable psi(t) that appears in the solution.

Here is the Notebook Sage code:

alpha(t)=function('alpha',t); beta(t)=function('beta',t); gamma(t)=function('gamma',t);
mi(t)=sin(beta)^2*diff(alpha(t), t) + (cos(beta)*diff(alpha(t), t) +diff(gamma(t), t))*cos(beta); 

Here is the result:

cos(beta(t))^2*diff(alpha(t), t) + sin(beta(t))^2*diff(alpha(t), t) +
cos(beta(t))*diff(gamma(t), t)
cos(beta(t))*gamma(t)*psi(t) + diff(alpha(t), t)
edit retag flag offensive close merge delete


have you tried psi? ? It will tell you what the psi function is.

nbruin gravatar imagenbruin ( 2017-12-21 23:49:22 +0200 )edit

Notebook tells it is psi(t). But it is amazing!! It is not defined. And seems to susbtitute 'diff(gamma(t),t)' that it is supposed to be the right answer.

Right answer must be: cos(beta(t))*diff(gamma(t), t) + diff(alpha(t), t)

ceiar gravatar imageceiar ( 2017-12-22 09:22:14 +0200 )edit

Sage just prefers writing out the differential in terms of the digamma function, which is documented to be the logarithmic derivative of the gamma function:

sage: var('t')
sage: diff(gamma(t),t)
sage: psi(1)

I'm not sure what you mean by "it is not defined". Are you using a very old version of Sage? In 8.1, the symbol psi in the global scope is bound to the digamma function.

nbruin gravatar imagenbruin ( 2017-12-22 22:03:59 +0200 )edit

I did not want to use mathematical function gamma. I only wanted to define an angle variable. I have just used another name for the symbolic angle variable 'rho' and now it works.

Here it is the code:

alpha(t)=function('alpha',t); beta(t)=function('beta',t); rho(t)=function('rho',t);
mi(t)=sin(beta)^2*diff(alpha(t), t) + (cos(beta)*diff(alpha(t), t) +diff(rho(t), t))*cos(beta); 

And the expected result:

cos(beta(t))^2*diff(alpha(t), t) + sin(beta(t))^2*diff(alpha(t), t) +
cos(beta(t))*diff(rho(t), t)
cos(beta(t))*diff(rho(t), t) + diff(alpha(t), t)

Thanks Nbruin

ceiar gravatar imageceiar ( 2017-12-23 12:16:12 +0200 )edit

@ceiar: what version of Sage are you using? (What do you get if you type version() in Sage?)

slelievre gravatar imageslelievre ( 2017-12-26 22:13:52 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2017-12-29 18:41:42 +0200

slelievre gravatar image

There is no need to declare alpha, beta, gamma as symbolic variables before defining them as symbolic functions. So you could simplify the declaration of variables and functions as follows.

sage: t = SR.var('t')
sage: alpha(t) = function('alpha')(t)
sage: beta(t) = function('beta')(t)
sage: gamma(t) = function('gamma')(t)

Then you define:

sage: mi(t) = sin(beta)^2*diff(alpha(t), t) + (cos(beta)*diff(alpha(t), t) +diff(gamma(t), t))*cos(beta)
sage: mi(t)
sin(beta(t))^2*diff(alpha(t), t) + (cos(beta(t))*diff(alpha(t), t) + diff(gamma(t), t))*cos(beta(t))

Then you expand and apply trig_simplify:

sage: mi_e = mi(t).expand()
sage: mi_e_ts = mi_e.trig_simplify()

This is what you get:

sage: mi_e
cos(beta(t))^2*diff(alpha(t), t) + sin(beta(t))^2*diff(alpha(t), t) + cos(beta(t))*diff(gamma(t), t)
sage: mi_e_ts
cos(beta(t))*gamma(t)*psi(t) + diff(alpha(t), t)

The result involves psi, so we investigate what it is. Sage allows you to use blah? to get the documentation of blah. Use this as follows:

sage: psi?
Signature:      psi(x, *args, **kwds)
   The digamma function, psi(x), is the logarithmic derivative of the
   gamma function.

      psi(x) = frac{d}{dx} log(Gamma(x)) =

   We represent the n-th derivative of the digamma function with
   psi(n, x) or psi(n, x).


      sage: psi(x)
      sage: psi(.5)
      sage: psi(3)
      -euler_gamma + 3/2
      sage: psi(1, 5)
      1/6*pi^2 - 205/144
      sage: psi(1, x)
      psi(1, x)
      sage: psi(1, x).derivative(x)
      psi(2, x)

      sage: psi(3, hold=True)
      sage: psi(1, 5, hold=True)
      psi(1, 5)
Init docstring: x.__init__(...) initializes x; see help(type(x)) for signature
File:           /path/to/sage-8.1/local/lib/python2.7/site-packages/sage/functions/
Type:           function
edit flag offensive delete link more


I did not know this way for define symbolic functions. Thanks

ceiar gravatar imageceiar ( 2018-01-10 10:12:28 +0200 )edit

If an answer solves your question, please accept it by clicking the "accept" button (the one with a check mark, below the upvote button, score, and downvote button, at the top left of the answer).

This will mark the question as solved in the list of questions on the main page of Ask Sage, as well as in lists of questions related to a particular query or keyword.

slelievre gravatar imageslelievre ( 2018-01-11 07:23:20 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-12-21 18:52:35 +0200

Seen: 376 times

Last updated: Dec 29 '17