Godtone (talk | contribs)
m add function to aid measuring complexity of intervals for designing custom optimizations
Godtone (talk | contribs)
m My Python 3 code: allow using factorization to avoid re-factorizations
Line 1,244: Line 1,244:
# the interval (x) and the the numerator (n) and denominator (d) of the interval once 2's have been removed.
# the interval (x) and the the numerator (n) and denominator (d) of the interval once 2's have been removed.
# for examples:
# for examples:
# * no-2's benedetti height: iv_complexity(x, lambda x,n,d: n*d)
# * no-2's benedetti height: iv_complexity(x, lambda x,f,n,d: n*d)
# * halving the odd-limit of harmonic intervals: iv_complexity(x, lambda x,n,d: max(n,d)/(1 if d>1 else 2))
# * halving the odd-limit of harmonic intervals: iv_complexity(x, lambda x,f,n,d: max(n,d)/(1 if d>1 else 2))
def iv_complexity(x, func=lambda x,n,d: max(n,d)):
def iv_complexity(x, func=lambda x,f,n,d: max(n,d)):
f = convert(x,list) # to monzo
f = convert(x,list) # to monzo
num2s = f[0] # save
f[0] = 0
f[0] = 0
no2s_x = unfact(f)
no2s_x = unfact(f)
if func==3: # sopfr would be slow to implement manually using this function
f[0] = num2s # restore
if func==3:
return sum([ prime_idx(i)*f[i] for i in range(len(f)) ])
return sum([ prime_idx(i)*f[i] for i in range(len(f)) ])
return no2s_x[0] * no2s_x[1] if func==2 else math.log(no2s_x[0] * no2s_x[1], 2) if func==1 else func(x, no2s_x[0], no2s_x[1])
return no2s_x[0]*no2s_x[1] if func==2 else math.log(no2s_x[0]*no2s_x[1], 2) if func==1 else func(x, f, no2s_x[0], no2s_x[1])


</syntaxhighlight>
</syntaxhighlight>