Leo is the best math platform!

197 views
Skip to first unread message

Edward K. Ream

unread,
Dec 13, 2024, 6:13:55 AM12/13/24
to leo-editor

Yesterday was a momentous day for me. I wrote a dead easy script that converts Jupyter notebooks to @file nodes. I immediately saw (Aha!) that Leo is a far better platform than Jupyter Lab!


I have forgotten exactly how the Aha came about. As usual, the Aha changed everything, including my memory!


But the historical details don't matter. What matters is that I now have an excellent workflow and environment for studying math.


math.leo, in the leo-editor-contrib repo, shows the results of yesterday's work.


The breakthrough script


The @button import-ipynb script converts .ipynb files to .py files. It practically wrote itself. math.leo contains the latest version.


The guts of the script are these lines:


p = parent.insertAsLastChild()

p.h = f"@jupytext {the_file}"

c.selectPosition(p)

c.refreshFromDisk()

new_fn = os.path.basename(the_file).replace('.ipynb', '.py')

p.h = f"# @file {dir_s}{os.sep}{new_fn}"


Wow. @jupytext does all the heavy lifting!!


Aha: Leo is the best math platform!


After converting the notebooks to Leo outlines, I immediately saw that Leo is much more powerful than Matlab or Jupyter.


To complete my new workflow, another @button script runs files externally:


import os

# Execute the script in the proper folder.

dir_ = os.path.dirname(c.fileName())

os.chdir(dir_)

# Use the common naming convention.

chapter = 'CH01'

section = r'SEC03_Rotation.py'

path = fr'{chapter}/{chapter}_{section}'

g.execute_shell_commands(f"&python {path}")


Summary


Yesterday was a golden day. Such milestones do not happen often.


math.leo, in the leo-editor-contrib, shows my latest work. Those wishing to use my work should carefully read the "Read me" node in math.leo.


For me, Leo is (by far!) the best platform for doing math. This insight could not have happened without @jupytext!


Questions? Comments? Acclaim?


Edward


P.S. There is still a place for Jupyter notebooks :-) They are an excellent way of collaborating. But I have no further interest in them.


EKR

Edward K. Ream

unread,
Dec 13, 2024, 7:36:48 AM12/13/24
to leo-editor
The conversion script shows the power of Leo's scripting API. Here are the lines that clean newly imported files:

def is_pure_python(p) -> bool:
    return not any(
        line.startswith('# %% [markdown]')
        for p2 in p.self_and_subtree()
        for line in g.splitLines(p2.b)
    )
...
# Delete the useless Jupyter boilerplate.
for child in p.children():
    if child.h == g.angleBrackets(' prefix '):
        child.doDelete()
        break
p.b = p.b.replace(g.angleBrackets(' prefix ') + '\n', '')
if is_pure_python(p):
    # Change the language and remove all jupytext comments.
    p.b = p.b.replace('@language jupytext', '@language python')
    for child in p.children():
        child.b = child.b.replace('# %%\n\n', '').replace('# %%\n', '')


Disable these lines to retain two-way compatibility with Jupyter Notebooks.

Onward to studying math!

Edward

Thomas Passin

unread,
Dec 13, 2024, 8:58:51 AM12/13/24
to leo-editor
I've been trying to sell Leo-as-a-notebook for some time now.  I glad to see you are starting to get the idea at last! Remember, with VR3 you can render an entire tree starting with the current node; by locking the view you can navigate to and edit a node without having the rendered view jump out from under you.

Jupyter has many strengths and capabilities that I don't see Leo ever getting.  Perhaps they aren't needed for your use.

Offray Vladimir Luna Cárdenas

unread,
Dec 13, 2024, 10:57:12 AM12/13/24
to leo-e...@googlegroups.com

In the same vein as Thomas, I was pushing Leo as an interactive notebook metasystem since years. 

I think that those aha moment would be greatly improved by screenshots particularly depicting the interactive story behind Leo usage in the scientific notebook context as still is not represented in a way that showcases Leo's advantages. I would say that LeoVue is something to imitate regarding how to showcase Leo (maybe because of its multiple and versatile web views for Leo structured information).

Cheers,

Offray

--
You received this message because you are subscribed to the Google Groups "leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/leo-editor/9040e29e-f6db-451f-bf0a-251585c43610n%40googlegroups.com.

John Clark

unread,
Dec 13, 2024, 6:45:52 PM12/13/24
to leo-editor
All interested in interactive notebooks,

Please also consider marimo if it's unknown to you.

It's claim of being "the future of python notebooks" is not far off the mark, IMO. It is an evolutionary step beyond Jupyter in my estimation.

Interestingly, the necessity for marimo to process cells internally in a tree-like manner similar to Leo is an integral part of what makes it work.

Cheers

Thomas Passin

unread,
Dec 13, 2024, 10:41:37 PM12/13/24
to leo-editor
Mario looks very impressive, all right. Thanks for the link.

Leo has many capabilities that can be useful in a notebook besides have flat cells with sophisticated execution.  I wonder if it would be practical to overlay such DAG structures onto Leo nodes to get some of the benefits of both worlds.  it sounds ideal for Edward's next project!

HaveF HaveF

unread,
Dec 13, 2024, 10:49:24 PM12/13/24
to leo-editor
On Saturday, December 14, 2024 at 7:45:52 AM UTC+8 leve...@theinsideworld.net wrote:
All interested in interactive notebooks,

Please also consider marimo if it's unknown to you.

It's claim of being "the future of python notebooks" is not far off the mark, IMO. It is an evolutionary step beyond Jupyter in my estimation.

Interestingly, the necessity for marimo to process cells internally in a tree-like manner similar to Leo is an integral part of what makes it work.

In my opinion, marimo is actually the python version of Observable.
https://observablehq.com/

Personally, I still like the combination of Leo + Jupyter. Think about the development history of Leo over the years, and we know how difficult it is to do a good job in a tree-like manner. Marimo may still have a long way to go.
 

Edward K. Ream

unread,
Dec 14, 2024, 5:46:59 AM12/14/24
to leo-editor
On Friday, December 13, 2024 at 5:13:55 AM UTC-6 Edward K. Ream wrote:

P.S. There is still a place for Jupyter notebooks :-) They are an excellent way of collaborating. But I have no further interest in them.


On second thought, the title of this thread is misguided. I apologize for the exaggeration.

Jupyter notebooks have strengths that Leo can only emulate:

- Excellent typing completion.
- Persistent namespaces.
- An ecosystem of plugins.
- An integrated debugging environment.
- And likely other features of which I am ignorant.

The conversion script makes it easy to import notebooks into Leo, but the script doesn't make notebooks obsolete!

Edward

Edward K. Ream

unread,
Dec 14, 2024, 6:18:14 AM12/14/24
to leo-e...@googlegroups.com
On Fri, Dec 13, 2024 at 5:45 PM John Clark <leve...@theinsideworld.net> wrote:

Please also consider marimo if it's unknown to you.

Thanks for the link!

Edward

Offray Vladimir Luna Cárdenas

unread,
Dec 15, 2024, 10:37:02 AM12/15/24
to leo-e...@googlegroups.com

