def log(A, B): """ A ⍟ B """ try: if A == 10: return math.log10(B) # Python 3.3 and later # if A == 2: return math.log2(B) return math.log(B, A) except ValueError: if fuzzyEquals(A, B): return 1.0 if fuzzyEquals(A, 0): return 0.0 if fuzzyEquals(B, 1): return 0.0 except ZeroDivisionError: if fuzzyEquals(A, B): return 1.0 assertError("DOMAIN ERROR")
def divide(A, B): """ A ÷ B """ try: return operator.truediv(A, B) except ZeroDivisionError: if fuzzyEquals(A, 0) and fuzzyEquals(B, 0): return 1 assertError("DOMAIN ERROR")
def gt(A, B): """ A > B """ if isinstance(A, int) and isinstance(B, int): return int(operator.gt(A, B)) if fuzzyEquals(A, B): return 0 return int(operator.gt(A, B))
def ge(A, B): """ A ≥ B """ if isinstance(A, int) and isinstance(B, int): return int(operator.ge(A, B)) if fuzzyEquals(A, B): return 1 return int(operator.ge(A, B))
def ne(A, B): """ A ≠ B """ if isinstance(A, int) and isinstance(B, int): return int(operator.ne(A, B)) if isinstance(A, str) and isinstance(B, str): return int(operator.ne(ord(A), ord(B))) try: return int(not fuzzyEquals(A, B)) except TypeError: return 1
def eq(A, B): """ A = B """ if isinstance(A, int) and isinstance(B, int): return int(operator.eq(A, B)) if isinstance(A, str) and isinstance(B, str): return int(operator.eq(ord(A), ord(B))) try: return int(fuzzyEquals(A, B)) except TypeError: return 0
def residue(A, B): """ A | B """ if isinstance(A, int): if A == 0: return B else: if fuzzyEquals(A, 0): return B if isinstance(fuzzyInteger(operator.truediv(B, A)), int): return 0 R = math.fmod(B, A) if (R < 0) != (A < 0): R += A if isinstance(A, int) and isinstance(B, int): R = int(R) return R