-
-
Notifications
You must be signed in to change notification settings - Fork 60
Revise Unevaluated[] #1463
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
base: master
Are you sure you want to change the base?
Revise Unevaluated[] #1463
Conversation
1ad8971
to
ace6931
Compare
@rocky, it is good to see you have start to looking at this long-standing issue. To see what happend, let's consider some basic examples.
Now, let's compare the output of some evaluations:
In the first case, the arguments of In the third case, F[Cos[Pi], 2, 16] does not match any rule, and we end with I do not think that this behavior can be implemented by associating rules to the Also, the behavior of
Now, let's consider more sophisticated examples, which happens on expressions involving heads with
Notice that the expression is ordered neglecting the
so this not seems to be implemented at the level of an special Now, let's see what happens with the
In the first case, looking at the
In the second case, Notice also what happens if the expression could match with the signature:
In the first example, as before, the flat expression does not match, so the elements receives the Finally, this is what happens if we combine both attributes:
The trickiest part of this is is that If the sort step wasn't there, one way to achieve the same would be to store the position of the
and then build the list of positions. But I leave the implementation to you. |
.... This is a very detailed examination of Unevaluated, but right now, I am interested in the way it is currently used in programs and the documented behavior. That is, real examples. The basic examples as given do work in this branch. And we could get closer in for those situations that really come up. Take for example, the sort order being different when patterns contain I'd like to understand, for example, if there is any WMA code that cares about the sort order when Unevaluated is used going into the evaluation phase (as opposed to the Boxing/Format phase. And if so, why? I am interested in insight into the conditions and purpose a person would use I suspect that some of the behavior is an artifact of the way the code happened to be implemented, rather than there being a need for it by any programmer or WMA program. And if that's the case, the behavior could change because the current undocumented behavior of Unevaluated isn't even important to WMA designers and maintainers. If that is the case, then it is probably not a good idea to spend time right now matching somewhat arbitrary behavior and complicating code. What I want to address right now is the intent for the need of this function. Down the line, it is possible or likely that our evaluation algorithm will happen to be more like Mathematica's based on information we glean later. |
Maybe the way to answer that question is to look at packages like Feyncalc, Rubi or even Combinatorica. In the code I have write in WMA for my day to day work, I have never used it. On the other hand, having this in mind could be useful to understand how the evaluation process goes in WMA. |
I asked ChatGPT
But to find better examples, I would need to do more research... |
This contains a reference to and out-of-print book "Power Programming with the Mathematica Kernel" for Mathematica version 3. I downloaded a PDF of that. |
I've now looked over the ChatGPT references, and have git grep'd WL packages I have. Most of the discussion is a while ago, from Mathematica version 3.0 to 5.0 days. The McGraw-Hill Wagner book mentions this, and perhaps this sparked an interest. Like you, his interest wasn't driven by any need, but, rather, as a means of understanding how evaluation works. I suspect there is a bit more work we can do to make the way we do evaluation more in line with what's described there, and in the future, I'll try to align As for the use that we see in Mathematica packages, it doesn't appear that often. And the uses are not that sophisticated. Especially the ones in Feyncalc, where most of what we encounter is In Dbg[Unevaluated["Submatrix ",ReplaceAll[output,knotComponent->"T"]//MatrixForm]]; The only place it appears in Rubi is:
It does, however, appear more often in WolframEngine System code 13.2 with more sophistication. It appears about 800 times. |
9e21929
to
30ff55f
Compare
In the line of looking at the way in which WMA evaluated expressions with
From this, I understand that the approach in this PR is incorrect: if it were right, we could overwrite the rule. |
I understood that the PR is incorrect based on the fact that there were tests that were failing, and the descriptions of how Unevaluated is supposed to work are different from what is done in this draft. I don't think we should try to get this working before release. It is a bit too involved. Here, though, are things I do understand:
From an engineering perspective, ideal would the temporary setting and restoring of HOLD attributes could be done totally inside the |
I understood that this is not something to put into the next release. I just added this comment as information for thinking about the right implementation, which I agree should not involve setting temporary attributes to the expression. |
Fixes #122