Git Product home page Git Product logo

juniper.jl's Introduction

Juniper

A simple computer algebra system in Julia.

juniper.jl's People

Contributors

jcrist avatar

Stargazers

yzrun avatar Konstantinos avatar Amit Kumar avatar Jason K. Moore avatar Cristóvão Duarte Sousa avatar

Watchers

James Cloos avatar  avatar  avatar

juniper.jl's Issues

Using parametric types for Symbolic?

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.

Use a macro to dispatch on Head

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.