Discussion:
NEW ARTICLE: From infix notation to postfix notation
(too old to reply)
Marc Petremann
2022-10-20 20:45:37 UTC
Permalink
Handling complex arithmetic formulas can become a source of errors in FORTH. Here, we will define the way to handle large formulas in infix notation and compile them in postfix notation.

https://esp32.arduino-forth.com/article/tools_infixToPostfix
Paul Rubin
2022-10-21 01:10:50 UTC
Permalink
Post by Marc Petremann
Handling complex arithmetic formulas can become a source of errors in
FORTH. Here, we will define the way to handle large formulas in infix
notation and compile them in postfix notation.
Does your Forth have local variables? That helps a lot. I think people
who want infix aren't likely to use Forth in the first place.
none) (albert
2022-10-21 10:18:23 UTC
Permalink
Post by Paul Rubin
Post by Marc Petremann
Handling complex arithmetic formulas can become a source of errors in
FORTH. Here, we will define the way to handle large formulas in infix
notation and compile them in postfix notation.
Does your Forth have local variables? That helps a lot. I think people
who want infix aren't likely to use Forth in the first place.
Prof Noble was right. There is great merit in being able to copy
checking complex formulae from textbooks verbatim.
Probably most notable in a practical technical environment.

Groetjes
--
"in our communism country Viet Nam, people are forced to be
alive and in the western country like US, people are free to
die from Covid 19 lol" duc ha
***@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
dxforth
2022-10-22 01:58:20 UTC
Permalink
Post by none) (albert
Post by Paul Rubin
Post by Marc Petremann
Handling complex arithmetic formulas can become a source of errors in
FORTH. Here, we will define the way to handle large formulas in infix
notation and compile them in postfix notation.
Does your Forth have local variables? That helps a lot. I think people
who want infix aren't likely to use Forth in the first place.
Prof Noble was right. There is great merit in being able to copy
checking complex formulae from textbooks verbatim.
Probably most notable in a practical technical environment.
Paul is right. FTRAN is no path to Forth acceptance. Was FTRAN a neat
application that caught a number of forthers' imagination? It would
appear so. Still, the number of apps requiring users to plug in arbitrary
textbook formula strikes me as extremely low to the point of 'who cares
whether forth can do that'.

BTW what is "practical technical environment"? We've had Wayne's "real
practical imagination". Perhaps there needs to be a trading halt on
the use of the word "practical" before it loses all meaning :)
Hans Bezemer
2022-10-24 07:47:03 UTC
Permalink
Post by none) (albert
Prof Noble was right. There is great merit in being able to copy
checking complex formulae from textbooks verbatim.
Probably most notable in a practical technical environment.
There certainly is. 4tH supports such expansion in its preprocessor, using
the LET command.

When I tried to convert the famous "batman" equation into 4tH, it most
certainly was helpful, since they are *godawful*!

What can I say - it worked ;-)
https://sourceforge.net/p/forth-4th/code/HEAD/tree/trunk/4th.src/4pp/gbatman.4pp

I wish I'd had such functionality when coding the 'teonw' program. All those formulas
had to be handcoded.
https://sourceforge.net/p/forth-4th/code/HEAD/tree/trunk/4th.src/4pp/teonw.4pp

Hans Bezemer
Marcel Hendrix
2022-10-24 17:35:37 UTC
Permalink
Post by Hans Bezemer
Post by none) (albert
Prof Noble was right. There is great merit in being able to copy
checking complex formulae from textbooks verbatim.
Probably most notable in a practical technical environment.
There certainly is. 4tH supports such expansion in its preprocessor, using
the LET command.
When I tried to convert the famous "batman" equation into 4tH, it most
certainly was helpful, since they are *godawful*!
What can I say - it worked ;-)
https://sourceforge.net/p/forth-4th/code/HEAD/tree/trunk/4th.src/4pp/gbatman.4pp
I wish I'd had such functionality when coding the 'teonw' program. All those formulas
had to be handcoded.
https://sourceforge.net/p/forth-4th/code/HEAD/tree/trunk/4th.src/4pp/teonw.4pp
Hans Bezemer
I need some motivation: what does 'batman' actually do?

-marcel
dxforth
2022-10-25 03:08:49 UTC
Permalink
Post by Marcel Hendrix
Post by Hans Bezemer
Post by none) (albert
Prof Noble was right. There is great merit in being able to copy
checking complex formulae from textbooks verbatim.
Probably most notable in a practical technical environment.
There certainly is. 4tH supports such expansion in its preprocessor, using
the LET command.
When I tried to convert the famous "batman" equation into 4tH, it most
certainly was helpful, since they are *godawful*!
What can I say - it worked ;-)
https://sourceforge.net/p/forth-4th/code/HEAD/tree/trunk/4th.src/4pp/gbatman.4pp
I wish I'd had such functionality when coding the 'teonw' program. All those formulas
had to be handcoded.
https://sourceforge.net/p/forth-4th/code/HEAD/tree/trunk/4th.src/4pp/teonw.4pp
Hans Bezemer
I need some motivation: what does 'batman' actually do?
Given an entire f/p application could theoretically be written in infix, where
to draw the line - if at all? That's a question for the forth scientific users.
For me, f/p apps tend to be as rare as hens' teeth so the issue never arises.
Hans Bezemer
2022-10-25 21:28:07 UTC
Permalink
Post by Marcel Hendrix
I need some motivation: what does 'batman' actually do?
It's a set of equations that plot the "batman" logo. Google "batman equation"
and a lot of links will pop up.

