Skip to content

Commit

Permalink
Able to compute some more complicated integrals using Rubi.
Browse files Browse the repository at this point in the history
  • Loading branch information
corywalker committed Sep 22, 2017
1 parent 340e2f8 commit 107d5bb
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 36 deletions.
13 changes: 11 additions & 2 deletions expreduce/builtin_replacement.go
Expand Up @@ -47,10 +47,11 @@ func rulesReplace(e Ex, rules []*Expression, es *EvalState) (Ex, bool) {
func replaceParts(e Ex, rules []*Expression, part *Expression, es *EvalState) Ex {
expr, isExpr := e.(*Expression)
if !isExpr {
return e.DeepCopy()
return e
}
res := E(expr.Parts[0])
part.Parts = append(part.Parts, NewInt(0))
dirty := false
for i, p := range expr.Parts[1:] {
part.Parts[len(part.Parts)-1] = NewInt(int64(i+1))
repVal, replaced := rulesReplace(part, rules, es)
Expand All @@ -59,11 +60,19 @@ func replaceParts(e Ex, rules []*Expression, part *Expression, es *EvalState) Ex
}
if replaced {
res.Parts = append(res.Parts, repVal)
dirty = true
} else {
res.Parts = append(res.Parts, replaceParts(p, rules, part, es))
newVal := replaceParts(p, rules, part, es)
res.Parts = append(res.Parts, newVal)
if newVal != p {
dirty = true
}
}
}
part.Parts = part.Parts[:len(part.Parts)-1]
if !dirty {
return e
}
return res
}

