Godtone
Joined 17 December 2020
added some python 3 code i think should be fine for experimenting with/further building on, needs extra proofreading just in case though |
m →My Python 3 code: renaming for clarity |
||
| Line 500: | Line 500: | ||
def iv(n, d, p=None): # provides automatic reduction to simplest form | def iv(n, d, p=None): # provides automatic reduction to simplest form | ||
return unfact(fact( (n,d),p ),p) | return unfact(fact( (n,d),p ),p) | ||
def as_float( | def as_float(x, p=None): | ||
if type( | if type(x)==list: # monzo (factored) | ||
uf = unfact( | uf = unfact(x, p) | ||
return uf[0] / uf[1] | return uf[0] / uf[1] | ||
elif type( | elif type(x)==tuple: # ratio (unfactored) | ||
return | return x[0] / x[1] | ||
else: | else: # assumed to already be a float (or integer) | ||
return | return x | ||
# Converts a prime factorisation into a prettier and potentially | # Converts a prime factorisation into a prettier and potentially | ||