140 registered members (bennevis, AssociateX, anotherscott, Balezin Dmitry, ajames, accordeur, Agent88, 29 invisible),
1,832
guests, and 10
spiders. 
Key:
Admin,
Global Mod,
Mod



Re: A mathematical question
[Re: PhilipInChina]
#2352592
11/20/14 02:17 AM
11/20/14 02:17 AM

Joined: Dec 2012
Posts: 4,516 Richmond, BC, Canada
Charles Cohen
4000 Post Club Member

4000 Post Club Member
Joined: Dec 2012
Posts: 4,516
Richmond, BC, Canada

I wish I had never posed the original question. ROFL !!!!!! That's the funniest comment in a long time. We're usually all so serious . . . <g> . Charles
. Charles  PX350 / microKorg XL+ / Pianoteq / Lounge Lizard / Korg Wavedrum / EV ZXA1 speaker



Re: A mathematical question
[Re: vevurka]
#2352593
11/20/14 02:20 AM
11/20/14 02:20 AM

Joined: Dec 2012
Posts: 4,516 Richmond, BC, Canada
Charles Cohen
4000 Post Club Member

4000 Post Club Member
Joined: Dec 2012
Posts: 4,516
Richmond, BC, Canada

I'm curious how many nerds of this kind are in PW? eulerdisk, you are not alone here . After a working life programming computers, I suppose I qualify. I suspect that a recursive function to compute the number of possibilities is equivalent to _enumerating_ the possibilities (without actually recording any of them): . . . It will run for a long, long time! . Charles
. Charles  PX350 / microKorg XL+ / Pianoteq / Lounge Lizard / Korg Wavedrum / EV ZXA1 speaker



Re: A mathematical question
[Re: Charles Cohen]
#2352608
11/20/14 03:44 AM
11/20/14 03:44 AM

Joined: Feb 2013
Posts: 25 Italy
eulerdisk
Full Member

Full Member
Joined: Feb 2013
Posts: 25
Italy

And you guys are still forgetting to take tuplets into account. Good point. But that is simply equivalent to take a smaller minumum note duration such that is the minimum common divisor of all tuples. However I'm not adding into account different phrases combination, but I could extend that to do so. I suspect that a recursive function to compute the number of possibilities is equivalent to _enumerating_ the possibilities (without actually recording any of them):
. . . It will run for a long, long time!
. Charles
That is why is the code I posted there are two version. The first one is pure recursive so it will run forever if you try to calculate for 32th in 4/4 bar. The second one save the subproblems already calculated, so I think it has O(n^2) complexity (maybe O(nlogn) ??) from O(n!) of the original, so it's very fast. However the python interpreter have a limit on the depth of recursion, so you must to rewrite it in an iterative form if you want to calculate long sequences. P.S: last super nerdy response, I promise



Re: A mathematical question
[Re: PhilipInChina]
#2352626
11/20/14 05:32 AM
11/20/14 05:32 AM

Joined: Jul 2011
Posts: 3,072 uk south
dire tonic
3000 Post Club Member

3000 Post Club Member
Joined: Jul 2011
Posts: 3,072
uk south

I wish I had never posed the original question.  don't be so hard on yourself, you've given the nerderati something to live for.



Re: A mathematical question
[Re: PhilipInChina]
#2352637
11/20/14 05:56 AM
11/20/14 05:56 AM

Joined: Oct 2013
Posts: 3,675 Kuwait
PhilipInChina
OP
3000 Post Club Member

OP
3000 Post Club Member
Joined: Oct 2013
Posts: 3,675
Kuwait

Just opened another bottle of scotch to try and cope with this.
It's my thread so:
88 note keyboard. 1 bar in common time. No rests. Minimum note duration 1/8. Forget pedals, any crescendo or other directions etc. etc.
What is the answer? Do I really want to know?
Moderator, if I stop answering messages I shall probably be found raving somewhere in a straitjacket. In that case please delete my membership.
Currently working towards "Twinkle twinkle little star"



Re: A mathematical question
[Re: PhilipInChina]
#2352682
11/20/14 08:41 AM
11/20/14 08:41 AM

Joined: Jul 2011
Posts: 3,072 uk south
dire tonic
3000 Post Club Member

3000 Post Club Member
Joined: Jul 2011
Posts: 3,072
uk south

