Square snowflake
Produce this square snowflake.
XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX
XX X X X X X X X X X X X X X X XX
X XXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXX X
XX X X X X X X X X X X X X ...
@AntonDyudin No, it is {A=+/,⍵}⌺3 3 that is optimised for any constant A
@AntonDyudin Unfortunately, 819⌶ isn't scalar, though I think it is obvious that it should be. It's 18.0 replacement, ⎕C isn't scalar either, but isn't limited to characters either.
@Bubbler it's not that the figure is incorrect. It is just that the trapezoid rule is being used over n intervals and the Simpson's rule is being used over n/2, where n is even. And thus the comparison between T and S is not as fair and not as obvious
@Bubbler but the point is that Simpson is more accurate because it is more complex, and usually Simpson's rule in a subinterval is defined at the expense of an auxiliar point which is the midpoint of the interval.
The thing here is the spirit of the methods, as T in an interval is the linear interpolation of the function in that interval and S in an interval is supposed to be quadratic interpolation in that interval; yes, at the expense of an auxiliar point, but that is why S becomes order 2 and T is only order 1. You are supposed to compare the methods in the length of the intervals used for the interpolations.
Of course that you can (rightfully) state that for the same number of intervals, S uses computes the function in more places. What I'm arguing is that from the numerical integration point of view, this comparison makes more sense
@Bubbler but then again, maybe I got a bit carried away; it wasn't really an important thing. I just wanted to voice my confusion when I checked the figure
@xpqz I think the real issue is "is one coding at the same level of abstraction"? If I see a train (or any bunch of primitives) or a golf trick or an embedded assignment dangling off the end of an :IF statement in a trad function, not good for readability. If things are in a well-defined and well-named dfn, where attention has been paid to every detail to make things short, its generally OK (though I still avoid embedded assignment.)
Clarifying question: I do have an app called RIDE, but I usually use the one that's just called 'Dialog 17.0' (now 17.1). Is that still RIDE in disguise?
@AviF.S. just tested, the file i named definitely affects the Dyalog version of launching RIDE, can't really help other than try tracing where else could the configs be stored
@Adám Am curious in general if there are any other more APL-esque constructs for while/for structures without using the ∇WHILE-type constructs. They always struck me as not in the spirit...
I've often tried abusing the ⍣ operator, but as it's not meant for it, it usually doesn't work. Sometimes it does, but even then it's obscenely obfuscated
Of course, you don't have to write everything inline. You could use a separate function for the main processing.
In your left operand, you can of course place your done-condition at the top or at the bottom, or anywhere else.
But let's say instead that we don't want the condition to be based on the data processed. Rather, we want to periodically read an outside value to decide whether to continue or not.
You can try this in your local APL: done←0 ⋄ {⎕←⍵⊣⎕dl 5}⍣{done}&'work'
It will run in the background, printing "work" every 5 seconds.
Wait, the solution given before of {⊃⍣(1<|≡⍵)⊢⍵}⍣≡⊂⊂⊂⊂2 2⍴'ok' was a general case fix because ⊂ might not always have an inverse, you said. But in the end, it uses ⊃ anyway...
Other than this, it is actually much the same as with ⍣: Establish the stop condition with a guard (or a control structure in a tradfn), and do the work otherwise.
@RGS Dyalog looks ahead if the result will be used. This is also in effect for "shy" functions and assignments. Sometimes it will not even compute something if the result won't be used.
@AviF.S. should be under ~/.config/Ride-4.3/ or similar. you can find out the exact path by pressing f12 and typing D.el.app.getPath('userData') in the js console
No problem. Let's finish with an exercise: I assume you're all familiar with the Fibonacci sequence. Try implementing Fib n (which returns the nth Fibonacci number) using ⍣ and recursion.
If I wanted to recurse on a function that takes a left and a right argument, how could I do this "trick" of carrying the calculations down the recursion..?
Is there a better way to do that, aside from the closed form, which sort of ruins the recursive point? And aside from the matrix version, which is more APL-esque but less... well, maybe I'm just being lazy
@Adám But that is because you took the example to be the Lucas numbers, which follow the same "add the previous two" pattern of Fibonacci and you abstracted away the seed
@AviF.S. I disagree. Haskell has spread this notion of recursion being "the" functional way to do things, but this is just as functional. You're not telling APL exactly what to do, but how ("thrice") you want your function applied.
@dzaima That'd have been a possibility, but I wanted to align myself with the refcard which uses X/Y and f/g like that.
Hmm, well if Haskell is a source of misunderstandings, I have to agree, that was my intro the functional world (though I've played around with Lisps as well)
But I still would have thought it imperative...
Because you are telling it precisely what to do, namely multiply the matrix by itself $n$ times. I suppose I'm not seeing the functional aspect
You're also telling it exactly what to do when you recurse. Pretty much all programming is telling the computer exactly what to do. (Except in Prolog, of course.)
In computer science, imperative programming is a programming paradigm that uses statements that change a program's state. In much the same way that the imperative mood in natural languages expresses commands, an imperative program consists of commands for the computer to perform. Imperative programming focuses on describing how a program operates.
The term is often used in contrast to declarative programming, which focuses on what the program should accomplish without specifying how the program should achieve the result.
== Imperative and procedural programming ==
Procedural programming is a type...
Ah, not only was I unclear in what I was saying, which you caught and corrected (ie logical programming/Prolog), but you're entirely right on the matter
@ngn Not sure how I'm failing at all this, but am unable to find the js console in RIDE, or in the brief moments I searched the help manual. And, of course, I had to be on a Mac so my function key bindings don't work as they should
_LinRec_ ← {
⍝ Dyadic operator that allows one to generate any sequence that arises from a linear recursion.
⍝ The left operand gives the weights of the sum and the right operand gives the initial values.
⍺ ← ⍺⍺
1=⍵: ⊃⍺
(⍵-1) ∇⍨ (-≢⍺⍺)↑⍺,⍵⍵+.×⍺
}
but had the syntax for the dop all mixed up and as a side-effect I wasn't being able to use the guard. at first I thought I couldn't use it, but as the dop kept insisting on not working, I realized maybe the problem wasn't the guard
Also, the first time I was told about operators, I thought they were supposed to return dfns, but the dop I included above just seems to be working as a regular dfn, except I have access to 4 arguments instead of 2...
@Adám when I had the guard, at the guard!
but the problem was coming from elsewhere, except it only showed up when executing the guard. but now all is good
@RGS The code in an operator isn't used until the derived function is called. At that point, the operator code specifies how the operands should be used.
@ngn No it's funny, you were right. It wasn't set to what it is in other web browsers (or Chrome). It was F12... But system wide function key mappings override app-specific ones, so when I used it, I simply got the normal system-wide response
@RGS control flow is okay when you're actually controlling program flow, of course you should prefer using array operations where you don't need short-circuiting
Hmm. My experience so far has been that recusion is slow(er), but maybe it's if you build up a large accumulator as the ⍺-side of the ∇ call? I way back when wrote a lot of Scheme, and I instinctively reach for recursion. To me, dfns feel very "Scheme-y".