Representation
An Implementation of J
Atomic Representation
Boxed Representation
Tree Representation
Linear Representation
Atomic Representation
5!:1 is a verb that applies to a boxed name, and produces
the atomic representation of the named object.
Gerunds (results of the ` conjunction)
are arrays of atomic representations.
The adverb 5!:0 defines an object from its representation.
The atomic representation is a boxed list of two boxes:
| noun | symbol value |
| verb | symbol arguments |
| adverb | symbol arguments |
| conjunction | symbol arguments |
The symbol is a string computed by
function spellout in file ws.c.
For a primitive with an assigned symbol
(for example + or /.),
the symbol is simply that word; for those without, the symbol is
one of the following:
'0' noun
'2' hook
'3' fork
'4' bonded conjunction
'5' 2-element a-train or c-train
'6' 3-element a-train or c-train
The "value" in the representation of a noun is just the noun itself;
arguments in the representation of a verb, adverb, or conjunction are
themselves atomic representations. If an object is uniquely identified
by the symbol alone, then the second box is elided, and the representation
is the boxed symbol alone.
The following examples illustrate atomic representation:
ar=: 5!:1
plus=: + sum=: +/ mean=: +/ % #
ar <'plus' ar <'sum' ar <'mean'
ÚÄ¿ ÚÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³+³ ³ÚÄÂÄÄÄ¿³ ³ÚÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ¿³
ÀÄÙ ³³/³ÚÄ¿³³ ³³3³ÚÄÄÄÄÄÄÄÂÄÂÄ¿³³
³³ ³³+³³³ ³³ ³³ÚÄÂÄÄÄ¿³%³#³³³
³³ ³ÀÄÙ³³ ³³ ³³³/³ÚÄ¿³³ ³ ³³³
³ÀÄÁÄÄÄÙ³ ³³ ³³³ ³³+³³³ ³ ³³³
ÀÄÄÄÄÄÄÄÙ ³³ ³³³ ³ÀÄÙ³³ ³ ³³³
³³ ³³ÀÄÁÄÄÄÙ³ ³ ³³³
³³ ³ÀÄÄÄÄÄÄÄÁÄÁÄÙ³³
³ÀÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÙ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
+`(+/)`(+/ % #)
ÚÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³+³ÚÄÂÄÄÄ¿³ÚÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ¿³
³ ³³/³ÚÄ¿³³³3³ÚÄÄÄÄÄÄÄÂÄÂÄ¿³³
³ ³³ ³³+³³³³ ³³ÚÄÂÄÄÄ¿³%³#³³³
³ ³³ ³ÀÄÙ³³³ ³³³/³ÚÄ¿³³ ³ ³³³
³ ³ÀÄÁÄÄÄÙ³³ ³³³ ³³+³³³ ³ ³³³
³ ³ ³³ ³³³ ³ÀÄÙ³³ ³ ³³³
³ ³ ³³ ³³ÀÄÁÄÄÄÙ³ ³ ³³³
³ ³ ³³ ³ÀÄÄÄÄÄÄÄÁÄÁÄÙ³³
³ ³ ³ÀÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÙ³
ÀÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
a=: 5 xenos=: !:
ar <'a' ar <'xenos' ar <'ar'
ÚÄÄÄÄÄ¿ ÚÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ÚÄÂÄ¿³ ³!:³ ³ÚÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ¿³
³³0³5³³ ÀÄÄÙ ³³!:³ÚÄÄÄÄÄÂÄÄÄÄÄ¿³³
³ÀÄÁÄÙ³ ³³ ³³ÚÄÂÄ¿³ÚÄÂÄ¿³³³
ÀÄÄÄÄÄÙ ³³ ³³³0³5³³³0³1³³³³
³³ ³³ÀÄÁÄÙ³ÀÄÁÄÙ³³³
³³ ³ÀÄÄÄÄÄÁÄÄÄÄÄÙ³³
³ÀÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÙ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
lgamma=: ^.@!@<:
ar <'lgamma'
ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ÚÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿³
³³@³ÚÄÄÄÄÄÄÄÄÄÄÂÄÄ¿³³
³³ ³³ÚÄÂÄÄÄÄÄÄ¿³<:³³³
³³ ³³³@³ÚÄÄÂÄ¿³³ ³³³
³³ ³³³ ³³^.³!³³³ ³³³
³³ ³³³ ³ÀÄÄÁÄÙ³³ ³³³
³³ ³³ÀÄÁÄÄÄÄÄÄÙ³ ³³³
³³ ³ÀÄÄÄÄÄÄÄÄÄÄÁÄÄÙ³³
³ÀÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
Boxed Representation
5!:2 is a verb that applies to a boxed name, and produces
the boxed representation of the named object. The representation
can be modelled as follows:
ar =: 5!:1
boxed =: 32&=@(3!:0)
oarg =: >@(1&{)
bxroot =: (<1 0)&C.@,`] @. (e.&(,&.>'0123456789')@[)
bxx =: {. bxroot bx&.>@oarg
bxgl =: {. bxroot (bxx&.>@{. , bx &.>@}.)@oarg
bxgr =: {. bxroot (bx &.>@{. , bxx&.>@}.)@oarg
bxg =: bxgr`bxgl`bxx @. (i.&(<,'`')@oarg)
bxtil =: bxx`(oarg@>@{.@oarg) @. ((<,'0')&=@{.@>@{.@oarg)
bxcase =: oarg`bxgl`bxgl`bxg`bxtil`bxx @. ((;:'0@.`:4~')&i.@{.)
bx =: ]`bxcase @. boxed
brep =: ,@<`[ @. boxed @ bx @ > @ ar
brep <'brep'
ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÂÄÄ¿
³ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÂÄ¿³@³ar³
³³ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÂÄÄ¿³@³>³³ ³ ³
³³³ÚÄÄÄÄÄÄÄÄÄÄÄÂÄÄÂÄÄÄÄÄ¿³@³bx³³ ³ ³³ ³ ³
³³³³ÚÄÄÄÄÄÄÄÂÄ¿³@.³boxed³³ ³ ³³ ³ ³³ ³ ³
³³³³³ÚÄÂÄÂÄ¿³[³³ ³ ³³ ³ ³³ ³ ³³ ³ ³
³³³³³³,³@³<³³ ³³ ³ ³³ ³ ³³ ³ ³³ ³ ³
³³³³³ÀÄÁÄÁÄÙ³ ³³ ³ ³³ ³ ³³ ³ ³³ ³ ³
³³³³ÀÄÄÄÄÄÄÄÁÄÙ³ ³ ³³ ³ ³³ ³ ³³ ³ ³
³³³ÀÄÄÄÄÄÄÄÄÄÄÄÁÄÄÁÄÄÄÄÄÙ³ ³ ³³ ³ ³³ ³ ³
³³ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÁÄÄÙ³ ³ ³³ ³ ³
³ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÁÄÙ³ ³ ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÁÄÄÙ
The model is divided into groups of verbs.
The first group are utilities:
|
ar |
atomic representation |
|
boxed |
1 if boxed |
|
oarg |
open the second element of the list argument |
bxroot produces an infix representation from a
root r and its list of arguments a.
If r is a digit, it denotes a primitive without an assigned word
(e.g. '3' denotes a fork;
see Atomic Representation),
and the result of bxroot is a;
otherwise, r bxroot a produces:
|
a,r |
if one argument |
|
({.a),r,(}.a) |
if two arguments |
|
r |
if no arguments (primitive) |
The other verbs named with the bx prefix apply to the
opened atomic representation, and embody logic to effect "nice"
displays for various special cases. The agenda items
in bxcase are:
| ID | Agenda |
|
0 |
oarg |
noun (leaf) |
|
@. |
bxgl |
gerundial left subtree |
|
`: |
bxgl |
gerundial left subtree |
|
4 |
bxg |
bonded conjunction; gerundial left or right subtree |
|
~ |
bxtil |
possible instance of evoke |
|
other |
bxx |
none of the above |
brep is a model of 5!:2.
Tree Representation
5!:4 is a verb that applies to a boxed name, and produces a literal
table of the tree representation of the named object. Thus:
tree=: connect @ > @ (,.&.>/) @ ('0'&root ; ]) @ (tr@>@ar)
5!:4 <'tree'
ÚÄ connect
ÚÄ @ ÄÁÄ >
ÚÄ @ Ä´ ÚÄ ,.
³ ÀÄ / ÄÄÄ &. ÄÄÄÄÁÄ >
³
ÚÄ @ Ä´ ÚÄ '0'
³ ³ ÚÄ & ÄÁÄ root
³ ÀÄÄÄÄÄÅÄ ;
³ ÀÄ ]
ÄÄ @ Ä´
³ ÚÄ tr
³ ÚÄ @ ÄÁÄ >
ÀÄ @ ÄÁÄ ar
The tree representation can be modelled as follows:
ar =: 5!:1
lr =: 3 : '5!:5 <''y.'''
boxed =: 32&= @ (3!:0)
mt =: 0&e.@$
oarg =: >@(1&{)
shr =: |.!.''
shl =: 1&(|.!.'')
mat =: (1 1&}.)@(_1 _1&}.)@":@<
boxc =: {. 9!:6 ''
dash =: 10{boxc
extent =: (+./\ *. +./\.) @ (' '&~:) @: ({."1)
limb1 =: 1&|.@$ 1&~: }. (10 6 0{boxc)&,@($&(9{boxc))
limb =: -@(i.&1)@[ |. #@[ {. limb1@]
pfx =: (limb +/)@extent ,. ]
pad =: [ {. ] ,. dash&=@({:"1)@] { ' '&,:@($&dash)@(-&{: $)
take =: pad`($&' '@[) @. (mt@])
rc =: #@>@{."1 ; >./@:({:@$@>)
kernt =: (0{boxc)&=@shl@[ *. ' '&~:@]
kernb =: (6{boxc)&=@] *. ' '&~:@shl@[
kern =: (<0 0)&{&>"2 (kernt +./"1@:+. kernb) (<_1 0)&{&>"2
gap =: ,&.>"_1 {&((0 1$' ');1 1$' ')@kern
graft =: (pfx&.>@{. 0} ]) @ (,&.>/) @ gap @ ({@rc take&.> ])
lab =: ,: @ (2&|.) @ ((' ',dash,dash,' ')&,)
label =: lab`((,.dash)&[) @. (e.&'0123456789'@{.)
center =: ((i.&1) -@+ <.@-:@(+/))@] |. #@] {. [
root =: label@[ center extent@>@{.@]
leaf =: ,@<@(((,:dash,' ')&[ center $&1@#) ,. ])@mat@":
trx =: >@{. (root ; ]) graft@:(tr@>)@oarg
trgl =: >@{. (root ; ]) graft@:(trx@>@{. , tr @>@}.)@oarg
trgr =: >@{. (root ; ]) graft@:(tr @>@{. , trx@>@}.)@oarg
trg =: trgr`trgl`trx @. (i.&(<,'`')@oarg)
trtil =: trx`(leaf@oarg@>@{.@oarg) @. ((<,'0')&=@{.@>@{.@oarg)
trnoun =: leaf @ lr @ oarg
trcase =: trnoun`trgl`trgl`trg`trtil`trx @. ((;:'0@.`:4~')&i.@{.)
tr =: leaf`trcase @. boxed
rep =: [. & (((# i.@#)@,@) (@])})
right =: (5{boxc) rep (e.&(9{boxc) *. shr"1@(e.&dash))
cross =: (4{boxc) rep (e.&(5{boxc) *. shl"1@(e.&dash))
left =: (3{boxc) rep (e.&(9{boxc) *. shl"1@(e.&dash))
bot =: (7{boxc) rep (e.&(6{boxc) *. shr"1@(e.&dash))
connect =: bot @ left @ cross @ right
tree =: connect @ > @ (,.&.>/) @ ('0'&root ; ]) @ (tr@>@ar)
The model is divided into groups of definitions
(which are verbs unless indicated otherwise).
The first group are utilities:
|
ar |
atomic representation |
|
boxed |
1 if boxed |
|
mt |
1 if empty |
|
oarg |
open the second element of the list argument |
|
shr |
shift right |
|
shl |
shift left |
|
mat |
a literal matrix image of the argument |
|
boxc |
(noun) box drawing characters |
|
dash |
(noun) the "dash" in the set of box drawing characters |
A "generational tree" (GT) is a list of boxed literal
tables having the same number of rows, such that nodes at the same depth
are in the same box. For example, the GT for tree
is: ÚÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄ¿
³ ³ ³ ³ ³ÚÄ connect³ ³
³ ³ ³ ³ÚÄ @ ijÀÄ > ³ ³
³ ³ ³ÚÄ @ ij³ ³ ³ÚÄ ,.³
³ ³ ³³ ³ÀÄ / ijÄÄ &. ÄÄÄijÀÄ > ³
³ ³ ³³ ³ ³ ³ ³
³ ³ÚÄ @ ij³ ³ ³ÚÄ '0' ³ ³
³ ³³ ³³ ³ÚÄ & ijÀÄ root ³ ³
³ ³³ ³ÀÄÄÄÄij³Ä ; ³ ³ ³
³ ³³ ³ ³ÀÄ ] ³ ³ ³
³ÄÄ @ ij³ ³ ³ ³ ³ ³
³ ³³ ³ ³ÚÄ tr ³ ³ ³
³ ³³ ³ÚÄ @ ijÀÄ > ³ ³ ³
³ ³ÀÄ @ ijÀÄ ar ³ ³ ³ ³
ÀÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÙ
graft is the main verb in the next group.
The argument is a table whose rows are GTs
for the nodes at the same depth.
The result is a GT.
root accepts a string left argument and a GT right argument.
The result is a literal matrix
with the string centered relative to the GT.
leaf computes a unitary (single-element) GT from its argument.
tr applies to the opened atomic representation of an object
and produces a GT. The verbs named with the tr prefix embody
logic to effect "nice" displays for various special cases.
The agenda items in trcase are:
|
|
|
ID |
Agenda |
|
0 |
leaf@oarg |
noun (leaf) |
|
@. |
trgl |
gerundial left subtree |
|
`: |
trgl |
gerundial left subtree |
|
4 |
trg |
bonded conjunction; gerund left or right |
|
~ |
trtil |
possible instance of evoke |
|
other |
trx |
none of the above |
rep is a conjunction whose left argument is
a single literal c and whose right argument is
a proposition p,
deriving a verb such that the phrase c rep p y
replaces with c the positions
in y marked by p y.
connect substitutes
Á (bot),
à (left),
Å (cross), and
´ (right)
at nexuses of the tree.
tree is a model of 5!:4.
Linear Representation
5!:5 is a verb that applies to a boxed name, and produces a literal list
of the linear representation of the named object. Thus:
lrep=: lr @ > @ ar
5!:5 <'lrep'
lr@>@ar
$ 5!:5 <'lrep'
7
The linear representation can be modelled as follows:
ar =: 5!:1
boxed =: 32&= @ (3!:0)
oarg =: >@(1&{)
mtv =: i.@0:
paren =: ('('&,)@(,&')')
symb =: $&' '@(e.&'.:')@{. , ]
quote =: ''''
alp =: (,65 97+/i.26){a.
dig =: '0123456789'
slist =: $&','@(1&=)
shape =: mtv`slist`(,&'$'@":)@.(2&<.@#)`('i.'&,@":) @. (0&e.) @ $
vchar =: >:@(quote&=)@, quote&,@(,"e)@# ,
vbox =: }. @ ; @: (','&,@paren@('<'&,)@lnoun&.>)
value =: vchar`vbox`(":!.18@,) @. (2 32&i.@(type * *@(*/)@$))
lnoun =: shape , value
dotco =: 2&=@# *. e.&'.:'@{:
name =: e.&alp@{. *. *./@(e.&(alp,dig,'_'))@}: *. e.&(alp,dig,'_.:')@{:
num =: e.&(dig,'_')@{. *. *./@(e.&(dig,'_ .ejdr'))
qstr =: mtv -: -.@(~:/\)@(e."e) -."e@# ]
pstr =: -.@(0&e.)@}:@(+/\)@({&1 _1 0)@('()'&i.)
nopar =: 1&=@# +. dotco +. name +. num +. qstr +. pstr
cp =: paren`] @. nopar
bp =: ]`cp@.(' '&e.)
hfork =: }.@;@:(' '&,@bp&.>)@]
left =: bp@>@{.
right =: mtv`(cp@>@{:)@.(1&<@#)
ins =: left@] , symb@>@[ , right@]
act =: ;@:(cp&.>)@]
insert =: hfork`hfork`act`act`act`ins @. ('23456'&i.@{.@>@[)
lx =: {. insert lr&.>@oarg
ltie =: lr`(}.@;@:('`'&,@cp@lr&.>)@oarg) @. ((<,'0')&=@{.)
lgl =: {. insert (ltie&.>@{. , lr &.>@}.)@oarg
lgr =: {. insert (lr &.>@{. , ltie&.>@}.)@oarg
lg =: lgr`lgl`lx @. (i.&(<,'`')@oarg)
ltil =: lx`(oarg@>@{.@oarg) @. ((<,'0')&=@{.@>@{.@oarg)
lcase =: (cp@lnoun@oarg)`lgl`lgl`lg`ltil`lx @. ((;:'0@.`:4~')&i.@{.)
lr =: symb`lcase@.boxed
lrep =: lr @ > @ ar
Next
Previous
Index
Table of Contents