Question: Converting piecewise to if selection statement

Hi guys,

 

I would like to convert a piecewise defined function of two variables into an if structure
Example :

F := (x,y) -> piecewise(x < 0, piecewise(y < 0, 0, 1), piecewise(y < 0, 1, 0));

What I expect is something like (the indentation is just for fun)
if x < 0 then
   if y < 0 then 0 else 1 end if;
else 
   if y < 0 then 1 else 0 end if;
 end if


I tried the following :

convert(F(x,y), `if`)  # but it only converts the "outer x condition" and keeps the "inner y conditions" unchanged

And next this :

map(u -> convert(u, `if`), F(x,y)):   # fails to give m
# and
map(u -> convert(u(x,y), `if`), F(x,y)): 
# ...

without success.

Can anoybody help me please.
I am also interested in an explanation of the reasons why the previous command do not work.

Thanks all

Please Wait...