Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions mathfunctionize/algebra.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import arithmetic
def algebraGamma(x):
if x == 0 or (x < 0 and x % 1 == 0):
raise Exception("Invalid input")
if x == 1:
return 1
if x == 0.5:
return algebraSquareRoot(3.141592653589793)
return (x - 1) * algebraGamma(x - 1)
def algebraFactorial(x):
if x == 0:
return 1
else:
return x * algebraFactorial(x-1)
def algebraAbsolute(x):
if x < 0:
return -x
else:
return x
def algebraSquareRoot(x):
return x ** (1/2)
def algebraCubeRoot(x):
return x ** (1/3)
def algebraNthRoot(x, n):
return x ** (1/n)
def algebraRound(x, place):
if (place > 0 and arithmetic.arithmeticModulo(place, 10) == 0) or (place == 1):
if arithmetic.arithmeticModulo(x, place) < (arithmetic.arithmeticMultiplication(0.5, place)):
return arithmetic.arithmeticFlatDivision(x, place)
return arithmetic.arithmeticFlatDivision(x, place) + place
30 changes: 8 additions & 22 deletions mathfunctionize/mathfunctionize.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,21 @@ def modulo(a, b):
def flatDivision(a, b):
return arithmetic.arithmeticFlatDivision(a, b)
# algebra
import algebra
def gamma(x):
if x == 0 or (x < 0 and x % 1 == 0):
raise Exception("Invalid input")
if x == 1:
return 1
if x == 0.5:
return squareRoot(pi)
return (x - 1) * gamma(x - 1)
return algebra.algebraGamma(x)
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x-1)
return algebra.algebraFactorial(x)
def absolute(x):
if x < 0:
return -x
else:
return x
return algebra.algebraAbsolute(x)
def squareRoot(x):
return x ** (1/2)
return algebra.algebraSquareRoot(x)
def cubeRoot(x):
return x ** (1/3)
return algebra.algebraCubeRoot(x)
def nthRoot(x, n):
return x ** (1/n)
return algebra.algebraNthRoot(x, n)
def round(x, place):
if (place > 0 and modulo(place, 10) == 0) or (place == 1):
if modulo(x, place) < (multiplication(0.5, place)):
return flatDivision(x, place)
return flatDivision(x, place) + place
return algebra.algebraRound(x, place)
# counting
def combinations(n, r):
return division(permutations(n, r), factorial(r))
Expand Down
Loading