# Mathics and Nebo

Subtitle: Symbolic Mathematics and AI Handwriting Recognition

I’ve been playing around with a couple of fun math toys recently, Mathics and Nebo. Mathics is a free, open-source symbolic calculator. Nebo is a note-taking app for laptops, tablets, and smartphones with stylus inputs, and it can accept and understand mathematics. Nebo is free for the iPad, ($10 on Windows), and you can try Nebo here.

## # Mathics

The description of Mathics says,

Mathics is a free, open-source general-purpose computer algebra system featuring Mathematica®-compatible syntax and functions.

It relies on Python libraries, in particular, Sympy for symbolics, mpmath for arbitrary precision floating-point arithmetic, MathJax to render equations, and three.js and Asymptote to create graphics. Mathics isn’t as powerful as Mathematica, but the price is much better. Here’s a problem we can try in Mathics,

$x = i + \frac{1}{i + \frac{1}{i + \frac{1}{i + \ldots}}} \\$

Find $x$.

Notice that everything in the denominator of the first fraction is identical to $x$, so the equation can be rewritten as

$\begin{aligned} x &= i + \frac{1}{x} \\ x^2 & = ix + 1 \\ x^2 &- ix - 1 = 0 \end{aligned}$

Using the quadratic formula,

$x = \frac{i \pm \sqrt{i^2 - 4(-1)}}{2} = \frac{i \pm \sqrt{-1+4}}{2} = \frac{i \pm \sqrt{3}}{2}.$

In Mathics, the symbol for the imaginary unit $i = \sqrt{-1}$ is $I$, so to solve for $x$ type

followed by `Ctrl-Enter`

to get the solution. Hmmm. These solutions are correct, but not informative. The solution for $x$ has an $x$ in it.

The roots of a polynomial are the values of $x$ that make the polynomial zero, in this case, $x^2 - ix -1 = 0$. An $n^{th}-$degree polynomial will always have $n$ roots, even if some are complex (real + imaginary parts). Suppose the two roots to this polynomial are $r$ and $s$, which means that

$x^2-ix-1 = (x-r)(x-s).$

Putting this into Mathics and collecting terms,

Then $rs = -1$ and $-r-s = -i \Rightarrow r + s = i$. Solving these two equations simultaneously in Mathics,

which is correct.

To open a help window in Mathics, click on the `?`

in the upper right corner. Complete documentation is available online here.

## # Nebo

MyScript Nebo uses AI to interpret handwriting. If you have a tablet or laptop that accepts input from a stylus, Nebo will convert your handwritten notes to text. With Nebo, you can draw diagrams, and it will clean them up:

You can insert images into a document, and draw freehand sketches. I tend to write ideas down on a pad of paper, and the next great idea goes on the next empty page in the pad. My house is cluttered with pads. What was this one all about?

So I thought Nebo might be useful in organizing and cleaning up all my scribblings. Here’s an example:

On the left are the original hand-written equations. After tapping twice on the screen, Nebo converted everything to MathJax format. I had to fix three errors - two of the lower case $v$’s had been changed to upper case, and one of the $r$’s was interpreted as an $n$. Other than that, Nebo got it exactly right on the first try.

If you copy a section of math in Nebo, you can paste it into a markdown editor like this.

$\begin{aligned} x^{2}+bx+c&=0\\ \left( x-r\right) \times \left( x-s\right) &=x^{2}-\left( r+s\right) x+rs\\ b&=-\left( r+s\right) \\ c&=rs\\ u&=\dfrac{r+s}{2}\\ v&=u-r=s-u\\ r&=u-v,s=u+v\\ rs&=\left( u-v\right) \times \left( u+v\right) =u^{2}-v^{2} \end{aligned}$

Nebo includes the formatting characters

```
\begin{aligned}
x^{2}+bx+c&=0\\
\left( x-r\right) \times \left( x-s\right) &=x^{2}-\left( r+s\right) x+rs\\
b&=-\left( r+s\right) \\
c&=rs\\
u&=\dfrac{r+s}{2}\\
v&=u-r=s-u\\
r&=u-v,s=u+v\\
rs&=\left( u-v\right) \times \left( u+v\right) =u^{2}-v^{2}
\end{aligned}
```

I added ampersands before the equal signs to align each equation with the one above it. Nebo did all of the rest, including the `\begin{aligned}`

and `\end{aligned}`

.

Getting back to the math, to find the roots of the quadratic polynomial $f(x) = x^2 + bx + c$, you might remember the quadratic formula,

$x = \frac{-b \pm \sqrt{b^2 - 4c}}{2}.$

If you have the form $f(x) = ax^2 + bx + c$, divide by $a$ and calling $\frac{b}{a}$ the new $b$, and $\frac{c}{a}$ the new $c$, which has the same roots.

If we call the roots $r$ and $s$, then the plot of $f(x)$ will cross the $x-$axis at $r$ and $s$, and $f$ can be written as

$f(x) = x^2 + bx + c = (x-r)(x-s).$

Expanding the terms on the right,

$f(x) = (x-r)(x-s) = x^2 - (r+s)x + rs$

which means that $b = -(r+s)$ and $c = rs$.

Let’s call the midpoint between $r$ and $s$ the point $u$. Then

$u = \frac{r+s}{2}$

or

$u = -\frac{b}{2}.$

Since $u$ is the midpoint, the distance from $u$ to $s$ is the same as the distance from $r$ to $u$, so let’s call that distance $v$. Another way to express this is $u = r + v$ and $s = v + u$. Solving for $r$ in the first equation, $r = u-v.$ Since $c = rs$ then

$c = rs = (u-v)(u+v) = u^2 - v^2.$

After calculating $u$ in terms of $b$, we can get $v$ from $c$ and $u$,

$v = \sqrt{u^2 - c}.$

To recap, first find the midpoint of the unknown roots which will be at $-\frac{b}{2}$, and then get the distance to the roots which is $\sqrt{u^2-c}$. The roots will be $v \pm u$. So, now you can follow all of my chicken-scratching in Nebo.

For example, suppose $f(x) = x^2 - 3x + 1$, the plot in the figure above drawn in GeoGebra. Then $u = -\frac{3}{2}$ and

$v = \sqrt{\left( -\frac{3}{2} \right)^2 - 1} = \sqrt{\frac{9}{4} - 1} = \sqrt{\frac{9}{4}-\frac{4}{4}} = \frac{\sqrt{5}}{2}.$

So, the roots are

$x = \frac{3}{2} \pm \frac{\sqrt{5}}{2} = \frac{3 \pm \sqrt{5}}{2}.$

One more Nebo trick - write the equation with an equal sign at the end like this:

Double-tap, and you’ll get a neatly written equation with the solution!

Erase the $+$, replace it with a minus sign, and double-tap to get the other root $r \approx 0.382$. Nebo doesn’t do complex math, so we wouldn’t be able to solve the problem done earlier in Mathics, but for quick calculations, it’s pretty neat!

A nice introduction to Nebo is available from Paperless and Vojislav Dimitrijevic of My Deep Guide reviews the mathematical capabilities here.

## # Obsessed with Obsidian

Obsidian is the electronic version of my pads of paper. Obsidian is a markdown editor and a knowledge database of your ideas linked together. Upmath shows how to get started using LaTeX in Markdown files to write equations. Help is available by clicking on the `?`

in the lower left-corner, which opens a new pop-up window. An outline appears in the left panel, and document links are shown in the right panel.

The graphical view of help looks like this:

Click on `Open another vault`

to switch to your files. To extend the capabilities of Obsidian there are both core plugins and community plugins. The Sweet Setup blog lists some of their favorite plugins, and LibHunt lists the top community projects.

## # SyncThing

I switch between the desktop computer and laptop frequently, depending on whichever is the most convenient at the moment. But, how should I keep files synchronized between the two? Copying back and forth whenever I modify a file on one seemed tedious.

This is where SyncThing comes to the rescue. It continuously synchronizes files between any number of your computers, all in the background, using your home network. Take a look at the “Getting Started” page, and online documentation. After installation, all you need to do is identify your computers and the folders you’d like to synchronize. After that, the software keeps everything up-to-date.

For Windows users, SyncTrayzor is a tray utility for SyncThing.

After installing SyncThing on both computers, I realized I needed to have both running simultaneously to be able to sync, but I almost always shut down one when working on the other. The solution is that SyncThing is available for both Android and iOS phones, using the same convenient GUI.

Since my phone is almost always on, it keeps the latest version of all the files from whichever computer I’m currently using. I’ve even found that Python code is automatically reloaded in the Spyder editor, so long as I’ve remembered to save my work.

Now, with the phone acting as an intermediary, SyncThing makes switching between computers indistinguishable from magic.

## # Mathics Installation

Installing Nebo, Obsidian, and SyncThing is just a matter of following their instructions. Mathics is slightly more complicated but still easy. Here are the steps I used:

- Start Anaconda Powershell as administrator. I use Anaconda Python.
- Check python version: python --version
- Check pip version: pip --version
- Install Mathics: pip install Mathics-omnibus[full]
- Type: mathicsserver --help to check the installation
- Start mathics: mathicsserver
- In your browser (Chrome or Firefox) go to localhost:8000
- Save the mathics.png image from https://github.com/Mathics3
- Convert the image to mathics.ico using https://www.icoconverter.com/
- Make a batch file called
*mathics.bat*containing the single command*mathicsserver* - Create a desktop icon linked to mathics.bat, and change the icon to mathics.ico
- Click on the desktop icon to start Mathics, and type localhost:8000 in the address bar. Drag to the bookmarks bar.

Running Mathics from now on requires two steps - clicking on the icon to start the server followed by clicking the link to localhost:8000.

#### # Image credits

Hero: Humphrey Bogart and Claude Rains in Casablanca (1942). IMDB (photo 101)

Floppy Disk: How did people get apps on their computer before the Internet? user3840170, Stack Exchange, Oct 4, 2022

## # Software

### Mathics

A free, open-source alternative to Mathematica.

### Nebo

Create beautiful notes and professional documents by hand, sketch ideas on a limitless canvas and annotate PDFs. Powered by the world’s best AI handwriting recognition.

### Anaconda

Anaconda is a distribution of the Python and R programming languages for scientific computing (data science, machine learning applications, large-scale data processing, predictive analytics, etc.), that aims to simplify package management and deployment.

### Python

Python is an interpreted, high-level and general-purpose programming language.

### Geogebra

GeoGebra is dynamic mathematics software for all levels of education that brings together geometry, algebra, spreadsheets, graphing, statistics and calculus in one easy-to-use package.

### Obsidian

Obsidian is a personal knowledge base and note-taking software application that operates on Markdown.

### Syncthing

Syncthing is a continuous file synchronization program. It synchronizes files between two or more computers in real time, safely protected from prying eyes. Your data is your data alone and you deserve to choose where it is stored, whether it is shared with some third party, and how it’s transmitted over the internet.

See all software used on wildpeaches →