another tacit question

73 views
Skip to first unread message

John Dixon

unread,
Aug 14, 2024, 12:17:19 PMAug 14
to fo...@jsoftware.com
I have recently been trying to write  a tacit version to execute a
program which returns:

    0, (i.1),(i.2),(i.4),...,(i.2^k)

For example, 0 0 0 1 0 1 2 3 0 1 2 3 4 5 6 7 for k = 3

More generally the problem is to return the concatenation of lists of
different lengths (without padding). I assume it must involve boxing and
unboxing.  Any suggestions?

    Thank you,

            John

Luke D

unread,
Aug 14, 2024, 12:57:34 PMAug 14
to fo...@jsoftware.com
[:;@:(<@i."+)1,2^i.@:>:
This seems perfectly valid but could likely be more elegant. It does involve boxing intermediate ranges as per your hunch.


Best Regards, 
Luke De La Cruz


To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.

Skip Cave

unread,
Aug 14, 2024, 1:35:14 PMAug 14
to fo...@jsoftware.com

Verb t(n):

t=.{{0,;i.&.>2^i.y}}

t 4

0 0 0 1 0 1 2 3 0 1 2 3 4 5 6 7

t 6

0 0 0 1 0 1 2 3 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31





Skip Cave
Cave Consulting LLC


On Wed, Aug 14, 2024 at 11:17 AM John Dixon <jdi...@math.carleton.ca> wrote:

Michael Day

unread,
Aug 14, 2024, 2:40:39 PMAug 14
to 'Skip Cave' via forum
Slightly "more tacit" than Skip's direct definition,  especially if John doesn't
really need the leading zero:

   t =: ;@(i.&.>@(2 ^ i.@>:))

eg
   t 3
0 0 1 0 1 2 3 0 1 2 3 4 5 6 7

I think the leading zero is extraneous,  since this t has

   t 0
0
   t 1
0 0 1


which seems adequate to me,  but you can of course prepend it if required:

   t0 =: 0, t
   t0 3
0 0 0 1 0 1 2 3 0 1 2 3 4 5 6 7


Mike

Virus-free.www.avast.com

Elijah Stone

unread,
Aug 14, 2024, 4:12:14 PMAug 14
to fo...@jsoftware.com
no box but slow

f=. 0:`(i.,~$:@-:)@.(~:&1)
f 8
0 0 1 0 1 2 3 0 1 2 3 4 5 6 7

Jorrit Kirsten

unread,
Aug 15, 2024, 12:39:31 AMAug 15
to forum, John Dixon
   NB. Solution 1: without boxing, but with recursion (similar to Elijah Stone's solution, but using argument y=k=3, instead of y=8):
   (2#0:)`($:@<:,2 i.@^])@.(0<]) 3

0 0 0 1 0 1 2 3 0 1 2 3 4 5 6 7
   
   NB. Solution 2: with boxing, but without recursion and agent-conjunction:
   0,;@(2<@i.@^i.@>:) 3

0 0 0 1 0 1 2 3 0 1 2 3 4 5 6 7
   0,;@(2 <@i.@^ i.@>:) 3    NB. with spaces to (arguably) improve readability
0 0 0 1 0 1 2 3 0 1 2 3 4 5 6 7
   
   NB. Solution 3: similar to Skip Cave's solution, but tacit:
   0,;@(2 i.&.>@^ i.@>:) 3  
0 0 0 1 0 1 2 3 0 1 2 3 4 5 6 7
   
Jorrit

Hauke Rehr

unread,
Aug 15, 2024, 3:37:09 PMAug 15
to fo...@jsoftware.com
possibility without boxes:

(i.@(2&^) |~ 1, 2 #~@:^ i.) >: 3
0 0 0 1 0 1 2 3 0 1 2 3 4 5 6 7


--
----------------------
mail written using NEO
neo-layout.org

More Rice

unread,
Aug 17, 2024, 5:30:55 PMAug 17
to fo...@jsoftware.com
neat tricks for boxless solutions!

I'll add my boxless, "unconventional" one to the collection:

NB. 5th solution so far
soln5 =. (] , i.@+:@>:@{:)^:
3 soln5 0 0
0 0 0 1 0 1 2 3 0 1 2 3 4 5 6 7

Maurice

Raul Miller

unread,
Aug 17, 2024, 5:45:38 PMAug 17
to fo...@jsoftware.com
Or, almost the same;

(i.@^~&2 - 0, [: #~ 2 ^ i.) >: 3
0 0 0 1 0 1 2 3 0 1 2 3 4 5 6 7

--
Raul

On Thu, Aug 15, 2024 at 3:37 PM Hauke Rehr <hauke...@uni-jena.de> wrote:
>

Jorrit Kirsten

unread,
Aug 18, 2024, 6:35:03 AMAug 18
to forum, Raul Miller

Kudos to all solutions!
I find Maurice's use of a VC-"modifier train" without boxing, recursion ($:), agent conjunction, filtering particularly inspiring and elegant.
In one line (if desired) this could, of course, be written as: 
3 ((],i.@+:@>:@{:)^:) 0 0

0 0 0 1 0 1 2 3 0 1 2 3 4 5 6 7

Raul Miller

unread,
Aug 18, 2024, 2:10:26 PMAug 18
to Jorrit Kirsten, forum
Hmm....

I think I understand the appeal of recursion. But, as a note of
caution, general recursion has costs which probably exceed the costs
of boxing in typical cases.

(That said, there's enough free variables behind the scenes that
there's probably exceptions to that trend.)

(Also, of course, machine efficiency only "matters" when machine
resources are the bottleneck.)

--
Raul

Henry Rich

unread,
Aug 18, 2024, 6:03:55 PMAug 18
to fo...@jsoftware.com
Agreed.  With recursion collecting the result can become O(n^2) for
one-sided recursion that has to append the result from a level to the
growing result, or O(n lg n) for recursions that keep left and right
sides approximately equal. [But if you can make your recursion run
inplace (perhaps by appending the result inplace), there's nothing to
collect (think inplace quicksort).]

The cost of recursion on the way down is tiny for tacit functions.  For
explicit functions each recursion level has to allocate a namespace and
set up for processing, which takes a couple of hundred instructions.

As David H H Diamond wrote in "A Programmer's ABCs",

This is the algorithm <big>A</big>
It makes its neat recursive way
into a stack.  It will be back,
but only after some delay.

Henry Rich
Reply all
Reply to author
Forward
0 new messages