Giter Site home page Giter Site logo

math-as-code's Introduction

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

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 (π ≈ 3.14159)
  • := is for definition (A is defined as B)

In JavaScript:

// equality
2 === 3

// inequality
2 !== 3

// approximately equal
almostEqual(Math.PI, 3.14159, 1e-5)

function almostEqual(a, b, epsilon) {
  return Math.abs(a - b) <= epsilon
}

You might see the :=, =: and = symbols being used for definition.1

For example, the following defines x to be another name for 2kj.

equals1

In JavaScript, we might use var to define our variables and provide aliases:

var x = 2 * k * j

However, this is mutable, and only takes a snapshot of the values at that time. Some languages have pre-processor #define statements, which are closer to a mathematical define.

A more accurate define in JavaScript (ES6) might look a bit like this:

const f = (k, j) => 2 * k * j

The following, on the other hand, represents equality:

equals2

The above equation might be interpreted in code as an assertion:

console.assert(x === (2 * k * j))

square root and complex numbers

A square root operation is of the form:

squareroot

In programming we use a sqrt function, like so:

var x = 9;
console.log(Math.sqrt(x));
//=> 3

Complex numbers are expressions of the form complex, where a is the real part and b is the imaginary part. The imaginary number i is defined as:

imaginary.

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:

var math = require('mathjs')

var a = math.complex(3, -1)
//=> { re: 3, im: -1 }

var b = math.sqrt(-1)
//=> { re: 0, im: 1 }

console.log(math.multiply(a, b).toString())
//=> '1 + 3i'

The library also supports evaluating a string expression, so the above could be re-written as:

console.log(math.eval('(3 - i) * i').toString())
//=> '1 + 3i'

Other implementations:

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:

dotcross1

In programming languages we tend to use asterisk for multiplication:

var result = 5 * 4

Often, the multiplication sign is only used to avoid ambiguity (e.g. between two numbers). Here, we can omit it entirely:

dotcross2

If these variables represent scalars, the code would be:

var result = 3 * k * j

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

dotcross3

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 [x, y] to represent the 2D vectors.

var s = 3
var k = [ 1, 2 ]
var j = [ 2, 3 ]

var tmp = multiply(k, j)
var result = multiplyScalar(tmp, s)
//=> [ 6, 18 ]

Our multiply and multiplyScalar functions look like this:

function multiply(a, b) {
  return [ a[0] * b[0], a[1] * b[1] ]
}

function multiplyScalar(a, scalar) {
  return [ a[0] * scalar, a[1] * scalar ]
}

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.

dotcross4

It is a very common feature of linear algebra, and with a 3D vector it might look like this:

var k = [ 0, 1, 0 ]
var j = [ 1, 0, 0 ]

var d = dot(k, j)
//=> 0

The result 0 tells us our vectors are perpendicular. Here is a dot function for 3-component vectors:

function dot(a, b) {
  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
}

cross product

The cross symbol × can be used to denote the cross product of two vectors.

dotcross5

In code, it would look like this:

var k = [ 0, 1, 0 ]
var j = [ 1, 0, 0 ]

var result = cross(k, j)
//=> [ 0, 0, -1 ]

Here, we get [ 0, 0, -1 ], which is perpendicular to both k and j.

Our cross function:

function cross(a, b) {
  var ax = a[0], ay = a[1], az = a[2],
    bx = b[0], by = b[1], bz = b[2]

  var rx = ay * bz - az * by
  var ry = az * bx - ax * bz
  var rz = ax * by - ay * bx
  return [ rx, ry, rz ]
}

For other implementations of vector multiplication, cross product, and dot product:

sigma

The big Greek Σ (Sigma) is for Summation. In other words: summing up some numbers.

sigma

Here, i=1 says to start at 1 and end at the number above the Sigma, 100. These are the lower and upper bounds, respectively. The i to the right of the "E" tells us what we are summing. In code:

var sum = 0
for (var i = 1; i <= 100; i++) {
  sum += i
}

The result of sum is 5050.

Tip: With whole numbers, this particular pattern can be optimized to the following:

var n = 100 // upper bound
var sum = (n * (n + 1)) / 2

Here is another example where the i, or the "what to sum," is different:

sum2

In code:

var sum = 0
for (var i = 1; i <= 100; i++) {
  sum += (2 * i + 1)
}

The result of sum is 10200.

The notation can be nested, which is much like nesting a for loop. You should evaluate the right-most sigma first, unless the author has enclosed them in parentheses to alter the order. However, in the following case, since we are dealing with finite sums, the order does not matter.

sigma3

In code:

var sum = 0
for (var i = 1; i <= 2; i++) {
  for (var j = 4; j <= 6; j++) {
    sum += (3 * i * j)
  }
}

Here, sum will be 135.

capital Pi

The capital Pi or "Big Pi" is very similar to Sigma, except we are using multiplication to find the product of a sequence of values.

Take the following:

capitalPi

In code, it might look like this:

var value = 1
for (var i = 1; i <= 6; i++) {
  value *= i
}

Where value will evaluate to 720.

pipes

Pipe symbols, known as bars, can mean different things depending on the context. Below are three common uses: absolute value, Euclidean norm, and determinant.

These three features all describe the length of an object.

absolute value

pipes1

For a number x, |x| means the absolute value of x. In code:

var x = -5
var result = Math.abs(x)
// => 5

Euclidean norm

pipes4

For a vector v, ‖v‖ is the Euclidean norm of v. It is also referred to as the "magnitude" or "length" of a vector.

Often this is represented by double-bars to avoid ambiguity with the absolute value notation, but sometimes you may see it with single bars:

pipes2

Here is an example using an array [x, y, z] to represent a 3D vector.

var v = [ 0, 4, -3 ]
length(v)
//=> 5

The length function:

function length (vec) {
  var x = vec[0]
  var y = vec[1]
  var z = vec[2]
  return Math.sqrt(x * x + y * y + z * z)
}

Other implementations:

determinant

pipes3

For a matrix A, |A| means the determinant of matrix A.

Here is an example computing the determinant of a 2x2 matrix, represented by a flat array in column-major format.

var determinant = require('gl-mat2/determinant')

var matrix = [ 1, 0, 0, 1 ]
var det = determinant(matrix)
//=> 1

Implementations:

hat

In geometry, the "hat" symbol above a character is used to represent a unit vector. For example, here is the unit vector of a:

hat

In Cartesian space, a unit vector is typically length 1. That means each part of the vector will be in the range of -1.0 to 1.0. Here we normalize a 3D vector into a unit vector:

var a = [ 0, 4, -3 ]
normalize(a)
//=> [ 0, 0.8, -0.6 ]

Here is the normalize function, operating on 3D vectors:

function normalize(vec) {
  var x = vec[0]
  var y = vec[1]
  var z = vec[2]
  var squaredLength = x * x + y * y + z * z

  if (squaredLength > 0) {
    var length = Math.sqrt(squaredLength)
    vec[0] = x / length
    vec[1] = y / length
    vec[2] = z / length
  }
  return vec
}

Other implementations:

element

In set theory, the "element of" symbol and can be used to describe whether something is an element of a set. For example:

element1

Here we have a set of numbers A { 3, 9, 14 } and we are saying 3 is an "element of" that set.

A simple implementation in ES5 might look like this:

var A = [ 3, 9, 14 ]

A.indexOf(3) >= 0
//=> true

However, it would be more accurate to use a Set which only holds unique values. This is a feature of ES6.

var A = new Set([ 3, 9, 14 ])

A.has(3)
//=> true

The backwards is the same, but the order changes:

element2

You can also use the "not an element of" symbols and like so:

element3

common number sets

