CAS Best Practices

I was warning that x-x is tricky. It’s actually fairly safe to transform it to 0*x. For one, that’s type-safe, in the sense that x is still around, so you know the result’s type properly. (Polymorphic 0 is a major pain.)

If your numeric types include infinities, then this is required. If your numeric types only contain finite values, and will never contain anything other than classical numbers (vectors, matrices and series all have non-trivial claims to be kinds of numbers too) like the reals, complex, etc, that might be safe. But it depends very strongly on your meaning of ‘number’.

5 Likes