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?
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.
To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
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?
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