Opened 2 years ago
Closed 23 months ago
#25838 closed defect (fixed)
sagemath does not translate function('F') to F := operator "F" for fricas interface
Reported by:  ghnasser1  Owned by:  

Priority:  minor  Milestone:  sage8.4 
Component:  interfaces  Keywords:  integrate, fricas, sagedays@icerm 
Cc:  rws  Merged in:  
Authors:  Martin Rubey  Reviewers:  Travis Scrimshaw 
Report Upstream:  N/A  Work issues:  
Branch:  aa044c5 (Commits)  Commit:  aa044c5a0e8edb13825000b2dd76acf5ff232ff3 
Dependencies:  Stopgaps: 
Description
When using algorithm="fricas" in integrate, I defined F as function in sagemath. BUt when the call is made to integrate using fricas, it did not seem to be translated correctly to fricas syntax, which is
F := operator "F"
So fricas was not happy.
>sage ┌────────────────────────────────────────────────────────────────────┐ │ SageMath version 8.3.rc0, Release Date: 20180708 │ │ Type "notebook()" for the browserbased notebook interface. │ │ Type "help()" for help. │ └────────────────────────────────────────────────────────────────────┘ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Warning: this is a prerelease version, and it may be unstable. ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ sage: var('x') x sage: F=function('F') sage: integrate(F(x),x,algorithm="fricas") ..... TypeError: An error occurred when FriCAS evaluated 'F(x)':
The Fricas syntax using Fricas directly is
>fricas Checking for foreign routines AXIOM="/usr/lib/fricas/target/x86_64linuxgnu" spadlib="/usr/lib/fricas/target/x86_64linuxgnu/lib/libspad.so" FriCAS Computer Algebra System Version: FriCAS 1.3.4 Timestamp: Thu Jun 28 08:31:47 CDT 2018  (1) > F := operator "F" (1) F Type: BasicOperator (2) > integrate(F(x),x) x ++ (2)  F(%A)d%A ++ Type: Union(Expression(Integer),...)
So many such integrals that use generic function such as the above now fail in sagemath when using FriCAS algorithm because it is not translated correctly.
Thank you
Nasser
Change History (19)
comment:1 Changed 2 years ago by
 Type changed from PLEASE CHANGE to defect
comment:2 Changed 2 years ago by
comment:3 Changed 2 years ago by
 Branch set to u/mantepse/sagemath_does_not_translate_function__f___to_f____operator__f__for_fricas_interface
comment:4 Changed 2 years ago by
 Cc rws added
 Commit set to 78027704e00f0a6516261cf559011fa58a1d4dec
 Status changed from new to needs_review
comment:5 Changed 2 years ago by
 Keywords sagedays@icerm added
 Milestone changed from sage8.3 to sage8.4
 Reviewers set to Travis Scrimshaw
One (trivial, looks like a bad copy/paste) doctest failure here:
def derivative(self, ex, operator): """ Convert the derivative of ``self`` in FriCAS. INPUT:  ``ex``  a symbolic expression  ``operator``  operator EXAMPLES:: sage: var('x,y,z') (x, y)
Should be (x, y, z)
.
Otherwise LGTM.
comment:6 Changed 2 years ago by
 Commit changed from 78027704e00f0a6516261cf559011fa58a1d4dec to 0665ead3c565bc6a7963c5a08837226f60b7df9c
Branch pushed to git repo; I updated commit sha1. New commits:
0665ead  fix trivial omission in doctest

comment:7 followup: ↓ 8 Changed 2 years ago by
Edge case for naming functions vs. variables:
sage: F=function('f') sage: f=SR.var('f') sage: F(f).diff(f).integrate(f) f(f)
amazingly this actually works with the maxima interface because:
sage: maxima_calculus(F(f)) 'f(_SAGE_VAR_f)
comment:8 in reply to: ↑ 7 ; followup: ↓ 10 Changed 2 years ago by
I'm not sure what I'm supposed to do. This "works" with FriCAS, too:
sage: F=function('f') sage: f=SR.var('f') sage: fricas(F(f)).D(f).integrate(f) f(f)
Am I missing something? Oh yes, a missing import, fixed.
comment:9 Changed 2 years ago by
 Commit changed from 0665ead3c565bc6a7963c5a08837226f60b7df9c to 9a76eb0fe7582151c290c001633b9f1720fe0bc3
Branch pushed to git repo; I updated commit sha1. New commits:
9a76eb0  fix missing import and add doctest

comment:10 in reply to: ↑ 8 ; followup: ↓ 11 Changed 2 years ago by
Replying to mantepse:
I'm not sure what I'm supposed to do. This "works" with FriCAS, too: Am I missing something? Oh yes, a missing import, fixed.
OK, then it's fine. I don't have FriCAS installed, so I couldn't check. When I saw F:= operator F
I figured some care should be taken to avoid name clashes, but apparently this is taken care of already.
comment:11 in reply to: ↑ 10 Changed 2 years ago by
review?
comment:12 Changed 2 years ago by
 Status changed from needs_review to positive_review
LGTM now, thanks.
comment:13 Changed 2 years ago by
Great, many thanks! Once #25602 is reviewed, integration via FriCAS should be useful for quite a variety of integrands!
comment:14 Changed 23 months ago by
 Status changed from positive_review to needs_work
Merge conflict
comment:15 Changed 23 months ago by
 Commit changed from 9a76eb0fe7582151c290c001633b9f1720fe0bc3 to aa044c5a0e8edb13825000b2dd76acf5ff232ff3
Branch pushed to git repo; I updated commit sha1. New commits:
aa044c5  Merge branch 'develop' of git://trac.sagemath.org/sage into t/25838/sagemath_does_not_translate_function__f___to_f____operator__f__for_fricas_interface

comment:16 Changed 23 months ago by
trivial rebase
comment:17 Changed 23 months ago by
 Status changed from needs_work to needs_review
comment:18 Changed 23 months ago by
 Status changed from needs_review to positive_review
comment:19 Changed 23 months ago by
 Branch changed from u/mantepse/sagemath_does_not_translate_function__f___to_f____operator__f__for_fricas_interface to aa044c5a0e8edb13825000b2dd76acf5ff232ff3
 Resolution set to fixed
 Status changed from positive_review to closed
I will work on this once #25602 is reviewed. It is not hard.