back to list

A MOS question using Python code

🔗akjmicro <akjmicro@comcast.net>

8/16/2004 8:58:46 PM

Hey all,

Below is a transcript of an interactive session with the Python
interpreter, playing with a function to find a MOS series, given a
fifth-size in cents as an argument. Here's the code, for all you
Pythonistas out there (you can put it in a library module, script,
or manually type it into a Python interpreter...I put it in my
'microtonal.py' personal library, so I import all the functions with
the first line of the transcript below):

def find_mos(fifth):
fifth=round(fifth*1000) #### re-express as large integer
for x in range(5,400,1):
values=[] ### empty array to be filled
for y in range(x):
values.append((y*fifth)%1200000)
values.append(1200000) ### really 1200 cents, but
### expressed as an integer w/ 3 digits after the dec. point.
values.sort()
differences=[]
for z in range(1,len(values),1): ### looks to
diff=values[z]-values[z-1] ### see if
if diff not in differences: ### there r only
differences.append(diff) ### 2 sizes
if len(differences)==2: ### of interval - a MOS !!
print x, ### if so, print it.....

My question is...does Wilson talk about the different behavior of
the MOS series depending on the size in cents of the fifth, other
than what I already know he said about whether they were sharp or
flat of just? Apparently, one can get radically differing series by
picking a different fifth....

Best, Aaron.

Here's my session, using different fifth sizes as the parentheses
argument:

