RUBI integration rules now reasonably fast to load

29 views
Skip to first unread message

Francesco Bonazzi

unread,
Jul 22, 2026, 5:44:04 PM (2 days ago) Jul 22
to sympy
Hi everyone,

I've worked on improving the RUBI integration rules and MatchPy, the external library that performs a very efficient associative-commutative pattern matching.

Here is the result:

Try it yourselves:

In [1]: from rubi_rules.base_objects import rubi_integrate

In [2]: from sympy import *

In [3]: var("x y z a b c d e f g h i j p q")
Out[3]: (x, y, z, a, b, c, d, e, f, g, h, i, j, p, q)

In [4]: rubi_integrate(sin(x)*cos(2*x), x, return_matched_rules=True)
Out[4]:
(cos(x)/2 - cos(3*x)/6,
 [(cos(x)/2 - cos(3*x)/6, [('4.7.4 (c trig)^m (d trig)^n', 3)])])

So far everything is a fork of MatchPy, but ideally the folders
  • matchpy
  • sympy_matching
  • sympy_wolfram
  • rubi_rules
could be split into four different packages.

The MatchPy library has been modified a lot, so it's currently quite different from its source.

sympy_matching is the connector between sympy and matchpy

sympy_wolfram has utilities to parse Wolfram Mathematica source code.

rubi_rules contains the integration rules and the rubi test suite.

We should also discuss if the SymPy community is willing to take over these four modules and support their development.

Aaron Meurer

unread,
Jul 22, 2026, 11:36:38 PM (2 days ago) Jul 22
to sy...@googlegroups.com
I had to pull the latest sympy master and point it to that (otherwise
I get a bunch of warnings and then an unevaluated integral). The
command took 22 seconds for me on my M3 Max. Subsequent integrals are
instant though.

I think we should take over matchpy. Do you think it should remain a
separate package or be merged in as a sympy submodule?

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/sympy/8b280073-8e2b-4881-9d82-591dffb8ca8cn%40googlegroups.com.

Francesco Bonazzi

unread,
Jul 23, 2026, 1:44:55 AM (yesterday) Jul 23
to sympy
On Thursday, July 23, 2026 at 5:36:38 a.m. UTC+2 Aaron Meurer wrote:
I had to pull the latest sympy master and point it to that (otherwise
I get a bunch of warnings and then an unevaluated integral). The
command took 22 seconds for me on my M3 Max. Subsequent integrals are
instant though.

 The bottleneck is the construction of SymPy objects in the rules.  I was able to get MatchPy fast at loading (earlier versions of Rubi took about 1 hour to load the rules).

I think we should take over matchpy. Do you think it should remain a
separate package or be merged in as a sympy submodule?

 If we merge it as a SymPy submodule we could start using it freely in SymPy. On the other hand, projects depending on just MatchPy would need to install the whole of sympy just to use matchpy.

By the way, shall we change its name? What about calling it MatchMath or something different than MatchPy? 

Aaron Meurer

unread,
Jul 23, 2026, 12:04:32 PM (yesterday) Jul 23
to sy...@googlegroups.com
On Wed, Jul 22, 2026 at 11:45 PM Francesco Bonazzi
<franz....@gmail.com> wrote:
>
>
>
> On Thursday, July 23, 2026 at 5:36:38 a.m. UTC+2 Aaron Meurer wrote:
>
> I had to pull the latest sympy master and point it to that (otherwise
> I get a bunch of warnings and then an unevaluated integral). The
> command took 22 seconds for me on my M3 Max. Subsequent integrals are
> instant though.
>
>
> The bottleneck is the construction of SymPy objects in the rules. I was able to get MatchPy fast at loading (earlier versions of Rubi took about 1 hour to load the rules).

Do the rules have to be sympy objects? Wouldn't it be faster to
convert the input expression to the matchpy format instead of
converting the rules to sympy?

>
> I think we should take over matchpy. Do you think it should remain a
> separate package or be merged in as a sympy submodule?
>
>
> If we merge it as a SymPy submodule we could start using it freely in SymPy. On the other hand, projects depending on just MatchPy would need to install the whole of sympy just to use matchpy.
>
> By the way, shall we change its name? What about calling it MatchMath or something different than MatchPy?

Let's see if we can get access to the PyPI. If we can't, we will need
to change the name.

Aaron Meurer

>
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/sympy/cb25671e-ed07-4dfa-adca-43ad718f6b36n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages