Skip to content

Commit 7bd5e3c

Browse files
committed
reorganize everything around upstream Python (e.g., delete jpython, all math code, etc.)
1 parent a7b7e81 commit 7bd5e3c

File tree

235 files changed

+43
-87458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

235 files changed

+43
-87458
lines changed

LICENSE

Lines changed: 29 additions & 674 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,17 @@ CWD = $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
44

55
export PATH := ${CWD}/packages/zig/dist:$(PATH)
66

7-
all: lib/${BUILT} packages/jpython/${BUILT}
7+
all: packages/python/${BUILT}
88

99
.PHONY: zig
1010
zig:
1111
cd packages/zig && make
1212

13-
packages/gmp/${BUILT}: zig
14-
cd packages/gmp && make all
15-
.PHONY: gmp
16-
gmp: packages/gmp/${BUILT}
17-
18-
packages/mpfr/${BUILT}: packages/gmp/${BUILT} zig
19-
cd packages/mpfr && make all
20-
.PHONY: mpfr
21-
mpfr: packages/mpfr/${BUILT}
22-
23-
packages/mpc/${BUILT}: packages/gmp/${BUILT} packages/mpfr/${BUILT} zig
24-
cd packages/mpc && make all
25-
.PHONY: mpc
26-
mpc: packages/mpc/${BUILT}
27-
28-
packages/gf2x/${BUILT}: zig wasi
29-
cd packages/gf2x && make all
30-
.PHONY: gf2x
31-
gf2x: packages/gf2x/${BUILT}
32-
33-
packages/ntl/${BUILT}: wasi packages/gmp/${BUILT} packages/gf2x/${BUILT} zig
34-
cd packages/ntl && make all
35-
.PHONY: ntl
36-
ntl: packages/ntl/${BUILT}
37-
38-
packages/flint/${BUILT}: packages/gmp/${BUILT} packages/mpfr/${BUILT} packages/ntl/${BUILT} zig
39-
cd packages/flint && make all
40-
.PHONY: flint
41-
flint: packages/flint/${BUILT}
42-
4313
packages/wasm-posix/${BUILT}: zig
4414
cd packages/wasm-posix && make all
4515
.PHONY: wasm-posix
4616
wasm-posix: packages/wasm-posix/${BUILT}
4717

48-
packages/pari/${BUILT}: wasi packages/gmp/${BUILT} packages/wasm-posix/${BUILT} zig
49-
cd packages/pari && make all
50-
.PHONY: pari
51-
pari: packages/pari/${BUILT}
52-
53-
packages/eclib/${BUILT}: wasi packages/gmp/${BUILT} packages/mpfr/${BUILT} packages/pari/${BUILT} packages/ntl/${BUILT} packages/flint/${BUILT} zig
54-
cd packages/eclib && make all
55-
.PHONY: eclib
56-
eclib: packages/eclib/${BUILT}
57-
58-
lib/${BUILT}: packages/gmp/${BUILT} packages/pari/${BUILT} wasi zig # packages/python/${BUILT}
59-
cd lib && make all
60-
.PHONY: lib
61-
lib: lib/${BUILT}
62-
63-
6418
# Included here since I did the work, but we're not using it.
6519
packages/openssl/${BUILT}: zig
6620
cd packages/openssl && make all
@@ -79,11 +33,6 @@ packages/python/${BUILT}: packages/zlib/${BUILT} packages/wasm-posix/${BUILT} zi
7933
.PHONY: python
8034
python: packages/python/${BUILT}
8135

82-
packages/jpython/${BUILT}: lib/${BUILT}
83-
cd packages/jpython && make all
84-
.PHONY: jpython
85-
jpython: packages/jpython/${BUILT}
86-
8736

8837
packages/wasi/${BUILT}: lib/${BUILT}
8938
cd packages/wasi && make all
@@ -93,23 +42,14 @@ wasi: packages/wasi/${BUILT}
9342

9443
.PHONY: docker
9544
docker:
96-
docker build --build-arg commit=`git ls-remote -h https://github.com/sagemathinc/jsage master | awk '{print $$1}'` -t jsage .
45+
docker build --build-arg commit=`git ls-remote -h https://github.com/sagemathinc/wapython master | awk '{print $$1}'` -t wapython .
9746

9847
.PHONY: docker-nocache
9948
docker-nocache:
100-
docker build --no-cache -t jsage .
49+
docker build --no-cache -t wapython .
10150

10251
clean:
103-
cd packages/gmp && make clean
104-
cd packages/gf2x && make clean
105-
cd packages/mpfr && make clean
106-
cd packages/mpc && make clean
107-
cd packages/ntl && make clean
108-
cd packages/flint && make clean
109-
cd packages/pari && make clean
110-
cd packages/eclib && make clean
11152
cd packages/wasi && make clean
112-
cd packages/jpython && make clean
11353
cd packages/python && make clean
11454
cd packages/openssl && make clean
11555
cd packages/zlib && make clean

README.md

Lines changed: 11 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,20 @@
1-
# JSage
1+
# WAPYTHON
22

3-
> _"Something like the Python-based [SageMath](https://sagemath.org), but for the Javascript world."_
3+
> _"Web Assembly Python"_
44
55
## Quick start
66

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.
8-
9-
```python
10-
> npm install @jsage/jpython
11-
> npx jsage # or npx jpython for no preparser
12-
Welcome to JSage. Using Node.js v16.13.0.
13-
Type dir(jsage) for available functions.
14-
jsage: list([2 .. 2^3])
15-
[2, 3, 4, 5, 6, 7, 8]
16-
jsage: 2/3 + 4/5
17-
22/15
18-
jsage: dir(jsage)
19-
['ComplexNumber', 'dims', 'P1List', 'ManinSymbols', 'EllipticCurve', 'factor', 'arith', 'Integer', 'ZZ', 'Rational', 'QQ', 'pari', 'misc', 'Number', 'init']
20-
jsage: dims.dimensionCuspForms(389)
21-
32
22-
jsage: E = EllipticCurve('389a'); E
23-
EllipticCurve([0, 1, 1, -2, 0])
24-
jsage: E.analyticRank()
25-
2
26-
jsage: E.conductor()
27-
389
28-
jsage: E.anlist(20)
29-
[0, 1, -2, -2, 2, -3, 4, -5, 0, 1, 6, -4, -4, -3, 10, 6, -4, -6, -2, 5, -6]
30-
jsage: %time v = E.anlist(10^5);
31-
Wall time: 170ms
32-
jsage: M = ManinSymbols(389); P = M.presentation(1009); t = P.heckeOperator(2);
33-
jsage: t.fcp()
34-
[x + 2 2]
35-
[x + 439 2]
36-
...
37-
[x^4 + 298*x^3 + 873*x^2 + 507*x + 325 2]
38-
[x^9 + 347*x^8 + 408*x^7 + 343*x^6 + 673*x^5 + 219*x^4 + 736*x^3 + 475*x^2 + 326*x + 697 2]
39-
jsage: for i in range(4): print(i, 10+i) # jsage is similar to Python...
40-
...
41-
0 10
42-
1 11
43-
2 12
44-
3 13
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
488

499
## OK, what is this?
5010

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 in 2021. This is one possible result of mulling over that question lately.
11+
TODO
5412

5513
## What's the goal? What is the good for?
5614

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 as PARI and 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) for WASM, 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
7716

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 JIT and all the functionality we build for WASM 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, and with 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, and for 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
10618

10719
### How to build
10820

@@ -123,18 +35,18 @@ In most subdirectories `foo` of packages, this will create some subdirectories:
12335

12436
### Extra Packages
12537

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.
12939

13040
### No common prefix directory
13141

13242
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.
13343

13444
### Native and Wasm
13545

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.), and in any 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).
13747

13848
### Contact
13949

140-
Email [wstein@sagemath.com](mailto:wstein@sagemath.com) if you find this interesting and want to help out. This is all as open 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

Comments
 (0)