###### transcript #############
bash$ python
Python 2.3.3 (#1, Feb 16 2004, 21:23:27)
[GCC 3.2.3 20030422 (Gentoo Linux 1.4 3.2.3-r1, propolice)] on
linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> from microtonal import *
>>> find_mos(697)
5 7 12 19 31 43 74 105 136 167 198 365
>>> find_mos(696)
5 7 12 19 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
387 388 389 390 391 392 393 394 395 396 397 398 399
>>> find_mos(701)
5 7 12 17 29 41 53 65 77 89 101 190 291 392
>>> find_mos(700)
5 7 8 9 10 11 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
389 390 391 392 393 394 395 396 397 398 399
>>> find_mos(702)
5 7 12 17 29 41 53 94 147 148 149 150 151 152 153 154 155 156 157
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
192 193 194 195 196 197 198 199 201 202 203 204 205 206 207 208 209
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
397 398 399

🔗Gene Ward Smith <gwsmith@svpal.org>

8/16/2004 9:44:46 PM

--- In tuning@yahoogroups.com, "akjmicro" <akjmicro@c...> wrote:

> My question is...does Wilson talk about the different behavior of
> the MOS series depending on the size in cents of the fifth, other
> than what I already know he said about whether they were sharp or
> flat of just? Apparently, one can get radically differing series by
> picking a different fifth....

You might check out the bottom of the meantone entry in the tuning
encyclopedia.

🔗Manuel Op de Coul <manuel.op.de.coul@eon-benelux.com>

8/17/2004 3:32:05 AM

Those without Python can do it in Scala too, like this:

conv/ce/se 697.0

>>>> find_mos(700)
>5 7 8 9 10 11 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

I think your script doesn't know when to stop.

Manuel

🔗Graham Breed <graham@microtonal.co.uk>

8/17/2004 7:07:48 AM

akjmicro wrote:

> Below is a transcript of an interactive session with the Python > interpreter, playing with a function to find a MOS series, given a > fifth-size in cents as an argument. Here's the code, for all you > Pythonistas out there (you can put it in a library module, script, > or manually type it into a Python interpreter...I put it in my > 'microtonal.py' personal library, so I import all the functions with > the first line of the transcript below): Here's a generator based on a function from my temperament finding library:

from __future__ import generators

import math

def find_mos(fifth, mustBeProper=0):
ratio = fifth/12e2
i = int(ratio)

mPrev, m = 0, 1
while abs(ratio-i)>1e-6:
ratio = 1/(ratio-i)
i = int(ratio)

if mustBeProper:
mPrev, m = m, m*i + mPrev
yield m

else:
mPrev, m = m, mPrev

for n in range(i):
m += mPrev
yield m

It's in turn based on some Pascal code Dave Keenan gave me. I get different results to you, but refreshingly similar ones to Scala.

>>> list(findmos.find_mos(697))
[1, 2, 3, 5, 7, 12, 19, 31, 43, 74, 105, 136, 167, 198, 365, 532, 699, 866, 1033, 1200]
>>> list(findmos.find_mos(696))
[1, 2, 3, 5, 7, 12, 19, 31, 50]
>>> list(findmos.find_mos(701))
[1, 2, 3, 5, 7, 12, 17, 29, 41, 53, 65, 77, 89, 101, 190, 291, 392, 493, 594, 695, 796, 897, 998, 1099, 1200]
>>> list(findmos.find_mos(700))
[1, 2, 3, 5, 7, 12]
>>> list(findmos.find_mos(702))
[1, 2, 3, 5, 7, 12, 17, 29, 41, 53, 94, 147, 200]

Graham

🔗akjmicro <akjmicro@comcast.net>

8/17/2004 10:38:39 AM

--- In tuning@yahoogroups.com, Graham Breed <graham@m...> wrote:
> akjmicro wrote:
>
> > Below is a transcript of an interactive session with the Python
> > interpreter, playing with a function to find a MOS series, given
a
> > fifth-size in cents as an argument. Here's the code, for all you
> > Pythonistas out there (you can put it in a library module,
script,
> > or manually type it into a Python interpreter...I put it in my
> > 'microtonal.py' personal library, so I import all the functions
with
> > the first line of the transcript below):
>
> Here's a generator based on a function from my temperament finding
library:
>
> from __future__ import generators
>
> import math
>
> def find_mos(fifth, mustBeProper=0):
> ratio = fifth/12e2
> i = int(ratio)
>
> mPrev, m = 0, 1
> while abs(ratio-i)>1e-6:
> ratio = 1/(ratio-i)
> i = int(ratio)
>
> if mustBeProper:
> mPrev, m = m, m*i + mPrev
> yield m
>
> else:
> mPrev, m = m, mPrev
>
> for n in range(i):
> m += mPrev
> yield m
>
> It's in turn based on some Pascal code Dave Keenan gave me. I get
> different results to you, but refreshingly similar ones to Scala.

Graham, Manuel-

Yes, I've obviously got a bug in my code I'll have to track down. In
the meantime, I'll add your code, Graham, to my library and fool
around with it.

I wonder where in the code my bug could be, because it displays good
behavior that agrees with Gene's post and Scala and this post most
of the time, but it barfs on certain fifth sizes!
Graham interesting that you use '12e2'--I didn't know that feature
of Python !!! You learn something new every day!!!

Best,
Aaron.

🔗akjmicro <akjmicro@comcast.net>

8/17/2004 11:54:05 AM

--- In tuning@yahoogroups.com, Graham Breed <graham@m...> wrote:

> Here's a generator based on a function from my temperament finding
library:
>
> from __future__ import generators
>
> import math
>
> def find_mos(fifth, mustBeProper=0):
> ratio = fifth/12e2
> i = int(ratio)
>
> mPrev, m = 0, 1
> while abs(ratio-i)>1e-6:
> ratio = 1/(ratio-i)
> i = int(ratio)
>
> if mustBeProper:
> mPrev, m = m, m*i + mPrev
> yield m
>
> else:
> mPrev, m = m, mPrev
>
> for n in range(i):
> m += mPrev
> yield m
>
> It's in turn based on some Pascal code Dave Keenan gave me. I get
> different results to you, but refreshingly similar ones to Scala.
>
> >>> list(findmos.find_mos(697))
> [1, 2, 3, 5, 7, 12, 19, 31, 43, 74, 105, 136, 167, 198, 365, 532,
699,
> 866, 1033, 1200]
> >>> list(findmos.find_mos(696))
> [1, 2, 3, 5, 7, 12, 19, 31, 50]
> >>> list(findmos.find_mos(701))
> [1, 2, 3, 5, 7, 12, 17, 29, 41, 53, 65, 77, 89, 101, 190, 291,
392, 493,
> 594, 695, 796, 897, 998, 1099, 1200]
> >>> list(findmos.find_mos(700))
> [1, 2, 3, 5, 7, 12]
> >>> list(findmos.find_mos(702))
> [1, 2, 3, 5, 7, 12, 17, 29, 41, 53, 94, 147, 200]

Graham-

I should note that I tried to do a floating point fifth size
(696.578), and it made my computer freeze--I had to reboot.

So you code works well for integers, but at least on my system,
there is a nasty bug.

Also, I had to figure this code out by trial and error-you didn't
preserve indentation, which is a no-no in Python ;)....here is the
code indented:

def find_mos_g(fifth, mustBeProper=0):
ratio = fifth/12e2
i = int(ratio)

mPrev, m = 0, 1
while abs(ratio-i)>1e-6:
ratio = 1/(ratio-i)
i = int(ratio)

