Jump to content

Talk:Forward difference: Difference between revisions

reorg response
(response to TBH)
(reorg response)
Line 1:
== forward distance of one number ==
 
What's the forward difference of one element? --[[User:Mwn3d|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. --[[User:TBH|TBH]] 07:31, 11 January 2008 (MST)
Line 4 ⟶ 6:
:::Yes, that's the way to handle receiving an empty list. (A similar "corner case" has been discussed [[Talk:Maximum_subarray|here]].) <br>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. --[[User:TBH|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. --[[User:TBH|TBH]] 09:45, 11 January 2008 (MST)
 
== J: verb vs adverb ==
 
With regard to the replacement of ((}. - }:) ^:) by (2&(-/\)):
Line 17 ⟶ 21:
:Yep, both solutions could be retained. I'll put the orig back in a moment. To address your specific comments:
 
:I actually think that <tt>2 -/\ y</tt> is a clearer expression of the concept of forward differences. That is, I think of a forward difference as "inserting a <tt>-</tt> between each pair of numbers", andwhich itis takesexactly awhat moment<tt>2 for-/\ mey</tt> tells J to realizedo; that'sit equivalenttook me a moment to realize subtracting the curtail from the behead. I just want to tell J "insert a <tt>-</tt> between each pair of numbers", which is exactly what <tt>2-/\y</tt> doesequivalent.
 
: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 mostprimary compellingargument differencefor Ia seeverb issolution thatruns <tt>2&(-/\)</tt>like isthis: how youwe wouldhave codetwo thenoun simpleinputs forwardand differencewant (i.e.to asproduce a monad).noun output, Thewhich factis thatthe itvery worksdefinition asof a dyaddyadic toverb. produce All the <tt>N</tt><sup>th</sup>arguments forwardare differencesupplied (forat any"run <tt>N</tt>)time" not "definition time", withoutand ano singlenew changeverbs are produced, reallyso highlightsthe J'sadverb valuedoes asnot abenefit notationus. PutYet anotherit way,costs Ius findplenty: itadverbs pleasantare thathard monadto isuse thelike dyadverbs. with anFor implicitexample, lefthow argumentwould you write the equivalent of <tt>1+/@(2&(-/\))</tt>, which(the issum of the "normalforward usedifferences) case".without rewriting your the adverb as a verb?
 
: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 originaladverb solution?
(3 2 3) 2&(-/\)"_1 ?. 3 5 $ 10
16 _20 0
Line 29 ⟶ 33:
_17 22 0
 
:Or even this (however contrived)?
:With regard to length, my metric was <tt>#</tt> rather than <tt>#@;:</tt>, as in :
(-:@#`],:<@#`+:) 2&(-/\)"1 ] 16 7 82 4 NB. Apply different _verbs_ (i.e. a multidim array of _verbs_ is an argument)
84 _153 0 0
0 0 0 0
0 0 0 0
0 0 0 0
32 14 164 8
18 _150 156 0
168 _306 0 0
474 0 0 0
 
:You're right that the adverb is a concise expression of the concept, which emphasizes J's strengths. I find the verb solution another compelling example of that: <tt>2&(-/\)</tt> 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 <tt>N</tt><sup>th</sup> forward difference (without a single change) 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 <tt>1</tt>, which is the "normal use case".
 
:Finally, With regard to length, my metric was <tt>#</tt> rather than <tt>#@;:</tt>, as in :
#'(}.-}:)^:'
9
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.