mirror of
https://github.com/Experience-Monks/math-as-code.git
synced 2026-04-23 03:00:42 -04:00
38
README.md
38
README.md
@@ -19,7 +19,7 @@ For simplicity, many of the code examples here operate on floating point values
|
||||
# contents
|
||||
|
||||
- [variable name conventions](#variable-name-conventions)
|
||||
- [equals `=` `≈` `≠` `=:`](#equals-symbols)
|
||||
- [equals `=` `≈` `≠` `:=`](#equals-symbols)
|
||||
- [dot & cross `∙` `×` `∘`](#dot--cross)
|
||||
- [scalar multiplication](#scalar-multiplication)
|
||||
- [vector multiplication](#vector-multiplication)
|
||||
@@ -51,11 +51,12 @@ This will also be the format of this guide.
|
||||
|
||||
## equals symbols
|
||||
|
||||
There are a number of symbols resembling the equals sign `=`. Here are three common examples:
|
||||
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:
|
||||
|
||||
@@ -74,44 +75,39 @@ function almostEqual(a, b, epsilon) {
|
||||
}
|
||||
```
|
||||
|
||||
In mathematics, the `:=` `=:` and `=` symbols are used for *definition*. The following defines *x* to be another name for 2*kj*.
|
||||
You might see the `:=`, `=:` and `=` symbols being used for *definition*.
|
||||
|
||||

|
||||
For example, the following defines *x* to be another name for 2*kj*.
|
||||
|
||||
<!-- x = 2kj -->
|
||||

|
||||
|
||||
In JavaScript, we might use `=` to *define* our variables and provide aliases. The above equation defines the following:
|
||||
<!-- x := 2kj -->
|
||||
|
||||
In JavaScript, we might use `var` to *define* our variables and provide aliases:
|
||||
|
||||
```js
|
||||
var x = 2 * k * j
|
||||
```
|
||||
|
||||
```js
|
||||
var k = x / (2 * j)
|
||||
```
|
||||
|
||||
```js
|
||||
var j = x / (2 * k)
|
||||
```
|
||||
|
||||
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 representation in JavaScript (ES6) might look a bit like this:
|
||||
A more accurate *define* in JavaScript (ES6) might look a bit like this:
|
||||
|
||||
```js
|
||||
const f = (k, j) => 2 * k * j
|
||||
```
|
||||
|
||||
<!--
|
||||
The following, on the other hand, represents equality:
|
||||
|
||||
///// Need a code sample?
|
||||
///// Maybe better suited in another place?
|
||||

|
||||
|
||||
The `≅` symbol is for [*congruence*](https://en.wikipedia.org/wiki/Congruence_%28geometry%29). For example, here the line segment AB is congruent with the segment CD.
|
||||
<!-- x = 2kj -->
|
||||
|
||||

|
||||
The above equation might be interpreted in code as an [assertion](https://developer.mozilla.org/en-US/docs/Web/API/console/assert):
|
||||
|
||||
\bar{AB} \cong \bar{CD} -->
|
||||
```js
|
||||
console.assert(x === (2 * k * j))
|
||||
```
|
||||
|
||||
## dot & cross
|
||||
|
||||
|
||||
Reference in New Issue
Block a user