You may see some some large Blackboard letters among equations. Often, these are used to describe sets.

For example, we might describe k to be an element of the set .

real

Listed below are a few common sets and their symbols.

real numbers

The large describes the set of real numbers. These include integers, as well as rational and irrational numbers.

JavaScript treats floats and integers as the same type, so the following would be a simple test of our k ∈ ℝ example:

function isReal (k) {
  return typeof k === 'number' && isFinite(k);
}

Note: Real numbers are also finite, as in, not infinite.

rational numbers

Rational numbers are real numbers that can be expressed as a fraction, or ratio (like ). Rational numbers cannot have zero as a denominator.

This also means that all integers are rational numbers, since the denominator can be expressed as 1.

An irrational number, on the other hand, is one that cannot be expressed as a ratio, like π (PI).

integers

An integer, i.e. a real number that has no fractional part. These can be positive or negative.

A simple test in JavaScript might look like this:

function isInteger (n) {
  return typeof n === 'number' && n % 1 === 0
}

natural numbers

A natural number, a positive and non-negative integer. Depending on the context and field of study, the set may or may not include zero, so it could look like either of these:

{ 0, 1, 2, 3, ... }
{ 1, 2, 3, 4, ... }

The former is more common in computer science, for example:

function isNaturalNumber (n) {
  return isInteger(n) && n >= 0
}

complex numbers

A complex number is a combination of a real and imaginary number, viewed as a co-ordinate in the 2D plane. For more info, see A Visual, Intuitive Guide to Imaginary Numbers.

function

Functions are fundamental features of mathematics, and the concept is fairly easy to translate into code.

A function relates an input to an output value. For example, the following is a function:

function1

We can give this function a name. Commonly, we use ƒ to describe a function, but it could be named A(x) or anything else.

function2

In code, we might name it square and write it like this:

function square (x) {
  return Math.pow(x, 2)
}

Sometimes a function is not named, and instead the output is written.

function3

In the above example, x is the input, the relationship is squaring, and y is the output.

Functions can also have multiple parameters, like in a programming language. These are known as arguments in mathematics, and the number of arguments a function takes is known as the arity of the function.

function4

In code:

function length (x, y) {
  return Math.sqrt(x * x + y * y)
}

piecewise function

Some functions will use different relationships depending on the input value, x.

The following function ƒ chooses between two "sub functions" depending on the input value.

piecewise1

This is very similar to if / else in code. The right-side conditions are often written as "for x < 0" or "if x = 0". If the condition is true, the function to the left is used.

In piecewise functions, "otherwise" and "elsewhere" are analogous to the else statement in code.

function f (x) {
  if (x >= 1) {
    return (Math.pow(x, 2) - x) / x
  } else {
    return 0
  }
}

common functions

There are some function names that are ubiquitous in mathematics. For a programmer, these might be analogous to functions "built-in" to the language (like parseInt in JavaScript).

One such example is the sgn function. This is the signum or sign function. Let's use piecewise function notation to describe it:

sgn

In code, it might look like this:

function sgn (x) {
  if (x < 0) return -1
  if (x > 0) return 1
  return 0
}

See signum for this function as a module.

Other examples of such functions: sin, cos, tan.

function notation

In some literature, functions may be defined with more explicit notation. For example, let's go back to the square function we mentioned earlier:

function2

It might also be written in the following form:

mapsto

The arrow here with a tail typically means "maps to," as in x maps to x2.

Sometimes, when it isn't obvious, the notation will also describe the domain and codomain of the function. A more formal definition of ƒ might be written as:

funcnot

A function's domain and codomain is a bit like its input and output types, respectively. Here's another example, using our earlier sgn function, which outputs an integer:

domain2

The arrow here (without a tail) is used to map one set to another.

In JavaScript and other dynamically typed languages, you might use documentation and/or runtime checks to explain and validate a function's input/output. Example:

