Skip to content

Fix problems with constructing or converting to SymPy expressions #20204

Closed
@rwst

Description

@rwst

In the Sympy-1.0 upgrade the AppliedUndef._sage_ method is patched away to enable the important upgrade. This function was planned to resolve part of #14723 but uncovers problems with symbolics. The following doctest in french_book fails if AppliedUndef._sage_ is defined:

sage: from sympy import Function, Symbol
sage: u = Function('u'); n = Symbol('n', integer=True)
sage: f = u(n+2)-(3/2)*u(n+1)+(1/2)*u(n)
NotImplementedError

tscrim found the minimal cases:

sage: f = function('f')
sage: x = var('x')
sage: sympy.sympify(f(x), evaluate=False)
f(x)
sage: sympy.sympify(3*f(x), evaluate=False)
AttributeError: 'Call' object has no attribute 'id'

However, we do seem to have our own troubles of constructing SymPy objects from symbolic expressions. All of these result in errors:

sage: f._sympy_()
sage: f(x)._sympy_()
sage: (f(x)+3)._sympy_()

This means that Sympy-1.0 probably only uncovered already existing problems in expression conversion. This ticket should remove the patch in build/pkgs/sympy and resolve all mentioned problems.

See #20185 for all previous discussion on this.

Depends on #23496
Depends on #22566

CC: @mforets @man74cio

Component: symbolics

Author: Marcelo Forets, Ralf Stephan

Branch/Commit: fd0db78

Reviewer: Marcelo Forets

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions