Different results using f@expr and expr // f in Mathematica -



Different results using f@expr and expr // f in Mathematica -

i playing around prefix , postfix operators (@ , // respectively) , ran next issue.

given next code, evaluate in same exact way:

hold[matrixplot@sort@data] // fullform (* hold[matrixplot[sort[data]]] *) hold[data // sort // matrixplot] // fullform (* hold[matrixplot[sort[data]]] *)

however, given next expressions, different results:

functionexpand@abs'[0] (* abs'[0] *) abs'[0] // functionexpand (* 0 *)

i'm not quite sure why is. in dozens of other snippets of code i've had, f@expr, expr // f, , f[expr] evaluate same result. why 1 particular case give result?

this precedence issue. @ has higher precedence //. see going on, place cursor on functionexpand in both cases, either cmd+. (on os x) or ctrl+. on else, , end selecting things precedence.

another way see utilize trace:

functionexpand@abs'[0] // trace (* -> {{{functionexpand[abs],abs},abs^\[prime]},(abs^\[prime])[0]} *)

while

abs'[0] // functionexpand//trace (* -> {functionexpand[(abs^\[prime])[0]],0} *)

in particular, notice how in first case mma first evaluates functionexpand[abs], obtaining abs, continuing. exactly due how @ binds compared //.

edit: inspired @leonid's comment, informative:

hold[functionexpand@abs'[0]] // fullform hold[abs'[0] // functionexpand] // fullform (* -> hold[derivative[1][functionexpand[abs]][0]] hold[functionexpand[derivative[1][abs][0]]] *)

which much improve demonstration of going on.

wolfram-mathematica

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -