Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: A problem with Thread[]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111414] Re: A problem with Thread[]
  • From: Themis Matsoukas <tmatsoukas at me.com>
  • Date: Sat, 31 Jul 2010 02:42:03 -0400 (EDT)

Here is a workaround:

Thread[f[{-1, 0, 1}, 0]] /. f -> MyArcTan
{\[Pi], 0, 0}

The problem is that Thread first evaluates and then threads (see ref/Thread under possible issues). To see what is going on, redefine your function in the simpler form:

MyArcTan2 := Function[{x, y}, If[x == 0 && y == 0, 0, ArcTan[x, y]]]

and execute

Thread[MyArcTan2[{-1, 0, 1}, 0]]
If[{-1, 0, 1} == 0, 0, ArcTan[{-1, 0, 1}, 0]]

This shows that instead of threading, Mathematica tries to evaluate the function with first argument {-1,0,1} and second argument 0, causing the If statement to choke. If at least one of these argument is not zero, then the If[] executes ArcTan[x, y], which is why the following still works:

Thread[MyArcTan[{-1, 0, 1}, 1]]
{(3 \[Pi])/4, \[Pi]/2, \[Pi]/4}

Themis


  • Prev by Date: Re: Cannot load example data
  • Next by Date: Re: Packages designed for use in player pro
  • Previous by thread: A problem with Thread[]
  • Next by thread: Re: A problem with Thread[]