Skip to content

A product is written letters before functions - #1635

Open
Rafael-SOWNet wants to merge 1 commit into
masterfrom
a-product-is-written-letters-before-functions
Open

Rafael-SOWNet wants to merge 1 commit into
masterfrom
a-product-is-written-letters-before-functions

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

By hand, a product is written with the number first, then the letters and their powers, then the functions: y sin(x), x e^x, z Γ(z) (DLMF 5.5.1). The reason is that a function's argument can be written without parentheses. ISO 80000-2 allows sin nπ, so a letter written after a function reads as part of its argument. Simplify wrote sin(x) * y and e ^ x * x.

The answer of Simplify is now put in that order as its last step (Simplificator.InPrintOrder): numbers, then letters and their powers, then everything else, each kind keeping the order it had. e^x and 2^n count as functions, and x^n counts as a letter. A leading number goes into a quotient over a number, so the derivative of arcsin(2 * x) simplifies to 2 / sqrt(1 - (2 * x) ^ 2) rather than 2 * 1 / sqrt(…).

Only the answer is reordered. I first measured sorting letters first inside the search itself, and it lost four things:

  • lim 1/x^2 - 1/sin(x)^2 at 0 became NaN, where it is -1/3, and its two siblings stopped answering.
  • x * (x - 1)! stopped becoming x!.
  • An integral stopped differentiating back.

The product rules are binary, and they meet 2 cos(x) sin(x) as neighbours only because the search's order sorts every function before every letter. With x between them, 2 x sin(x) cos(x) stopped becoming x sin(2x), and l'Hôpital's quotients grew past their guard. The numbers are on #1628. So the search keeps its order, and InnerSimplified and Differentiate return that order as before.

Simplify of 2.5.0 now
sin(x) * y sin(x) * y y * sin(x)
x * e ^ x e ^ x * x x * e ^ x
2 * sin(x) * y 2 * sin(x) * y 2 * y * sin(x)
a / sin(x) csc(x) * a a * csc(x)
2 * x * sin(x) * cos(x) sin(2 * x) * x x * sin(2 * x)
derivative(arcsin(2 * x), x) 1 / sqrt(1 - (2 * x) ^ 2) * 2 2 / sqrt(1 - (2 * x) ^ 2)

FactorOrderTest covers three things:

  • the order itself, including exponentials and powers of letters;
  • the round trip from printed form back to the same product;
  • TheRulesStillMeetTheFactorsTheyCombine: 2 x sin(x) cos(x) → x sin(2x) and x (x - 1)! → x!. Both fail if the order is changed inside the search.

Twenty-one existing expectations are updated to the new spelling. None of them changes value.

Suite on net10.0, at 405b4d2a on master fac6ce16: 14202 passed, none failed. Every target framework builds.
Gate: allocation matches the baseline on all 19 gated benchmarks. The step reads a product's order before building anything, and most answers are in order already.

Closes #1628.

Part of #180.

🤖 Generated with Claude Code

https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

By hand a product is written the number first, then the letters and their
powers, then the functions: y sin(x), x e^x, z Γ(z) (DLMF 5.5.1). ISO
80000-2 lets a function's argument go without parentheses, sin nπ, so a
letter written after a function reads as part of its argument. Simplify
wrote sin(x) * y and e ^ x * x, the order its search sorts by.

The answer of Simplify is now put in that order as its last step, each kind
of factor keeping the order it had, and a leading number is taken into a
quotient over a number: 2 / s, not 2 * 1 / s. The search keeps its own
order. Its product rules are binary and meet 2 cos(x) sin(x) as neighbours
only because nothing sorts between them; sorting letters first inside the
search stopped 2 x sin(x) cos(x) becoming x sin(2x) and made
lim 1/x^2 - 1/sin(x)^2 at 0 NaN.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
@Rafael-SOWNet Rafael-SOWNet added this to the 2.6.0 milestone Sep 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A product is written letters before functions: y sin(x), not sin(x) y

1 participant