/**
 * Squares a number.
 * @param  {Number} a real number
 * @return {Number} a real number
 */
function square (a) {
  if (typeof a !== 'number') {
    throw new TypeError('expected a number')
  }
  return Math.pow(a, 2)
}

Some tools like flowtype attempt to bring static typing into JavaScript.

Other languages, like Java, allow for true method overloading based on the static types of a function's input/output. This is closer to mathematics: two functions are not the same if they use a different domain.

prime

The prime symbol () is often used in variable names to describe things which are similar, without giving it a different name altogether. It can describe the "next value" after some transformation.

For example, if we take a 2D point (x, y) and rotate it, you might name the result (x′, y′). Or, the transpose of matrix M might be named M′.

In code, we typically just assign the variable a more descriptive name, like transformedPosition.

For a mathematical function, the prime symbol often describes the derivative of that function. Derivatives will be explained in a future section. Let's take our earlier function:

function2

Its derivative could be written with a prime symbol:

prime1

In code:

function f (x) {
  return Math.pow(x, 2)
}

function fPrime (x) {
  return 2 * x
}

Multiple prime symbols can be used to describe the second derivative ƒ′′ and third derivative ƒ′′′. After this, authors typically express higher orders with roman numerals ƒIV or superscript numbers ƒ(n).

floor & ceiling

The special brackets ⌊x⌋ and ⌈x⌉ represent the floor and ceil functions, respectively.

floor

ceil

In code:

Math.floor(x)
Math.ceil(x)

When the two symbols are mixed ⌊x⌉, it typically represents a function that rounds to the nearest integer:

round

In code:

Math.round(x)

arrows

Arrows are often used in function notation. Here are a few other areas you might see them.

material implication

Arrows like and are sometimes used in logic for material implication. That is, if A is true, then B is also true.

material1

Interpreting this as code might look like this:

if (A === true) {
  console.assert(B === true)
}

The arrows can go in either direction , or both . When A ⇒ B and B ⇒ A, they are said to be equivalent:

material-equiv

equality

In math, the < > and are typically used in the same way we use them in code: less than, greater than, less than or equal to and greater than or equal to, respectively.

50 > 2 === true
2 < 10 === true
3 <= 4 === true
4 >= 4 === true

On rare occasions you might see a slash through these symbols, to describe not. As in, k is "not greater than" j.

ngt

The and are sometimes used to represent significant inequality. That is, k is an order of magnitude larger than j.

orderofmag

In mathematics, order of magnitude is rather specific; it is not just a "really big difference." A simple example of the above:

orderOfMagnitude(k) > orderOfMagnitude(j)

And below is our orderOfMagnitude function, using Math.trunc (ES6).

function log10(n) {
  // logarithm in base 10
  return Math.log(n) / Math.LN10
}

function orderOfMagnitude (n) {
  return Math.trunc(log10(n))
}

Note: This is not numerically robust.

See math-trunc for a ponyfill in ES5.

conjunction & disjunction

Another use of arrows in logic is conjunction and disjunction . They are analogous to a programmer's AND and OR operators, respectively.

The following shows conjunction , the logical AND.

and

In JavaScript, we use &&. Assuming k is a natural number, the logic implies that k is 3:

if (k > 2 && k < 4) {
  console.assert(k === 3)
}

Since both sides are equivalent , it also implies the following:

if (k === 3) {
  console.assert(k > 2 && k < 4)
}

The down arrow is logical disjunction, like the OR operator.

logic-or

In code:

A || B

logical negation

Occasionally, the ¬, ~ and ! symbols are used to represent logical NOT. For example, ¬A is only true if A is false.

Here is a simple example using the not symbol:

negation

An example of how we might interpret this in code:

if (x !== y) {
  console.assert(!(x === y))
}

Note: The tilde ~ has many different meanings depending on context. For example, row equivalence (matrix theory) or same order of magnitude (discussed in equality).

intervals

Sometimes a function deals with real numbers restricted to some range of values, such a constraint can be represented using an interval

For example we can represent the numbers between zero and one including/not including zero and/or one as:

  • Not including zero or one: interval-opened-left-opened-right
  • Including zero or but not one: interval-closed-left-opened-right
  • Not including zero but including one: interval-opened-left-closed-right
  • Including zero and one: interval-closed-left-closed-right

For example we to indicate that a point x is in the unit cube in 3D we say:

interval-unit-cube

In code we can represent an interval using a two element 1d array:

var nextafter = require('nextafter')

var a = [nextafter(0, Infinity), nextafter(1, -Infinity)]     // open interval
var b = [nextafter(0, Infinity), 1]                           // interval closed on the left 
var c = [0, nextafter(1, -Infinity)]                          // interval closed on the right
var d = [0, 1]                                                // closed interval

Intervals are used in conjunction with set operations:

  • intersection e.g. interval-intersection
  • union e.g. interval-union
  • difference e.g. interval-difference-1 and interval-difference-2

In code:

var Interval = require('interval-arithmetic')
var nextafter = require('nextafter')

var a = Interval(3, nextafter(5, -Infinity))
var b = Interval(4, 6)

Interval.intersection(a, b)
// {lo: 4, hi: 4.999999999999999}

Interval.union(a, b)
// {lo: 3, hi: 6}

Interval.difference(a, b)
// {lo: 3, hi: 3.9999999999999996}

Interval.difference(b, a)
// {lo: 5, hi: 6}

See:

more...

Like this guide? Suggest some more features or send us a Pull Request!

Contributing

For details on how to contribute, see CONTRIBUTING.md.

License

MIT, see LICENSE.md for details.

math-as-code's People

Contributors

0xflotus avatar asmeurer avatar brainsucker avatar cbrown132 avatar chocolateboy avatar conaclos avatar ewjmulder avatar luxcoldury avatar mattdesl avatar mauriciopoppe avatar mrdoob avatar nshen avatar quinn-dougherty avatar styfle avatar swerwath avatar wthtw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

math-as-code's Issues

"In mathematics, the := =: and = symbols are used for definition."

In mathematics, the := =: and = symbols are used for definition.

Are all three equivalent? If not, would you kindly explain the differences? If so, would you mention please that they are exchangeable?

Thank you _very much_ for writing this. I have wanted a document like this forever.

A draft for exclamation mark

exclamation mark

The exclamation mark has many uses in mathematics. We can take a look at these as follows.

factorial

Exclamation mark ! in mathematics typically denotes the factorial operation.

factorial

This expression means "the product of the integers from 1 to n". For example, 4! (read four factorial) is 4 × 3 × 2 × 1 = 24.

In JavaScript:

function factorialize(num) {
  if (num < 0) 
        return -1;
  else if (num == 0) 
      return 1;
  else {
      return (num * factorialize(num - 1));
  }
}
factorialize(5);

double factorial

The double factorial is an extension onto the normal factorial function. It is denoted with two exclamation points: a!! .

The double factorial of an integer n is defined recursively as:

doublefactorial1

The double factorial is not defined when n is a negative even integer. Also do not confuse the double factorial for a factorial computed twice.

doublefactorial2

The double in double factorial represents the increment between the values of the terms when the factorial is expanded into a product. In the case of a regular factorial, each factor is decremented by one, from the number 'a' to 1. In the case of a double factorial, each factor is decremented by two.

doublefactorial3

The double factorial terminates with the sequence of evens, for example: 4 × 2 × 0!! or the sequence of odds: eg 5 × 3 × 1!! where 1!! = 0!! = 1.

In JavaScript:

function doublefactorial(num) {
  if (num < 0)
    return -1;
  else if (num == 0 || num == 1)
    return 1;
  return (num * doublefactorial(n - 2));
}

uniqueness

