> This works, but it doesn't seem like it was a worthwhile exercise:

Maybe, maybe not, depending on one's priority regarding conciseness and
space-time performance.  A comparison of three fixed tacit verbs follows,
foo is a tacit version of Boss' explicit verb, goo is your tacit verb
(fixed), and hoo is a tacit straightforward transcription of your explicit
version produced elsewhere (and reproduced here using a j902 interpreter),

   Y=. ?.@#~66

   stp 666
  foo Y
  goo Y
  hoo Y
)
┌────────┬─────┬──────────┬────────────┐
│Sentence│Space│Time      │Space * Time│
├────────┼─────┼──────────┼────────────┤
│  foo Y │12672│2.60968e_5│0.330699    │
├────────┼─────┼──────────┼────────────┤
│  goo Y │22976│1.15749e_5│0.265945    │
├────────┼─────┼──────────┼────────────┤
│  hoo Y │13760│1.15728e_5│0.159242    │
└────────┴─────┴──────────┴────────────┘

   Y=. ?.@#~666

   stp 666
  foo Y
  goo Y
  hoo Y
)
┌────────┬──────┬───────────┬────────────┐
│Sentence│Space │Time       │Space * Time│
├────────┼──────┼───────────┼────────────┤
│  foo Y │122752│0.000258194│31.6938     │
├────────┼──────┼───────────┼────────────┤
│  goo Y │210368│5.90565e_5 │12.4236     │
├────────┼──────┼───────────┼────────────┤
│  hoo Y │127424│5.35683e_5 │6.82589     │
└────────┴──────┴───────────┴────────────┘

   Y=. ?.@#~6666

   stp 666
  foo Y
  goo Y
  hoo Y
)
┌────────┬───────┬───────────┬────────────┐
│Sentence│Space  │Time       │Space * Time│
├────────┼───────┼───────────┼────────────┤
│  foo Y │1181440│0.00280684 │3316.11     │
├────────┼───────┼───────────┼────────────┤
│  goo Y │2175168│0.00104154 │2265.53     │
├────────┼───────┼───────────┼────────────┤
│  hoo Y │1118400│0.000541218│605.298     │
└────────┴───────┴───────────┴────────────┘