marimo looks pretty cool! and a breath of fresh air in the overcomplicated notebook space that Jupyter popularized. Once a tool(kit) like Jupyter becomes the defacto standard in a community (let's say data scientists) it is difficult to reimagine what can be done in that space. That's why seeing things like Pluto.jl[1] (named in the inspirations for marimo) that choose simplicity and reproducible flat files over nested unreproducible JSON, as a default for interactive computing is really inspiring.

[1] https://cinemaphile.com/watch?v=Rg3r3gG4nQo

In my case, after being pretty reluctant to web development (mainly because of Javascript and all the messiness behind web "standards" by committee ), seems that things like Pluto, marimo and Hypermedia systems[2][2a] are showing that the time to develop pretty interesting web experiences and publications without all that incidental complexity and without the JavaScript monoculture is finally arriving. I'll share my experiment on that front.

[2] https://hypermedia.systems/
[2a] https://hx-pod.transistor.fm

Cheers,

Offray

Thomas Passin

unread,
Dec 15, 2024, 12:15:49 PM12/15/24
to leo-editor
Thank you for the links!  I'm just getting into reading the hypermedia book and already I can see that it's right up my alley.  I stopped working with web frameworks when they got so complex and  programming-oriented.  I'm repelled by many modern javascript practices. As I started reading the book it felt like I had finally met a kindred spirit.

Offray Vladimir Luna Cárdenas

unread,
Dec 16, 2024, 10:37:35 AM12/16/24
to leo-e...@googlegroups.com

Thomas,

I'm glad you liked :). 

You should take a look of the Hypermedia podcast, particularly the long recent chapter about Data-Star[1]. I think it gives you a pretty broad overview of the possibilities of Hypermedia beyond its flagship tech: HTMX

[1] https://data-star.dev/

I really like the moment we are arriving now, where web development, particularly in the front-end, doesn't mean to subsume yourself totally to the "Javascript mindset" with all its technical design flaws, patchy features, gratuitous overcomplexity and so on. I imagine instead that now I'll doing web stuff, that I was thinking years ago, from my favorite computing environment: Pharo/GToolkit, with sparks of Javascript here and there, without making it or the web a "development platform" and thinking about the web more like a "exportation target".

My idea for this holidays, is to use hypermedia for creating an interactive publishing format for the data stories we have made with Grafoscopio and see if, eventually, it can evolve to a (reactive) web notebook, working on several Smalltalk variants (but baby steps, I'll jus start with the interactive publishing format). As usual, I'll share preliminary results, when I see there is an overlap with the topics discussed here.

Cheers,

Offray

HaveF HaveF

unread,
Dec 16, 2024, 7:00:57 PM12/16/24
to leo-e...@googlegroups.com

On Mon, Dec 16, 2024 at 1:15 AM Thomas Passin <tbp1...@gmail.com> wrote:
Thank you for the links!  I'm just getting into reading the hypermedia book and already I can see that it's right up my alley.  I stopped working with web frameworks when they got so complex and  programming-oriented.  I'm repelled by many modern javascript practices. As I started reading the book it felt like I had finally met a kindred spirit.

hi, Thomas,

For hypermedia related, I recommend fasthtml lib. You may like it(Although it's not particularly mature yet, I think the basic concept is solid). For some simple programs, it is completely fine. For pages that require complex interactions, I believe htmx has its inherent defects.

Edward K. Ream

unread,
Dec 17, 2024, 10:14:21 AM12/17/24
to leo-editor
On Saturday, December 14, 2024 at 4:46:59 AM UTC-6 Edward K. Ream wrote:

On second thought, the title of this thread is misguided.

I have spent the last week coming up to speed on all the fabulous math tools and websites out there.

This morning I finally got around to writing my first matplotlib program. See the Postscript.
This exercise has been a ton of fun. execute-script just works!

For me, Leo is the perfect platform for running Matplotlib programs.
The more I use Jupyter, the less I like it, so the title of this thread seems about right :-)

Edward

P.S. Here is my first plot:

import matplotlib.pyplot as plt
import numpy as np

# Use a monospace font for
plt.rcParams["font.family"] = 'DejaVu Sans Mono'

a, b = [], []
for x in range(-50,50):
    y=x**2
    a.append(x)
    b.append(y)

fig= plt.figure()
fig.suptitle('Parabola with Tangents')
axes=fig.add_subplot()
axes.plot(a,b)

# Cut the tangent lines off at y = 0
plt.ylim(bottom=0)
color = iter(plt.cm.rainbow(np.linspace(0, 1, 6)))
for i, x in enumerate(range(-50, 60, 20)):
    if x == 0:
        continue
    y = x**2
    slope = 2 * x
    x_y_s = f"({x:3}, {y})"
    label = f"{x_y_s:<11} slope: {slope:4}, x-intercept: {x - y/slope:>5}"
    plt.axline((x, y), slope=slope, label=label, c=next(color))
axes.legend()
fig.canvas.manager.window.move(50,50)  # Move the window.
plt.show()

EKR

Thomas Passin

unread,
Dec 17, 2024, 2:06:42 PM12/17/24
to leo-editor
pyplot can be fun.

As an alternative to
a, b = [], []
for x in range(-50,50):
    y=x**2
    a.append(x)
    b.append(y)


this is shorter and probably a little easier to grasp what the variables represent:

xy = [(x, x**2) for x in range(-50, 50)]
x, y = zip(*xy)  # type(x) is a tuple

I also recommend you develop a set of styles you like and save them to a style file in a known place.  The you can apply its styles to each graph like this:

plt.style.use(style_file)

Here is one of mine:

axes.facecolor: white
axes.grid : True

text.hinting_factor : 8
xtick.direction: out
ytick.direction: out

grid.color: lightgrey
grid.linestyle: -    # solid line

figure.facecolor: (.90,.90,.90)
figure.edgecolor: 0.50
figure.figsize: 8, 5.5

axes.prop_cycle: cycler('color', ['black', 'lightgrey', 'indigo', 'red', 'blue', 'cyan', 'gray', 'magenta'])

mathtext.fontset : stix

You might want to check out plotnine, too, for plotting your datasets. You install it with pip.

Another fun little goodie is the attached outline.  It contains a command that plots in a new tab in the log frame.
matplotlib-plot-in-tab.zip

Edward K. Ream

unread,
Dec 17, 2024, 4:20:51 PM12/17/24
to leo-e...@googlegroups.com
On Tue, Dec 17, 2024 at 1:06 PM Thomas Passin <tbp1...@gmail.com> wrote:

pyplot can be fun.

It's addictive!

I also recommend you develop a set of styles you like and save them to a style file in a known place. 

Thanks for the advice! I'll look into it.
 
You might want to check out plotnine, too, for plotting your datasets. You install it with pip.

Will do.

Another fun little goodie is the attached outline.  It contains a command that plots in a new tab in the log frame.

Excellent. The full power of python is on display.

Many thanks for your guidance.

Edward

Thomas Passin

unread,
Dec 17, 2024, 5:43:19 PM12/17/24
to leo-editor
VR3 has a basic but useful plotting capability that uses pyplot behind the scenes.  Basically if your node contains 1 or 2-column data, VR3's plotting function will ignore any non-numeric lines and plot the data with a 2D line plot. These plots can be made from VR3's Other Actions menu.  Here is an example node to try it out (all ini-style configuration sections are optional):

[style]
stylename = xkcd

[labels]
title = Test Graph
xaxis = The X axis
yaxis = The Y Axis

# [source]
# file = temp\testdata.txt

1 1
2 4
3 9  # a comment about this point
4 16

Offray Vladimir Luna Cárdenas

unread,
Dec 18, 2024, 7:06:32 PM12/18/24
to leo-e...@googlegroups.com

Hi,

I still fail to see the interactive story behind Leo usage, particularly in the math learning context, and interactivity in its most general sense is important for learning. See for example the seam carving algorithm by Grant Sanderson, from the excellent 3Blue1Brown at [1], that is explained interactively with Pluto.jl/Julia and reimplemented in marimo/Python. The educative advantages from the explaining and learning sides are pretty difficult to imagine by seeing just the source code or executing it in batch mode, without interactivity.

[1] https://huggingface.co/spaces/marimo-team/seam-carving

As said, LeoVue and maybe the variant of Leo for VS Code/Codium can convey this sense of interactivity, thanks to the integration with web technologies.  Maybe with Hypermedia and things like FastHTML, much of that can be done within Leo. But I think that this more interactive/visual storytelling is needed to make Leo a good math platform for wider audiences.

Cheers,

Offray

--
You received this message because you are subscribed to the Google Groups "leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+...@googlegroups.com.

Edward K. Ream

unread,
Dec 19, 2024, 10:29:50 AM12/19/24
to leo-editor
On Wednesday, December 18, 2024 at 6:06:32 PM UTC-6 Offray wrote:

I still fail to see the interactive story behind Leo usage, particularly in the math learning context, and interactivity in its most general sense is important for learning.

My priority (singular) is to master ME 564. I intend to master the solutions to all exercises. Solutions using Jupyter Notebooks are acceptable, implying that Matplotlib suffices. I trust Steve Brunton to know his pedagogy. He's a brilliant educator.


My experience shows that Leo is superior to Jupyter Notebooks for my purposes. Those who wish to experiment with other platforms may do so, but I shall not distract myself from my priority.

Edward

Offray Vladimir Luna Cárdenas

unread,
Dec 19, 2024, 4:01:42 PM12/19/24
to leo-e...@googlegroups.com

Totally understandable. I just add that particularity for the assertion: Leo is superior to Jupyter notebook for Leo's main author and it's the best math platform for him.

As a tool maker myself, I share part of that feeling, as I think that Grafoscopio is a better tool than Jupyter or Leo for my purposes and the ones of my local community at the hackerspace: being able to adapt interactively the tool to our future needs. But I claiming that is the best for a general endeavor would be overselling Grafoscopio, to its detriment. I still find inspiring and superior use cases in Pluto, marimo, Leo in particular domains and I hope to learn from them and I don't consider that a distraction but a refreshing external view that reveals much of the blind spots that, by definition, I can not see by myself. And, of course, everyone can find seeing outside distracting or not.

Cheers,

Offray

--
You received this message because you are subscribed to the Google Groups "leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages