Skip to main content
added 464 characters in body
Source Link
Nasser
  • 157.4k
  • 12
  • 175
  • 398

I would just check for the Head.

ClearAll[myIntegrate]
myIntegrate[expr_Times, var_Symbol] := Map[Integrate[#, var] &, Expand[expr]]
myIntegrate[expr_Plus, var_Symbol] := Map[Integrate[#, var] &, expr]
myIntegrate[expr_, var_Symbol] := Integrate[expr, var]

And now call myIntegrate instead of Integrate and Mathematica will figure which wrapper to call on its own.

For example

myIntegrate[x, x]
myIntegrate[3*(1 + x), x]
myIntegrate[x^2, x]

gives

Mathematica graphics

In the above, Expand is used for Head times, to take care of cases such as a*(b+c) and if it is already + then no need to expand. For all other cases, normal Integrate is called. This should take care of all cases you want to map integrate over terms I hope.

I would just check for the Head.

ClearAll[myIntegrate]
myIntegrate[expr_Times, var_Symbol] := Map[Integrate[#, var] &, Expand[expr]]
myIntegrate[expr_Plus, var_Symbol] := Map[Integrate[#, var] &, expr]
myIntegrate[expr_, var_Symbol] := Integrate[expr, var]

And now call myIntegrate instead of Integrate and Mathematica will figure which wrapper to call on its own.

For example

myIntegrate[x, x]
myIntegrate[3*(1 + x), x]
myIntegrate[x^2, x]

gives

Mathematica graphics

In the above, Expand is used for Head times, to take care of cases such as a*(b+c) and if it is already + then no need to expand. For all other cases, normal Integrate is called. This should take care of all cases you want to map integrate over terms I hope.

I would just check for the Head.

ClearAll[myIntegrate]
myIntegrate[expr_Times, var_Symbol] := Map[Integrate[#, var] &, Expand[expr]]
myIntegrate[expr_Plus, var_Symbol] := Map[Integrate[#, var] &, expr]
myIntegrate[expr_, var_Symbol] := Integrate[expr, var]

And now call myIntegrate instead of Integrate and Mathematica will figure which wrapper to call on its own.

For example

myIntegrate[x, x]
myIntegrate[3*(1 + x), x]
myIntegrate[x^2, x]

gives

Mathematica graphics

In the above, Expand is used for Head times, to take care of cases such as a*(b+c) and if it is already + then no need to expand. For all other cases, normal Integrate is called. This should take care of all cases you want to map integrate over terms I hope.

added 27 characters in body
Source Link
Nasser
  • 157.4k
  • 12
  • 175
  • 398

I would just check for the Head. As you are only interested in distributing Integrate over sum. For all other cases, use normal call to Integrate.

myIntegrate[expr_ClearAll[myIntegrate]
myIntegrate[expr_Times, var_Symbol] := 
 Map[Integrate[#, If[Head[expr]var] ===&, PlusExpand[expr]]
myIntegrate[expr_Plus, var_Symbol] := Map[Integrate[#, var] &, Expand[expr]]expr]
myIntegrate[expr_, 
 var_Symbol] := Integrate[expr, var]]var]

And now call myIntegrate instead of Integrate and Mathematica will figure which wrapper to call on its own.

For example

myIntegrate[x, x]
myIntegrate[1myIntegrate[3*(1 + x), x]
myIntegrate[x^2, x]

Givesgives

Mathematica graphicsMathematica graphics

An alternativeIn the above, Expand is to define two wrappers. One that only accepts Plus and oneused for everything else.

ClearAll[myIntegrate]
myIntegrate[expr_Plus, var_Symbol] := Map[Integrate[#, var] &, Expand[expr]]
myIntegrate[expr_, var_Symbol] := Integrate[expr, var]

And now call myIntegrateHead insteadtimes, to take care of cases such as Integratea*(b+c) and Mathematica will figure which wrapperif it is already + then no need to call on its ownexpand. For all other cases, normal Integrate is called. This should take care of all cases you want to map integrate over terms I hope.

I would just check for the Head. As you are only interested in distributing Integrate over sum. For all other cases, use normal call to Integrate.

myIntegrate[expr_, var_Symbol] := 
  If[Head[expr] === Plus, Map[Integrate[#, var] &, Expand[expr]], 
   Integrate[expr, var]]

And now

myIntegrate[x, x]
myIntegrate[1 + x, x]
myIntegrate[x^2, x]

Gives

Mathematica graphics

An alternative is to define two wrappers. One that only accepts Plus and one for everything else.

ClearAll[myIntegrate]
myIntegrate[expr_Plus, var_Symbol] := Map[Integrate[#, var] &, Expand[expr]]
myIntegrate[expr_, var_Symbol] := Integrate[expr, var]

And now call myIntegrate instead of Integrate and Mathematica will figure which wrapper to call on its own.

I would just check for the Head.

ClearAll[myIntegrate]
myIntegrate[expr_Times, var_Symbol] := Map[Integrate[#, var] &, Expand[expr]]
myIntegrate[expr_Plus, var_Symbol] := Map[Integrate[#, var] &, expr]
myIntegrate[expr_, var_Symbol] := Integrate[expr, var]

And now call myIntegrate instead of Integrate and Mathematica will figure which wrapper to call on its own.

For example

myIntegrate[x, x]
myIntegrate[3*(1 + x), x]
myIntegrate[x^2, x]

gives

Mathematica graphics

In the above, Expand is used for Head times, to take care of cases such as a*(b+c) and if it is already + then no need to expand. For all other cases, normal Integrate is called. This should take care of all cases you want to map integrate over terms I hope.

added 27 characters in body
Source Link
Nasser
  • 157.4k
  • 12
  • 175
  • 398

I would just check for the Head. As you are only interested in distributing Integrate over sum. For all other cases, use normal call to Integrate.

myIntegrate[expr_, var_Symbol] := 
 If[Head[expr] === Plus, Map[Integrate[#, var] &, Expand[expr]], 
  Integrate[expr, var]]

And now

myIntegrate[x, x]
myIntegrate[1 + x, x]
myIntegrate[x^2, x]

Gives

Mathematica graphics

An alternative is to define two wrappers. One that only accepts Plus and one for everything else.

ClearAll[myIntegrate]
myIntegrate[expr_Plus, var_Symbol] := Map[Integrate[#, var] &, Expand[expr]]
myIntegrate[expr_, var_Symbol] := Integrate[expr, var]

And now call myIntegrate instead of Integrate and Mathematica will figure which wrapper to call on its own.

I would just check for the Head. As you are only interested in distributing Integrate over sum. For all other cases, use normal call to Integrate.

myIntegrate[expr_, var_Symbol] := 
 If[Head[expr] === Plus, Map[Integrate[#, var] &, Expand[expr]], 
  Integrate[expr, var]]

And now

myIntegrate[x, x]
myIntegrate[1 + x, x]
myIntegrate[x^2, x]

Gives

Mathematica graphics

An alternative is to define two wrappers. One that only accepts Plus and one for everything else.

myIntegrate[expr_Plus, var_Symbol] := Map[Integrate[#, var] &, Expand[expr]]
myIntegrate[expr_, var_Symbol] := Integrate[expr, var]

And now call myIntegrate instead of Integrate and Mathematica will figure which wrapper to call on its own.

I would just check for the Head. As you are only interested in distributing Integrate over sum. For all other cases, use normal call to Integrate.

myIntegrate[expr_, var_Symbol] := 
 If[Head[expr] === Plus, Map[Integrate[#, var] &, Expand[expr]], 
  Integrate[expr, var]]

And now

myIntegrate[x, x]
myIntegrate[1 + x, x]
myIntegrate[x^2, x]

Gives

Mathematica graphics

An alternative is to define two wrappers. One that only accepts Plus and one for everything else.

ClearAll[myIntegrate]
myIntegrate[expr_Plus, var_Symbol] := Map[Integrate[#, var] &, Expand[expr]]
myIntegrate[expr_, var_Symbol] := Integrate[expr, var]

And now call myIntegrate instead of Integrate and Mathematica will figure which wrapper to call on its own.

Source Link
Nasser
  • 157.4k
  • 12
  • 175
  • 398
Loading