On Sat, May 22, 2021 at 8:59 AM Raul Miller <rauldmil...@gmail.com> wrote:
>
> Nope, I didn't take my thinking far enough. Those last two lines
> require some significant duct tape and glue if I want to "minimize"
> recalculation.
>
> But... one thing I could do is glue the ucnt and uval values together
> (since they have the same length). And, then, when I calculate sndx, I
> can glue that on top of the other two (since it also had the same
> length). And, then, when I compute reps, I can glue that to the top of
> the stack (since it is also the same length). This greatly simplifies
> value passing, since I can now pick whichever of these four values I
> want to work with. But that still leaves useg buried in the middle, so
> I might as well make useg the same length as everything else and throw
> it onto the stack.
>
> This works, but it doesn't seem like it was a worthwhile exercise:
>
> undx=: [: +/\ 2~:/\(,~ 1+{.)
> ucvs=: (#/.~@] ,: {./.~) undx NB. uval: _1{  ucnt: _2{
> useg=: ,~ 1,[: ((2 ~:/\ ]) , 0#~0<#)@:* 2 -/\ {: NB. useg: _3{
> reps=: ,~ _2&{ * 1, 1+1}._3&{ NB. reps: _4{
> sndx=: ,~ +/\@(_4&{) NB. sndx: _5{
> segs=: _3&{@]`((_5{])-_2{])`(0#~(<_5 _1){])}~ NB. _6{
> result=: <;.1 (_4&{) # _1&{
> updowns=: (result~ segs)@sndx@reps@useg@ucvs
>
> Oh well... at least it's harder to read. Or, something like that.
>
> --
> Raul
>
> On Fri, May 21, 2021 at 9:01 PM Raul Miller <rauldmil...@gmail.com> wrote:
> >
> > After thinking about this for a little bit, I have decided that it
> > should be *almost* straightforward to convert this definition to a
> > fully tacit form.
> >
> > The simplest tactic would be to define tacit expressions for each of
> > the local names in the definition, but that would result in
> > significant repeat work.
> >
> > But we can use trains to calculate and save two values and of course a
> > third value can be calculated inside the train if it's used only once.
> > So, looking at the structure of the definition:
> >
> > labels=: ;:'y undx uval ucnt useg reps sndx segs result'
> > reset=:{{
> >   connections=:0$~2##labels
> > }}
> > depends=:{{
> >   connections=:1 ({(labels i.;:x);(#labels)-.~labels i.;:y)} connections
> > }}
> >
> >   reset''
> >   'uval' depends ' undx {./. y'
> >   'ucnt' depends ' #/.~ undx'
> >   'useg' depends ' ((2 ~:/\ ]),0#~0<#) * 2 -/\ uval'
> >   'reps' depends ' ucnt*1,1+useg'
> >   'sndx' depends ' +/\reps'
> >   'segs' depends ' (1,useg) (sndx-ucnt)} 0#~{:sndx'
> >   'result' depends ' segs<;.1 reps#uval'
> >
> > We can also see that each value is used by at most two other values
> > which is promising:
> >    +/connections
> > 1 2 2 2 2 2 1 1 0
> >
> > And, we can remind ourselves that each value depends on at most three
> > other values, which is also promising:
> >    +/"1 connections
> > 0 0 2 1 1 2 1 3 3
> >
> > But those last two could use some further inspection:
> >
> > Looking at the computation for segs:
> >    (labels i.;:'useg sndx ucnt') { +/connections
> > 2 1 2
> >
> > sndx is only used once, so it could be computed inside a train. But,
> > it appears twice in the expression, so we would need to rearrange
> > things to eliminate that as a problem. Perhaps the simplest approach
> > would be to replace those two uses with +/\reps and +/reps.
> >
> > Looking at the result, we see:
> >    (labels i.;:'segs reps uval') { +/connections
> > 1 2 2
> >
> > Here, segs itself is used only once.
> >
> > After this inspection, it seems like it should be completely
> > straightforward to convert that definition of updowns to a fully tacit
> > nested train representation.
> >
> > And, perhaps this way of thinking about things would be of interest to
> > some others here in the forums?
> >
> >
> > --
> > Raul
> >
> > On Fri, May 21, 2021 at 8:23 AM Raul Miller <rauldmil...@gmail.com>
wrote:
> > >
> > > Ok...
> > >
> > > I didn't feel like trying to make this tacit:
> > >
> > > updowns=:{{
> > >   undx=. +/\ 2 ~:/\ (,~ 1+{.) y
> > >   uval=. undx {./. y
> > >   ucnt=. #/.~ undx
> > >   useg=. ((2 ~:/\ ]),0#~0<#) * 2 -/\ uval
> > >   reps=. ucnt*1,1+useg
> > >   sndx=. +/\reps
> > >   segs=. (1,useg) (sndx-ucnt)} 0#~{:sndx
> > >   segs<;.1 reps#uval
> > > }}
> > >
> > > This is of course quite a bit longer than your Foo, but also somewhat
> > > faster on long sequences in my trivial tests.
> > >
> > > It's less space efficient, perhaps because I've retained all
> > > intermediate results until the end.
> > >
> > > I hope this helps,
> > >
> > > --
> > > Raul
> > >
> > >
> > >
> > >
> > > On Fri, May 21, 2021 at 7:21 AM R.E. Boss <r.e.b...@outlook.com>
wrote:
> > > >
> > > > Yep.
> > > >
> > > >
> > > > R.E. Boss
> > > >
> > > >
> > > > -----Original Message-----
> > > > From: Programming <programming-boun...@forums.jsoftware.com> On
Behalf Of Raul Miller
> > > > Sent: vrijdag 21 mei 2021 12:47
> > > > To: Programming forum <programm...@jsoftware.com>
> > > > Subject: Re: [Jprogramming] ups & downs
> > > >
> > > > Ok... so... this is correct behavior?
> > > >
> > > >    Foo 1 10 1 # 1 2 1
> > > > +---------------------+---------------------+
> > > > |1 2 2 2 2 2 2 2 2 2 2|2 2 2 2 2 2 2 2 2 2 1|
> > > > +---------------------+---------------------+
> > > >
> > > > Thanks,
> > > >
> > > > --
> > > > Raul
> > > >
> > > >
> > > > On Fri, May 21, 2021 at 4:09 AM R.E. Boss <r.e.b...@outlook.com>
wrote:
> > > > >
> > > > >   ud 2#1 2 1 2 1
> > > > > +-------+-----+-----+-----+
> > > > > |1 1 2 2|2 1 1|1 2 2|2 1 1|
> > > > > +-------+-----+-----+-----+
> > > > >   Foo 2#1 2 1 2 1
> > > > > +-------+-------+-------+-------+
> > > > > |1 1 2 2|2 2 1 1|1 1 2 2|2 2 1 1|
> > > > > +-------+-------+-------+-------+
> > > > >
> > > > > the latter being the required, maximal length ups & downs.
> > > > >
> > > > > OTOH, Foo does not handle correct your first two values 4#1  and
3#1 2.
> > > > > But they are rather trivial ones, being constant or only one up
(or down), I can live with that. An easy check could filter that out.
> > > > >
> > > > >
> > > > > R.E. Boss
> > > > >
> > > > >
> > > > > -----Original Message-----
> > > > > From: Programming <programming-boun...@forums.jsoftware.com> On
Behalf Of Raul Miller
> > > > > Sent: vrijdag 21 mei 2021 00:32
> > > > > To: Programming forum <programm...@jsoftware.com>
> > > > > Subject: Re: [Jprogramming] ups & downs
> > > > >
> > > > > Bugfix:
> > > > >
> > > > > reps=: 1+0,~0,2~:/\[:[^:(0~:[)/\.&|.^:2@:*2 -/\]
> > > > > ud=: reps ((1,2 =/\ [ # #\@]) <;.1 #) ]
> > > > >
> > > > > This fixes a problem where the duplicate values appeared at the
end of the sequence.
> > > > >
> > > > > Here are some values to test against:
> > > > >    4#1
> > > > >    3#1 2
> > > > >    2#1 2 1 2 1
> > > > >
> > > > > I think I've dealt with all of these correctly (though of course,
there's some ambiguity where a run of equal values appears at the edge of
an up/down border). But let me know if I should be doing this differently.
> > > > >
> > > > > Thanks,
> > > > >
> > > > > --
> > > > > Raul
> > > > >
> > > > > On Thu, May 20, 2021 at 12:17 PM Raul Miller <
rauldmil...@gmail.com> wrote:
> > > > > >
> > > > > > Oh...  I see...
> > > > > >
> > > > > > I noticed that the ravel of the boxes did not match the original
> > > > > > sequence and did not look close enough after that.
> > > > > >
> > > > > > Anyways, I guess here's how I would approach this:
> > > > > >
> > > > > > reps=: 1+0,~0,2~:/\[:[^:(0~:[)/\.@:*2 -/\]
> > > > > > ud=: reps ((1,2 =/\ [ # #\@]) <;.1 #) ]
> > > > > >
> > > > > > Thanks,
> > > > > >
> > > > > > --
> > > > > > Raul
> > > > > >

NB. Beware of line-wrapping...


foo=. ,@:|:@:((#~ (1 < #@~.S:0))"1)@:(\:~)@:(<;.2"1~ (1 ,.~ (}. < }:)`(}. > 
}:)`:0))

goo=. (((<;.1) (_4&{ # _1&{))~ _3&{@]`((_5 { ]) - _2 { ])`(0 #~ (<_5 _1) { 
])}~)@(,~ +/\@(_4&{))@(,~ (_2&{ * 1 , 1 + 1 }. _3&{))@(,~ (1 , [: ((2 ~:/\ ]) , 
0 #~ 0 < #)@:* 2 -/\ {:))@((#/.~@] ,: {./.~) ([: +/\ 2 ~:/\ (,~ (1 + {.))))

hoo=. (7&({::) (<;.1) 5&({::) # 2&({::))@:(<@:((0 (0 {:: ])`(<@:(1 {:: ]))`(2 
{:: ])} ])@:((1 , 4&({::)) ; (6&({::) <@:- 3&({::)) ; 0 #~ {:@:(6&({::)))) 7} 
])@:(<@:(+/\@:(5&({::))) 6} ])@:(<@:(3&({::) * 1 , 1 + 4&({::)) 5} ])@:(<@:(((2 
~:/\ ]) , 0 #~ 0 < #)@:*@:(2 -/\ ])@:(2&({::))) 4} ])@:(<@:(#/.~@:(1&({::))) 3} 
])@:(<@:(1&({::) {./. 0&({::)) 2} ])@:(<@:(+/\@:(2 ~:/\ (,~ (1 + 
{.)))@:(0&({::))) 1} ])@:(,&(<;._1 '. . . . . . .'))@:<


stp=. ] (([ ((<;._1 '|Sentence|Space|Time|Space * Time') , (, */&.:>@:(1 
2&{))@:(] ; 7!:2@:] ; 6!:2)&>) (10{a.) -.&a:@:(<;._2@,~) ]) [ (0 0 $ 13!:8^:((0 
e. ])`(12"_)))@:(2 -:/\ ])@:(".&.>)@:((10{a.) -.&a:@:(<;._2@,~) ]) ::(0 
0&$@(1!:2&2)@:('Mismatch!'"_))) ".@:('0( : 0)'"_)


Y=. ?.@#~66

stp 666
  foo Y
  goo Y
  hoo Y
)

Y=. ?.@#~666

stp 666
  foo Y
  goo Y
  hoo Y
)

Y=. ?.@#~6666

stp 666
  foo Y
  goo Y
  hoo Y
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to