Skip to content

svanderbleek/rwr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 

Repository files navigation

rwr

world's cutest javascript term rewriting system

Roadmap

Motivation

Rewrite systems have long been used as decision procedures for validity in equational theories, that is, for truth of an equation in all models of the theory.

  • Equational Logic and Rewriting

Modern

Machine

Unification

TRS

Examples

Simple Example
      (VAR x y)
      (RULES

        plus(s(s(x)),y) -> s(plus(x,s(y)))
        plus(x,s(s(y))) -> s(plus(s(x),y))
        plus(s(0),y) -> s(y)
        plus(0,y) -> y

        ack(0,y) -> s(y)
        ack(s(x),0) -> ack(x,s(0))
        ack(s(x),s(y)) -> ack(x,plus(y,ack(s(x),y)))
      )
Context Sensitive Example
      (VAR X Y Z)
      (STRATEGY CONTEXTSENSITIVE
        (and 1)
        (true)
        (false)
        (if 1)
        (add 1)
        (0)
        (s)
        (first 1 2)
        (nil)
        (cons)
        (from)
      )
      (RULES
      and(true,X) -> X
      and(false,Y) -> false
      if(true,X,Y) -> X
      if(false,X,Y) -> Y
      add(0,X) -> X
      add(s(X),Y) -> s(add(X,Y))
      first(0,X) -> nil
      first(s(X),cons(Y,Z)) -> cons(Y,first(X,Z))
      from(X) -> cons(X,from(s(X)))
      )
Equational Example
      (VAR x y u v w)

      (RULES
        minus(plus(x, y), y) -> x
        div(0, plus(y, 1)) -> 0
        div(plus(x, 1),plus(y, 1)) -> plus(div(minus(x, y), plus(y, 1)), 1)
      )
      (THEORY (EQUATIONS
        plus(0, 0) == 0
        plus(1, 0) == 1
        plus(0, 1) == 1
        plus(u, plus(v, w)) == plus(plus(u, v), w)
      ))
AC Example
      (VAR x y)
      (THEORY (AC plus))
      (RULES
        plus(x, 0) -> x
        plus(x, s(y)) -> s(plus(x, y))
      )

Termination

Logic

editor

rwr language

ee will implement rwr a javascript rewriting interpreter. The API is minimal.

match(expression, rule) 
rewrite(expression, rule)
evaluate(expression, environment)

It is inspired by mathematica and TRS presented in literature such as Term Rewriting Systems and Advanced Topics in Term Rewriting.

rwr implements a rewriting logic and type checking ideas can be ported through this logic.

Impelmentations

Thoerem Proving

Rewriting

ReplaceAll [Object, [Rules]]

we use a close version:

["f" ["x"]]
  • Simulation of Turing machines by a regular rewrite rule

theory

Parser

JavaScript metatheory

Quantifier Elimination

  • Computation-Oriented Reductions of Predicate to Propositional Logic

Unification

Compiling

Redex

Weird

About

the internet's cutest javascript term rewriting system

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages