Skip to content

markblokpoel/mathlib-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MATHLIB logo

mathlib Scala version support license Website Maven Central Scaladoc Contributor Covenant

mathlib is a library for Scala supporting functional programming that resembles mathematical expressions such as set theory, graph theory and probability theory. This library was developed to complement the theory development method outlined in the open education book Theoretical modeling for cognitive science and psychology by Blokpoel and van Rooij (2021).

The goal of this library is to facilitate users to implement simulations of their formal theories. mathlib and Scala code is:

  • 👓 easy to read, because mathlib syntax closely resembles mathematical notation
  • ✅ easy to verify, by proving that the code exactly implements the theoretical model (or not)
  • ❤️ easy to sustain, older versions of Scala and mathlib can easily be run on newer machines

The mathlib library github page is https://github.com/markblokpoel/mathlib and the companion website can be found at https://www.markblokpoel.com/mathlib.

Contents

Running these notebooks

We document two options to run the examples and tutorial: the mybinder service and a local installation on your computer.

Free mybinder service

You can create an interactive Jupyter lab instance of this repository for free on mybinder.org by clicking Binder. Please note that this service might at times be slow.

Installation instructions

If you want to install Jupyter lab with Scala support on your own machine, you can follow the instructions below. Please note that some instructions will vary for different operating systems (e.g., Windows, macOS or Linux). We assume you have installation rights on your machine and are familiar with the Terminal (macOS and Linux) or Powershell (Windows).

Step 1

First check if you already have Python 3 installed on your machine. Open up a Terminal or Powershell and run the following command.

python3 --version

You should see the version of Python as output, if not then go to https://www.python.org/downloads/ and download and install the latest version of Python 3.

You will also need pip to install Jupyter. Check if you have it installed with:

pip --version

pip should come by default with the official Python release. If you have installed Python in a different way, please refer to your installation method to also install pip.

Step 2

Install Jupyter Lab following by running the following command in a terminal (macOS and Linux) or the Powershell (Windows).

pip install jupyterlab

Note: If you are using a macOS version that comes with Python 2, run pip3 instead of pip.

Test the if the installation is working properly by running this command and check if you get some output.

jupyter --version

Step 3

Install the Almond kernel version 0.13.1 with Scala 2.13.8 support (so you can use Scala in Jupyter). The versions are important! For the original instructions see https://almond.sh/docs/quick-start-install.

First, install a Java Virtual Machine (JVM) needs to on your system. You can check if a JVM is installed by running from a Terminal or Powershell.

java -version

It should output something like this:

java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

If you don't have a JVM yet, we recommend installing AdoptOpenJDK (https://adoptopenjdk.net/) version 8.

Then, the Almond kernel can (for macOS and Linux users) be fetched and installed with coursier:

curl -Lo coursier https://git.io/coursier-cli

chmod +x coursier

./coursier launch --fork almond:0.13.1 --scala 2.13.8 -- --install

rm -f coursier

If you receive the error: "Cannot find default main class. Specify one with -M or --main-class", run this command instead:

./coursier launch --fork almond:0.13.1 --scala 2.13.8  -M almond.ScalaKernel -- --install

If you use a Windows OS, use these lines of code instead

bitsadmin /transfer downloadCoursierCli https://git.io/coursier-cli "%cd%\coursier"

bitsadmin /transfer downloadCoursierBat https://git.io/coursier-bat "%cd%\coursier.bat"

.\coursier launch --fork almond:0.13.1 --scala 2.13.8 -- --install

Step 4

You can check that you have the kernel correctly installed by entering the following command. It should list Scala and a Python 3 version.

jupyter kernelspec list

Step 5 (Optional)

If you want to enable Plotly support for displaying graphs you need to install the Jupyterlab extension using the following Terminal command.

jupyter labextension install jupyterlab-plotly

You can check if the extension installed correctly using this command.

jupyter labextension list

Step 6

Finally, download a copy of the repository from the releases page and unpack the files. Then navigate to the folder that contains the Scala notebook(s) and run:

jupyter lab

Licenses

  • Scala is licensed under the Apache License, Version 2.0 (the “License”).
  • Almond is Copyright 2018 Alexandre Archambault.
  • Plotly-scala is Liscenced under the LGPL v3 license.
  • Plotly.js is free and open-source software, licensed under the MIT license.
  • JupyterLab uses a shared copyright model that enables all contributors to maintain the copyright on their contributions. All code is licensed under the terms of the revised BSD license.

About

This repository contains examples for the mathlib library.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages