Search the web
Sign In
New User? Sign Up
concatenative · Discuss the concatenative variety of computer languages: Joy, Forth, Postscript
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Concatenative macros?   Message List  
Reply | Forward Message #3194 of 4643 |
Re: Concatenative macros?

Billy and all,

Sorry for taking so long to respond to this. When I first read your
email, the server hosting Chris Okasaki's paper was apparently down.
And then for a couple weeks I forgot to come back and try it again. I
must say -- What he's accomplished is pretty cool.

> My question is: how does Okasaki's and Barker's work apply to this?
> Okay, actually, what I want to know is how to design a flat,
> two-combinator, concatenative language that's implemented using
stacks
> and lists (like Joy).

I want to respond to your second question first; hopefully this will
in turn shed some light on the relationship between flat
concatenative systems and Okasaki's and Barker's work.

When I wrote that flaky old program that searches for optimal Joy
constructions, I put in an option to search only for flat
constructions (activated by uncommenting the line "//#define
NOQUOTES" :-) ) but never really pursued the problem, although I
agree it is an interesting one.

Let's try this. We're looking for a finite set of combinators from
which we can construct any combinator by concatenation alone (no
quotations). We'll say that such a set of combinators forms complete
flat basis. To start, we observe that if "z" is any combinator
forming a complete (non-flat) basis (for example, z == X\ zap [cake]
[k] X, as we've seen), then {[], [z], unit, cat, i} forms a complete
flat basis. Any concatenative combination of "z" can be decomposed
into a flat one in terms of these combinators quite easily; For
example,

[z [z z] z]
== [z] [[z z] z] cat
== [z] [[z z]] [z] cat cat
== [z] [z z] unit [z] cat cat
== [z] [z] [z] cat unit [z] cat cat

If the expression had contained a dequoted 'z', then we would have
needed to use '[z] i' (or, if desired, we could have included 'z' in
the basis instead of i); and if the expression had contained a null
quotation, we would have had to use []. In this way, we can decompose
any concatenative combination of "z", and hence any combinator
whatsoever, into a flat expression in terms of {[], [z], unit, cat,
i}.

Now, we can do better than that. You really want a basis in terms of
just two combinators (not five). So let's think about what would have
to be true about such a basis:

1. One of the two combinators must be able to execute on an empty
stack; therefore it must do nothing but push a sequence of constant
quotations onto the stack (This will necessarily be an improper
combinator).

2. The other combinator must be a total dequoter, such as 'i' or 'k'
(otherwise, roughly speaking, it's impossible to get down to an empty
stack again once anything has been pushed onto it).

It might be possible to relax the first requirement if our system has
a "bottomless stack", i.e., if we can assume infinitely many stack
items are always available if needed, so that "[] dip" is considered
equivalent to the empty program (analagous to the beta-eta-theory of
classical combinatory logic, as opposed to the beta-theory). In any
case, this won't be necessary, because it turns out there is a
solution satisfying both requirements.

Also, intuitively, the empty quotation [] must be embedded somehow in
the first combinator. My first attempts at a two-combinator flat
basis were {[] [z], i}, {[z] [], i}, {[] [cake] [k], i}, {[cake] [k]
[], i}, and so forth, before realizing that these are all doomed
because it is impossible to construct "cat" from them. But I'll skip
over my failed attempts and cut straight to one that works. To do
this, first define a new combinator "q":

[B] [A] q == [[B]] [A B]

This combinator, along with k, forms a complete basis (in the
ordinary, non-flat sense). This is interesting in itself, since "q"
is a bit simpler than "cake" ({cake, k} formerly being the simplest
known basis of two proper combinators). But, as you've mentioned,
Billy, it's not exactly clear how to count the size of a combinator.
In my search program, I've counted it as the total number of atoms
plus the number of quotations (so "q" would be size 6, 3 atoms plus 3
quotations, while "cake" would be size 8, 4 atoms plus 4 quotations);
but other schemes may be equally valid.

Anyhow, here are the essential constructions from {q,k}:

zap == [] k
i == [] q k
unit == [] q zap
swat == q unit k (where swat == X\ Y\ [X Y] == swap cat)
dip == unit [unit] swat i swat i
dup == [] q unit swat i

I'll give the verification of "dip", the most interesting of these:

[Y] [X] unit [unit] swat i swat i
== [Y] [[X]] [unit] swat i swat i
== [Y] [unit [X]] i swat i
== [Y] unit [X] swat i
== [[Y]] [X] swat i
== [X [Y]] i
== X [Y]

It's worth noting that

swat i == X\ Y\ X Y == dip i

This combinator simply executes the top two programs on the stack. It
may be constructed simply as "q k". Using this makes the above
constructions of "dip" and "dup" much more efficient (In fact, a
computer search shows that they are then minimal, in terms of their
size as combinations of the original base combinators "q" and "k").

Also, notice that the constructions of unit and swat (as well as zap,
i, and dup) are flat in terms of [], q, and k. This will be useful to
us in a moment. But I want to emphasize that I'm not claiming that
{q, k} is a complete flat basis, because it certainly isn't. However,
{q, k} is complete in the ordinary sense, and will be useful in
building a flat basis:

All right, so for a two-combinator basis, define:

o == [] [q] [k]

Then {o,i} is a complete flat basis. To prove this, we just need to
show how to construct each combinator in {[], [q], [k], swat, unit},
because this set, along with "i", clearly forms a complete flat
basis, applying with minor adjustment the simple algorithm
illustrated above for {[], [z], cat, unit, i}, noticing that "swat"
will do just as well as "cat".

So here we go. First, as an auxiliary step, we find that

oi == q

and

ooooqiiiiii == [][k]

(We might as well dispense with unnecessary spaces). Here's the
verification:

oi
== [][q][k]i
== [][q]k
== q

ooooqiiiiii
== ooo[][q][k]qiiiiii
== ooo[][[q]][kq]iiiiii
== ooo[][[q]]kqiiiii
== ooo[q]qiiiii
== oo[][q][k][q]qiiiii
== oo[][q][[k]][qk]iiiii
== oo[][q][[k]]qkiiii
== oo[][[q]][[k]q]kiiii
== oo[][k]qiiii
== oo[[]][k[]]iiii
== oo[[]]k[]iiii
== oo[[]]kiii
== o[][q][k][[]]kiii
== o[][q][]iii
== o[][q]ii
== o[]qi
== [][q][k][]qi
== [][q][[k]][k]i
== [][q][[k]]k
== [][k]

From this we can get zap:

zap == [][k] i

The verification:

[A][][k]i
== [A][]k
==

Now we can construct []:

[] == [][k] zap

This was one of the five we wanted. So, one down, four to go.
Actually, we're done with most of the hard work. Next construct [k]:

[k] == [][k] [] q i

The verification:

[][k][]qi
== [][[k]][k]i
== [][[k]]k
== [k]

Now take advantage of our original flat constructions of "unit"
and "swat":

unit == [] q zap
swat == q unit k

Now it remains only to construct [q]. (Note we already
constructed "q" at the very beginning, but in a flat system, this is
not enough.):

[q] == o zap unit k

The verification:

o zap unit k
== [][q][k] zap unit k
== [] [q] unit k
== [] [[q]] k
== [q]

So there we have it! We can write all this explicitly as

[] == oooooiiiiiiioooooiiiiiiii
[k] == oooooiiiiiiioooooiiiiiiioooooiiiiiiiioii
unit == oooooiiiiiiioooooiiiiiiiioioooooiiiiiiii
swat ==
oioooooiiiiiiioooooiiiiiiiioioooooiiiiiiiioooooiiiiiiioooooiiiiiiioooo
oiiiiiiiioiii
[q] ==
ooooooiiiiiiiioooooiiiiiiioooooiiiiiiiioioooooiiiiiiiioooooiiiiiiioooo
oiiiiiiioooooiiiiiiiioiii

Of course, these constructions could probably be improved; my poor
little Joy searcher (among other restrictions) only works on a basis
of proper combinators, which does not apply in this case. So I'm not
able to determine what the minimal constructions might be. Also, it
is certainly possible that a more clever choice of basis could lead
to smaller constructions.

- Brent





Tue Feb 6, 2007 5:39 am

iepos
Offline Offline
Send Email Send Email

Forward
Message #3194 of 4643 |
Expand Messages Author Sort by Date

Sorry; I said in my last post that I had one more question, and then I forgot to ask it. My question is: how does Okasaki's and Barker's work apply to this? ...
William Tanksley, Jr
wtanksle
Offline Send Email
Jan 19, 2007
6:33 pm

Billy and all, Sorry for taking so long to respond to this. When I first read your email, the server hosting Chris Okasaki's paper was apparently down. And...
iepos
Offline Send Email
Feb 6, 2007
5:41 am

... I agree -- and it was both instructive and reasonably fun to read. ... Indeed it did! I especially appreciate you including your reasoning. Not only do I...
William Tanksley, Jr
wtanksle
Offline Send Email
Feb 6, 2007
7:20 pm

... i thought it might be subliminal tribute to o[kasak]i....
sa@...
Send Email
Feb 6, 2007
7:53 pm

... From: "William Tanksley, Jr" <wtanksleyjr@...> ... i think this should be 00101 0011 1 1 = [] q k k i've posted an interpreter for 01 at: ...
stevan apter
sa@...
Send Email
Feb 8, 2007
11:15 pm

... [A] [] q k k = [[A]] [A] k k = A k Too many k's. What might be messing things up is how you treat the [A B] term in the result of 'q'. In this quotation,...
William Tanksley, Jr
wtanksle
Offline Send Email
Feb 9, 2007
5:02 am

... From: "William Tanksley, Jr" <wtanksleyjr@...> To: <concatenative@yahoogroups.com> Sent: Thursday, February 08, 2007 11:54 PM Subject: Re: [stack]...
stevan apter
sa@...
Send Email
Feb 9, 2007
12:54 pm

... This is one of the things that confuses me about this notation -- but it's something you have to learn. The reason it's confusing to us is that it's a...
William Tanksley, Jr
wtanksle
Offline Send Email
Feb 9, 2007
3:29 pm

... [:] ... [:] ... my confusion was purely notational: i didn't realize that "A B" meant (what i would write as) "A^B", although the left-hand-side of the...
sa@...
Send Email
Feb 9, 2007
4:38 pm

... Included at the end of this post. ... Indeed. Although I'm also interested in genetic systems, my main interest is in understanding languages for use by...
William Tanksley, Jr
wtanksle
Offline Send Email
Feb 9, 2007
7:45 pm

My apologies to the many people (I hope) reading this list and hoping for something useful. This stuff is a LONG way from usefulness. I hope that it will...
William Tanksley, Jr
wtanksle
Offline Send Email
Feb 8, 2007
12:01 am

... Wow! That's much better. Nice work. ... Well, what exactly do you mean by that? There's certainly one combinator which is shorter in my {o,i}, namely "i"....
iepos
Offline Send Email
Feb 8, 2007
3:35 am

Billy & all, I hacked at my old Joy searcher for a while and was at last able to persuade it to deal with improper combinators; so I've been able to determine...
iepos
Offline Send Email
Feb 9, 2007
8:35 am

... Okay; and then you posted it where? :-) Let me get my credit card. -Billy...
William Tanksley, Jr
wtanksle
Offline Send Email
Feb 9, 2007
8:09 pm

... Thanks, but obviously it builds on your work -- you actually know what you're doing, and you get all the credit for making it make sense. I suspect that...
William Tanksley, Jr
wtanksle
Offline Send Email
Feb 9, 2007
6:48 pm

i would be extremely interested in reading a description of the algorithm. (my dog ate my credit card) ... From: "William Tanksley, Jr" <wtanksleyjr@...>...
stevan apter
sa@...
Send Email
Feb 9, 2007
10:03 pm

... Oh, yeah, I forgot to mention that. It's at http://www.tunes.org/~iepos/joys.zip (it's linked from the article "Theory of Concatenative Combinators"); I...
Brent L Kerby
iepos
Offline Send Email
Feb 9, 2007
10:58 pm

