#I'm working on an algebra package for Python. It includes a LinearRelationship class where every instance is
#a function of the general form y = mx + b, and I'm planning on adding as many of the basic function forms as I
#can, e.g. polynomials as a general class. Here's the Numbers module so far:
#a function of the general form y = mx + b, and I'm planning on adding as many of the basic function forms as I
#can, e.g. polynomials as a general class. Here's the Numbers module so far:
# Module: Numbers # Date Started: February 2, 2018 # Author: George Keith Watson, a.k.a. Keith Michael Collins # Copyrights: (c) 2017 George Keith Watson, a.k.a. Keith Michael Collins # Application: Chemistry Laboratory, including Medical. # Documentation: # import math class Rational: registry = {} def __init__(self, name, numerator, denominator): self.name = None self.numerator = None self.denominator = None self.floatValue = None if name != None and isinstance(name, str) and numerator != None and isinstance(numerator,int) and \ denominator != None and isinstance(denominator, int): self.name = name self.numerator = numerator self.denominator = denominator Rational.registry[name] = self def floatValue(self): return self.numerator / self.denominator def isInteger(self): if self.denominator == 1: return True self.floatValue = self.floatValue() if self.floatValue - math.floor( self.floatValue ) == 0: return True return False def isWhole(self): if self.isInteger(): self.floatValue = self.floatValue() return self.floatValue >= 0 return False def isNatural(self): if self.isWhole(): return self.floatValue >= 1 return False def set(self, numerator=None, denominator=None): if numerator != None: self.numerator = numerator if denominator != None: self.denominator = denominator return self def __str__(self): return str(self.numerator) + " / " + (str(self.denominator)) class Real: registry = {} def __init__(self, name, value, sigDigits=None): self.name = None self.value = None self.sigDigits = None if name != None and isinstance(name, str) and value != None and isinstance(value, float): self.name = name self.value = value Real.registry[name] = self def set(self, value=None, sigDigits=None): if value != None and (isinstance(value,float) or isinstance(value,Real)): self.value = value if sigDigits != None and isinstance(sigDigits,int) and sigDigits > 0: self.sigDigits = sigDigits return self def __str__(self): return str(self.value) class Imaginary: registry = {} def __init__(self, name, coefficient): self.name = None self.coefficient = None if name != None and isinstance(name, str) and coefficient != None and \ (isinstance(coefficient,int) or isinstance(coefficient, float) or isinstance(coefficient,Real)): self.name = name self.coefficient = coefficient Imaginary.registry[name] = self def set(self, coefficient): if coefficient != None and (isinstance(coefficient,int) or isinstance(coefficient, float) or isinstance(coefficient,Real)): self.coefficient = coefficient return self def __str__(self): return str(self.coefficient) + "i" class Complex: registry = {} def __init__(self, name, x, y): "z = x + iy" self.x = None self.y = None self.name = None if name != None and isinstance(name, str) and x != None and (isinstance(x, float) or isinstance(x,Real)) and \ y != None and (isinstance(y,float) or isinstance(y,Real)): self.name = name self.x = x self.y = y Complex.registry[name] = self def set(self, x=None,y=None): if x != None and (isinstance(x, float) or isinstance(x,Real)): self.x = x if y != None and (isinstance(y, float) or isinstance(y,Real)): self.y = y return self def __str__(self): return str(self.x) + " + " + str(self.y) + "i"