alt.hn

2/23/2026 at 5:01:26 PM

Some silly Z3 scripts I wrote

https://www.hillelwayne.com/post/z3-examples/

by azhenley

2/26/2026 at 5:45:23 PM

I'm suspicious of the theorem proving example. I thought Z3 could fail to return sat or unsat, but he is assuming that if it's not sat the theorem must be proven

by jeremysalwen

2/26/2026 at 6:33:25 PM

No I think it's fine. On another note, I have proven Fermat's Last Theorem with z3 using this setup :) and it goes faster if you reduce a variable called "timeout" for some reason!

  from z3 import *
  
  s = Solver()
  s.set("timeout", 600)
  a = Int('a')
  b = Int('b')
  c = Int('c')
  s.add(a > 0)
  s.add(b > 0)
  s.add(c > 0)
  theorem = a ** 3 + b ** 3 != c ** 3
  if s.check(Not(theorem)) == sat:
      print(f"Counterexample: {s.model()}")
  else:
      print("Theorem true")

by ymherklotz

2/26/2026 at 6:31:16 PM

...Whoops. Yup, SMT solvers can famously return `unknown` on top of `sat` and `unsat`. Just added a post addendum about the mistake.

by hwayne

2/26/2026 at 3:29:04 PM

For the curious, solvers like z3 are used in programming languages to verify logic and constraints. Basically it can help find logic issues and bugs during compile time itself, instead of waiting for it to show up in runtime.

https://en.wikipedia.org/wiki/Satisfiability_modulo_theories...

by potato-peeler

2/26/2026 at 4:14:45 PM

The concept is called static analysis.

by bjornsing

2/26/2026 at 4:47:44 PM

Seems adjacent, with some overlap.

by ukuina

2/26/2026 at 5:15:41 PM

in theory that's what a compiler is - a thin wrapper over a SAT solver. in practice most compilers just use heuristics <shrug>.

by mathisfun123

2/26/2026 at 3:21:28 PM

I was expecting a Z3 computer from Germany.

by iberator