Skip to content

Commit dadc06d

Browse files
committed
Merge branch 'master' of https://github.com/Jam3/math-as-code
2 parents d05dc6f + 6820127 commit dadc06d

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

README.md

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ For simplicity, many of the code examples here operate on floating point values
1919
# contents
2020

2121
- [variable name conventions](#variable-name-conventions)
22-
- [equals `=` `` `` `=:`](#equals-symbols)
22+
- [equals `=` `` `` `:=`](#equals-symbols)
2323
- [dot & cross `` `×` ``](#dot--cross)
2424
- [scalar multiplication](#scalar-multiplication)
2525
- [vector multiplication](#vector-multiplication)
@@ -51,11 +51,12 @@ This will also be the format of this guide.
5151

5252
## equals symbols
5353

54-
There are a number of symbols resembling the equals sign `=`. Here are three common examples:
54+
There are a number of symbols resembling the equals sign `=`. Here are a few common examples:
5555

5656
- `=` is for equality (values are the same)
5757
- `` is for inequality (value are not the same)
5858
- `` is for approximately equal to (`π ≈ 3.14159`)
59+
- `:=` is for definition (A is defined as B)
5960

6061
In JavaScript:
6162

@@ -74,44 +75,39 @@ function almostEqual(a, b, epsilon) {
7475
}
7576
```
7677

77-
In mathematics, the `:=` `=:` and `=` symbols are used for *definition*. The following defines *x* to be another name for 2*kj*.
78+
You might see the `:=`, `=:` and `=` symbols being used for *definition*.
7879

79-
![equals1](img/equals1.png)
80+
For example, the following defines *x* to be another name for 2*kj*.
8081

81-
<!-- x = 2kj -->
82+
![equals1](http://latex.codecogs.com/svg.latex?x%20%3A%3D%202kj)
8283

83-
In JavaScript, we might use `=` to *define* our variables and provide aliases. The above equation defines the following:
84+
<!-- x := 2kj -->
8485

85-
```js
86-
var x = 2 * k * j
87-
```
86+
In JavaScript, we might use `var` to *define* our variables and provide aliases:
8887

8988
```js
90-
var k = x / (2 * j)
91-
```
92-
93-
```js
94-
var j = x / (2 * k)
89+
var x = 2 * k * j
9590
```
9691

9792
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*.
9893

99-
A more accurate representation in JavaScript (ES6) might look a bit like this:
94+
A more accurate *define* in JavaScript (ES6) might look a bit like this:
10095

10196
```js
10297
const f = (k, j) => 2 * k * j
10398
```
10499

105-
<!--
100+
The following, on the other hand, represents equality:
106101

107-
///// Need a code sample?
108-
///// Maybe better suited in another place?
102+
![equals2](http://latex.codecogs.com/svg.latex?x%20%3D%202kj)
109103

110-
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.
104+
<!-- x = 2kj -->
111105

112-
![equals2](img/equals2.png)
106+
The above equation might be interpreted in code as an [assertion](https://developer.mozilla.org/en-US/docs/Web/API/console/assert):
113107

114-
\bar{AB} \cong \bar{CD} -->
108+
```js
109+
console.assert(x === (2 * k * j))
110+
```
115111

116112
## dot & cross
117113

0 commit comments

Comments
 (0)