Giter VIP home page Giter VIP logo

sorcetta's Introduction

Sorcetta

Source-to-source translation.

Why? because a lot of research code exists only in R, Python, Matlab. One can interface with other languages by using e.g. PyCall, but in this case, it is preferable to have the Python code translated to Julia (for performance reasons if nothing else). Since human translation is slow and burdensome, automated translation may be a good alternative.

Goal: we do not expect Sorcetta to obtain 100% coverage without human assistance, but merely to speed up the process of translating code from other languages into Julia.

Dogma: as long as the outputs agree for every valid input, the codes are good translations of each other. This means that you can use any approach you like (human translation, statistical machine translation, genetic algorithms, inductive logic programming, etc), as long as the tests pass. Note: we don't worry about mutating code just yet.

Current project: R. (Future: Matlab, Python)

Project A: automatic test generation

Q: when are two pieces of code good translations of each other? i.e. when do two pieces of code compute the same function?
A: when they agree on every valid input.
Q: what is valid input?
A: for the purposes of Project A, an input is valid if it satisfies the precondition (i.e. the last PRE statement).

For Project B, we will be testing sequences of lines, and will compare variable values after each line. The precondition is only enforced at the top of the sequence. At a given line, an input is valid if it can be achieved, given the code above it and the precondition at the top.

.Rjl file

== Code ==
R: a+b
J: a+b

This tells to test whether a+b in R corresponds to a+b in Julia. If no precondition (PRE statement) is specified, then a and b will take their full range of values. The full range of values is specified under the "Inputs" header.

== Inputs ==
a::Real -1.0, 0.0, 1.0, 5.0, 1e10, Inf
b::Real -1.0, 0.0, 1.0, 5.0, 1e10, Inf

A blank line is required between tests.

PRE: typeof(a)<:Real && a>=0
R: sqrt(a)
J: sqrt(a)

The PRE statement restricts the range of values, and propagates downwards. To reset to default state, one can use PRE: true. Likewise PRE: false will cause tests to be skipped until the next PRE statement. The above block tells to test whether sqrt(a) in R corresponds to sqrt(a) in Julia, but only for non-negative values of a.

== Libraries ==
R:
J: Distributions

This specifies which libraries need to be loaded before tests are run. For R, the Base package is enough. For Julia, it will call using Distributions.

Issues

  • Some R identifiers are not valid Julia identifiers, e.g. anything containing ..

How to run

...

Project B: web application to collect parallel corpus from humans

Ruby on Rails?

Plan

  • interface showing R code, side-by-side with Julia code, aligned by line

  • use Project A to judge correctness of translations.

== R-to-Julia glossaries ==

https://github.com/johnmyleswhite/JuliaVsR/blob/master/vocab.csv

http://gustavolacerda.livejournal.com/1191381.html

== Python-to-Julia glossaries ==

sorcetta's People

Contributors

gusl avatar

Watchers

 avatar  avatar

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.