Experience-Monks / math-as-code

a cheat-sheet for mathematical notation in code form
MIT License
14.98k stars 1.07k forks source link

A draft for exclamation mark #70

Open maidis opened 5 years ago

maidis commented 5 years ago

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