Opened 4 years ago
Closed 4 years ago
#20312 closed defect (fixed)
parent of argument lost with Functions
Reported by:  rws  Owned by:  

Priority:  major  Milestone:  sage7.2 
Component:  symbolics  Keywords:  
Cc:  jdemeyer  Merged in:  
Authors:  Ralf Stephan  Reviewers:  Volker Braun 
Report Upstream:  N/A  Work issues:  
Branch:  58f3d00 (Commits)  Commit:  58f3d007fdef577beafc67b43ec6e9eaece846f3 
Dependencies:  Stopgaps: 
Description (last modified by )
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.
Change History (11)
comment:1 Changed 4 years ago by
 Description modified (diff)
comment:2 Changed 4 years ago by
 Cc jdemeyer added
comment:3 Changed 4 years ago by
 Description modified (diff)
 Summary changed from parent of argument lost with GinacFunctions to parent of argument lost with Functions
comment:4 Changed 4 years ago by
 Description modified (diff)
comment:5 Changed 4 years ago by
 Branch set to u/rws/parent_of_argument_lost_with_functions
comment:6 Changed 4 years ago by
 Commit set to eb5bf9367e1f781b6a5e649f4be6fe0fa4da2c39
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:
eb5bf93  20312: preserving function arg parent, first version

comment:8 Changed 4 years ago by
 Commit changed from eb5bf9367e1f781b6a5e649f4be6fe0fa4da2c39 to 5c377cc79bb1a8f61c01b1473081382ec2af50f6
Branch pushed to git repo; I updated commit sha1. New commits:
5c377cc  20312: fix for constant results

comment:9 Changed 4 years ago by
 Commit changed from 5c377cc79bb1a8f61c01b1473081382ec2af50f6 to 58f3d007fdef577beafc67b43ec6e9eaece846f3
Branch pushed to git repo; I updated commit sha1. New commits:
58f3d00  Merge branch 'develop' into t/20312/parent_of_argument_lost_with_functions

comment:10 Changed 4 years ago by
 Reviewers set to Volker Braun
 Status changed from needs_review to positive_review
comment:11 Changed 4 years ago by
 Branch changed from u/rws/parent_of_argument_lost_with_functions to 58f3d007fdef577beafc67b43ec6e9eaece846f3
 Resolution set to fixed
 Status changed from positive_review to closed
@Jeroen: 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.