Skip to main content

A simple python package for algebraic calculations

Project description

algebra

Install with PyPi

pip install algebra.py

How to use

Importing

from algebra.components import term

Initializing

Note: to see the output shown in the comments you will need to run print() or str() at the answer

Note:Do not use j as a variable.it is being used for complex number handling

term1 = term('2x')# 2x
#exponent in terms
term2 = term('2x²')# 2x²
term3 = term('2x2')# also works
#supports multiple variables
term4 = term('2x2y3')# 2x²y³
# suports negative coefficients
term5 = term('-2x3')# -2x³
#supports complex exponents and coefficients
term6 = term('2x2+2j')# 2x²⁺²ⁱ
term7 = term('3+1jx3')# (3+1j)x³

Accesssing properties

t1 = term('2x3+2jy4+3j') # 2x³⁺²ⁱy⁴⁺³ⁱ
# coefficient
t1.coefficiente # 2
# variables
t1.variables # list of the variables,in alphabetic order
t1.variables[0].letra # x
t1.variables[0].exponente # (3+2j)

Supported Operations

sum

substraction is supported the same way

sum1 = term('2x') + term('3x')# 5x
sum2 = term('2x') + term('2y')# 2x + 2y
# supports integer,float or decimal sums
sum3 = term('3x') + 4 # 3x + 4
# supports complex sums
sum4 = term('3x2+1j') + term('3x3+2j') # 3x²⁺¹ⁱ + 3x³⁺²ⁱ
#supports sums with complex numbers
sum5 = term('3x2+1j') + 5-2j # 3x²⁺¹ⁱ + (5-2j)

multiplication

mul1 = term('2x') * 4# 8x
mul2 = term('2x') * term('3x')# 6x²
mul3 = term('2x') * term('3y')# 6xy
mul4 = term('2xy') * term('3yz')# 6xy²z
mul5 = term('3x1+3j') * term('3x')# 9x²⁺³ⁱ
mul6 = term('3x1+3j') * (2+1j) # (6+3j)x¹⁺³ⁱ
mul7 = term('3x1+3j') * term('3x2+4j')#9x³⁺⁷ⁱ

division

div1  = term('4x')/2 # 2x
div2 = term('4x')/term('2x')# 2
div3 = term('4x2')/term('4x')# x
div4 = term('4x')/term('4x2')# xᐨ¹
div5 = term('4x2')/term('4x2')# 1

Exponentiation

exp1 = term('2x')**2 #4x²
exp2 = term('2x')**-1 # 0.5xᐨ¹
exp2 = term('2x')**term('2x')# not supported
exp3 = term('2x')**2.5 # 5.656854249492381x⁵ᐟ²

polynoms

example

pol1 = term('2x') + term('3y') # 2x + 3y
pol2 = term('2x') - 2 # 2x - 2
# polynom properties
pol2.variables # list of terms
pol2.variables[0] # 2x
pol2.variables[1] # -2
# sum
pol4 = pol1 + pol2 #  4x + 3y - 2
# multiplication
pol5 = pol1 * pol2 # 4x² + 6xy + -4x + -6y'
# exponentiation
pol6 = pol1**2 # 4x² + 12xy + 9y²
pol7 = pol1**2.5 # non-integer powers are not yet supported
pol8 = pol1**pol2 # not supported
div1  = pol1/2 # x + 1.5y
div2 = pol1/term('2x')# 1 + 1.5xᐨ¹y
div3 = pol1/pol2 # not supported

substituting numbers to the variables

term1 = term('2y')
pol1 = term('2x') + term('3y')
term1.plot(y=2) # 4
pol1.plot(x=2,y=3)# 13
# univ sets every variable which does not has a value to its value
pol1.plot(univ=5) # 25 (x=5,y=5)
pol1.plot(x=2,univ=4) # 16 (only replaces y,x is set to 2)

accessing properties on terms

t1 = term('2x²y')
t1.coefficiente # acceses the coefficient (2)
t1.variables # accesses the list of variables (returns [x²,y])
t1.variables[0].letra # x
t1.variables[0].exponente # 2

accessing properties on polynoms

t1 = term('2x²y')
t2 = 2
p1 = t1 + t2 # 2x²y + 2
p1.variables # [term(2x²y),2]
for i in p1:
    print(i) 
    #  iterating a polynom iterates over the list of terms
    #  it contains 
# term() objects cannot be iterated over

polynoms support sum, substraction, multiplication and exponents as terms do.

have fun!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

algebra_py-1.4.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

algebra_py-1.4.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file algebra_py-1.4.0.tar.gz.

File metadata

  • Download URL: algebra_py-1.4.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for algebra_py-1.4.0.tar.gz
Algorithm Hash digest
SHA256 1c3004e50831d19552275eee03d3329c4cbeff3fa3eadca53a9df7c84e40a6e9
MD5 c66d21455d77ca3f57a7894b564529c0
BLAKE2b-256 946508b74f982c5497c96a5370f67afa2011b1a634452103eb8afef4a391383f

See more details on using hashes here.

File details

Details for the file algebra_py-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: algebra_py-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for algebra_py-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 838c60df7ac0ba4deee59df7d8df02ca67b9f91f92f16e15f4c5100fc55abe34
MD5 00378481b2f6774d48f9b083e6bdd417
BLAKE2b-256 d67a3ca811e38d1e37a2a80c79460ca70a2bb125655e98b3dd6ccf209f900de1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page