#15025: automatically injected function does not work with desolve
------------------------------------+--------------------------
Reporter: dkrenn | Owner:
Type: defect | Status: new
Priority: major | Milestone: sage-5.12
Component: symbolics | Resolution:
Keywords: desolve function | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Dependencies:
Stopgaps: |
------------------------------------+--------------------------
Comment (by nbruin):
It seems what gets injected and what gets returned is always an issue. On
top level,
{{{
x = var('x')
}}}
is redundant: {{{var('x')}}} already injects the binding. On the other
hand,
{{{
t = SR.var('t')
}}}
is not redundant because the methods on `SR` do not have injection side
effects.
Looking at the side-effect free methods:
{{{
sage: from sage.symbolic.function_factory import function as new_function
sage: new_function('g')
g
sage: new_function('g',x)
g(x)
sage: type(new_function('g'))
sage.symbolic.function_factory.NewSymbolicFunction
sage: type(new_function('g',x))
sage.symbolic.expression.Expression
}}}
you see the design problem: The routine that constructs new symbolic
functions creates entirely different objects depending on the arguments
given.
A `NewSymbolicFunction` is really a different kind of object: it goes into
the "operator" slot of symbolic expressions:
{{{
sage: (y(x)).operator()
y
sage: (2*x).operator()
<function operator.mul>
}}}
I understand how the shorthand `new_function('f',x)` was considered
convenient, but it really muddles the interface and it's only one
character shorter than the unambiguous `new_function('f')(x)`.
The confusion is compounded by the top-level `function` which does inject
the function into the global namespace as well, but both `function('f')`
and `function('f',x)` inject the same thing into the global namespace: the
NewSymbolicFunction. It has to do that because after typing either, one
would expect f(x) to work. But it does raise the expectation that after
declaring `function('f',x)`, the system would somehow know that even the
bare function `f` has something to do with `x`. It doesn't:
{{{
sage: var('t')
t
sage: function('f',t)
f(t)
sage: f.number_of_arguments()
0
sage: f.variables()
()
sage: f.default_variable()
x
}}}
You would get the same results from `function('f')`.
For the problem at hand in this ticket: The problem is that `desolve`
really wants a symbolic expression, and that there's no good way of
turning a bare function into a symbolic expression: It might try
{{{
f( *(f.default_variable() for i in range(f.number_of_arguments())))
}}}
but you'll quickly see why that's a senseless try.
'''IN SHORT:'''
- The interface for `function` leads to wrong expectations by the user
- The writer of the documentation of `function` was equally confused
- `desolve` should return a more informative error message when the given
argument cannot be turned into a symbolic expression.
--
Ticket URL: <http://trac.sagemath.org/ticket/15025#comment:1>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.