r/concatenative • • 13d ago

Using LEAN to prove your language

Wondering if anyone has used LEAN (or similar) to validate their stack language?

2 Upvotes

3 comments sorted by

1

u/Hypercubed 12d ago edited 12d ago

Inspired by https://bend-lang.com/ I think it would be very easy to generate LEAN proofs from stack effect comments in stack languages. Much easier than non-stack languages (applicative languages?).

Examples:

/* @effect a b c rot == c b a */
rot: bury swap ;

could generate:

def rotProg : List Tok := [Tok.swap, Tok.qpush, Tok.swap, Tok.qpull, Tok.swap]
theorem rot_effect (a b c : Int) :
    exec rotProg ((c) :: (b) :: (a) :: []) [] = some (((a) :: (b) :: (c) :: []), []) := by
  first | rfl | simp [exec, step] | (simp [exec, step]; omega)

(untested, LLM generated).

A more complex definition could define multiple @effects:

/* @effect n isqrt == r when 0 <= n where r^2 <= n ∧ n < (r+1)^2 */
/* @effect n isqrt == ERROR when n < 0 */

I haven't done anything like this but think it's a really interesting idea.

1

u/Hypercubed 8d ago

Is anyone interested in updates on this? I bascially had an AI agent build out a LEAN interpetor for my toy language (that I have been builind for something like 25 years); that was the easy part. The next step is proving that the stdandard library definitions do what I say that do. I'm having some trouble with this. I'm very interested in seeing if anyone else is doing anything similar.