Skip to content
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

Using Callable Structs in Symbolic Expressions #672

Open
jpfairbanks opened this issue Nov 8, 2024 · 3 comments
Open

Using Callable Structs in Symbolic Expressions #672

jpfairbanks opened this issue Nov 8, 2024 · 3 comments

Comments

@jpfairbanks
Copy link
Contributor

I think I am correctly using a callable struct as an operator name in the following code, but then the rules don't work

using SymbolicUtils
import SymbolicUtils.Symbolic
using SymbolicUtils.Rewriters

abstract type Form <: Number end
struct ZeroForm <: Form end

struct d
  dim::Int
end

(op::d)(x::Symbolic) = SymbolicUtils.Term{Form}(op, Any[x])

Base.nameof(op::d) = Symbol("d$(''+op.dim)")

@syms x::Form
@syms y::Form

f = d(0)(x)

d₀rule = @rule d(1)(d(0)(~x)) => ZeroForm()
drule = @rule d(~i+1)(d(~i)(~x)) => ZeroForm()

using Test
@test_broken d₀rule(d(1)(d(0)(x))) == ZeroForm()
@test d₀rule(d(2)(d(1)(x))) == nothing # accidentally passing
@test_broken drule(d(1)(d(0)(x))) == ZeroForm()
@test_broken drule(d(2)(d(1)(x))) == ZeroForm()
@test drule(d(3)(d(1)(x))) == nothing # accidentally passing

Do I need to specify some different syntax to make the rules understand the callable structs?

@ChrisRackauckas
Copy link
Member

Hmm, I don't know who would've last looked into this. @shashi or @AayushSabharwal have you tried stuff like this?

@AayushSabharwal
Copy link
Contributor

I haven't, but will see if I can find anything

@AayushSabharwal
Copy link
Contributor

Looking at how the macro works, I don't think it supports rules for callable structs. Will see how difficult it is to add support for this.

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

No branches or pull requests

3 participants