The Scala-REPL + MMT as a lightweight mathematical user interface

Scala is a general purpose programming language that includes a read-eval-print loop (REPL). Mmt is a general representation language for formal mathematical knowledge implemented in Scala. Independent recent developments permit combining them into an extremely simple user interface that can act as a nucleus for a variety of systems. Firstly, Scala introduced string interpolation – a convenient syntax that permits escaping back and forth between strings and arbitrary Scala expressions (while preserving type safety). Secondly, Mmt introduced a notation-based text syntax and a rule-based evaluation engine for its mathematical objects (which are based on OpenMath). Combining these, users can enter and work with Mmt objects in the Scala-REPL with so little overhead that it essentially behaves like a dedicated Mmt-REPL – except for also providing the full power of Scala. Implicit conversions (e.g., between integers represented in Mmt and Scala integers) further blur the distinction between metaand object language. Mmt is highly extensible: Users can add new type systems and logics as well as new theories and notations and evaluation rules. Thus, we obtain a REPL-style interface for any language represented in Mmt with essentially no effort. 1 Representing Languages in MMT Mmt [RK13] is a generic, formal module system for mathematical knowledge and is a basis for foundation-independent knowledge representation. The Mmt language is designed to be applicable to a large collection of declarative formal base languages and all Mmt notions are fully abstract in the choice of the base language. Therefore, Mmt focuses on foundation-independence, scalability and modularity. Every Mmt declaration is identified by a canonical, globally unique URI. Mmt symbol declarations subsume most semantically relevant statements in declarative mathematical languages including function and predicate symbols, type and universe symbols, and — using the Curry-Howard correspondence — axioms, theorems, and inference rules. Their syntax and semantics is determined by the foundation, in which Mmt is parametric. The Mmt API [Rab13] is a Scala-based [OSV07] open source implementation of the Mmt language and of a number of knowledge management services for it. Declaring Symbols A theory declaration T = {Sym∗} introduces a theory with name T containing a list of symbol declarations. A symbol declaration c : ω = ω′ # ν introduces a symbol named c with type ω, definiens ω′ and notation ν (all of which are optional). Terms ω over a theory T are formed from symbols OMS(T? c) declared in T , bound variables OMV(x), applications OMA(ω, ω1, . . . , ωn) of a function ω to a sequence of arguments, bindings OMBIND(ω,X, ω′) using a binder ω, a bound variable context X, and a scope ω′ as well as integers OMI(i) and floats OMF(f) where i and f are integers and floats, respectively. This is a fragment of the OpenMath language [BCC04]. Remark 1. For readability we will write T? c instead of OMS(T? c) in the following. Furthermore, we will write c instead of T? c when the theory T is clear from the context. Example 1. Figure 1 shows an Mmt theory Lists, based on the logical framework LF [HHP93]. Lists declares natural numbers and lists as well as additional operations on them (plus for naturals and append for lists). Using the Mmt notation language, described below, we also declare the usual notations: infix + , :: and ::: for plus, cons, and append, respectively. theory Lists meta LF tp : type tm : tp → type # tm A1 nat : tp zero : tm nat # o succ : tm nat → tm nat # s A1 plus : tm nat → tm nat → tm nat # A1 + A2 list : tp → tm nat → tp # list A1 A2 nil : {A} tm list A zero cons : {A,N} tm A → tm list A N → tm list A (s N) # A3 :: A4 append : {A,M,N} tm list A M → tm list A M → tm list A (M + N) # A4 ::: A5 Fig. 1. Theory declaration in Mmt Remark 2. The theory Lists from Figure 1 has the theory LF as meta-theory which means that all symbols and notations declared in LF are available and can be used in Lists. Specifically, in Lists, we use the symbols for type, arrow (with notation A1 → A2), and the Pi binder (with notation { V1 } S2) all of which are declared in LF with the corresponding notations. Adding Notations Notations act as the parsing and printing rules that transform between abstract syntax and text-based concrete syntax (that supports