CAS stands for computer algebra system and is any software meant to manipulate mathematical expressions. Popular software of this form are SymPy, Sage, and Maple.

Debugging these types of systems can be difficult. Inputs to the same mathematical function might send you into wildly different areas of the code base (but that is not clear a priori). Especially in the case of SymPy, a very complex codebase which makes extensive use of Python's overloading capabilities.

My go-to debugging strategy in this scenario is to, run both input instances simultaneously then step through each in parallel. This can be arduous and super easy to miss the diverging point.

I created a small debugging aid, called divergence. The tool helps you figure out where two different inputs diverge in their respective stack traces.

Simply choose which function you’re trying to test, create a testing method for it, tack on the @diverge decorate at the top with the corresponding two arguments and run! It’ll return whether they diverge and if so, which function they diverge at. A trivial example below:

    
    from divergence import diverge

    args = {"arg1": (3,5), "arg2": (0,0)}

    @diverge(args)
    def test_min(a,b):
	return min(a,b)

    test_min()
    
    

A few remarks on the tool:

Divergence is very hacky, so I don't expect it to work super well, but if you have any feedback on the approach I took in trying to solve this problem, I'd love to hear it!