-
-
Notifications
You must be signed in to change notification settings - Fork 489
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
Meta-ticket: Callable symbolic expressions #28434
Comments
This comment has been minimized.
This comment has been minimized.
comment:2
Let's look at these one by one:
Some of these (in particular 4, 5, 8) are really user mistakes where an ordinary Python function is meant instead of a symbolic function. I agree that this may be confusing, but there really is an important difference between
and
I recommend you to create separate tickets for the bugs that you want to see fixed. I cannot at all promise that they will be fixed. But it will help discussion if we don't have a single issue which is about multiple unrelated things. |
comment:3
I have to disagree that these issues are unrelated. The main source of confusion (in my opinion) is that this syntax is reserved for something very particular (callable symbolic expressions), while it looks like something much more general, like a lambda-style definition of a Python function.
What I meant to show was: the (naive) expectation is that when you put in an integer, you get back an integer. This is false, because what you get is a symbolic expression. So a better example (with a method that isn't available on symbolic expressions) would be
They can often be mixed. A "fix" here is to write
How does the user know that this is an issue? It's not an issue with Python functions...
We know this and we are used to it, but in my opinion it really makes no sense. I can kind of understand the desire to create a type of function object (which is what happens in the first case), e.g. for prettyprinting, but the fact that these two
Some would expect two scalar-valued functions of a scalar variable to always add up to a scalar-valued function of a scalar variable. But I will concede this is the least confusing one.
How does the user know that they are defining a symbolic callable expression, and that they shouldn't? All the questions were rhetorical. In my experience (and in the posted threads), the user doesn't know, because it isn't clear. Sage would be less confusing without this syntax (in its current form). |
comment:4
So, is this ticket suggesting to remove the syntax? If so, I'm not convinced a ticket is the right place to have such a discussion. Do you realize how much user code it would break? Maybe you should lay out your plan more clearly on sage-devel. |
comment:5
Thanks for putting the list together. It's nice to have a record which issues (often?) arise. A lot of confusion happens because of the mathematics underneath. Confusion is a common state for students who are learning mathematics and I think it is to be expected that they will also encounter it while working with a computer algebra system of significant scope and complexity. It's nice to reduce confusion where possible, but I think it's unrealistic to expect we can do away with it. Some of your items are indicated above as bugs and can probably be solved. Other items might be better to put in an FAQ document (or the documentation) for people to point to if questions arise. I don't know if these examples are best kept track of on a ticket. The ticket itself isn't really resolvable, but there are other administrative tracker tickets around. Answer to "how does a user know"?
Once a user run into issues like this, it's clear that they have to progress beyond the level of "beginner" and start a more "advanced" approach. When they have questions concerning this, they have a motivation to read an "advanced" tutorial that goes more into the nuts and bolts of things. After that tutorial they should be at a level where they can make sense of the reference guide. Perhaps the "advanced" tutorial already exists. Perhaps it needs to be written? Note that callable symbolic expressions serve a very definite purpose and are therefore not going away. The preparse trick of defining them A general comment: Building a computer algebra system on top of python is necessarily a compromise. This is true for other python-based solutions too, for instance pandas or matplotlib. In most of these cases, a Domain Specific Language would be much more elegant and unified. Although, beware what you ask for: in for instance Maple, they DO have a very clear symbolic expression model that is fundamental to everything. And they found it doesn't address all their needs and had to bolt on other solutions. It makes for a decidedly unpleasant system to program for. They ended up with their compromises in other places.
|
comment:6
Thanks for a very well-organized resume of the issues at stake, Nils. |
comment:7
Replying to @kcrisman:
+1 |
comment:8
Thanks, Nils. I had a look at the implementation. A callable symbolic expression like This is quite simple and powerful, and I now agree that the notation should be kept. It seems that the best resolution is to fix the bugs, improve the documentation, improve error handling, and extend the functionality to include a matrix-valued variant. See a detailed proposal below. I found that the Guided Tour already has a page Some Common Issues with Functions which is a great start for clarifying some of the issues. This should be the page to point people to when they run into any of this. Let me go over the list again:
The Common Issues page point 2 should explain more precisely what a callable symbolic expression is. In particular, at definition-time, the arguments are symbolic variables (and treated as such on the right-hand side); calling means substitution, and the result (in the scalar-valued case) is a symbolic expression. Also, the "vector-valued" (and possibly "matrix-valued", see 3 below) variant deserves a mention.
Covered by the previous point. I would like to have the "solution" to this (explicit conversion) as an example somewhere, but since the Common Issues page is part of the Guided Tour it would be too early there.
Currently a bug. I believe matrices are not much different from vectors, and a matrix-valued variant could be implemented. It should return a matrix over a
In my opinion the syntax with square brackets for vector-valued functions is an abuse of notation (which has caused confusion with lists); it should be
Handled by point 1. In particular, the point is that the arguments in the right-hand side of the definition of a callable symbolic expression are symbolic variables, not arbitrary objects, and in particular they cannot be functions.
From the implementation we know that
I can live with this. Maybe it should be mentioned in the documentation.
Can we improve the preparser here? Currently, it translates
But how about this instead?
The best part about this is that it informs the user that it is attempting to define a callable symbolic expression. If this is not what they meant, the user will probably do a web search for "Sage function" and will land on the (highly ranked) Common Issues page, which starts with the definition of ordinary Python functions. |
comment:9
Ticket retargeted after milestone closed |
comment:10
Batch modifying tickets that will likely not be ready for 9.1, based on a review of the ticket title, branch/review status, and last modification date. |
comment:12
Setting new milestone based on a cursory review of ticket status, priority, and last modification date. |
comment:13
Suggestion: make this a meta-ticket and track each item
|
comment:14
For item 7, see #32008. |
The syntax for callable symbolic expressions works in the simplest cases, but beyond that it breaks down and causes much confusion, as can be often seen on Ask SageMath and (in my experience) when trying to teach SageMath to people. Here is a non-exhaustive list of 8 examples:
https://ask.sagemath.org/question/47064/how-to-turn-the-function-into-expression/
https://ask.sagemath.org/question/10457/arithmetic-with-matrices-of-formal-functions/
https://ask.sagemath.org/question/10449/how-to-return-a-list-from-callable-symbolic-expression/
https://ask.sagemath.org/question/9842/the-difference-between-fx3-and-f3-of-callable-symbolic-expression-f/
https://ask.sagemath.org/question/38524/defining-functions-acting-on-matrix-elements/
https://ask.sagemath.org/question/10782/symbolic-functions-without-named-variables/
https://ask.sagemath.org/question/47672/is-this-a-bug-or-intended-behavior/
Additional issues and tickets related to callable symbolic expressions:
CallableSymbolicExpressionRing
over subrings ofSR
CallableSymbolicExpressionRing
: Fix broken element methodsSee also:
arguments
(alias:args
),number_of_arguments
,_fast_callable_
for non-callable symbolic expressionsCC: @slel @orlitzky @egourgoulhon
Component: symbolics
Keywords: CallableSymbolicExpression, function, callable
Issue created by migration from https://trac.sagemath.org/ticket/28434
The text was updated successfully, but these errors were encountered: