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

Partial evaluation bug for callable vector functions #12302

Open
sagetrac-gbe mannequin opened this issue Jan 12, 2012 · 2 comments
Open

Partial evaluation bug for callable vector functions #12302

sagetrac-gbe mannequin opened this issue Jan 12, 2012 · 2 comments

Comments

@sagetrac-gbe
Copy link
Mannequin

sagetrac-gbe mannequin commented Jan 12, 2012

For callable (scalar) functions, taking sections (partial evaluation) of functions works perfectly fine; that is to say the following code works perfectly as expected:

sage: f(x,y,z) = x*y*z; f
(x, y, z) |--> x*y*z
sage: g(x, z) = f(y=1); g
(x, z) |--> x*z

Move up to callable vector functions and taking sections breaks however:

sage: v(x, y) = [x+y, x-y]; v
(x, y) |--> (x + y, x - y)
sage: v(x,0)
(x, x)
sage: w(x) = v(y=0)
TypeError

This is because all evaluation, even if partial, of a callable vector function returns a Vector_symbolic_dense. The relevant function _ _call_ _() is defined in free_module_element.pyx.

The fix, of course, is to make the code intelligent enough to know that an evaluation is only partial -- one hopes that type(vx) would return 'sage.modules.vector_callable_symbolic_dense.Vector_callable_symbolic_dense'> rather than 'sage.modules.vector_symbolic_dense.Vector_symbolic_dense'>

sage: v(x, y) = [x+y, x-y]
sage: type(v)
<class 'sage.modules.vector_callable_symbolic_dense.Vector_callable_symbolic_dense'>
sage: vx = v(y=0); vx
(x,x)
sage: type(vx)
<class 'sage.modules.vector_symbolic_dense.Vector_symbolic_dense'>

Work-around

This isn't so bad since we can still do:

sage: v(x, y) = [x+y, x-y]
sage: vx = v(y=0)

Now, if every entry still has a variable everything, including positional rather than named arguments, works.

sage: v(x, y) = [x+y, x-y]
sage: vx = v(y=0)
sage: vx(x=1)
(1, 1)
sage: vx(1) #deprecated, but works fine

However, things break if taking a section kills off all variables in any component we try to use positional arguments:

sage: v(x, y) = [x+y, x-y]
sage: vy = v(y=x)
sage: vy
(2*x, 0)
sage: vx
(x, x)
sage: vy(x=1) #named arguments still work
(2, 0)
sage: vy(1) #positional arguments don't
ValueError

CC: @jasongrout

Component: symbolics

Keywords: sd35.5

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

@sagetrac-gbe sagetrac-gbe mannequin added this to the sage-5.11 milestone Jan 12, 2012
@sagetrac-gbe sagetrac-gbe mannequin self-assigned this Jan 12, 2012
@sagetrac-gbe

This comment has been minimized.

@sagetrac-gbe

This comment has been minimized.

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@mkoeppe mkoeppe removed this from the sage-6.4 milestone Dec 29, 2022
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