Jupyter for .NET. "Like in python"

A few months ago, Microsoft talked about Jupyter in .NET. But there is very little activity on this topic, and the topic is very interesting. But what's cool to think of? I decided to make a convenient derivation of the class Entityfrom the symbolic algebra library:







Looks cooler than in python. It is easy to do, it is a lot of fun. I invite you under the cut!



About Jupyter



It's kind of like an IDE for creating interactive notebooks. Instead of running all the code at once in familiar environments, here you run it in chunks, saving the states of the variables. It is very convenient for research and simple scripts to “calculate something”.



About dotnet / interactive



This project just allows you to embed Dotnet into Jupiter. That is, you can literally write



AND get the results of the code right away.



And some of the chips work out of the box





About AngouriMath



It is a relatively small symbolic algebra library for .NET for working with mathematical expressions. Of course, you can work with mathematical expressions in one line, but this is not always convenient / beautiful.



All mathematical expressions somehow inherit from a class Entitythat has a method Latexisethat returns a string. Therefore, all that remains is to render it.



Embedding latech



We have the ability to register our own inference for our types, which is what I do:



let magic() =
    let register (value : ILatexiseable) = $@"
            <script src='https://polyfill.io/v3/polyfill.min.js?features=es6'></script>
            <script id='MathJax-script' async src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js'></script>
            \[{value.Latexise()}\]
            "

    Formatter.Register<ILatexiseable>(register, "text/html")


(Habr for some reason does not support F #)



That is, we simply register that the type ILatexiseableshould be displayed in html format, and the code itself will be generated by our function. For rendering, I took MathJax, although it probably makes sense to cache the js script, but this is for future updates.



Well, that's all, now all expressions inherited from this interface will be beautifully rendered. This is how it looks in C #:







What exactly is going on here?
1. extension- ToEntity(),

2.

3.





Since Jupiter is intended for small chunks of code that don't have to follow any design requirements, F # is better suited for this. Therefore, as is clear from the screenshot at the beginning of the article, it is also supported. For example, this is how the solution to the school equation looks like:







Future plans



I am a very big fan of .NET but I also really love Jupyter. Therefore, Interactive made me very happy, and I hastened to make Interactive support for AngouriMath for displaying expressions in LaTeX. But further - more interesting. I am thinking of doing something of the type Entity.Plot()that would immediately display the graph of the function. For simple use-cases, a piece is really needed, I think.



If you want to try without installing anything from the necessary, you can poke around here: (alarm: for some reason it takes a long time to load, you will have to wait)



Thank you for your attention! Such is a short note.



Links



1. Jupyter - a convenient browser environment for interactive programming

2. .NET Interactive - the very brilliant thing, thanks to which you can use the dotnet in Jupiter

3. AngouriMath - a mathematical library for which I wrote a wrapper for latech

4. MyBinder - a demo for the lazy



All Articles