# Infinite expression in function defined at singularity when in List

Posted 8 years ago
5599 Views
|
5 Replies
|
4 Total Likes
|
 Community: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[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? v/r-Ado
5 Replies
Sort By:
Posted 8 years ago
 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 8 years ago
 Also works fine, thank you.
Posted 8 years ago
 In[40]:= f[x_] := If[x != 1, 1/(1 - x), 1] In[41]:= f[1] Out[41]= 1 
Posted 8 years ago
 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 8 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!