A simple computer algebra system in Julia.
jcrist / juniper.jl Goto Github PK
View Code? Open in Web Editor NEWA simple computer algebra system, in Julia
License: Other
A simple computer algebra system, in Julia
License: Other
Hi, I have noticed that you define the type of Symbolic
by an Int8
parameter (not UInt8
?).
What about a parametric type instead? That is, something like Symbolic{:Add}(args...)
.
This way you can use multiple dispatch easily on the node types. Mathematica uses "Plus", "Times", "Power" in its M-expressions, and it doesn't seem to be a noticeable performance loss over an Int8
.
Juniper uses an Int8
to represent the type of the object, getting around the issue of dynamically dispatching on types. This means that some methods look like:
if expr.head == ADD
do stuff
elseif expr.head == MUL
do stuff
...
Ideally, this could be abstacted out with a macro, simplifying the logic. This could look something like the following may work?
@dispatch expr extra_args begin
@case ADD func
@case MUL func
...
end
This would then turn into:
if expr.head == ADD
func(Val{ADD}, expr, extra_args)
elseif expr.head == MUL
func(Val{MUL}, expr, extra_args)
...
Specific methods could then be written as:
function func(::Type{Val{MUL}}, expr::Symbolic, ...)
Because Val{...}
is known at compile time, the calls to func
will be fixed, and may even be inlined. This should prevent type instability, while also making such functions easier to read.
Note that this is extremely similar to the macro provided by Switch.jl, except it doesn't require break statements, and can be written in one line.
What I'd really like is if there was a way to do an actual switch
statement, like in C, so that the long if...elseif...
could be replaced with a computed goto. There doesn't seem to be such an option yet.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.