Skip to content

Matching function call as pattern variable during saturation #279

@karlwessel

Description

@karlwessel

With ale/3.0.

I can match a function call with a slot using simple rule matching:

julia> using Metatheory

julia> r = @rule (~fn)(~a::Number) => eval(~fn)(~a)
(~fn)(~(a::Number)) => (eval(fn))(a)

julia> r(:(sin(2)))
0.9092974268256817

The same is not matched during E-Graph saturation:

julia> t = @theory fn a begin
       (~fn)(a::Number) => fn(a)
       end
1-element Vector{RewriteRule}:
 (~fn)(~(a::Number)) => fn(a)

julia> g = EGraph(:(sin(2)))
EGraph{Expr, Nothing} with 2 e-classes:
  1 => [2]
  2 => [sin(%1)]

julia> saturate!(g, t)
SaturationReport
=================
	Stop Reason: saturated
	Iterations: 2
	EGraph Size: 2 eclasses, 2 nodes
────────────────────────────────────────────────────────────────────
                           Time                    Allocations      
                  ───────────────────────   ────────────────────────
Tot / % measured:      135μs /   7.8%           6.12KiB /  17.9%    

Section   ncalls     time    %tot     avg     alloc    %tot      avg
────────────────────────────────────────────────────────────────────
Search         2   5.98μs   57.1%  2.99μs      800B   71.4%     400B
  1            2   3.95μs   37.7%  1.97μs     0.00B    0.0%    0.00B
Rebuild        2   3.80μs   36.2%  1.90μs      320B   28.6%     160B
Apply          2    703ns    6.7%   352ns     0.00B    0.0%    0.00B
────────────────────────────────────────────────────────────────────


julia> g
EGraph{Expr, Nothing} with 2 e-classes:
  1 => [2]
  2 => [sin(%1)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions