J-ottings 32: the Stylish Part of Vector
Vector 18:4, page 41
Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 41
Browsing through back numbers the other day, it struck me that in spite of being in its eighteenth year, "Vector" has won no awards for outstanding literary merit, has received no Booker prize nominations, and features in no university reading lists for exemplary 20th century English prose. This situation demands remedy, and while the urge burned hot within me, I resolved to take some immediately necessary steps. I had heard recently that if one is allowed to oversee a couple of million monkeys equipped with an equal number of keyboards, it is a near cert that one of the little brutes will eventually outperform Shakespeare. So with my computer thus dedicated to monkey business, here is what emerged.
Start with the distinction between 7?10 and 7(?@#)10 which give 7 random numbers from the set 0,.., 9 with and without repetition respectively. In the former case the left argument must be no greater than the right. The latter phrase uses copy (dyadic #) to replicate the 10 seven times prior to rolling.
It is easy using indexing and tally (monadic #) to extend randomisation to lists such as
To obtain a single random letter from lets say :
Suppose that you want the number of random numbers in a selection to be random. Two applications of ? are needed:
The hook 10(?~?)7 means (?7)? 10 that is, the roles of the right and left arguments have been reversed by using the passive adverb. Because there can be no repetitions, the right argument should be no greater than the left, since, depending on the luck of the draw you might hit
If you want to exclude the possibility of an empty selection use 10(?~q)7
where
A nice little palindromic fork #(?~?)# delivers the indices of a random selection of letters :
and the addition of from makes this into a random selection from the list
In order to obtain the indices of, say, ten random letters with repetition say :
and to convert these to indices use from as before :
The problem with this as a technique for random words is that words like this are not very beautiful and are almost certain to be unpronounceable. One possible strategy to overcome this might be to use as weights a list of rough relative frequencies of occurrence of the various letters in English :
The 16th. letter ‘q’ has been given the value of 0, on account of its tiresome requirement to be followed by a ‘u’, a matter which can comfortably be left to a later refinement. A weighted letter list is then
wlets=.fr#lets NB. weighted letters
#wlets NB. sum of weights
106
({~10&(?@#)@#)wlets
iedorthgwh
({~10&(?@#)@#)wlets
doakidsoas
At least the words look vaguely like words, and some (but only some) are just about pronounceable! Somewhat greater control of the patterns, as opposed to the mere frequencies, of vowels and consonants is desirable, so weight the vowels and the consonants separately:
Next determine some vowel/consonant patterns, and randomize each component in turn:
The patterns can be extended using $ to allow for longer words, and at the same time the occurrence of unpleasing single letter words can be inhibited by using
which is used to provide a random argument for take:
Everything is now in place to define a verb to produce random words:
Prefixes and suffixes help, and prototype lists of each are built into the verbs:
following which:
What about random sentences? Different strategies are available. One possibility is simply to string along a random number of random words with as left argument the maximum word length before inflections, and the right argument the maximum sentence length:
rs=.dyad define
s=.'' [ i=.0 [ lim=.?y.
while.i<lim do.
s=.s,(x. rword wpat),' ' [ i=.i+1
end.
)
6 rs 9
intoto sots labist nime prediwoft extatotced sudirts
7 rs 10
undusatbo presalos
and of course the global variable wpat is also available for tweaking. A bit short in any attributable meaning (my spellcheck also sees red!) but the likes of Kenneth Branagh might be able to put it across for a fee!
Another view is that a random sentence is a random drawing from an available list of words in the same way that a random word is a random drawing from an available random list of letters. In the case of a sentence the list is called a vocabulary, which can be divided into separate siub-lists of, for example, nouns, verbs, and adjs. Only the start of the definitions of these are shown, the rest should become apparent as matters proceed, and no doubt will provide invaluable physcoanalyitic evidence for future diagnosis of my various personality disorders:
nouns=.'cats';'degree';'philosophy'; ..
verbs=.'hopes';'keeps';'flies';'steps'; ..
adjs=.'great';'lean';'fat';'blue'; ..
Define a sentence pattern analogous to the consonant/vowel patterns:
Parts of speech patterns are analogous to the vowel/consonant pattern for words:
ran&>spat
+-----+----+------+-----+-----+
|faint|boat|enters|empty|light|
+-----+----+------+-----+-----+
Add a standard idiom for removing blanks:
and here is the basis for some random sentences:
As with letter patterns, different parts of speech patterns add variety:
spat1=.(<adj),(<adj),(<nouns),(<verbs),(<nouns)
rsent spat1
sneaky greek catalyst steps faith
rsent (<adj),(<nouns),(<verbs),(<nouns),(<verbs)
nice faith mates hope castigates
Chomsky, thou shouldst be living at this hour!
Of course things are still in the early stages but there are enough controls in place to make incremental refinements, and I think I can claim to have given my monkeys a head start. Progress so far is thus promising, and I confidently expect "Vector" to be awarded a Nobel prize for Literature before too long. Perhaps our friends in the Swedish APL Association could show the spirit of brotherliness and pull whatever strings are necessary to accelerate this outcome.
And in case you are concerned that I may nothing left to say in J-ottings 33, don’t worry, it is already written, as is J-ottings 34,.. and J-ottings 35, ,.. and J-ottings 36 all the way up to six million in fact. And what is more they are all completely fresh, not a single hint of repetition anywhere!