From eeeba9fb8500f36aa3f91ab2b927a61d1d7be65c Mon Sep 17 00:00:00 2001 From: Nick Drozd Date: Wed, 3 Jan 2024 16:03:09 -0600 Subject: [PATCH] Use estimate for assert_less --- test/test_num.py | 82 ++++++++++++++++++++++++++++++++---------------- tm/num.py | 7 +++++ 2 files changed, 62 insertions(+), 27 deletions(-) diff --git a/test/test_num.py b/test/test_num.py index d9df3cd5..c64c3151 100644 --- a/test/test_num.py +++ b/test/test_num.py @@ -63,9 +63,9 @@ def tearDownClass(cls): assert_num_counts({ "adds": 2259, "divs": 2068, - "exps": 1227, + "exps": 1231, "muls": 1401, - "totl": 6955, + "totl": 6959, }) def assert_mod( @@ -113,10 +113,27 @@ def assert_num( self.assert_mod(num, mod, rem) - def assert_less(self, val1: Count, val2: Count): - self.assertLess(int(val1), int(val2)) + def assert_less( + self, + val1: Count, + val2: Count, + estimate: bool = False, + ): self.assertLess(val1, val2) + if not estimate: + self.assertLess( + int(val1), + int(val2)) + + else: + assert not isinstance(val1, int) + assert not isinstance(val2, int) + + self.assertLessEqual( + val1.estimate(), + val2.estimate()) + def assert_less_not_implemented( self, val1: Count, @@ -728,9 +745,10 @@ def test_comparisons(self): Exp(10, 3 + Exp(10, Exp(10, 3))) < Exp(10, 3 + Exp(10, 3))) - self.assertTrue( - Exp(10, 3 + Exp(10, 3)) - < Exp(10, 3 + Exp(10, Exp(10, 3)))) + self.assert_less( + Exp(10, 3 + Exp(10, 3)), + Exp(10, 3 + Exp(10, Exp(10, 3))), + estimate = True) self.assert_less_not_implemented( Exp(2, 13) * (-1 + Exp(2, 13)), @@ -740,9 +758,10 @@ def test_comparisons(self): 2 ** (-3 + Exp(2, 13)), )) - self.assertLess( + self.assert_less( -Exp(10, 14050258128), - Exp(10, 14050259810)) + Exp(10, 14050259810), + estimate = True) self.assert_less_not_implemented( Exp(3, 5) * (-243 + (3 ** Exp(3, 5))), @@ -752,21 +771,25 @@ def test_comparisons(self): 3 ** Exp(3, 5), )) - self.assertLess( + self.assert_less( Exp(2, 5) * (-1 + (2 ** (-5 + Exp(2, 5)))), - -1 + (Exp(2, 5) * (-1 + (2 ** (-5 + (2 ** Exp(2, 5))))))) + -1 + (Exp(2, 5) * (-1 + (2 ** (-5 + (2 ** Exp(2, 5)))))), + estimate = True) - self.assertLess( + self.assert_less( Exp(2, 5) * (-1 + (2 ** (-5 + Exp(2, 5)))), - Exp(2, 5) * (-1 + (2 ** (-5 + (2 ** Exp(2, 5)))))) + Exp(2, 5) * (-1 + (2 ** (-5 + (2 ** Exp(2, 5))))), + estimate = True) - self.assertLess( + self.assert_less( -1 + (2 ** (-5 + Exp(2, 5))), - -1 + (2 ** (-5 + (2 ** Exp(2, 5))))) + -1 + (2 ** (-5 + (2 ** Exp(2, 5)))), + estimate = True) - self.assertLess( + self.assert_less( 2 ** (-5 + Exp(2, 5)), - 2 ** (-5 + (2 ** Exp(2, 5)))) + 2 ** (-5 + (2 ** Exp(2, 5))), + estimate = True) self.assertFalse( -(Exp(2, 65536) * (-1 + 2 ** (-65536 + Exp(2, 65536)))) @@ -784,25 +807,28 @@ def test_comparisons(self): ((2 + Exp(2, 3)) * 2 ** ((-4 + (5 * Exp(2, 11))) // 3)) < Exp(2, 3)) - self.assertLess( + self.assert_less( Exp(2, 33) * (1 + Exp(2, 2)), - (1 + Exp(2, 2)) * 2 ** (-3 + (Exp(2, 33) * (1 + Exp(2, 2))))) + (1 + Exp(2, 2)) * 2 ** (-3 + (Exp(2, 33) * (1 + Exp(2, 2)))), + estimate = True) self.assertFalse( (10 ** Exp(10, 8274649522)) < 8274649524 + Exp(10, 8274649522)) - self.assertLess( + self.assert_less( -(Exp(2, 11760) * (1 + Exp(2, 5879))) + (Exp(2, 20578) * (-1 + (11 * Exp(2, 1469)))), - (Exp(2, 44097) * (-1 + (11 * Exp(2, 1469)))) + -(Exp(2, 23520) * (1 + (Exp(2, 11759) * (1 + Exp(2, 5879)))))) + (Exp(2, 44097) * (-1 + (11 * Exp(2, 1469)))) + -(Exp(2, 23520) * (1 + (Exp(2, 11759) * (1 + Exp(2, 5879))))), + estimate = True) self.assert_less( Exp(2, 3), Exp(2, 3) * (2 + Exp(2, 3))) - self.assertLess( + self.assert_less( Exp(2, 3) * (2 + (Exp(2, 3) * (2 + (Exp(2, 3) * (2 + (Exp(2, 3) * (2 + Exp(2, 3)))))))), - Exp(2, 3) * (2 + (Exp(2, 3) * (2 + (Exp(2, 3) * (2 + (Exp(2, 3) * (2 + (Exp(2, 3) * (2 + Exp(2, 3))))))))))) + Exp(2, 3) * (2 + (Exp(2, 3) * (2 + (Exp(2, 3) * (2 + (Exp(2, 3) * (2 + (Exp(2, 3) * (2 + Exp(2, 3)))))))))), + estimate = True) self.assertFalse( (3 * 2 ** (5 + (Exp(2, 5) * (1 + 2 ** Exp(2, 5))))) @@ -812,9 +838,10 @@ def test_comparisons(self): (-(Exp(2, 8) * (-1 + 2 ** (-8 + Exp(2, 8)))) + (Exp(2, 8) * (-1 + 2 ** (-8 + 2 ** 2 ** Exp(2, 8))))) < ((Exp(2, 8) * (-1 + 2 ** (-8 + 2 ** Exp(2, 8)))) + -(Exp(2, 8) * (-1 + 2 ** (-8 + Exp(2, 8)))))) - self.assertLess( + self.assert_less( Tet(10, 2), - Tet(10, 3)) + Tet(10, 3), + estimate = True) self.assertGreater( Tet(10, 3), @@ -860,9 +887,10 @@ def test_comparisons(self): Exp(2, 13), )) - self.assertLess( + self.assert_less( 2 ** (Exp(2, 19) * (-1 + (2 ** (-17 + Exp(2, 19))))), - 2 ** (2 + (Exp(2, 19) * (-1 + (2 ** (-17 + Exp(2, 19))))))) + 2 ** (2 + (Exp(2, 19) * (-1 + (2 ** (-17 + Exp(2, 19)))))), + estimate = True) self.assertGreater( Tet(10, 5), diff --git a/tm/num.py b/tm/num.py index e92f2b32..8aff1e67 100644 --- a/tm/num.py +++ b/tm/num.py @@ -1060,6 +1060,9 @@ def __lt__(self, other: Count) -> bool: if r.exp <= exp: return (self // r) < l + elif isinstance(other, Tet): + return other > self + return super().__lt__(other) # no-cover def __pow__(self, other: Count) -> Exp: @@ -1119,6 +1122,10 @@ def __lt__(self, other: Count) -> bool: return self.height < other.height + if isinstance(other, Exp): # no-branch + if isinstance(other.exp, int) and 2 < self.height: + return False + return super().__lt__(other) def __add__(self, other: Count) -> Count: