lubgr / tsym

Tiny symbolic library
GNU General Public License v3.0
6 stars 2 forks source link

add < and > operators to Var class #8

Closed lubgr closed 6 years ago

lubgr commented 7 years ago

There is no consistent boolean return value, because e.g. comparing two symbols will yield an unclear result. Using the order relation of these two symbols could be a choice, but obscures the difference between comparisons of e.g. numbers (or operands which can be compared with a definite result) and symbols (or operators that can't). A new Comparison object should instead be returned.

Implementation of the actual comparison can be achieved by a lessThan method that subtracts the right hand side from the left hand side and comparing to zero. This way, automatic simplification does the work, e.g. 3ab < 4ab results into -a*b < 0, which is unclear if a and b aren't symbols with a positive flag, and true otherwise.

Public methods of the Comparison class could be isTrue(), isFalse(), isUnclear(), isTrueByOrderRelation() etc.

lubgr commented 6 years ago

The confusion these operators cause would probably be too big, the gain isn't worth it. When the above exemplary check 3ab < 4ab must be made, the mechanism (3ab - 4ab) < 0 could be made manually in client code.