Newbie question to under (&.)

64 views
Skip to first unread message

Roland Senn

unread,
Sep 9, 2024, 9:01:31 AMSep 9
to fo...@jsoftware.com

In https://www.jsoftware.com/books/pdf/easyj.pdf section 3 we have:

up =: *10&^

down =: %10&^

rnd =: <. @ (0.5&+)

round =: rnd @ up down ]

5.123 up 2 NB. 512.3 up is dyadic

512.3 down 2 NB. 5.123 down is dyadic and inverse function of up

rnd 3.657 5.123 NB. 4 5 rnd is monadic

3.657 5.123 round 2 NB. 3.66 5.12

Now as 'down' is the inverse of 'up', it should be possible to use 'under' (&.):

roundu =: rnd &. up

Unfortunately this doesn't work:

3.657 5.123 roundu 2

|domain error in roundu, executing dyad rnd&.up

| 3.657 5.123 roundu 2

I think the issue is: The verb 'up' is dyadic, but 'rnd' is monadic. So I tried:

rounduu =: ([: rnd [) &. up

This gives the same error!

In https://code.jsoftware.com/wiki/Essays/Under I found:

Round to p decimal places: ([: <. +&0.5) &. (*&(10^p))

However here p (number of digits to round) is a noun variable and not an argument of the verb!

How do I write a working version of roundu using under (&.)? How can I tell the interpreter to call 'rnd' monadically?

Clifford Reiter

unread,
Sep 9, 2024, 9:29:05 AMSep 9
to fo...@jsoftware.com
You can make the "p" into an adverb argument:

roundm=:{{([: <. +&0.5) &. (*&(10^m)) }}

2 roundm 51.1234

51.12

2 roundm 51.1264

51.13

Not exactly what you were seeking. Also, you might look at :. which allows you to define an inverse, but using dyads makes it hard to use.



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

Roland Senn

unread,
Sep 9, 2024, 10:19:54 AMSep 9
to forum, Clifford Reiter
Many thanks! The {{(...)}} way to define verbs is new to me. Where is this syntax documented/described?

Gilles Kirouac

unread,
Sep 9, 2024, 11:07:45 AMSep 9
to fo...@jsoftware.com

Henry Rich

unread,
Sep 9, 2024, 12:23:56 PMSep 9
to forum
Dyads make inverses trickier. x u^_1 y is

x&u^_1 y

which underlies the J rule that 'x is control information, y is data'. 

If (up) and (down) has been defined to take the number of digits as x and the value as y, they would be be inverses. 

Henry Rich 

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

More Rice

unread,
Sep 9, 2024, 10:17:45 PMSep 9
to fo...@jsoftware.com
Yes, you've the valence of u and v reversed.

the language specifies:

   x u&.v y ↔ vi (v x) u (v y)  NB. Ref

in roundu, I would think 'up' survived the monadic execution (not the results you want), but when it hits rnd, J detects it is calling the monadic verb there with x and y and issues the domain error.

in rounduu case, the domain error is from the obverse portion of 'up'. (And that's the more interesting part ...)

Henry, but wouldn't J assume v is always monadic (in this case) and would attempt only to find its monadic (not dyadic) obverse instead?


thanks 

Maurice

Roland Senn

unread,
Sep 10, 2024, 4:42:13 AMSep 10
to forum, More Rice

Many Thanks! This explains everything!


I clicked on the (under) link in the NuVoc and landed on the page https://code.jsoftware.com/wiki/Vocabulary/ampdot. There the 2 very important formulas

   u&.v y ↔ vi u v y

   x u&.v y ↔ vi (v x) u (v y)

are missing.


How do I navigate from the main  Wiki page to this excellent https://www.jsoftware.com/help/dictionary/d631.htm page?


@Henry: I suggest to add these 2 formulas to the page linked by NuVoc?

trx2358...@yahoo.com

unread,
Sep 10, 2024, 5:01:24 AMSep 10
to Digest Recipients
On the Wiki page:  https://code.jsoftware.com/wiki/Vocabulary/ampdot 

There is a link “Through to Dictionary” near the top which should bring you to the page you want.

Roland Senn

unread,
Sep 10, 2024, 5:11:55 AMSep 10
to forum, trx2358...@yahoo.com
Excellent! Thanks!

Jan-Pieter Jacobs

unread,
Sep 10, 2024, 6:47:22 AMSep 10
to fo...@jsoftware.com

I agree a formula like that would be more clear, particularly for &.: .

For &. they are not entirely precise, as they do not take into account that &. imposes the rank of v on u:

   *:^:_1 +/ *: 3 4
5
   +/&.*: 3 4
3 4

   +/&.:*: 3 4

5

The latter result should, according to the formula, be the same, but is not, because in the later executes +/ at rank 0 (the rank of *:).

I think the formula should read (and similarly, the dyadic case):

u&.v y <->  v^:_1 u"rv v y, with rv=: 0{.v b.0, i.e. the monadic rank of v.

That said, the wiki is a wiki, you could add it yourself if you want to...

Jan-Pieter

Reply all
Reply to author
Forward
0 new messages