All Projects → sagemathinc → JSage

sagemathinc / JSage

Licence: GPL-3.0 license
Something like Sage, but for the WebAssembly and JavaScript world.

Programming Languages

javascript
184084 projects - #8 most used programming language
python
139335 projects - #7 most used programming language
Zig
133 projects
typescript
32286 projects
Makefile
30231 projects
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to JSage

tweedle
Generator and supporting evidence for security of the Tweedledum/Tweedledee pair of elliptic curves suitable for Halo
Stars: ✭ 16 (-30.43%)
Mutual labels:  mathematics, sagemath
GNFS
A complete, proof-of-concept, C# implementation of the General Number Field Sieve algorithm for factoring very large semi-prime numbers. The focus was on readability and understandability of the code, not performance.
Stars: ✭ 39 (+69.57%)
Mutual labels:  mathematics, number-theory
Math Php
Powerful modern math library for PHP: Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with matrices and vectors, Numerical analysis; special mathematical functions; Algebra
Stars: ✭ 2,009 (+8634.78%)
Mutual labels:  mathematics, number-theory
Awesome-Math-Learning
📜 Collection of the most awesome Math learning resources in the form of notes, videos and cheatsheets.
Stars: ✭ 73 (+217.39%)
Mutual labels:  mathematics, number-theory
jubjub
Supporting evidence for security of the Jubjub curve to be used in Zcash
Stars: ✭ 13 (-43.48%)
Mutual labels:  mathematics, sagemath
cafe
🧊 Презентації та Воркшопи
Stars: ✭ 20 (-13.04%)
Mutual labels:  mathematics
ra
Basic Analysis, undergraduate real analysis textbook
Stars: ✭ 33 (+43.48%)
Mutual labels:  mathematics
smoothfit
Smooth data fitting in N dimensions.
Stars: ✭ 40 (+73.91%)
Mutual labels:  mathematics
alchemy
Generate any a-by-( b + c ) finite rectangle SVG containing potentially Infinitely many a-by-( 2 * b ) finite rectangles animated along a number line of ( ( c - b ) / a )^n scale symmetry.
Stars: ✭ 29 (+26.09%)
Mutual labels:  mathematics
ML-University
Machine Learning Open Source University
Stars: ✭ 423 (+1739.13%)
Mutual labels:  mathematics
Mathematics
Various math formulas coded in Java to help students all across the world!
Stars: ✭ 35 (+52.17%)
Mutual labels:  mathematics
mathlingua
MathLingua is a language used to describe mathematical definitions, theorems, conjectures, and axioms in a way that can be easily written, read, and understood by both people and computers.
Stars: ✭ 68 (+195.65%)
Mutual labels:  mathematics
curve-shortening-demo
Visualize curve shortening flow in your browser.
Stars: ✭ 19 (-17.39%)
Mutual labels:  mathematics
series-formelles
Translation of, and commentary on, Joyal's classic paper "Une théorie combinatoire des séries formelles" (A combinatorial theory of formal series)
Stars: ✭ 24 (+4.35%)
Mutual labels:  mathematics
math eval
✖️➕➖➗ `math_eval` safely evaluates mathematical expressions
Stars: ✭ 33 (+43.48%)
Mutual labels:  mathematics
EmbeddedLapack
Linear algebra for embedded system with MATLAB style
Stars: ✭ 92 (+300%)
Mutual labels:  mathematics
maths-for-deep-learning-ai
A open source book covering the foundational maths of deep learning and machine learning using TensorFlow
Stars: ✭ 35 (+52.17%)
Mutual labels:  mathematics
pwsh-prelude
PowerShell “standard” library for supercharging your productivity. Provides a powerful cross-platform scripting environment enabling efficient analysis and sustainable science in myriad contexts.
Stars: ✭ 26 (+13.04%)
Mutual labels:  mathematics
rclc
Mathematical expression calculator with big integers, floats, common fractions, and complex numbers support
Stars: ✭ 24 (+4.35%)
Mutual labels:  mathematics
Project-Euler
Send PRs to contribute and see the Codemasters solving some really mind boggling questions.
Stars: ✭ 21 (-8.7%)
Mutual labels:  mathematics

