JuliaSymbolics / SymbolicUtils.jl

Symbolic expressions, rewriting and simplification
https://docs.sciml.ai/SymbolicUtils/stable/
Other
539 stars 108 forks source link

Migrate to Expronicon.jl v0.8 from Unityper.jl #611

Open YingboMa opened 3 months ago

YingboMa commented 3 months ago

Unityper.jl doesn't support recursive type and it also doesn't support powerful pattern matching with MLStyle.jl.

Note that we have to use Expronicon.jl v0.8 and not any other release because later version cause massive invalidations.

CC: @Roger-luo

Roger-luo commented 3 months ago

Well I do realize it's a bad idea overloading getproperty to provide namespace syntax. So I'm still working on a refactor of Expronicon sum type. I have a working version inside Liang.jl but still WIP splitting that out and stabilizing.

bowenszhu commented 3 months ago

I'm running into an issue with using parametric types like BasicSymbolic{T} with Expronicon v0.10.8. It seems that Expronicon doesn't yet support them, as demonstrated by the following error:

module SymbolicADT
using Expronicon.ADT: @adt

@adt BasicSymbolic{T} begin end

end # module

Error:

ERROR: LoadError: ArgumentError: generic ADT is not supported yet
...

Is there a workaround for this, or is support for parametric types planned for a future release?

Thanks!

Roger-luo commented 3 months ago

Yes it doesn't support such for the same reason as Unityper - if we obey C tagged union convention this will require Julia compiler to support generated struct (as pointed out in a previous discussion under JuliaLang/julia)

However, Mason have demonstrated that without this convention we can achieve better performance by just using julia's Union type in SumTypes.jl. I'm planning to adopt this solution and rewrite MLStyle on top of this. The new package is named Moshi.jl stands for the name pattern in Chinese.

But as you may know I just graduated recently so I will be in vacation and moving for the summer. So I'm not sure how much time I have to push this forward this year.

bowenszhu commented 3 months ago

@YingboMa Do you have any recommendations on how to handle parametric types with Expronicon for the time being?

YingboMa commented 3 months ago

Since T in Symbolic{T} is only a tag for for symtype. We could just do

struct BasicSymbolic{T}
    x::BasicSymbolicImpl
end

and use Expronicon to implement BasicSymbolicImpl.

bowenszhu commented 3 months ago

@YingboMa Thanks for the suggestion! That's a smart workaround for the parametric type limitation.

Roger-luo commented 2 months ago

Ok well, good but maybe also bad news: I got bored with vacationing and decided to code up this. I just released a version of Moshi.jl with new pattern matching and ADT support (with generics) and should have no invalidation anymore. The interface will be a bit breaking in order to fix the invalidation issue.

And bonus is now many methods are generated by derive macro optional upon your choice instead of automatically (e.g equivalence and show). It's still experimental and in early stages but please feel free to try it out!