Opened 4 years ago

Closed 4 years ago

#25597 closed defect (fixed)

bivariate fricas gamma not interfaced with sage

Reported by: tmonteil Owned by:
Priority: major Milestone: sage-8.3
Component: interfaces: optional Keywords: fricas
Cc: ​mantepse, rws Merged in:
Authors: Martin Rubey Reviewers: Frédéric Chapoton
Report Upstream: N/A Work issues:
Branch: a6ba957 (Commits, GitHub, GitLab) Commit: a6ba9572ad888539e6e1df8e5b0d331fa0abc83f
Dependencies: Stopgaps:

Status badges

Description (last modified by mantepse)

As reported on this ask question, onevariate gamma is correcly interfaced with Sage:

sage: fricas.Gamma(3/2)
sage: fricas.Gamma(3/2).sage()

but not bivariate gamma:

sage: fricas.Gamma(3/2,2)
sage: fricas.Gamma(3/2,2).sage()
NotImplementedError: The translation of the FriCAS Expression Gamma(3/2,2) to sage is not yet implemented.
sage: gamma(3/2,2)
gamma(3/2, 2)

The bug in the integration result returned by FriCAS was reported upstream and acknowledged:!topic/fricas-devel/BhtEiNSW3j4

Change History (15)

comment:1 Changed 4 years ago by chapoton

  • Keywords fricas added

comment:2 follow-up: Changed 4 years ago by gh-nasser1

hi, FYI, these are additional integrals which also generate NotImplementedError? error. I did not know if you need to include these in this bug or open a new bug for them. Here are the commands to use to produce the errors

integrate(sqrt(x + sqrt(x + 1))/((x^2 + 1)*sqrt(x + 1)),x, algorithm="fricas")

NotImplementedError?: The translation of the FriCAS Expression

integrate(sqrt(x + sqrt(x + 1))/(x^2 + 1),x, algorithm="fricas")

NotImplementedError?: The translation of the FriCAS Expression

I can find more if needed. Both of these integrals work OK using Fricas directly. Thanks you, --Nasser

Last edited 4 years ago by gh-nasser1 (previous) (diff)

comment:3 in reply to: ↑ 2 Changed 4 years ago by rws

Replying to gh-nasser1:

integrate(sqrt(x + sqrt(x + 1))/((x^2 + 1)*sqrt(x + 1)),x, algorithm="fricas")

This depends on what RootOf means. Does Sage's complex_root_of suffice?

comment:4 Changed 4 years ago by rws

Unrelated but are you sure that FriCAS solves these two correctly? Rubi's solutions do not contain any root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[x+Sqrt[1+x]])])/(2 Sqrt[(1+I)/(I+Sqrt[1+I])])

comment:5 Changed 4 years ago by gh-nasser1

I am no expert on Fricas nor on Sage. But a quick check shows these are not the same. in sage:

c = complex_root_of(x^6 + x + 1, 1); c
       complex_root_of(x^6 + x + 1, 1)

-0.790667188814418 + 0.300506920309552*I

But in Fricas, there is no definition for rootOf which takes a polynomial and an integer

There is one unexposed function called rootOf :

   [1] (SparseUnivariatePolynomial(D1),Symbol) -> D1
            from AlgebraicFunction(D4,D1)
            if D1 has FS(D4) and D4 has Join(COMPAR,INTDOM)

So using

rootOf(x^2 + x + 1, 1) 

similar to sage's complex_root_of gives error

(3) -> rootOf(x^2 + x + 1, 1)
   Cannot find a definition or applicable library operation named 
      rootOf with argument type(s) 

But this works in fricas

rootOf(x^3 + x + 1, x)

So I think it is best to ask the experts in FriCAS group to find what is the best way to translate Fricas rootOf to sage syntax.!forum/fricas-devel as I am not qualified to answer.

Last edited 4 years ago by gh-nasser1 (previous) (diff)

comment:6 Changed 4 years ago by mantepse

Concerning Gamma, it would be necessary to know what the correct definition is. In case you have time, please provide a simple integral which fricas can do, where the result contains a Gamma, and which we can evaluate numerically. In other words, a doctest.

Concerning RootOf, the translation is probably more tricky, but also doable. I have no clue, but it might be a problem that fricas does not specify which root is meant.

comment:7 follow-up: Changed 4 years ago by gh-nasser1

The 2 argument Gamma function is the incomplete Gamma function


Gamma: (F, F) -> F
Gamma(a, x) returns the incomplete Gamma function applied to a and x
Gamma: F -> F
Gamma(f) returns the formal Gamma function applied to f

So I think it will be safe to translate Fricas Gamma(a,x) to sage's gamma_inc(a,x)

Type:           Function_gamma_inc
String form:    gamma
File:           /home/sc_serv/sage/local/lib/python2.7/site-packages/sage/functions/
      The upper incomplete gamma function.

      It is defined by the integral

         Gamma(a,z)=int_z^infty t^{a-1}e^{-t},dt

comment:8 in reply to: ↑ 7 Changed 4 years ago by mantepse

It is not clear to me whether FriCAS Gamma is the lower or the upper incomplete Gamma function. In any case, there should be a doctest, this is what makes sage reliable.

comment:9 Changed 4 years ago by mantepse

I added a simple doctest. However, there is at least a problem with the integral FriCAS returns for the original question mentioned in the ticket description. I'll forward this to the FriCAS mailing list.

Could you please open a different ticket for the rootOf problem?

sage: f = log(x)^(-t-1)
sage: f_int = integrate(f,x, algorithm="fricas"); f_int             # optional - fricas                                                               
cos(pi + pi*t)*gamma(-t, -log(x))
sage: [(diff(f_int, x) - f).subs(t=k/2).full_simplify() for k in range(-5,5)] # optional - fricas                                                     
sage: f_int = integrate(f,x, algorithm="maxima"); f_int
-(-log(x))^t*log(x)^(-t)*gamma(-t, -log(x))
sage: [(diff(f_int, x) - f).subs(t=k/2).full_simplify() for k in range(-5,5)]                                                     
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

comment:10 Changed 4 years ago by mantepse

  • Branch set to u/mantepse/bivariate_fricas_gamma_not_interfaced_with_sage

comment:11 Changed 4 years ago by mantepse

  • Authors set to Martin Rubey
  • Commit set to 30a4aa804699f4881ef2216b7caf57210a345bc9
  • Description modified (diff)
  • Status changed from new to needs_review

I opened #25602 for the rootOf problem.

New commits:

30a4aa8add FriCAS translation of upper incomplete gamma

comment:12 Changed 4 years ago by chapoton

  • Reviewers set to Frédéric Chapoton

Please remove ; in var("t");

once done, you can set to positive

comment:13 Changed 4 years ago by git

  • Commit changed from 30a4aa804699f4881ef2216b7caf57210a345bc9 to a6ba9572ad888539e6e1df8e5b0d331fa0abc83f

Branch pushed to git repo; I updated commit sha1. New commits:

a6ba957remove semicolon, adapt doctest

comment:14 Changed 4 years ago by mantepse

  • Status changed from needs_review to positive_review

Thank you!

comment:15 Changed 4 years ago by vbraun

  • Branch changed from u/mantepse/bivariate_fricas_gamma_not_interfaced_with_sage to a6ba9572ad888539e6e1df8e5b0d331fa0abc83f
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.