// 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 packageA 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 an S-expression based 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))
, the example outputs x
.
There are a couple resources about Symbolverse to check out:
Symbolverse functions as a standalone executable operating on files. To build the executables from source code, do the following:
sudo npm install -g pkg
on Linux, or npm install -g pkg
on Windowsgit clone https://github.com/tearflake/symbolverse
cd symbolverse
pkg . --out-path bin/
./bin/
directoryExecutables 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 (Application Programming Interface), 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, approach the API as:
var strRules = `
(
REWRITE
(
RULE
(READ (EXP (\\hello \\machine)))
(WRITE (EXP (\\hello \\world) ))
)
)
`;
var arrRules = Rewriter.compile (strRules);
if (!arrRules.err) {
var strInput = `
(hello machine)
`;
var strOutput = Rewriter.rewrite (arrRules, strInput);
if (!strOutput.err) {
console.log (strOutput);
}
}
We are making efforts to reach the version 1.0.0.
// work in progress //