Integrate with If and Which
- To: mathgroup at smc.vnet.net
- Subject: [mg20167] Integrate with If and Which
- From: "L. Dwynn Lafleur" <lafleur at usl.edu>
- Date: Sun, 3 Oct 1999 21:07:36 -0400
- Organization: University of Louisiana at Lafayette
- Sender: owner-wri-mathgroup at wolfram.com
It has been pointed out before in this newsgroup that Mathematica integrates some conditional functions but not others. For example, consider the following text translation of a notebook from version 4: In[1]:= f[u_] := If[u < 0, u, u^2]; g[u_] := Which[u < 0, u, u >= 0, u^2]; In[3]:= Integrate[f[u], {u, -1, 1}] Out[3]= -(1/6) In[4]:= Integrate[g[u], {u, -1, 1}] Out[4]= Integrate[Which[u < 0, u, u >= 0, u^2], {u, -1, 1}] Functions f[u] and g[u] are mathematically identical integrands, but Mathematica integrates only the former. You can force numerical evaluation of the latter by wrapping it in N[]. My question is, "What is the fundamental difference between If and Which that makes Mathematica treat them differently?" As I said above, this Mathematica "feature" has been pointed out before and ways to avoid it have been described, but I don't recall a post giving the reason for the behavior. I guess I am just curious to know if there is a logical principle involved. Dwynn -- ========================================== L. Dwynn Lafleur Professor of Physics University of Louisiana at Lafayette lafleur at usl.edu ==========================================