Welcome to the Piano World Piano Forums
Over 2.7 million posts about pianos, digital pianos, and all types of keyboard instruments
Join the World's Largest Community of Piano Lovers (it's free)
It's Fun to Play the Piano ... Please Pass It On!

SEARCH
Piano Forums & Piano World
(ad)
Piano Life Saver - Dampp Chaser
Dampp Chaser Piano Life Saver
What's Hot!!
Mr. PianoWorld - the full interview
-------------------
European Tour for Piano Lovers
JOIN US FOR THE TOUR!
--------------------
Posting Pictures on the Forums
-------------------
Forums RULES & HELP
-------------------
ADVERTISE on Piano World
Find a Professional
Our Classified Ads
Find Piano Professionals-

*Piano Dealers - Piano Stores
*Piano Tuners
*Piano Teachers
*Piano Movers
*Piano Restorations
*Piano Manufacturers

Advertise on Piano World

(ad)
Piano Buyer Guide
Piano Buyer Spring 2018
ad
Pierce Piano Atlas


Who's Online Now
140 registered members (bennevis, AssociateX, anotherscott, Balezin Dmitry, ajames, accordeur, Agent88, 29 invisible), 1,832 guests, and 10 spiders.
Key: Admin, Global Mod, Mod
(ad)
Estonia Pianos
Estonia Pianos
Quick Links to Useful Piano & Music Resources
Quick Links:
*Advertise On Piano World
*Free Piano Newsletter
*Online Piano Recitals
*Piano Recitals Index
*Piano & Music Accessories
*Live Piano Venues
*Music School Listings
* Buying a Piano
*Buying A Acoustic Piano
*Buying a Digital Piano
*Pianos for Sale
*Sell Your Piano
*How Old is My Piano?
*Directory/Site Map
*Virtual Piano
*Music Word Search
*Piano Videos
*Virtual Piano Chords & Scales
Previous Thread
Next Thread
Print Thread
Page 2 of 2 1 2
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
C
Charles Cohen Offline
4000 Post Club Member
Charles Cohen  Offline
4000 Post Club Member
C

Joined: Dec 2012
Posts: 4,516
Richmond, BC, Canada
Originally Posted by PhilipInChina
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
---------------------------
PX-350 / microKorg XL+ / Pianoteq / Lounge Lizard / Korg Wavedrum / EV ZXA1 speaker
(ad)
Piano & Music Accessories
piano accessories music gifts tuning and moving equipment
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
C
Charles Cohen Offline
4000 Post Club Member
Charles Cohen  Offline
4000 Post Club Member
C

Joined: Dec 2012
Posts: 4,516
Richmond, BC, Canada
Originally Posted by verqueue
I'm curious how many nerds of this kind are in PW?

eulerdisk, you are not alone here wink.


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
---------------------------
PX-350 / 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
E
eulerdisk Offline
Full Member
eulerdisk  Offline
Full Member
E

Joined: Feb 2013
Posts: 25
Italy
Originally Posted by Polyphonist
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.

Originally Posted by Charles Cohen

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 smile


Re: A mathematical question [Re: eulerdisk] #2352612
11/20/14 03:49 AM
11/20/14 03:49 AM
Joined: Jul 2011
Posts: 3,072
uk south
D
dire tonic Offline
3000 Post Club Member
dire tonic  Offline
3000 Post Club Member
D

Joined: Jul 2011
Posts: 3,072
uk south
Other than the 6502 assembler I learnt 30+ years ago I know nothing about programming so your code is completely opaque to me.

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?


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
D
dire tonic Offline
3000 Post Club Member
dire tonic  Offline
3000 Post Club Member
D

Joined: Jul 2011
Posts: 3,072
uk south
Originally Posted by PhilipInChina
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 Offline OP
3000 Post Club Member
PhilipInChina  Offline 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
D
dire tonic Offline
3000 Post Club Member
dire tonic  Offline
3000 Post Club Member
D

Joined: Jul 2011
Posts: 3,072
uk south
Originally Posted by PhilipInChina

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
E
eulerdisk Offline
Full Member
eulerdisk  Offline
Full Member
E

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: PhilipInChina] #2352687
11/20/14 09:06 AM
11/20/14 09:06 AM
Joined: Jul 2011
Posts: 3,072
uk south
D
dire tonic Offline
3000 Post Club Member
dire tonic  Offline
3000 Post Club Member
D

Joined: Jul 2011
Posts: 3,072
uk south
3892357470806552 vs 3.8824182e+15

There shouldn't be an error on the third significant digit.


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
E
eulerdisk Offline
Full Member
eulerdisk  Offline
Full Member
E

Joined: Feb 2013
Posts: 25
Italy
Originally Posted by dire tonic

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
E
eulerdisk Offline
Full Member
eulerdisk  Offline
Full Member
E

Joined: Feb 2013
Posts: 25
Italy
Originally Posted by dire tonic
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
D
dire tonic Offline
3000 Post Club Member
dire tonic  Offline
3000 Post Club Member
D

