Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Never make any mistaeks. -- Anonymous, in a mail discussion about to a kernel bug report


devel / comp.lang.forth / Re: Suggested exercise in Forth

SubjectAuthor
* Suggested exercise in ForthKrishna Myneni
+* Re: Suggested exercise in Forthpahihu
|`* Re: Suggested exercise in ForthKrishna Myneni
| +* Re: Suggested exercise in Forthdxforth
| |`* Re: Suggested exercise in ForthKrishna Myneni
| | `* Re: Suggested exercise in Forthdxforth
| |  `- Re: Suggested exercise in Forthpahihu
| `* Re: Suggested exercise in Forthpahihu
|  +* Re: Suggested exercise in Forthdxforth
|  |+* Re: Suggested exercise in Forthpahihu
|  ||`- Re: Suggested exercise in Forthpahihu
|  |`* Re: Suggested exercise in ForthKrishna Myneni
|  | +* Re: Suggested exercise in Forthdxforth
|  | |`* Re: Suggested exercise in ForthKrishna Myneni
|  | | `- Re: Suggested exercise in Forthdxforth
|  | `* Re: Suggested exercise in ForthBrian Fox
|  |  +- Re: Suggested exercise in Forthminf...@arcor.de
|  |  `* Re: Suggested exercise in ForthKrishna Myneni
|  |   `* Re: Suggested exercise in ForthMarcel Hendrix
|  |    `- Re: Suggested exercise in ForthKrishna Myneni
|  `- Re: Suggested exercise in ForthKrishna Myneni
+* Re: Suggested exercise in ForthClive Arthur
|`- Re: Suggested exercise in ForthKrishna Myneni
+* Re: Suggested exercise in ForthS Jack
|`* Re: Suggested exercise in ForthKrishna Myneni
| `* Re: Suggested exercise in ForthS Jack
|  `* Re: Suggested exercise in ForthKrishna Myneni
|   +* Re: Suggested exercise in ForthS Jack
|   |`* Re: Suggested exercise in ForthKrishna Myneni
|   | `- Re: Suggested exercise in ForthKrishna Myneni
|   `* Re: Suggested exercise in Forthpahihu
|    `* Re: Suggested exercise in ForthKrishna Myneni
|     `- Re: Suggested exercise in Forthpahihu
+* Re: Suggested exercise in Forthdxforth
|+* Re: Suggested exercise in ForthKrishna Myneni
||`* Re: Suggested exercise in Forthdxforth
|| `- Re: Suggested exercise in ForthKrishna Myneni
|`* Re: Suggested exercise in ForthS Jack
| `* Re: Suggested exercise in ForthBrian Fox
|  `* Re: Suggested exercise in ForthS Jack
|   +* Re: Suggested exercise in ForthS Jack
|   |`- Re: Suggested exercise in ForthS Jack
|   `- Re: Suggested exercise in ForthKrishna Myneni
`* Re: Suggested exercise in ForthPaul Rubin
 `- Re: Suggested exercise in ForthKrishna Myneni

Pages:12
Re: Suggested exercise in Forth

<sntlvp$c6i$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15355&group=comp.lang.forth#15355

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Suggested exercise in Forth
Date: Sat, 27 Nov 2021 10:22:16 -0600
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <sntlvp$c6i$1@dont-email.me>
References: <snhi1g$tip$1@dont-email.me>
<7955c833-76c8-4773-998f-d926c64dc231n@googlegroups.com>
<snjn5t$so5$1@dont-email.me>
<0e1e6c46-49fd-4fa4-a14d-0da38ecfc857n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 27 Nov 2021 16:22:17 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f0c38e295e6d459f993b935c947a3766";
logging-data="12498"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18yB8D5s1a2/Riz91YNfKb9"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.1.0
Cancel-Lock: sha1:szhXKKXby87Cj6vjgHztm4fxiHo=
In-Reply-To: <0e1e6c46-49fd-4fa4-a14d-0da38ecfc857n@googlegroups.com>
Content-Language: en-US
 by: Krishna Myneni - Sat, 27 Nov 2021 16:22 UTC

On 11/24/21 02:31, pahihu wrote:
> Krishna Myneni ezt írta (2021. november 23., kedd, 22:41:18 UTC+1):
>> Nice. However, I find an accuracy problem:
>
> Increasing the digits of the halftone constants and using the scaled definition
> below solves the accuracy problem.
>
> 10594631 constant halftone
> 09438743 constant 1/halftone
>
> : scaled ( #halftones mult -- freq )
> \ Scale frequency of A4 with given number of seminotes.
> freqA4 1000 * rot 0 ?DO
> over 10000000 */
> LOOP
> swap drop
> 500 + 1000 /
> ;
>
> Gives errors only at C#9 and G9 (out of the C0 - B8 range).
>
> pahihu
>

Ok. Just had a chance to test your fix under kforth64. The note to
frequency conversions over the C0--B8 range are accurate to two decimal
places.

Krishna

--

E 'b 3 tone freq? .2 tone to frequency (modifiers 'b '#)
24694 tone? type frequency to tone ok
ok
..s
<empty>
ok
F '# 0 tone freq? .2
23.12 ok
F 0 tone freq? .2
21.83 ok
B 0 tone freq? .2
30.87 ok
F 1 tone freq? .2
43.65 ok
G 1 tone freq? .2
49.00 ok
A 4 tone freq? .2
440.00 ok
C 4 tone freq? .2
261.63 ok
ok
\ End point tests
ok
C 0 tone freq? .2
16.35 ok
B 8 tone freq? .2
7902.13 ok

Re: Suggested exercise in Forth

<sntmjc$gh9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15356&group=comp.lang.forth#15356

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Suggested exercise in Forth
Date: Sat, 27 Nov 2021 10:32:42 -0600
Organization: A noiseless patient Spider
Lines: 202
Message-ID: <sntmjc$gh9$1@dont-email.me>
References: <snhi1g$tip$1@dont-email.me>
<14ca7deb-7740-4fe2-b141-3cfb0586d7f9n@googlegroups.com>
<snr7mt$pum$1@dont-email.me>
<6adaa63b-d2a2-4413-9238-755e682a98e5n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 27 Nov 2021 16:32:44 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f0c38e295e6d459f993b935c947a3766";
logging-data="16937"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18WxDjwh+B5ix0fijzQqwPS"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.1.0
Cancel-Lock: sha1:6UU9CgkB7OVAC3lUv5nlDVOfSc4=
In-Reply-To: <6adaa63b-d2a2-4413-9238-755e682a98e5n@googlegroups.com>
Content-Language: en-US
 by: Krishna Myneni - Sat, 27 Nov 2021 16:32 UTC

On 11/26/21 22:03, S Jack wrote:
> On Friday, November 26, 2021 at 12:06:22 PM UTC-6, Krishna Myneni wrote:
>>>
>> Your code looks relatively compact, but it's unclear at first glance how
>> much of the compactness derives from use of non-standard Forth words and
>> features.
>
> The non-standard doesn't make it any better or worse. Much of the code
> for just for display. I tuned the frequency calculation up some; it
> passes two decimal accuracy for all half-steps up to 82 and a few after.
> The ones that fail are still within accuracy of one decimal digit.
> The tuned up calculation only uses the feature of the "*/" that does
> an internal double product along with applied roundup.
> A math person may get better accuracy but my interest is more in
> how my words play together in an application and what may need reworking
> or added.
>
> :) frogd
> ELF32X86_64 Frog Version 1.0d
>
> "job" /go
> Twelve tone equal tempered
>
>
>
> 1,059,463 CONST F0 \ 12th root of 2 (approx) x 1,000,000
>
> : FREQ ( hs -- u )
> 58 -
> DUP 0= IF DROP 44000
> EXIT FI
> DUP 0> IF
> 440,000,0 SWAP 0 ?DO F0 1,000,00 */ 5 + 10 / LOOP
> 50 + 100 /
> EXIT FI
> ABS 440,000,000 SWAP 0 DO 1,000,000 F0 */ LOOP
> 5,000 + 10,000 /
> ;
>
>
>
>
> Frequency (hz)
> Half-step Calculated Expected
> 1 16.35 16.35 PASS
> 2 17.32 17.32 PASS
> 3 18.35 18.35 PASS
> 4 19.45 19.45 PASS
> 5 20.60 20.60 PASS
> 6 21.83 21.83 PASS
> 7 23.12 23.12 PASS
> 8 24.50 24.50 PASS
> 9 25.96 25.96 PASS
> 10 27.50 27.50 PASS
> 11 29.14 29.14 PASS
> 12 30.87 30.87 PASS
> 13 32.70 32.70 PASS
> 14 34.65 34.65 PASS
> 15 36.71 36.71 PASS
> 16 38.89 38.89 PASS
> 17 41.20 41.20 PASS
> 18 43.65 43.65 PASS
> 19 46.25 46.25 PASS
> 20 49.00 49.00 PASS
> 21 51.91 51.91 PASS
> 22 55.00 55.00 PASS
> 23 58.27 58.27 PASS
> 24 61.74 61.74 PASS
> 25 65.41 65.41 PASS
> 26 69.30 69.30 PASS
> 27 73.42 73.42 PASS
> 28 77.78 77.78 PASS
> 29 82.41 82.41 PASS
> 30 87.31 87.31 PASS
> 31 92.50 92.50 PASS
> 32 98.00 98.00 PASS
> 33 103.83 103.83 PASS
> 34 110.00 110.00 PASS
> 35 116.54 116.54 PASS
> 36 123.47 123.47 PASS
> 37 130.81 130.81 PASS
> 38 138.59 138.59 PASS
> 39 146.83 146.83 PASS
> 40 155.56 155.56 PASS
> 41 164.81 164.81 PASS
> 42 174.61 174.61 PASS
> 43 185.00 185.00 PASS
> 44 196.00 196.00 PASS
> 45 207.65 207.65 PASS
> 46 220.00 220.00 PASS
> 47 233.08 233.08 PASS
> 48 246.94 246.94 PASS
> 49 261.63 261.63 PASS
> 50 277.18 277.18 PASS
> 51 293.66 293.66 PASS
> 52 311.13 311.13 PASS
> 53 329.63 329.63 PASS
> 54 349.23 349.23 PASS
> 55 369.99 369.99 PASS
> 56 392.00 392.00 PASS
> 57 415.30 415.30 PASS
> 58 440.00 440.00 PASS
> 59 466.16 466.16 PASS
> 60 493.88 493.88 PASS
> 61 523.25 523.25 PASS
> 62 554.37 554.37 PASS
> 63 587.33 587.33 PASS
> 64 622.25 622.25 PASS
> 65 659.25 659.25 PASS
> 66 698.46 698.46 PASS
> 67 739.99 739.99 PASS
> 68 783.99 783.99 PASS
> 69 830.61 830.61 PASS
> 70 880.00 880.00 PASS
> 71 932.33 932.33 PASS
> 72 987.77 987.77 PASS
> 73 1046.50 1046.50 PASS
> 74 1108.73 1108.73 PASS
> 75 1174.66 1174.66 PASS
> 76 1244.51 1244.51 PASS
> 77 1318.51 1318.51 PASS
> 78 1396.91 1396.91 PASS
> 79 1479.98 1479.98 PASS
> 80 1567.98 1567.98 PASS
> 81 1661.22 1661.22 PASS
> 82 1760.00 1760.00 PASS
> 83 1864.65 1864.66 FAIL
> 84 1975.53 1975.53 PASS
> 85 2093.00 2093.00 PASS
> 86 2217.46 2217.46 PASS
> 87 2349.31 2349.32 FAIL
> 88 2489.01 2489.02 FAIL
> 89 2637.01 2637.02 FAIL
> 90 2793.82 2793.83 FAIL
> 91 2959.95 2959.96 FAIL
> 92 3135.96 3135.96 PASS
> 93 3322.43 3322.44 FAIL
> 94 3519.99 3520.00 FAIL
> 95 3729.30 3729.31 FAIL
> 96 3951.05 3951.07 FAIL
> 97 4186.00 4186.01 FAIL
> 98 4434.91 4434.92 FAIL
> 99 4698.62 4698.63 FAIL
> 100 4978.01 4978.03 FAIL
> 101 5274.02 5274.04 FAIL
> 102 5587.63 5587.65 FAIL
> 103 5919.89 5919.91 FAIL
> 104 6271.90 6271.93 FAIL
> 105 6644.85 6644.88 FAIL
> 106 7039.97 7040.00 FAIL
> 107 7458.59 7458.62 FAIL
> 108 7902.10 7902.13 FAIL
>
> -fin-
> ok
> --
> me
>

