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

parent of argument lost with Functions #20312

Closed
rwst opened this issue Mar 28, 2016 · 15 comments
Closed

parent of argument lost with Functions #20312

rwst opened this issue Mar 28, 2016 · 15 comments

Comments

@rwst
Copy link

rwst commented Mar 28, 2016

Some Python objects as function arguments lose their parent, i.e. the code in the specific function can no longer access it because the object was coerced into SR. This can result in violation of the rule that function input and output should be of the same type.

sage: S.<y> = PolynomialRing(RR)
sage: ex = sin(asin(y)); ex
y
sage: type(ex)
<type 'sage.symbolic.expression.Expression'>
sage: ex.is_symbol()
True

The specific function (here sin) code cannot remedy this because there the damage is already done. The problem is in symbolic/function.pyx:BuiltinFunction.__call__ where the parent of function arguments is lost.

See also #18832 and maybe #17790.

CC: @jdemeyer

Component: symbolics

Author: Ralf Stephan

Branch/Commit: 58f3d00

Reviewer: Volker Braun

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

@rwst rwst added this to the sage-7.2 milestone Mar 28, 2016
@rwst

This comment has been minimized.

@rwst
Copy link
Author

rwst commented Mar 28, 2016

comment:2

@jdemeyer: I really would appreciate any input you can give me here. If it is not possible to decide which argument of the function determines the return type, a small database of functions with more than one argument could be used that contains that information.

@rwst

This comment has been minimized.

@rwst rwst changed the title parent of argument lost with GinacFunctions parent of argument lost with Functions Mar 29, 2016
@rwst

This comment has been minimized.

@rwst
Copy link
Author

rwst commented Apr 22, 2016

@rwst
Copy link
Author

rwst commented Apr 22, 2016

comment:6

It looks like the first version here can handle the binomial example of #20060 as well as the symbolic poly functions. It works by adding a field _preserved_arg to every BuiltinFunction that is set on function creation and says which of the function arguments is the one where we try to preserve the arg's parent. Then Expression.polynomial() is used to convert back in case of polynomial rings. Also, by not setting a default preserved_arg the functionality is limited to the cases where the developer has given this parameter in the function init call.

This does not work however with the title example because there the functions are nested. Since it seems we cannot decide where in a nested expression the specific element is whose parent we want to preserve I tend to exclude the nested case.


New commits:

eb5bf9320312: preserving function arg parent, first version

@rwst
Copy link
Author

rwst commented Apr 22, 2016

Author: Ralf Stephan

@rwst
Copy link
Author

rwst commented Apr 22, 2016

Commit: eb5bf93

@rwst
Copy link
Author

rwst commented Apr 23, 2016

comment:7

Tests pass.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 23, 2016

Changed commit from eb5bf93 to 5c377cc

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 23, 2016

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

5c377cc20312: fix for constant results

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 6, 2016

Changed commit from 5c377cc to 58f3d00

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 6, 2016

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

58f3d00Merge branch 'develop' into t/20312/parent_of_argument_lost_with_functions

@vbraun
Copy link
Member

vbraun commented May 6, 2016

Reviewer: Volker Braun

@vbraun
Copy link
Member

vbraun commented May 6, 2016

Changed branch from u/rws/parent_of_argument_lost_with_functions to 58f3d00

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

2 participants