Page 1 of 1

Calling all Dfnistas!

Posted: Wed Apr 10, 2024 3:27 pm
by paulmansour
Much to my amusement, the opportunity to productively use ∇∇ arose just the other day - a first for me.

This brings up the question: why not just a single ∇ for operator self-reference? I don't see how both a single and double del would be meaningful in the same function or operator. However, as I write this, it dawns on me that in an operator with nested dfns, an inner dfn might want to refer to itself and to the outer operator*. Hmm...is that why?

*I hope I never find myself in that situation.

Re: Calling all Dfnistas!

Posted: Fri Apr 12, 2024 1:38 pm
by Phil Last
Hey Paul

Without reference to the reference this is the way I look at it. First off and without trying it I think that within a dfn ∇∇ has no meaning.

But within a dop, as within a dfn, means the current function.

So within a dop it's not a reference to itself but to the derived function; that is: the dop itself bound with its operands.

Now lets say we've written an operator - in this case an adverb (monadic operator) - that has a wide range of application.
.
lm←{
     ⍵ ⍺⍺{⍺≡⍵:⍵ ⋄ ⍵ ⍺⍺ ∇∇ ⍺⍺ ⍵ ⋄ ⍵:⍵≡⍺}⍺⍺ ⍵
⍝ limit ←→ ⍣≡
 }
Here's one I wrote earlier - much earlier - before JS implemented the power operator .

This use of ∇∇ at the time was completely fanciful as even then the operator could have been written much more succinctly with replacing the whole of ⍺⍺ ∇∇ ⍺⍺ and the final guard ⍵:⍵≡⍺ missing entirely as it follows an unassigned result returning expression.

My reason was that in developing the dop it had begun to look rather symmetrical and I then spent as long folding it into a palindrome as I had in working out the mechanics.

The final version waa demonstrated by JS in a silly video that's probably still up in YouTube. It is nowhere used in any of my subsequent code and it's slightly more elegant derived adverb equivalent ⍣≡ is used only twice therein.

Nor have I had recourse to use ∇∇ elsewhere - not once.

Re: Calling all Dfnistas!

Posted: Fri Apr 12, 2024 1:50 pm
by Phil Last
Again without recourse to actually trying it I don't believe your suggestion would be possible to reference the outside dop from a nested dfn therein.

Or let's say it may be possible because no-one ever got round to writing code that would prevent it but remembering what I do of JS's hopes and aims I doubt very much that he would have approved of its use.

Re: Calling all Dfnistas!

Posted: Fri Apr 12, 2024 4:36 pm
by paulmansour
Doh!

So my use of
⍺ ⍺⍺ ∇∇ ⍵
Could easily be replaced by
⍺ ∇ ⍵
Obviously now in hindsight. So then the only real use of ∇∇ is if the operands might vary on each recursive call?

Re: Calling all Dfnistas!

Posted: Sat Apr 13, 2024 6:30 pm
by Phil Last
I never could find a requirement for that - though I did try - perhaps Adam may have done?

Apologies for lack of diacritic Adam.

Re: Calling all Dfnistas!

Posted: Mon Apr 15, 2024 6:23 am
by Adam|Dyalog
∇∇ is especially useful when normalising or iterating operands, most commonly with array operands, but it can also happen with function operands:

The right operand of Rank (⍤) is normalised to ⌽3⍴⌽ so one could imagine an implementation of Rank or a similar operator containing the guard
2≥≢⍵⍵:⍺(⍺⍺∇∇(⌽3⍴⌽⍵⍵))⍵
The At operator can collapse a function right operand to an array operand with code like
⍺(⍺⍺∇∇((⍵⍵(/⍥,)⍳⍤⍴)⍵)⍵
An nth derivative operator (assuming D is a simple derivative operator) can be stated as
{⍵⍵=1:⍺⍺D⍵ ⋄ ((⍺⍺D)∇∇(⍵⍵-1))⍵}
And here's a backscan:
{0≡≢⍵:⍬ ⋄ h←⍺ ⍺⍺⊃⍵ ⋄ (⊂h),h⍺⍺∇∇1↓⍵}

Re: Calling all Dfnistas!

Posted: Mon Apr 15, 2024 10:33 pm
by Phil Last
Adam|Dyalog wrote:especially useful when ... iterating ... array operands
Thanks for that Adam. I've tried and, I think, succeeded in doing that but always more long-winded by demoting the array operand as an argument to reduction applied to an inner dop rather than linking it with a recursive call to the dop itself.

Your second and third examples look interesting and non-trivial but the guard in the first could most easily be replaced by something like i j k←⌽3⍴⌽⍵⍵ which, if the requirement is for 3=≢⍵⍵, is likely to be the next step.

The ⍺⍺∇∇ in your last example could of course be replaced with as with Paul's unseen example and my palindrome.

But thnks for demonstrating that ∇∇ is at least non-trivially useful.