# Defining a piecewise function where the conditions are points

I am trying to define the following function in Mathematica:

$$pw=\begin{cases} x y \cos \left(\frac{1}{x^2+y^2}\right) & (x,y)\neq(0,0) \\ 0 & (x,y)=(0,0) \end{cases}$$

I want to use this to calculate the derivative of $pw$ with respecto to $v=(a,b)$ at $(0,0)$ with

$$\lim_{h\to 0} \frac{pw(ha,hb)-pw(0,0)}{h}$$

by writing Limit[(pw[h*a,h*b]-pw[0,0])/h,h->0]. I do not want to worry about the value of $pw$ at $(0,0)$.

(In general, I would like to do this for as many variables as needed).

I can correctly define the function if the conditions are intervals ($x>0$ or $-\pi<y<7\pi$ for instance). However, when the condition is a point, I am at a loss.

I tried:

The naive approach with:

pw[x_,y_]=Piecewise[{{x*y*Cos[1/(x^2 + y^2)], (x,y)!=(0,0)}, {0, (x,y)==(0,0)}}]


A more clever, albeit less general, approach:

pw[x_,y_]=Piecewise[{{x*y*Cos[1/(x^2 + y^2)], x^2+y^2!=0}, {0, x^2+y^2==0}}]


The idea behind this one is that the point $(0,0)$ is the only one that satisfies $x^2+y^2=0$ (because it is a sum of positives). However, this wouldn't work for all points $(a,b)$.

This other thing:

pw[x_,y_]=Piecewise[{{x*y*Cos[1/(x^2 + y^2)], x==0 && y==0}},0]


Which doesn't give anything.

UPDATE: Xavier posted a function that works as I expected:

Piecewise[{{x*y*Cos[1/(x^2 + y^2)], x != 0 || y != 0}}]


However, I am now having trouble with evaluating the limit. As $(a,b)$ could be anything, $pw[ha,hb]$ evaluates to the whole Piecewise function. I want to force $(a,b)\neq(0,0)$ so I tried using Assuming[a != 0 || b != 0, Limit[(pw[h*a, h*b] - pw[0, 0])/h, h -> 0]] which doesn't solve it cause it changes the $x$ and $y$ in the condtion for $a$ and $b$. How could I evaluate the limit?

UPDATE 2: I tried Limit[((Refine[pw[a, b], a != 0 || b != 0] /. {a -> h*a, b -> h*b}) - pw[0, 0])/h, h -> 0] and another function that has nice derivatives. It seems to do the correct operations. I sometimes get a weird answer, but by setting $(a,b)=$some numbers I get nice output.

I'm not sure if this is a correct use of the edit function (updating with progress I mean). Should I delete everything that doesn't contribute to the current problem or leave it to show workings?

P.S.: I'm kind of new here, so please let me know if I can improve my posts format, wording or conciseness-wise. Criticism is welcome.

• Xavier, thanks for the comment. I forgot to say I tried that with another function and it did not work. That other function should have evaluated to 3 when $(x,y)=(0,3)$ and it still spat 0. Similar behaviour can be seend (I think) by changing the condition on what you proposed: pw[x_, y_] = Piecewise[{{x*y*Cos[1/(x^2 + y^2)], x != 2 && y != 0}, {0, x == 2 && y == 0}}] Where $pw[2,3]$ evaluates to 0. What am I doing wrong? – Peanut14 Sep 6 '16 at 23:55
• Sorry, I was typing a response while trying a few things out. The function using || works like a charm. Say I define $pw$ as 25 when $(x,y)=(0,0)$. I tried pw[x_, y_] = Piecewise[{{x + y + Cos[1/(x^2 + y^2)], x != 0 || y != 0}, {25, x == 0 && y == 0}}] That outputs $$\begin{cases} \cos \left(\frac{1}{x^2+y^2}\right)+x+y & x\neq 0\lor y\neq 0 \\ 25 & x=0\land y=0 \end{cases}$$ What is the 0 True doing there? I tried the limit with Limit[(pw[h*a, h*b] - pw[0, 0])/h, h -> 0, Assumptions -> a != 0 && b != 0] but it returns some weird things. What would you suggest? – Peanut14 Sep 7 '16 at 0:16
• Welp, the 0 True doesn't show here. But it does appear in my Notebook. – Peanut14 Sep 7 '16 at 0:18
• – Peanut14 Sep 7 '16 at 0:24