|
Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
|
Canonical ordering of commutative-operator operands (reorder-only). More...
Go to the source code of this file.
Namespaces | |
| namespace | bertini |
| namespace | bertini::node |
Enumerations | |
| enum class | bertini::node::MonomialOrder { bertini::node::Lex , bertini::node::RevLex , bertini::node::GrevLex } |
| Pluggable monomial orders for canonicalization. More... | |
Functions | |
| MonomialOrder | bertini::node::CurrentMonomialOrder () |
| The monomial order currently used for canonicalization (session-global – it must be consistent session-wide, since it determines interned identity). | |
| void | bertini::node::SetMonomialOrder (MonomialOrder order) |
| Set the session-wide monomial order (determines interned identity). | |
| bool | bertini::node::CanonicalizeByDefault () |
| Whether Sum/Mult construction canonicalizes operand order by default. | |
| void | bertini::node::SetCanonicalizeByDefault (bool on) |
| Set whether Sum/Mult construction canonicalizes operand order by default. | |
| bool | bertini::node::PowerFoldByDefault () |
| Whether Mult construction flattens + power-folds (x*x -> x^2) by default. | |
| void | bertini::node::SetPowerFoldByDefault (bool on) |
| Set whether Mult construction flattens + power-folds by default. | |
| void | bertini::node::CanonicalizeNaryOperands (std::vector< std::shared_ptr< Node > > &operands, std::vector< bool > &flags, bool multiplicands_first) |
| Sort an n-ary operator's (operand, flag) pairs into canonical order, in place. | |
Canonical ordering of commutative-operator operands (reorder-only).
When canonicalization is enabled, the operands of a Sum / Mult are sorted into a deterministic, content-based canonical order BEFORE the node is interned, so that structurally-equal-up-to-reordering expressions (x+y and y+x) collapse to one shared node.
The order is a pluggable monomial order – Lex / RevLex / GrevLex – on the operands' exponent vectors (via Node::MultiDegree), built on the global variable order BY NAME (node::GatherVariables already returns variables sorted alphabetically). Non-polynomial operands sort after the polynomial ones, with a printed-form tie-break to stay total.
For a Mult, before sorting the operands are also FLATTENED (nested products spliced into one factor list) and POWER-FOLDED (repeated bases collapsed into a single IntegerPower – x*x -> x^2, y*x*x -> x^2*y, x*x/x -> x). This makes a squared factor the same interned IntegerPower node the differentiator emits, so the SLP computes it once and shares it between the function and its Jacobian. Numeric constants are left alone (2*2 stays 2*2 – constant folding is a separate pass). Sums are still sort-only (like-term folding for sums – a full polynomial normal form – is future work).
Nothing here changes Node::Hash()/IsSame(): canonicalization is a normalization applied at construction, and the existing order-sensitive predicates then see the normalized order.