[GSoC 2026] Proposing Piecewise Algebra Engine

33 views
Skip to first unread message

Vishu Saini

unread,
Mar 9, 2026, 3:16:43 PM (3 days ago) Mar 9
to sympy
Greetings to all the mentors and fellow contributors out there

Recently when i was exploring the sympy codebase, i noticed some limitations around handling piecewise expressions, when multiple piecewise expressions interact, the resulting expressions often contain redundant conditions, overlapping region and fragmented logical structures which causes these expressions to grow unnecessarily complex and harder to simplify or manipulate symbolically

Yes, i agree that there are already partial mechanisms such as the "Piecewise" class and some helper utilities that perform limited simplifications but not to be forgotten that these mainly operate locally and do not provide a systematic way to reason about the full domain defined by the conditions, in this context, it seems that sympy currently lacks a structured algebra layer for piecewise expressions

I am thinking about proposing a "Piecewise Algebra Engine" that performs domain partitioning algebra. The idea would be to extract condition boundaries from interacting piecewise expressions, partition the domain into minimal non overlapping regions, evaluate the expression within each region, merge equivalent regions and produce a canonical and simplified piecewise representation

The initial scope would focus on algebraic operations involving piecewise expressions, particularly addition, multiplication and simplification with the goal of normalising the resulting expressions into a minimal canonical form, the implementation could be build on existing infrastructure by leveraging relational conditions, logical simplification and interval reasoning already present in the sets and logic modules and by extending the existing piecewise implementation in "sympy/functions/elementary/piecewise.py"

If the mentors love the direction, the work would require the following task to be done:
• extracting condition boundaries from interacting piecewise expressions
• designing a domain partitioning algorithm to construct minimal non overlapping intervals
• evaluating algebraic expressions within each partitioned region
• implementing region-merging logic to collapse adjacent regions that produce identical expressions
• producing canonical piecewise representations after algebraic operations
• supporting normalised results for addition and multiplication between piecewise expressions
• integrating the normalisation workflow with the existing "Piecewise" infrastructure
• adding extensive test coverage across a wide range of symbolic and conditional cases
• evaluating behaviour on representative symbolic workloads involving piecewise expressions

In my opinion, this could be quite practical since piecewise expressions appear very frequently across symbolic workflows. Improving this area could directly benefit several subsystems including simplification, integration, solvers, sets and the assumptions framework therefore impacting a large portion of the ecosystem, no doubt sympy already has strong building blocks such as piecewise expressions, relational conditions and interval reasoning but they are not yet fully integrated into a unified algebraic workflow and that is my idea

Also let us not forget the area where we can lack, two aspects that will require careful attention is controlling region explosion when multiple piecewise expressions interact and ensuring extensive test coverage due to the wide variety of symbolic cases involved

I would really appreciate everyone's guidance whether this idea is project worthy or is there any area which i might have missed
Reply all
Reply to author
Forward
0 new messages