Skip to content

[WIP] Negative exponent matching #750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Bumblebee00
Copy link
Contributor

@Bumblebee00 Bumblebee00 commented Jun 14, 2025

This pr builds on top of the defslot feature i added in another pr. The aim is for rule @rule (~x)^(~m) => ..something.. to match 1 / (x^2) with m=-2.

I did that by modifying the term_matcher and defslot_term_matcher functions, they are functions called when the rule gets applied, and they have to check wheter a certain term (the pattern to match in the ruel, like in this example (~x)^(~m)) matches with certain data (1/(x^2) in this example). I did basically the same modification to the two of them. They work by using a loop function called recursively, that uses some matcher functions (1) that assign the values to their label. The modification di did in term_matcher is:

  • call the loop function recursively like normal.
  • If still you dont have a match, and if the operation of the term is a power, and if data is in the form 1 over a power, like 1/a^b, then:
    • if the exponent of the power b is not a number (but a symbol or expression), call the loop function with a^-b
    • if b is a number, this cannot be done bc x^-3 gets automatically transformed into 1 / (x^3). So I cant call loop with a^-b, i have to call it with a^b, so I had to create a new matcher function (1) that assigns the opposite value of data to the label.

in defslot_term_matcher i did a similar thing, and if after all this still doesnt find a match, also tries to match with the default value of defslot

I find it a bit messy

Copy link
Contributor

Benchmark Results

master dc94232... master / dc94232...
overhead/acrule/a+2 0.987 ± 0.33 μs 1.03 ± 0.041 μs 0.958 ± 0.32
overhead/acrule/a+2+b 1.18 ± 0.32 μs 1.02 ± 0.047 μs 1.16 ± 0.32
overhead/acrule/a+b 0.268 ± 0.031 μs 0.341 ± 0.0082 μs 0.786 ± 0.093
overhead/acrule/noop:Int 1.56 ± 0.01 ns 1.56 ± 0.01 ns 1 ± 0.009
overhead/acrule/noop:Sym 27.6 ± 6.6 ns 22.5 ± 5.8 ns 1.23 ± 0.43
overhead/rule/noop:Int 0.035 ± 0.024 μs 0.0346 ± 0.0018 μs 1.01 ± 0.7
overhead/rule/noop:Sym 0.0336 ± 0.024 μs 0.033 ± 0.0016 μs 1.02 ± 0.74
overhead/rule/noop:Term 0.0337 ± 0.024 μs 0.0332 ± 0.0014 μs 1.01 ± 0.74
overhead/ruleset/noop:Int 0.111 ± 0.0026 μs 0.122 ± 0.0039 μs 0.91 ± 0.036
overhead/ruleset/noop:Sym 0.119 ± 0.0029 μs 0.121 ± 0.0032 μs 0.986 ± 0.035
overhead/ruleset/noop:Term 4.49 ± 0.11 μs 4.59 ± 0.1 μs 0.979 ± 0.032
overhead/simplify/noop:Int 0.235 ± 0.018 μs 0.216 ± 0.0046 μs 1.09 ± 0.085
overhead/simplify/noop:Sym 0.232 ± 0.018 μs 0.208 ± 0.0035 μs 1.12 ± 0.087
overhead/simplify/noop:Term 0.0471 ± 0.002 ms 0.0533 ± 0.0018 ms 0.885 ± 0.049
overhead/simplify/randterm (+, *):serial 0.119 ± 0.0034 s 0.13 ± 0.0024 s 0.915 ± 0.031
overhead/simplify/randterm (+, *):thread 0.0712 ± 0.0066 s 0.0786 ± 0.0068 s 0.906 ± 0.11
overhead/simplify/randterm (/, *):serial 0.232 ± 0.024 ms 0.261 ± 0.021 ms 0.891 ± 0.12
overhead/simplify/randterm (/, *):thread 0.267 ± 0.022 ms 0.299 ± 0.021 ms 0.894 ± 0.095
overhead/substitute/a 0.107 ± 0.012 ms 0.101 ± 0.0062 ms 1.06 ± 0.14
overhead/substitute/a,b 0.0918 ± 0.01 ms 0.0857 ± 0.0085 ms 1.07 ± 0.16
overhead/substitute/a,b,c 21.3 ± 2.6 μs 19.6 ± 1.4 μs 1.08 ± 0.15
polyform/easy_iszero 0.0412 ± 0.0016 ms 0.0421 ± 0.0011 ms 0.979 ± 0.046
polyform/isone 4.02 ± 0.92 ns 3.1 ± 0.01 ns 1.3 ± 0.3
polyform/iszero 1.43 ± 0.03 ms 1.44 ± 0.028 ms 0.992 ± 0.029
polyform/simplify_fractions 1.94 ± 0.035 ms 1.96 ± 0.034 ms 0.988 ± 0.025
time_to_load 1.15 ± 0.0044 s 1.15 ± 0.0086 s 1 ± 0.0084

Benchmark Plots

A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR.
Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).

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.

1 participant