You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> _"Something like the Python-based [SageMath](https://sagemath.org), but for the Javascript world."_
3
+
> _"Web Assembly Python"_
4
4
5
5
## Quick start
6
6
7
-
You should have Node version 16.x installed. All the compiled code is WebAssembly, so it should work on any computer with Node 16.x installed and install very quickly; in particular, nothing needs to be compiled when installing.
jsage: for i inrange(4): print(i, 10+i) # jsage is similar to Python...
40
-
...
41
-
010
42
-
111
43
-
212
44
-
313
45
-
```
46
-
47
-
As explained below, it's also pretty easy to build JSage from source. We fully support building and developing natively using x86\_64 and aarch64 Linux, and Intel and M1 MacOS. There's also a Docker build recipe.
7
+
TODO
48
8
49
9
## OK, what is this?
50
10
51
-
The name "JSage"is meant to suggest a small combination of ideas from Javascript and Sage.
52
-
53
-
In 2004, I started https://www.sagemath.org/, which has gone on to be very successful in supporting pure mathematics research and teaching. Similar to Ryan Dahl who started node.js, I haven't been deeply involved in the weeds of Sage development for a long time, and also [similar to Ryan](https://www.youtube.com/watch?v=M3BM9TB-8yA), I've been thinking what I would do differently if I were to start Sage today in2021. This is one possible result of mulling over that question lately.
11
+
TODO
54
12
55
13
## What's the goal? What is the good for?
56
14
57
-
**!! Right now I don't claim this is useful for anything at all. It's a "Proof of Concept" !!**
58
-
59
-
Some potential longterm goals are listed below.
60
-
61
-
### Create a ridiculously easy to distribute and install platform-independent distribution of SageMath
62
-
63
-
SageMath is a very large Python/Cython library that also includes a large number of other mathematical software systems such asPARIand Gap and Singular. Thus part of the goal is to build each of PARI, GAP, etc. using Zig. This could be distributed as a small native Electron app along with a few hundred megabytes of cross-platform WebAssembly and data files. When there's a new release of Sage, the WebAssembly files need to get rebuilt and tested once, and the resulting binary will then support all versions of Linux, Windows, MacOS, and iOS. For iOS we would use [a-shell](https://github.com/holzschu/a-shell#programming--add-more-commands) (or simple contribute a free package to a-shell).
64
-
65
-
- There's probably [no way to build R](https://www.r-project.org/) with Zig, so we'll toss it; the Python community has not ended up building stats around rpy2 so this is fine.
66
-
- It might be very difficult to build Maxima via ECL (embedded common lisp) forWASM, in which case we will have to change Sage to not depend on Maxima for symbolic computation. We'll see. This is a very challenging project!
67
-
68
-
### Make research level mathematical software available to the Javascript ecosystem
69
-
70
-
Javascript is the most widely deployed language, but there is essentially nothing similar to any part of Sage, Pari, Gap or Singular available natively in [their ecosystem](https://www.npmjs.com/). Web applications, Node.js programs, and [sandboxed code running via WebAssembly](https://blog.cloudflare.com/workers-unbound-ga/) could all benefit from such software.
71
-
72
-
#### JIT: Just in time compiler
73
-
74
-
Modern Javascript runtimes --in particular, Chrome V8 and Firefox SpiderMonkey -- have good just-in-time (JIT) compilers that optimize a wide range of Javascript code. It could be valuable to combine math research software with the power of Javascript JIT. The Python ecosystem's JIT story is very different than what's available in Javascript. There's Pypy, but it's more "fringe", and it has real performance issues with C extensions. There's also numba, which is amazing for what it is amazing at, but only works for very specific types of code. There's also the new [Pyston](https://www.pyston.org/) spinoff from Dropbox.
75
-
76
-
Compared to Julia, the Javascript JIT's are also impressive due to how quickly and seamlessly it does JIT'ing, since that's a critical requirement for web pages. Sometimes Julia's JIT experience can involve waiting a long time for the JIT to happen before your code runs.
15
+
TODO
77
16
78
-
In any case, there may be situations where a program is fairly easy to write using a combination of Javascript and some of the WebAssembly libraries that come out of this project, and Javascript's JIT might also result in a very pleasant experience overall, as compared to other options.
79
-
80
-
##### JPython: yet another Python-to-Javascript compiler
81
-
82
-
Another experimental project you will find here is`jpython`, which is a _very lightweight_ Python-to-Javascript compiler. It makes it possible to write Python code, but benefit from a Javascript JITandall the functionality we build forWASM above. JPython runs natively in Javascript, so there is no dependence on Python itself (unlike Transcrypt). JPython is a fork of RapydScript, but with very different goals and constraints, e.g., much better conformance with the Python language, support for operator overloading, support for numerical computation, a mode to parse the "Sage preparser" language, andwith a lot of what RapydScript does removed (e.g., everything related to frontend UI programming). This barely exists today though!
83
-
84
-
#### New low level code
85
-
86
-
Making libraries like Pari, NTL, eclib, etc. available to Javascript is just a first step. This project also includes building new tools using modern low-level high-performance languages like Zig.
87
-
88
-
### Does this compete with SageMath?
89
-
90
-
Unlike [Julia](https://julialang.org/) or [Oscar](https://oscar.computeralgebra.de/), this project does not attempt to directly compete with SageMath. Indeed, one of the goals is to provide a distribution of SageMath that is easier to use, and another goal is to make the components of Sage and ultimately much of the core Sage library efficiently usable in more situations (e.g., node.js, web browsers, etc.). This project is thus about enriching the mathematical software ecosystem and expanding it beyond Python.
91
-
92
-
## Build JSage from source
93
-
94
-
### Dependencies to build
95
-
96
-
-**Node.js at least version 16.x:** the `node`in your path must be this recent version of node.js, which is very [easy to install](https://nodejs.org/en/download/) on most computers.
97
-
-**Standard build tools:** e.g., git, make, curl, m4, etc. For Linux see the Dockerfile remark below, andfor macOS, just make sure to install XCode which includes all this.
98
-
- This [Dockerfile](./Dockerfile) automates building JSage from source on Ubuntu Linux 20.04. It fully works on both x86\_64 and aarch64 Linux, and looking at it might answer any questions about build dependencies. Also, if you're having trouble building JSage and have Docker installed, you could instead do `make docker` and build this Docker image locally.
99
-
-**Tested Platforms:** I've tested building on the following platforms:
100
-
- _x86\_64 and aarch64 Linux_ -- via the Dockerfile above
101
-
- _macOS 12.x with Apple Silicon_, and XCode installed (to provide make, git, etc.)
102
-
- x86\_64 Linux as in any [CoCalc](https://cocalc.com) project with network access.
103
-
- [Microsoft Windows via WSL](https://docs.microsoft.com/en-us/windows/wsl/install#change-the-default-linux-distribution-installed) -- works fine, at least using Ubuntu (the default) after `apt install` the packages in the Dockerfile.
104
-
105
-
The build takes on the order of **one hour**or so.
17
+
## Build from source
106
18
107
19
### How to build
108
20
@@ -123,18 +35,18 @@ In most subdirectories `foo` of packages, this will create some subdirectories:
123
35
124
36
### Extra Packages
125
37
126
-
I have put a lot of work into getting various things to build, e.g., NTL, FLINT, Python, which are currently _**not**_ needed as a dependency for the core library I find myself building. Thus they are now NOT being built by default, since they aren't needed. Really all we need so far to build what we want to build is JPython (a Python language->Javascript compiler), GMP and Pari. It's amazing how much functionality Pari has built in, which overall is much broader (but less deep in some ways) than what's available in the C/C++ ecosystem of NTL/FLINT, etc. For our purposes though (of something very cross platform and easy to maintain!), Pari is really ideal.
127
-
128
-
That said, I put a lot of work into these other packages, and maybe they will be important at some point. But don't expect them to just work.
38
+
I have put a lot of work into getting various things to build.
129
39
130
40
### No common prefix directory
131
41
132
42
Unlike SageMath, where everything is built into a single `local` directory, here we build everything in its own self-contained package. When a package like `pari` depends on another package like `gmp` , our Makefile for `pari` explicitly references the `dist` directory in the `packages/dist/gmp` . This makes it possible to uninstall packages, update them, etc., whereas using a common directory for everything can be a mess with possibly conflicting versions of files.
133
43
134
44
### Native and Wasm
135
45
136
-
The build creates directories dist/native and dist/wasm. The `dist/native` artifacts are only of value on the computer where you ran the build, since they are architecture dependent and can easily depend on libraries on your system. In contrast, the `dist/wasm` artifacts are platform independent. They can be used nearly everywhere: on servers via WASM, on ARM computers (e.g., aarch64 linux, Apple Silicon, etc.), andinany modern web browser (though many details remain, obviously).
46
+
The build creates directories dist/native and dist/wasm. The `dist/native` artifacts are only of value on the computer where you ran the build, since they are architecture dependent and can easily depend on libraries on your system. In contrast, the `dist/wasm` artifacts are platform independent. They can be used nearly everywhere: on servers via WASM, on ARM computers (e.g., aarch64 linux, Apple Silicon, etc.), and in any modern web browser (though many details remain, obviously).
137
47
138
48
### Contact
139
49
140
-
Email [wstein@sagemath.com](mailto:wstein@sagemath.com) if you find this interesting and want to help out. This isallasopen source as possible, given what each dependency allows. This is right now entirely a _"project for fun and exploration"_ with no real constraints.
50
+
Email [[email protected]](mailto:[email protected]) if you find this interesting and want to help out. **This is an open source BSD licensed project.**
51
+
52
+
There is a related project https://github.com/sagemathinc/jsage that is GPL licensed, and has a goal related to https://sagemath.org.
0 commit comments