Additionally, exclamation mark can also represent uniqueness in mathematics and logic. The phrase "there is one and only one" is used to indicate that exactly one object with a certain property exists and this sort of quantification is known as uniqueness quantification or unique existential quantification.

Uniqueness quantification is often denoted with the symbols ∃! or ∃=1. For example, the formal statement

uniqueness

may be read aloud as "there is exactly one natural number n such that n - 2 = 4".

subfactorial

If exclamation mark used in front of a number, it can represent a subfactorial. The nth subfactorial (also called the derangement number) is the number of permutations of n objects in which no object appears in its natural place (i.e., "derangements").

The first few values of !n for n=1, 2, ... are 0, 1, 2, 9, 44, 265, 1854, 14833, ... For example, the only derangements of {1,2,3} are {2,3,1} and {3,1,2}, so !3=2. Similarly, the derangements of {1,2,3,4} are {2,1,4,3}, {2,3,4,1}, {2,4,1,3}, {3,1,4,2}, {3,4,1,2}, {3,4,2,1}, {4,1,2,3}, {4,3,1,2}, and {4,3,2,1}, so !4=9.

Sums and formulas for !n include:

subfactorial

modality

In linear logic, the exclamation mark denotes one of the modalities that control weakening and contraction.

The exclamation mark is also used in programming, but not the way it's in mathematics. Several computer languages use "!" at the beginning of an expression to denote logical negation: e.g. "!A" means "the logical negation of A", also called "not A" and A != B means "A is not equal to B".

Resources
https://www.wikiwand.com/en/Exclamation_mark
https://www.wikiwand.com/en/Uniqueness_quantification
https://www.wikiwand.com/en/Derangement
http://mathworld.wolfram.com/Subfactorial.html
https://plato.stanford.edu/entries/logic-linear/
https://math.stackexchange.com/questions/67801/what-does-the-exclamation-mark-do
http://math.wikia.com/wiki/Double_factorial
https://medium.freecodecamp.org/how-to-factorialize-a-number-in-javascript-9263c89a4b38

Ambiguity in the variable definition section

I think that it should be noted that the JS code isn't equivalent, as in math the '=' sign denotes an alias when used as presented.

I saw that you noted that 'x' is just another name, but further clarification would be beneficial in my opinion.

Hope this helps.

PS: Love your effort. I think it will be useful for a lot of people. If I get some free time, expect some pull requests from me. Keep up the good work.

:heart:

I thought I was the only one who had a hard time with mathmatical notation. This is exactly what I needed (and what I always thought would be a great idea) to aid my personal CS/game programming studies.

Just thought I'd say thanks! ❤️

Explain concepts used in papers

Like

"Let x be ..." means x will be defined there, either explicit (you can code it directly) or as an element from an not fully known set, which should be explored in the remainder of the theorem.

"... then there exists a y ..." means y must exist, if the preconditions are met, but we do not neccessarly know how to find y.

And metaconcepts like:

In a paper the author can define anything he wants. There are many papers, which define "if CONDITION is met, the element is called admissable", but there is no general concept of admissable.
Authors also can redefine existing concepts like "in the following we assume all vectors are normed" (this means you need to make sure in your code, your vectors are normed). Some will even admit some easy going notation like "with a bit abusive notation we can write ..."

dot and cross product

Matrix A dot Matrix B