if mustBeProper:
mPrev, m = m, m*i + mPrev
yield m

else:
mPrev, m = m, mPrev

for n in range(i):
m += mPrev
yield m

I'm interested to know where you learned about that weird assignment
style where you can state somethiing like such:

mPrev, m = m, m*i + mPrev

....I haven't come across that in the Python documentation ever.
It's really cool, but where can I read more about it?

Best,
Aaron.

🔗Graham Breed <graham@microtonal.co.uk>

8/17/2004 12:13:12 PM

akjmicro wrote:

> I should note that I tried to do a floating point fifth size > (696.578), and it made my computer freeze--I had to reboot. > > So you code works well for integers, but at least on my system, > there is a nasty bug. It's probably because the generator doesn't terminate. Here's a way to force a finite list:

>>> import findmos
>>> def first(n, g):
... return [g.next() for x in range(n)]
...
>>> first(10, findmos.find_mos(696.578))
[1, 2, 3, 5, 7, 12, 19, 31, 50, 81]
>>> first(20, findmos.find_mos(696.578))
[1, 2, 3, 5, 7, 12, 19, 31, 50, 81, 112, 143, 174, 205, 379, 584, 789, 994, 1783, 2572]

> Also, I had to figure this code out by trial and error-you didn't > preserve indentation, which is a no-no in Python ;)....here is the > code indented: It's Yahoo that does that. This bit:

> for n in range(i): > m += mPrev > yield m should be indented another level.

> I'm interested to know where you learned about that weird assignment > style where you can state somethiing like such: > > mPrev, m = m, m*i + mPrev > > ....I haven't come across that in the Python documentation ever. > It's really cool, but where can I read more about it? well, the tutorial:

http://docs.python.org/tut/node5.html

see the Fibonacci example.

It's called tuple unpacking. The right hand side could be written (m, m*i+mPrev). So it forms a tuple, and unpacks it to the variables on the left. In the same way, you can get a function to return more than one value.

Graham

🔗akjmicro <akjmicro@comcast.net>

8/17/2004 9:49:30 PM

--- In tuning@yahoogroups.com, Graham Breed <graham@m...> wrote:
> akjmicro wrote:
>
> > I should note that I tried to do a floating point fifth size
> > (696.578), and it made my computer freeze--I had to reboot.
> >
> > So you code works well for integers, but at least on my system,
> > there is a nasty bug.
>
> It's probably because the generator doesn't terminate. Here's a
way to
> force a finite list:
>
> >>> import findmos
> >>> def first(n, g):
> ... return [g.next() for x in range(n)]
> ...
> >>> first(10, findmos.find_mos(696.578))
> [1, 2, 3, 5, 7, 12, 19, 31, 50, 81]
> >>> first(20, findmos.find_mos(696.578))
> [1, 2, 3, 5, 7, 12, 19, 31, 50, 81, 112, 143, 174, 205, 379, 584,
789,
> 994, 1783, 2572]

That makes sense, thanks.

I'm curious about how this code works.

mPrev, m = 0, 1
while abs(ratio-i)>1e-6:
ratio = 1/(ratio-i)
i = int(ratio)

how does this do the magic of figuring out that there is a MOS going
on? It's interesting that there are no arrays where you count the
interval sizes, etc.

>
> > Also, I had to figure this code out by trial and error-you
didn't
> > preserve indentation, which is a no-no in Python ;)....here is
the
> > code indented:
>
> It's Yahoo that does that. This bit:
>
> > for n in range(i):
> > m += mPrev
> > yield m
>
> should be indented another level.
>
>
> > I'm interested to know where you learned about that weird
assignment
> > style where you can state somethiing like such:
> >
> > mPrev, m = m, m*i + mPrev
> >
> > ....I haven't come across that in the Python documentation ever.
> > It's really cool, but where can I read more about it?
>
> well, the tutorial:
>
> http://docs.python.org/tut/node5.html
>
> see the Fibonacci example.
>
> It's called tuple unpacking. The right hand side could be written
(m,
> m*i+mPrev). So it forms a tuple, and unpacks it to the variables
on the
> left. In the same way, you can get a function to return more than
one
> value.

Of course! In fact I *do* know about it, but for some reason,
instead of parsing it this way:

two things = two things

where the '=' is central, I parsed it this way:

(thing), (thing=another_thing), (yet_another_thing)

where the ',' were central, i.e. I saw it as a tripartite statement
instead of bipartite! I must be losing it....

Best,
Aaron.