HN user

philzook

941 karma

Website: https://www.philipzucker.com Twitter: https://twitter.com/SandMouth

Posts65
Comments228
View on HN
www.philipzucker.com 10mo ago

Compositional Datalog on SQL: Relational Algebra of the Environment

philzook
47pts3
www.philipzucker.com 11mo ago

A Python CLI for Verifying Assembly

philzook
1pts0
www.philipzucker.com 1y ago

A Python Frozenset Interpretation of Dependent Type Theory

philzook
5pts0
www.philipzucker.com 1y ago

"Verified" "Compilation" of "Python" with Knuckledragger, GCC, and Ghidra

philzook
2pts0
www.philipzucker.com 1y ago

A Small Prolog on the Z3 AST

philzook
3pts0
www.philipzucker.com 1y ago

Symbolic Execution by Overloading __bool__

philzook
81pts10
www.philipzucker.com 1y ago

Higher Order Pattern Unification on the Z3py AST

philzook
2pts0
www.philipzucker.com 1y ago

Tensors and Graphs: Canonization by Search

philzook
1pts0
www.philipzucker.com 1y ago

Acyclic Egraphs and Smart Constructors

philzook
4pts0
www.philipzucker.com 1y ago

String Knuth Bendix

philzook
2pts0
www.philipzucker.com 1y ago

Ordinals aren't much worse than Quaternions

philzook
62pts28
www.philipzucker.com 1y ago

Knuckledragger, a Semi-Automated Python Proof Assistant

philzook
71pts24
www.philipzucker.com 2y ago

Hashing Modulo Theories

philzook
59pts3
www.philipzucker.com 2y ago

Compiling with Constraints

philzook
126pts36
www.philipzucker.com 2y ago

Copy and Micropatch: Writing Binary Patches in C with Clang Preserve_none

philzook
3pts0
www.philipzucker.com 2y ago

The C bounded model checker: criminally underused

philzook
209pts125
www.philipzucker.com 3y ago

MiniLitelog: Easy Breezy SQLite Datalog

philzook
3pts0
www.philipzucker.com 3y ago

Datalite: A Simple Datalog Built Around SQLite

philzook
4pts0
www.philipzucker.com 3y ago

Duckegg: A Datalog / Egraph Implementation Built Around DuckDB

philzook
4pts0
www.philipzucker.com 4y ago

The Almighty Dwarf: A Trojan Horse for PL Research

philzook
2pts0
www.philipzucker.com 4y ago

Embedding E-Graph Rewriting in Constraint Handling Rules

philzook
2pts0
www.philipzucker.com 4y ago

Constrained Horn Clauses for Bap (2022)

philzook
2pts0
www.philipzucker.com 4y ago

Verifying Nand2Tetris Assembly with Constrained Horn Clauses (2021)

philzook
22pts4
www.philipzucker.com 4y ago

Egglog Examples: Pullbacks, Ski, Lists, and Arithmetic (2021)

philzook
1pts0
www.philipzucker.com 4y ago

Proving a Category Theory Theorem with Rust and Egraphs

philzook
2pts0
www.philipzucker.com 4y ago

Egglog: A Prolog Syntax for the Egg Egraph Library (2021)

philzook
2pts0
www.philipzucker.com 5y ago

An Interpreter of the Algebra of Programming in miniKanren

philzook
3pts0
www.philipzucker.com 5y ago

Making a “MiniKanren” using Z3Py

philzook
62pts5
www.philipzucker.com 5y ago

A Simple, Probably-Not-Exp-Time Disjoint Set in Coq

philzook
2pts0
www.philipzucker.com 5y ago

A Simplified E-graph Implementation

philzook
31pts7

It's a really neat board. You can get kits from aliexpress etc. I wrote up some notes here https://www.philipzucker.com/td4-4bit-cpu/ . English descriptions are not so readily available.

I also had some fun modelling the chips in verilog and model checking a verilog interpreter against them. https://www.philipzucker.com/td4_ebmc/ George Rennie got a similar thing working using the yosys toolchain https://github.com/georgerennie/philip_zucker_sby_demo

Yeah, using `<=` in this way is pretty sinful.

My maybe inaccurate understanding of recursive CTEs was that they only allow linear occurrences of the recursively defined relation in the query and do not allow many mutually recursively defined relations. These might be per implementation restrictions. These are pretty harsh restrictions from a datalog perspective. I should explore what Postgres offers more. It's just so easy to try stuff out on sqlite.

My suspicion is that if you can get away with it that recursive CTEs would be more performant than doing the datalog iteration query by query. AFAIK for general rules the latter is the only option though. I had a scam in that post to do seminaive using timestamps but it was ugly. I recently came across this new feature in duckdb and was wondering if there is some way to use it to make a nice datalog https://duckdb.org/2025/05/23/using-key.html . Anything that adds expressiveness to recursive CTEs is a possibility in that direction

Nice!

I'll note there is a really shallow version of naive datalog I rather like if you're willing to compromise on syntax and nonlinear variable use.

   edge = {(1,2), (2,3)}
   path = set()
   for i in range(10):
       # path(x,y) :- edge(x,y).
       path |= edge
       # path(x,z) :- edge(x,y), path(y,z).
       path |= {(x,z) for x,y in edge for (y1,z) in path if y == y1}

Similarly it's pretty easy to hand write SQL in a style that looks similar and gain a lot of functionality and performance from stock database engines. https://www.philipzucker.com/tiny-sqlite-datalog/

