Skip to content

RFC: Domain symbolics #175

@Roger-luo

Description

@Roger-luo

A short recap of slack discussion: currently, we have Expression <: Number, however, if a generic function is defined on Real, this won't "just work".

The simplest fix as proposed by @ChrisRackauckas is to move Expression <: Real. However, this will fail if there are symbolic complex numbers (which is also crucial in Yao's case). In fact, I believe we will need some kind of domain inference/ types to represent domains instead of letting the IR expression to handle it.

My proposal is to separate the IR with domain types, which mean Expression will not be subtype of Real nor Number, we will have a wrap type to help the dispatch, which can just be

struct SymReal <: Real
    data
end

where data can be Expression or Variable or other things that is defined as real number or inferred as real number and same for complex number and other kind of numbers or even matrices, linear maps etc. I'm trying out this idea in my toy symbolic engine, I'll make that public soon.

This is actually a similar idea with Tracker, the implementation of TrackedReal looks like following:

struct TrackedReal{T} <: Real
   tape::Tracked
   data::T
end

Update: I implemented some of my ideas here Sym.jl

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions