Timeline for answer to Replacing fraction (rational number) inside Hold by E. Chan-López
Current License: CC BY-SA 4.0
Post Revisions
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 1, 2025 at 18:10 | comment | added | WReach |
The problem is that h//FullForm is not the same as ToExpression[ToBoxes[h,StandardForm],StandardForm]//FullForm even though the OutputForms are identical. It is likely an implementation accident that ToExpression and ToBoxes are not true inverses in this case.
|
|
| Oct 1, 2025 at 17:39 | vote | accept | azerbajdzan | ||
| Oct 1, 2025 at 17:39 | comment | added | azerbajdzan |
Hmm... I was expecting since expression is inside Hold that copy/paste can not modify it in any way.
|
|
| Oct 1, 2025 at 17:37 | history | edited | E. Chan-López | CC BY-SA 4.0 |
Additional explanation.
|
| Oct 1, 2025 at 17:33 | comment | added | E. Chan-López | @azerbajdzan That was a nice observation! This whole issue hinges on the subtle difference between canonicalization and what the Frontend does when you copy/paste a held expression. It's a key subtlety that confuses many user - thanks for asking! :-) | |
| Oct 1, 2025 at 17:28 | history | edited | E. Chan-López | CC BY-SA 4.0 |
Additional explanation.
|
| Oct 1, 2025 at 17:18 | comment | added | E. Chan-López |
The documentation refers to Standard Evaluation (defs, upvalues, etc.). However, 3/7 is a literal expression and is converted to its canonical form (Times[3,Power[7,−1]]) at the absolute earliest stage - before the evaluation that HoldPattern prevents. So, the pattern matcher actually sees HoldPattern[Times[3,Power[7,−1]]]. It works because HoldPattern is transparent to the matcher, letting the internal canonical form of the pattern match the identical canonical form inside the Hold expression. See the update, please!
|
|
| Oct 1, 2025 at 17:13 | comment | added | azerbajdzan | Can you explain also another example I added in OP? | |
| Oct 1, 2025 at 16:53 | history | edited | E. Chan-López | CC BY-SA 4.0 |
Additional explanation.
|
| Oct 1, 2025 at 16:51 | comment | added | azerbajdzan |
The documentation says: HoldPattern[expr] is equivalent to expr for pattern matching, but maintains expr in an unevaluated form. But HoldPattern[3/7] // FullForm outputs Times[3, Power[7, -1] so evidently the expression inside HoldPattern was evaluated.
|
|
| Oct 1, 2025 at 16:46 | comment | added | azerbajdzan |
But 3/7 is represented by Times[3, Power[7, -1] as can be seen in FullForm of the h. So why HoldPattern[3/7] should much the pattern when the pattern is not 3/7?
|
|
| Oct 1, 2025 at 16:43 | history | answered | E. Chan-López | CC BY-SA 4.0 |