88 note keyboard. 1 bar in common time. No rests. Minimum note duration 1/8. Forget pedals, any crescendo or other directions etc. etc.
What is the answer? Do I really want to know?
Moderator, if I stop answering messages I shall probably be found raving somewhere in a straitjacket. In that case please delete my membership.
google's default calculator only seems to provide an answer to 8 significant figures, namely 3.8824182e+15  quite a bit less than the total US consumer debt. I'd be interested to see if eulerdisk's figure is any different.



Re: A mathematical question
[Re: dire tonic]
#2352686
11/20/14 09:00 AM
11/20/14 09:00 AM

Joined: Feb 2013
Posts: 25 Italy
eulerdisk
Full Member

Full Member
Joined: Feb 2013
Posts: 25
Italy

Removing rests management from the code, with 88 notes and one 8th as minimum note, give me: 3892357470806552. By the way, I made a terrible mistake in the previous page. I calculated the number not for one bar, but for 4 bars !! The correct number for one bar is (32h as the minimum, every combination of 12 notes and rests etc...) 3754314046659595722768960270925020481, not 2446018428630537543409......1. Sorry.
Last edited by eulerdisk; 11/20/14 09:04 AM.



Re: A mathematical question
[Re: dire tonic]
#2352690
11/20/14 09:10 AM
11/20/14 09:10 AM

Joined: Feb 2013
Posts: 25 Italy
eulerdisk
Full Member

Full Member
Joined: Feb 2013
Posts: 25
Italy

