// work in progress //
tags: s-expression, rewriting, term-rewriting, term-graph-rewriting
project roadmap:
-
[x]
v0.1.x basic rewrite rules -
[x]
v0.2.x scoped rewrite rules -
[ ]
v1.0.x finalizing the package
A term rewriting system is a tool for automating the transformation of expressions, enabling efficient problem-solving in areas like formal verification, symbolic computation, and programming. By applying systematic rules, it ensures consistent and correct results in optimizing code, proving theorems, and simplifying complex expressions.
An S-expression (Symbolic Expression) is a simple and uniform way of representing nested data or code using parentheses to denote lists and atoms, commonly used in Lisp programming and symbolic computation.
Symbolverse is a term rewriting system. Symbolverse code functions like a set of mathematical formulas, but with a broader scope. It can transform not just mathematical expressions but any type of S-expressions, depending on rules we provide. Symbolverse is a Turing complete system, which means it has the capability to perform any computation that can be done by any other known computational system.
To get a glimpse on how a Symbolverse program looks like, here's a simple example:
(
REWRITE
/expression addition/
(
RULE
(VAR A B)
(READ (EXP (\add \A \A)))
(WRITE (EXP (\mul (((\0 \0) \1) \0) \A)))
)
/reducible fraction/
(
RULE
(VAR A B)
(READ (EXP (\div (\mul \A \B) \A)))
(WRITE (EXP \B ))
)
)
Providing the input (div (add x x) (((0 0) 1) 0))
, this example outputs x
.
There are a couple resources about Symbolverse to check out:
- Explore examples at online playground.
- Read the Symbolverse specification.
Symbolverse functions as a standalone executable operating on files. To build the executables from source code, do the following:
- make sure you have git, Node.js, and npm installed in your system
- enter OS command prompt
- install pkg:
sudo npm install -g pkg
on Linux, ornpm install -g pkg
on Windows - change to your project directory
- clone this repository:
git clone https://github.com/tearflake/symbolverse
- change directory:
cd symbolverse
- run pkg:
pkg . --out-path bin/
- if everything goes well, executables for Linux, Windows, and MacOS will be in
./bin/
directory
Executables run from command prompt, and take three parameters: rules-file, input-file, and output-file. If we omit the output-file parameter, the output is redirected to the terminal.
Symbolverse may expose its functionality through javascript API, both in browser and in Node.js.
To access the API from Node.js, install this package: npm i @tearflake/symbolverse
, and include the following line in your code:
const Rewriter = require('@tearflake/symbolverse');
To access the API from browser, clone this repository from GitHub: git clone https://github.com/tearflake/symbolverse
, and include the following line in your code:
<script src="path-to-symbolverse-package/symbolverse.js"></script>
Below, regardless of using Node.js or browser, use the API as:
var strRules = `
(
REWRITE
(
RULE
(READ (EXP (\\hello \\machine)))
(WRITE (EXP (\\hello \\world) ))
)
)
`;
var arrRules = Rewriter.compile (strRules);
var strInput = `
(hello machine)
`;
var strOutput = Rewriter.rewrite (arrRules, strInput);
console.log (strOutput);
We are making efforts to reach the version 1.0.0.
// work in progress //