Calling all Dfnistas!

General APL language issues

Calling all Dfnistas!

Postby paulmansour on Wed Apr 10, 2024 3:27 pm

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.
paulmansour
 
Posts: 430
Joined: Fri Oct 03, 2008 4:14 pm

Re: Calling all Dfnistas!

Postby Phil Last on Fri Apr 12, 2024 1:38 pm

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.
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Calling all Dfnistas!

Postby Phil Last on Fri Apr 12, 2024 1:50 pm

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.
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Calling all Dfnistas!

Postby paulmansour on Fri Apr 12, 2024 4:36 pm

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?
paulmansour
 
Posts: 430
Joined: Fri Oct 03, 2008 4:14 pm

Re: Calling all Dfnistas!

Postby Phil Last on Sat Apr 13, 2024 6:30 pm

I never could find a requirement for that - though I did try - perhaps Adam may have done?

Apologies for lack of diacritic Adam.
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Calling all Dfnistas!

Postby Adam|Dyalog on Mon Apr 15, 2024 6:23 am

∇∇ 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↓⍵}
User avatar
Adam|Dyalog
 
Posts: 143
Joined: Thu Jun 25, 2015 1:13 pm

Re: Calling all Dfnistas!

Postby Phil Last on Mon Apr 15, 2024 10:33 pm

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.
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex


Return to Language

Who is online

Users browsing this forum: Google [Bot] and 1 guest