home .. forth .. colorforth mail list archive ..

RE: [colorforth] Machineforth IFs


On Tue, 4 Feb 2003, [iso-8859-1] Fréderic DUBOIS wrote:

> Thanks for the explaination. A kind of inline jumptable.
> It seems that the idea is to replace IFs by arithmetic computation. And this
> is possible to me if the "objects" we are processing and the operators on it
> form an algebra (or maybe something even lesser - a ring?).

In a sense they do. The set of objects in this case are the integers
modulo 2^32, with the addition and multilpication operators they form a
commutative ring. 'jump' and 'if' don't seem to fit in the algebra because
they are not purely operations on the set but effect the flow of control.
Still it is useful think of the algebraic properties in the computation.
In the colorForth kernel there is a good example. Chuck has a memory
location which can assume two value, and there is a toggle function
to switch between the two values. Call the location X, and the two values
A and B. One can imagine someone toggling the values using a conditional
of this form:

if [X] = A then X <- B else X <- A

Instead Chuck cleverly uses a property of exclusive or, and does:

X <- [X] xor A xor B

hence he eliminates a conditional that might be present in less thoughtful
code.

Footnote:

[] means fetch the contents of a location
<- means store to a location

> On c.l.f someone posted a link to an article dealing with linear
> programming; I was amazed to see that with it's pragmatic philosophy Forth
> meets some important mathematical properties (there's also the laws of form
> - but I don't understand at all what it deals with :).

I think you refer to this document:

http://home.pipeline.com/~hbaker1/ForthStack.html

This also inrigued my interest, I'd like to learn more about this linear
logic when I get a chance.

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com