Here's a 'formula' for finding the natural and sharp notes, expressed as Python/numpy calculations (MATLAB would do just as well). It's not a refined calculation, just an easy way to generate the numbers and group them (mixing arrays, sets and sorted lists).
i = np.arange(5,200,7) # numbers from 5 up, stepping by 7
natural = set((i%12)[:7]) # modulus by 12; 1st set of 7
# set([0, 2, 4, 5, 7, 9, 11])
next = set((i%12)[7:14]) # 2nd set
# set([0, 1, 3, 5, 6, 8, 10])
sharps = sorted(set(next-natural) # remove the naturals
# [1, 3, 6, 8, 10]
Naturals are the 1st set of 7, sharps are the 2nd set, minus the ones we already identified as naturals (0 and 5).
If I start the count with 0
,
naturals: [0, 2, 4, 6, 7, 9, 11])
sharps: [1, 3, 5, 8, 10]
In effect, F G A B C D E
and F# G# A# C# D#
.
So I can start the count anywhere, but the location of the half steps in the natural scale will shift.
https://en.wikipedia.org/wiki/Mode_(music)#Summary - describes this connection between modes and the circle.
Using your formula
f(x) = (x - 5) * 7 mod 12.
If f(x) <= 6, the note is non-sharp.
Otherwise it's sharp.
x >= 0 and x <= 11.
In [79]: x=np.arange(0,12)
In [80]: fx=((x-5)*7)%12
In [81]: x[~(fx<7)] # the sharps
Out[81]: array([ 1, 3, 6, 8, 10])
In [82]: x[fx<7] # the naturals
Out[82]: array([ 0, 2, 4, 5, 7, 9, 11])
The 7&12 are producing the circular pattern of TTSTTTS
; the 5 is anchoring it to the Ionian (CMajor) mode.
0 2 4 5 7 9 11
, instead, for example,0 2 3 5 7 8 10
(a minor scale pattern)?modes
.