#25838 closed defect (fixed)

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

Reported by: gh-nasser1 Owned by:
Priority: minor Milestone: sage-8.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: 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

Change History (19)

comment:1 Changed 16 months ago by gh-nasser1

  • Type changed from PLEASE CHANGE to defect

comment:2 Changed 16 months ago by mantepse

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

comment:3 Changed 15 months ago by mantepse

  • Branch set to u/mantepse/sagemath_does_not_translate_function__f___to_f____operator__f__for_fricas_interface

comment:4 Changed 15 months ago by mantepse

  • Authors set to Martin Rubey
  • Cc rws added
  • Commit set to 78027704e00f0a6516261cf559011fa58a1d4dec
  • Status changed from new to needs_review

New commits:

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

comment:5 Changed 15 months ago by tscrim

  • Keywords sagedays@icerm added
  • Milestone changed from sage-8.3 to sage-8.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 15 months ago by git

  • Commit changed from 78027704e00f0a6516261cf559011fa58a1d4dec to 0665ead3c565bc6a7963c5a08837226f60b7df9c

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

0665eadfix trivial omission in doctest

comment:7 follow-up: Changed 15 months ago by nbruin

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 ; follow-up: Changed 15 months ago by mantepse

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 15 months ago by git

  • Commit changed from 0665ead3c565bc6a7963c5a08837226f60b7df9c to 9a76eb0fe7582151c290c001633b9f1720fe0bc3

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

9a76eb0fix missing import and add doctest

comment:10 in reply to: ↑ 8 ; follow-up: Changed 15 months ago by nbruin

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 15 months ago by mantepse

review?

comment:12 Changed 15 months ago by tscrim

  • Status changed from needs_review to positive_review

LGTM now, thanks.

comment:13 Changed 15 months ago by mantepse

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

comment:14 Changed 14 months ago by vbraun

  • Status changed from positive_review to needs_work

Merge conflict

comment:15 Changed 14 months ago by git

  • Commit changed from 9a76eb0fe7582151c290c001633b9f1720fe0bc3 to aa044c5a0e8edb13825000b2dd76acf5ff232ff3

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

comment:16 Changed 14 months ago by mantepse

trivial rebase

comment:17 Changed 14 months ago by mantepse

  • Status changed from needs_work to needs_review

comment:18 Changed 14 months ago by tscrim

  • Status changed from needs_review to positive_review

comment:19 Changed 14 months ago by vbraun

  • 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
Note: See TracTickets for help on using tickets.