2

I want to access Coq or Isabelle/HOL interactive theorem prover using my python program. Is there any python packages is available? Please suggest

Tom
  • 904
  • 1
  • 7
  • 21
  • 1
    Could you please clarify what you mean with "access" or "using"? Do you want to run Coq/Isabelle on a set of files? Do you want to create a new interface? Automatically prove things? – larsrh Nov 29 '17 at 14:33
  • 1
    I should add that it is possible to talk to Isabelle using any JVM language. If you're willing to use Jython to execute your Python programs, this could actually be made to work, I think. – larsrh Nov 29 '17 at 15:43
  • Sound interesting. If possible, can you provide few references? – Tom Nov 29 '17 at 15:52
  • I'll try to put together a small example. – larsrh Nov 29 '17 at 15:53
  • 1
    Related question https://stackoverflow.com/questions/46032067/how-to-call-proof-asistant-coq-from-external-software/46039814#46039814 [almost a duplicate] – ejgallego Nov 29 '17 at 16:11
  • 1
    cross-posted: https://www.quora.com/unanswered/What-is-the-best-way-to-interact-with-Coq-through-a-Python-API – Charlie Parker Feb 02 '19 at 22:00

2 Answers2

5

I am not expert on Isabelle but I believe the most common used interface is the Scala API used by the IDE, unfortunately, I can't tell more.

Regarding Coq, the standard way of interaction for quite a few years has been talking to the terminal REPL interface. That is not very convenient. You have a more recent IDE protocol, but however I don't recommend to invest on it heavily as it is gonna have a major revision soon, (hopefully improving it :))

A non-mature, but working alternative is SerAPI, [disclaimer I am the author] which offers a glimpse of what is it coming next in the protocol. Depending on what you would like to do, it could work. Unfortunately there is not Python binding as I couldn't figure out how to best do asynchronous programming, but help/PRs are welcome.

An last, you can of course use OCaml directly to talk to Coq from Python. Again, depending on your use cases it will fun or a very challenging endeavor.

ejgallego
  • 6,709
  • 1
  • 14
  • 29
  • If possible, can you provide any documentation related to SerAPI – Tom Nov 29 '17 at 15:53
  • There is some documentation on the project's web page, please open an issue there if you need more details. Also, if you search for `serapi` in this site some more information will come up. – ejgallego Nov 29 '17 at 16:10
4

This is a very rough draft of how to start an Isabelle instance and perform an RPC call from Python:

import $ivy.`info.hupel::libisabelle-setup:0.9.2`
import $ivy.`org.python:jython-standalone:2.7.1`

import javax.script.ScriptEngineManager

val python = """
  |from info.hupel.isabelle.api import Configuration, Version
  |from info.hupel.isabelle.japi import JResources, JSetup, JSystem, Operations
  |res = JResources.dumpIsabelleResources()
  |print res
  |config = Configuration.simple("Protocol")
  |print config
  |env = JSetup.makeEnvironment(JSetup.defaultSetup(Version.Stable("2016-1")), res)
  |print env
  |sys = JSystem.create(env, config)
  |print sys
  |response = sys.invoke(Operations.HELLO, "world")
  |print response
  |sys.dispose()""".stripMargin

new ScriptEngineManager().getEngineByName("python").eval(python)

This is wrapped in Scala code for the simple reason that this was the easiest way to get Jython working.

To execute the script above, save it as a file (e.g. isa.sc), download the Ammonite REPL for Scala, and run it like ammonite isa.sc. This should then take a while to do some setup and finally, something like this should appear:

info.hupel.isabelle.japi.JResources@59d0fac9
session Protocol
<Isabelle2016-1> at /home/lars/.local/share/libisabelle/setups/Isabelle2016-1
info.hupel.isabelle.japi.JSystem@138a952f
Hello world

This demonstrates very simple Isabelle bootstrapping from Python.

larsrh
  • 2,579
  • 8
  • 30