Refactor arithmetic code. More symbolic result tracking.
Bug:21957368 Add UnifiedReal class, which represents the product of a CR and a BoundedRational. Preferring well-known constants in the CR part allows us to perform some symbolic-like symplifications, such as keeping track of rational multiples of pi. But the real motivation for this change is to factor out the combined rational/CR logic, so that we can reuse it for other applications. Our limited symbolic manipulations have several immediate effects: - Evaluator.java is cleaner. The actual arithmetic is isaolated to UnifiedReal.java, BoundedRational.java, and the external CR.java. - We can display exact symbolic representations for some irrationals. - We are guaranteed to produce correctly truncated results for those values. Switches from zeroes to 9s can no longer occur for those. - We are more likely to be able to detect division by zero up front instead of diverging. 1/(pi - pi) is detectable. - Factorial argument validity checks are more likely to be exact. - We can commonly determine the leading digit of a number near zero, and hence quickly produce appropriate scientific notation more often. - Radian trig evaluations, like sin(pi), now produce exact rational results. We also remove the separate degree-based trig function implementations, since they are no longer needed. Degrees transalate to exact multiples of pi, which are now tracked correctly. The logic for producing exact results from trig functions at special points moved from BoundedRational to UnifiedReal, and was strengthened. BoundedRational now uses a random normalization strategy, to allow MAX_SIZE to be increased sufficiently to get more benefits from some of the other changes. Break BRTest.java into UnifiedRealTest.java and BoundedRationalTest.java. The tests are still useful, but some now only apply to UnifiedReal, since the transcendental functions no longer exist in BoundedRationsl. Change-Id: Ic9d5d70252d54e17043c7328f69d93ab9225223f
Loading
Please register or sign in to comment