# How I can get faster code for computing a fractional integral?

I use of this code Fractional Integral and wrote the following code:

INT[α_, f_, x_, opts___] :=
Integrate[(x - t)^(-α - 1) (f /. x -> t), {t, 0, x}, opts]/Gamma[-α]
INT[mu_?Positive, f_, x_, opts___] :=
Module[{m = Ceiling[mu]},
D[INT[-(m - mu), f, x, opts], {x, m}]]


I run for:

u1[x] =
INT[-α, 0.9 - 0.1 x, x, Assumptions -> {x > 0 && Re[β] > -1 && Re[α] > 0}]

u2[x] =
INT[-α, 8. u1[x] - 2. x u1[x], x,
Assumptions -> {x > 0 && Re[β] > -1 && Re[α] > 0}]


But Mathematica needs a lot of time to make the calculations. Any suggestion code for get faster calculation?

• your attempt to decompose integral of sums is not as general as needed. For example u1[x] is a sum of two terms but 8 u1[x] has head Times. that said I'm puzzled why thats needed at all, but notice INT[-\[Alpha], u1[x], x, Assumptions...] returns almost immediately while INT[-\[Alpha], 8 u1[x], x, Assumptions...] does not. Mar 31, 2016 at 18:35
• I wrote this code to obtain u1 and then u2 obtain with u1, and u3 with u2 and .... Mar 31, 2016 at 19:11
• This is a part of Homotopy perturbation iteration method. Mar 31, 2016 at 19:18
• FractionalIntegrate Oct 11, 2020 at 16:04

I have two suggestions to speed up the code:

1. Always Expand the input expression f
2. Set option GenerateConditions→False to Integrate to bypass convergence test routines.

This Expands the input and passes the result to the integrators internalINT:

INT[α_, f_, x_, opts___] :=
Module[{expr = Expand[f]},
internalINT[α, f, x, opts]
]


Of the following, the first two definitions for internalINT is your code copied here. The third definition Maps the internalINT over addition (Plus):

SetOptions[Integrate, GenerateConditions -> False];

internalINT[α_, f_, x_, opts___] :=
Integrate[(x - t)^(-α - 1) (f /. x -> t), {t, 0, x}, opts]/Gamma[-α]

internalINT[mu_?Positive, f_, x_, opts___] :=
Module[{m = Ceiling[mu]}, D[internalINT[-(m - mu), f, x, opts], {x, m}]]

internalINT[α_, f_Plus, x_, opts___] := Map[internalINT[α, #, x, opts] &, Expand@f]

• Which code is correct in line four: " internalINT[mu_?Positive, f_, x_, opts___] := Module[{m = Ceiling[mu]}, D[INT[-(m - mu), f, x, opts], {x, m}]]" or "internalINT[mu_?Positive, f_, x_, opts___] := Module[{m = Ceiling[mu]}, D[internalINT[-(m - mu), f, x, opts], {x, m}]]". Both codes are correct I think! Apr 3, 2016 at 14:10
• @user37694 Both are fine; but internalINT[mu_?Positive, f_, x_, opts___] := Module[{m = Ceiling[mu]}, D[internalINT[-(m - mu), f, x, opts], {x, m}]] is preferred. I simply forgot to replace INT with internalINT; I have made the appropriate change in the edit. Apr 3, 2016 at 14:16
• Many many thanks. Apr 3, 2016 at 14:18
• @QuantumDot could you please let me know, can you help me for this code? May 2, 2016 at 10:10