Zushah/Chalkboard
https://zushah.github.io/Chalkboard
Contents
About
The Chalkboard library is a JavaScript namespace that provides a plethora of both practical and abstract mathematical functionalities for its user. It was developed by Zushah during 2022 and 2023 and then released on November 6, 2023. As per the latest release of v2.2.0 Galois, Chalkboard has 564 unique commands. The library is available for regular JavaScript on both the client-side and the server-side as well as Proccesing.js (fully compatible with Khan Academy). Chalkboard's website can be visited here.
Installation
If your JavaScript project is being run on the client-side within a webpage, you can install Chalkboard with this HTML tag:
<script src="https://cdn.jsdelivr.net/gh/Zushah/Chalkboard@2.2.0/dist/Chalkboard.min.js"></script>
If your JavaScript project is being run on the server-side within the Node.js environment, you can install Chalkboard with this console command:
npm install @zushah/chalkboard
Alternatively, you can simply download the latest release and put the relevant files in your project's directory.
Chalkboard can also be downloaded on Khan Academy from the code in the corresponding release.
Documentation
Chalkboard has thirteen categories of commands:
abal
- Abstract algebra definitions, sets, operations, structures, and morphismscalc
- Single/multi-variable real/complex-valued calculus operationscomp
- Complex number and complex function operationsgeom
- Geometric operationsmatr
- Multidimensional matrix operationsnumb
- Number-theory-related operationsplot
- Plotting real and complex functions, complex numbers, vectors, matrices, and statistical graphsquat
- Quaternion operationsreal
- Real number and real function operationsstat
- Statistical array operationstens
- Tensor (multidimensional multidimensional matrix) operationstrig
- Trigonometric function operationsvect
- Two-, three-, and four-dimensional vector and vector field operations
There are also eight "global" commands and constants, which are:
APPLY
- Applies a callback function in an element-wise manner on a Chalkboard objectCONTEXT
- The JavaScript canvas rendering context to use for plottingE()
- Computes the number eLOGO()
- Draws the Chalkboard logoPARSEPREFIX
- Used for adding custom functions to the Chalkboard parserPI()
- Computes the number πREADME()
- Prints basic information about Chalkboard in the consoleVERSION
- The installed version of ChalkboardVERSIONALIAS
- The alias of the installed version of Chalkboard
Lastly, Chalkboard has eleven data types (also known as Chalkboard objects):
ChalkboardComplex
- Complex numbersChalkboardFunction
- Mathematical functionsChalkboardMatrix
- MatricesChalkboardMorphism
- MorphismsChalkboardQuaternion
- QuaternionsChalkboardSet
- SetsChalkboardStructure
- Algebraic structuresChalkboardStructureExtension
- Algebraic structure extensionsChalkboardTensor
- TensorsChalkboardVector
- VectorsChalkboardVectorField
- Vector fields
The comprehensive Chalkboard documentation can be visited here.
Getting Started
After installing Chalkboard into your program, you can immediately get started with using it. Every Chalkboard command begins with typing "Chalkboard" followed by a period, then the name of the category of the command (all categories are listed above in the documentation section) with another period, and lastly the desired command itself.
Chalkboard.category.command(parameters);
Here is some code that shows off only a few features of Chalkboard:
const cb = Chalkboard; // Initialize in a browser
const cb = require("@zushah/chalkboard"); // Initialize in Node with CommonJS
import cb from "@zushah/chalkboard"; // Initiialize in Node with ES Modules
const f = cb.real.define("Math.cos(2 * x)"); // f(x) = cos(2x)
const dfdx = cb.calc.dfdx(f, 2); // Derivative of f at x = 0
const fxdx = cb.calc.fxdx(f, 0, 2); // Antiderivative of f from x = 0 to x = 2
const fourier = cb.calc.Fourier(f, 2); // Fourier transform of f at x = 2
const f = cb.vect.field("x", "y", "z"); // f(x, y, z) = (x, y, z)
const r = cb.real.define(["Math.cos(s) * Math.cos(t)", "Math.sin(s) * Math.cos(t)", "Math.sin(t)"], "surf"); // r(s, t) = (cos(s)cos(t), sin(s)cos(t), sin(t))
const fnds = cb.calc.fnds(f, r, cb.PI(-1/2), cb.PI(1/2), 0, cb.PI(2)); // Flux of the radial vector field through the unit sphere
const primes = cb.numb.primeArr(0, 100); // Array of prime numbers between 0 and 100
const midPrime = cb.stat.median(primes); // Median number in the primes array
cb.plot.barplot(primes, cb.stat.array(0, 100, 11), {size: 5, strokeStyle: "black", fillStyle: "blue"}); // Barplot of the primes array with a bin size of 10, a scale of 2, a stroke color of black, and a fill color of blue
const z = cb.comp.init(1, 1); // z = 1 + i
const zsqsqrt = cb.comp.sqrt(cb.comp.sq(z)); // The square root of z squared equals z
const f = cb.comp.define("a*a - b*b + 1", "2*a*b"); // f(z) = z^2 + 1
cb.plot.definition(f); // Plots the domain coloring of f
const r = cb.real.define(["Math.cos(t)", "Math.sin(t)"], "curv"); // r(t) = (cos(t), sin(t))
cb.plot.xyplane({size: 2}); // Draws the Cartesian coordinate plane scaled by 2
cb.plot.definition(r, {size: 2, strokeStyle: "rgb(255, 100, 100)", domain: [0, cb.PI(2)]}); // Plots r(t) scaled by 2 colored light red from t = 0 to t = π/2
const a = cb.vect.init(1, 2, 3); // Vector a = (1, 2, 3)
const b = cb.vect.init(4, 5, 6); // Vector b = (4, 5, 6)
const c = cb.vect.init(7, 8, 9); // Vector c = (7, 8, 9)
const axbxc = cb.vect.vectorTriple(a, b, c); // Triple cross product between a, b, and c
cb.vect.print(axbxc); // Prints axbxc in the console
const m = cb.matr.init( // m is a 5x5 matrix
[0, 1, 1, 1, 1],
[1, 0, 1, 1, 1],
[1, 1, 0, 1, 1],
[1, 1, 1, 0, 1],
[1, 1, 1, 1, 0]
);
const mi = cb.matr.invert(m); // mi is the inverse of m
const mmi = cb.matr.mul(m, mi); // mmi is the product of m and mi
cb.matr.print(mmi); // Prints mmi in the console
const t = cb.tens.init( // t is a 2x2x2 rank-3 tensor
[
[1, 2],
[3, 4]
],
[
[5, 6],
[7, 8]
]
);
const tt = cb.tens.mul(t, t); // tt is a 2x2x2x2x2x2 rank-6 tensor
const ttm = cb.tens.resize(tt, 8, 8); // ttm is an 8x8 matrix (or rank-2 tensor)
cb.tens.print(tt); // Prints tt in the console just to see what it looks like for fun
const factorialt = cb.APPLY(t, (x) => cb.numb.factorial(x)); // Calculates the factorial of each element of t
const Z4 = cb.abal.Z(4); // The set of integers modulo 4 is the set {0, 1, 2, 3}
const C4 = cb.abal.C(4); // The set of fourth roots of unity is the set {1, i, -1, -i}
const G = cb.abal.group(Z4, (a, b) => (a + b) % 4); // The group G is the set Z4 with mod 4 addition
const H = cb.abal.group(C4, (z, w) => cb.comp.mul(z, w)); // The group H is the set C4 with complex multiplication
const F = cb.abal.isomorphism(G, H, (n) => cb.comp.round(cb.comp.pow(cb.comp.init(0, 1), n))); // The isomorphism F: G → H is defined by F(n) = i^n for all n in Z4
Several examples that are rather interesting can be seen here, and their source code is here.
Contributing
- Fork Chalkboard's GitHub repository. Make sure the fork is based on the main branch.
- Clone the repository, download the dev dependencies with `npm install`, and then make your contributions to your fork.
- When you're done, commit the changes to your fork with a detailed description.
- Open a pull request. It will be reviewed soon and then merged to the main branch.
NOTE: If you want to change the documentation, you will also have to clone the zushah.github.io repository because that's where the files are generated.
The changelog can be read here.
The Chalkboard library is available under the MIT License.
Acknowledgments
Thanks to @bhavjitChauhan for his contribution (here) to v1.3.0 Heaviside.
Thanks to @gyang0 for his contributions (here and here) to the documentation.
Thanks to @JentGent for his implementation (here) for calculating QR decomposition which was adapted into v1.7.0 Descartes.