Experience-Monks / Experience-Monks/math-as-code

A draft for exclamation mark

Open
#70 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
15.5k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

## 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](http://latex.codecogs.com/svg.latex?n%21)

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:

```js
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](http://latex.codecogs.com/svg.latex?n%21%21%3D%20%5Cbegin%7Bcases%7D%201%2C%20%26%20%5Ctext%7Bif%20%7D%20n%20%3D%200%5C%20or%5C%20n%20%3D%201%5C%5C%20n%20%5Ctimes%20%28n-2%29%21%21%2C%20%26%20%5Ctext%7Bif%20%7D%20n%20%5Cgeq%202%20%5Cend%7Bcases%7D)

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](http://latex.codecogs.com/svg.latex?a%21%21%5Cneq%28a%21%29%21)

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](http://latex.codecogs.com/svg.latex?a%21%3D%20a%28a-1%29%28a-2%29%5Ccdots%203%5Ctimes%202%5Ctimes%201%20%5Cpar%20a%21%21%3D%20a%28a-2%29%28a-4%29%28a-6%29%5Ccdots)

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:

```js
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](http://latex.codecogs.com/svg.latex?%5Cexists%21%20n%20%5Cin%20%5Cmathbb%7BN%7D%5C%2C%28n%20-%202%20%3D%204%29)

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](http://latex.codecogs.com/svg.latex?%21n%3Dn%21%5Csum%20_%7Bi%3D0%7D%5E%7Bn%7D%7B%5Cfrac%7B%28-1%29%5Ei%7D%7Bi%21%7D%7D)

#### 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.