Skip to content

Conversation

@Bumblebee00
Copy link
Collaborator

New mechanism for rules, that aims to be much faster. Currently still a expermient

@Bumblebee00 Bumblebee00 marked this pull request as draft November 14, 2025 23:32
@AayushSabharwal
Copy link
Member

Yep, Mattia and I are discussing this on Slack. It's potentially promising, at the very least until we get better rules in SU (which will take a while)

@Bumblebee00
Copy link
Collaborator Author

ok so i improved the new rule mechanism to a almost working state:

  • predicates, commutative checks and defslot are working
  • negative power matching and segments not yet, but they will be easy to add

Then I converted about 600 rules to the new mechanism and tested the loading time.
New:

julia> @benchmark reload_rules()
BenchmarkTools.Trial: 22 samples with 1 evaluation per sample.
 Range (min … max):  212.345 ms … 352.751 ms  ┊ GC (min … max): 0.00% … 39.61%
 Time  (median):     221.739 ms               ┊ GC (median):    3.45%
 Time  (mean ± σ):   227.933 ms ±  28.247 ms  ┊ GC (mean ± σ):  5.77% ±  7.87%

     █▄                                                          
  ▄▄▆███▁▁▄▄▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▄ ▁
  212 ms           Histogram: frequency by time          353 ms <

 Memory estimate: 61.63 MiB, allocs estimate: 1516910.

Old (loading only the same ~600 rules as above):

julia> @benchmark reload_rules()
BenchmarkTools.Trial: 1 sample with 1 evaluation per sample.
 Single result which took 53.839 s (6.36% GC) to evaluate,
 with a memory estimate of 7.09 GiB, over 138098822 allocations.

@Bumblebee00
Copy link
Collaborator Author

it faster 😁😁😁, now remains to test only the time it takes to apply them

@Bumblebee00
Copy link
Collaborator Author

Ok so the other problem that this pr amis to solve is the TTFX because the first integrate call is sooo slow. I did NOT yet come up with a way to measure this (btw @ChrisRackauckas @AayushSabharwal if you have suggestions on how to properly benchmark ttfx tell me), but in the meanwhile I benchmarked the normal execution time (not the first).

I repeat, this pr doesnt aim to improve the "average" execution time, only the first. but I am pleased to see that the average execution time it's on the same "order of magnitude" of the old rule system, even a bit faster. Trying the resolution of the integral eex = 1/(1+5x^2)^(3//2)

Old:

julia> @benchmark integrate($eex;verbose=false)
BenchmarkTools.Trial: 3436 samples with 1 evaluation per sample.
 Range (min … max):  1.304 ms …  27.218 ms  ┊ GC (min … max): 0.00% … 93.19%
 Time  (median):     1.362 ms               ┊ GC (median):    0.00%
 Time  (mean ± σ):   1.453 ms ± 815.304 μs  ┊ GC (mean ± σ):  4.12% ±  7.20%

  █▇▅▂▁                                                       ▁
  ██████▇▆█▆▆▄▅▃▅▅▁▅▅▄▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▄▅ █
  1.3 ms       Histogram: log(frequency) by time      4.89 ms <

 Memory estimate: 933.57 KiB, allocs estimate: 9121.

New:

julia> @benchmark integrate($eex)
BenchmarkTools.Trial: 5690 samples with 1 evaluation per sample.
 Range (min … max):  842.875 μs …  14.742 ms  ┊ GC (min … max): 0.00% … 92.22%
 Time  (median):     851.834 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   877.402 μs ± 357.303 μs  ┊ GC (mean ± σ):  1.34% ±  3.12%

  ▇█▆▅▃▂▁                                                    ▁  ▁
  ████████▇██▆▆▃▁▄▄▃▁▃▁▁▁▁▁▁▃▃▁▁▁▁▁▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▆▇███ █
  843 μs        Histogram: log(frequency) by time        1.2 ms <

 Memory estimate: 196.41 KiB, allocs estimate: 5386.

@Bumblebee00
Copy link
Collaborator Author

another important thing to mention is that updating the package to work with SUv4 is a bit more work than expected

@Bumblebee00
Copy link
Collaborator Author

The one thing i came up with to benchmark the ttfx is creating a simple script prova.jl:

using Symbolics, SymbolicIntegration
@variables x
eex = 1/(1+5x^2)^(3//2)
result = integrate(eex, RuleBasedMethod(verbose=true))
println(result)

and then running time julia --project=. prova.jl.

So we have:

. new old
compilation time 8 69
total time 20 94
total - compilation 16 25

where the last row is time it takes to compute the first integrate call, the part that should be improved by specifying all the types so that type inference is fast. Remember that this is still using a subset of the total rules (600/3400). I am pleased to see that is faster 😁😁😁









full output:
Old:

~/.julia/dev/SymbolicIntegration.jl_official copy (main ✗) time julia --project=. prova.jl      
Precompiling SymbolicIntegration...
Info Given SymbolicIntegration was explicitly requested, output will be shown live 
Loaded 608 rules from 15 files.
  1 dependency successfully precompiled in 69 seconds. 167 already precompiled.
  1 dependency had output during precompilation:
┌ SymbolicIntegration
│  [Output was shown above]
└  
┌-------Applied rule 1_1_2_1_2 on ∫(1 / ((1 + 5(x^2))^(3//2)), x)
| ∫(1 / (a + b * x ^ 2) ^ (3 // 2), x) => if 
|       !(contains_var(a, b, x))
| x / (a * √(a + b * x ^ 2))
└-------with result: x / sqrt(1 + 5(x^2))
x / sqrt(1 + 5(x^2))
julia --project=. prova.jl  98.52s user 3.52s system 108% cpu 1:34.29 total

New:

~/.julia/dev/SymbolicIntegration.jl_official (rule2 ✗) time julia --project=. prova.jl
Precompiling SymbolicIntegration...
Info Given SymbolicIntegration was explicitly requested, output will be shown live 
Loaded 608 rules from 15 files.
  1 dependency successfully precompiled in 8 seconds. 118 already precompiled.
  1 dependency had output during precompilation:
┌ SymbolicIntegration
│  [Output was shown above]
└  
┌-------Applied rule 1_1_2_1_2 on ∫(1 / ((1 + 5(x^2))^(3//2)), x)
| ∫(1 / (a + b * x ^ 2) ^ (3 // 2), x) => if 
|       !(contains_var(a, b, x))
| x / (a * √(a + b * x ^ 2))
└-------with result: x / sqrt(1 + 5(x^2))
x / sqrt(1 + 5(x^2))
julia --project=. prova.jl  15.36s user 1.35s system 83% cpu 19.998 total

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants