From brianh at cs.pdx.edu Thu Apr 14 22:40:53 2011 From: brianh at cs.pdx.edu (Brian Huffman) Date: Thu, 14 Apr 2011 15:40:53 -0700 Subject: [opentheory-users] importer for Isabelle Message-ID: Hello, I now have a working OpenTheory importer for Isabelle (tested with Isabelle2011). The code is still kind of a mess, with a bunch of extra debugging code sitting around, so I'll wait until I've cleaned it up a bit before I share it. There are still a few improvements that need to be made, but I think I have all the major bugs fixed now: It can successfully import the parser-1.5 library (reading the article file generated by "opentheory info --article parser-1.5"). The implementation adds three new tables to Isabelle's Theory_Data: 1) A set of theorems; there must be an entry here that matches each "axiom" command. 2) A mapping of type names; there must be a matching entry for each "typeOp" command. 3) A mapping of constant names; there must be a matching entry for each "const" command. The set of theorems is extended using the [opentheory] attribute, like this: lemma [opentheory]: "ALL m::nat. m + 0 = m" by simp (I have lots of these kinds of proofs for natural numbers and booleans.) The importer also adds new theorems to the set whenever it processes a "thm" command. The complete list of theorems can be accessed using the name "opentheory", which is one of those new dynamic theorem references in Isabelle; it can be used in proof scripts or anywhere just like any other theorem name. The other tables are extended using "setup" commands with "add_tyop" and "add_const" ML functions, like this: setup {* fold OpenTheory.add_tyop [("->", @{type_name "fun"}), ("bool", @{type_name "bool"}), ("Number.Natural.natural", @{type_name "nat"}), ("Data.Pair.*", @{type_name "prod"})] *} setup {* fold OpenTheory.add_const [("=", @{const_name "HOL.eq"}), ("Data.Bool.!", @{const_name "All"}), ("Data.Bool.==>", @{const_name "HOL.implies"}), ("Data.Bool.\\\\/", @{const_name "HOL.disj"}), ("Data.Bool./\\\\", @{const_name "HOL.conj"}), ("Data.Bool.cond", @{const_name "If"}), ("Data.Bool.select", @{const_name "Eps"})] *} The importer should also extend these tables whenever it defines a new constant or type, but I haven't implemented this yet. Another nice feature would be a way for users to influence how the importer chooses names for newly-defined constants and types. Right now it takes the names directly from the strings in the article file, which isn't so nice for names like "HOLLight._dest_rec" (Isabelle's parser can't handle names that start with underscores). Once I clean up the code, I'm not sure what I should do with it... I suppose I could add it to the Isabelle repo, but I'm not sure if I want to advertise to Munich crowd that I've been doing all this work that is unrelated to finishing my thesis :) - Brian From joe at gilith.com Fri Apr 15 02:03:26 2011 From: joe at gilith.com (Joe Hurd) Date: Thu, 14 Apr 2011 19:03:26 -0700 Subject: [opentheory-users] importer for Isabelle In-Reply-To: References: Message-ID: Hi Brian, That is really great work! Am I right in thinking you can import the parser-1.5 article binding all the input symbols and axioms to existing ones in Isabelle? I would have guessed that Isabelle type classes would have managed to get in the way at some point, but perhaps this would only be for converting Isabelle proofs to OpenTheory format? > The set of theorems is extended using the [opentheory] attribute, like this: > > lemma [opentheory]: "ALL m::nat. m + 0 = m" > by simp > > (I have lots of these kinds of proofs for natural numbers and booleans.) > > The importer also adds new theorems to the set whenever it processes a > "thm" command. The complete list of theorems can be accessed using the > name "opentheory", which is one of those new dynamic theorem > references in Isabelle; it can be used in proof scripts or anywhere > just like any other theorem name. The [opentheory] attribute looks like a great scheme that could perhaps be used in the HOL family of theorem provers to import OpenTheory proofs. You mentioned that you prove a lot of theorems that the OpenTheory article relies on, but it seems you could reduce this by processing a set of OpenTheory packages that don't make any definitions. When I was designing the standard theory library I tried to isolate packages that made definitions and have them export just a minimal theorem interface - most of the theorems are proved in packages that make no definitions and so can be safely run to populate the [opentheory] set of theorems. > The importer should also extend these tables whenever it defines a new > constant or type, but I haven't implemented this yet. Another nice > feature would be a way for users to influence how the importer chooses > names for newly-defined constants and types. Right now it takes the > names directly from the strings in the article file, which isn't so > nice for names like "HOLLight._dest_rec" (Isabelle's parser can't > handle names that start with underscores). You should find that constants and type operators with names like this are never exported from a theory (i.e., never appear in exported theorems), so it's perfectly safe to normalize their names to something more acceptable to Isabelle. They are `local definitions' that are used only in proofs. > Once I clean up the code, I'm not sure what I should do with it... I > suppose I could add it to the Isabelle repo, but I'm not sure if I > want to advertise to Munich crowd that I've been doing all this work > that is unrelated to finishing my thesis :) I would very much like to see it live on in some fashion - my hope is that more and more theories will be converted to OpenTheory packages, and your code could be used to import them into Isabelle in a principled way. Thanks for having a go at this - I never thought you'd crank it out so quickly. Cheers, Joe From brianh at cs.pdx.edu Fri Apr 15 16:34:39 2011 From: brianh at cs.pdx.edu (Brian Huffman) Date: Fri, 15 Apr 2011 09:34:39 -0700 Subject: [opentheory-users] importer for Isabelle In-Reply-To: References: Message-ID: On Thu, Apr 14, 2011 at 7:03 PM, Joe Hurd wrote: > Hi Brian, > > That is really great work! Am I right in thinking you can import the > parser-1.5 article binding all the input symbols and axioms to > existing ones in Isabelle? I would have guessed that Isabelle type > classes would have managed to get in the way at some point, but > perhaps this would only be for converting Isabelle proofs to > OpenTheory format? Yes, each of the input constants of the article is mapped to a pre-existing Isabelle constant. Some of these existing Isabelle constants happen to be overloaded, but that doesn't cause any problems. This mapping of constant names does not even need to be one-to-one; for example, I imagine that "Number.Natural.+" and "Number.Integer.+" would map to the same overloaded "plus" constant in Isabelle. Of course, exporting proofs from Isabelle is a completely different story. > You mentioned that you prove a lot of theorems that the OpenTheory > article relies on, but it seems you could reduce this by processing a > set of OpenTheory packages that don't make any definitions. When I was > designing the standard theory library I tried to isolate packages that > made definitions and have them export just a minimal theorem interface > - most of the theorems are proved in packages that make no definitions > and so can be safely run to populate the [opentheory] set of theorems. Your idea of keeping definitions in separate, minimal modules is a good design. I'm sure I could have greatly reduced the number of [opentheory] lemmas that I needed by finding the right additional article files to import; I was just too lazy to figure out how the packages were organized. >> The importer should also extend these tables whenever it defines a new >> constant or type, but I haven't implemented this yet. Another nice >> feature would be a way for users to influence how the importer chooses >> names for newly-defined constants and types. Right now it takes the >> names directly from the strings in the article file, which isn't so >> nice for names like "HOLLight._dest_rec" (Isabelle's parser can't >> handle names that start with underscores). > > You should find that constants and type operators with names like this > are never exported from a theory (i.e., never appear in exported > theorems), so it's perfectly safe to normalize their names to > something more acceptable to Isabelle. They are `local definitions' > that are used only in proofs. Actually, it seems like it would be safe to rename *any* constant (whether exported or not) to any name that I want in Isabelle, as long as the importer keeps track of the name mapping so that later imports can use the same names. I suppose I should write an "import_name" function that converts from OpenTheory names to Isabelle-friendly ones. It would be nice to parameterize this by a list of user-specified exceptions to the mapping, so you could say something like, "import this article, but when you define constant 'foo', call it 'bar' instead." >> Once I clean up the code, I'm not sure what I should do with it... I >> suppose I could add it to the Isabelle repo, but I'm not sure if I >> want to advertise to Munich crowd that I've been doing all this work >> that is unrelated to finishing my thesis :) > > I would very much like to see it live on in some fashion - my hope is > that more and more theories will be converted to OpenTheory packages, > and your code could be used to import them into Isabelle in a > principled way. I suppose I'll add it to the Isabelle distribution at some point, maybe after I finish writing my thesis. In the meantime, I guess I can post the code to the list, so it will be archived and people can try it out. - Brian