Skip to content
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

sagemath does not translate function('F') to F := operator "F" for fricas interface #25838

Closed
nasser1 opened this issue Jul 12, 2018 · 23 comments

Comments

@nasser1
Copy link

nasser1 commented Jul 12, 2018

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: 2018-07-08                 │
│ Type "notebook()" for the browser-based 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_64-linux-gnu"
spad-lib="/usr/lib/fricas/target/x86_64-linux-gnu/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

CC: @rwst

Component: interfaces

Keywords: integrate, fricas, sagedays@icerm

Author: Martin Rubey

Branch/Commit: aa044c5

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/25838

@nasser1 nasser1 added this to the sage-8.3 milestone Jul 12, 2018
@mantepse
Copy link
Contributor

comment:2

I will work on this once #25602 is reviewed. It is not hard.

@mantepse
Copy link
Contributor

@mantepse
Copy link
Contributor

Commit: 7802770

@mantepse
Copy link
Contributor

New commits:

c31c7e0provide FriCAS translations of formal functions and their derivatives
7802770add doctest

@mantepse
Copy link
Contributor

Author: Martin Rubey

@tscrim
Copy link
Collaborator

tscrim commented Jul 23, 2018

Changed keywords from integrate, fricas to integrate, fricas, sagedays@icerm

@tscrim
Copy link
Collaborator

tscrim commented Jul 23, 2018

comment:5

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.

@tscrim
Copy link
Collaborator

tscrim commented Jul 23, 2018

Reviewer: Travis Scrimshaw

@tscrim tscrim modified the milestones: sage-8.3, sage-8.4 Jul 23, 2018
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 23, 2018

Changed commit from 7802770 to 0665ead

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 23, 2018

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

0665eadfix trivial omission in doctest

@nbruin
Copy link
Contributor

nbruin commented Jul 23, 2018

comment:7

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)

@mantepse
Copy link
Contributor

comment:8

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.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 23, 2018

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

9a76eb0fix missing import and add doctest

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 23, 2018

Changed commit from 0665ead to 9a76eb0

@nbruin
Copy link
Contributor

nbruin commented Jul 24, 2018

comment:10

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.

@mantepse
Copy link
Contributor

comment:11

review?

@tscrim
Copy link
Collaborator

tscrim commented Jul 27, 2018

comment:12

LGTM now, thanks.

@mantepse
Copy link
Contributor

comment:13

Great, many thanks! Once #25602 is reviewed, integration via FriCAS should be useful for quite a variety of integrands!

@vbraun
Copy link
Member

vbraun commented Aug 26, 2018

comment:14

Merge conflict

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 26, 2018

Changed commit from 9a76eb0 to aa044c5

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 26, 2018

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

aa044c5Merge branch 'develop' of git://trac.sagemath.org/sage into t/25838/sagemath_does_not_translate_function__f___to_f____operator__f__for_fricas_interface

@mantepse
Copy link
Contributor

comment:16

trivial rebase

@vbraun
Copy link
Member

vbraun commented Sep 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants