« first day (1906 days earlier)      last day (171 days later) » 

6:18 AM
0
Q: Implement Map function in APL Language

Abdellah Mchati MecI have created the map function using Scheme, but I want to implement it in APL. (define (map func lstt) (cond ((null? lst) '()) (else (cons (func (car lst)) (map func (cdr lst)))) ) ) The map function takes two arguments: a function: func (like double: *2) and list of integers: lst Calling...

 
 
9 hours later…
2:52 PM
i am not prepared for today's apl quest
 
@PyGamer0 If you start preparing now, you'll be fine: problems.tryapl.org/psets/2014.html
 
You can do it within 5 minutes :)
 
and done
@Adám that was easy..
 
So time left to make it tacit ;)
 
yeah i am trying to do that
apling is hard to do on a phone
 
2:58 PM
I have the most untacit solution
 
I am little bit stuck with making it tacit
@Razetime by using many '{' & '}'?
 
      3 4(⊂,⊢)5
┌┬┬─┬┬┬┬─┬─┐
│││5││││5│5│
└┴┴─┴┴┴┴─┴─┘
clearly i still dont understand trains
 
@Richard tacit is the lack of explicit names
sorry, absence
 
@PyGamer0 (3 4⊂5),(3 4⊢5)
Welcome to the APL Quest! Today's quest is It Is All Right:
> Write a dfn that takes the length of the legs of a triangle as its left argument, and the length of the hypotenuse as its right argument and returns 1 if the triangle is a right triangle, 0 otherwise.
 
{(×⍨⍵)=+/×⍨⍺}
 
3:00 PM
OK, that's a nice start.
 
{(+.×⍨⍺)=×⍨⍵}
 
^^^ bad
@Richard nice
 
{(a b c)←⍺,⍵⋄(c*2)=(a*2)+b*2}
 
o_o
 
@Richard That's basically the same, but maybe it can inspire something clever.
@Razetime Surely you don't need to do a←⍺
This is a classic split-compose: We want to apply f on the left argument and h on the right argument, and g between the results.
 
ovs
3:03 PM
With Dyalog 18: =∘(+/)⍨⍥(*∘2)
 
((+/⊣)=⊢)⍥(×⍨)
 
Very good, both.
But there's one thing you're missing (if you're looking for short code)
 
=⍥(+/×⍨)
 
Indeed.
Or . instead of /
 
ah, ok. Didn't find out where to put all the parentheses
and the right tacks
 
3:05 PM
@Razetime Can be rephrased as =∘(+/)⍨⍥(×⍨) or =∘(+/)⍥(×⍨)⍨
 
yeah but i don't like the look of either of those
 
How about +/⍤⊣ instead of (+/⊣)?
 
+/⍛=⍥(×⍨) with a hypothetical
 
@Adám sure ok
 
@dzaima Indeed. Although I'd expect +.× to be be optimised on scalars so it skips the +. part.
Anyone likes {⍵=2*∘÷⍨+/⍺*2}?
(I'd be nice if we could write {⍵=√+/⍺*2})
 
3:09 PM
neeeded apl builtins: ⍛√
 
=∘(+/⍢(×⍨))⍨ would be nice too.
 
@dzaima does your apl support ^^?
 
It does.
 
@PyGamer0 well, there is also no square
but power 2 instead
 
Yeah, but * has two inverses: and
Really, * is anti-log. Power should be *⍨
 
3:11 PM
@PyGamer0 TIO
 
Because the parameter goes on the left, and the main data on the right.
 
ngn/k because i can program it on a phone: {y=%+/x*x}
 
Right, even K with hard limits on number of built-ins, has square root.
Anyone up for basing a solution on ?
 
Could you make the solution tacit step by step if you don't mind?
 
@Richard Which one?
 
3:15 PM
pYGamer or mine
 
{(+.×⍨⍺)=×⍨⍵}
((+.×⍨⊣)=(×⍨⊢)) is a direct tacit equivalent.
(+.×⍨⍤⊣=×⍨⍤⊢) using atop operator.
 
thanks!!
 
(+.×⍨⍤⊣=+.×⍨⍤⊢) gives the same result.
=⍥(+.×⍨)
 
the last one I don't understand
 
Do you follow why (+.×⍨⍤⊣=+.×⍨⍤⊢) gives the same as (+.×⍨⍤⊣=×⍨⍤⊢)?
 
3:19 PM
ytes
 
OK, let's say g←+.×⍨ — now we have (g⍤⊣=g⍤⊢)
I.e. = but with both arguments pre-processed by g. That's ⍥g i.e. =⍥g or =⍥(+.×⍨) if we substitute g back into the formula.
 
o wow
 
We could do much the same derivation with {(×⍨⍵)=+/×⍨⍺} — ending with =⍥(+/×⍨)
 
ovs
@Adám I guess we could use complex numbers for the 2-norm: =∘(|⊢/+¯11○⊃)⍨
 
@PyGamer0 Another built-in needed: ⊕←{⍺+0j1×⍵}
Then we could write |⍤⊕/⍛=
Anyone understands?
 
3:27 PM
I don't...
 
@Richard Do you understand ovs's solution?
 
yes I think so, was just looking at it
 
In TMN, it is saying ⍵=|⍺₂+i⍺₁|
Roger Hui proposed a function (j. in J) which is {⍺+i×⍵} where i←0j1
 
yes
 
(¯11○ is simply 0j1∘×)
And is a proposed operator similar to but preprocesses its left argument with the left operand. Cf. which preprocesses its right argument with the right operand.
 
3:31 PM
thanks
 
⊕/ takes a 2-element vector and uses the elements as real and complex part.
|⍤⊕/ is the absolute value of that, i.e. the hypotenuse.
|⍤⊕/⍛= is just like = but preprocesses its left argument by computing the hypotenuse of a right triangle with those two legs.
 
:) like magic. I'll study it this week, thanks
But I think I understand now
 
@ovs Shouldn't it be possible to use 4○?
 
@Adám that'd be a really cool builtin though
 
@Richard You can experiment with it:
      Ⓞ←{⍵ ⍵⍵⍨⍺⍺ ⍺}
      J←{⍺+0j1×⍵}
      f←|⍤J/Ⓞ=
      2 3 f 4 ⋄ 3 4 f 5
0
1
 
ovs
3:37 PM
@Adám I'm sure you can use some trigonometric functions for that, but I don't see how (1+⍵*2)*0.5 helps
 
@KamilaSzewczyk I'd say it has beauty:
⊕←{⍺←0 ⋄ ⍺+¯11○⍵}   ⍝ NB: 0=+/⍬
⊗←{⍺←1 ⋄ ⍺ׯ12○⍵}   ⍝ NB: 1=×/⍬
 
@Adám yes! (1+(⍵*2)÷(⍺*2))
 
@Richard ?
 
for some reason i like {¯9 ¯11+.○⍺ ⍵} more
even though it's objectively worse
 
ovs
In that case I would rather use {1 0J1+.×⍺ ⍵}
 
3:41 PM
also good idea
circle is mostly useless but really climatic
 
0J1⊥,⍨
 
oh that's really smart
 
@KamilaSzewczyk (What does "climatic" mean in this context?)
 
i like the fact that i can do e.g. {÷/1 2○⍵} for the tangent
of course i can just use 3
but it's an illustration how circle can compute many values at once
for some reason this feels very arrayish for me
 
@KamilaSzewczyk ÷.○
 
3:43 PM
even though in the end many functions circle provides are trivial to implement outside of the circle
i haven't really seen the fancy circle usage with inner products too often so far
 
Anyway, I think we've veered off from the challenge.
Next week, I won't be here, so RikedyP will lead the How Tweet It Is Quest instead. I'll still make the follow-up video.
 
one excellent use for circle i thought of was computing the Jacobian matrix in polar-Cartesian transformation
 
○4 = (1 + ⍵*2) * 0.5
a*2 + b*2 = c*2
(a*2 + b*2) * 0.5 = c
a × (1 + (b*2)÷(a*2)) * 0.5 = c
a × ○4 b÷a = c
 
{2 2⍴1 (-⍺) 1 ⍺×2 1 1 2○⍵} isn't really that visually appealing though
 
No one found the 5 character one?
 
3:50 PM
@rak1507 No.
 
÷⍥⌹≡÷
 
Whoa.
 
wow
 
:)
 
Can you explain?
 
3:52 PM
matrix division used. incredible :O
 
⍺ (÷⍥⌹≡÷) ⍵
((⌹⍺)÷(⌹⍵)) ≡ (⍺÷⍵)
((⍺÷+/⍺×⍺)÷(÷⍵)) ≡ (⍺÷⍵)
((⍺÷+/⍺×⍺)×⍵) ≡ (⍺÷⍵)
(⍵÷+/⍺×⍺) ≡ (÷⍵)
((⍵×⍵)÷+/⍺×⍺) ≡ 1
(⍵×⍵) ≡ (+/⍺×⍺)
the trick is that ⌹⍺ is ⍺÷+/⍺×⍺ so it does the sum of squares bit for you, just have to 'extract' it into a usable form
 
Fails if any argument is all-zero, but that's very much and edge (no pun intended) case.
 
yeah good point
 
@Adám {⍵=(1↓⍺)×4○ ÷/⍺}
 
4:17 PM
@Adám nice
@rak1507 o_o
 

« first day (1906 days earlier)      last day (171 days later) »