typos
This commit is contained in:
@@ -237,7 +237,7 @@ x1 + x2 + x3 + x4 + x5 + x6
|
||||
|
||||
Someone doesn't need to know `Julia`'s syntax to guess what this computes, save for the idiosyncratic tuple assignment used, which could have been bypassed at the cost of even more typing.
|
||||
|
||||
A more efficient means to do, as each componenent isn't named, this would be to store the data in a container:
|
||||
A more efficient means to do, as each component isn't named, this would be to store the data in a container:
|
||||
|
||||
```{julia}
|
||||
xs = [1, 2, 3, 4, 5, 6] # as a vector
|
||||
@@ -275,7 +275,7 @@ reduce(*, xs; init=1) # prod(xs)
|
||||
|
||||
The functions (`+` and `*`) are binary operators and are serially passed the running value (or `init`) and the new term from the iterator.
|
||||
|
||||
The initial value above is the unit for the operation (which could be found programatically by `zero(eltype(xs))` or `one(eltype(xs))` where the type is useful for better performance).
|
||||
The initial value above is the unit for the operation (which could be found programmatically by `zero(eltype(xs))` or `one(eltype(xs))` where the type is useful for better performance).
|
||||
|
||||
The `foldl` and `foldr` functions are similar to `reduce` only left (and right) associativity is guaranteed. This example uses the binary, infix `Pair` operator, `=>`, to illustrate the difference:
|
||||
|
||||
@@ -289,7 +289,7 @@ and
|
||||
foldr(=>, xs)
|
||||
```
|
||||
|
||||
Next, we do a slighlty more complicated problem.
|
||||
Next, we do a slightly more complicated problem.
|
||||
|
||||
Recall the distance formula between two points, also called the *norm*. It is written here with the square root on the other side: $d^2 = (x_1-y_1)^2 + (x_0 - y_0)^2$. This computation can be usefully generalized to higher dimensional points (with $n$ components each).
|
||||
|
||||
@@ -303,7 +303,7 @@ sum((xs - ys).^2)
|
||||
```
|
||||
|
||||
|
||||
This formula is a sum after applying an operation to the paired off values. Using a geneator that sum would look like:
|
||||
This formula is a sum after applying an operation to the paired off values. Using a generator that sum would look like:
|
||||
|
||||
```{julia}
|
||||
sum((xi - yi)^2 for (xi, yi) in zip(xs, ys))
|
||||
@@ -366,7 +366,7 @@ bs
|
||||
```
|
||||
|
||||
|
||||
The `bs` are represented with an iterator and can be collected to yield the values, though often this is unecessary and possibly a costly step:
|
||||
The `bs` are represented with an iterator and can be collected to yield the values, though often this is unnecessary and possibly a costly step:
|
||||
|
||||
```{julia}
|
||||
collect(bs), sum(bs)
|
||||
|
||||
Reference in New Issue
Block a user