Talk:Forward difference

Revision as of 23:01, 26 August 2008 by rosettacode>DanBron (response to TBH)

What's the forward difference of one element? --Mwn3d 07:17, 11 January 2008 (MST)

With regard to pure mathematics I suppose it is undefined. It is natural, however, to extend it by definition so that the forward difference of a list of one element is the empty list. That's how the J code resolves it, too. --TBH 07:31, 11 January 2008 (MST)
I guess the FD of an empty list should just be another empty list then? These corner cases always get you. --Mwn3d 07:39, 11 January 2008 (MST)
Yes, that's the way to handle receiving an empty list. (A similar "corner case" has been discussed here.)
One of the things I appreciate about J is how many of these exception-situations have been resolved within the language itself. In this instance both the single-element and empty-list possibilities require no specific code. --TBH 09:45, 11 January 2008 (MST)

It is very nice to see the Python entry. Studying it has improved my grasp of that language. --TBH 09:45, 11 January 2008 (MST)

With regard to the replacement of ((}. - }:) ^:) by (2&(-/\)): I agree that a solution in the form of a verb is somewhat better than a solution that is an adverb, although the benefits strike me as subtle and minor. I think the original solution is worth retaining as an example because of its form. It is not only a different algorithm, it is another strong example of how tacit form allows one to "code the concept." These two solutions complement one another, so both should be included. Contrary to the comment upon replacement, the new program is not shorter than the first solution. This is demonstrated by the following J interaction:

   #;:'(}. - }:) ^:'
6
   #;:'2&(-/\)'
7

--TBH 21:13, 20 August 2008 (UTC)

Yep, both solutions could be retained. I'll put the orig back in a moment. To address your specific comments:
I actually think that 2 -/\ y is a clearer expression of the concept of forward differences. That is, I think of a forward difference as "inserting a - between each pair of numbers", and it takes a moment for me to realize that's equivalent to subtracting the curtail from the behead. I just want to tell J "insert a - between each pair of numbers", which is exactly what 2-/\y does.
Of course, this is entirely subjective: it depends on the way you think about the problem. So you may think of "forward differences" exactly as "subtracting the behead from the curtail". In fact, I think some of the other languages calculate their results exactly that way, so the original solution may serve better as a "direct translation".
Regarding verbal vs adverbal: I don't think the differences are minor (though they may be subtle). The most compelling difference I see is that 2&(-/\) is how you would code the simple forward difference (i.e. as a monad). The fact that it works as a dyad to produce the Nth forward difference (for any N), without a single change, really highlights J's value as a notation. Put another way, I find it pleasant that monad is the dyad with an implicit left argument of 1, which is the "normal use case".
A secondary (but still important) difference is generality: Verbal solutions can be easily extended with rank, but it's difficult to slice-and-dice arguments to adverbs. For example, how would you recreate this result using the original solution?
   (3 2 3) 2&(-/\)"_1 ?. 3 5 $ 10
 16 _20  0
 16 _14 11
_17  22  0
With regard to length, my metric was # rather than #@;:, as in :
   #'(}.-}:)^:'
9
   #'2&(-/\)'
7
I chose # because the comment on the solution specifically highlighted succinctness, and total length is the metric of succictness for the solution's target audience (i.e. developers unfamiliar with J, who we're trying to impress).

DanBron 23:01, 26 August 2008 (UTC)

Return to "Forward difference" page.