Godtone
Joined 17 December 2020
→My Python 3 code: added code for determining gen ranges for (nL)L(ns)s MOSSes |
|||
| Line 620: | Line 620: | ||
def unfact(f, p=None): | def unfact(f, p=None): | ||
return unfact_int([max(n,0) for n in f],p), unfact_int([-min(d,0) for d in f],p) | return unfact_int([max(n,0) for n in f],p), unfact_int([-min(d,0) for d in f],p) | ||
# to simplify an existing rational "x" expressed as a (pythonic) 2-tuple, use: "iv(*x)" | |||
def iv(n, d, p=None): # provides automatic reduction to simplest form | def iv(n, d, p=None): # provides automatic reduction to simplest form | ||
if n==0: | if n==0: | ||
| Line 1,072: | Line 1,073: | ||
def mediant(r1, r2): | def mediant(r1, r2): | ||
return | return (r1[0] + r2[0], r1[1] + r2[1]) | ||
def mediant_iv(r1, r2): # for convenience; provides simplified form | |||
return iv(*mediant(r1,r2)) | |||
def mulmediant(r, k): | |||
return (r[0]*k, r[1]*k) | |||
</syntaxhighlight> | </syntaxhighlight> | ||