Skip to content

Expand throws AngouriBugException on a quotient of factorials #817

Description

@Rafael-SOWNet

Expand crashes on (x + 1)! / x!, an expression Simplify handles without trouble.

Measured

On master at d1c4a4dd (which is 21f0d16f plus #816; Expand's logic is untouched by that PR), net10.0/Release:

(x + 1)! / x!        -> AngouriBugException: SmartExpandOver must be only called of non-sum expression
(x + 1)!             -> (x + 1)!
x! / y!              -> x! / y!
(x + 1)! / x!        -> 1 + x        // Simplify, for comparison
sin(x)! / x!         -> sin(x)! / x!

So it is specific to a quotient whose numerator is a factorial of a sum: (x + 1)! alone is fine, x! / y! is fine, sin(x)! / x! is fine.

Where

TreeAnalyzer.SmartExpandOver asserts its argument is not a sum (Expansion.cs:97). Entity.Expand reaches it through Patterns.ExpandFactorialDivisions, which rewrites the quotient of factorials into a product of the terms that do not cancel — and the recursive call at Expansion.cs:101 then hands it a sum.

Why it matters

AngouriBugException is the library telling a caller that the library is broken, from a public method, on an expression that is perfectly ordinary — and it is thrown rather than returned, so a caller who wraps Expand over a corpus loses the whole run rather than one entry. Per AGENTS.md the honest failure here is to hand back the expression unexpanded.

How it was found

Writing a corpus for the rule-set registry tests in #816's follow-up: applying every registered rule set and every catalogue transformation to a factorial expression. The expression is not exotic; it simply had no test pointing at it.

A skipped regression test is included in that follow-up PR, referencing this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions