Git Product home page Git Product logo

slang's Introduction

slang

Slang is a javascript library used to get the natural representation of a program from theoretical L (or S) language, from Martin Davis' Computability, Complexity and Languages.

Installation

Just run npm install to install every dependency. We depend mostly on gulp, babel, and mocha.

Run

To compile and use it, just run npm start from the terminal.

Test

To run the tests, just run npm test from the terminal.

Example

Try it online on https://ramadis.github.io/slang/. For further understanding, keep reading the theory.

Instructions

To encode an instruction we use a (bijective) pairing function (Mapping from N^2 --> N) with the form <x,y> = 2^x(2y+1)-1. We divide the syntax in 3 disjoint groups and generate the code for an instruction using <a,<b,c>>.

Labels (encoded as a)

Starting in 0, the labels are [A1, B1, C1, D1, E1, A2, ...]. They are optional in a given line.

Operations (encoded as b)

Starting in 0, the possible operations inside the S languague are

  • V Does nothing
  • V++ Increments the variable V in 1
  • V-- Decrements the variable V in 1
  • V?#L If V is not zero, go to label L

Variables (encoded as c)

Starting in 0, tha variables are Y, X1, Z1, X2, Z2, X3, Z3, .... Being Y the outuput variable. the Xs the input variables and the Zs the auxiliary variables.

Program encoding

We encode programs using Gödel numbering. So a program is finally encoded as [#I1, #I2, #I3, ...] - 1 being #Ij the code for the jth instruction, and [] the syntax using for the given Gödel number.

Documentation

Program Class: Represents the program by holding an array of Instructions

static fromCode: returns a Program from a given program code.
static fromString: returns a Program from a valid S language program string.

getString: returns the Program's string representation.
getCode(Program.codeModes): returns the code for the given Program.

equals: returns true or false, depending on the equality between Programs.

static codeModes = {
  GODEL: represent a Gödel formed program string => [..] - 1,
  NUMBER: represent the program code as a Number => 31,
  PRIMES: represent a prime formed program string => 2^.. - 1
}

Instruction Class: Represents an instruction, with its encoding representation.

static fromString: returns an Instruction from a valid S language instruction string.
static fromCode: returns an Instruction from a valid instruction code.

getCode: returns the code for an Instruction
getString: returns a valid S language instruction string from a given Instruction.

equals: returns true or false, depending on the equality between Instructions.
toString: returns a String representation from the instruction using the Pairing Function syntax.

Notes

Every encoding step can be proved, showing that exists a bijectivity between natural numbers and the S language programs. Further proving, that there are functions which can not be computed.

slang's People

Contributors

ramadis avatar

Watchers

James Cloos avatar Rajesh  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.