def test_matchpy_connector(): if matchpy is None: skip("matchpy not installed") from multiset import Multiset from matchpy import Pattern, Substitution w_ = WildDot("w_") w__ = WildPlus("w__") w___ = WildStar("w___") expr = x + y pattern = x + w_ p, subst = _get_first_match(expr, pattern) assert p == Pattern(pattern) assert subst == Substitution({'w_': y}) expr = x + y + z pattern = x + w__ p, subst = _get_first_match(expr, pattern) assert p == Pattern(pattern) assert subst == Substitution({'w__': Multiset([y, z])}) expr = x + y + z pattern = x + y + z + w___ p, subst = _get_first_match(expr, pattern) assert p == Pattern(pattern) assert subst == Substitution({'w___': Multiset()})
def _init_anserini(): global anserini_monkey if anserini_monkey: return # jnius monkypatching import jnius_config anserini_found = False for j in jnius_config.get_classpath(): if "anserini" in j: anserini_found = True break assert anserini_found, 'Anserini jar not found: you should start PyTerrier, e.g. with '\ + 'pt.init(boot_packages=["io.anserini:anserini:0.9.2:fatjar"])' jnius_config.set_classpath = lambda x: x anserini_monkey = True #this is the Anserini early rank cutoff rule from matchpy import Wildcard, ReplacementRule, Pattern from .transformer import RankCutoffTransformer, rewrite_rules x = Wildcard.dot('x') _brAnserini = Wildcard.symbol('_brAnserini', AnseriniBatchRetrieve) def set_k(_brAnserini, x): _brAnserini.k = int(x.value) return _brAnserini rewrite_rules.append(ReplacementRule( Pattern(RankCutoffTransformer(_brAnserini, x) ), set_k ))
def test_matchpy_optional(): if matchpy is None: skip("matchpy not installed") from matchpy import Pattern, Substitution from matchpy import ManyToOneReplacer, ReplacementRule p = WildDot("p", optional=1) q = WildDot("q", optional=0) pattern = p*x + q expr1 = 2*x pa, subst = _get_first_match(expr1, pattern) assert pa == Pattern(pattern) assert subst == Substitution({'p': 2, 'q': 0}) expr2 = x + 3 pa, subst = _get_first_match(expr2, pattern) assert pa == Pattern(pattern) assert subst == Substitution({'p': 1, 'q': 3}) expr3 = x pa, subst = _get_first_match(expr3, pattern) assert pa == Pattern(pattern) assert subst == Substitution({'p': 1, 'q': 0}) expr4 = x*y + z pa, subst = _get_first_match(expr4, pattern) assert pa == Pattern(pattern) assert subst == Substitution({'p': y, 'q': z}) replacer = ManyToOneReplacer() replacer.add(ReplacementRule(Pattern(pattern), lambda p, q: sin(p)*cos(q))) assert replacer.replace(expr1) == sin(2)*cos(0) assert replacer.replace(expr2) == sin(1)*cos(3) assert replacer.replace(expr3) == sin(1)*cos(0) assert replacer.replace(expr4) == sin(y)*cos(z)
def _get_first_match(expr, pattern): from matchpy import ManyToOneMatcher, Pattern matcher = ManyToOneMatcher() matcher.add(Pattern(pattern)) return next(iter(matcher.match(expr)))
def setup_rewrites(): from .batchretrieve import BatchRetrieve, FeaturesBatchRetrieve #three arbitrary "things". x = Wildcard.dot('x') xs = Wildcard.plus('xs') y = Wildcard.dot('y') z = Wildcard.dot('z') # two different match retrives _br1 = Wildcard.symbol('_br1', BatchRetrieve) _br2 = Wildcard.symbol('_br2', BatchRetrieve) _fbr = Wildcard.symbol('_fbr', FeaturesBatchRetrieve) # batch retrieves for the same index BR_index_matches = CustomConstraint(lambda _br1, _br2: _br1.indexref == _br2.indexref) BR_FBR_index_matches = CustomConstraint(lambda _br1, _fbr: _br1.indexref == _fbr.indexref) # rewrite nested binary feature unions into one single polyadic feature union rewrite_rules.append(ReplacementRule( Pattern(FeatureUnionPipeline(x, FeatureUnionPipeline(y,z)) ), lambda x, y, z: FeatureUnionPipeline(x,y,z) )) rewrite_rules.append(ReplacementRule( Pattern(FeatureUnionPipeline(FeatureUnionPipeline(x,y), z) ), lambda x, y, z: FeatureUnionPipeline(x,y,z) )) rewrite_rules.append(ReplacementRule( Pattern(FeatureUnionPipeline(FeatureUnionPipeline(x,y), xs) ), lambda x, y, xs: FeatureUnionPipeline(*[x,y]+list(xs)) )) # rewrite nested binary compose into one single polyadic compose rewrite_rules.append(ReplacementRule( Pattern(ComposedPipeline(x, ComposedPipeline(y,z)) ), lambda x, y, z: ComposedPipeline(x,y,z) )) rewrite_rules.append(ReplacementRule( Pattern(ComposedPipeline(ComposedPipeline(x,y), z) ), lambda x, y, z: ComposedPipeline(x,y,z) )) rewrite_rules.append(ReplacementRule( Pattern(ComposedPipeline(ComposedPipeline(x,y), xs) ), lambda x, y, xs: ComposedPipeline(*[x,y]+list(xs)) )) # rewrite batch a feature union of BRs into an FBR rewrite_rules.append(ReplacementRule( Pattern(FeatureUnionPipeline(_br1, _br2), BR_index_matches), lambda _br1, _br2: FeaturesBatchRetrieve(_br1.indexref, ["WMODEL:" + _br1.controls["wmodel"], "WMODEL:" + _br2.controls["wmodel"]]) )) def push_fbr_earlier(_br1, _fbr): #TODO copy more attributes _fbr.controls["wmodel"] = _br1.controls["wmodel"] return _fbr # rewrite a BR followed by a FBR into a FBR rewrite_rules.append(ReplacementRule( Pattern(ComposedPipeline(_br1, _fbr), BR_FBR_index_matches), push_fbr_earlier )) global rewrites_setup rewrites_setup = True
def integrand_simplification(): from sympy.integrals.rubi.constraints import ( cons1, cons2, cons3, cons4, cons5, cons6, cons7, cons8, cons9, cons10, cons11, cons12, cons13, cons14, cons15, cons16, cons17, cons18, cons19, cons20, cons21, cons22, cons23, cons24, cons25, cons26, cons27, cons28, cons29, cons30, cons31, cons32, cons33, cons34, cons35, cons36, cons37, cons38, cons39, cons40, cons41, cons42, cons43, cons44, cons45, cons46, cons47, cons48, cons49, cons50, cons51, cons52, cons53, cons54, cons55, cons56, cons57, cons58, cons59, cons60, cons61, cons62, cons63, cons64, cons65, cons66, cons67, ) pattern1 = Pattern( Integral( (a_ + x_**WC("n", S(1)) * WC("b", S(1)))**WC("p", S(1)) * WC("u", S(1)), x_, ), cons2, cons3, cons4, cons5, cons1, ) rule1 = ReplacementRule(pattern1, replacement1) pattern2 = Pattern( Integral( (x_**WC("n", S(1)) * WC("b", S(1)) + WC("a", S(0)))**WC("p", S(1)) * WC("u", S(1)), x_, ), cons2, cons3, cons4, cons5, cons6, ) rule2 = ReplacementRule(pattern2, replacement2) pattern3 = Pattern( Integral( (a_ + x_**WC("j", S(1)) * WC("c", S(1)) + x_**WC("n", S(1)) * WC("b", S(1)))**WC("p", S(1)) * WC("u", S(1)), x_, ), cons2, cons3, cons8, cons4, cons5, cons7, cons1, ) rule3 = ReplacementRule(pattern3, replacement3) pattern4 = Pattern( Integral( (x_**WC("j", S(1)) * WC("c", S(1)) + x_**WC("n", S(1)) * WC("b", S(1)) + WC("a", S(0)))**WC("p", S(1)) * WC("u", S(1)), x_, ), cons2, cons3, cons8, cons4, cons5, cons7, cons6, ) rule4 = ReplacementRule(pattern4, replacement4) pattern5 = Pattern( Integral( (x_**WC("j", S(1)) * WC("c", S(1)) + x_**WC("n", S(1)) * WC("b", S(1)) + WC("a", S(0)))**WC("p", S(1)) * WC("u", S(1)), x_, ), cons2, cons3, cons8, cons4, cons5, cons7, cons9, ) rule5 = ReplacementRule(pattern5, replacement5) pattern6 = Pattern( Integral( (v_ * WC("a", S(1)) + v_ * WC("b", S(1)) + WC("w", S(0)))**WC( "p", S(1)) * WC("u", S(1)), x_, ), cons2, cons3, cons10, ) rule6 = ReplacementRule(pattern6, replacement6) pattern7 = Pattern(Integral(Pm_**p_ * WC("u", S(1)), x_), cons11, cons12, cons13) rule7 = ReplacementRule(pattern7, replacement7) pattern8 = Pattern(Integral(a_, x_), cons2, cons2) rule8 = ReplacementRule(pattern8, replacement8) pattern9 = Pattern(Integral(a_ * (b_ + x_ * WC("c", S(1))), x_), cons2, cons3, cons8, cons14) rule9 = ReplacementRule(pattern9, replacement9) pattern10 = Pattern(Integral(-u_, x_)) rule10 = ReplacementRule(pattern10, replacement10) pattern11 = Pattern(Integral(u_ * Complex(S(0), a_), x_), cons2, cons15) rule11 = ReplacementRule(pattern11, replacement11) pattern12 = Pattern(Integral(a_ * u_, x_), cons2, cons16) rule12 = ReplacementRule(pattern12, replacement12) pattern13 = Pattern(Integral(u_, x_), cons17) rule13 = ReplacementRule(pattern13, replacement13) pattern14 = Pattern( Integral(u_ * (x_ * WC("c", S(1)))**WC("m", S(1)), x_), cons8, cons19, cons17, cons18, ) rule14 = ReplacementRule(pattern14, replacement14) pattern15 = Pattern( Integral(v_**WC("m", S(1)) * (b_ * v_)**n_ * WC("u", S(1)), x_), cons3, cons4, cons20, ) rule15 = ReplacementRule(pattern15, replacement15) pattern16 = Pattern( Integral((v_ * WC("a", S(1)))**m_ * (v_ * WC("b", S(1)))**n_ * WC("u", S(1)), x_), cons2, cons3, cons19, cons21, cons22, cons23, ) rule16 = ReplacementRule(pattern16, replacement16) pattern17 = Pattern( Integral((v_ * WC("a", S(1)))**m_ * (v_ * WC("b", S(1)))**n_ * WC("u", S(1)), x_), cons2, cons3, cons19, cons21, cons24, cons23, ) rule17 = ReplacementRule(pattern17, replacement17) pattern18 = Pattern( Integral((v_ * WC("a", S(1)))**m_ * (v_ * WC("b", S(1)))**n_ * WC("u", S(1)), x_), cons2, cons3, cons19, cons4, cons21, cons25, cons23, ) rule18 = ReplacementRule(pattern18, replacement18) pattern19 = Pattern( Integral((v_ * WC("a", S(1)))**m_ * (v_ * WC("b", S(1)))**n_ * WC("u", S(1)), x_), cons2, cons3, cons19, cons4, cons21, cons25, cons26, ) rule19 = ReplacementRule(pattern19, replacement19) pattern20 = Pattern( Integral( (a_ + v_ * WC("b", S(1)))**WC("m", S(1)) * (c_ + v_ * WC("d", S(1)))**WC("n", S(1)) * WC("u", S(1)), x_, ), cons2, cons3, cons8, cons29, cons4, cons27, cons20, cons28, ) rule20 = ReplacementRule(pattern20, replacement20) pattern21 = Pattern( Integral( (a_ + v_ * WC("b", S(1)))**m_ * (c_ + v_ * WC("d", S(1)))**n_ * WC("u", S(1)), x_, ), cons2, cons3, cons8, cons29, cons19, cons4, cons27, cons30, cons31, ) rule21 = ReplacementRule(pattern21, replacement21) pattern22 = Pattern( Integral( (a_ + v_ * WC("b", S(1)))**m_ * (c_ + v_ * WC("d", S(1)))**n_ * WC("u", S(1)), x_, ), cons2, cons3, cons8, cons29, cons19, cons4, cons27, cons32, ) rule22 = ReplacementRule(pattern22, replacement22) pattern23 = Pattern( Integral( (v_ * WC("a", S(1)))**m_ * (v_**S(2) * WC("c", S(1)) + v_ * WC("b", S(1))) * WC("u", S(1)), x_, ), cons2, cons3, cons8, cons33, cons34, ) rule23 = ReplacementRule(pattern23, replacement23) pattern24 = Pattern( Integral( (a_ + v_ * WC("b", S(1)))**m_ * (v_**S(2) * WC("C", S(1)) + v_ * WC("B", S(1)) + WC("A", S(0))) * WC("u", S(1)), x_, ), cons2, cons3, cons36, cons37, cons38, cons35, cons33, cons34, ) rule24 = ReplacementRule(pattern24, replacement24) pattern25 = Pattern( Integral( (a_ + x_**WC("n", S(1)) * WC("b", S(1)))**WC("m", S(1)) * (c_ + x_**WC("q", S(1)) * WC("d", S(1)))**WC("p", S(1)) * WC("u", S(1)), x_, ), cons2, cons3, cons8, cons29, cons19, cons4, cons39, cons40, cons41, cons42, ) rule25 = ReplacementRule(pattern25, replacement25) pattern26 = Pattern( Integral( (a_ + x_**WC("n", S(1)) * WC("b", S(1)))**WC("m", S(1)) * (c_ + x_**j_ * WC("d", S(1)))**WC("p", S(1)) * WC("u", S(1)), x_, ), cons2, cons3, cons8, cons29, cons19, cons4, cons5, cons7, cons43, cons44, cons45, cons46, ) rule26 = ReplacementRule(pattern26, replacement26) pattern27 = Pattern( Integral( (a_ + x_**S(2) * WC("c", S(1)) + x_ * WC("b", S(1)))**WC( "p", S(1)) * WC("u", S(1)), x_, ), cons2, cons3, cons8, cons47, cons40, ) rule27 = ReplacementRule(pattern27, replacement27) pattern28 = Pattern( Integral( (a_ + x_**n_ * WC("b", S(1)) + x_**WC("n2", S(1)) * WC("c", S(1))) **WC("p", S(1)) * WC("u", S(1)), x_, ), cons2, cons3, cons8, cons4, cons48, cons47, cons40, ) rule28 = ReplacementRule(pattern28, replacement28) pattern29 = Pattern( Integral( (d_ + x_ * WC("e", S(1))) * (x_**S(2) * WC("c", S(1)) + x_ * WC("b", S(1)) + WC("a", S(0)))** WC("p", S(1)), x_, ), cons2, cons3, cons8, cons29, cons50, cons5, cons49, ) rule29 = ReplacementRule(pattern29, replacement29) pattern30 = Pattern( Integral( (x_**WC("p", S(1)) * WC("a", S(1)) + x_**WC("q", S(1)) * WC("b", S(1)))**WC("m", S(1)) * WC("u", S(1)), x_, ), cons2, cons3, cons5, cons52, cons20, cons51, ) rule30 = ReplacementRule(pattern30, replacement30) pattern31 = Pattern( Integral( (x_**WC("p", S(1)) * WC("a", S(1)) + x_**WC("q", S(1)) * WC("b", S(1)) + x_**WC("r", S(1)) * WC("c", S(1)))**WC("m", S(1)) * WC("u", S(1)), x_, ), cons2, cons3, cons8, cons5, cons52, cons54, cons20, cons51, cons53, ) rule31 = ReplacementRule(pattern31, replacement31) pattern32 = Pattern( Integral(x_**WC("m", S(1)) / (a_ + x_**n_ * WC("b", S(1))), x_), cons2, cons3, cons19, cons4, cons55, ) rule32 = ReplacementRule(pattern32, replacement32) pattern33 = Pattern( Integral(x_**WC("m", S(1)) * (a_ + x_**n_ * WC("b", S(1)))**p_, x_), cons2, cons3, cons19, cons4, cons5, cons55, cons56, ) rule33 = ReplacementRule(pattern33, replacement33) pattern34 = Pattern( Integral( x_**WC("m", S(1)) * (a1_ + x_**WC("n", S(1)) * WC("b1", S(1)))**p_ * (a2_ + x_**WC("n", S(1)) * WC("b2", S(1)))**p_, x_, ), cons59, cons60, cons61, cons62, cons19, cons4, cons5, cons57, cons58, cons56, ) rule34 = ReplacementRule(pattern34, replacement34) pattern35 = Pattern( Integral( Qm_ * (Pm_**WC("n", S(1)) * WC("b", S(1)) + WC("a", S(0)))**WC( "p", S(1)), x_, ), cons2, cons3, cons4, cons5, cons11, cons63, CustomConstraint(With35), ) rule35 = ReplacementRule(pattern35, replacement35) pattern36 = Pattern( Integral( Qm_ * (Pm_**WC("n", S(1)) * WC("b", S(1)) + Pm_**WC("n2", S(1)) * WC("c", S(1)) + WC("a", S(0)))**WC("p", S(1)), x_, ), cons2, cons3, cons8, cons4, cons5, cons48, cons11, cons63, CustomConstraint(With36), ) rule36 = ReplacementRule(pattern36, replacement36) pattern37 = Pattern( Integral(Pq_**m_ * Qr_**p_ * WC("u", S(1)), x_), cons64, cons65, cons66, cons67, CustomConstraint(With37), ) rule37 = ReplacementRule(pattern37, replacement37) pattern38 = Pattern( Integral(Pq_ * Qr_**p_ * WC("u", S(1)), x_), cons65, cons66, cons67, CustomConstraint(With38), ) rule38 = ReplacementRule(pattern38, replacement38) return [ rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8, rule9, rule10, rule11, rule12, rule13, rule14, rule15, rule16, rule17, rule18, rule19, rule20, rule21, rule22, rule23, rule24, rule25, rule26, rule27, rule28, rule29, rule30, rule31, rule32, rule33, rule34, rule35, rule36, rule37, rule38, ]
def piecewise_linear(rubi): pattern1 = Pattern( Integral(u_**WC('m', S(1)), x_), CustomConstraint(lambda m, x: FreeQ(m, x)), CustomConstraint(lambda x, u: PiecewiseLinearQ(u, x)), ) def With1(x, m, u): c = D(u, x) return Subst(Int(x**m, x), x, u) / c rule1 = ReplacementRule(pattern1, lambda x, m, u: With1(x, m, u)) rubi.add(rule1) pattern2 = Pattern( Integral(v_ / u_, x_), CustomConstraint(lambda x, v, u: PiecewiseLinearQ(u, v, x)), CustomConstraint(lambda v, b, x, u, a: NonzeroQ(-a * v + b * u))) def With2(x, v, u): a = D(u, x) b = D(v, x) return b * x / a - (-a * v + b * u) * Int(1 / u, x) / a rule2 = ReplacementRule(pattern2, lambda x, v, u: With2(x, v, u)) rubi.add(rule2) pattern3 = Pattern( Integral(v_**n_ / u_, x_), CustomConstraint(lambda x, v, u: PiecewiseLinearQ(u, v, x)), CustomConstraint(lambda n: RationalQ(n)), CustomConstraint(lambda n: Greater(n, S(0))), CustomConstraint(lambda n: Unequal(n, S(1))), CustomConstraint(lambda v, b, n, x, u, a: NonzeroQ(-a * v + b * u))) def With3(x, n, v, u): a = D(u, x) b = D(v, x) return -(-a * v + b * u) * Int(v** (n + S(-1)) / u, x) / a + v**n / (a * n) rule3 = ReplacementRule(pattern3, lambda x, n, v, u: With3(x, n, v, u)) rubi.add(rule3) pattern4 = Pattern( Integral(S(1) / (u_ * v_), x_), CustomConstraint(lambda x, v, u: PiecewiseLinearQ(u, v, x)), CustomConstraint(lambda v, b, x, u, a: NonzeroQ(-a * v + b * u))) def With4(x, v, u): a = D(u, x) b = D(v, x) return -a * Int(1 / u, x) / (-a * v + b * u) + b * Int( 1 / v, x) / (-a * v + b * u) rule4 = ReplacementRule(pattern4, lambda x, v, u: With4(x, v, u)) rubi.add(rule4) pattern5 = Pattern( Integral(S(1) / (u_ * sqrt(v_)), x_), CustomConstraint(lambda x, v, u: PiecewiseLinearQ(u, v, x)), CustomConstraint(lambda v, b, u, a: NonzeroQ(-a * v + b * u) & PosQ( (-a * v + b * u) / a))) def With5(x, v, u): a = D(u, x) b = D(v, x) return S(2) * ArcTan(sqrt(v) / Rt( (-a * v + b * u) / a, S(2))) / (a * Rt((-a * v + b * u) / a, S(2))) rule5 = ReplacementRule(pattern5, lambda x, v, u: With5(x, v, u)) rubi.add(rule5) pattern6 = Pattern( Integral(S(1) / (u_ * sqrt(v_)), x_), CustomConstraint(lambda x, v, u: PiecewiseLinearQ(u, v, x)), CustomConstraint(lambda v, b, u, a: NonzeroQ(-a * v + b * u) & NegQ( (-a * v + b * u) / a))) def With6(x, v, u): a = D(u, x) b = D(v, x) return -S(2) * atanh(sqrt(v) / Rt( (a * v - b * u) / a, S(2))) / (a * Rt((a * v - b * u) / a, S(2))) rule6 = ReplacementRule(pattern6, lambda x, v, u: With6(x, v, u)) rubi.add(rule6) pattern7 = Pattern( Integral(v_**n_ / u_, x_), CustomConstraint(lambda x, v, u: PiecewiseLinearQ(u, v, x)), CustomConstraint(lambda n: RationalQ(n)), CustomConstraint(lambda n: Less(n, S(-1))), CustomConstraint(lambda v, b, n, x, u, a: NonzeroQ(-a * v + b * u))) def With7(x, n, v, u): a = D(u, x) b = D(v, x) return -a * Int(v**(n + S(1)) / u, x) / (-a * v + b * u) + v**( n + S(1)) / ((n + S(1)) * (-a * v + b * u)) rule7 = ReplacementRule(pattern7, lambda x, n, v, u: With7(x, n, v, u)) rubi.add(rule7) pattern8 = Pattern( Integral(v_**n_ / u_, x_), CustomConstraint(lambda x, v, u: PiecewiseLinearQ(u, v, x)), CustomConstraint(lambda n: Not(IntegerQ(n))), CustomConstraint(lambda v, b, n, u, a: NonzeroQ(-a * v + b * u))) def With8(x, n, v, u): a = D(u, x) b = D(v, x) return v**(n + S(1)) * Hypergeometric2F1( S(1), n + S(1), n + S(2), -a * v / (-a * v + b * u)) / ((n + S(1)) * (-a * v + b * u)) rule8 = ReplacementRule(pattern8, lambda x, n, v, u: With8(x, n, v, u)) rubi.add(rule8) pattern9 = Pattern( Integral(S(1) / (sqrt(u_) * sqrt(v_)), x_), CustomConstraint(lambda x, v, u: PiecewiseLinearQ(u, v, x)), CustomConstraint( lambda v, b, u, a: PosQ(a * b) & NonzeroQ(-a * v + b * u))) def With9(x, v, u): a = D(u, x) b = D(v, x) return S(2) * atanh(sqrt(u) * Rt(a * b, S(2)) / (a * sqrt(v))) / Rt(a * b, S(2)) rule9 = ReplacementRule(pattern9, lambda x, v, u: With9(x, v, u)) rubi.add(rule9) pattern10 = Pattern( Integral(S(1) / (sqrt(u_) * sqrt(v_)), x_), CustomConstraint(lambda x, v, u: PiecewiseLinearQ(u, v, x)), CustomConstraint( lambda v, b, u, a: NegQ(a * b) & NonzeroQ(-a * v + b * u))) def With10(x, v, u): a = D(u, x) b = D(v, x) return S(2) * ArcTan(sqrt(u) * Rt(-a * b, S(2)) / (a * sqrt(v))) / Rt(-a * b, S(2)) rule10 = ReplacementRule(pattern10, lambda x, v, u: With10(x, v, u)) rubi.add(rule10) pattern11 = Pattern( Integral(u_**m_ * v_**n_, x_), CustomConstraint(lambda m, x: FreeQ(m, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda x, v, u: PiecewiseLinearQ(u, v, x)), CustomConstraint(lambda n, m: ZeroQ(m + n + S(2))), CustomConstraint(lambda m: NonzeroQ(m + S(1))), CustomConstraint(lambda v, b, n, m, u, a: NonzeroQ(-a * v + b * u))) def With11(x, n, v, u, m): a = D(u, x) b = D(v, x) return -u**(m + S(1)) * v**(n + S(1)) / ((m + S(1)) * (-a * v + b * u)) rule11 = ReplacementRule(pattern11, lambda x, n, v, u, m: With11(x, n, v, u, m)) rubi.add(rule11) pattern12 = Pattern( Integral(u_**m_ * v_**WC('n', S(1)), x_), CustomConstraint(lambda m, x: FreeQ(m, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda x, v, u: PiecewiseLinearQ(u, v, x)), CustomConstraint(lambda m: NonzeroQ(m + S(1))), CustomConstraint(lambda n, m: (NegativeIntegerQ(m) & Not(IntegerQ( n))) | (PositiveIntegerQ(n) & Not(IntegerQ(m))) | ( LessEqual(n, m) & PositiveIntegerQ(n, m) ) | (Greater(n, S(0)) & Less(m, S(-1)) & RationalQ(m, n) & Not( IntegerQ(m + n) & Less(m + n + S(2), S(0)) & (FractionQ(m) | GreaterEqual(m + S(2) * n + S(1), S(0)))))), CustomConstraint(lambda v, b, n, x, m, u, a: NonzeroQ(-a * v + b * u))) def With12(x, n, v, u, m): a = D(u, x) b = D(v, x) return -b * n * Int(u**(m + S(1)) * v**(n + S(-1)), x) / ( a * (m + S(1))) + u**(m + S(1)) * v**n / (a * (m + S(1))) rule12 = ReplacementRule(pattern12, lambda x, n, v, u, m: With12(x, n, v, u, m)) rubi.add(rule12) pattern13 = Pattern( Integral(u_**m_ * v_**WC('n', S(1)), x_), CustomConstraint(lambda x, v, u: PiecewiseLinearQ(u, v, x)), CustomConstraint(lambda n, m: NonzeroQ(m + n + S(2))), CustomConstraint(lambda n: RationalQ(n)), CustomConstraint(lambda n: Greater(n, S(0))), CustomConstraint(lambda n, m: NonzeroQ(m + n + S(1))), CustomConstraint(lambda n, m: Not( PositiveIntegerQ(m) & (Not(IntegerQ(n)) | Less(S(0), m, n)))), CustomConstraint( lambda n, m: Not(IntegerQ(m + n) & Less(m + n + S(2), S(0)))), CustomConstraint(lambda v, b, n, x, m, u, a: NonzeroQ(-a * v + b * u))) def With13(x, n, v, u, m): a = D(u, x) b = D(v, x) return -n * (-a * v + b * u) * Int(u**m * v**(n + S(-1)), x) / ( a * (m + n + S(1))) + u**(m + S(1)) * v**n / (a * (m + n + S(1))) rule13 = ReplacementRule(pattern13, lambda x, n, v, u, m: With13(x, n, v, u, m)) rubi.add(rule13) pattern14 = Pattern( Integral(u_**m_ * v_**n_, x_), CustomConstraint(lambda x, v, u: PiecewiseLinearQ(u, v, x)), CustomConstraint(lambda n, m: NonzeroQ(m + n + S(1))), CustomConstraint(lambda n: Not(RationalQ(n))), CustomConstraint(lambda n: SumSimplerQ(n, S(-1))), CustomConstraint(lambda v, b, n, x, m, u, a: NonzeroQ(-a * v + b * u))) def With14(x, n, v, u, m): a = D(u, x) b = D(v, x) return -n * (-a * v + b * u) * Int(u**m * v**(n + S(-1)), x) / ( a * (m + n + S(1))) + u**(m + S(1)) * v**n / (a * (m + n + S(1))) rule14 = ReplacementRule(pattern14, lambda x, n, v, u, m: With14(x, n, v, u, m)) rubi.add(rule14) pattern15 = Pattern( Integral(u_**m_ * v_**n_, x_), CustomConstraint(lambda x, v, u: PiecewiseLinearQ(u, v, x)), CustomConstraint(lambda n, m: NonzeroQ(m + n + S(2))), CustomConstraint(lambda m: RationalQ(m)), CustomConstraint(lambda m: Less(m, S(-1))), CustomConstraint(lambda v, b, n, x, m, u, a: NonzeroQ(-a * v + b * u))) def With15(x, n, v, u, m): a = D(u, x) b = D(v, x) return b * (m + n + S(2)) * Int(u**(m + S(1)) * v**n, x) / ( (m + S(1)) * (-a * v + b * u)) - u**(m + S(1)) * v**(n + S(1)) / ( (m + S(1)) * (-a * v + b * u)) rule15 = ReplacementRule(pattern15, lambda x, n, v, u, m: With15(x, n, v, u, m)) rubi.add(rule15) pattern16 = Pattern( Integral(u_**m_ * v_**n_, x_), CustomConstraint(lambda x, v, u: PiecewiseLinearQ(u, v, x)), CustomConstraint(lambda m: Not(RationalQ(m))), CustomConstraint(lambda m: SumSimplerQ(m, S(1))), CustomConstraint(lambda v, b, n, x, m, u, a: NonzeroQ(-a * v + b * u))) def With16(x, n, v, u, m): a = D(u, x) b = D(v, x) return b * (m + n + S(2)) * Int(u**(m + S(1)) * v**n, x) / ( (m + S(1)) * (-a * v + b * u)) - u**(m + S(1)) * v**(n + S(1)) / ( (m + S(1)) * (-a * v + b * u)) rule16 = ReplacementRule(pattern16, lambda x, n, v, u, m: With16(x, n, v, u, m)) rubi.add(rule16) pattern17 = Pattern( Integral(u_**m_ * v_**n_, x_), CustomConstraint(lambda x, v, u: PiecewiseLinearQ(u, v, x)), CustomConstraint(lambda m: Not(IntegerQ(m))), CustomConstraint(lambda n: Not(IntegerQ(n))), CustomConstraint(lambda v, b, n, m, u, a: NonzeroQ(-a * v + b * u))) def With17(x, n, v, u, m): a = D(u, x) b = D(v, x) return u**m * v**(n + S(1)) * (b * u / (-a * v + b * u))**( -m) * Hypergeometric2F1(-m, n + S(1), n + S(2), -a * v / (-a * v + b * u)) / (b * (n + S(1))) rule17 = ReplacementRule(pattern17, lambda x, n, v, u, m: With17(x, n, v, u, m)) rubi.add(rule17) pattern18 = Pattern( Integral(u_**WC('n', S(1)) * log(x_ * WC('b', S(1)) + WC('a', S(0))), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda x, u: PiecewiseLinearQ(u, x)), CustomConstraint(lambda x, u: Not(LinearQ(u, x))), CustomConstraint(lambda n: RationalQ(n)), CustomConstraint(lambda n: Greater(n, S(0))), ) def With18(x, n, b, u, a): c = D(u, x) return -Int(u**n, x) - c * n * Int( u**(n + S(-1)) * (a + b * x) * log(a + b * x), x) / b + u**n * (a + b * x) * log(a + b * x) / b rule18 = ReplacementRule(pattern18, lambda x, n, b, u, a: With18(x, n, b, u, a)) rubi.add(rule18) pattern19 = Pattern( Integral( u_**WC('n', S(1)) * (x_ * WC('b', S(1)) + WC('a', S(0)))**WC('m', S(1)) * log(x_ * WC('b', S(1)) + WC('a', S(0))), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda m, x: FreeQ(m, x)), CustomConstraint(lambda x, u: PiecewiseLinearQ(u, x)), CustomConstraint(lambda x, u: Not(LinearQ(u, x))), CustomConstraint(lambda n: RationalQ(n)), CustomConstraint(lambda n: Greater(n, S(0))), CustomConstraint(lambda m: NonzeroQ(m + S(1))), ) def With19(x, n, b, u, a, m): c = D(u, x) return -Int(u**n * (a + b * x)**m, x) / (m + S(1)) - c * n * Int( u**(n + S(-1)) * (a + b * x)** (m + S(1)) * log(a + b * x), x) / (b * (m + S(1))) + u**n * ( a + b * x)**(m + S(1)) * log(a + b * x) / (b * (m + S(1))) rule19 = ReplacementRule(pattern19, lambda x, n, b, u, a, m: With19(x, n, b, u, a, m)) rubi.add(rule19) return rubi
def integrand_simplification(rubi): from sympy.integrals.rubi.constraints import cons1, cons2, cons3, cons4, cons5, cons6, cons7, cons8, cons9, cons10, cons11, cons12, cons13, cons14, cons15, cons16, cons17, cons18, cons19, cons20, cons21, cons22, cons23, cons24, cons25, cons26, cons27, cons28, cons29, cons30, cons31, cons32, cons33, cons34, cons35, cons36, cons37, cons38, cons39, cons40, cons41, cons42, cons43, cons44, cons45, cons46, cons47, cons48, cons49, cons50, cons51, cons52, cons53, cons54, cons55, cons56, cons57, cons58, cons59, cons60, cons61, cons62, cons63, cons64, cons65 pattern1 = Pattern( Integral((a_ + x_**WC('n', S(1)) * WC('b', S(1)))**WC('p', S(1)) * WC('u', S(1)), x_), cons2, cons3, cons4, cons5, cons1) def replacement1(p, u, b, a, n, x): rubi.append(1) return Int(u * (b * x**n)**p, x) rule1 = ReplacementRule(pattern1, replacement1) pattern2 = Pattern( Integral( (a_ + x_**WC('j', S(1)) * WC('c', S(1)) + x_**WC('n', S(1)) * WC('b', S(1)))**WC('p', S(1)) * WC('u', S(1)), x_), cons2, cons3, cons7, cons4, cons5, cons6, cons1) def replacement2(p, u, j, b, c, n, a, x): rubi.append(2) return Int(u * (b * x**n + c * x**(S(2) * n))**p, x) rule2 = ReplacementRule(pattern2, replacement2) pattern3 = Pattern( Integral( (x_**WC('j', S(1)) * WC('c', S(1)) + x_**WC('n', S(1)) * WC('b', S(1)) + WC('a', S(0)))**WC('p', S(1)) * WC('u', S(1)), x_), cons2, cons3, cons7, cons4, cons5, cons6, cons8) def replacement3(p, u, j, b, a, c, n, x): rubi.append(3) return Int(u * (a + c * x**(S(2) * n))**p, x) rule3 = ReplacementRule(pattern3, replacement3) pattern4 = Pattern( Integral( (x_**WC('j', S(1)) * WC('c', S(1)) + x_**WC('n', S(1)) * WC('b', S(1)) + WC('a', S(0)))**WC('p', S(1)) * WC('u', S(1)), x_), cons2, cons3, cons7, cons4, cons5, cons6, cons9) def replacement4(p, u, j, b, a, c, n, x): rubi.append(4) return Int(u * (a + b * x**n)**p, x) rule4 = ReplacementRule(pattern4, replacement4) pattern5 = Pattern( Integral((v_ * WC('a', S(1)) + v_ * WC('b', S(1)) + WC('w', S(0)))**WC( 'p', S(1)) * WC('u', S(1)), x_), cons2, cons3, cons10) def replacement5(v, w, p, u, b, a, x): rubi.append(5) return Int(u * (v * (a + b) + w)**p, x) rule5 = ReplacementRule(pattern5, replacement5) pattern6 = Pattern(Integral(Pm_**p_ * WC('u', S(1)), x_), cons11, cons12, cons13) def replacement6(x, p, Pm, u): rubi.append(6) return Int(Pm**p * u, x) rule6 = ReplacementRule(pattern6, replacement6) pattern7 = Pattern(Integral(a_, x_), cons2, cons2) def replacement7(x, a): rubi.append(7) return Simp(a * x, x) rule7 = ReplacementRule(pattern7, replacement7) pattern8 = Pattern(Integral(a_ * (b_ + x_ * WC('c', S(1))), x_), cons2, cons3, cons7, cons14) def replacement8(x, c, b, a): rubi.append(8) return Simp(a * (b + c * x)**S(2) / (S(2) * c), x) rule8 = ReplacementRule(pattern8, replacement8) pattern9 = Pattern(Integral(-u_, x_)) def replacement9(x, u): rubi.append(9) return Dist(S(-1), Int(u, x), x) rule9 = ReplacementRule(pattern9, replacement9) pattern10 = Pattern(Integral(u_ * Complex(S(0), a_), x_), cons2, cons15) def replacement10(x, a, u): rubi.append(10) return Dist(Complex(S(0), a), Int(u, x), x) rule10 = ReplacementRule(pattern10, replacement10) pattern11 = Pattern(Integral(a_ * u_, x_), cons2, cons2) def replacement11(x, a, u): rubi.append(11) return Dist(a, Int(u, x), x) rule11 = ReplacementRule(pattern11, replacement11) pattern12 = Pattern(Integral(u_, x_), cons16) def replacement12(x, u): rubi.append(12) return Simp(IntSum(u, x), x) rule12 = ReplacementRule(pattern12, replacement12) pattern13 = Pattern( Integral(v_**WC('m', S(1)) * (b_ * v_)**n_ * WC('u', S(1)), x_), cons3, cons4, cons17) def replacement13(v, u, m, b, n, x): rubi.append(13) return Dist(b**(-m), Int(u * (b * v)**(m + n), x), x) rule13 = ReplacementRule(pattern13, replacement13) pattern14 = Pattern( Integral((v_ * WC('a', S(1)))**m_ * (v_ * WC('b', S(1)))**n_ * WC('u', S(1)), x_), cons2, cons3, cons21, cons18, cons19, cons20) def replacement14(v, u, m, b, a, n, x): rubi.append(14) return Dist( a**(m + S(1) / 2) * b**(n + S(-1) / 2) * sqrt(b * v) / sqrt(a * v), Int(u * v**(m + n), x), x) rule14 = ReplacementRule(pattern14, replacement14) pattern15 = Pattern( Integral((v_ * WC('a', S(1)))**m_ * (v_ * WC('b', S(1)))**n_ * WC('u', S(1)), x_), cons2, cons3, cons21, cons18, cons22, cons20) def replacement15(v, u, m, b, a, n, x): rubi.append(15) return Dist( a**(m + S(-1) / 2) * b**(n + S(1) / 2) * sqrt(a * v) / sqrt(b * v), Int(u * v**(m + n), x), x) rule15 = ReplacementRule(pattern15, replacement15) pattern16 = Pattern( Integral((v_ * WC('a', S(1)))**m_ * (v_ * WC('b', S(1)))**n_ * WC('u', S(1)), x_), cons2, cons3, cons21, cons4, cons18, cons23, cons20) def replacement16(v, u, m, b, a, n, x): rubi.append(16) return Dist(a**(m + n) * (a * v)**(-n) * (b * v)**n, Int(u * v**(m + n), x), x) rule16 = ReplacementRule(pattern16, replacement16) pattern17 = Pattern( Integral((v_ * WC('a', S(1)))**m_ * (v_ * WC('b', S(1)))**n_ * WC('u', S(1)), x_), cons2, cons3, cons21, cons4, cons18, cons23, cons24) def replacement17(v, u, m, b, a, n, x): rubi.append(17) return Dist( a**(-IntPart(n)) * b**IntPart(n) * (a * v)**(-FracPart(n)) * (b * v)**FracPart(n), Int(u * (a * v)**(m + n), x), x) rule17 = ReplacementRule(pattern17, replacement17) pattern18 = Pattern( Integral((a_ + v_ * WC('b', S(1)))**WC('m', S(1)) * (c_ + v_ * WC('d', S(1)))**WC('n', S(1)) * WC('u', S(1)), x_), cons2, cons3, cons7, cons27, cons4, cons25, cons17, cons26) def replacement18(v, u, m, b, d, a, n, c, x): rubi.append(18) return Dist((b / d)**m, Int(u * (c + d * v)**(m + n), x), x) rule18 = ReplacementRule(pattern18, replacement18) pattern19 = Pattern( Integral((a_ + v_ * WC('b', S(1)))**m_ * (c_ + v_ * WC('d', S(1)))**n_ * WC('u', S(1)), x_), cons2, cons3, cons7, cons27, cons21, cons4, cons25, cons28, cons29) def replacement19(v, u, m, b, d, a, c, n, x): rubi.append(19) return Dist((b / d)**m, Int(u * (c + d * v)**(m + n), x), x) rule19 = ReplacementRule(pattern19, replacement19) pattern20 = Pattern( Integral((a_ + v_ * WC('b', S(1)))**m_ * (c_ + v_ * WC('d', S(1)))**n_ * WC('u', S(1)), x_), cons2, cons3, cons7, cons27, cons21, cons4, cons25, cons30) def replacement20(v, u, m, b, d, a, c, n, x): rubi.append(20) return Dist((a + b * v)**m * (c + d * v)**(-m), Int(u * (c + d * v)**(m + n), x), x) rule20 = ReplacementRule(pattern20, replacement20) pattern21 = Pattern( Integral( (v_ * WC('a', S(1)))**m_ * (v_**S(2) * WC('c', S(1)) + v_ * WC('b', S(1))) * WC('u', S(1)), x_), cons2, cons3, cons7, cons31, cons32) def replacement21(v, u, m, b, c, a, x): rubi.append(21) return Dist(S(1) / a, Int(u * (a * v)**(m + S(1)) * (b + c * v), x), x) rule21 = ReplacementRule(pattern21, replacement21) pattern22 = Pattern( Integral( (a_ + v_ * WC('b', S(1)))**m_ * (v_**S(2) * WC('C', S(1)) + v_ * WC('B', S(1)) + WC('A', S(0))) * WC('u', S(1)), x_), cons2, cons3, cons34, cons35, cons36, cons33, cons31, cons32) def replacement22(B, v, C, u, m, b, a, x, A): rubi.append(22) return Dist( b**(S(-2)), Int( u * (a + b * v)**(m + S(1)) * Simp(B * b - C * a + C * b * v, x), x), x) rule22 = ReplacementRule(pattern22, replacement22) pattern23 = Pattern( Integral((a_ + x_**WC('n', S(1)) * WC('b', S(1)))**WC('m', S(1)) * (c_ + x_**WC('q', S(1)) * WC('d', S(1)))**WC('p', S(1)) * WC('u', S(1)), x_), cons2, cons3, cons7, cons27, cons21, cons4, cons37, cons38, cons39, cons40) def replacement23(p, u, m, b, d, a, n, c, x, q): rubi.append(23) return Dist((d / a)**p, Int(u * x**(-n * p) * (a + b * x**n)**(m + p), x), x) rule23 = ReplacementRule(pattern23, replacement23) pattern24 = Pattern( Integral((a_ + x_**WC('n', S(1)) * WC('b', S(1)))**WC('m', S(1)) * (c_ + x_**j_ * WC('d', S(1)))**WC('p', S(1)) * WC('u', S(1)), x_), cons2, cons3, cons7, cons27, cons21, cons4, cons5, cons6, cons41, cons42, cons43, cons44) def replacement24(p, u, j, m, b, d, a, n, c, x): rubi.append(24) return Dist((-b**S(2) / d)**m, Int(u * (a - b * x**n)**(-m), x), x) rule24 = ReplacementRule(pattern24, replacement24) pattern25 = Pattern( Integral((a_ + x_**S(2) * WC('c', S(1)) + x_ * WC('b', S(1)))**WC( 'p', S(1)) * WC('u', S(1)), x_), cons2, cons3, cons7, cons45, cons38) def replacement25(p, u, b, c, a, x): rubi.append(25) return Int( S(2)**(-S(2) * p) * c**(-p) * u * (b + S(2) * c * x)**(S(2) * p), x) rule25 = ReplacementRule(pattern25, replacement25) pattern26 = Pattern( Integral( (a_ + x_**n_ * WC('b', S(1)) + x_**WC('n2', S(1)) * WC('c', S(1))) **WC('p', S(1)) * WC('u', S(1)), x_), cons2, cons3, cons7, cons4, cons46, cons45, cons38) def replacement26(p, u, b, n2, c, a, n, x): rubi.append(26) return Dist(c**(-p), Int(u * (b / S(2) + c * x**n)**(S(2) * p), x), x) rule26 = ReplacementRule(pattern26, replacement26) pattern27 = Pattern( Integral( (d_ + x_ * WC('e', S(1))) * (x_**S(2) * WC('c', S(1)) + x_ * WC('b', S(1)) + WC('a', S(0)))** WC('p', S(1)), x_), cons2, cons3, cons7, cons27, cons48, cons5, cons47) def replacement27(p, b, d, c, a, x, e): rubi.append(27) return Dist(d / b, Subst(Int(x**p, x), x, a + b * x + c * x**S(2)), x) rule27 = ReplacementRule(pattern27, replacement27) pattern28 = Pattern( Integral( (x_**WC('p', S(1)) * WC('a', S(1)) + x_**WC('q', S(1)) * WC('b', S(1)))**WC('m', S(1)) * WC('u', S(1)), x_), cons2, cons3, cons5, cons50, cons17, cons49) def replacement28(p, u, m, b, a, x, q): rubi.append(28) return Int(u * x**(m * p) * (a + b * x**(-p + q))**m, x) rule28 = ReplacementRule(pattern28, replacement28) pattern29 = Pattern( Integral( (x_**WC('p', S(1)) * WC('a', S(1)) + x_**WC('q', S(1)) * WC('b', S(1)) + x_**WC('r', S(1)) * WC('c', S(1)))**WC('m', S(1)) * WC('u', S(1)), x_), cons2, cons3, cons7, cons5, cons50, cons52, cons17, cons49, cons51) def replacement29(p, u, m, b, r, a, c, x, q): rubi.append(29) return Int(u * x**(m * p) * (a + b * x**(-p + q) + c * x**(-p + r))**m, x) rule29 = ReplacementRule(pattern29, replacement29) pattern30 = Pattern( Integral(x_**WC('m', S(1)) / (a_ + x_**n_ * WC('b', S(1))), x_), cons2, cons3, cons21, cons4, cons53) def replacement30(m, b, a, n, x): rubi.append(30) return Simp(log(RemoveContent(a + b * x**n, x)) / (b * n), x) rule30 = ReplacementRule(pattern30, replacement30) pattern31 = Pattern( Integral(x_**WC('m', S(1)) * (a_ + x_**n_ * WC('b', S(1)))**p_, x_), cons2, cons3, cons21, cons4, cons5, cons53, cons54) def replacement31(p, m, b, a, n, x): rubi.append(31) return Simp((a + b * x**n)**(p + S(1)) / (b * n * (p + S(1))), x) rule31 = ReplacementRule(pattern31, replacement31) pattern32 = Pattern( Integral( x_**WC('m', S(1)) * (a1_ + x_**WC('n', S(1)) * WC('b1', S(1)))**p_ * (a2_ + x_**WC('n', S(1)) * WC('b2', S(1)))**p_, x_), cons57, cons58, cons59, cons60, cons21, cons4, cons5, cons55, cons56, cons54) def replacement32(p, a2, m, b2, b1, n, x, a1): rubi.append(32) return Simp( (a1 + b1 * x**n)**(p + S(1)) * (a2 + b2 * x**n)**(p + S(1)) / (S(2) * b1 * b2 * n * (p + S(1))), x) rule32 = ReplacementRule(pattern32, replacement32) def With33(p, Pm, b, a, n, Qm, x): if isinstance(x, (int, Integer, float, Float)): return False m = Expon(Pm, x) if And( Equal(Expon(Qm, x), m + S(-1)), ZeroQ(-Qm * m * Coeff(Pm, x, m) + Coeff(Qm, x, m + S(-1)) * D(Pm, x))): return True return False pattern33 = Pattern( Integral( Qm_ * (Pm_**WC('n', S(1)) * WC('b', S(1)) + WC('a', S(0)))**WC( 'p', S(1)), x_), cons2, cons3, cons4, cons5, cons11, cons61, CustomConstraint(With33)) def replacement33(p, Pm, b, a, n, Qm, x): m = Expon(Pm, x) rubi.append(33) return Dist( Coeff(Qm, x, m + S(-1)) / (m * Coeff(Pm, x, m)), Subst(Int((a + b * x**n)**p, x), x, Pm), x) rule33 = ReplacementRule(pattern33, replacement33) def With34(p, Pm, b, n2, c, a, n, Qm, x): if isinstance(x, (int, Integer, float, Float)): return False m = Expon(Pm, x) if And( Equal(Expon(Qm, x), m + S(-1)), ZeroQ(-Qm * m * Coeff(Pm, x, m) + Coeff(Qm, x, m + S(-1)) * D(Pm, x))): return True return False pattern34 = Pattern( Integral( Qm_ * (Pm_**WC('n', S(1)) * WC('b', S(1)) + Pm_**WC('n2', S(1)) * WC('c', S(1)) + WC('a', S(0)))**WC('p', S(1)), x_), cons2, cons3, cons7, cons4, cons5, cons46, cons11, cons61, CustomConstraint(With34)) def replacement34(p, Pm, b, n2, c, a, n, Qm, x): m = Expon(Pm, x) rubi.append(34) return Dist( Coeff(Qm, x, m + S(-1)) / (m * Coeff(Pm, x, m)), Subst(Int((a + b * x**n + c * x**(S(2) * n))**p, x), x, Pm), x) rule34 = ReplacementRule(pattern34, replacement34) def With35(p, u, m, Pq, Qr, x): if isinstance(x, (int, Integer, float, Float)): return False gcd = PolyGCD(Pq, Qr, x) if NonzeroQ(gcd + S(-1)): return True return False pattern35 = Pattern(Integral(Pq_**m_ * Qr_**p_ * WC('u', S(1)), x_), cons62, cons63, cons64, cons65, CustomConstraint(With35)) def replacement35(p, u, m, Pq, Qr, x): gcd = PolyGCD(Pq, Qr, x) rubi.append(35) return Int( gcd**(m + p) * u * PolynomialQuotient(Pq, gcd, x)**m * PolynomialQuotient(Qr, gcd, x)**p, x) rule35 = ReplacementRule(pattern35, replacement35) def With36(p, u, Pq, Qr, x): if isinstance(x, (int, Integer, float, Float)): return False gcd = PolyGCD(Pq, Qr, x) if NonzeroQ(gcd + S(-1)): return True return False pattern36 = Pattern(Integral(Pq_ * Qr_**p_ * WC('u', S(1)), x_), cons63, cons64, cons65, CustomConstraint(With36)) def replacement36(p, u, Pq, Qr, x): gcd = PolyGCD(Pq, Qr, x) rubi.append(36) return Int( gcd**(p + S(1)) * u * PolynomialQuotient(Pq, gcd, x) * PolynomialQuotient(Qr, gcd, x)**p, x) rule36 = ReplacementRule(pattern36, replacement36) return [ rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8, rule9, rule10, rule11, rule12, rule13, rule14, rule15, rule16, rule17, rule18, rule19, rule20, rule21, rule22, rule23, rule24, rule25, rule26, rule27, rule28, rule29, rule30, rule31, rule32, rule33, rule34, rule35, rule36, ]
def piecewise_linear(rubi): from sympy.integrals.rubi.constraints import cons1090, cons21, cons1091, cons87, cons88, cons1092, cons89, cons23, cons72, cons66, cons4, cons1093, cons214, cons683, cons100, cons101, cons1094, cons1095, cons31, cons94, cons356, cons1096, cons18, cons1097, cons2, cons3 def With1882(x, m, u): c = D(u, x) rubi.append(1882) return Dist(S(1) / c, Subst(Int(x**m, x), x, u), x) pattern1882 = Pattern(Integral(u_**WC('m', S(1)), x_), cons21, cons1090) rule1882 = ReplacementRule(pattern1882, With1882) def With1883(v, x, u): if isinstance(x, (int, Integer, float, Float)): return False a = D(u, x) b = D(v, x) if NonzeroQ(-a * v + b * u): return True return False pattern1883 = Pattern(Integral(v_ / u_, x_), cons1091, CustomConstraint(With1883)) def replacement1883(v, x, u): a = D(u, x) b = D(v, x) rubi.append(1883) return -Dist( (-a * v + b * u) / a, Int(S(1) / u, x), x) + Simp(b * x / a, x) rule1883 = ReplacementRule(pattern1883, replacement1883) def With1884(v, x, n, u): if isinstance(x, (int, Integer, float, Float)): return False a = D(u, x) b = D(v, x) if NonzeroQ(-a * v + b * u): return True return False pattern1884 = Pattern(Integral(v_**n_ / u_, x_), cons1091, cons87, cons88, cons1092, CustomConstraint(With1884)) def replacement1884(v, x, n, u): a = D(u, x) b = D(v, x) rubi.append(1884) return -Dist( (-a * v + b * u) / a, Int(v**(n + S(-1)) / u, x), x) + Simp( v**n / (a * n), x) rule1884 = ReplacementRule(pattern1884, replacement1884) def With1885(v, x, u): if isinstance(x, (int, Integer, float, Float)): return False a = D(u, x) b = D(v, x) if NonzeroQ(-a * v + b * u): return True return False pattern1885 = Pattern(Integral(S(1) / (u_ * v_), x_), cons1091, CustomConstraint(With1885)) def replacement1885(v, x, u): a = D(u, x) b = D(v, x) rubi.append(1885) return -Dist(a / (-a * v + b * u), Int(S(1) / u, x), x) + Dist( b / (-a * v + b * u), Int(S(1) / v, x), x) rule1885 = ReplacementRule(pattern1885, replacement1885) def With1886(v, x, u): if isinstance(x, (int, Integer, float, Float)): return False a = D(u, x) b = D(v, x) if And(NonzeroQ(-a * v + b * u), PosQ((-a * v + b * u) / a)): return True return False pattern1886 = Pattern(Integral(S(1) / (u_ * sqrt(v_)), x_), cons1091, CustomConstraint(With1886)) def replacement1886(v, x, u): a = D(u, x) b = D(v, x) rubi.append(1886) return Simp( S(2) * ArcTan(sqrt(v) / Rt((-a * v + b * u) / a, S(2))) / (a * Rt( (-a * v + b * u) / a, S(2))), x) rule1886 = ReplacementRule(pattern1886, replacement1886) def With1887(v, x, u): if isinstance(x, (int, Integer, float, Float)): return False a = D(u, x) b = D(v, x) if And(NonzeroQ(-a * v + b * u), NegQ((-a * v + b * u) / a)): return True return False pattern1887 = Pattern(Integral(S(1) / (u_ * sqrt(v_)), x_), cons1091, CustomConstraint(With1887)) def replacement1887(v, x, u): a = D(u, x) b = D(v, x) rubi.append(1887) return Simp( -S(2) * atanh(sqrt(v) / Rt(-(-a * v + b * u) / a, S(2))) / (a * Rt(-(-a * v + b * u) / a, S(2))), x) rule1887 = ReplacementRule(pattern1887, replacement1887) def With1888(v, x, n, u): if isinstance(x, (int, Integer, float, Float)): return False a = D(u, x) b = D(v, x) if NonzeroQ(-a * v + b * u): return True return False pattern1888 = Pattern(Integral(v_**n_ / u_, x_), cons1091, cons87, cons89, CustomConstraint(With1888)) def replacement1888(v, x, n, u): a = D(u, x) b = D(v, x) rubi.append(1888) return -Dist(a / (-a * v + b * u), Int(v**(n + S(1)) / u, x), x) + Simp( v**(n + S(1)) / ((n + S(1)) * (-a * v + b * u)), x) rule1888 = ReplacementRule(pattern1888, replacement1888) def With1889(v, x, n, u): if isinstance(x, (int, Integer, float, Float)): return False a = D(u, x) b = D(v, x) if NonzeroQ(-a * v + b * u): return True return False pattern1889 = Pattern(Integral(v_**n_ / u_, x_), cons1091, cons23, CustomConstraint(With1889)) def replacement1889(v, x, n, u): a = D(u, x) b = D(v, x) rubi.append(1889) return Simp( v**(n + S(1)) * Hypergeometric2F1(S(1), n + S(1), n + S(2), -a * v / (-a * v + b * u)) / ((n + S(1)) * (-a * v + b * u)), x) rule1889 = ReplacementRule(pattern1889, replacement1889) def With1890(v, x, u): if isinstance(x, (int, Integer, float, Float)): return False a = D(u, x) b = D(v, x) if And(NonzeroQ(-a * v + b * u), PosQ(a * b)): return True return False pattern1890 = Pattern(Integral(S(1) / (sqrt(u_) * sqrt(v_)), x_), cons1091, CustomConstraint(With1890)) def replacement1890(v, x, u): a = D(u, x) b = D(v, x) rubi.append(1890) return Simp( S(2) * atanh(sqrt(u) * Rt(a * b, S(2)) / (a * sqrt(v))) / Rt(a * b, S(2)), x) rule1890 = ReplacementRule(pattern1890, replacement1890) def With1891(v, x, u): if isinstance(x, (int, Integer, float, Float)): return False a = D(u, x) b = D(v, x) if And(NonzeroQ(-a * v + b * u), NegQ(a * b)): return True return False pattern1891 = Pattern(Integral(S(1) / (sqrt(u_) * sqrt(v_)), x_), cons1091, CustomConstraint(With1891)) def replacement1891(v, x, u): a = D(u, x) b = D(v, x) rubi.append(1891) return Simp( S(2) * ArcTan(sqrt(u) * Rt(-a * b, S(2)) / (a * sqrt(v))) / Rt(-a * b, S(2)), x) rule1891 = ReplacementRule(pattern1891, replacement1891) def With1892(v, u, m, n, x): if isinstance(x, (int, Integer, float, Float)): return False a = D(u, x) b = D(v, x) if NonzeroQ(-a * v + b * u): return True return False pattern1892 = Pattern(Integral(u_**m_ * v_**n_, x_), cons21, cons4, cons1091, cons72, cons66, CustomConstraint(With1892)) def replacement1892(v, u, m, n, x): a = D(u, x) b = D(v, x) rubi.append(1892) return -Simp( u**(m + S(1)) * v**(n + S(1)) / ((m + S(1)) * (-a * v + b * u)), x) rule1892 = ReplacementRule(pattern1892, replacement1892) def With1893(v, u, m, n, x): if isinstance(x, (int, Integer, float, Float)): return False a = D(u, x) b = D(v, x) if NonzeroQ(-a * v + b * u): return True return False pattern1893 = Pattern(Integral(u_**m_ * v_**WC('n', S(1)), x_), cons21, cons4, cons1091, cons66, cons1093, CustomConstraint(With1893)) def replacement1893(v, u, m, n, x): a = D(u, x) b = D(v, x) rubi.append(1893) return -Dist(b * n / (a * (m + S(1))), Int(u**(m + S(1)) * v**(n + S(-1)), x), x) + Simp(u**(m + S(1)) * v**n / (a * (m + S(1))), x) rule1893 = ReplacementRule(pattern1893, replacement1893) def With1894(v, u, m, n, x): if isinstance(x, (int, Integer, float, Float)): return False a = D(u, x) b = D(v, x) if NonzeroQ(-a * v + b * u): return True return False pattern1894 = Pattern(Integral(u_**m_ * v_**WC('n', S(1)), x_), cons1091, cons214, cons87, cons88, cons683, cons100, cons101, CustomConstraint(With1894)) def replacement1894(v, u, m, n, x): a = D(u, x) b = D(v, x) rubi.append(1894) return -Dist(n * (-a * v + b * u) / (a * (m + n + S(1))), Int(u**m * v**(n + S(-1)), x), x) + Simp(u**(m + S(1)) * v**n / (a * (m + n + S(1))), x) rule1894 = ReplacementRule(pattern1894, replacement1894) def With1895(v, u, m, n, x): if isinstance(x, (int, Integer, float, Float)): return False a = D(u, x) b = D(v, x) if NonzeroQ(-a * v + b * u): return True return False pattern1895 = Pattern(Integral(u_**m_ * v_**n_, x_), cons1091, cons683, cons1094, cons1095, CustomConstraint(With1895)) def replacement1895(v, u, m, n, x): a = D(u, x) b = D(v, x) rubi.append(1895) return -Dist(n * (-a * v + b * u) / (a * (m + n + S(1))), Int(u**m * v**(n + S(-1)), x), x) + Simp(u**(m + S(1)) * v**n / (a * (m + n + S(1))), x) rule1895 = ReplacementRule(pattern1895, replacement1895) def With1896(v, u, m, n, x): if isinstance(x, (int, Integer, float, Float)): return False a = D(u, x) b = D(v, x) if NonzeroQ(-a * v + b * u): return True return False pattern1896 = Pattern(Integral(u_**m_ * v_**n_, x_), cons1091, cons214, cons31, cons94, CustomConstraint(With1896)) def replacement1896(v, u, m, n, x): a = D(u, x) b = D(v, x) rubi.append(1896) return Dist(b * (m + n + S(2)) / ( (m + S(1)) * (-a * v + b * u)), Int(u**(m + S(1)) * v**n, x), x) - Simp( u**(m + S(1)) * v**(n + S(1)) / ((m + S(1)) * (-a * v + b * u)), x) rule1896 = ReplacementRule(pattern1896, replacement1896) def With1897(v, u, m, n, x): if isinstance(x, (int, Integer, float, Float)): return False a = D(u, x) b = D(v, x) if NonzeroQ(-a * v + b * u): return True return False pattern1897 = Pattern(Integral(u_**m_ * v_**n_, x_), cons1091, cons356, cons1096, CustomConstraint(With1897)) def replacement1897(v, u, m, n, x): a = D(u, x) b = D(v, x) rubi.append(1897) return Dist(b * (m + n + S(2)) / ( (m + S(1)) * (-a * v + b * u)), Int(u**(m + S(1)) * v**n, x), x) - Simp( u**(m + S(1)) * v**(n + S(1)) / ((m + S(1)) * (-a * v + b * u)), x) rule1897 = ReplacementRule(pattern1897, replacement1897) def With1898(v, u, m, n, x): if isinstance(x, (int, Integer, float, Float)): return False a = D(u, x) b = D(v, x) if NonzeroQ(-a * v + b * u): return True return False pattern1898 = Pattern(Integral(u_**m_ * v_**n_, x_), cons1091, cons18, cons23, CustomConstraint(With1898)) def replacement1898(v, u, m, n, x): a = D(u, x) b = D(v, x) rubi.append(1898) return Simp( u**m * v**(n + S(1)) * (b * u / (-a * v + b * u))**(-m) * Hypergeometric2F1(-m, n + S(1), n + S(2), -a * v / (-a * v + b * u)) / (b * (n + S(1))), x) rule1898 = ReplacementRule(pattern1898, replacement1898) def With1899(u, b, a, n, x): c = D(u, x) rubi.append(1899) return -Dist(c * n / b, Int(u**(n + S(-1)) * (a + b * x) * log(a + b * x), x), x) - Int( u**n, x) + Simp( u**n * (a + b * x) * log(a + b * x) / b, x) pattern1899 = Pattern( Integral(u_**WC('n', S(1)) * log(x_ * WC('b', S(1)) + WC('a', S(0))), x_), cons2, cons3, cons1090, cons1097, cons87, cons88) rule1899 = ReplacementRule(pattern1899, With1899) def With1900(u, m, b, a, n, x): c = D(u, x) rubi.append(1900) return -Dist( c * n / (b * (m + S(1))), Int(u**(n + S(-1)) * (a + b * x)**(m + S(1)) * log(a + b * x), x), x) - Dist( S(1) / (m + S(1)), Int(u**n * (a + b * x)**m, x), x) + Simp( u**n * (a + b * x)**(m + S(1)) * log(a + b * x) / (b * (m + S(1))), x) pattern1900 = Pattern( Integral( u_**WC('n', S(1)) * (x_ * WC('b', S(1)) + WC('a', S(0)))**WC('m', S(1)) * log(x_ * WC('b', S(1)) + WC('a', S(0))), x_), cons2, cons3, cons21, cons1090, cons1097, cons87, cons88, cons66) rule1900 = ReplacementRule(pattern1900, With1900) return [ rule1882, rule1883, rule1884, rule1885, rule1886, rule1887, rule1888, rule1889, rule1890, rule1891, rule1892, rule1893, rule1894, rule1895, rule1896, rule1897, rule1898, rule1899, rule1900, ]
def integrand_simplification(rubi): pattern1 = Pattern( Integral((a_ + x_**WC('n', S(1)) * WC('b', S(1)))**WC('p', S(1)) * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda p, x: FreeQ(p, x)), CustomConstraint(lambda a: ZeroQ(a))) rule1 = ReplacementRule(pattern1, lambda p, b, u, a, x, n: Int(u * (b * x**n)**p, x)) rubi.add(rule1) pattern2 = Pattern( Integral( (a_ + x_**WC('j', S(1)) * WC('c', S(1)) + x_**WC('n', S(1)) * WC('b', S(1)))**WC('p', S(1)) * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda c, x: FreeQ(c, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda p, x: FreeQ(p, x)), CustomConstraint(lambda n, j: ZeroQ(j - S(2) * n)), CustomConstraint(lambda a: ZeroQ(a))) rule2 = ReplacementRule( pattern2, lambda j, b, p, u, a, x, n, c: Int( u * (b * x**n + c * x**(S(2) * n))**p, x)) rubi.add(rule2) pattern3 = Pattern( Integral((x_**WC('j', S(1)) * WC('c', S(1)) + x_**WC('n', S(1)) * WC('b', S(1)) + WC('a', S(0)))**WC( 'p', S(1)) * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda c, x: FreeQ(c, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda p, x: FreeQ(p, x)), CustomConstraint(lambda n, j: ZeroQ(j - S(2) * n)), CustomConstraint(lambda b: ZeroQ(b))) rule3 = ReplacementRule( pattern3, lambda j, b, p, u, a, x, n, c: Int(u * (a + c * x**(S(2) * n))**p, x)) rubi.add(rule3) pattern4 = Pattern( Integral((x_**WC('j', S(1)) * WC('c', S(1)) + x_**WC('n', S(1)) * WC('b', S(1)) + WC('a', S(0)))**WC( 'p', S(1)) * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda c, x: FreeQ(c, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda p, x: FreeQ(p, x)), CustomConstraint(lambda n, j: ZeroQ(j - S(2) * n)), CustomConstraint(lambda c: ZeroQ(c))) rule4 = ReplacementRule( pattern4, lambda j, b, p, u, a, x, n, c: Int(u * (a + b * x**n)**p, x)) rubi.add(rule4) pattern5 = Pattern( Integral((v_ * WC('a', S(1)) + v_ * WC('b', S(1)) + WC('w', S(0)))**WC( 'p', S(1)) * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda x, v: NFreeQ(v, x))) rule5 = ReplacementRule( pattern5, lambda p, b, v, u, a, x, w: Int(u * (v * (a + b) + w)**p, x)) rubi.add(rule5) pattern6 = Pattern(Integral(Pm_**p_ * WC('u', S(1)), x_), CustomConstraint(lambda p, x: FreeQ(p, x)), CustomConstraint(lambda x, Pm: PolyQ(Pm, x)), CustomConstraint(lambda p: Not(RationalQ(p))), CustomConstraint(lambda p: RationalQ(p))) rule6 = ReplacementRule(pattern6, lambda u, x, p, Pm: Int(Pm**p * u, x)) rubi.add(rule6) pattern7 = Pattern(Integral(a_, x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda a, x: FreeQ(a, x))) rule7 = ReplacementRule(pattern7, lambda a, x: a * x) rubi.add(rule7) pattern8 = Pattern( Integral(a_ * (b_ + x_ * WC('c', S(1))), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda c, x: FreeQ(c, x)), CustomConstraint(lambda a, c, b, x: FreeQ(List(a, b, c), x))) rule8 = ReplacementRule( pattern8, lambda a, c, b, x: a * (b + c * x)**S(2) / (S(2) * c)) rubi.add(rule8) pattern9 = Pattern(Integral(-u_, x_)) rule9 = ReplacementRule(pattern9, lambda u, x: I * Int(u, x)) rubi.add(rule9) pattern10 = Pattern(Integral(u_ * Complex(S(0), a_), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda a: EqQ(a**S(2), S(1)))) rule10 = ReplacementRule(pattern10, lambda u, a, x: Int(u, x) * Complex(I, a)) rubi.add(rule10) pattern11 = Pattern(Integral(a_ * u_, x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda a, x: FreeQ(a, x))) rule11 = ReplacementRule(pattern11, lambda u, a, x: a * Int(u, x)) rubi.add(rule11) pattern12 = Pattern(Integral(u_, x_), CustomConstraint(lambda u: SumQ(u))) rule12 = ReplacementRule(pattern12, lambda u, x: IntSum(u, x)) rubi.add(rule12) pattern13 = Pattern( Integral(v_**WC('m', S(1)) * (b_ * v_)**n_ * WC('u', S(1)), x_), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda m: IntegerQ(m))) rule13 = ReplacementRule( pattern13, lambda b, v, u, m, x, n: b**(-m) * Int(u * (b * v)**(m + n), x)) rubi.add(rule13) pattern14 = Pattern( Integral((v_ * WC('a', S(1)))**m_ * (v_ * WC('b', S(1)))**n_ * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda m, x: FreeQ(m, x)), CustomConstraint(lambda m: Not(IntegerQ(m))), CustomConstraint(lambda n: PositiveIntegerQ(n + S(1) / 2)), CustomConstraint(lambda m, n: IntegerQ(m + n))) rule14 = ReplacementRule( pattern14, lambda b, v, u, m, a, x, n: a**(m + S(1) / 2) * b** (n + S(-1) / 2) * sqrt(b * v) * Int(u * v**(m + n), x) / sqrt(a * v)) rubi.add(rule14) pattern15 = Pattern( Integral((v_ * WC('a', S(1)))**m_ * (v_ * WC('b', S(1)))**n_ * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda m, x: FreeQ(m, x)), CustomConstraint(lambda m: Not(IntegerQ(m))), CustomConstraint(lambda n: NegativeIntegerQ(n + S(-1) / 2)), CustomConstraint(lambda m, n: IntegerQ(m + n))) rule15 = ReplacementRule( pattern15, lambda b, v, u, m, a, x, n: a**(m + S(-1) / 2) * b** (n + S(1) / 2) * sqrt(a * v) * Int(u * v**(m + n), x) / sqrt(b * v)) rubi.add(rule15) pattern16 = Pattern( Integral((v_ * WC('a', S(1)))**m_ * (v_ * WC('b', S(1)))**n_ * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda m, x: FreeQ(m, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda m: Not(IntegerQ(m))), CustomConstraint(lambda n: Not(IntegerQ(n))), CustomConstraint(lambda m, n: IntegerQ(m + n))) rule16 = ReplacementRule( pattern16, lambda b, v, u, m, a, x, n: a**(m + n) * (a * v)**(-n) * (b * v)**n * Int(u * v**(m + n), x)) rubi.add(rule16) pattern17 = Pattern( Integral((v_ * WC('a', S(1)))**m_ * (v_ * WC('b', S(1)))**n_ * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda m, x: FreeQ(m, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda m: Not(IntegerQ(m))), CustomConstraint(lambda n: Not(IntegerQ(n))), CustomConstraint(lambda m, n: Not(IntegerQ(m + n)))) rule17 = ReplacementRule( pattern17, lambda b, v, u, m, a, x, n: a**(-IntPart(n)) * b**IntPart(n) * (a * v)**(-FracPart(n)) * (b * v)**FracPart(n) * Int(u * (a * v)**(m + n), x)) rubi.add(rule17) pattern18 = Pattern( Integral((a_ + v_ * WC('b', S(1)))**WC('m', S(1)) * (c_ + v_ * WC('d', S(1)))**WC('n', S(1)) * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda c, x: FreeQ(c, x)), CustomConstraint(lambda d, x: FreeQ(d, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda a, c, b, d: ZeroQ(-a * d + b * c)), CustomConstraint(lambda m: IntegerQ(m)), CustomConstraint(lambda b, a, x, d, n, c: Not(IntegerQ(n)) | SimplerQ( c + d * x, a + b * x))) rule18 = ReplacementRule( pattern18, lambda b, v, u, m, a, x, d, n, c: (b / d)**m * Int(u * (c + d * v)**(m + n), x)) rubi.add(rule18) pattern19 = Pattern( Integral((a_ + v_ * WC('b', S(1)))**m_ * (c_ + v_ * WC('d', S(1)))**n_ * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda c, x: FreeQ(c, x)), CustomConstraint(lambda d, x: FreeQ(d, x)), CustomConstraint(lambda m, x: FreeQ(m, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda a, c, b, d: ZeroQ(-a * d + b * c)), CustomConstraint(lambda b, d: PositiveQ(b / d)), CustomConstraint(lambda m, n: Not(IntegerQ(m) | IntegerQ(n)))) rule19 = ReplacementRule( pattern19, lambda b, v, u, m, a, x, d, n, c: (b / d)**m * Int(u * (c + d * v)**(m + n), x)) rubi.add(rule19) pattern20 = Pattern( Integral((a_ + v_ * WC('b', S(1)))**m_ * (c_ + v_ * WC('d', S(1)))**n_ * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda c, x: FreeQ(c, x)), CustomConstraint(lambda d, x: FreeQ(d, x)), CustomConstraint(lambda m, x: FreeQ(m, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda a, c, b, d: ZeroQ(-a * d + b * c)), CustomConstraint(lambda m, n, b, d: Not( IntegerQ(m) | IntegerQ(n) | PositiveQ(b / d)))) rule20 = ReplacementRule( pattern20, lambda b, v, u, m, a, x, d, n, c: (a + b * v)**m * (c + d * v)**(-m) * Int(u * (c + d * v)**(m + n), x)) rubi.add(rule20) pattern21 = Pattern( Integral( (v_ * WC('a', S(1)))**m_ * (v_**S(2) * WC('c', S(1)) + v_ * WC('b', S(1))) * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda c, x: FreeQ(c, x)), CustomConstraint(lambda m: RationalQ(m)), CustomConstraint(lambda m: LessEqual(m, S(-1)))) rule21 = ReplacementRule( pattern21, lambda b, v, u, m, a, x, c: Int(u * (a * v)**(m + S(1)) * (b + c * v), x) / a) rubi.add(rule21) pattern22 = Pattern( Integral( (a_ + v_ * WC('b', S(1)))**m_ * (v_**S(2) * WC('C', S(1)) + v_ * WC('B', S(1)) + WC('A', S(0))) * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda A, x: FreeQ(A, x)), CustomConstraint(lambda B, x: FreeQ(B, x)), CustomConstraint(lambda C, x: FreeQ(C, x)), CustomConstraint(lambda b, A, B, a, C: ZeroQ(A * b**S(2) - B * a * b + C * a**S(2))), CustomConstraint(lambda m: RationalQ(m)), CustomConstraint(lambda m: LessEqual(m, S(-1)))) rule22 = ReplacementRule( pattern22, lambda b, v, u, A, B, m, a, x, C: Int( u * (a + b * v)** (m + S(1)) * Simp(B * b - C * a + C * b * v, x), x) / b**S(2)) rubi.add(rule22) pattern23 = Pattern( Integral((a_ + x_**WC('n', S(1)) * WC('b', S(1)))**WC('m', S(1)) * (c_ + x_**WC('q', S(1)) * WC('d', S(1)))**WC('p', S(1)) * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda c, x: FreeQ(c, x)), CustomConstraint(lambda d, x: FreeQ(d, x)), CustomConstraint(lambda m, x: FreeQ(m, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda n, q: ZeroQ(n + q)), CustomConstraint(lambda p: IntegerQ(p)), CustomConstraint(lambda a, c, b, d: ZeroQ(a * c - b * d)), CustomConstraint(lambda m, n: Not(IntegerQ(m) & NegQ(n)))) rule23 = ReplacementRule( pattern23, lambda q, p, b, u, m, a, x, d, n, c: (d / a)**p * Int(u * x**(-n * p) * (a + b * x**n)**(m + p), x)) rubi.add(rule23) pattern24 = Pattern( Integral((a_ + x_**WC('n', S(1)) * WC('b', S(1)))**WC('m', S(1)) * (c_ + x_**j_ * WC('d', S(1)))**WC('p', S(1)) * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda c, x: FreeQ(c, x)), CustomConstraint(lambda d, x: FreeQ(d, x)), CustomConstraint(lambda m, x: FreeQ(m, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda p, x: FreeQ(p, x)), CustomConstraint(lambda n, j: ZeroQ(j - S(2) * n)), CustomConstraint(lambda m, p: ZeroQ(m + p)), CustomConstraint(lambda a, c, b, d: ZeroQ(a**S(2) * d + b**S(2) * c)), CustomConstraint(lambda a: PositiveQ(a)), CustomConstraint(lambda d: NegativeQ(d))) rule24 = ReplacementRule( pattern24, lambda p, b, j, u, m, a, x, d, n, c: (-b**S(2) / d)**m * Int(u * (a - b * x**n)**(-m), x)) rubi.add(rule24) pattern25 = Pattern( Integral((a_ + x_**S(2) * WC('c', S(1)) + x_ * WC('b', S(1)))**WC( 'p', S(1)) * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda c, x: FreeQ(c, x)), CustomConstraint(lambda a, c, b: ZeroQ(-S(4) * a * c + b**S(2))), CustomConstraint(lambda p: IntegerQ(p))) rule25 = ReplacementRule( pattern25, lambda p, b, u, a, x, c: Int( S(2)**(-S(2) * p) * c**(-p) * u * (b + S(2) * c * x)**(S(2) * p), x)) rubi.add(rule25) pattern26 = Pattern( Integral( (a_ + x_**n_ * WC('b', S(1)) + x_**WC('n2', S(1)) * WC('c', S(1))) **WC('p', S(1)) * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda c, x: FreeQ(c, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda n, n2: ZeroQ(-S(2) * n + n2)), CustomConstraint(lambda a, c, b: ZeroQ(-S(4) * a * c + b**S(2))), CustomConstraint(lambda p: IntegerQ(p))) rule26 = ReplacementRule( pattern26, lambda n2, p, b, u, a, x, n, c: c** (-p) * Int(u * (b / S(2) + c * x**n)**(S(2) * p), x)) rubi.add(rule26) pattern27 = Pattern( Integral( (d_ + x_ * WC('e', S(1))) * (x_**S(2) * WC('c', S(1)) + x_ * WC('b', S(1)) + WC('a', S(0)))** WC('p', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda c, x: FreeQ(c, x)), CustomConstraint(lambda d, x: FreeQ(d, x)), CustomConstraint(lambda e, x: FreeQ(e, x)), CustomConstraint(lambda p, x: FreeQ(p, x)), CustomConstraint(lambda e, c, b, d: ZeroQ(-b * e + S(2) * c * d))) rule27 = ReplacementRule( pattern27, lambda p, b, a, x, d, e, c: d * Subst( Int(x**p, x), x, a + b * x + c * x**S(2)) / b) rubi.add(rule27) pattern28 = Pattern( Integral( (x_**WC('p', S(1)) * WC('a', S(1)) + x_**WC('q', S(1)) * WC('b', S(1)))**WC('m', S(1)) * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda p, x: FreeQ(p, x)), CustomConstraint(lambda q, x: FreeQ(q, x)), CustomConstraint(lambda m: IntegerQ(m)), CustomConstraint(lambda q, p: PosQ(-p + q))) rule28 = ReplacementRule( pattern28, lambda q, p, b, u, m, a, x: Int( u * x**(m * p) * (a + b * x**(-p + q))**m, x)) rubi.add(rule28) pattern29 = Pattern( Integral( (x_**WC('p', S(1)) * WC('a', S(1)) + x_**WC('q', S(1)) * WC('b', S(1)) + x_**WC('r', S(1)) * WC('c', S(1)))**WC('m', S(1)) * WC('u', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda c, x: FreeQ(c, x)), CustomConstraint(lambda p, x: FreeQ(p, x)), CustomConstraint(lambda q, x: FreeQ(q, x)), CustomConstraint(lambda r, x: FreeQ(r, x)), CustomConstraint(lambda m: IntegerQ(m)), CustomConstraint(lambda q, p: PosQ(-p + q)), CustomConstraint(lambda r, p: PosQ(-p + r))) rule29 = ReplacementRule( pattern29, lambda q, r, p, b, u, m, a, x, c: Int( u * x**(m * p) * (a + b * x**(-p + q) + c * x**(-p + r))**m, x)) rubi.add(rule29) pattern30 = Pattern( Integral(x_**WC('m', S(1)) / (a_ + x_**n_ * WC('b', S(1))), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda m, x: FreeQ(m, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda m, n: ZeroQ(m - n + S(1)))) rule30 = ReplacementRule( pattern30, lambda b, m, a, x, n: log(RemoveContent(a + b * x**n, x)) / (b * n)) rubi.add(rule30) pattern31 = Pattern( Integral(x_**WC('m', S(1)) * (a_ + x_**n_ * WC('b', S(1)))**p_, x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda m, x: FreeQ(m, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda p, x: FreeQ(p, x)), CustomConstraint(lambda m, n: ZeroQ(m - n + S(1))), CustomConstraint(lambda p: NonzeroQ(p + S(1)))) rule31 = ReplacementRule( pattern31, lambda p, b, m, a, x, n: (a + b * x**n)**(p + S(1)) / (b * n * (p + S(1)))) rubi.add(rule31) pattern32 = Pattern( Integral( x_**WC('m', S(1)) * (a1_ + x_**WC('n', S(1)) * WC('b1', S(1)))**p_ * (a2_ + x_**WC('n', S(1)) * WC('b2', S(1)))**p_, x_), CustomConstraint(lambda a1, x: FreeQ(a1, x)), CustomConstraint(lambda b1, x: FreeQ(b1, x)), CustomConstraint(lambda a2, x: FreeQ(a2, x)), CustomConstraint(lambda b2, x: FreeQ(b2, x)), CustomConstraint(lambda m, x: FreeQ(m, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda p, x: FreeQ(p, x)), CustomConstraint(lambda b2, b1, a1, a2: ZeroQ(a1 * b2 + a2 * b1)), CustomConstraint(lambda m, n: ZeroQ(m - S(2) * n + S(1))), CustomConstraint(lambda p: NonzeroQ(p + S(1)))) rule32 = ReplacementRule( pattern32, lambda p, a1, b2, m, x, a2, n, b1: (a1 + b1 * x**n)**(p + S(1)) * (a2 + b2 * x**n)**(p + S(1)) / (S(2) * b1 * b2 * n * (p + S(1)))) rubi.add(rule32) ''' pattern33 = Pattern(Integral(Qm_*(Pm_**WC('n', S(1))*WC('b', S(1)) + WC('a', S(0)))**WC('p', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda p, x: FreeQ(p, x)), CustomConstraint(lambda x, Pm: PolyQ(Pm, x)), CustomConstraint(lambda Qm, x: PolyQ(Qm, x)), ) def With33(p, b, a, x, n, Qm, Pm): m = Expon(Pm, x) if Equal(Expon(Qm, x), m + S(-1)) & ZeroQ(-Qm*m*Coeff(Pm, x, m) + Coeff(Qm, x, m + S(-1))*D(Pm, x)): return Coeff(Qm, x, m + S(-1))*Subst(Int((a + b*x**n)**p, x), x, Pm)/(m*Coeff(Pm, x, m)) print("Unable to Integrate") rule33 = ReplacementRule(pattern33, lambda p, b, a, x, n, Qm, Pm : With33(p, b, a, x, n, Qm, Pm)) rubi.add(rule33) pattern34 = Pattern(Integral(Qm_*(Pm_**WC('n', S(1))*WC('b', S(1)) + Pm_**WC('n2', S(1))*WC('c', S(1)) + WC('a', S(0)))**WC('p', S(1)), x_), CustomConstraint(lambda a, x: FreeQ(a, x)), CustomConstraint(lambda b, x: FreeQ(b, x)), CustomConstraint(lambda c, x: FreeQ(c, x)), CustomConstraint(lambda n, x: FreeQ(n, x)), CustomConstraint(lambda p, x: FreeQ(p, x)), CustomConstraint(lambda n, n2: ZeroQ(-S(2)*n + n2)), CustomConstraint(lambda x, Pm: PolyQ(Pm, x)), CustomConstraint(lambda Qm, x: PolyQ(Qm, x)), ) def With34(n2, p, b, a, x, n, Qm, c, Pm): m = Expon(Pm, x) if Equal(Expon(Qm, x), m + S(-1)) & ZeroQ(-Qm*m*Coeff(Pm, x, m) + Coeff(Qm, x, m + S(-1))*D(Pm, x)): return Coeff(Qm, x, m + S(-1))*Subst(Int((a + b*x**n + c*x**(S(2)*n))**p, x), x, Pm)/(m*Coeff(Pm, x, m)) print("Unable to Integrate") rule34 = ReplacementRule(pattern34, lambda n2, p, b, a, x, n, Qm, c, Pm : With34(n2, p, b, a, x, n, Qm, c, Pm)) rubi.add(rule34) pattern35 = Pattern(Integral(Pq_**m_*Qr_**p_*WC('u', S(1)), x_), CustomConstraint(lambda m: PositiveIntegerQ(m)), CustomConstraint(lambda p: NegativeIntegerQ(p)), CustomConstraint(lambda Pq, x: PolyQ(Pq, x)), CustomConstraint(lambda Qr, x: PolyQ(Qr, x)), ) def With35(Qr, p, u, Pq, m, x): gcd = PolyGCD(Pq, Qr, x) if NonzeroQ(gcd + S(-1)): return Int(gcd**(m + p)*u*PolynomialQuotient(Pq, gcd, x)**m*PolynomialQuotient(Qr, gcd, x)**p, x) print("Unable to Integrate") rule35 = ReplacementRule(pattern35, lambda Qr, p, u, Pq, m, x : With35(Qr, p, u, Pq, m, x)) rubi.add(rule35) pattern36 = Pattern(Integral(Pq_*Qr_**p_*WC('u', S(1)), x_), CustomConstraint(lambda p: NegativeIntegerQ(p)), CustomConstraint(lambda Pq, x: PolyQ(Pq, x)), CustomConstraint(lambda Qr, x: PolyQ(Qr, x)), ) def With36(Qr, p, u, Pq, x): gcd = PolyGCD(Pq, Qr, x) if NonzeroQ(gcd + S(-1)): return Int(gcd**(p + S(1))*u*PolynomialQuotient(Pq, gcd, x)*PolynomialQuotient(Qr, gcd, x)**p, x) print("Unable to Integrate") rule36 = ReplacementRule(pattern36, lambda Qr, p, u, Pq, x : With36(Qr, p, u, Pq, x)) rubi.add(rule36) ''' return rubi
def piecewise_linear(): from sympy.integrals.rubi.constraints import cons1092, cons19, cons1093, cons89, cons90, cons1094, cons91, cons25, cons74, cons68, cons4, cons1095, cons216, cons685, cons102, cons103, cons1096, cons1097, cons33, cons96, cons358, cons1098, cons21, cons1099, cons2, cons3 pattern1885 = Pattern(Integral(u_**WC('m', S(1)), x_), cons19, cons1092) rule1885 = ReplacementRule(pattern1885, With1885) pattern1886 = Pattern(Integral(v_ / u_, x_), cons1093, CustomConstraint(With1886)) rule1886 = ReplacementRule(pattern1886, replacement1886) pattern1887 = Pattern(Integral(v_**n_ / u_, x_), cons1093, cons89, cons90, cons1094, CustomConstraint(With1887)) rule1887 = ReplacementRule(pattern1887, replacement1887) pattern1888 = Pattern(Integral(S(1) / (u_ * v_), x_), cons1093, CustomConstraint(With1888)) rule1888 = ReplacementRule(pattern1888, replacement1888) pattern1889 = Pattern(Integral(S(1) / (u_ * sqrt(v_)), x_), cons1093, CustomConstraint(With1889)) rule1889 = ReplacementRule(pattern1889, replacement1889) pattern1890 = Pattern(Integral(S(1) / (u_ * sqrt(v_)), x_), cons1093, CustomConstraint(With1890)) rule1890 = ReplacementRule(pattern1890, replacement1890) pattern1891 = Pattern(Integral(v_**n_ / u_, x_), cons1093, cons89, cons91, CustomConstraint(With1891)) rule1891 = ReplacementRule(pattern1891, replacement1891) pattern1892 = Pattern(Integral(v_**n_ / u_, x_), cons1093, cons25, CustomConstraint(With1892)) rule1892 = ReplacementRule(pattern1892, replacement1892) pattern1893 = Pattern(Integral(S(1) / (sqrt(u_) * sqrt(v_)), x_), cons1093, CustomConstraint(With1893)) rule1893 = ReplacementRule(pattern1893, replacement1893) pattern1894 = Pattern(Integral(S(1) / (sqrt(u_) * sqrt(v_)), x_), cons1093, CustomConstraint(With1894)) rule1894 = ReplacementRule(pattern1894, replacement1894) pattern1895 = Pattern(Integral(u_**m_ * v_**n_, x_), cons19, cons4, cons1093, cons74, cons68, CustomConstraint(With1895)) rule1895 = ReplacementRule(pattern1895, replacement1895) pattern1896 = Pattern(Integral(u_**m_ * v_**WC('n', S(1)), x_), cons19, cons4, cons1093, cons68, cons1095, CustomConstraint(With1896)) rule1896 = ReplacementRule(pattern1896, replacement1896) pattern1897 = Pattern(Integral(u_**m_ * v_**WC('n', S(1)), x_), cons1093, cons216, cons89, cons90, cons685, cons102, cons103, CustomConstraint(With1897)) rule1897 = ReplacementRule(pattern1897, replacement1897) pattern1898 = Pattern(Integral(u_**m_ * v_**n_, x_), cons1093, cons685, cons1096, cons1097, CustomConstraint(With1898)) rule1898 = ReplacementRule(pattern1898, replacement1898) pattern1899 = Pattern(Integral(u_**m_ * v_**n_, x_), cons1093, cons216, cons33, cons96, CustomConstraint(With1899)) rule1899 = ReplacementRule(pattern1899, replacement1899) pattern1900 = Pattern(Integral(u_**m_ * v_**n_, x_), cons1093, cons358, cons1098, CustomConstraint(With1900)) rule1900 = ReplacementRule(pattern1900, replacement1900) pattern1901 = Pattern(Integral(u_**m_ * v_**n_, x_), cons1093, cons21, cons25, CustomConstraint(With1901)) rule1901 = ReplacementRule(pattern1901, replacement1901) pattern1902 = Pattern( Integral(u_**WC('n', S(1)) * log(x_ * WC('b', S(1)) + WC('a', S(0))), x_), cons2, cons3, cons1092, cons1099, cons89, cons90) rule1902 = ReplacementRule(pattern1902, With1902) pattern1903 = Pattern( Integral( u_**WC('n', S(1)) * (x_ * WC('b', S(1)) + WC('a', S(0)))**WC('m', S(1)) * log(x_ * WC('b', S(1)) + WC('a', S(0))), x_), cons2, cons3, cons19, cons1092, cons1099, cons89, cons90, cons68) rule1903 = ReplacementRule(pattern1903, With1903) return [ rule1885, rule1886, rule1887, rule1888, rule1889, rule1890, rule1891, rule1892, rule1893, rule1894, rule1895, rule1896, rule1897, rule1898, rule1899, rule1900, rule1901, rule1902, rule1903, ]
star = Wildcard.star('star') star_a = Wildcard.star('star_a') star_b = Wildcard.star('star_b') plus = Wildcard.plus('plus') plus_a = Wildcard.plus('plus_a') θ = Theta def equijoin(a, c, b, d): return Equal(Column(a, c), Column(b, d)) cross_with_universe = ReplacementRule( Pattern(Cross(UniverseSet(), plus_a)), lambda plus_a: Cross(*plus_a) ) remove_empty_select = ReplacementRule( Pattern(Select(a, And())), lambda a: a ) convert_union_into_select = ReplacementRule( Pattern(Union(Select(a, b), Select(a, c))), lambda a, b, c: Select(a, Or(b, c)) ) """
from matchpy import Wildcard, Pattern, ReplacementRule, is_match, replace_all, ManyToOneReplacer from operation import Int, Mul, Add, Pow, Log from symbol import VariableSymbol, ConstantSymbol from constraint import FreeQ, NonzeroQ a, b, c, d, e, f, g, h, x = map(VariableSymbol, 'abcdefghx') n, m = map(VariableSymbol, 'nm') a_, b_, c_, d_, e_, f_, g_, h_ = map(Wildcard.dot, 'abcdefgh') n_, m_ = map(Wildcard.dot, 'nm') pattern1 = Pattern(Int(1/x, x)) rule1 = ReplacementRule(pattern1, lambda x: Log(x)) pattern2 = Pattern(Int(x**m, x), FreeQ(m, x) and NonzeroQ(m + 1)) rule2 = ReplacementRule(pattern2, lambda m, x: x**(m + 1)/(m + 1)) pattern3 = Pattern(Int(1/(a + b*x), x), FreeQ((a, b), x)) rule3 = ReplacementRule(pattern3, lambda a, b, x: Log(RemoveContent(a + b*x, x))/b) pattern4 = Pattern(Int((a + b*x)**m, x), FreeQ((a, b, m), x) and NonzeroQ(m + 1)) rule4 = ReplacementRule(pattern4, lambda a, b, m, x: (a + b*x)**(m + 1)/(b*(m + 1))) pattern5 = Pattern(Int((a + b*u)**m, x), FreeQ((a, b, m), x) and LinearQ(u, x) and NonzeroQ(u - x)) rule5 = ReplacementRule(pattern5, lambda a, b, m, u, x: 1/Coefficient(u, x, 1)*Subst(Pattern(Int((a + b*x)**m, x), x, u))) # 1.2 (a + b x)**m (c + d x)**n) pattern6 = Pattern(Int(1/((a + b*x)*(c + d*x)), x), FreeQ((a, b, c, d), x) and ZeroQ(b*c + a*d)) rule6 = ReplacementRule(pattern6, lambda a, b, c, d, x: Pattern(Int(1/(a*c + b*d*x**2), x)))
from operation import Int, Mul, Add, Pow, Log from symbol import VariableSymbol, ConstantSymbol from constraint import FreeQ, NonzeroQ a, b, c, d, e, f, g, h, x = map(VariableSymbol, 'abcdefghx') n, m = map(VariableSymbol, 'nm') a_, b_, c_, d_, e_, f_, g_, h_ = map(Wildcard.dot, 'abcdefgh') n_, m_ = map(Wildcard.dot, 'nm') x_ = Wildcard.symbol('x') u_ = Wildcard.symbol('u') one = ConstantSymbol(1) m_one = ConstantSymbol(-1) pattern1 = Pattern(Int(Mul(a_, Pow(x_, -1)), x), FreeQ((a, ), x)) rule1 = ReplacementRule(pattern1, lambda a, x: Mul(a, Log(x))) pattern2 = Pattern(Int(Pow(x_, m_), x), FreeQ((m, ), x), NonzeroQ(Add(m_, one), (m, ))) rule2 = ReplacementRule( pattern2, lambda m, x: Mul(Pow(x, Add(m, one)), Pow(Add(m, one), m_one))) rubi = ManyToOneReplacer(rule1) rubi.add(rule2) test = [[ Int(Pow(x, one), x), Mul(Pow(Add(one, one), m_one), Pow(x, Add(one, one))) ], [Int(Mul(a, Pow(x, -1)), x), Mul(Log(x), a)]]