Godtone (talk | contribs)
→My Python 3 code: correction to softly allow negatives
Godtone (talk | contribs)
→My Python 3 code: added code for determining gen ranges for (nL)L(ns)s MOSSes
Line 1,038: Line 1,038:
print( striv(worstupperiv), str(maxerr)+'c' )
print( striv(worstupperiv), str(maxerr)+'c' )
print( striv(worstloweriv), '-'+str(-minerr)+'c' )
print( striv(worstloweriv), '-'+str(-minerr)+'c' )
def bright_gen(nL, ns): # credit to inthar for this function
nL, ns = nL//math.gcd(nL, ns), ns//math.gcd(nL, ns)
path = []
while nL > 1 or ns > 1:
path.append((nL, ns))
nL, ns = min(nL, ns), abs(nL - ns)
result = [1, 0]
for j in range(len(path)-1, -1, -1):
child_nL, child_ns = path[j][0], path[j][1]
if child_nL > child_ns:
result = [child_nL - (result[0] + result[1]), child_ns - result[0]]
else:
result = [result[0], result[0] + result[1]]
return result
def bright_gens(nL, ns):
r = bright_gen(nL, ns)
return [iv(r[0], nL), iv(r[0]+r[1], nL+ns)]
def least_gens(nL, ns):
d = math.gcd(nL,ns)
r = bright_gens(nL//d, ns//d)
if as_float(r[0])>=1/2:
r[0] = sub_iv((1,1), r[0])
if as_float(r[1])>=1/2:
r[1] = sub_iv((1,1), r[1])
if as_float(r[0]) > as_float(r[1]):
r = [r[1], r[0]]
return [mul_iv( r[0], (1,d) ), mul_iv( r[1], (1,d) )]
def mediant(r1, r2):
return iv(r1[0] + r2[0], r1[1] + r2[1])
</syntaxhighlight>
</syntaxhighlight>