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.3.1.tar.gz (8.2 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.3.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: algebra_py-1.3.1.tar.gz
  • Upload date:
  • Size: 8.2 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.3.1.tar.gz
Algorithm Hash digest
SHA256 047e3d0e2a1485f8f5a42b17aa44ea6ac56d29a8f625aa23e0f99efe41a316b4
MD5 0a883ed2942bd54e9492751919a1433a
BLAKE2b-256 5d9dbbd82d4d62d3594a7faf61eb55c1caffb55271e2dc130e52eef6a4cd6009

See more details on using hashes here.

File details

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

File metadata

  • Download URL: algebra_py-1.3.1-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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 df8103c694d6f573dffd40b9f8daf9f2e8ccc74d718ba18f17fb18d2efdc9ef5
MD5 7079589e9a3f8c3104c9a0efa8aaf2ca
BLAKE2b-256 c033bfecceb86303f041d81b24aabbd0610a1cd42b01ac32c366ef78e3376963

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