Show HN: Vector-logic, a lightweight rules engine from first principles(github.com)
github.com
Show HN: Vector-logic, a lightweight rules engine from first principles
https://github.com/dmitry-lesnik/vector-logic
9 コメント
Hi Dmitry. This is really cool -- thanks for sharing! This is very clean and intuitive, and it definitely come in handy when I'm mapping out systems logic.
Glad to hear that! Ping me if you have any questions
How does this compare to something like Prolog?
Prolog is heavy-weight 1st order logic machine.
vector-logic is light-weight propositional logic inference engine. Optimised for simple queries like "what is the value of 'y' given all rules and evidences", and also allows you to iterate through the entire valid set (all valid assignments).
We also bothered to make the interface very simple and intuitive - you'll have very shallow learning curve.
vector-logic is light-weight propositional logic inference engine. Optimised for simple queries like "what is the value of 'y' given all rules and evidences", and also allows you to iterate through the entire valid set (all valid assignments).
We also bothered to make the interface very simple and intuitive - you'll have very shallow learning curve.
Is it brute force or uses some sort of heuristics?
Good point. Yes, it uses optimisation for various tasks.
First of all, it uses compact representatin of rules - similar to DNF, but converted to a sparse matrix.
Second, for the inference (which is a process of compiling the knowledge base) the order in which rules are compiled is crucial. We use two types of heuristic optimisations for this process, one is based on Jaccard similarity, another is so called predator-pray heuristics.
Happy to give more details, let me know
First of all, it uses compact representatin of rules - similar to DNF, but converted to a sparse matrix.
Second, for the inference (which is a process of compiling the knowledge base) the order in which rules are compiled is crucial. We use two types of heuristic optimisations for this process, one is based on Jaccard similarity, another is so called predator-pray heuristics.
Happy to give more details, let me know
I checked your benchmarks. Runtime with 30 rules is 5x longer than with 45 rules. Am I missing something?
This is an expected behaviour. More rules impose more constraints on the feasible space. The space with more rules is hence much smaller. The only pitfall is that in the middle of calculation the feasible space may blow up before eventually shrinking. This is where the optimisation heuristics helps. Your previous question was spot on :)
We built vector-logic (it's on PyPI) and wrote a hands-on guide for Towards Data Science: https://towardsdatascience.com/building-a-rules-engine-from-...
The whole framework is based on a theory we call 'State Algebra,' which we co-authored for arXiv: https://arxiv.org/abs/2509.10326
Happy to answer any questions!