Perhaps you can try pahihu's conversion, which uses another significant
digit for the 12th root of 12 (scale factor of ten million instead of 1
million). This may fix the frequency accuracy without any other major
changes. The relevant code, snipped from his revised program is,

----
0 constant C
2 constant D
4 constant E
5 constant F
7 constant G
9 constant A
11 constant B

: '# ( n1 -- n2 ) 1+ ;
: 'b ( n1 -- n2 ) 1- ;

: tone ( #halftones #octave -- #halftones ) 12 * + ;

A 4 tone constant A4
44000 constant freqA4
10594631 constant halftone
09438743 constant 1/halftone

: scaled ( #halftones mult -- freq )
\ Scale frequency of A4 with given number of seminotes.
freqA4 1000 * rot 0 ?DO
over 10000000 */
LOOP
swap drop
500 + 1000 /
;

: freq? ( #halftones -- freq )
\ Convert numeric tone to frequency.
A4 -
dup 0< IF negate 1/halftone
ELSE halftone
THEN
scaled ;
----

KM

Re: Suggested exercise in Forth

<93becc3c-adf3-4514-9871-4c413ac94d7fn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15357&group=comp.lang.forth#15357

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:5ad1:: with SMTP id d17mr32583590qtd.23.1638033300325;
Sat, 27 Nov 2021 09:15:00 -0800 (PST)
X-Received: by 2002:a05:622a:354:: with SMTP id r20mr23750540qtw.571.1638033300134;
Sat, 27 Nov 2021 09:15:00 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sat, 27 Nov 2021 09:14:59 -0800 (PST)
In-Reply-To: <sntmjc$gh9$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:3f7a:20d0:d41c:86fd:a610:b7c5;
posting-account=V5nGoQoAAAC_P2U0qnxm2kC0s1jNJXJa
NNTP-Posting-Host: 2600:1700:3f7a:20d0:d41c:86fd:a610:b7c5
References: <snhi1g$tip$1@dont-email.me> <14ca7deb-7740-4fe2-b141-3cfb0586d7f9n@googlegroups.com>
<snr7mt$pum$1@dont-email.me> <6adaa63b-d2a2-4413-9238-755e682a98e5n@googlegroups.com>
<sntmjc$gh9$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <93becc3c-adf3-4514-9871-4c413ac94d7fn@googlegroups.com>
Subject: Re: Suggested exercise in Forth
From: sdwjac...@gmail.com (S Jack)
Injection-Date: Sat, 27 Nov 2021 17:15:00 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 149
 by: S Jack - Sat, 27 Nov 2021 17:14 UTC

On Saturday, November 27, 2021 at 10:32:46 AM UTC-6, Krishna Myneni wrote:
> On 11/26/21 22:03, S Jack wrote:
> >
> Perhaps you can try pahihu's conversion, which uses another significant
> digit for the 12th root of 12 (scale factor of ten million instead of 1
> million). This may fix the frequency accuracy without any other major
> changes. The relevant code, snipped from his revised program is,

Plugged in the exter digit and got green for all but G5 and D8 which
were off by .01 .
:) fg
frogd
go
go
Twelve tone equal tempered

1,059,4631 CONST F0 \ 12th root of 2 (approx) x 1,000,000

: FREQ ( hs -- u )
58 -
DUP 0= IF DROP 44000
EXIT FI
DUP 0> IF
440,000,0 SWAP 0 ?DO F0 1,000,000 */ 5 + 10 / LOOP
50 + 100 /
EXIT FI
ABS 440,000,000 SWAP 0 DO 1,000,000,0 F0 */ LOOP
5,000 + 10,000 /
;

Frequency (hz)
Half-step Calculated Expected
1 16.35 16.35 PASS
2 17.32 17.32 PASS
3 18.35 18.35 PASS
4 19.45 19.45 PASS
5 20.60 20.60 PASS
6 21.83 21.83 PASS
7 23.12 23.12 PASS
8 24.50 24.50 PASS
9 25.96 25.96 PASS
10 27.50 27.50 PASS
11 29.14 29.14 PASS
12 30.87 30.87 PASS
13 32.70 32.70 PASS
14 34.65 34.65 PASS
15 36.71 36.71 PASS
16 38.89 38.89 PASS
17 41.20 41.20 PASS
18 43.65 43.65 PASS
19 46.25 46.25 PASS
20 49.00 49.00 PASS
21 51.91 51.91 PASS
22 55.00 55.00 PASS
23 58.27 58.27 PASS
24 61.74 61.74 PASS
25 65.41 65.41 PASS
26 69.30 69.30 PASS
27 73.42 73.42 PASS
28 77.78 77.78 PASS
29 82.41 82.41 PASS
30 87.31 87.31 PASS
31 92.50 92.50 PASS
32 98.00 98.00 PASS
33 103.83 103.83 PASS
34 110.00 110.00 PASS
35 116.54 116.54 PASS
36 123.47 123.47 PASS
37 130.81 130.81 PASS
38 138.59 138.59 PASS
39 146.83 146.83 PASS
40 155.56 155.56 PASS
41 164.81 164.81 PASS
42 174.61 174.61 PASS
43 185.00 185.00 PASS
44 196.00 196.00 PASS
45 207.65 207.65 PASS
46 220.00 220.00 PASS
47 233.08 233.08 PASS
48 246.94 246.94 PASS
49 261.63 261.63 PASS
50 277.18 277.18 PASS
51 293.66 293.66 PASS
52 311.13 311.13 PASS
53 329.63 329.63 PASS
54 349.23 349.23 PASS
55 369.99 369.99 PASS
56 392.00 392.00 PASS
57 415.30 415.30 PASS
58 440.00 440.00 PASS
59 466.16 466.16 PASS
60 493.88 493.88 PASS
61 523.25 523.25 PASS
62 554.37 554.37 PASS
63 587.33 587.33 PASS
64 622.25 622.25 PASS
65 659.26 659.25 FAIL
66 698.46 698.46 PASS
67 739.99 739.99 PASS
68 783.99 783.99 PASS
69 830.61 830.61 PASS
70 880.00 880.00 PASS
71 932.33 932.33 PASS
72 987.77 987.77 PASS
73 1046.50 1046.50 PASS
74 1108.73 1108.73 PASS
75 1174.66 1174.66 PASS
76 1244.51 1244.51 PASS
77 1318.51 1318.51 PASS
78 1396.91 1396.91 PASS
79 1479.98 1479.98 PASS
80 1567.98 1567.98 PASS
81 1661.22 1661.22 PASS
82 1760.00 1760.00 PASS
83 1864.66 1864.66 PASS
84 1975.53 1975.53 PASS
85 2093.00 2093.00 PASS
86 2217.46 2217.46 PASS
87 2349.32 2349.32 PASS
88 2489.02 2489.02 PASS
89 2637.02 2637.02 PASS
90 2793.83 2793.83 PASS
91 2959.96 2959.96 PASS
92 3135.96 3135.96 PASS
93 3322.44 3322.44 PASS
94 3520.00 3520.00 PASS
95 3729.31 3729.31 PASS
96 3951.07 3951.07 PASS
97 4186.01 4186.01 PASS
98 4434.92 4434.92 PASS
99 4698.64 4698.63 FAIL
100 4978.03 4978.03 PASS
101 5274.04 5274.04 PASS
102 5587.65 5587.65 PASS
103 5919.91 5919.91 PASS
104 6271.93 6271.93 PASS
105 6644.88 6644.88 PASS
106 7040.00 7040.00 PASS
107 7458.62 7458.62 PASS
108 7902.13 7902.13 PASS

-fin-
ok
--
me

Re: Suggested exercise in Forth

<snubg8$2q3$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15358&group=comp.lang.forth#15358

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Suggested exercise in Forth
Date: Sat, 27 Nov 2021 16:29:26 -0600
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <snubg8$2q3$1@dont-email.me>
References: <snhi1g$tip$1@dont-email.me>
<14ca7deb-7740-4fe2-b141-3cfb0586d7f9n@googlegroups.com>
<snr7mt$pum$1@dont-email.me>
<6adaa63b-d2a2-4413-9238-755e682a98e5n@googlegroups.com>
<sntmjc$gh9$1@dont-email.me>
<93becc3c-adf3-4514-9871-4c413ac94d7fn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 27 Nov 2021 22:29:28 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f0c38e295e6d459f993b935c947a3766";
logging-data="2883"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/RGXDkXiBYmPuBNUoGq7l8"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.1.0
Cancel-Lock: sha1:3EvFeHczap+M7JugDDJ7zAV3MXs=
In-Reply-To: <93becc3c-adf3-4514-9871-4c413ac94d7fn@googlegroups.com>
Content-Language: en-US
 by: Krishna Myneni - Sat, 27 Nov 2021 22:29 UTC

On 11/27/21 11:14, S Jack wrote:
> On Saturday, November 27, 2021 at 10:32:46 AM UTC-6, Krishna Myneni wrote:
>> On 11/26/21 22:03, S Jack wrote:
>>>
>> Perhaps you can try pahihu's conversion, which uses another significant
>> digit for the 12th root of 12 (scale factor of ten million instead of 1
>> million). This may fix the frequency accuracy without any other major
>> changes. The relevant code, snipped from his revised program is,
>
> Plugged in the exter digit and got green for all but G5 and D8 which
> were off by .01 .

....
> 63 587.33 587.33 PASS
> 64 622.25 622.25 PASS
> 65 659.26 659.25 FAIL
....

It is E5 which appeared to fail, not G5. Your answer is correct. The
reference table appears to be incorrect. We can check this using f(A4) =
440.00 Hz. E5 is 7 semitones above A4:

2e0 1e 12e f/ f** fconstant 12root2
440.00e fconstant f(A4)

\ frequency of n semitones above A4
: f(n) ( n -- ) ( F: -- r )
f(A4) 7 0 DO 12root2 f* LOOP ;

7 f(n) f.
659.255 ok

This should round off to two decimal places as 659.26.

Pahihu's code produces the same result for f(E5).

Krishna

Re: Suggested exercise in Forth

<snuler$q3e$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15359&group=comp.lang.forth#15359

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Suggested exercise in Forth
Date: Sat, 27 Nov 2021 19:19:21 -0600
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <snuler$q3e$1@dont-email.me>
References: <snhi1g$tip$1@dont-email.me>
<14ca7deb-7740-4fe2-b141-3cfb0586d7f9n@googlegroups.com>
<snr7mt$pum$1@dont-email.me>
<6adaa63b-d2a2-4413-9238-755e682a98e5n@googlegroups.com>
<sntmjc$gh9$1@dont-email.me>
<93becc3c-adf3-4514-9871-4c413ac94d7fn@googlegroups.com>
<snubg8$2q3$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 28 Nov 2021 01:19:23 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5328d8984a32c771c174ccc3a4a63c7c";
logging-data="26734"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18uT/hy084JCPKOdDdenN5+"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.1.0
Cancel-Lock: sha1:uRVpaMPMHCwCB+Pqq0A0kkk6xeU=
In-Reply-To: <snubg8$2q3$1@dont-email.me>
Content-Language: en-US
 by: Krishna Myneni - Sun, 28 Nov 2021 01:19 UTC

On 11/27/21 16:29, Krishna Myneni wrote:
> On 11/27/21 11:14, S Jack wrote:
>> On Saturday, November 27, 2021 at 10:32:46 AM UTC-6, Krishna Myneni
>> wrote:
>>> On 11/26/21 22:03, S Jack wrote:
>>>>
>>> Perhaps you can try pahihu's conversion, which uses another significant
>>> digit for the 12th root of 12 (scale factor of ten million instead of 1
>>> million). This may fix the frequency accuracy without any other major
>>> changes. The relevant code, snipped from his revised program is,
>>
>> Plugged in the exter digit and got green for all but G5 and D8 which
>> were off by .01 .
>
> ...
>>     63         587.33       587.33     PASS
>>     64         622.25       622.25     PASS
>>     65         659.26       659.25     FAIL
> ...
>
> It is E5 which appeared to fail, not G5. Your answer is correct. The
> reference table appears to be incorrect. We can check this using f(A4) =
> 440.00 Hz. E5 is 7 semitones above A4:
>
> 2e0 1e 12e f/ f** fconstant 12root2
> 440.00e fconstant f(A4)
>
> \ frequency of n semitones above A4
> : f(n) ( n -- ) ( F: -- r )
>    f(A4) 7 0 DO 12root2 f* LOOP ;
>
> 7 f(n) f.
> 659.255  ok
>
> This should round off to two decimal places as 659.26.
>
> Pahihu's code produces the same result for f(E5).
>

I was a bit rushed previously. Here's a more general version of f(n),
which computes the frequency for n semitones offset from note A4. This
version accepts both positive and negative n.

: f(n) ( n -- ) ( F: -- r )
f(A4)
dup 0< IF
abs 0 DO 12root2 f/ LOOP
ELSE
0 ?DO 12root2 f* LOOP
THEN ;

\ proper use

7 f(n) fs.
6.59255113825740e+02 ok \ 659.26 Hz

Floating point is not necessary but useful as a check.

Krishna

Re: Suggested exercise in Forth

<snurbg$1njh$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15360&group=comp.lang.forth#15360

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: Suggested exercise in Forth
Date: Sun, 28 Nov 2021 14:00:00 +1100
Organization: Aioe.org NNTP Server
Message-ID: <snurbg$1njh$1@gioia.aioe.org>
References: <snhi1g$tip$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="56945"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Content-Language: en-GB
X-Notice: Filtered by postfilter v. 0.9.2
 by: dxforth - Sun, 28 Nov 2021 03:00 UTC

On 23/11/2021 13:01, Krishna Myneni wrote:
> I think the following problem might make for a useful exercise in Forth
> coding.
>
> For the standard 12-tone equal tempered music scale (12-TET), compute
> the frequency of any specified note in the scale, ranging from C0 to B8,
> and vice-versa (see https://pages.mtu.edu/~suits/notefreqs.html ). The
> frequency, in Hz, should be returned to 2 decimal places of accuracy.

Why the author of the webpage chose 2 decimal places isn't stated but
we can surmise from the accompanying page:

https://pages.mtu.edu/~suits/NoteFreqCalcs.html

The author supplies an Excel document which uses floating-point calculation
and displays the result in fixed-point notation. Apparently a minimum 4
digits of precision was wanted at the low frequencies - hence the 2 decimal
places. At the high end this results in 6 digits of precision, which is
wasted, but was easier to display.

Had the results been displayed at a constant 4 digits of precision, it would
have appeared as below. I used VFX for Windows.

1.059463094359e fconstant f0

: freq
109 1 do
f0 i 58 - s>f f** 440e f*
cr i 4 .r space
\ 8 set-precison 2 0 f.r ( 2 decimal places)
4 set-precision -1 0 f.r ( 4 significant digits)
loop
;

freq
1 16.35
2 17.32
3 18.35
4 19.45
5 20.6
6 21.83
7 23.12
8 24.5
9 25.96
10 27.5
11 29.14
12 30.87
13 32.7
14 34.65
15 36.71
16 38.89
17 41.2
18 43.65
19 46.25
20 49.
21 51.91
22 55.
23 58.27
24 61.74
25 65.41
26 69.3
27 73.42
28 77.78
29 82.41
30 87.31
31 92.5
32 98.
33 103.8
34 110.
35 116.5
36 123.5
37 130.8
38 138.6
39 146.8
40 155.6
41 164.8
42 174.6
43 185.
44 196.
45 207.7
46 220.
47 233.1
48 246.9
49 261.6
50 277.2
51 293.7
52 311.1
53 329.6
54 349.2
55 370.
56 392.
57 415.3
58 440.
59 466.2
60 493.9
61 523.3
62 554.4
63 587.3
64 622.3
65 659.3
66 698.5
67 740.
68 784.
69 830.6
70 880.
71 932.3
72 987.8
73 1047.
74 1109.
75 1175.
76 1245.
77 1319.
78 1397.
79 1480.
80 1568.
81 1661.
82 1760.
83 1865.
84 1976.
85 2093.
86 2217.
87 2349.
88 2489.
89 2637.
90 2794.
91 2960.
92 3136.
93 3322.
94 3520.
95 3729.
96 3951.
97 4186.
98 4435.
99 4699.
100 4978.
101 5274.
102 5588.
103 5920.
104 6272.
105 6645.
106 7040.
107 7459.
108 7902. ok

Re: Suggested exercise in Forth

<snv5vl$6ht$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15361&group=comp.lang.forth#15361

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Suggested exercise in Forth
Date: Sun, 28 Nov 2021 00:01:24 -0600
Organization: A noiseless patient Spider
Lines: 84
Message-ID: <snv5vl$6ht$1@dont-email.me>
References: <snhi1g$tip$1@dont-email.me> <snurbg$1njh$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 28 Nov 2021 06:01:25 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5328d8984a32c771c174ccc3a4a63c7c";
logging-data="6717"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/upvFJOAW0zgmFSJspL4EF"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.1.0
Cancel-Lock: sha1:rAeDnagdwpmP7HwnqSeVCpRmxYM=
In-Reply-To: <snurbg$1njh$1@gioia.aioe.org>
Content-Language: en-US
 by: Krishna Myneni - Sun, 28 Nov 2021 06:01 UTC

On 11/27/21 21:00, dxforth wrote:
> On 23/11/2021 13:01, Krishna Myneni wrote:
>> I think the following problem might make for a useful exercise in Forth
>> coding.
>>
>> For the standard 12-tone equal tempered music scale (12-TET), compute
>> the frequency of any specified note in the scale, ranging from C0 to B8,
>> and vice-versa (see https://pages.mtu.edu/~suits/notefreqs.html ). The
>> frequency, in Hz, should be returned to 2 decimal places of accuracy.
>
> Why the author of the webpage chose 2 decimal places isn't stated but
> we can surmise from the accompanying page:
>
> https://pages.mtu.edu/~suits/NoteFreqCalcs.html
> The author supplies an Excel document which uses floating-point calculation
> and displays the result in fixed-point notation.  Apparently a minimum 4
> digits of precision was wanted at the low frequencies - hence the 2 decimal
> places.  At the high end this results in 6 digits of precision, which is
> wasted, but was easier to display.
>
> Had the results been displayed at a constant 4 digits of precision, it
> would
> have appeared as below.  I used VFX for Windows.
>
> 1.059463094359e fconstant f0
>
> : freq
>    109 1 do
>      f0 i 58 - s>f f** 440e f*
>      cr i 4 .r  space
> \    8 set-precison  2 0 f.r  ( 2 decimal places)
>      4 set-precision  -1 0 f.r  ( 4 significant digits)
>    loop
> ;
>
> freq
....
>    73 1047.
>    74 1109.
>    75 1175.
>    76 1245.
>    77 1319.
>    78 1397.
>    79 1480.
>    80 1568.
>    81 1661.
>    82 1760.
>    83 1865.
>    84 1976.
>    85 2093.
....

I would not infer the author's reason for using two decimal place
precision for the table. This exercise is to write code to generate the
theoretical frequency table for the equal tempered scale, given the
frequency of note A4 is 440.00 Hz. The results say nothing further about
what happens in practice. I have argued some theoretical reasons why
such precision is warranted. To understand the practical, one probably
has to understand how a piano tuner does their job.

It's clear to me that simply using 4 digits does not capture what is
achievable in tuning. The reason is that while a note like C6, with
theoretical frequency of 1046.50 Hz, may not be realizable to that many
significant digits in the tuning of an instrument, the difference
between C6 and the note one octave higher, C7 (2093.00 Hz), should be
tunable such that the difference frequency between C6 and C7 can be
accurate to much less than 1 Hz, by listening to the beating when C6 and
C7 are simultaneously played. If you simply list these frequencies as
1047. Hz and 2093. Hz, as you have done in your table, it implies that
the difference frequency between C6 and C7 is uncertain to about 1 Hz,
which does not have to be the case in practice.

Also, for electronically synthesized music, a quartz oscillator
providing the time base can be used to generate frequencies accurate to
six digits. In this case, the theoretical table is more useful. It's
drawback is that it likely does not represent the achievable tuning
accuracy for individual note frequencies for non-electronic instruments.

Finally, there is the mystery of why the theoretical G5 frequency
appears to be wrong in the author's spreadsheet. In general, my
experience with using spreadsheets for numerical computing is that it's
a risky proposition.

KM

Re: Suggested exercise in Forth

<snvhmv$6t3$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15362&group=comp.lang.forth#15362

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: Suggested exercise in Forth
Date: Sun, 28 Nov 2021 20:21:35 +1100
Organization: Aioe.org NNTP Server
Message-ID: <snvhmv$6t3$1@gioia.aioe.org>
References: <snhi1g$tip$1@dont-email.me> <snurbg$1njh$1@gioia.aioe.org>
<snv5vl$6ht$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="7075"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-GB
 by: dxforth - Sun, 28 Nov 2021 09:21 UTC

On 28/11/2021 17:01, Krishna Myneni wrote:
> On 11/27/21 21:00, dxforth wrote:
>> On 23/11/2021 13:01, Krishna Myneni wrote:
>>> I think the following problem might make for a useful exercise in Forth
>>> coding.
>>>
>>> For the standard 12-tone equal tempered music scale (12-TET), compute
>>> the frequency of any specified note in the scale, ranging from C0 to B8,
>>> and vice-versa (see https://pages.mtu.edu/~suits/notefreqs.html ). The
>>> frequency, in Hz, should be returned to 2 decimal places of accuracy.
>>
>> Why the author of the webpage chose 2 decimal places isn't stated but
>> we can surmise from the accompanying page:
>>
>> https://pages.mtu.edu/~suits/NoteFreqCalcs.html
>> The author supplies an Excel document which uses floating-point calculation
>> and displays the result in fixed-point notation.  Apparently a minimum 4
>> digits of precision was wanted at the low frequencies - hence the 2 decimal
>> places.  At the high end this results in 6 digits of precision, which is
>> wasted, but was easier to display.
>>
>> Had the results been displayed at a constant 4 digits of precision, it
>> would
>> have appeared as below.  I used VFX for Windows.
>>
>> 1.059463094359e fconstant f0
>>
>> : freq
>>    109 1 do
>>      f0 i 58 - s>f f** 440e f*
>>      cr i 4 .r  space
>> \    8 set-precison  2 0 f.r  ( 2 decimal places)
>>      4 set-precision  -1 0 f.r  ( 4 significant digits)
>>    loop
>> ;
>>
>> freq
> ...
>>    73 1047.
>>    74 1109.
>>    75 1175.
>>    76 1245.
>>    77 1319.
>>    78 1397.
>>    79 1480.
>>    80 1568.
>>    81 1661.
>>    82 1760.
>>    83 1865.
>>    84 1976.
>>    85 2093.
> ...
>
> I would not infer the author's reason for using two decimal place
> precision for the table.

No, but it falls on the user to justify his use :)

> This exercise is to write code to generate the
> theoretical frequency table for the equal tempered scale, given the
> frequency of note A4 is 440.00 Hz. The results say nothing further about
> what happens in practice. I have argued some theoretical reasons why
> such precision is warranted. To understand the practical, one probably
> has to understand how a piano tuner does their job.

I doubt there's much precision in BASIC's PLAY command.

> It's clear to me that simply using 4 digits does not capture what is
> achievable in tuning. The reason is that while a note like C6, with
> theoretical frequency of 1046.50 Hz, may not be realizable to that many
> significant digits in the tuning of an instrument, the difference
> between C6 and the note one octave higher, C7 (2093.00 Hz), should be
> tunable such that the difference frequency between C6 and C7 can be
> accurate to much less than 1 Hz, by listening to the beating when C6 and
> C7 are simultaneously played. If you simply list these frequencies as
> 1047. Hz and 2093. Hz, as you have done in your table, it implies that
> the difference frequency between C6 and C7 is uncertain to about 1 Hz,
> which does not have to be the case in practice.

No more uncertain than 21.83 and 43.65 in the listing you've adopted.
Most readers understand the representation is not the thing. The
author's choice of displaying as decimal places seems to have been
just that. Below is an example of a listing which employs significant
digits. Perhaps (like me) the author felt it was a better fit.

http://www.phys.unsw.edu.au/jw/notes.html

Re: Suggested exercise in Forth

<so00ht$tj5$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15363&group=comp.lang.forth#15363

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Suggested exercise in Forth
Date: Sun, 28 Nov 2021 07:34:51 -0600
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <so00ht$tj5$1@dont-email.me>
References: <snhi1g$tip$1@dont-email.me> <snurbg$1njh$1@gioia.aioe.org>
<snv5vl$6ht$1@dont-email.me> <snvhmv$6t3$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 28 Nov 2021 13:34:53 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5328d8984a32c771c174ccc3a4a63c7c";
logging-data="30309"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/PSBqleFPYmbAeN5Ys/uhz"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.1.0
Cancel-Lock: sha1:H9xrkx9n9NJerPISwEYi5G/Uk+w=
In-Reply-To: <snvhmv$6t3$1@gioia.aioe.org>
Content-Language: en-US
 by: Krishna Myneni - Sun, 28 Nov 2021 13:34 UTC

On 11/28/21 03:21, dxforth wrote:
> On 28/11/2021 17:01, Krishna Myneni wrote:

>>
>> I would not infer the author's reason for using two decimal place
>> precision for the table.
>
> No, but it falls on the user to justify his use :)
>

This is a coding exercise. It needs no further justification. If you
want the author of the table to justify his use of precision, you should
discuss it with him.

KM

Re: Suggested exercise in Forth

<47a5adf7-936e-42b1-a401-638052da5c43n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15364&group=comp.lang.forth#15364

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:14a3:: with SMTP id x3mr35006015qkj.286.1638131677973;
Sun, 28 Nov 2021 12:34:37 -0800 (PST)
X-Received: by 2002:ac8:4e96:: with SMTP id 22mr39222191qtp.76.1638131677796;
Sun, 28 Nov 2021 12:34:37 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sun, 28 Nov 2021 12:34:37 -0800 (PST)
In-Reply-To: <snurbg$1njh$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:3f7a:20d0:9024:8b61:d40b:6e1e;
posting-account=V5nGoQoAAAC_P2U0qnxm2kC0s1jNJXJa
NNTP-Posting-Host: 2600:1700:3f7a:20d0:9024:8b61:d40b:6e1e
References: <snhi1g$tip$1@dont-email.me> <snurbg$1njh$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <47a5adf7-936e-42b1-a401-638052da5c43n@googlegroups.com>
Subject: Re: Suggested exercise in Forth
From: sdwjac...@gmail.com (S Jack)
Injection-Date: Sun, 28 Nov 2021 20:34:37 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 40
 by: S Jack - Sun, 28 Nov 2021 20:34 UTC

On Saturday, November 27, 2021 at 9:00:03 PM UTC-6, dxforth wrote:

> 1.059463094359e fconstant f0
>
> : freq
> 109 1 do
> f0 i 58 - s>f f** 440e f*
> cr i 4 .r space
> \ 8 set-precison 2 0 f.r ( 2 decimal places)
> 4 set-precision -1 0 f.r ( 4 significant digits)
> loop
> ;
>
> freq
> 1 16.35
> 2 17.32
> 3 18.35
> 4 19.45

Multiplying the 3rd half-step frequency (1835) in the table
by the 12th root of 2 and showing result with digits to 5 decimal places
(1944147 or 19.44147) does not give the 4th half-step frequency (1945)
in the table:

1,059,463,1 CONST F0 \ 12th root of 2 (approx) x 10,000,000
1835 f0 1000 */ . ==> 19,441,147 \ 4th half-step frequency calculated
4 tblFREQ [] . ==> 1945 \ 4th half-step frequency in table

However, if I start at the 58th half-step (A4: 440) and divide down
to the 4th half-step, thus accumulating some error, I get the table
result.

: foo
440,000,000
58 4 DO 10,000,000 F0 */ LOOP
5,000 + 10,000 / ;
foo . ==> 1945

Not sure what the target should be, 19.45 or 19.44?

Re: Suggested exercise in Forth

<2f38d521-a41b-4027-afd5-58bde2921f40n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15365&group=comp.lang.forth#15365

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:28d0:: with SMTP id l16mr35230308qkp.500.1638134147268;
Sun, 28 Nov 2021 13:15:47 -0800 (PST)
X-Received: by 2002:ad4:5945:: with SMTP id eo5mr25963049qvb.130.1638134147084;
Sun, 28 Nov 2021 13:15:47 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sun, 28 Nov 2021 13:15:46 -0800 (PST)
In-Reply-To: <47a5adf7-936e-42b1-a401-638052da5c43n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2607:fea8:2a60:9ae:1150:779f:3773:b1bc;
posting-account=2z7GawoAAADc70p5SM5AbaCyzjLblS3g
NNTP-Posting-Host: 2607:fea8:2a60:9ae:1150:779f:3773:b1bc
References: <snhi1g$tip$1@dont-email.me> <snurbg$1njh$1@gioia.aioe.org> <47a5adf7-936e-42b1-a401-638052da5c43n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2f38d521-a41b-4027-afd5-58bde2921f40n@googlegroups.com>
Subject: Re: Suggested exercise in Forth
From: brian....@brianfox.ca (Brian Fox)
Injection-Date: Sun, 28 Nov 2021 21:15:47 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 47
 by: Brian Fox - Sun, 28 Nov 2021 21:15 UTC

On Sunday, November 28, 2021 at 3:34:38 PM UTC-5, S Jack wrote:
> On Saturday, November 27, 2021 at 9:00:03 PM UTC-6, dxforth wrote:
>
> > 1.059463094359e fconstant f0
> >
> > : freq
> > 109 1 do
> > f0 i 58 - s>f f** 440e f*
> > cr i 4 .r space
> > \ 8 set-precison 2 0 f.r ( 2 decimal places)
> > 4 set-precision -1 0 f.r ( 4 significant digits)
> > loop
> > ;
> >
> > freq
> > 1 16.35
> > 2 17.32
> > 3 18.35
> > 4 19.45
> Multiplying the 3rd half-step frequency (1835) in the table
> by the 12th root of 2 and showing result with digits to 5 decimal places
> (1944147 or 19.44147) does not give the 4th half-step frequency (1945)
> in the table:
>
> 1,059,463,1 CONST F0 \ 12th root of 2 (approx) x 10,000,000
> 1835 f0 1000 */ . ==> 19,441,147 \ 4th half-step frequency calculated
> 4 tblFREQ [] . ==> 1945 \ 4th half-step frequency in table
>
> However, if I start at the 58th half-step (A4: 440) and divide down
> to the 4th half-step, thus accumulating some error, I get the table
> result.
>
> : foo
> 440,000,000
> 58 4 DO 10,000,000 F0 */ LOOP
> 5,000 + 10,000 / ;
>
> foo . ==> 1945
>
> Not sure what the target should be, 19.45 or 19.44?

Probably not that important since humans can't really hear below 20Hz.
We can feel the vibration at loud intensity but "pitch" is not really detected.
The lowest instrument instrument I know of is the contra-bassoon which
occasionally has to play Bb0. (29.135 Hz)

Sounds like this :-)
https://www.youtube.com/watch?v=ZYnCfYrI7TU&t=239s

Re: Suggested exercise in Forth

<7779c277-2aef-4821-ae54-4add0e63c2efn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15372&group=comp.lang.forth#15372

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:6214:519c:: with SMTP id kl28mr27515754qvb.71.1638161668611;
Sun, 28 Nov 2021 20:54:28 -0800 (PST)
X-Received: by 2002:a05:622a:11d4:: with SMTP id n20mr38991580qtk.412.1638161668425;
Sun, 28 Nov 2021 20:54:28 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sun, 28 Nov 2021 20:54:28 -0800 (PST)
In-Reply-To: <2f38d521-a41b-4027-afd5-58bde2921f40n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:3f7a:20d0:9024:8b61:d40b:6e1e;
posting-account=V5nGoQoAAAC_P2U0qnxm2kC0s1jNJXJa
NNTP-Posting-Host: 2600:1700:3f7a:20d0:9024:8b61:d40b:6e1e
References: <snhi1g$tip$1@dont-email.me> <snurbg$1njh$1@gioia.aioe.org>
<47a5adf7-936e-42b1-a401-638052da5c43n@googlegroups.com> <2f38d521-a41b-4027-afd5-58bde2921f40n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7779c277-2aef-4821-ae54-4add0e63c2efn@googlegroups.com>
Subject: Re: Suggested exercise in Forth
From: sdwjac...@gmail.com (S Jack)
Injection-Date: Mon, 29 Nov 2021 04:54:28 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 317
 by: S Jack - Mon, 29 Nov 2021 04:54 UTC

:) frogd
ELF32X86_64 Frog Version 1.0d

"job" /go
Twelve tone equal tempered

-- half step table
CREATE tblHS
"C " SG, "C#" SG, "D " SG, "D#" SG, "E " SG, "F " SG,
"F#" SG, "G " SG, "G#" SG, "A " SG, "A#" SG, "B " SG,
align

-- half-step (u) to note (string)
: note ( u -- s )
dup 109 1 within abort" bad half-step"
1- 12 /mod
asc 0 + swap
2 * tblHS + 2 pad gts
pad 2 CHARS + DUP C@ bl = if 2 pad c! \ whole note, XN
ii 3 pad c! char+ \ sharp note, X#N
fi c!
pad ;

-- note (string) to half-step (u)
: HS ( s -- u )
UPPER DUP COUNT 1- + C@ ASC 0 - >R \ scale register (0-8)
-1 OVER C+! >R \ PITCH
1 TBLHS BEGIN DUP R C@ R GSCMP
WHILE 2 + SWAP 1+
13 OVER >
WHILE SWAP
REPEAT ABORT FI
RDROP DROP R> 12 * + ;

1,059,463,1 CONST F0 \ 12th root of 2 (approx) x 10,000,000

-- half-step (hs) to frequency (hz)
: FREQ ( hs -- hz )
58 -
DUP 0= IF DROP 44000
EXIT FI
DUP 0> IF 440,000,0 SWAP 0 ?DO F0 1,000,000 */ 5 + 10 / LOOP
50 + 100 /
EXIT FI
ABS 440,000,000 SWAP 0 DO 10,000,000 F0 */ LOOP
5,000 + 10,000 /
;

\ -STAB 0 2 13 26 38 TABS
\ cr ul( "Pitch vs. Frequency (hz)" 40 s.c )
\ cr tab ul( .( Half-step)) tab ul( .( Pitch)) tab ul( .( Frequency))
\ { 109 1 do cr tab i 3 u.r i note dup tab tell hs freq tab 2 8 un.r loop } run1

Pitch vs. Frequency (hz)
Half-step Pitch Frequency
1 C0 16.35
2 C#0 17.32
3 D0 18.35
4 D#0 19.45
5 E0 20.60
6 F0 21.83
7 F#0 23.12
8 G0 24.50
9 G#0 25.96
10 A0 27.50
11 A#0 29.14
12 B0 30.87
13 C1 32.70
14 C#1 34.65
15 D1 36.71
16 D#1 38.89
17 E1 41.20
18 F1 43.65
19 F#1 46.25
20 G1 49.00
21 G#1 51.91
22 A1 55.00
23 A#1 58.27
24 B1 61.74
25 C2 65.41
26 C#2 69.30
27 D2 73.42
28 D#2 77.78
29 E2 82.41
30 F2 87.31
31 F#2 92.50
32 G2 98.00
33 G#2 103.83
34 A2 110.00
35 A#2 116.54
36 B2 123.47
37 C3 130.81
38 C#3 138.59
39 D3 146.83
40 D#3 155.56
41 E3 164.81
42 F3 174.61
43 F#3 185.00
44 G3 196.00
45 G#3 207.65
46 A3 220.00
47 A#3 233.08
48 B3 246.94
49 C4 261.63
50 C#4 277.18
51 D4 293.66
52 D#4 311.13
53 E4 329.63
54 F4 349.23
55 F#4 369.99
56 G4 392.00
57 G#4 415.30
58 A4 440.00
59 A#4 466.16
60 B4 493.88
61 C5 523.25
62 C#5 554.37
63 D5 587.33
64 D#5 622.25
65 E5 659.26
66 F5 698.46
67 F#5 739.99
68 G5 783.99
69 G#5 830.61
70 A5 880.00
71 A#5 932.33
72 B5 987.77
73 C6 1046.50
74 C#6 1108.73
75 D6 1174.66
76 D#6 1244.51
77 E6 1318.51
78 F6 1396.91
79 F#6 1479.98
80 G6 1567.98
81 G#6 1661.22
82 A6 1760.00
83 A#6 1864.66
84 B6 1975.53
85 C7 2093.00
86 C#7 2217.46
87 D7 2349.32
88 D#7 2489.02
89 E7 2637.02
90 F7 2793.83
91 F#7 2959.96
92 G7 3135.96
93 G#7 3322.44
94 A7 3520.00
95 A#7 3729.31
96 B7 3951.07
97 C8 4186.01
98 C#8 4434.92
99 D8 4698.64
100 D#8 4978.03
101 E8 5274.04
102 F8 5587.65
103 F#8 5919.91
104 G8 6271.93
105 G#8 6644.88
106 A8 7040.00
107 A#8 7458.62
108 B8 7902.13

Pitch

: pitch ( f -- s )
44000 over -
dup 0= if ( f = FA ) 2DROP "a4" exit fi
0> if ( f < FA )
58 swap >R
440,000,000
BEGIN R OVER 10,000 /
< WHILE
10,000,000 F0 */
over while
swap 1- swap
REPEAT ." OOPS#1" fi
RDROP drop
ii ( f > FA )
58 SWAP
BEGIN 440,00 over < while
10,000,000 F0 */
over 109 < while
swap 1+ swap
REPEAT ." OPPS2" fi
drop
fi
note
;

\ cr ul( "Frequency (hz) vs. Pitch" 40 s.c )
\ cr tab ul( .( Half-step)) tab ul( .( Frequency)) tab ul( .( Pitch))
\ { 109 1 do cr tab i 3 u.r tab i tblFREQ [] dup 2 3 un.r pitch tab tell loop }
\ run1

Frequency (hz) vs. Pitch
Half-step Frequency Pitch
1 16.35 C0
2 17.32 C#0
3 18.35 D0
4 19.45 D#0
5 20.60 E0
6 21.83 F0
7 23.12 F#0
8 24.50 G0
9 25.96 G#0
10 27.50 A0
11 29.14 A#0
12 30.87 B0
13 32.70 C1
14 34.65 C#1
15 36.71 D1
16 38.89 D#1
17 41.20 E1
18 43.65 F1
19 46.25 F#1
20 49.00 G1
21 51.91 G#1
22 55.00 A1
23 58.27 A#1
24 61.74 B1
25 65.41 C2
26 69.30 C#2
27 73.42 D2
28 77.78 D#2
29 82.41 E2
30 87.31 F2
31 92.50 F#2
32 98.00 G2
33 103.83 G#2
34 110.00 A2
35 116.54 A#2
36 123.47 B2
37 130.81 C3
38 138.59 C#3
39 146.83 D3
40 155.56 D#3
41 164.81 E3
42 174.61 F3
43 185.00 F#3
44 196.00 G3
45 207.65 G#3
46 220.00 A3
47 233.08 A#3
48 246.94 B3
49 261.63 C4
50 277.18 C#4
51 293.66 D4
52 311.13 D#4
53 329.63 E4
54 349.23 F4
55 369.99 F#4
56 392.00 G4
57 415.30 G#4
58 440.00 a4
59 466.16 A#4
60 493.88 B4
61 523.25 C5
62 554.37 C#5
63 587.33 D5
64 622.25 D#5
65 659.25 E5
66 698.46 F5
67 739.99 F#5
68 783.99 G5
69 830.61 G#5
70 880.00 A5
71 932.33 A#5
72 987.77 B5
73 1046.50 C6
74 1108.73 C#6
75 1174.66 D6
76 1244.51 D#6
77 1318.51 E6
78 1396.91 F6
79 1479.98 F#6
80 1567.98 G6
81 1661.22 G#6
82 1760.00 A6
83 1864.66 A#6
84 1975.53 B6
85 2093.00 C7
86 2217.46 C#7
87 2349.32 D7
88 2489.02 D#7
89 2637.02 E7
90 2793.83 F7
91 2959.96 F#7
92 3135.96 G7
93 3322.44 G#7
94 3520.00 A7
95 3729.31 A#7
96 3951.07 B7
97 4186.01 C8
98 4434.92 C#8
99 4698.63 D8
100 4978.03 D#8
101 5274.04 E8
102 5587.65 F8
103 5919.91 F#8
104 6271.93 G8
105 6644.88 G#8
106 7040.00 A8
107 7458.62 A#8
108 7902.13 B8


Click here to read the complete article
Re: Suggested exercise in Forth

<88b4230b-7359-4c54-965e-98d0cfee92cdn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15373&group=comp.lang.forth#15373

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:622a:120b:: with SMTP id y11mr33287445qtx.544.1638175015471;
Mon, 29 Nov 2021 00:36:55 -0800 (PST)
X-Received: by 2002:a05:620a:4691:: with SMTP id bq17mr38280617qkb.510.1638175015290;
Mon, 29 Nov 2021 00:36:55 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 29 Nov 2021 00:36:55 -0800 (PST)
In-Reply-To: <sntmjc$gh9$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=78.131.56.82; posting-account=5cIhGQgAAAD51vWxObfbr2Fz1M5rcgWL
NNTP-Posting-Host: 78.131.56.82
References: <snhi1g$tip$1@dont-email.me> <14ca7deb-7740-4fe2-b141-3cfb0586d7f9n@googlegroups.com>
<snr7mt$pum$1@dont-email.me> <6adaa63b-d2a2-4413-9238-755e682a98e5n@googlegroups.com>
<sntmjc$gh9$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <88b4230b-7359-4c54-965e-98d0cfee92cdn@googlegroups.com>
Subject: Re: Suggested exercise in Forth
From: pah...@gmail.com (pahihu)
Injection-Date: Mon, 29 Nov 2021 08:36:55 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 67
 by: pahihu - Mon, 29 Nov 2021 08:36 UTC

Hi,

I was able to reduce to required precision to 4 decimal places using the
fact that an octave step is multiply/divide with 2 and a half octave step
is multiply/divide with sqrt(2). The code always rounds the halftones in
such a way that max. 3 multiply/divide step is necessary to reach the
target frequency.

pahihu

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 constant C
2 constant D
4 constant E
5 constant F
7 constant G
9 constant A
11 constant B

: '# ( n1 -- n2 ) 1+ ;
: 'b ( n1 -- n2 ) 1- ;

: tone ( #halftones #octave -- #halftones ) 12 * + ;

A 4 tone constant A4
44000 constant freqA4
18904 17843 2constant halftone \ d 4.117e-10
27720 19601 2constant sqrt2 \ d 1.840e-09

false value divide?
: /octave ( #octave -- freq )
\ Divide/multiply f(A4) by 2 (an octave).
freqA4 swap
divide? IF rshift
ELSE lshift
THEN ;

: roundTones ( #halftones -- #notes sqrt2 #octaves )
\ Multiply/divide max. 3 times only. Round to the nearest
\ half octave.
6 /mod ( rem quo)
>R
dup 3 > IF 6 - R> 1+ >R THEN
R> 2 /mod ;

: scaled ( #halftones -- freq )
\ Scale frequency of A4 with given number of seminotes.
roundTones /octave
100 * \ 4 decimal places
swap IF
sqrt2 divide? IF swap THEN */ \ scale with sqrt(2)
THEN
swap dup 0< IF
negate divide? 0= to divide? \ change direction
THEN
0 ?DO
halftone divide? IF swap THEN */
LOOP
50 + 100 / ; \ round the result

: freq? ( #halftones -- freq )
\ Convert numeric tone to frequency.
A4 -
dup 0< IF negate true to divide?
ELSE false to divide?
THEN
scaled ;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Re: Suggested exercise in Forth

<87lf17i7kc.fsf@nightsong.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15374&group=comp.lang.forth#15374

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: no.em...@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.forth
Subject: Re: Suggested exercise in Forth
Date: Mon, 29 Nov 2021 02:23:47 -0800
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <87lf17i7kc.fsf@nightsong.com>
References: <snhi1g$tip$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="12f1b84400539defdeac8314ad866276";
logging-data="9109"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18wPF2XQqDdtTOx/fRJUeRn"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:ja6hnfR+by4AmxlD7IuEsLtaj8s=
sha1:uos5vMdSc+fCgAbj4K03LcLlyXQ=
 by: Paul Rubin - Mon, 29 Nov 2021 10:23 UTC

Krishna Myneni <krishna.myneni@ccreweb.org> writes:
> I think the following problem might make for a useful exercise in
> Forth coding.

It's Forth, redefine the problem and ignore half of it.
================================================================

FVARIABLE pitch
2e 1e 12e F/ F** FCONSTANT semitone \ 2**(1/12)

\ C4 = 9 semitones below A4 = 261.625 hz
440e semitone 9e f** f/ FCONSTANT c4

: nextf ( -- f ) pitch F@ FDUP semitone F* pitch F! ;

: note.1 ( f "name" -- ) CREATE f,
DOES> ( octave:n a -- pitch:f )
>R 4 - S>F 2e FSWAP F** R> F@ f* ;
: note ( "name" ) nextf note.1 ;

c4 pitch f! \ start scale at c4

note c note c# note d note d# note e note f
note f# note g note g# note a note a# note b

\ 3 f# f. \ prints 184.997211355817

Re: Suggested exercise in Forth

<6539059c-177a-4e61-a43a-3271acfbf194n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15386&group=comp.lang.forth#15386

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:75a:: with SMTP id i26mr39959753qki.179.1638207089956;
Mon, 29 Nov 2021 09:31:29 -0800 (PST)
X-Received: by 2002:ad4:5aeb:: with SMTP id c11mr32691628qvh.69.1638207089424;
Mon, 29 Nov 2021 09:31:29 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 29 Nov 2021 09:31:29 -0800 (PST)
In-Reply-To: <7779c277-2aef-4821-ae54-4add0e63c2efn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:3f7a:20d0:d5d9:92e2:f1d4:87d5;
posting-account=V5nGoQoAAAC_P2U0qnxm2kC0s1jNJXJa
NNTP-Posting-Host: 2600:1700:3f7a:20d0:d5d9:92e2:f1d4:87d5
References: <snhi1g$tip$1@dont-email.me> <snurbg$1njh$1@gioia.aioe.org>
<47a5adf7-936e-42b1-a401-638052da5c43n@googlegroups.com> <2f38d521-a41b-4027-afd5-58bde2921f40n@googlegroups.com>
<7779c277-2aef-4821-ae54-4add0e63c2efn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6539059c-177a-4e61-a43a-3271acfbf194n@googlegroups.com>
Subject: Re: Suggested exercise in Forth
From: sdwjac...@gmail.com (S Jack)
Injection-Date: Mon, 29 Nov 2021 17:31:29 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 74
 by: S Jack - Mon, 29 Nov 2021 17:31 UTC

Replaced the 12th root of 2 with ratio of two adjacent pitch frequencies
in the frequency to note (PITCH) calculation. Gets same result but the
routine is simplified some.

Pitch

58 tblFREQ [] CONST F1
57 tblFREQ [] CONST F2 \ F1/F2 = 12th root of 2

: pitch ( f -- s )
44000 over -
dup 0= if ( f = FA ) 2DROP "A4" EXIT fi
0> if ( f < FA )
58 swap >R
44,000
BEGIN R OVER
< WHILE
F2 F1 */
OVER WHILE
SWAP 1- SWAP
REPEAT ." OOPS#1" fi
RDROP DROP
ii ( f > FA )
58 SWAP >R
44,000
BEGIN R OVER
> while
F1 F2 */
OVER 109 < WHILE
SWAP 1+ SWAP
REPEAT ." OPPS2" fi
RDROP DROP
fi
note
;

\ cr ul( "Frequency (hz) vs. Pitch" 40 s.c )
\ cr tab ul( .( Half-step)) tab ul( .( Frequency)) tab ul( .( Pitch))
\ { 109 1 do cr tab i 3 u.r tab i tblFREQ [] dup 2 3 un.r pitch tab tell loop }
\ run1

Frequency (hz) vs. Pitch
Half-step Frequency Pitch
1 16.35 C0
2 17.32 C#0
3 18.35 D0
4 19.45 D#0
5 20.60 E0
6 21.83 F0
7 23.12 F#0
8 24.50 G0
9 25.96 G#0
10 27.50 A0
11 29.14 A#0
12 30.87 B0
13 32.70 C1
...
97 4,186.01 C8
98 4,434.92 C#8
99 4,698.63 D8
100 4,978.03 D#8
101 5,274.04 E8
102 5,587.65 F8
103 5,919.91 F#8
104 6,271.93 G8
105 6,644.88 G#8
106 7,040.00 A8
107 7,458.62 A#8
108 7,902.13 B8

-fin-
ok
--
me

Re: Suggested exercise in Forth

<cbb287c5-57ae-4d02-8cb9-d409d3010847n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15387&group=comp.lang.forth#15387

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:5f47:: with SMTP id y7mr44996087qta.342.1638212093570;
Mon, 29 Nov 2021 10:54:53 -0800 (PST)
X-Received: by 2002:a05:620a:13f9:: with SMTP id h25mr41084366qkl.99.1638212093374;
Mon, 29 Nov 2021 10:54:53 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 29 Nov 2021 10:54:53 -0800 (PST)
In-Reply-To: <6539059c-177a-4e61-a43a-3271acfbf194n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:3f7a:20d0:d5d9:92e2:f1d4:87d5;
posting-account=V5nGoQoAAAC_P2U0qnxm2kC0s1jNJXJa
NNTP-Posting-Host: 2600:1700:3f7a:20d0:d5d9:92e2:f1d4:87d5
References: <snhi1g$tip$1@dont-email.me> <snurbg$1njh$1@gioia.aioe.org>
<47a5adf7-936e-42b1-a401-638052da5c43n@googlegroups.com> <2f38d521-a41b-4027-afd5-58bde2921f40n@googlegroups.com>
<7779c277-2aef-4821-ae54-4add0e63c2efn@googlegroups.com> <6539059c-177a-4e61-a43a-3271acfbf194n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <cbb287c5-57ae-4d02-8cb9-d409d3010847n@googlegroups.com>
Subject: Re: Suggested exercise in Forth
From: sdwjac...@gmail.com (S Jack)
Injection-Date: Mon, 29 Nov 2021 18:54:53 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 26
 by: S Jack - Mon, 29 Nov 2021 18:54 UTC

PITCH frogafied:

58 tblFREQ [] CONST F1
57 tblFREQ [] CONST F2 \ F1/F2 = 12th root of 2

: PITCH ( f -- s )
44000 OVER -
DUP 0= IF ( f = FA ) 2DROP "A4" EXIT FI
0> IF ( f < FA )
F2 F1 ' < ' 1- SP@ SET \ $4=f $3=F2 $2=F1 $1=xt(<) $0=xt(1-)
ii ( f > FA )
F1 F2 ' > ' 1+ SP@ SET \ $4=f $3=F1 $2=F2 $1=xt(>) $0=xt(1+)
fi
58 \ A4 half-step
44,000 \ A4 frequency
BEGIN $4 OVER
$1 EXECUTE WHILE
$3 $2 */
OVER WHILE
SWAP $0 EXECUTE SWAP
REPEAT ." OOPS" FI
DROP ( $4 $3 $2 $1 $0 hs )
NOTE &4 ! ( s $3 $2 $1 $0 )
4DROP ( s )
;
--
me

Re: Suggested exercise in Forth

<so6ksa$75o$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15404&group=comp.lang.forth#15404

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Suggested exercise in Forth
Date: Tue, 30 Nov 2021 19:58:34 -0600
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <so6ksa$75o$1@dont-email.me>
References: <snhi1g$tip$1@dont-email.me>
<14ca7deb-7740-4fe2-b141-3cfb0586d7f9n@googlegroups.com>
<snr7mt$pum$1@dont-email.me>
<6adaa63b-d2a2-4413-9238-755e682a98e5n@googlegroups.com>
<sntmjc$gh9$1@dont-email.me>
<88b4230b-7359-4c54-965e-98d0cfee92cdn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 1 Dec 2021 01:58:34 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="519b4b801ea1c6db626588b195e7cf42";
logging-data="7352"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/yb0vSoqhq0Lrz0T13gQdK"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.1.0
Cancel-Lock: sha1:Z2poUfcdPMVzrAxHRZ+T4/6upLc=
In-Reply-To: <88b4230b-7359-4c54-965e-98d0cfee92cdn@googlegroups.com>
Content-Language: en-US
 by: Krishna Myneni - Wed, 1 Dec 2021 01:58 UTC

On 11/29/21 02:36, pahihu wrote:
> Hi,
>
> I was able to reduce to required precision to 4 decimal places using the
> fact that an octave step is multiply/divide with 2 and a half octave step
> is multiply/divide with sqrt(2). ...

Do you mean you *increased* the precision of the frequency result to 4
decimal places? I didn't see an example, but that's what I'm assuming
you mean. That's a nice result.

Krishna

Re: Suggested exercise in Forth

<so6lcg$aid$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15405&group=comp.lang.forth#15405

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Suggested exercise in Forth
Date: Tue, 30 Nov 2021 20:07:10 -0600
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <so6lcg$aid$1@dont-email.me>
References: <snhi1g$tip$1@dont-email.me> <snurbg$1njh$1@gioia.aioe.org>
<47a5adf7-936e-42b1-a401-638052da5c43n@googlegroups.com>
<2f38d521-a41b-4027-afd5-58bde2921f40n@googlegroups.com>
<7779c277-2aef-4821-ae54-4add0e63c2efn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 1 Dec 2021 02:07:12 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="519b4b801ea1c6db626588b195e7cf42";
logging-data="10829"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+yj4bkA9UX4KOVsxyjoqfd"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.1.0
Cancel-Lock: sha1:zLIbe0RbIMWcNIfhDlR5ARKGiBw=
In-Reply-To: <7779c277-2aef-4821-ae54-4add0e63c2efn@googlegroups.com>
Content-Language: en-US
 by: Krishna Myneni - Wed, 1 Dec 2021 02:07 UTC

On 11/28/21 22:54, S Jack wrote:
>
>
> 1,059,463,1 CONST F0 \ 12th root of 2 (approx) x 10,000,000
>
> -- half-step (hs) to frequency (hz)
> : FREQ ( hs -- hz )
> 58 -
> DUP 0= IF DROP 44000
> EXIT FI
> DUP 0> IF 440,000,0 SWAP 0 ?DO F0 1,000,000 */ 5 + 10 / LOOP
> 50 + 100 /
> EXIT FI
> ABS 440,000,000 SWAP 0 DO 10,000,000 F0 */ LOOP
> 5,000 + 10,000 /
> ;
>

The word FREQ is a nice factor for reuse -- converting number of
half-steps from A4 to a scaled frequency in units of 0.01 Hz. I suggest
that this word is amenable to factoring. Some of the scaling and
rounding arithmetic should be factorable to make FREQ more readily
understandable. You may also want to define some constants, e.g. the
scaled frequency of A4, and the half-step number of A4, to make the code
even more apparent.

Congrats on your working code.

Krishna

Re: Suggested exercise in Forth

<so6lq7$ci2$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15406&group=comp.lang.forth#15406

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Suggested exercise in Forth
Date: Tue, 30 Nov 2021 20:14:29 -0600
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <so6lq7$ci2$1@dont-email.me>
References: <snhi1g$tip$1@dont-email.me> <87lf17i7kc.fsf@nightsong.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 1 Dec 2021 02:14:31 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="519b4b801ea1c6db626588b195e7cf42";
logging-data="12866"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18miNXzV5aXQ9uqWv55jkzu"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.1.0
Cancel-Lock: sha1:OFdvtSrdHMbPBWI5YIv8nLliPk8=
In-Reply-To: <87lf17i7kc.fsf@nightsong.com>
Content-Language: en-US
 by: Krishna Myneni - Wed, 1 Dec 2021 02:14 UTC

On 11/29/21 04:23, Paul Rubin wrote:
> Krishna Myneni <krishna.myneni@ccreweb.org> writes:
>> I think the following problem might make for a useful exercise in
>> Forth coding.
>
> It's Forth, redefine the problem and ignore half of it.
> ================================================================
>
> FVARIABLE pitch
> 2e 1e 12e F/ F** FCONSTANT semitone \ 2**(1/12)
>
> \ C4 = 9 semitones below A4 = 261.625 hz
> 440e semitone 9e f** f/ FCONSTANT c4
>
> : nextf ( -- f ) pitch F@ FDUP semitone F* pitch F! ;
>
> : note.1 ( f "name" -- ) CREATE f,
> DOES> ( octave:n a -- pitch:f )
> >R 4 - S>F 2e FSWAP F** R> F@ f* ;
> : note ( "name" ) nextf note.1 ;
>
> c4 pitch f! \ start scale at c4
>
> note c note c# note d note d# note e note f
> note f# note g note g# note a note a# note b
>
> \ 3 f# f. \ prints 184.997211355817
>

This is a nice approach to converting from the note to a frequency --
getting the Forth interpreter to handle all of the string processing for
free, with just a little reformat of the input. You are not supplying an
output to two decimal places, which of course is trivial to do with
standard floating point.

One suggestion I would make is that the lowest factor returns the number
of semitones instead of the frequency. This is a useful factor for both
computing the frequency and other quantities that are important in music
theory. For example, if you had implemented the second half as well, you
could write a trivially simple word to display the Circle of Fifths:

https://en.wikipedia.org/wiki/Circle_of_fifths

Krishna

Re: Suggested exercise in Forth

<6b0a0982-2b63-410e-b42a-d17ac65f73afn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15407&group=comp.lang.forth#15407

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:5ad1:: with SMTP id d17mr5094437qtd.23.1638349998682;
Wed, 01 Dec 2021 01:13:18 -0800 (PST)
X-Received: by 2002:a05:620a:2f9:: with SMTP id a25mr4475206qko.327.1638349998467;
Wed, 01 Dec 2021 01:13:18 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Wed, 1 Dec 2021 01:13:18 -0800 (PST)
In-Reply-To: <so6ksa$75o$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=78.131.56.82; posting-account=5cIhGQgAAAD51vWxObfbr2Fz1M5rcgWL
NNTP-Posting-Host: 78.131.56.82
References: <snhi1g$tip$1@dont-email.me> <14ca7deb-7740-4fe2-b141-3cfb0586d7f9n@googlegroups.com>
<snr7mt$pum$1@dont-email.me> <6adaa63b-d2a2-4413-9238-755e682a98e5n@googlegroups.com>
<sntmjc$gh9$1@dont-email.me> <88b4230b-7359-4c54-965e-98d0cfee92cdn@googlegroups.com>
<so6ksa$75o$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6b0a0982-2b63-410e-b42a-d17ac65f73afn@googlegroups.com>
Subject: Re: Suggested exercise in Forth
From: pah...@gmail.com (pahihu)
Injection-Date: Wed, 01 Dec 2021 09:13:18 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 10
 by: pahihu - Wed, 1 Dec 2021 09:13 UTC

Krishna Myneni ezt írta (2021. december 1., szerda, 2:58:37 UTC+1):
> Do you mean you *increased* the precision of the frequency result to 4
> decimal places? I didn't see an example, but that's what I'm assuming
> you mean.

Hi,

Yes, I meant that the original calculation increased the precision to 5
decimal places, hence the reduction to 4.

pahihu


devel / comp.lang.forth / Re: Suggested exercise in Forth

Pages:12
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor