Knuckledragger Update: Halmos Set Theory, Pretty Printing, and Emotions Phil Zucker's Knuckledragger, a shallow z3-based proof assistant built as a Python library, added autoformalizations of Halmos's Naive Set Theory (pull request 99) and roughly half of Abbott's Understanding Analysis (pull request 108), along with a new formula and goal pretty printer, tf-idf-based lemma suggestions on proof failure, and a theorem search plus browser-based JupyterLite REPL. Zucker wrote that the autoformalization work is "the least surprising thing AI has demonstrated in the last year, but good to know what's possible," and said of the new pretty printer, "I should have prioritized this way earlier." The update matters to developers building formal-methods and theorem-proving tooling in Python. Knuckledragger Update: Halmos Set Theory, Pretty Printing, and Emotions Got a fresh wind on Knuckledragger https://www.kdrag.com https://www.kdrag.com https://github.com/philzook58/knuckledragger https://github.com/philzook58/knuckledragger , my shallow z3 proof assistant as a python library. TLDR: - Autoformalized Halmos Naive Set Theory https://github.com/philzook58/knuckledragger/pull/99 and 1/2 of Abbott’s Understanding Analysis https://github.com/philzook58/knuckledragger/pull/108 . This is the least surprising thing AI has demonstrated in the last year, but good to know what’s possible. - New formula and goal pretty printer. Holy shit, it’s so much better. I should have prioritized this way earlier. It look like this: a₀ b₀ c₀ : ℤ → ℝ x₀ ε₀ : ℝ N₀ N₁ : ℤ 0: ∀n : ℤ, n ≥ 0 → a₀ n ≤ c₀ n ∧ c₀ n ≤ b₀ n 1: ∀n : ℤ, n N₀ → |a₀ n - x₀| < ε₀ 2: ∀n : ℤ, n N₁ → |b₀ n - x₀| < ε₀ 3: ε₀ 0 ────────────────────────────────────────────────────────────── ⊢ ∀n : ℤ, n if N₀ ≥ N₁ then N₀ else N₁ → |c₀ n - x₀| < ε₀ - Auto suggest lemmas on failure via tf-idf https://en.wikipedia.org/wiki/Tf%E2%80%93idf on symbols - Theorem search https://www.philipzucker.com/knuckledragger/theorems.html?theorem=lim and jupyterlite https://www.philipzucker.com/knuckledragger/lite/repl/index.html?kernel=python&execute=0&clearCodeContentOnExecute=0&code=%23+Shift%2BEnter+to+run.+Python+runs+in+your+browser+via+Pyodide.%0A%23+The+first+run+installs+knuckledragger+and+z3%2C+which+takes+a+few+seconds.%0A%25pip+install+-q+--no-deps+knuckledragger+z3-solver+lark+graphviz%0Afrom+kdrag.all+import+%2A%0Afrom+kdrag.theories.real.rseq+import+%2A%0A%0A%40PTheorem%28%22forall+%28a+%3A+RSeq%29+%28x+y+%3A+Real%29%2C+has lim+a+x+-%3E+has lim+a+y+-%3E+x+%3D+y%22%29%0Adef+lim unique%28l%29%3A%0A++++return++%23+move+down+%28Alt%2BDown%29+to+step+through+the+proof%0A++++a%2C+x%2C+y+%3D+l.fixes%28%29%0A++++l.intros%28%29%0A++++l.contra%28%29%0A++++eps+%3D+real.abs%28x+-+y%29+%2F+2%0A++++l.unfold%28has lim%2C+at%3D0%29%0A++++l.unfold%28has lim%2C+at%3D1%29%0A++++hx+%3D+l.top goal%28%29.ctx%5B0%5D%0A++++hy+%3D+l.top goal%28%29.ctx%5B1%5D%0A++++l.specialize%28hx%2C+eps%29%0A++++l.specialize%28hy%2C+eps%29%0A++++l.have%28real.abs%28x+-+y%29+%3E+0%2C+by%3D%5Breal.abs pos iff%5D%29%0A++++l.have%28eps+%3E+0%2C+by%3D%5B%5D%29%0A++++n1+%3D+Int%28%22N%22%29++%23+%22N1%22+is+problem+for+alpha+rename%0A++++n2+%3D+Int%28%22N%22%29++%23+%22N2%22+is+problem+for+alpha+rename%0A++++n+%3D+Int%28%22n%22%29%0A++++exists x+%3D+QExists%28%0A++++++++%5Bn1%5D%2C%0A++++++++QForAll%28%5Bn%5D%2C+n+%3E+n1%2C+real.abs%28a%5Bn%5D+-+x%29+%3C+eps%29%2C%0A++++%29%0A++++exists y+%3D+QExists%28%0A++++++++%5Bn2%5D%2C%0A++++++++QForAll%28%5Bn%5D%2C+n+%3E+n2%2C+real.abs%28a%5Bn%5D+-+y%29+%3C+eps%29%2C%0A++++%29%0A++++l.have%28exists x%2C+by%3D%5B%5D%29++%23+unstable+due+to+alpha+rename%3F%0A++++N1%2C+ +%3D+l.obtain%28exists x%29%0A++++l.have%28exists y%2C+by%3D%5B%5D%29%0A++++N2%2C+ +%3D+l.obtain%28exists y%29%0A++++N+%3D+If%28N1+%3E+N2%2C+N1%2C+N2%29+%2B+1%0A++++forall x+%3D+QForAll%28%5Bn%5D%2C+n+%3E+N1%2C+real.abs%28a%5Bn%5D+-+x%29+%3C+eps%29%0A++++forall y+%3D+QForAll%28%5Bn%5D%2C+n+%3E+N2%2C+real.abs%28a%5Bn%5D+-+y%29+%3C+eps%29%0A++++l.specialize%28forall x%2C+N%29%0A++++l.specialize%28forall y%2C+N%29%0A++++l.have%28N+%3E+N1%2C+by%3D%5B%5D%29%0A++++l.have%28N+%3E+N2%2C+by%3D%5B%5D%29%0A++++l.have%28real.abs%28a%5BN%5D+-+x%29+%3C+eps%2C+by%3D%5B%5D%29%0A++++l.have%28real.abs%28a%5BN%5D+-+y%29+%3C+eps%2C+by%3D%5B%5D%29%0A++++l.have%28real.abs%28x+-+a%5BN%5D%29+%3C+eps%2C+by%3D%5Breal.abs neg%5D%29%0A++++l.have%28%0A++++++++real.abs%28x+-+y%29+%3C%3D+real.abs%28x+-+a%5BN%5D%29+%2B+real.abs%28a%5BN%5D+-+y%29%2C%0A++++++++by%3D%5Breal.abs triangle%28x%2C+y%2C+a%5BN%5D%29%5D%2C%0A++++%29%0A++++l.have%28%0A++++++++real.abs%28x+-+y%29+%3C+eps+%2B+eps%2C%0A++++++++by%3D%5Breal.abs triangle%28x%2C+y%2C+a%5BN%5D%29%5D%2C%0A++++%29%0A++++l.have%28eps+%2B+eps+%3D%3D+real.abs%28x+-+y%29%2C+by%3D%5B%5D%29%0A++++l.have%28real.abs%28x+-+y%29+%3C+real.abs%28x+-+y%29%2C+by%3D%5B%5D%29%0A++++l.auto%28%29 examples in docs - More cleanup and syntactic niceties - Wired in cvc5, eprover, vampire as available by default, although they are basically not that useful overtop z3 see below . - https://github.com/philzook58/knuckledragger/pull/89 issuecomment-7068674786 https://github.com/philzook58/knuckledragger/pull/89 issuecomment-7068674786 expandable proof traces in PRs - Playing around with using manim. I think this is more flashy than it is educational or useful. Phil’s Emotions I had kind of been off Knuckledragger for 6 months. I had been trying to do things adjacent to Knuckledragger at work, using it for binary verification and TLA model validation, but that project was cancelled which feels ironic given the recent hype cycle that occurred only months later . It was very draining to try and manually apply knuckledragger to these gnarly awful symbolic execution goals, so I think that drained enthusiasm This past week has also been very tough in regards to AI news the Riemann hypothesis thing . I was in full non stop panic mode for about 5 days, but now I’m coming out of it I think. I wonder if you weighed benefits to society of current AI against the mental health toll and demotivation you’d come out ahead or not. Personally, I think it is a net negative because the trends and uncertainty make me so stressed and sad. I got a little pep in my step just setting up PyPI packages for vampire and eprover as a treat. There is something that really excites me about having something packaged on PyPI or available in WASM. It is a totally irrational nerd impulse and I’m grateful for it. Joy is good. So I replaced my nasty build scripts that nobody had ever used with these dependencies and then one thing led to another with more cleanups, features and stuff as I said above. Why Knuckledragger? You know, Knuckledragger is pretty fucking cool. And I don’t expect anybody to ever use it and that is fine. Here’s a question: how does one do or try anything when most new things fail? Don’t listen to me, I’m depressed, and it is my explicit goal not to spread that. The point of life is to be happy and share it with others. At the outset of Knuckledragger, I knew the project is on the face of it completely deluded. Lean was already hot by then, and there are a number of systems with decades of work by smart hardworking people in them. I have found that regardless how the world changes or the news cycle, I can come up with some new story about how it could make sense to build this thing. So I guess I’m just building it because I’m building it, not for some coherent constant reason. At the beginning, I had just come off a project developing verification tooling for a hacker crowd and it was legitamately a major downside for our tooling to be in OCaml if that was our audience, in terms of their familarity with the ecosystem or language or willingness to type opam install . So at one point, a hypothesis was that if I built knuckledragger, a different sort of community with a different sort of problems might be engaged. The kinds of people who are using matplotlib, scipy, numpy etc. This has not born out and to my knowledge no one has ever used knuckledragger. I have not produced the necessary educational material so I don’t know how that would have magically happened anyway. At another point, we thought that it might be that AI would be vastly superior at Python compared to other languages because of the larger dataset. AI has shown itself to be basically good at all languages. It does appear use little python snippets to achieve tasks? I do not expect AI to be superior at knuckledragger compared to Lean and Lean has a much better soundness story by design + comparator. The case for knuckledragger is close to vanishingly small The biggest problem AI has right now in regards to verification is how to keep the human in the driver seat on top of the bucking bronco. How to funnel the mass of confusion to a simple thing the human tracks. Roughly, this is in the form of specs and the model, which the human needs to kind of check off on. Maybe a python native form of this is useful because many humans are currently good at python and I think this is partially because of an intrinsic friendliness of the system / language compared to some alternatives for many people yeah yea yea, show me you weird variable binding examples or dense inscrutable walrus, mutation, comprehension examples, Fuck off. . Building knuckledragger has been one of the most educational and fun projects I’ve ever done. I’ve learned so much more about logic and have a way better context for discussions about how other systems work. That is a reason to build it, but that is not a reason for anyone else to use it. I have always found it interesting and educational to strip out complexity. Many quantum phenomenon have classical counterparts, continuous or infinite have finite counterparts, noncomputational stuff has computational, etc. A good method for understanding and solving is to strip out so much complexity that it becomes really trivial and then if you still care you can try and put the complexity back in. There is a quote about “make explanations as simple as possible, but no simpler”, but I disagree. Completely mangle all nuance beyond recognition. Go simpler than is reasonable. I do like having a system I understand the entirety of and can change anything about. That is not the case of Lean or Isabelle or Rocq. So maybe for some of you, I recommend you build your own knuckledragger more so than use mine. I do think the shallow smt design gets you far fast and I do wonder what kinds of idioms might be nice for embedding in other languages. Surprising Lessons A happy accident in knuckledragger was when I early on switched from my own AST to just reusing Z3’s. This removed a lot of boiler plat. At the same time, I have been very frustrated by the foundations of knuckledragger as z3 is missing notions or is not extensible in ways I wanted. Parametric types currently do not work at the level of thoroughness or correctness I’d need them too to more closely hew to some of Isabelle or HOL-light’s designs for abstractions locales, typeclasses, etc . Trying to do it from the outisde is in principle possible, but self defeating in terms of bloat and reliability and wasted computational effort. My current thinking though that this accidental restriction is kind of beautiful and the main draw to me of knuckledragger over other systems. You like can’t abstract, so you can’t be distracted or confused by it. It’s kind of like C vs Haskell or something. C offers very low abstraction capabilities, so in the good case you just solve your actual problem and move on. Haskell is super fun and beautiful but more prone to abstraction naval gazing and eventually gains an inscrutable web of stacked concepts if you do not practice restraint. I mean, if you don’t practice restraint, you’ll end up fucked in every system or full AI I don’t understand anything about the code bankrupt, which might be the perfectly economically viable normal future . I find it simpler, illuminating and intuitive to see how a problem can be formulated in simply typed higher order logic with built in Int, Real, and Bool than it is to see a problem formulated in dependent type theory using inductives. I don’t think I will ever not think those are less weird. All we really should have ever needed for normal math was second order arithmetic anyway right? Another surprise was that external solvers has by an large been useless. Z3 is so good but not perfect that again the reliability, soundness, and slowness of shelling out to vampire or cvc5 has basically never been worth it except for fun. It is my policy that every z3 call should solve in ~1ms since I need to do a lot of them. This means that really the calls I make are pretty “easy” mostly and ones you expect not to have much delta between solvers anyhow. Another frustration is that the python- C interop and the z3py rewrappings are slow slow slow slow compared to even pure python AST manipulation . This is scary for the viability of knuckledragger because at a certain point, spelling out manual proof steps is more expensive than a z3 solver call. The nuclear option here is to eventually move more bulk operations like the kernel or rewriting into an external c++ or rust side car project. I think showing restraint here has thus far been the right move. It is a big jump in project complexity. If Knuckledragger becomes complex, it is self defeated. But also I should do whatever is fun for me. The herband and skolem axiom schema for dealing with binders is kind of working pretty well despite being extremely dirty. I keep being tempted to add a context to my protected Proof judgement, but it just doesn’t seem worth it so far. AI Thoughts So yea, I was trying to really keep a handle on using AI with knuckledragger. I was trying to make sure I understand and walked through every proof. It was excrutiatingly slow and really not that fun : . Like, on one hand proving stuff sucks. Remembering the lemmas, realizing how many lemmas you’re missing when you start a problem that really you’d like to just take for granted. On the other hand, the process is a thing to do, a thing to be engaged with, and does add precision and missing understanding. I guarantee you will misformulate your theorem’s statements or even definitions all the time and only realize once you go to actually prove them. I don’t really understand mathematician’s math. I like literally can’t parse the homework problems in textbooks as an activity. I need the computer arbiter to agree that we are doing an activity that makes sense. So I just let the thing loose and started burning tokens. One thing that helps me mentally is to keep the output in a different folder than what I was working on and have a handle on. I am keeping the ai output in kdrag.contrib and will move it if and when I understand it, which I may never do if it isn’t enriching or useful work. AI feels like a tragedy because it is destroying the point to problems I thought were fun, but I only was in the equilibrium I was because of circumstances. Problems that were already completely solved I enjoyed mostly ignoring like anything z3 can handle automatically . Having a useful library of lemmas to get to actually interesting physics or engineering problems was years away if it ever happened. So I guess I’m thinking I’ll just put my foot on the gas and see where I end up. What is the new equilibrium? On the other hand, it is so so emotionally draining to hear the news and also watch the thing use my system to prove a stream of theorems that I probably could do eventually, but at a rate 10000x what I can do. I also see that the thing just plows through ergonomic issues that I would stop and fix. I am missing the opportunity to feel friction. Ergonomics and UI are more important than ever. A possible pitch for Knuckledragger now is that AI can do all theorem proving if you don’t care about the details of it. We have basically perfect minus efficiency automated theorem provers available now. There is no prospect for for automated theorem provers to ever be superior to AI based systems ever again in terms of generality and flexibility. It is possible that the basis in z3 means that Knuckledragger could be more token efficient. It is possible that human ergonomic ~ token efficient. Good error messages, difficult to do the wrong thing, traditional automation. Bits and Bobbles A better exact? lim lemma ctx : list var , e It should be a contextual term yeah? Do I also want the unfolded lim lemmas? Hmm. So lean olean files are compiled and assumed trust by default. Makes perfect sense a pickle cache in kernel? thm.sepxr might be espnsive too. It’s interesting how the naive definitions are probably the ones I want. Maybe specializing the abstract things to them Filter - eventually Generate C++ https://www.youtube.com/watch?v=ERemvvBxlxo https://www.youtube.com/watch?v=ERemvvBxlxo . Yeah, why didn’t i try this? Too scared of C++ iunion sunion Revamp simp Wait, didn’t I have a rewrite set? Not as a named thing class Simp: data : dict FuncDeclRef, get implied equalities + oritent according to depth and ground. - substitute. That’d be kind of a nice simp https://github.com/Copilot-Language/copilot https://github.com/Copilot-Language/copilot use case of C backend https://ivorylang.org/ivory-fib.html https://ivorylang.org/ivory-fib.html cast huh. bidirectioanl typing. cast ~ check? cast ~ ann? Why in the world is the sort first py2expr is synth ? py2sexpr - list BoolRef , Expr a list of validity conditions? synth object - SortRef, ctx ~ {Int | x = 0} ctx ~pre |- object == {Sort | post} check object, ctx, SortRef ~ … Hmm. That’s kind of interesting. check ctx, object, SortRef, post ~ ctx |- object <== {Sort | post} ctx : list Hyp | Var I can spec a recursive definition, but then need to prove it exists and then obtain ? How could I prove such a thing though… ? elaboration inside Maybe I should really overload how Function works from scratch. Take over coerce Take over other things. Avoid redundant ctypes calls. solve for metavars too? When do I actually care about that. Maybe vec operations? , data : Seq Real Model 2 php kd.tuple coord : Seq Int - Int, : data : RSeq stride? shape? Tensor = Struct coord coord : Seq Int - Int, data : SeqSort Real . dom is implicitly if coord idx is greater than data size or less than zero Model 1 tensor = SeqSort Int - Real It’s total. Sry not sry I guess this is an assumed convention for casting? Or the assume convention is in the contruction. tesnro SeqSort Int - Option Real SeqSort Int - Real, dom : SetSort SeqSort ones = K , 1 zeros = K , 0 matmul = yikes broadcasting. We’re always broadcasting in infinite space… broadcast = Lambda idx , A thin idx tensor eq = dom1 == dom2 & forall idx, dom1 idx = data1 idx == data2 idx Is there a point to all this? resize shape = Set SeqSort Int , not Int,Int,Int . That’s a first order syntactic. Akin to Intervals as tuples vs sets zeros shape = Lambda idx, If shape idx , 0, undef zeros shape matmul isn’t even sensical without sizes. We’re assuming they are rank 2 now? Well, remora wants prefix broadcasting, so it pulls out 2 dims from each and matmal n,A,B = Lambda idx, Length idx = 2, recdef of matmul , undef matmul matmul n, A, B im2col conv tensor = Index - A Do induction right with a ForAll P, axiom. Also maybe swithc Traces as Seq Result . But that’s only true for Int/Nat indexed stuff. Seq Unit = Nat. Is that crazy? Yeah prob Look at Tao examples O n^3 etc ass eq a,b,3 Oeq a,b,3 plazter deriv y = f y,t 1d forall t, has deriv at y, t, f y,t = y = solution? has deriv at y,t,f y,t = Safetyprop y,t internalized GAT facilitie body = f <= Not f not a = a is obviously not allowed. Hmm. So even = is not enough. Might want to Theorem x,y,z , hyp1,hyp2 Theorem ForAll x,y,z , hyp1, hyp2 When we close, maybe we want to always strip off the shitty of freshvar Better get lemma. Maybe get lemma should start reporting it as an error. x,y,z = fixes but this is repetitive usually h1,h2,h3 = intros not previously named Things to copy rom other interesting tactics? Take halmos and intersperse proofs Analysis Open Texts euclid’s elements? Do symbolic exploration of a binary via z3 pathways? knuth spivak multivariable munkres, topology spivak axler hyperreals constructive analysis - intervals traat measure functional analysis? proof mining reverse mathematics categories? manifolds exteriorir calculus complex anlaysis Nand2tetris kalman filters etc ok but what is it for then. I think holding suspecion of dispbelief is fine for now. But if I’m not gonna look at it, why not lean? It is a little interesting to see fully concrete implementations without abstraction How to fomrulate Data set although skewed because it’s using the tools as they exist Do videos on halmos? I did write the first stuff. Can I understand the later stuff? Maybe videos is an inspiration iprove class IProof thm def check inuitionistics thm, kwargs : check format of problem return prove thm, kwargs One liners = Lemma .fix lambda x,y,z: l.auto .qed Lemma .fix lambda x,y,z: l.unfold , forallI 2, lambda x, prove The exact tactic is pretty weird move tele and contracts to junk arbtitrary bitwidth as Int - Bool python def fun goal, k : n = inspect.sginature k herb, vars and hyps = open binder goal, n pf = k vars and hyp,s, newgoal return modus pf, herb BoolRef.fun foo = ForAll x, x 0 .by lemma1, lemma2 Exists x, x 0 .intro 17, 17 0 .mk .sigma? I don't think we really need to offer the thing? It's inferrable ForAll x, x 0 .exact lemma a by is short, exact is a bit long? goal.by l maybe l should just do a quick check that l isn't equal to goal Vis HCI Domain specific vis? For just real analysis. There probably is some way to visualize eps-delta proofs… Outside the box thinking of ways to show me. Visualization? Using 3 blue 1 brown https://github.com/3b1b/manim https://github.com/3b1b/manim Does that actually help? Theory of UI. affordances Suggest and Hammer Hammering toards QED https://www.cl.cam.ac.uk/~lp15/papers/Automation/h4qed-clean.pdf https://www.cl.cam.ac.uk/~lp15/papers/Automation/h4qed-clean.pdf MePo SinE symbol counts + tf-idf Maybe this is a totally different tact, but I’ve heard of and not understood the “waterfall method” of acl2 / boyer moore https://github.com/samth/waterfall https://github.com/samth/waterfall and not rwally understood what it is. Also Bundy’s rippling in reagrds to improving induction proving. And or help me learn about them? Finite Sets is finite set a is finite set sort s FiniteSetSort elem sort FiniteSetEmpty set sort Singleton elem FiniteSetUnion s1, s2 FiniteSetIntersect s1, s2 FiniteSetDifference s1, s2 FiniteSetMember elem, set In elem, set FiniteSetSize set FiniteSetSubset s1, s2 FiniteSetMap f, set FiniteSetFilter f, set FiniteSetRange low, high from kdrag.all import from kdrag.theories.real import RSeqFSet = FiniteSetSort RSeq already has an or sub or = kd.notation.or .register RSeqFSet, FiniteSetUnion and = kd.notation.and .register RSeqFSet, FiniteSetIntersect sub = kd.notation.sub.register RSeqFSet, FiniteSetDifference le = kd.notation.le.register RSeqFSet, FiniteSetSubset empty = FiniteSetEmpty RSeqFSet def finset induct S, P : S1 = FreshConst RSeqSeq, prefix="S" v = FreshConst RSeq, prefix="v" return axiom Implies And P empty , ForAll f, S , P S1 , Not S v , P Singleton v | S1 P S A = Const "A", RSeqFSet How doe you sum if there is no ordering... ? span = define "spac", A, Lambda v, Exists x, span A v Set of vectors RSeqSet is basis = define "is basis", ForAll u,v,w from kdrag.all import from kdrag.theories.real import from kdrag.theories.real.seq import n = Int "n" in = Const "I", ArraySort IntSort ,RSet a,b,c = Consts "a b c", RSeq x,y,z = Reals "x y z" @PTheorem ForAll a,b, c, x , ForAll n, n = 0, And a n <= c n , c n <= b n , has lim a,x , has lim b,x , has lim c,x def squeeze l : a,b,c,x = l.fixes l.unfold has lim squeeze, lima, limb = l.intros eps = l.fix eps pos = l.intro l.specialize lima, eps, eps pos l.specialize limb, eps, eps pos N1 = l.obtain 1 N2 = l.obtain 2 N = If N1 = N2, N1, N2 l.exists N l. Next Goal: a₀ b₀ c₀ : ℤ → ℝ x₀ ε₀ : ℝ N₀ N₁ : ℤ 0: ∀n : ℤ, n ≥ 0 → a₀ n ≤ c₀ n ∧ c₀ n ≤ b₀ n 1: ∀n : ℤ, n N₀ → |a₀ n - x₀| < ε₀ 2: ∀n : ℤ, n N₁ → |b₀ n - x₀| < ε₀ 3: ε₀ 0 ────────────────────────────────────────────────────────────── ⊢ ∀n : ℤ, n if N₀ ≥ N₁ then N₀ else N₁ → |c₀ n - x₀| < ε₀ search "squeeze" --------------------------------------------------------------------------- ValueError Traceback most recent call last Cell In 17 , line 1 ---- 1 search "squeeze" File ~/vibe coding/knuckledragger/src/kdrag/utils.py:1435, in search db, es 1433 results.append search expr e, db 1434 else: - 1435 raise ValueError "Unsupported type for search", e 1436 return {k: v for k, v in results 0 .items if all k in db for db in results } ValueError: 'Unsupported type for search', 'squeeze' from kdrag.all import from kdrag.theories.real import from kdrag.theories.real.rset import n = Int "n" in = Const "I", ArraySort IntSort ,RSet a,b = Consts "a b", RSeq x,y = Reals "x y" @PTheorem ForAll a, b , nested I , ForAll n, n = 0, a n <= b n , Exists x, iinter I x def nonempty iinter icc of nested l : a, b = l.fixes l.intros Ignore negative indices, just as nested and iinter do. lower = Lambda x, Exists n, n = 0, a n == x bounds = l.have ForAll m, m = 0, is ub lower, b m j = l.fix l.intro l.unfold is ub point = l.fix l.beta member = l.intro k = l.obtain member l.auto by= nested icc bounds a, b, k, j The lower endpoints form a nonempty set bounded by b 0 . l.have lower a 0 , by= l.have Exists x, lower x , by= l.specialize bounds, 0, keep=True l.have bdd above lower , by= bdd above.defn lower supremum = l.have Exists u, is lub lower, u , by= exists is lub of bdd above lower s = l.obtain supremum l.exists s l.unfold iinter l.beta j = l.fix l.intro l.specialize bounds, j Every a j is below the supremum, and every b j is above it. l.have lower a j , by= l.have is ub lower, s , by= is ub of is lub lower, s l.have a j <= s, by= le of mem of is ub lower, a j , s l.have s <= b j , by= le of is lub of is ub lower, s, b j l.auto by= icc.defn a j , b j search bdd above is lub bdd above icc n = Int "n" in = Const "I", ArraySort IntSort ,RSet a,b = Consts "a b", RSeq x,y = Reals "x y" def I def I n : return icc a n b n @Theorem ForAll x,y , is ub icc x,y , y def is ub icc l : x,y = l.fixes l.unfold is ub, icc l.auto @Theorem ForAll x,y , is lb icc x,y , x def is lb icc l : x,y = l.fixes l.unfold is lb, icc l.auto @Theorem ForAll x,y , x <= y, is lub icc x,y , y def t l : x,y = l.fixes l.unfold is lub l.intro l.split l.auto by= is ub icc x,y l.unfold is ub, icc l.auto I = Lambda n, icc a n , b n @PTheorem ForAll a,b , ForAll n, n = 0, I n = I n+1 , ForAll n, n = 0, Exists x, I n x , Exists x, iinter I x def t l : a,b = l.fixes dec, nonemp = l.intros A = Lambda x, Exists n, a n == x l.have is ub A, b 0 l.unfold is ub l.fix A a 0 pretty expr is lub.defn.thm '∀A : ℝ → Bool, u : ℝ,\n RSet.is lub A, u = RSet.is ub A, u ∧ ∀v : ℝ, RSet.is ub A, v → u ≤ v ' Next Goal: a₀ b₀ : ℤ → ℝ 0: ∀n : ℤ, n ≥ 0 → RSet.icc a₀ n + 1 , b₀ n + 1 ⊆ RSet.icc a₀ n , b₀ n 1: ∀n : ℤ, n ≥ 0 → ∃x : ℝ, RSet.icc a₀ n , b₀ n x ────────────────────────────────────────────────────────────────────────── ⊢ ∀x : ℝ, λx′1 : ℝ, ∃n : ℤ, a₀ n = x′1 x → x ≤ b₀ 0 iinter I RSet.iinter λn : RSet.icc a n , b n class Function: decl : FuncDeclRef defn : Proof | None pointwise : bool = True set lift : bool = True def call self, args, kwargs - Any: ... automatic lifting over set arguments or pointwise application although we could do it via conversion of Int = Set Int as singleton set... python def indrel name, args,body : assert body.sort == BoolSort sorts = x.sort for x in args f = Function name, x.sort for x in args , BoolSort defn = axiom ForAll args, body, f args f.defn = defn Allow implies defns? The other direction requires proof work. An "invalid" doesn't define a unique fixed point. How often is the other direction important though? I guess for constructing an instance? R = FreshConst ArraySort sorts, BoolSort prefix="R" smt.substittue body, R,R ind = ForAll R , ForAll args, Implies R args , body , f <= R least return defn, ind insists defining something boolean rel <= body and rel minimal sort = DecalreSort "Sort" item = DeclareSort "Item" Term? Element? Expr? Int, Real, Bool = Consts "Int Real Bool" Arr = Function "Arr", sort, sort, sort has type = Function "has type", item, sort, Bool from int = Function "from int", Int, item from real = Function "from real", Real, item from bool = Function "from bool", Bool, item has type from int = axiom ForAll n , has type from int n , Int axiom ForAll r , has type from real r , Real axiom ForAll b , has type from bool b , Bool def to item x: ExprRef - item: if x.sort == Int: return from int x if x.sort == Real: return from real x if x.sort == Bool: return from bool x def synth x - tuple ExprRef, Proof def check x, T : ExprRef - Proof | None: decl = x.decl if decl == from int: has type from int x.arg 0 ... constants = { } synth = { } check = { } --------------------------------------------------------------------------- NameError Traceback most recent call last Cell In 10 , line 1 ---- 1 sort = DecalreSort "Sort" 2 item = DeclareSort "Item" 3 4 Int, Real, Bool = Consts "Int Real Bool" NameError: name 'DecalreSort' is not defined class App: f : FuncDeclRef | ExprRef | object args : list class Partial type Term = App | Emb class Term: ctx : f : class Emb: e : ExprRef from kdrag.all import Z f = Const "f",Z Z n = Const "n", Z fact spec = Exists f, ForAll n, f n == If n = 0, 1, n f n-1 print pretty expr fact spec fact spec ∃f : ℤ → ℤ, ∀n : ℤ, f n = if n ≥ 0 then 1 else n f n - 1 ∃f : ∀n : f n = If n ≥ 0, 1, n·f n - 1 python import kdrag as kd from kdrag.smt import R = RealSort RSet = SetSort R RSetSeq = ArraySort IntSort , RSet RSetSet = SetSort RSet S, T, U = Consts "S T U", RSet F = Const "F", RSetSeq A = Const "A", RSetSet a, b, x, y, r, eps, u, v = Reals "a b x y r eps u v" i, n = Ints "i n" empty = EmptySet R univ = FullSet R Nonnegative integer indices stand in for ℕ. iunion = kd.define "RSet.iunion", F, Lambda x, Exists i, i = 0, F i x The Kernel crashed while executing code in the current cell or a previous cell. Please review the code in the cell s to identify a possible cause of the failure. Click