Fun with SymbolicUtils #43
cscherrer
started this conversation in
Show and tell
Replies: 2 comments 2 replies
-
(4) is here julia> using SymbolicCodegen
julia> simplify(logdensity(d,x), polynorm=true) |> cse
9-element Vector{Pair{Symbol, SymbolicUtils.Term{Number}}}:
Symbol("##286") => log(σ)
Symbol("##287") => -1 * ##286
Symbol("##288") => σ ^ -2
Symbol("##289") => x * μ * ##288
Symbol("##290") => x ^ 2
Symbol("##291") => -0.5 * ##290 * ##288
Symbol("##292") => μ ^ 2
Symbol("##293") => -0.5 * ##292 * ##288
Symbol("##294") => ##287 + ##289 + ##291 + ##293
julia> simplify(logdensity(d,x), polynorm=true) |> codegen
quote
var"##303" = (log)(σ)
var"##304" = (*)(-1, var"##303")
var"##305" = (^)(σ, -2)
var"##306" = (*)(x, μ, var"##305")
var"##307" = (^)(x, 2)
var"##308" = (*)(-0.5, var"##307", var"##305")
var"##309" = (^)(μ, 2)
var"##310" = (*)(-0.5, var"##309", var"##305")
var"##311" = (+)(var"##304", var"##306", var"##308", var"##310")
end |
Beta Was this translation helpful? Give feedback.
0 replies
-
Very nice! This really showcases the benefit of a more lightweight and less constrained implementation of distributions. What does the |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Check it out:
In Soss, I'm using the
simplify
result (after a few other rules as well). It's something like<: Number
subexpression where all values are known at compile timeBeta Was this translation helpful? Give feedback.
All reactions