I wrote a small datalog from the Z3 AST to sqlite recently along these lines https://github.com/philzook58/knuckledragger/blob/main/kdrag...

Wide context.

But to be a bit more specific, I've been involved in the egraphs community https://github.com/philzook58/awesome-egraphs and we don't currently have a shared database of rewrite rules for benchmarking, nor do we collect the rules from different projects. Seeing the actual files is helpful.

On a slightly different front, I'm also trying to collect rules or interesting theories up in my python interactive theorem prover Knuckledragger https://github.com/philzook58/knuckledragger . Rewrite rule or equational theory looking things are easier to work with than things with deeply nested notions of quantifiers or tons of typeclass / mathematical abstraction like you find when you try to translate out of Coq, Lean, Isabelle.

There are also different approaches to declarative rewrite rules in major compilers. GCC, LLVM, and cranelift have their own declarative rewrite rule systems for describing instruction selection and peephole optimizations but also of course lots of code that programatically does this. I also want to collate these sorts of things. Working on fun clean systems while not confronting the ugly realities of the real and useful world is ultimately empty feeling. Science is about observing and systematizing. Computer science ought to include occasionally observing what people actually do or need.

I don't always care about consistency between rule sets. Depends what I'm trying to do.

The question at hand is motivating and getting benchmarks for different approaches or engines to equational reasoning / rewriting. I sometimes lose sight of motivations and get discouraged. Doing associativity and commutativity and constant fusion for the nth time I start to become worried it's all useless.

I'm curious if there is a useful connection between Apache's rule and other term rewriting. Some sort of static analysis? If there is a interesting database of them, I'd add it.

It's interesting how sometimes it feels like a topic starts showing up super often all of the sudden. It probably isn't a coincidence, since my interest and probably this post's interest is due to Tao's recent equation challenge https://teorth.github.io/equational_theories/ .

I was surprised and intrigued to find Wolfram's name when I was reading background literature doing this blog post https://www.philipzucker.com/cody_sheffer/ where I translated my friend's Lean proof of the correspondence of Sheffer stroke to Boolean algebra in my python proof assistant knuckledragger https://github.com/philzook58/knuckledragger (an easier result than Wolfram's single axiom one).

I was also intrigued reading about the equational theorem prover Waldmeister https://www.mpi-inf.mpg.de/departments/automation-of-logic/s... that it may have been acquired by Mathematica? It's hard to know how Mathematica's equational reasoning system is powered behind the scenes.

Mathematica can really make for some stunning visuals. Quite impressive.

It's a good question. I was asking something like this myself at lunch today.

Basically I think the issue is that SAT solvers accept stuff at a conjunctive normal form level, which is pretty far from what you'd want to use for most applications. It's more like an IR. So SAT solvers are more typically backends to higher level tools which compile to them.

If your tool offers a high level interface, one may be inclined to just call it an SMT solver. I too despite being interested in SAT, basically reach for an SMT solver even if my problem is pure boolean because of convenience.

- SAT/SMT by example is an excellent text https://smt.st/

- https://pysathq.github.io/ offers a nicer interface directly to SAT solvers

- Z3 https://microsoft.github.io/z3guide/docs/logic/intro/ can put problems into CNF and pretty print dimacs. It contains a SAT solver, but one would probably expect a purely boolean problem to do better on the top of the line SAT-only solver like Kissat.

I am also a bit surprised, but happy that people find value here. Maybe just pretend the article ends before "bits and bobbles". Then it is just a short note on a brute force solver and a Davis Putnam solver. I like keeping my notes in my posts because it's useful for me to do so and helps psychologically with editing and scope creep. People have been able to interpret what I was getting at but didn't flesh out a lot more than I expect. Sometimes they explain a point that I mention I was confused on or wondering about in the notes section.

This looks like a nice reflection of python into a syntax tree, but unless I'm mistaken, it can't reflect python control structures like if-then-else? Z3 or sympy already are kind of ready to go systems that overload all the typical operators. Is there something you've done here they are missing?

This looks great! The paper linked in your README https://hoheinzollern.files.wordpress.com/2008/04/seer1.pdf also seems like a nice explanation of similar ideas.

The reason I'm exploring this idea is to use more natural looking python as dsl for function definitions in my proof assistant https://github.com/philzook58/knuckledragger

Also to see if I can make a nice-looking staged metaprogramming framework in python like buildit, but maybe to generate C/C++ rather than more python.

Could Crosshair be used in these ways?

I like what I find clearest (a moving target for all sorts of reasons). I typically find recursion clearest for things dealing with terms/ASTs. My coding style usually leans towards comprehensions or fold/map etc rather than loops. That's why I find the loop being clearer for this algorithm surprising.

How do you go from these definitions of ordinal arithmetic by transfinite recursion to mechanical rules for arithmetic on the cantor normal form / deriving the needed algebraic identities? It seems very non obvious to me, although certainly must be very obvious to many. I would like a reference if you have one.

I think a deficiency of my post is that I didn't go into much of what the ordinals are, but I think a strength is that it is all quite mechanical.

I leave my notes at the bottom of my posts. It is a combination link dump, half thoughts, speculation, parts I was too exhausted to flesh out.

I recommend the technique.

- It is actually the part that is the most valuable for me to refer to, since the actual content of the post I understand well by the time I write it.

- It has generated the most conversations, since people are more interested in pipping up about an unsolved problem than a solved one.

- It helps me edit since tossing stuff back there helps me more ruthlessly delete without the irrevocable loss of some paragraph I kind of liked.

- It gets it out there. Perfection is the enemy of the good.