SymbolicUtils.jl icon indicating copy to clipboard operation
SymbolicUtils.jl copied to clipboard

Converting types to predicates for rule matching constraints

Open jpfairbanks opened this issue 1 year ago • 1 comments

In trying to solve #629 with rewriting I came up with some rules:

abstract type Form <: Number end
struct Form0 <: Form end
struct Form1 <: Form end
struct Form2 <: Form end

d(::Form)::Form
d₀(::Form0)::Form1
# these don't work because Form0/Form1 are types and not predicates that check for types
@rule d(~x::Form0) => d₀(~x)
@rule d(~x::Form1) => d₁(~x)

# these functions fix it because we can match on predicates
form0p(x) = symtype(x) == Form0
form1p(x) = symtype(x) == Form1

@rule d(~x::form0p) => d₀(~x)
@rule d(~x::form1p) => d₁(~x)

Is there a way that we could hook into @rule so that if you tried to match on a type it automatically lifts that type to a predicate?

jpfairbanks avatar Aug 05 '24 00:08 jpfairbanks