Hi DEV Community! 👋
I’ve just released version 0.9.2 of zelph, a semantic network system capable of encoding inference rules within the network itself.
It’s open source and designed for high-performance logical reasoning.
What makes it special?
In zelph, rules are facts. Unlike traditional systems where logic is external code applied to data, zelph treats relation types (like "transitivity") as first-class nodes in the graph. This allows for powerful meta-reasoning where you can make statements about statements.
A Taste of Logic: Try it yourself
Before we talk about terabytes of data, let’s look at how it feels to use. zelph has an interactive CLI.
1. Basic Inference
You can define facts and rules on the fly. Note that none of the items below are predefined; zelph learns them as you type:
# Start the interactive shell
zelph
Berlin "is capital of" Germany
Germany "is located in" Europe
# Define a rule: If X is capital of Y, and Y is in Z, then X is in Z
X "is capital of" Y, Y "is located in" Z => X "is located in" Z
Output:
«Berlin» «is located in» «Europe» ⇐ («Germany» «is located in» «Europe»), («Berlin» «is capital of» «Germany»)
zelph automatically inferred the location of Berlin based on the rule.
2. Meta-Reasoning (Transitivity)
This is where it gets interesting. Instead of writing a specific rule for every transitive relation, we can define "transitivity" itself as a concept in the network.
(Note: ~ is shorthand for "instance of" or "is a").
# Define a general rule for ANY transitive relation R
R ~ "transitive relation", X R Y, Y R Z => X R Z
# Now, declare that "greater than" is a transitive relation
> ~ "transitive relation"
# Give it some numbers
6 > 5
5 > 4
Output:
«6» «>» «4» ⇐ («5» «>» «4»), («6» «>» «5»), («>» «~» «transitive relation»)
Because > is an instance of a transitive relation, zelph applied the meta-rule and deduced that 6 > 4.
3. Detecting Contradictions
You can also define what is impossible using !.
# Rule: If X is opposite of Y, a thing A cannot be both X and Y
X "is opposite of" Y, A ~ X, A ~ Y => !
If you (or an imported dataset) try to assert facts that violate this, zelph detects the logical contradiction immediately.
The Benchmark: Debugging 1.7 TB of Knowledge
To test the limits, I optimized zelph to process the entire Wikidata Knowledge Graph (over 113 million entities). But this wasn't just a performance test—it was a logic audit.
Using the rules described above (like disjointness and transitivity), zelph identified hundreds of megabytes of logical contradictions hidden within the live Wikidata dataset.
- Performance: ~1000x speedup in reasoning compared to early prototypes.
- Scale: A single-pass analysis of the full graph (requires ~256 GB RAM for the full dump, but scales down for smaller tasks).
- Results: We detected massive amounts of Split Order Violations (broken hierarchies) and Disjointness Errors (items belonging to mutually exclusive categories).
You can dive into the results and see the actual logical "bugs" found in the Grant Report.
Now available everywhere
Thanks to a recent sprint (and a Wikimedia Grant), you can install it natively to play with the logic engine yourself:
- Windows:
choco install zelph - macOS:
brew tap acrion/zelph && brew install zelph - Linux:
pikaur -S zelph(AUR)
Future Directions: Lisp & "Code as Data"
This is where I’d love your input.
The current custom scripting language (shown above) works well, but I plan to embed a Lisp dialect (specifically Fennel or Janet) to perfectly mirror the semantic network structure where rules and facts are identical nodes.
This aligns perfectly with the "Code as Data" philosophy.
- Why Fennel? Incredible performance (LuaJIT) and seamless synergy with my other project, nexuslua.
- Why Janet? Modern, great macro system, clean C API.
If you are interested in C++20, Semantic Web, or Lisp embedding, check out the repo!
🔗 GitHub: https://github.com/acrion/zelph
🔗 Grant Report & Architecture: https://zelph.org/grant-report
Happy coding!
Stefan
Top comments (0)