Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Algrbra Package
#1
#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:

# 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"


Messages In This Thread
Algrbra Package - by kmcollins - Feb-02-2018, 07:42 PM
RE: Algrbra Package - by Mekire - Feb-02-2018, 10:33 PM
RE: Algrbra Package - by kmcollins - Feb-02-2018, 11:50 PM
RE: Algrbra Package - by kmcollins - Feb-03-2018, 11:11 PM
RE: Algrbra Package - by Gribouillis - Feb-04-2018, 12:31 AM
RE: Algrbra Package - by Windspar - Feb-04-2018, 02:55 PM
RE: Algrbra Package - by kmcollins - Feb-04-2018, 07:30 PM
RE: Algrbra Package - by kmcollins - Feb-06-2018, 12:02 AM
RE: Algrbra Package - by wavic - Feb-06-2018, 02:17 AM
RE: Algrbra Package - by kmcollins - Feb-06-2018, 04:22 PM
RE: Algrbra Package - by Gribouillis - Feb-06-2018, 06:11 PM
RE: Algrbra Package - by wavic - Feb-06-2018, 07:50 PM
RE: Algrbra Package - by kmcollins - Feb-06-2018, 09:54 PM
RE: Algrbra Package - by micseydel - Feb-06-2018, 11:02 PM
RE: Algrbra Package - by wavic - Feb-07-2018, 06:10 AM
RE: Algrbra Package - by kmcollins - Feb-07-2018, 09:06 PM
RE: Algrbra Package - by Gribouillis - Feb-07-2018, 09:37 PM
RE: Algrbra Package - by Mekire - Feb-08-2018, 01:45 AM
RE: Algrbra Package - by metulburr - Feb-08-2018, 02:02 AM
RE: Algrbra Package - by kmcollins - Feb-08-2018, 10:04 PM
RE: Algrbra Package - by Gribouillis - Feb-08-2018, 10:17 PM
RE: Algrbra Package - by kmcollins - Feb-08-2018, 11:26 PM
RE: Algrbra Package - by metulburr - Feb-08-2018, 11:52 PM
RE: Algrbra Package - by Mekire - Feb-09-2018, 04:47 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020