where the dot is usually a small circle (not sure if there's a unicode character for it)

cross product is also a peculiar x, but is not the same as matrix multiplication or component wise multiplication

Feature: transpiler

These explanations are really cool, thanks for this. It turns something abstract into something tangible that a developer can play with. To build on this, I would love to see a transpiler that leverages these explanations to turn mathematics into executable javascript, and potentially turn executable javascript into mathematical notation. It would go a long way towards demystifying scientific research for the layprogrammer.

Calculating Vector Magnitude

What do you think of me adding a pull request to add the vector variable to calculate vector magnitude? Can be done easily with Pythagorean theorem which most people will understand.

Ambiguity about Real numbers

Note: Real numbers are also finite, as in, not infinite.

I don't think this expresses well what it is trying to express. I'm guessing that it is referring to the check && isFinite(k) to exclude ∞ (Infinity) from ℝ, which in itself is correct, as infinity is not a Real number. But, saying that "infinity is not a real number" is different from saying that "real numbers are finite". This second way of saying it may confuse people with the fact that "ℝ is of infinite size", i.e. that "there are infinite real numbers".

What I think may mark the difference is that, in english, "Real numbers" usually refers to all of them as a whole, while "A Real number" refers explicitly to any individual Real number. I think a better way of saying this could be something along the lines of "Note: Infinity is not a Real number" or maybe "A Real number is also finite, as in, ∞ ∉ ℝ").

Elements and Sets

I think it might be more mathematically "correct" to use Sets instead of Arrays for Elements ("In"/"Not In"). Most of the time, mathematicians make the assumption that they are working on sets (uniqueness, abstract ordering) instead of lists. I know it depends on usage, especially with respect to game and graphics dev, but I think the ES6/Harmony API for Set is pretty nifty!

Consider writing this as Jupyter notebooks instead of JavaScript

GitHub supports executing and rendering Jupyter notebooks which would be much more maintainable and expressive (especially since you can use numpy to execute all kinds of math operations out of the box).

Another big benefit is that you can have GitHub render math notations for you instead of including lots of images in the repo (+ you get retina support!).

Example on GitHub using Jupyter:

A C++ version of this notebook with some extra notations and implementations

I have personally wrote C++ code representations for all the functions and notations referred in the current readme file and also have implemented some extra features, such as 2D point, 2D line class, 3D point, 3D vector class, and all their calculative functions(addition, negation, dot product, scalar product,perpendicular eqn of a line, parallel eqn of a line). Plus for the ease of use of geometry, I have implemented translation, rotation, scaling etc functions for the above classes. If permitted, I would like to add them in a new file dedicated towards C/C++ developers.

Better search

Imagine I was looking for some symbol description.
What if I could come here, ⌘ + f, and then search for something, that looks like what I'm looking for.
For example <=> or /=.

Python version?

I really love this project, and think it could be a fantastic way for math and physics students in particular to become familiar with a programming language.

Any prospect for a Python language version?

SVG Rendering

Some of the SVGs are failing because the site hosting them is 503ing.

Could switch to @blixt's SVG Latex viewer. Or maybe save them (eg gh-readme-scrape) and host them in GitHub since this guide has stabilized for the time being.

code comment typo in 'intervals' section

the code example goes like this

var b = [nextafter(0, Infinity), 1]                           // interval closed on the left 
var c = [0, nextafter(1, -Infinity)]                          // interval closed on the right

however, I think the correct version is

var b = [nextafter(0, Infinity), 1]                           // interval closed on the right
var c = [0, nextafter(1, -Infinity)]                          // interval closed on the left

Sigma n or i

at the Sigma part:

var sum = 0
for (var i = 1; i <= 100; i++) {
  sum += i
}
var n = 100 // upper bound
var sum = (n * (n + 1)) / 2

shouldn't n be i?

Off-by-one in Sigma

sum([k for k in range(100)])

output: 4950

The reference said output: 5050
Which would be

sum([i for i in range(101)])

prime symbol

primes represent the next value, for example:

A' = A * MVP
can be thought of as
A *= MVP

The single apostrophe is sometimes referred to as prime. "Matrix A prime is the result of matrix A times matrix MVP"

Graph Theory

Could I potentially start a section on basic graph theory?

Add (first order) logic

First of all, I think this repository is a great initiative to help programmers delve into and understand theoretical (computer science) literature. However, it would be great if there were more content about the symbols used in (First Order) Logic. Logic sentences are often comprised of just these symbols, making them very hard to read without an intuitive understanding of them.