Expand Down
1 change: 1 addition & 0 deletions expreduce/evalstate.go
Expand Up @@ -114,6 +114,7 @@ func (es *EvalState) Init(loadAllDefs bool) {
es.MarkSeen("System`Info")
es.MarkSeen("System`Notice")
es.MarkSeen("System`Echo")
es.MarkSeen("System`Row")

es.MarkSeen("System`Attributes")
es.MarkSeen("System`Orderless")
Expand Down
16 changes: 8 additions & 8 deletions expreduce/resources.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions expreduce/resources/rubi.m
Expand Up @@ -7,14 +7,14 @@
outside of test suite.*)
ESameTest[Null, LoadRubi[]],
ESameTest[x^3/3 + 2*x, Rubi`Int[x^2+2, x]],
ESameTest[(-3*ArcTanh[Cosh[a+b*x]])/(8*b)+(3*Coth[a+b*x]*Csch[a+b*x])/(8*b)-(Coth[a+b*x]*Csch[a+b*x]^3)/(4*b), Rubi`Int[Csch[a + b*x]^5,x]],
ESameTest[Log[x], Rubi`Int[1/x, x]],
ESameTest[-(a/(4 x^4))-b/(3 x^3), Rubi`Int[(a+b x)/x^5,x]],
ESameTest[-((3/2+2 x)^2/(3 x^2)), Rubi`Int[(3/2+2 x)/x^3,x]],
], ETests[
ESameTest[x^3/3, Rubi`Int[x^2, x]],
(*ESameTest[Null, therule = (HoldPattern[Rubi`Int[((a_ + (c_. * x_^2))^-1/2 * (d_ + (e_. * x_))^m_), x_Symbol]]) :> (Condition[(2 * a * Rubi`Private`Rt[((c * -1) * a^-1), 2] * (d + (e * x))^m * (Sqrt[(1 + (c * (x^2 * a^-1)))] * (c * Sqrt[(a + (c * x^2))] * (c * ((d + (e * x)) * ((c * d) + ((a * e * Rubi`Private`Rt[((c * -1) * a^-1), 2]) * -1))^-1))^m)^-1) * Rubi`Subst[Rubi`Int[((1 + (2 * a * e * Rubi`Private`Rt[((c * -1) * a^-1), 2] * (x^2 * ((c * d) + ((a * e * Rubi`Private`Rt[((c * -1) * a^-1), 2]) * -1))^-1)))^m * Sqrt[(1 + (x^2 * -1))]^-1), x], x, Sqrt[((1 + ((Rubi`Private`Rt[((c * -1) * a^-1), 2] * x) * -1)) * 2^-1)]]), (FreeQ[{a, c, d, e}, x] && Rubi`Private`NeQ[((c * d^2) + (a * e^2))] && Rubi`Private`EqQ[(m^2 + ((1 * 4^-1) * -1))])]);],*)
(*ESameTest[Null, Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];Rubi`Private`FixIntRule[therule,x];],*)
], EKnownFailures[
(*Equal, but SameQ cannot tell:*)
ESameTest[-((3/2+2 x)^2/(3 x^2)), Rubi`Int[(3/2+2 x)/x^3,x]],
(*Will not work until we add support for FixIntRules. Coefficients
will not distribute.*)
ESameTest[-(3/8) ArcTanh[Cos[a+x]]-3/8 Cot[a+x] Csc[a+x]-1/4 Cot[a+x] Csc[a+x]^3, Rubi`Int[csc[a+x]^5,x]],
Expand Down
44 changes: 22 additions & 22 deletions expreduce/resources/rubi/3 Logarithms.m
Expand Up @@ -47,28 +47,28 @@
FreeQ[{a,b,c,d,g,h,i,j,p,q,r,s},x] && EqQ[b*c-a*d,0]


Int[Log[a_+b_.*x_]*Log[c_+d_.*x_]/x_,x_Symbol] :=
Log[-b*x/a]*Log[a+b*x]*Log[c+d*x] +
1/2*Log[-b*x/a]*Log[a*(c+d*x)/(c*(a+b*x))]^2 +
1/2*Log[-(b*c-a*d)/(d*(a+b*x))]*Log[a*(c+d*x)/(c*(a+b*x))]^2 -
1/2*Log[a*(c+d*x)/(c*(a+b*x))]^2*Log[(b*c-a*d)*x/(c*(a+b*x))] -
Log[-b*x/a]*Log[a+b*x]*Log[1+d*x/c] +
Log[-(d*x/c)]*Log[a+b*x]*Log[1+d*x/c] -
Log[-b*x/a]*Log[a*(c+d*x)/(c*(a+b*x))]*Log[1+d*x/c] +
Log[-d*x/c]*Log[a*(c+d*x)/(c*(a+b*x))]*Log[1+d*x/c] +
1/2*Log[-b*x/a]*Log[1+d*x/c]^2 -
1/2*Log[-d*x/c]*Log[1+d*x/c]^2 +
Log[c+d*x]*PolyLog[2,1+b*x/a] -
Log[a*(c+d*x)/(c*(a+b*x))]*PolyLog[2,1+b*x/a] -
Log[a*(c+d*x)/(c*(a+b*x))]*PolyLog[2,a*(c+d*x)/(c*(a+b*x))] +
Log[a*(c+d*x)/(c*(a+b*x))]*PolyLog[2,b*(c+d*x)/(d*(a+b*x))] +
Log[a+b*x]*PolyLog[2,1+d*x/c] +
Log[a*(c+d*x)/(c*(a+b*x))]*PolyLog[2,1+d*x/c] -
PolyLog[3,1+b*x/a] +
PolyLog[3,a*(c+d*x)/(c*(a+b*x))] -
PolyLog[3,b*(c+d*x)/(d*(a+b*x))] -
PolyLog[3,1+d*x/c]/;
FreeQ[{a,b,c,d},x] && NeQ[b*c-a*d,0]
(*Int[Log[a_+b_.*x_]*Log[c_+d_.*x_]/x_,x_Symbol] :=*)
(*Log[-b*x/a]*Log[a+b*x]*Log[c+d*x] + *)
(*1/2*Log[-b*x/a]*Log[a*(c+d*x)/(c*(a+b*x))]^2 + *)
(*1/2*Log[-(b*c-a*d)/(d*(a+b*x))]*Log[a*(c+d*x)/(c*(a+b*x))]^2 - *)
(*1/2*Log[a*(c+d*x)/(c*(a+b*x))]^2*Log[(b*c-a*d)*x/(c*(a+b*x))] - *)
(*Log[-b*x/a]*Log[a+b*x]*Log[1+d*x/c] + *)
(*Log[-(d*x/c)]*Log[a+b*x]*Log[1+d*x/c] - *)
(*Log[-b*x/a]*Log[a*(c+d*x)/(c*(a+b*x))]*Log[1+d*x/c] + *)
(*Log[-d*x/c]*Log[a*(c+d*x)/(c*(a+b*x))]*Log[1+d*x/c] + *)
(*1/2*Log[-b*x/a]*Log[1+d*x/c]^2 - *)
(*1/2*Log[-d*x/c]*Log[1+d*x/c]^2 + *)
(*Log[c+d*x]*PolyLog[2,1+b*x/a] - *)
(*Log[a*(c+d*x)/(c*(a+b*x))]*PolyLog[2,1+b*x/a] - *)
(*Log[a*(c+d*x)/(c*(a+b*x))]*PolyLog[2,a*(c+d*x)/(c*(a+b*x))] + *)
(*Log[a*(c+d*x)/(c*(a+b*x))]*PolyLog[2,b*(c+d*x)/(d*(a+b*x))] + *)
(*Log[a+b*x]*PolyLog[2,1+d*x/c] + *)
(*Log[a*(c+d*x)/(c*(a+b*x))]*PolyLog[2,1+d*x/c] - *)
(*PolyLog[3,1+b*x/a] +*)
(*PolyLog[3,a*(c+d*x)/(c*(a+b*x))] - *)
(*PolyLog[3,b*(c+d*x)/(d*(a+b*x))] - *)
(*PolyLog[3,1+d*x/c]/;*)
(*FreeQ[{a,b,c,d},x] && NeQ[b*c-a*d,0]*)


Int[Log[v_]*Log[w_]/x_,x_Symbol] :=
Expand Down
2 changes: 1 addition & 1 deletion expreduce/resources/rubi_loader.m
Expand Up @@ -95,7 +95,7 @@
LoadRules["9.4 Miscellaneous integration rules"];


(*FixIntRules[];*)
FixIntRules[];


(*If[Global`$LoadShowSteps===True, StepFunction[Int]];*)
Expand Down
5 changes: 5 additions & 0 deletions expreduce/resources/trig.m
Expand Up @@ -17,8 +17,13 @@
Cos[I*a_] := Cosh[a];
Cos[-x_] := Cos[x];
Cos[x_Integer?Negative] := Cos[-x];
Cos[inner : Verbatim[Plus][Repeated[_*I]]] := Cosh[-I*inner // Distribute]
Cos[Indeterminate] := Indeterminate;
Attributes[Cos] = {Listable, NumericFunction, Protected};

Tan::usage = "`Tan[x]` is the tangent of `x`.";
Attributes[Tan] = {Listable, NumericFunction, Protected};

Csc[inner : Verbatim[Plus][Repeated[_*I]]] := -I*Csch[-I*inner // Distribute]

Cosh[a_]*Csch[a_]^(b_Integer?Positive)*rest___ := Coth[a]*Csch[a]^(b - 1)*rest

0 comments on commit 107d5bb

Please sign in to comment.