Joined: Jul 2011
Posts: 3,072
uk south
Originally Posted by eulerdisk
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] #2352696
11/20/14 09:17 AM
11/20/14 09:17 AM
Joined: Feb 2013
Posts: 25
Italy
E
eulerdisk Offline
Full Member
eulerdisk  Offline
Full Member
E

Joined: Feb 2013
Posts: 25
Italy
Yes, no combination with consecutive rests is generated. Only single (on any length) rests surrounded by notes (or at begin/end of bar).

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
E
eulerdisk Offline
Full Member
eulerdisk  Offline
Full Member
E

Joined: Feb 2013
Posts: 25
Italy
Originally Posted by dire tonic

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
D
dire tonic Offline
3000 Post Club Member
dire tonic  Offline
3000 Post Club Member
D

Joined: Jul 2011
Posts: 3,072
uk south
Originally Posted by eulerdisk
Originally Posted by dire tonic
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
E
eulerdisk Offline
Full Member
eulerdisk  Offline
Full Member
E

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.

Quote
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 cool

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
D
dire tonic Offline
3000 Post Club Member
dire tonic  Offline
3000 Post Club Member
D

Joined: Jul 2011
Posts: 3,072
uk south
Originally Posted by eulerdisk
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.

Quote
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 cool


I see what you mean! ...thanks for doing the sums.

Re: A mathematical question [Re: PhilipInChina] #2352714
11/20/14 10:04 AM
11/20/14 10:04 AM
Joined: Jul 2011
Posts: 3,072
uk south
D
dire tonic Offline
3000 Post Club Member
dire tonic  Offline
3000 Post Club Member
D

Joined: Jul 2011
Posts: 3,072
uk south
...one thing still puzzles me. If you didn't consider the empty bar, how did you end up with an odd number for the case of the 32nds but an even number for the 8ths. Both should be even (the plot thickens....).

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
E
eulerdisk Offline
Full Member
eulerdisk  Offline
Full Member
E

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
D
dire tonic Offline
3000 Post Club Member
dire tonic  Offline
3000 Post Club Member
D

Joined: Jul 2011
Posts: 3,072
uk south
Originally Posted by eulerdisk
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 Offline OP
3000 Post Club Member
PhilipInChina  Offline 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
D
Dwscamel Offline
500 Post Club Member
Dwscamel  Offline
500 Post Club Member
D

Joined: Mar 2013
Posts: 623
Originally Posted by eulerdisk
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:
100000000000000000000000000000000000000000000000000

I 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 !!

Code

# 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 smile.

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 Online content

Platinum Supporter until Feb 18  2015
Retsacnal  Online Content

Platinum Supporter until Feb 18  2015


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
D
dire tonic Offline
3000 Post Club Member
dire tonic  Offline
3000 Post Club Member
D

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 N-1 slots (but this is the rhythm, not the pitch). The third note can occupy N-2 slots. You also have to eliminate double-counting.

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
W
WimPiano Offline
2000 Post Club Member
WimPiano  Offline
2000 Post Club Member
W

Joined: Sep 2013
Posts: 2,149
The Netherlands
Originally Posted by Dwscamel
Originally Posted by eulerdisk
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:
100000000000000000000000000000000000000000000000000

I 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 !!

Code

# 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 smile.

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.

Page 2 of 2 1 2

Moderated by  BB Player 

(ad)
Sweetwater - Keyboards
Sweetwater
New Topics - Multiple Forums
New old guy here; just starting piano journey at 58!
by PianoWVBob. 11/15/18 03:38 PM
One vs. Two-Hnaded Sight Reading
by BbAltered. 11/15/18 01:08 PM
Casio PX-160 or Yamaha P-125 for Beginner
by jediknight. 11/15/18 11:42 AM
Late 19th - early 20th century Pleyel pianos.
by Wckoek. 11/15/18 08:36 AM
(ad)
Pianoteq
PianoTeq Petrof
Forum Statistics
Forums40
Topics188,343
Posts2,761,397
Members91,493
Most Online15,252
Mar 21st, 2010
(ad)
Accu-Tuner
Sanderson Accu-Tuner
Please Support Our Advertisers
Dampp Chaser Piano Life Saver

Sweetwater

PianoTeq Petrof
Piano Buyer Spring 2018
Visit our online store for gifts for music lovers


 
Help keep the forums up and running with a donation, any amount is appreciated!
Or by becoming a Subscribing member! Thank-you.
Donate   Subscribe
 
Our Piano Related Classified Ads
| Dealers | Tuners | Lessons | Movers | Restorations | Pianos For Sale | Sell Your Piano |

Advertise on Piano World
| Subscribe | Piano World | PianoSupplies.com | Advertise on Piano World |
| |Contact | Privacy | Legal | About Us | Site Map | Free Newsletter |


copyright 1997 - 2018 Piano World ® all rights reserved
No part of this site may be reproduced without prior written permission
Powered by UBB.threads™ PHP Forum Software 7.6.2