Personally, I find it very helpful to think about them programmatically when reading them, though not all symbols are equally simple to mentally model.

http://tug.ctan.org/info/undergradmath/undergradmath.pdf provides a nice summary of symbols


#12 is an example of another person with difficulties in this area.

More Features

The guide is not complete. More planned features:

  • cross product
  • tensor product
  • delta
  • dot product
    • common patterns like clamped dot product with angled brackets too specific I think
  • indefinite integral
  • ƒ - function
  • Heaviside function (step()) possibly too specific; already have sgn
  • common patterns like greek letters vs latin ?

And generally:

  • converting some complex/intimidating expressions into code
  • notation-to-code examples from real papers (e.g. graphics programming papers)

Some ideas

  • Missing mathematic symbols like "it exists" or "for all"
  • transitivity, commutativity ... maths vs. informatics
  • column vector (french notation) vs line column (american notation) and therefore the transpose notation.
  • you should add a note concerning implications/risks using almostEqual (ae). A ae B and B ec => A ae C ?
  • In almostEqual() code you should use ulp instead of epsilon (ulp are the least significant bit for float). So the current code is ok for pedagogic point of view. Could be nice to add a note on this topic.
  • A note concerning strict float comparison (a = b).
  • Rational number. You can give a example: 3/5 = (3 * 65536) / (5 * 65536) = 229376/65536 = Q16(229376) So float 0.6 can be written as int 229376.
  • logs: log2(1024) = log2(2^10) = 10.
  • logs: log(1000) = log10(10^3) = 3
  • round: x in [0.0 ... 0.4] => 0 else (x in [0.5 .. 0.9]) => 1
    In C: round(float x) = (int) (x + 0.5f); because cast downgrade the value
  • Can show the different norms for matrix (by column, by lines)
  • discrete time vs continuous time
  • variance / covariance can be inspired by: https://www.youtube.com/watch?v=ieL0jxzLhCE&list=PLX2gX-ftPVXU3oUFNATxGXY90AULiqnWT&index=19

Number hierarchy and floating point numbers

It's probably worth noting that floating point numbers are rational numbers (as well as real and complex).

The number hierarchy is usually ordered by inclusion:

  1. Natural
  2. Integers
  3. Rational
  4. Real
  5. Complex

It helps in explaining how each type of number contains the previous numbers.

Great page. Just trying to help. Thanks!

Improve rendering of images

It appears many notations can also be expressed as unicode. Not sure if it's useful, but it might be worth considering. So far these are the pros / cons I could think of:

pro

  • sharable! It's just plain text so it'll work anywhere.
  • crisper rendering, though saving mathjax output as svg might achieve the same

con

  • it's visually different from formulas out in the wild (e.g. LaTeX rendering)

Example

100
 ∑ i
i=1
100
 ∑ (2i+1)
i=1
 3   6
 ∑   ∑ (3ij)
i=1 j=4
 6
 Π i
i=1
â

Thanks!

sqrt(x^2) is not equal to x

The readme says sqrt(x^2) = x. But this is not true in general (take x=-1). In general it's equal to +/- x.

It probably should say sqrt(x)^2 = x, which is always true, and can be taken as a "definition" of the square root.

Add demo gif to README

Disclaimer: This is a bot

It looks like your repo is trending. The github_trending_videos Instgram account automatically shows the demo gifs of trending repos in Github.

Your README doesn't seem to have any demo gifs. Add one and the next time the parser runs it will pick it up and post it on its Instagram feed. If you don't want to just close this issue we won't bother you again.

natural numbers

{ 0, 1, 2, 3, ... }
{ 1, 2, 3, 4, ... }

The latter is more common in computer science, for example:

function isNaturalNumber (n) {
  return isInteger(n) && n >= 0
}

the latter one is n > 0, not n>= 0
so which one is more common in computer science?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.