Leibniz in Pharo

Ayush Anand
5 min readApr 28, 2019

--

In my previous two articles I’ve explained what Leibniz is and how it works.We now go to the Pharo implementation of Leibniz.

The image below is how the Pharo implementation looks like currently, with subpackages like Rules,Assets and Contexts need to be created from scratch.I need to create each one of them and attach them to the Contexts subpackage for an overall implementation of Leibniz.These packages are what I intend to create and add to the Leibniz package. There has to be methods and subpackages that allow Parsing and visualization. The user must be able to play around with the models they read. This will give it feature parity with the Racket-Leibniz. I’ve explained how to install the package and how it works below.

Installation

To install the package in Pharo 7, run the following lines in the Pharo playground:

Metacello new
baseline: 'Leibniz';
repository: 'github://khinsen/leibniz-pharo/src';
load.

Leibniz makes generous use of Unicode glyphs that are not contained in the default fonts used by the standard Pharo images. The following code can be run if you have “Arial Unicode MS Regular 10” and “DejaVu Sans Mono Regular 10” on your system.

FreeTypeFontProvider current updateFromSystem.

StandardFonts defaultFont:
(LogicalFont
familyName: 'Arial Unicode MS'
pointSize: 10).

StandardFonts codeFont:
(LogicalFont
familyName: 'DejaVu Sans Mono'
pointSize: 10).

StandardFonts listFont:
(LogicalFont
familyName: 'Arial Unicode MS'
pointSize: 10).

StandardFonts menuFont:
(LogicalFont
familyName: 'Arial Unicode MS'
pointSize: 10).

StandardFonts buttonFont:
(LogicalFont
familyName: 'Arial Unicode MS'
pointSize: 10).

StandardFonts windowTitleFont:
(LogicalFont
familyName: 'Arial Unicode MS'
pointSize: 11).

StandardFonts balloonFont:
(LogicalFont
familyName: 'Arial Unicode MS'
pointSize: 9).

StandardFonts haloFont:
(LogicalFont
familyName: 'Arial Unicode MS'
pointSize: 9).

Package Overview

I’ve explained each of the layers below in a comprehensive manner.

Document Layer — This is the layer where the documents in Pillar are parsed .The document layer then sends the contexts which represent the scientific model further down to the context layer. It is in the document layer where we use the XML tree and extract the contexts mentioned in the XML page and send them to be built and created.

The document layer also consists of the LeibnizBuiltins which has the builtin contexts like integers,rational numbers,strings etc. These are some of the contexts used by most models that’ll be implemented by users.

Context Layer — This is where the parts of the context are broken down further into its different constituent parts.The subpackages contained here perform the reading of the XML tree. They detect the different aspects like vals,op etc and pass it on to their own subpackages i.e SortGraphs for sorts.

Here my task would be to add values for rules,terms,evalterms and other aspects. Complete the subpackages with basic skeletons. The first objective here is to identify these components and create it in the corresponding packages from the subpackages below. Currently these are the ones that exist.

Each one has methods to add ops,vars,sorts etc. I will implement the ones for rules,terms and assets. Each one will be declared later and I’ll shed more light on the procedure once the work gets started.

Terms — This subpackage contains a concise definition of the values and quantities existing in a context. This can even be relations existing between values in an context. The terminology of these terms define a scientific model and make them more readable and usable.

Each term has its own Sort which is shown in the package sortgraphs.

The sort is figured it with connections to the Signatures subpackage. From there each term is given its own sort.Like an integer term used in a scientific model can be traced back to having an integer sort.

Signatures — The collection of all the operators in various contexts are called signatures. This is a big help to observe scientific models as shown below. Each of the operator below has a separate sorts and the way they work. These can be visualized from the inspector in the way the graphs look in two different ways. This hasn’t been implemented anywhere in other languages. I’ve attached images of how amazing the visualization is for operations in the boolean sort.

The operators for boolean context

Below I’ve attached the multiplication operator in Real numbers seen using tree view.

Tree view of the multiplication op

The image below is Network view of the same operator.

Network view

Two different kind of visualizations with in depth understanding of how each layer works is the strength Pharo.

SortGraphs — The subpackage Sortgraphs is used to store categories and sets of values. As explained in Leibniz-Racket implementation sorts are used to describe quantities like mass,integers. Their relationship is represented by Sortgraph. All these features are represented in the inspector tab with graphs using Roassal2 .

How the sorts are represented

The remaining three subpackages are rules,terms and assets.This is where my work begins. A bare skeleton exists requiring connections and methods implemented. My fourth article in the series will focus on the work and how I go forward to implement these subpackages and complete the package.

Conclusion

There’s an aura of mystery around what a scientific model actually does and how the computer makes it work. Pharo is the perfect language to remove this as the Pharo community has always reduced the difference between the developer and user. The freedom that this language gives is very freeing as any of the components in the code base can be changed and manipulated.

The project if selected starts on May 6 after which I’ll post weekly updates on how I go about my project and how to improve upon it further.

--

--