GithubHelp home page GithubHelp logo

kennethlaskoski / fractran Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pimlu/fractran

0.0 0.0 0.0 5.34 MB

World's fastest FRACTRAN interpeter

Home Page: https://pimlu.github.io/fractran/

License: MIT License

Shell 1.99% JavaScript 48.40% Python 1.01% Haskell 48.60%

fractran's Introduction

Cycle Detecting FRACTRAN Evaluator

Or, How I Evaluated my FRACTRAN Programs 10x Faster Using this One Weird Trick

Try it out here: pimlu.github.io/fractran

It's actually over 30x faster than the fastest interpreter I could find online for my standard benchmark (PRIMEGAME, first 100 primes). Better yet, some FRACTRAN programs/input combinations run billions of times faster or more (like the Hamming weight calculator).

It works by detecting repeating cycles of fractions that are being multiplied by and "fast forwarding" until some register depletes. It doesn't output intermediate states that it skips, but in my experience programs that indicate meaningful intermediate state always do so at "boundaries" where the logic progression changes, which can't get skipped. So PRIMEGAME still outputs the primes on its own.

Here's the implementation with some demo (hard coded) FRACTRAN programs called inside main to get you started. The code was primarily written a few days before a deadline so it's kind of sad-looking. I cleaned it up a little bit - the better methods of evaluating used to be called smart, smarter, and smartest...

Building and running the code

You need an installation of GHC. Then run ./build.sh to compile, or run ./build.sh clean to remove the build products. Then to run the demo, run ./fractran.

To build for the browser, there are more steps. You need to install docker and run ./build.sh --browser to first populate web/gen. Webpack depends on the JS output from Asterius which gets dumped to that directory. Then cd into web and run yarn which will install the NPM package dependencies. You then should be able to run yarn run serve.

There are some optional mods you can make to the Asterius build to improve the result: a) You can put a proper polyfill of setImmediate in gen/rts.setImmediate.js to greatly increase the running speed and b) Remove import('fs') from gen/rts.node.mjs which gets rid of an empty bundle in the webpack output.

Whitepaper with proofs, benchmarks

Here. It's not human readable though.

License

MIT. Would be nice to get attribution if something interesting were to (somehow) happen though.

fractran's People

Contributors

pimlu 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.