Message Boards Message Boards

5 Replies
4 Total Likes
View groups...
Share this post:

Infinite expression in function defined at singularity when in List

Posted 9 years ago


Why does this happen? I have a function where I define a value at the singularity. When called, it returns the proper value f[1] = 1, but when called in a List, it returns 1/0!

In[2774]:= f[x_] := 1/(1 - x);
f[1] = 1;
f[{0, 1}]

Out[2776]= 1
   During evaluation of In[2774]:= Power::infy: Infinite expression 1/0 encountered. >>
Out[2777]= {1, ComplexInfinity}

Any thoughts?



POSTED BY: Bryan Adomanis
5 Replies

That doesn't solve the problem however. It just makes the function not evaluate when given a list.

Another solution is to use a function attribute like Listable to define the functions behavior for a list.

SetAttributes[f, Listable]
POSTED BY: Sean Clarke
Posted 9 years ago

Also works fine, thank you.

POSTED BY: Bryan Adomanis
In[40]:= f[x_] := If[x != 1, 1/(1 - x), 1]

In[41]:= f[1]

Out[41]= 1
POSTED BY: S M Blinder

You can use Trace to see how the evaluation unfloads:

f[{0, 1}]

1/(1 - {0, 1})

1/{1, 0}

{1/1, 1/0}

What do you want your function to do with a list? A simple solution to your problem is to Map f over the list:

f /@ {0, 1}
POSTED BY: Sean Clarke
Posted 9 years ago

Yes, this will work! I typically just make Table-based functions--never really used Trace/Map before, so I had not thought of incorporating it in my problem-solving. I see their value, now!

Thank you, Sean!

POSTED BY: Bryan Adomanis
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract