back to home

Experience-Monks / math-as-code

a cheat-sheet for mathematical notation in code form

15,471 stars
1,101 forks
36 issues

AI Architecture Analysis

This repository is indexed by RepoMind. By analyzing Experience-Monks/math-as-code in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.

Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.

Source files are only loaded when you start an analysis to optimize performance.

Embed this Badge

Showcase RepoMind's analysis directly in your repository's README.

[![Analyzed by RepoMind](https://img.shields.io/badge/Analyzed%20by-RepoMind-4F46E5?style=for-the-badge)](https://repomind.in/repo/Experience-Monks/math-as-code)
Preview:Analyzed by RepoMind

Repository Overview (README excerpt)

Crawler view

math-as-code >Chinese translation (中文版) >Python version (English) This is a reference to ease developers into mathematical notation by showing comparisons with JavaScript code. Motivation: Academic papers can be intimidating for self-taught game and graphics programmers. :) This guide is not yet finished. If you see errors or want to contribute, please open a ticket or send a PR. > **Note**: For brevity, some code examples make use of npm packages. You can refer to their GitHub repos for implementation details. foreword Mathematical symbols can mean different things depending on the author, context and the field of study (linear algebra, set theory, etc). This guide may not cover *all* uses of a symbol. In some cases, real-world references (blog posts, publications, etc) will be cited to demonstrate how a symbol might appear in the wild. For a more complete list, refer to Wikipedia - List of Mathematical Symbols. For simplicity, many of the code examples here operate on floating point values and are not numerically robust. For more details on why this may be a problem, see Robust Arithmetic Notes by Mikola Lysenko. contents • variable name conventions • equals • square root and complex numbers * * • dot & cross • scalar multiplication • vector multiplication • dot product • cross product • sigma - *summation* • capital Pi - *products of sequences* • pipes • absolute value • Euclidean norm • determinant • hat ** ** - *unit vector* • "element of" • common number sets • function • piecewise function • common functions • function notation • prime • floor & ceiling • arrows • material implication • equality • conjunction & disjunction • logical negation • intervals • more... variable name conventions There are a variety of naming conventions depending on the context and field of study, and they are not always consistent. However, in some of the literature you may find variable names to follow a pattern like so: • *s* - italic lowercase letters for scalars (e.g. a number) • **x** - bold lowercase letters for vectors (e.g. a 2D point) • **A** - bold uppercase letters for matrices (e.g. a 3D transformation) • *θ* - italic lowercase Greek letters for constants and special variables (e.g. polar angle *θ*, *theta*) This will also be the format of this guide. equals symbols There are a number of symbols resembling the equals sign . Here are a few common examples: • is for equality (values are the same) • is for inequality (value are not the same) • is for approximately equal to ( ) • is for definition (A is defined as B) In JavaScript: You might see the , and symbols being used for *definition*. [1] For example, the following defines *x* to be another name for 2*kj*. In JavaScript, we might use to *define* our variables and provide aliases: However, this is mutable, and only takes a snapshot of the values at that time. Some languages have pre-processor statements, which are closer to a mathematical *define*. A more accurate *define* in JavaScript (ES6) might look a bit like this: The following, on the other hand, represents equality: The above equation might be interpreted in code as an assertion: square root and complex numbers A square root operation is of the form: In programming we use a function, like so: Complex numbers are expressions of the form , where is the real part and is the imaginary part. The imaginary number is defined as: . In JavaScript, there is no built-in functionality for complex numbers, but there are some libraries that support complex number arithmetic. For example, using mathjs: The library also supports evaluating a string expression, so the above could be re-written as: Other implementations: • immutable-complex • complex-js • Numeric-js dot & cross The dot and cross symbols have different uses depending on context. They might seem obvious, but it's important to understand the subtle differences before we continue into other sections. scalar multiplication Both symbols can represent simple multiplication of scalars. The following are equivalent: In programming languages we tend to use asterisk for multiplication: Often, the multiplication sign is only used to avoid ambiguity (e.g. between two numbers). Here, we can omit it entirely: If these variables represent scalars, the code would be: vector multiplication To denote multiplication of one vector with a scalar, or element-wise multiplication of a vector with another vector, we typically do not use the dot or cross symbols. These have different meanings in linear algebra, discussed shortly. Let's take our earlier example but apply it to vectors. For element-wise vector multiplication, you might see an open dot to represent the Hadamard product. [2] In other instances, the author might explicitly define a different notation, such as a circled dot or a filled circle . [3] Here is how it would look in code, using arrays to represent the 2D vectors. Our and functions look like this: Similarly, matrix multiplication typically does not use the dot or cross symbol . Matrix multiplication will be covered in a later section. dot product The dot symbol can be used to denote the *dot product* of two vectors. Sometimes this is called the *scalar product* since it evaluates to a scalar. It is a very common feature of linear algebra, and with a 3D vector it might look like this: The result tells us our vectors are perpendicular. Here is a function for 3-component vectors: cross product The cross symbol can be used to denote the *cross product* of two vectors. In code, it would look like this: Here, we get , which is perpendicular to both **k** and **j**. Our function: For other implementations of vector multiplication, cross product, and dot product: • gl-vec3 • gl-vec2 • vectors - includes n-dimensional sigma The big Greek (Sigma) is for Summation. In other words: summing up some numbers. Here, says to start at and end at the number above the Sigma, . These are the lower an…