Comments (4)
It might also be a good idea to use Mjolnir to extract symbolic expressions from Julia code, over the current operator overloading approach. This would be better able to support type constraints, intrinsics (ifelse
), higher-order functions (map
/reduce
/sum
etc.) and even simple control flow (the branches could be lowered to a functional or ifelse
representation if that's easier for SymbolicUtils to work with). I plan to throw up a prototype of that idea soon.
from symbolicutils.jl.
the branches could be lowered to a functional or ifelse representation
By the way, the XLA work effectively has a proof of concept for this:
julia> using XLA
julia> relu(x) = x > 0 ? x : 0
relu (generic function with 1 method)
julia> ir = XLA.@code_xla relu(5)
1: (%1 :: Int64)
%2 = (XLA.Gt())(%1, 0)
br 2 unless %2
br 3 (%1)
2:
br 3 (0)
3: (%3 :: Int64)
return %3
julia> XLA.controlflow(ir)
1: (%1 :: Int64)
%2 = (XLA.Gt())(%1, 0)
%4 = (XLA.Not())(%2)
%5 =
1: (%1)
%2 = (XLA.XTuple())(0)
%6 =
1: (%1)
%7 = (XLA.XTuple())()
%8 = (XLA.XTuple())(%1)
%9 = (XLA.Conditional())(%4, %7, %5, %8, %6)
%10 = (XLA.GetTupleElement(0))(%9)
The XLA representation is a bit fiddly, but the controlflow
transformed IR is equivalent to
julia> cond(c, t, f) = c ? t() : f() # XLA's `cond`, roughly
julia> relu(x) = cond(x > 0, () -> x, () -> 0)
Which is equivalent to a piecewise function definition. I'm not sure if you support things like lambdas, piecewise functions, list comprehensions etc., or if you plan to, but at any rate there's no issue using pulling those things out of Julia code.
from symbolicutils.jl.
Awesome! Yes this could be a fix for #16 cc @MasonProtter
from symbolicutils.jl.
the branches could be lowered to a functional or ifelse representation if that's easier for SymbolicUtils to work with
Just added cond
in #75
from symbolicutils.jl.
Related Issues (20)
- Regression: infinite loop during simplification on v1 HOT 14
- A simple question on deps change HOT 1
- `nameof(f)` not defined for all functors
- Confusing Documentation: Relation to TermInterface.jl
- `@arithmetic_rule` HOT 1
- LiteralReal printing issue
- Stable release HOT 2
- x86 (32-bit) Support HOT 1
- Semantics of `==` not good for generic programming HOT 7
- Add Text Name Symbol
- Conversion from `LiteralReal` to `Real` HOT 1
- Stack overflow in custom interface
- Use genetic algorithm to avoid state explosion HOT 1
- Inf becomes -Inf in rational simplifier sometimes
- Generated functions no longer re-tracable with Symbolics HOT 4
- Issue with creating rule for even and odd function of cos and sin HOT 2
- Metadata is lost on construction of Mul HOT 1
- SciML documentation has broken links
- typos
- method ambiguity for exponentiation of `Complex{Num}` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from symbolicutils.jl.