#14270: Remove function call syntax for symbolic expressions
-------------------------------------+-------------------------------------
Reporter: ppurka | Owner: burcin
Type: defect | Status: needs_work
Priority: major | Milestone: sage-6.4
Component: symbolics | Resolution:
Keywords: | Merged in:
Authors: Punarbasu | Reviewers:
Purkayastha | Work issues: fix
Report Upstream: N/A | combinat/tutorial.py
Branch: | Commit:
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Comment (by nbruin):
Replying to [comment:3 ppurka]:
> I am able to fix all the doctests except for the following one in
combinat/tutorial.py.
OK, from what you've written down here, I can come up with one way of
rewriting the example.
> {{{
> sage: C, z = var('C,z');
> sage: sys = [ C == z + C*C ]
> sage: sol = solve(sys, C, solution_dict=True); sol
> [{C: -1/2*sqrt(-4*z + 1) + 1/2}, {C: 1/2*sqrt(-4*z + 1) + 1/2}]
> sage: s0 = sol[0][C]; s1 = sol[1][C]
> }}}
> {{{
> sage: C = s0; C
> -1/2*sqrt(-4*z + 1) + 1/2
> }}}
I think this should be deleted. Use s0 if you want that and just leave C
bound to the variable. It's already bad enough that we need "C as a
function" further down.
> {{{
> sage: equadiff
> (4*z - 1)*D[0](C)(z) - 2*C(z) + 1 == 0
> sage: Cf = sage.symbolic.function_factory.function('C')
> }}}
Didn't we need Cf before to arrive at `equadiff`? How did `C(z)` get into
that expression in the first place?
> {{{
> sage: equadiff.substitute_function(Cf, s0) # Original answer is the
deprecation + answer
> ...
> TypeError: %d format: a number is required, not NoneType
> }}}
I think the following should work (it does in vanilla, without a
deprecation warning):
{{{
sage: equadiff.substitute_function(Cf, s0.function(z))
}}}
> Let us try to "fix" this (`z` is a symbolic variable). Somehow the
following works (beats me why it does):
> {{{
> sage: equadiff.substitute_function(Cf(z), s0)
> (4*z - 1)*D[0](C)(z) - 2*C(z) + 1 == 0 # OK, so this seems to work
> }}}
I'm not so sure it "works". It doesn't give an error (which is surprising
in its own right; perhaps that should change), but I don't think it gives
the same answer. In vanilla:
sage: equadiff.substitute_function(Cf(z), s0)
{{{
(4*z - 1)*D[0](C)(z) - 2*C(z) + 1 == 0
sage: equadiff.substitute_function(Cf, s0.function(z))
(4*z - 1)/sqrt(-4*z + 1) + sqrt(-4*z + 1) == 0
}}}
> But now the next command in the tutorial gives `False` instead of `True`
Rightly so, judging from the results above.
> Why is all this happening? Looking at the documentation of
`substitute_function` shows that it should be used for substituting
''functions'', not anything else
> {{{
> def substitute_function(self, original, new):
> """
> Returns this symbolic expressions all occurrences of the
> function *original* replaced with the function *new*.
> }}}
>
> And what exactly are we substituting above?
> {{{
> sage: type(Cf)
> sage.symbolic.function_factory.NewSymbolicFunction
> sage: type(s0)
> sage.symbolic.expression.Expression
> }}}
> We are substituting a symbolic function with a symbolic expression! How
was this even working earlier?
I guess because symbolic expressions were deprecated "functions": you
could call then with symbolic arguments and get a symbolic expression, at
the cost of a deprecation warning.
> What should I do with this portion of the tutorial? Delete this?
No, just do
{{{
sage: equadiff.substitute_function(Cf, s0.function(z))
}}}
That's probably a useful example to have anyway. It shows how to turn a
symbolic expression into a function in a non-ambiguous way, because you
need to specify argument order.
--
Ticket URL: <http://trac.sagemath.org/ticket/14270#comment:14>
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/d/optout.