Re: [isabelle] Embedded languages in Isabelle



On 03/10/2019 17:29, Daniel Kirchner wrote:
> 
> To say a bit more about my application: I'm constructing a shallow semantic 
> embedding of a philosophical logic (Edward Zalta's "Theory of Abstract 
> Objects"). That logic is quite different from HOL in multiple ways, which makes 
> this an interesting research project. For example the language contains two 
> kinds of atomic formulas, i.e. Fxy "x and y 'exemplify' F" and xyF "x and y 
> 'encode' F", neither of which can be implemented as mere function application 
> in an embedding in HOL. The variable names have type implications, e.g. x and 
> y have a different type than F and G, which again have a different type from 
> e.g. \kappa, etc. - some of these types map directly to types in HOL, others I 
> need to implement with guarding behind additional constants, etc.

Thanks for the general application outline -- it is always important to
keep the big picture in mind. A language that is very different from the
Isabelle/Pure lambda calculus (which is reused in the Isabelle/HOL
library) definitely poses a challenge. It will require very careful
exploration to do just the right thing, otherwise it will lead to an
unmaintainable blob of "code" that nobody can understand nor maintain.


> The target logic itself also defines new symbols in terms of its basic symbols, 
> so the implementation should be extensible very much like with mixfix 
> annotations to constants or "syntax" commands. That's why I'm trying to avoid 
> duplicating an implementation of a priority grammar. (The definitions in the 
> target logic themselves are not quite the same as Isar definitions, so I will 
> probably introduce new outer syntax commands for them, but in the end they 
> will translate to "plain", but more complex definitions satisfying the narrowly 
> defined inferential role of definitions in the hyper-intensional free logic of 
> the target system).

Note that there are different levels of complexity rolled into Isabelle
term notation. A command like 'notation' with plain mixfix is relatively
close to the priority grammer: if you subtract special things like
'binder' from the mixfix syntax, it is even simpler. In contrast,
'syntax' + 'translations' (or 'parse_translation' etc.) opens a not so
clearly defined space of adhoc syntax additions. If your own language
does not require that, it would greatly simplify a standalone
implementation of it (one that is independent of the Isabelle "syntax
phases").


> At the moment I'm trying to only *parse* the actual syntax of the language, 
> not to print it, i.e. a formula given in the syntax of the target logic, will 
> be translated to its representation in Isabelle's term logic and further 
> reasoning will be done in Isabelle's term logic directly (I think this should 
> alleviate the problem of transformed names like x_ and xa, but at a later 
> stage it might also be interesting to go further and print in the target 
> logic's syntax and continue reasoning in it as well, for which this indeed 
> will be an issue).

BTW, printing also means document output of the sources in HTML or
LaTeX. There is an implicit assumption that adjacent letters for one
word, not individual identifiers. Compare this with LaTeX typesetting of
$abc$ vs. \emph{abc}. Presently, there is no proper way in the document
preparation system to change the typesetting of names, but it is
conceivable that a future notion of antiquotations within terms could
also go through document presentation.


> I'm now trying to mainly stay within the Isabelle term language itself. 
> Interestingly, only now after looking through the syntax parsing ML code I 
> realize that I can do much more than I thought within its boundaries.
> 
> Simplified that approach will look like
> 
> consts valid :: "p => bool"
> consts emb_implies :: "p => p => p"
> nonterminal q
> syntax valid :: "q => bool" ("[\Turnstile _]")
>              emb_implies "q => q => q" (infixl "->" 8)
>              emb_not "q => q" ("\<not>_" [40] 70)
>              "_atomic_formula" :: "id_position => q" ("_")
> etc.
> 
> and then installing a parse_ast_translation for "_atomic_formula" which splits 
> up e.g. "Fxy" to "(_exe F x y)" and "xyF" to "(_enc x y F)", which is then 
> translated to the corresponding term in a parse_translation.

This looks much better to me. It deescalates the overall complexity of
the implementation by some orders of magnitude.

Apart from id_position you can also experiment with cartouches for
certain well-defined sub-languages.


> In general in the long run it would, of course, be nice to have a self-
> contained "reentrant" and "public" version of the parser for Isabelle's term 
> language in ML, in which every aspect could be customized, including the 
> lexicon and tokenizing and maybe even the generation of "fresh" variable 
> names, etc. - but I realize that this is way too much to ask especially for my 
> very specific and probably rather exotic use case :-).

This sounds a bit like marketing talk for "software frameworks". Such
software components don't exist, and where people have tried it its has
lead to maintenance nightmares.

The inner syntax implementation of Isabelle/Pure is the opposite of
that. It has many special tricks based on the particular situation to
make it just work by accident. I have reworked the architecture and
implementation many times in the past 25 years. A few more reforms of it
are still in the pipeline, e.g. subterm PIDE markup as seen in the tiny
rail example.

Such reforms naturally break bad applications of it -- or the other way
round: bad applications prevent further reforms.


	Makarius

Attachment: signature.asc
Description: OpenPGP digital signature



This archive was generated by a fusion of Pipermail (Mailman edition) and MHonArc.