14

I need define the function with parameter so I could directly generate a power series expansion. The problem is that in some cases ConditionalExpression appears in output. Here is my code:

S[x_, l_] := 
  (C[1] + 
     Integrate[
       E^(2 Sum[t^i/i, {i, 1, l - 1}])*(1 - t)^2*
         Sum[(l - i*2)*t^i, {i, 1, l - 1}]/((t - 1)*t^l), 
       {t, 1, x}])*
   x^(l - 1)*E^(-2 Sum[x^i/i, {i, 1, l - 1}])/(1 - x)^2; 

Table[S[x, i], {i, 2, 3}] // TableForm
CoefficientList[Series[S[x, 2] , {x, 0, 3}], x]
CoefficientList[Series[S[x, 3] , {x, 0, 3}], x]
CoefficientList[Series[S[x, 3][[1]] , {x, 0, 3}], x]
dionys
  • 4,321
  • 1
  • 19
  • 46
  • 1
    Why not make up a rule (if you are sure of the Trueness of your conditional) rule = ConditionalExpression[a_, b__] -> a and apply it to the output? i.e. CoefficientList[Series[S[x, 3], {x, 0, 3}], x] /. rule – gpap Nov 11 '13 at 10:14

4 Answers4

24

A more general way, which can be used for other functions like Solve, is to use Normal.

Integrate[1/x^s, {x, 1, Infinity}]

(* ConditionalExpression[1/(-1 + s), Re[s] > 1] *)

Normal[%, ConditionalExpression]

(* 1/(-1 + s) *)

Edit

It looks like as of version 10, one can just use the one argument Normal:

Integrate[1/x^s, {x, 1, Infinity}]

(* ConditionalExpression[1/(-1 + s), Re[s] > 1] *)

Normal[%]

(* 1/(-1 + s) *)
Greg Hurst
  • 35,921
  • 1
  • 90
  • 136
  • Just as a note for prefix form: Normal@f'[x] does not seem to work. Normal@(f'[x]) rectifies the issue. –  Apr 02 '19 at 13:53
  • 1
    Correct. @ appears above ' in this list: https://reference.wolfram.com/language/tutorial/OperatorInputForms.html. – Greg Hurst Apr 02 '19 at 14:26
9

You can use GenerateConditions->False to eliminate conditions (assuming they do not affect your planned use):

S[x_, l_] := (C[1] + 
     Integrate[
      E^(2 Sum[t^i/i, {i, 1, l - 1}]) (1 - t)^2*
       Sum[(l - i*2) t^i, {i, 1, l - 1}]/((t - 1) t^l), {t, 1, x}, 
      GenerateConditions -> False]) x^(l - 1)*
   E^(-2 Sum[x^i/i, {i, 1, l - 1}])/(1 - x)^2;
Table[S[x, i], {i, 2, 3}] // TableForm
CoefficientList[Series[S[x, 2], {x, 0, 3}], x]
CoefficientList[Series[S[x, 3], {x, 0, 3}], x]
CoefficientList[Series[S[x, 3][[1]], {x, 0, 3}], x]
ubpdqn
  • 60,617
  • 3
  • 59
  • 148
  • I would not recommend using GenerateConditions -> False as there are many cases where adding this option results in Mma either not being able to solve the integral, or returning a different answer than it otherwise would do. In my experience, a better approach is to let it do its thing, and then remove the ConditionalExpression – wolfies Apr 06 '17 at 15:48
6

It might be late to answer this, but I think it's important to add my approach.

I came to the same problem of having ConditionalExpressions in my outputs.

After googling I came about this solution, by using the Assuming[] function.

An example:

Assuming[Re[s] > 1, Integrate[1/x^s,{x,1,Infinity}]

Which gives:

1/(-1+s) 
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
milia
  • 181
  • 1
  • 4
1

Assuming[Re[s] > 1, Integrate[1/x^s, {x, 1, Infinity}]] is the fastest way to do an integral. If you don't know the conditions for which the integral works, you can also use Integrate[1/x^s, {x, 1, Infinity}, GenerateConditions -> False]

Normal[Integrate[1/x^s, {x, 1, Infinity}]] is significatively longer because you must compute the conditions and then throw them away. It can be very long in some cases.

For example,

In[215]:= Normal[Integrate[1/x^s, {x, 1, Infinity}]] // AbsoluteTiming

Out[215]= {0.319937,1/(s-1)}

In[212]:= 
Integrate[1/x^s, {x, 1, Infinity}, 
  GenerateConditions -> False] // AbsoluteTiming

Out[212]= {0.140617,1/(s-1)}

In[214]:= 
Integrate[1/x^s, {x, 1, Infinity}, 
  Assumptions -> s > 1] // AbsoluteTiming

Out[214]= {0.148892,1/(s-1)}

In[219]:= 
Assuming[Re[s] > 1, 
  Integrate[1/x^s, {x, 1, Infinity}]] // AbsoluteTiming

Out[219]= {0.103522,1/(s-1)}
user47938
  • 11
  • 1