Godtone (talk | contribs)
Godtone (talk | contribs)
m add function to aid measuring complexity of intervals for designing custom optimizations
Line 1,239: Line 1,239:
def identity_M(dim): # dim by dim identity matrix (of dimension dim); self-explanatory
def identity_M(dim): # dim by dim identity matrix (of dimension dim); self-explanatory
return sum([[ [0]*i + [1] + [0]*(dim-1-i) for i in range(dim) ]],[])
return sum([[ [0]*i + [1] + [0]*(dim-1-i) for i in range(dim) ]],[])
# leave 2nd parameter unspecified for odd-limit, use 1 for tenney height (log2(a*b)), 2 for benedetti (a*b) and 3 for sopfr
# optionally, you can define your own complexity in terms of:
# the interval (x) and the the numerator (n) and denominator (d) of the interval once 2's have been removed.
# for examples:
# * no-2's benedetti height: iv_complexity(x, lambda x,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))
def iv_complexity(x, func=lambda x,n,d: max(n,d)):
f = convert(x,list) # to monzo
f[0] = 0
no2s_x = unfact(f)
if func==3: # sopfr would be slow to implement manually using this function
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])
</syntaxhighlight>
</syntaxhighlight>