Did you take into account the empty bar (a bar's rest)?
I'm assuming that's the "....1" at the end of your result?
The code take into account every duration multiple of the minimum, for notes and rests, whole time include. Sequence of rests are not counted, two consecutive 8th rests is considered the same as a 4th rest.



Re: A mathematical question
[Re: dire tonic]
#2352694
11/20/14 09:13 AM
11/20/14 09:13 AM

Joined: Feb 2013
Posts: 25 Italy
eulerdisk
Full Member

Full Member
Joined: Feb 2013
Posts: 25
Italy

3892357470806552 vs 3.8824182e+15
There shouldn't be an error on the third significant digit.
Depends on how Google truncate the results during the various calculation steps. Your calculations involve divisions ?? If yes Google thinks you want floating point numbers so it switch to them and you start to lose precision.
Last edited by eulerdisk; 11/20/14 09:14 AM.



Re: A mathematical question
[Re: eulerdisk]
#2352695
11/20/14 09:14 AM
11/20/14 09:14 AM

Joined: Jul 2011
Posts: 3,072 uk south
dire tonic
3000 Post Club Member

3000 Post Club Member
Joined: Jul 2011
Posts: 3,072
uk south

Sequence of rests are not counted, two consecutive 8th rests is considered the same as a 4th rest.  quite. So consecutive rests don't need to be considered at all, not even as a 4th rest. Clearly, the two methods produce results close enough to show they 'work' but I wonder why there's any discrepancy.



Re: A mathematical question
[Re: dire tonic]
#2352699
11/20/14 09:20 AM
11/20/14 09:20 AM

Joined: Feb 2013
Posts: 25 Italy
eulerdisk
Full Member

Full Member
Joined: Feb 2013
Posts: 25
Italy

Clearly, the two methods produce results close enough to show they 'work' but I wonder why there's any discrepancy.
Read one of my previous posts. Limited precision floating point numbers and summation of big and little numbers produces bad results.



Re: A mathematical question
[Re: eulerdisk]
#2352703
11/20/14 09:25 AM
11/20/14 09:25 AM

Joined: Jul 2011
Posts: 3,072 uk south
dire tonic
3000 Post Club Member

3000 Post Club Member
Joined: Jul 2011
Posts: 3,072
uk south

3892357470806552 vs 3.8824182e+15
There shouldn't be an error on the third significant digit.
Depends on how Google truncate the results during the various calculation steps. Your calculations involve divisions ?? If yes Google thinks you want floating point numbers so it switch to them and you start to lose precision. It does involve division but the numerator will always be divisible by the denominator to an integral value. there are only 9 terms 1 +(empty bar) 88 + (first note only  no rests allowed) [7!/[6!*1!)]*(88^2)+ (2 notes) [7!/(5!*2!)]*(88^3)+ (3 notes) [7!/(4!*3!)]*(88^4)+ (4 notes) [7!/(3!*4!)]*(88^5)+ [7!/(2!*5!)]*(88^6)+ [7!/(1!*6!)]*(88^7)+ [7!/(0!*7!)]*(88^8) (all 8 notes played) *edit* missed out the 88^2 term
Last edited by dire tonic; 11/20/14 09:36 AM.



Re: A mathematical question
[Re: dire tonic]
#2352710
11/20/14 09:50 AM
11/20/14 09:50 AM

Joined: Feb 2013
Posts: 25 Italy
eulerdisk
Full Member

Full Member
Joined: Feb 2013
Posts: 25
Italy

I just coded your formula, and that gives me 3892357470806553, so it's right. You have considered the "empty" bar, I didn't cause I removed spaces entirely so you have 1 more than mine. Now we can sleep in peace. It does involve division but the numerator will always be divisible by the denominator to an integral value. Yes but Google doesn't know that
Last edited by eulerdisk; 11/20/14 09:51 AM.



Re: A mathematical question
[Re: eulerdisk]
#2352711
11/20/14 09:54 AM
11/20/14 09:54 AM

Joined: Jul 2011
Posts: 3,072 uk south
dire tonic
3000 Post Club Member

3000 Post Club Member
Joined: Jul 2011
Posts: 3,072
uk south

I just coded your formula, and that gives me 3892357470806553, so it's right. You have considered the "empty" bar, I didn't cause I removed spaces entirely so you have 1 more than mine. Now we can sleep in peace. It does involve division but the numerator will always be divisible by the denominator to an integral value. Yes but Google doesn't know that I see what you mean! ...thanks for doing the sums.



Re: A mathematical question
[Re: dire tonic]
#2352718
11/20/14 10:21 AM
11/20/14 10:21 AM

Joined: Feb 2013
Posts: 25 Italy
eulerdisk
Full Member

Full Member
Joined: Feb 2013
Posts: 25
Italy

Only when I calculated 3892357470806552 I removed completely the rest possibilities from the code, so no rest of any length (so no "empty" bar) The original code has the rest management.
Last edited by eulerdisk; 11/20/14 10:23 AM.



Re: A mathematical question
[Re: eulerdisk]
#2352732
11/20/14 10:45 AM
11/20/14 10:45 AM

Joined: Jul 2011
Posts: 3,072 uk south
dire tonic
3000 Post Club Member

3000 Post Club Member
Joined: Jul 2011
Posts: 3,072
uk south

Only when I calculated 3892357470806552 I removed completely the rest possibilities from the code, so no rest of any length (so no "empty" bar) The original code has the rest management. Understood. What we need now is a means of formulating 'beauty' so we can filter out all the rubbish tunes and arrive at a meaningful number. I'm happy to leave that to you and Python.



Re: A mathematical question
[Re: Retsacnal]
#2352973
11/20/14 10:21 PM
11/20/14 10:21 PM

Joined: Oct 2013
Posts: 3,675 Kuwait
PhilipInChina
OP
3000 Post Club Member

OP
3000 Post Club Member
Joined: Oct 2013
Posts: 3,675
Kuwait

I tried python but it ate my labrador.
Currently working towards "Twinkle twinkle little star"



Re: A mathematical question
[Re: eulerdisk]
#2352993
11/20/14 10:55 PM
11/20/14 10:55 PM

Joined: Mar 2013
Posts: 623
Dwscamel
500 Post Club Member

500 Post Club Member
Joined: Mar 2013
Posts: 623

If we take a 32th as the minimum note duration, there are: 244601842863053754340937981537651198832237890212083485501963127501261947397454705500426716559736743757454676068635596937635829273540930184903619841 possible 4/4 bars. For refere this is an estimate of the number of atoms on earth: 100000000000000000000000000000000000000000000000000I wrote a simple recursive function in Python that given the minimum note duration enumerate every possibile bar. It counts every combination of notes and pauses of every duration. !! WARNING NERDY STUFF !!
# Minum unit in quarter note subdivisions. 8 means 8th, 16 means 16th...
NOTE_MINIMUM_UNIT = 32
# Naturals + sharps
NOTE_NUMBER = 12
# This is simple but SLOW, it will run forever with the parameters above
def enumBars(previousNoteIsSilence, remainingTimeInUnit):
# Ends the recursion
if remainingTimeInUnit == 0:
return 1
tot = 0
# Here we iterate over all possibile note duration.
#
# if NOTE_MINIMUM_UNIT is 32
# from 1 (one 32th), 2 (one 16th), 3 (dotted 16th) ... to 32 (one quarter note)
for noteDuration in range(1, remainingTimeInUnit + 1):
if noteDuration <= remainingTimeInUnit:
# We chose a note (12 possibilities)
# then we recalculate the function recursively with the remaining time.
tot = tot + NOTE_NUMBER * enumBars(False, remainingTimeInUnit  noteDuration)
# Pause special case
# We can count "pause combination" only if the previus "note" is not a pause.
if previousNoteIsSilence is False:
tot = tot + enumBars(True, remainingTimeInUnit  noteDuration)
return tot
# This is the same but it cache subproblems so it's FAST.
def enumBarsOptimized(previousNoteIsSilence, remainingTimeInUnit, state):
# Ends the recursion
if remainingTimeInUnit == 0:
return 1
# We use emainingTimeInUnit  1 as the correct index in the array
table = state[0 if previousNoteIsSilence is True else 1]
if table[remainingTimeInUnit  1] != False:
return table[remainingTimeInUnit  1]
tot = 0
# Here we iterate over all possibile note duration.
#
# if NOTE_MINIMUM_UNIT is 16
# from 1 (one 16th), 2 (one 8th), 3 (dotted 8th) ... to 16 (one quarter note)
for noteDuration in range(1, remainingTimeInUnit + 1):
if noteDuration <= remainingTimeInUnit:
# We chose a note (12 possibilities)
# then we recalculate the function recursively with the remaining time.
tot = tot + NOTE_NUMBER * enumBarsOptimized(False, remainingTimeInUnit  noteDuration, state)
# Pause special case
# We can count "pause combination" only if the previus "note" is not a pause.
if previousNoteIsSilence is False:
tot = tot + enumBarsOptimized(True, remainingTimeInUnit  noteDuration, state)
table[remainingTimeInUnit  1] = tot
return tot
# (NOTE_MINIMUM_UNIT * 4) is one 4/4 bar, (NOTE_MIN.. * 3) is one 3/4 bar ...
DURATION = NOTE_MINIMUM_UNIT * 4
print enumBarsOptimized(False, DURATION, [[False] * DURATION for i in range (2)])
I knew someone would implement this in Python! You're the best . Would be nice to see it in a big compiled language with arbitrary precision, like Lisp or Java. But right now I have only a few interpreters.
Beethoven  Op.49 No.1 (sonata 19) Czerny  Op.299 Nos. 5,7 (School of Velocity) Liszt  S.172 No.2 (Consolation No.2)
Dream piece: Rachmaninoff  Sonata 2, movement 2 in E minor



Re: A mathematical question
[Re: PhilipInChina]
#2354095
11/23/14 09:55 PM
11/23/14 09:55 PM

Joined: Oct 2012
Posts: 3,616 ðŸŽ¹
Retsacnal

Joined: Oct 2012
Posts: 3,616
ðŸŽ¹

I confess...I like nerdy stuff. After posting in this thread the other day, I went to the gym and found myself thinking about the math. My probability theory is rusty, and I'm too lazy to look it up. What stymied me in the gym was that if the first "note" (quarter, sixteenth, whatever) can have up to five pitches. The first can be one in 12, the second one in 11, the third one in 10, etc. Except that it's actually one in 13 if you consider a rest one of the choices (and it should be). And if it was held over is a 14th option. But if the first is a rest, you don't subtract 1 from the next possibility. In other words, each finger that theoretically presses a note removes one from the choices for the subsequent finger, but not so if a rest is chosen. One key can be pressed by only one finger, but all five can "play" a rest. Anyway, I forget how to compute that sort of thing.
I pondered putting together a spreadsheet. It never even dawned on me to write a program to simply count 'em up (and I teach software engineering)! Anyway, not worth following up on, except that I was intrigued by the python program shown above.
if you're content with A V E R A G E . . . then just do what everyone else does



Re: A mathematical question
[Re: Retsacnal]
#2354149
11/24/14 02:41 AM
11/24/14 02:41 AM

Joined: Jul 2011
Posts: 3,072 uk south
dire tonic
3000 Post Club Member

3000 Post Club Member
Joined: Jul 2011
Posts: 3,072
uk south

That's the right idea and it is closely related to probability theory but the constraint isn't on the pitch at all (of which there are 12 rather than 5). Every note in the bar, no matter how many notes, can occupy the same pitch (e.g. one note samba), the constraint is only on the rhythm. Two notes can't be simultaneous, unless we allow chords. So, if the bar is to be subdivided into N parts:
The first note is constrained to the beginning of the bar (no rests) and only has 1 rhythmic option (but 12 pitch options). After that all other notes are free to be placed in any unoccupied slot. Clearly, as we add more notes the number of slots diminishes, i.e.the second note is free to occupy any one of the remaining N1 slots (but this is the rhythm, not the pitch). The third note can occupy N2 slots. You also have to eliminate doublecounting.



Re: A mathematical question
[Re: Dwscamel]
#2354159
11/24/14 03:27 AM
11/24/14 03:27 AM

Joined: Sep 2013
Posts: 2,149 The Netherlands
WimPiano
2000 Post Club Member

2000 Post Club Member
Joined: Sep 2013
Posts: 2,149
The Netherlands

If we take a 32th as the minimum note duration, there are: 244601842863053754340937981537651198832237890212083485501963127501261947397454705500426716559736743757454676068635596937635829273540930184903619841 possible 4/4 bars. For refere this is an estimate of the number of atoms on earth: 100000000000000000000000000000000000000000000000000I wrote a simple recursive function in Python that given the minimum note duration enumerate every possibile bar. It counts every combination of notes and pauses of every duration. !! WARNING NERDY STUFF !!
# Minum unit in quarter note subdivisions. 8 means 8th, 16 means 16th...
NOTE_MINIMUM_UNIT = 32
# Naturals + sharps
NOTE_NUMBER = 12
# This is simple but SLOW, it will run forever with the parameters above
def enumBars(previousNoteIsSilence, remainingTimeInUnit):
# Ends the recursion
if remainingTimeInUnit == 0:
return 1
tot = 0
# Here we iterate over all possibile note duration.
#
# if NOTE_MINIMUM_UNIT is 32
# from 1 (one 32th), 2 (one 16th), 3 (dotted 16th) ... to 32 (one quarter note)
for noteDuration in range(1, remainingTimeInUnit + 1):
if noteDuration <= remainingTimeInUnit:
# We chose a note (12 possibilities)
# then we recalculate the function recursively with the remaining time.
tot = tot + NOTE_NUMBER * enumBars(False, remainingTimeInUnit  noteDuration)
# Pause special case
# We can count "pause combination" only if the previus "note" is not a pause.
if previousNoteIsSilence is False:
tot = tot + enumBars(True, remainingTimeInUnit  noteDuration)
return tot
# This is the same but it cache subproblems so it's FAST.
def enumBarsOptimized(previousNoteIsSilence, remainingTimeInUnit, state):
# Ends the recursion
if remainingTimeInUnit == 0:
return 1
# We use emainingTimeInUnit  1 as the correct index in the array
table = state[0 if previousNoteIsSilence is True else 1]
if table[remainingTimeInUnit  1] != False:
return table[remainingTimeInUnit  1]
tot = 0
# Here we iterate over all possibile note duration.
#
# if NOTE_MINIMUM_UNIT is 16
# from 1 (one 16th), 2 (one 8th), 3 (dotted 8th) ... to 16 (one quarter note)
for noteDuration in range(1, remainingTimeInUnit + 1):
if noteDuration <= remainingTimeInUnit:
# We chose a note (12 possibilities)
# then we recalculate the function recursively with the remaining time.
tot = tot + NOTE_NUMBER * enumBarsOptimized(False, remainingTimeInUnit  noteDuration, state)
# Pause special case
# We can count "pause combination" only if the previus "note" is not a pause.
if previousNoteIsSilence is False:
tot = tot + enumBarsOptimized(True, remainingTimeInUnit  noteDuration, state)
table[remainingTimeInUnit  1] = tot
return tot
# (NOTE_MINIMUM_UNIT * 4) is one 4/4 bar, (NOTE_MIN.. * 3) is one 3/4 bar ...
DURATION = NOTE_MINIMUM_UNIT * 4
print enumBarsOptimized(False, DURATION, [[False] * DURATION for i in range (2)])
I knew someone would implement this in Python! You're the best . Would be nice to see it in a big compiled language with arbitrary precision, like Lisp or Java. But right now I have only a few interpreters. If you really need it I can write it in Java, C, C++, C# or any other modern language.




Forums40
Topics188,343
Posts2,761,397
Members91,493

Most Online15,252 Mar 21st, 2010


