Zulip Chat Archive

Stream: general

Topic: Lean Oscar Interface


Cedric Holle (May 22 2024 at 16:35):

I am working on interfacing Lean and Oscar. You can find code at my repo. I would love to get some comments and feedback.

Currently working:

proving that a permutation is in the closure of some permutation

proving some equalities in presented groups/proving that a presented group is trivial

and some more small stuff.

The later is not well tested. I am happy that it works.
It's my master's thesis. Text will follow within a month.
@Laurent Bartholdi

Henrik Böving (May 22 2024 at 16:38):

How does this work in proofs? Are you getting a proof certificate from Oscar and converting that into a proper Lean proof? Are there additional axioms involved that assume the correctness of (parts of) Oscar?

Cedric Holle (May 22 2024 at 16:41):

Henrik Böving said:

How does this work in proofs? Are you getting a proof certificate from Oscar and converting that into a proper Lean proof? Are there additional axioms involved that assume the correctness of (parts of) Oscar?

I am getting a proof certificate in Oscar and using it to build a proof in Lean. No additional axioms.

Henrik Böving (May 22 2024 at 16:42):

That's awesome! Is this limited to a certain fragment of what Oscar can do or is your proof recovery procedure complete with respect to everything that Oscar might output?

Cedric Holle (May 22 2024 at 16:45):

It's using Oscar's serialization to send data forth and back. So we are limited to data types for which it is implemented in Oscar and for which I have implemented the same in Lean.

Miguel Marco (May 22 2024 at 22:02):

Very nice!

How does the communication Lean<-> Oscar work?

Kim Morrison (May 22 2024 at 22:38):

(It took me a moment to find the Oscar homepage: https://www.oscar-system.org/)

Patrick Massot (May 22 2024 at 22:58):

Thanks Kim, I did not have the patience to search for it.

Patrick Massot (May 22 2024 at 22:58):

The presentation of the project goal sounds awfully similar to Sage. Why did they start something else?

Mario Carneiro (May 22 2024 at 23:09):

probably because julia is obviously the right language to be writing a CAS in

Utensil Song (May 23 2024 at 00:29):

It's really nice to see Lean interfacing a Julia CAS!

My understanding is that Julia aims to be a modern Fortran (which still is the language for fast math routines that C calls) that CAS made by it could replace the slow Python based symbolic calculation ecosystem with much better type and abstraction support.

As a maintainer of a SymPy based symbolic package, Julia was my dream language before Rust and Lean, unfortunately Rust has less support for rich operators and symbolic calculation except for egg, and Lean has its emphasis on theorem proving and it's still at a prototype stage interfacing with existing CAS systems.

Julia based Oscar has one more potential advantage, to be interfaced via FFI and have performance gain, over other IO based CAS interfacing. Maybe it could be a better choice over C++ library GiNaC, thanks to its matched performance and previous work on proof generation.

Cedric Holle (May 23 2024 at 00:34):

Miguel Marco said:

Very nice!

How does the communication Lean<-> Oscar work?

Start a julia file as a child with a lean command/tactic. The julia file is then a simple while true loop waiting for a command. I use Std.Tactic.Cache for the definition of the child to make it possible to access the child multiple times in a file.
The Code can be found in Mrdi/Server.lean and Mrdi/server.jl.
Does this answer your question? It is so general that I'm not sure what exactly to elaborate on.

Andrés Goens (May 23 2024 at 05:56):

this is really cool! I'm confused that Oscar gives you proof certificates! I thought especially for group theory like in your examples, Oscar itself would be just calling GAP under the hood? does oscar build the proofs on its own on top of the gap computation, or how does that work?

Andrés Goens (May 23 2024 at 05:56):

CC @Siddharth Bhat

Utensil Song (May 23 2024 at 07:57):

Judging from the code, Lean-Oscar mainly uses Oscar (so far, mostly GAP behind it) to construct complex objects then convert them to Lean for definitions, as for theorems, Oscar seems to be helpful to generate intermediate goals, and the proof recontruction is still done in Lean, with tactics and some heuristics around the intermediate goals.

Laurent Bartholdi (May 23 2024 at 09:49):

Chiming in: e.g. Julia contains Oscar which delegates to GAP which
delegates to KBMAG (Knuth-Bendix) which quickly and cleverly produces new
rules in a rewriting system. Asking it to print a trace of the new rules
that it produced, and how it obtained them ("exploit the overlap of rule #i
with rule #j") makes it possible to replicate the operation in Lean. There
would still be work to do to have, e.g., KBMAG only print the new rules
that were actually used. In principle there could be an arbitrarily large
number of going-nowhere explorations done by KBMAG, but a very small number
of useful ones which are the only one needed in a certificate to be checked
by Lean.

Cedric Holle (May 23 2024 at 14:28):

If I would have managed to let KBMAG also print which rules were used, the reconstruction in Lean would be much more simple and less compute heavy. But this isn't gonna happen in time.

Cedric Holle (May 23 2024 at 14:28):

We were looking for more complex examples beyond just finding a witness. Additionally, I had a lot more fun with the challenging problems. If you want to see a simpler example, take a look at

matrix_inverse

Miguel Marco (May 23 2024 at 20:05):

Cedric Holle said:

Does this answer your question? It is so general that I'm not sure what exactly to elaborate on.

Mostly yes. So it sounds like a trick that could be easily generalized to other CAS systems, right?

I am thinking mostly on having a version of polyrith that relies on a local install of a CAS instead of an online service.

Cedric Holle (May 23 2024 at 20:29):

Miguel Marco said:

Cedric Holle said:

Does this answer your question? It is so general that I'm not sure what exactly to elaborate on.

Mostly yes. So it sounds like a trick that could be easily generalized to other CAS systems, right?

I am thinking mostly on having a version of polyrith that relies on a local install of a CAS instead of an online service.

Should work.
I like the way it is handled in polyrith. It skips all the setup problems for the user.

Utensil Song (May 24 2024 at 08:56):

Miguel Marco said:

I am thinking mostly on having a version of polyrith that relies on a local install of a CAS instead of an online service.

Yes, IMHO, a mature practice of interfacing CAS should probably be able to (modulos the cache invalidation stuff):

  1. use a cached result if available
  2. use bundled FFI if available
  3. use the local CAS if available
  4. if steps above fail, and the online option is off or not set, fail the tactic with hint for users to opt-in to rely on an online service, or a guide to set up a local CAS
  5. if the online option is on, use the online service, and cache the result.

Relying on a Python installation and a package requests that might not be installed properly and an online service that might not be accessible or stable silently is not really how it should be in the long run.

But this is a little off-topic, and was discussed here, and people clearly have different preferences on this.


Last updated: May 02 2025 at 03:31 UTC