... It basically works by trying all programs of size 0 (There aren't too many of these :-) ), then all programs of size 1, and so forth, testing each program...
Brent L Kerby
iepos
Offline Send Email
Feb 10, 2007
3:31 am

thanks brent as usual, work that you consider throw-away contains more insights than can fit in a standard published article, much less the margins of one. ......
stevan apter
sa@...
Send Email
Feb 11, 2007
12:07 am

... I'm looking forward to your genetic system -- one would expect that it would be useful for the same purpose. Perhaps you should tailor a version of it to...
William Tanksley, Jr
wtanksle
Offline Send Email
Feb 11, 2007
12:27 am

Great stuff! Still, I don't see the need for a flat binary base (except for extreme simplicity and fun). Why not allow 4 flat primitives that follow the 4...
Robbert van Dalen
r_v_dalen
Offline Send Email
Feb 11, 2007
11:27 am

... That's a great reason :-). I'm using it to better understand perfect flatness, in hopes that I can see whether flatness has any desirable properties. It's...
William Tanksley, Jr
wtanksle
Offline Send Email
Feb 11, 2007
6:58 pm

... I played with this -- it definitely does make things simpler, since you don't need to have a "do everything" 'o' combinator; the other combinators can help...
William Tanksley, Jr
wtanksle
Offline Send Email
Feb 26, 2007
12:12 am

... From: "William Tanksley, Jr" <wtanksleyjr@...> To: <concatenative@yahoogroups.com> Sent: Friday, January 05, 2007 11:16 AM Subject: Re: [stack]...
stevan apter
sa@...
Send Email
Jan 5, 2007
8:27 pm

... An improper list is one whose final cons does not have a car of nil. -- He played King Lear as though John Cowan <cowan@...> someone had...
John Cowan
johnwcowan
Online Now Send Email
Jan 5, 2007
9:01 pm

... My system tries not to specify the shape of lists -- I consider it a bad habit. Even being able to take apart lists is mathematically problematic within a...
William Tanksley, Jr
wtanksle
Offline Send Email
Jan 6, 2007
7:01 am

... From: "John Cowan" <cowan@...> To: <concatenative@yahoogroups.com> Sent: Friday, January 05, 2007 3:52 PM Subject: Re: [stack] Concatenative macros? ...
stevan apter
sa@...
Send Email
Jan 5, 2007
10:33 pm

between you and john, i now understand the point about "improper lists". i think the two notations can be made equivalent by adding a special symbol to each. ...
stevan apter
sa@...
Send Email
Jan 6, 2007
12:17 pm

... Yes, that would make them equivalent (although "." wouldn't mean 'nil' for me; instead, it would be a code that meant that the previous item was the end of...
William Tanksley, Jr
wtanksle
Offline Send Email
Jan 7, 2007
2:01 am

... From: "William Tanksley, Jr" <wtanksleyjr@...> To: <concatenative@yahoogroups.com> Sent: Saturday, January 06, 2007 8:56 PM Subject: Re: [stack]...
stevan apter
sa@...
Send Email
Jan 8, 2007
1:16 pm
 First  |  |  Last 
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help