JSage

"Something like the Python-based SageMath, but for the Javascript world."

Quick start

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.

> npm install @jsage/jpython
> npx jsage    # or npx jpython for no preparser
Welcome to JSage.  Using Node.js v16.13.0.  
Type dir(jsage) for available functions.
jsage: list([2 .. 2^3])
[2, 3, 4, 5, 6, 7, 8]
jsage: 2/3 + 4/5
22/15
jsage: dir(jsage)
['ComplexNumber', 'dims', 'P1List', 'ManinSymbols', 'EllipticCurve', 'factor', 'arith', 'Integer', 'ZZ', 'Rational', 'QQ', 'pari', 'misc', 'Number', 'init']
jsage: dims.dimensionCuspForms(389)
32
jsage: E = EllipticCurve('389a'); E
EllipticCurve([0, 1, 1, -2, 0])
jsage: E.analyticRank()
2
jsage: E.conductor()
389
jsage: E.anlist(20)
[0, 1, -2, -2, 2, -3, 4, -5, 0, 1, 6, -4, -4, -3, 10, 6, -4, -6, -2, 5, -6]
jsage: %time v = E.anlist(10^5);
Wall time: 170ms
jsage: M = ManinSymbols(389); P = M.presentation(1009); t = P.heckeOperator(2);
jsage: t.fcp()
[x + 2 2]
[x + 439 2]
...
[x^4 + 298*x^3 + 873*x^2 + 507*x + 325 2]
[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]
jsage: for i in range(4): print(i, 10+i)   # jsage is similar to Python...
... 
0 10
1 11
2 12
3 13

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.

OK, what is this?

The name "JSage" is meant to suggest a small combination of ideas from Javascript and Sage.

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

What's the goal? What is the good for?

!! Right now I don't claim this is useful for anything at all. It's a "Proof of Concept" !!

Some potential longterm goals are listed below.

Create a ridiculously easy to distribute and install platform-independent distribution of SageMath

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 (or simple contribute a free package to a-shell).

  • There's probably no way to build R with Zig, so we'll toss it; the Python community has not ended up building stats around rpy2 so this is fine.
  • 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!

Make research level mathematical software available to the Javascript ecosystem

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. Web applications, Node.js programs, and sandboxed code running via WebAssembly could all benefit from such software.

JIT: Just in time compiler

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 spinoff from Dropbox.

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.

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.

JPython: yet another Python-to-Javascript compiler

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!

New low level code

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.

Does this compete with SageMath?

Unlike Julia or Oscar, 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.

Build JSage from source

Dependencies to build

  • 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 on most computers.
  • 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.
    • This 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.
  • Tested Platforms: I've tested building on the following platforms:
    • x86_64 and aarch64 Linux -- via the Dockerfile above
    • macOS 12.x with Apple Silicon, and XCode installed (to provide make, git, etc.)
    • x86_64 Linux as in any CoCalc project with network access.
    • Microsoft Windows via WSL -- works fine, at least using Ubuntu (the default) after apt install the packages in the Dockerfile.

The build takes on the order of one hour or so.

How to build

Just type "make"

...$ make

This runs a single top level makefile to build all the packages. The build process for all individual packages is also accomplished using a Makefile. We don't use shell scripts or Python code to orchestrate building anything, since make is much cleaner and easier to read, maintain and debug.

What happens

In most subdirectories foo of packages, this will create some subdirectories:

  • packages/foo/dist/[native|wasm] -- a native or WebAssembly build of the package; this has binaries, headers, and libs. These get used by other packages.
  • packages/build/[native|wasm] - build artifacts for the native or WebAssembly build; can be safely deleted

Extra Packages

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.

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.

No common prefix directory

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.

Native and Wasm

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

Contact

Email [email protected] 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].