Hans Bezemer
Paul Rubin
2022-10-25 21:49:58 UTC
Permalink
Post by Hans Bezemer
It's a set of equations that plot the "batman" logo. Google "batman equation"
and a lot of links will pop up.
Heh cute. This one is informative: https://math.stackexchange.com/q/54506
dxforth
2022-10-26 01:16:03 UTC
Permalink
Post by Paul Rubin
Post by Hans Bezemer
It's a set of equations that plot the "batman" logo. Google "batman equation"
and a lot of links will pop up.
Heh cute. This one is informative: https://math.stackexchange.com/q/54506
One for the mathematicians...

\ This version translated to DX-Forth
\
\ FORTH-F.EXE - INCLUDE WEED BYE
\
\ -----------------------------------------------
\ Originally programmed in XPL0 by ...
\
\ http://www.idcomm.com/personal/lorenblaney/
\
\ Weed.xpl 15-Jan-2009
\ Plots the "Weed" function

empty forth definitions decimal
application

1 fload XPLGRAPH \ XPL0 graphics

100.e fconstant S \ size of plotted image (scale factor)
32000.e fconstant N \ number of points plotted
3.14159265e 2.e f* fconstant 2Pi
0 value X \ graphic coordinates (pixels)
0 value Y

: Main ( -- )
$12 SetVid \ set 640x480 graphics with 16 colors
0.0e ( Angle) \ for A:= 0 to Pi2 do...
begin
fdup ( A) fsin 1.e f+
fover ( A) 8.e f* fcos 0.9e f* 1.e f+ f*
fover ( A) 24.e f* fcos 0.1e f* 1.e f+ f*
fover ( A) 200.e f* fcos 0.05e f* 0.9e f+ f* ( Distance)
fover ( A) fcos fover ( D) f* S f* f>s to X \ polar to rect
fover ( A) fsin f* S f* f>s to Y
320 X + 400 Y - 2 ( green) Point
( A) 2Pi N f/ f+ fdup 2Pi f< not
until ( A) fdrop
key drop \ wait for keystroke
$03 SetVid \ restore normal text mode
;

cr .( Save to disk? ) y/n
[if] turnkey Main WEED [then]
Hans Bezemer
2022-10-27 17:13:41 UTC
Permalink
Post by dxforth
One for the mathematicians...
.. and the 4tH version. This one fills it up as well. Nice code, easy to port:

\ This version translated to DX-Forth

\ FORTH-F.EXE - INCLUDE WEED BYE

\ -----------------------------------------------
\ Originally programmed in XPL0 by ...

\ http://www.idcomm.com/personal/lorenblaney/

\ Weed.xpl 15-Jan-2009
\ Plots the "Weed" function

[PRAGMA] usestackflood

include lib/fp3.4th \ for floating point
include lib/fsinfcos.4th \ for FSIN
include lib/graphics.4th \ for graphics support
include lib/gflood.4th \ for FLOOD
include 4pp/lib/float.4pp \ since we're using the preprocessor..


f% 100 fconstant S \ size of plotted image (scale factor)
f% 32000 fconstant N \ number of points plotted
pi fdup f+ fconstant 2Pi
0 value X \ graphic coordinates (pixels)
0 value Y

: Main ( -- )
640 pic_width ! 480 pic_height ! \ set canvas size
color_image 255 whiteout black \ paint black on white
." WAIT! - it will get there.." cr \ set 640x480 graphics with 16 colors

f% 0 ( Angle) \ for A:= 0 to Pi2 do...

begin
fdup ( A) fsin f% 1 f+
fover ( A) f% 8 f* fcos f% 0.9e f* f% 1 f+ f*
fover ( A) f% 24 f* fcos f% 0.1e f* f% 1 f+ f*
fover ( A) f% 200 f* fcos f% 0.05e f* f% 0.9e f+ f* ( Distance)
fover ( A) fcos fover ( D) f* S f* f>s to X \ polar to rect
fover ( A) fsin f* S f* f>s to Y
320 X + 400 Y - swap set_pixel
( A) 2Pi N f/ f+ fdup 2Pi f< 0=
until ( A) fdrop
;

Main
green 200 320 flood
s" weed.ppm" save_image \ save the image
dxforth
2022-10-27 21:03:54 UTC
Permalink
Post by dxforth
One for the mathematicians...
BTW the original XPL0 code is now here:

https://web.archive.org/web/20220403073604/http://www.xpl0.org/guess.html

Don't know why author suggested it was 'for the mathematically inclined'.
Perhaps they have an affinity for it :)

Marc Petremann
2022-10-21 14:35:24 UTC
Permalink
Does your Forth have local variables? That helps a lot. I think people
who want infix aren't likely to use Forth in the first place.
ESP32forth uses local variables.
I didn't want to use them for my examples, because when decompiling, we no longer see the names of the variables.
Loading...