Skip to content

Commit f1b8d40

Browse files
authored
Use math expressions (#453)
Enabled MathJax support[1]. [1] https://rust-lang.github.io/mdBook/format/mathjax.html
1 parent 402d5af commit f1b8d40

File tree

6 files changed

+8
-7
lines changed

6 files changed

+8
-7
lines changed

book.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ src = "text"
66
title = "PureScript by Example"
77
[output.html]
88
git-repository-url = "https://github.com/purescript-contrib/purescript-book"
9+
mathjax-support = true

text/chapter10.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ export const unsafeHead = arr => {
477477

478478
## Exercises
479479

480-
1. (Medium) Given a record that represents a quadratic polynomial `a*x^2 + b*x + c = 0`:
480+
1. (Medium) Given a record that represents a quadratic polynomial \\( a x ^ 2 + b x + c = 0 \\):
481481

482482
```hs
483483
type Quadratic = {

text/chapter11.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,15 @@ Tuple 3 ["gcdLog 21 15","gcdLog 6 15","gcdLog 6 9","gcdLog 6 3","gcdLog 3 3"]
342342
## Exercises
343343

344344
1. (Medium) Rewrite the `sumArray` function above using the `Writer` monad and the `Additive Int` monoid from the `monoid` package.
345-
1. (Medium) The _Collatz_ function is defined on natural numbers `n` as `n / 2` when `n` is even and `3 * n + 1` when `n` is odd. For example, the iterated Collatz sequence starting at `10` is as follows:
345+
1. (Medium) The _Collatz_ function is defined on natural numbers \\( n \\) as \\( n / 2 \\) when \\( n \\) is even and \\( 3 n + 1 \\) when \\( n \\) is odd. For example, the iterated Collatz sequence starting at \\( 10 \\) is as follows:
346346

347347
```text
348348
10, 5, 16, 8, 4, 2, 1, ...
349349
```
350350
351-
It is conjectured that the iterated Collatz sequence always reaches `1` after some finite number of applications of the Collatz function.
351+
It is conjectured that the iterated Collatz sequence always reaches \\( 1 \\) after some finite number of applications of the Collatz function.
352352
353-
Write a function that uses recursion to calculate how many iterations of the Collatz function are required before the sequence reaches `1`.
353+
Write a function that uses recursion to calculate how many iterations of the Collatz function are required before the sequence reaches \\( 1 \\).
354354
355355
Modify your function to use the `Writer` monad to log each application of the Collatz function.
356356

text/chapter12.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ and open `html/index.html`. You should see the Koch curve rendered to the canvas
558558
1. (Easy) Try changing the various numerical constants in the code to understand their effect on the rendered system.
559559
1. (Medium) Break the `lsystem` function into two smaller functions. The first should build the final sentence using repeated application of `concatMap`, and the second should use `foldM` to interpret the result.
560560
1. (Medium) Add a drop shadow to the filled shape using the `setShadowOffsetX`, `setShadowOffsetY`, `setShadowBlur`, and `setShadowColor` actions. _Hint_: use PSCi to find the types of these functions.
561-
1. (Medium) The angle of the corners is currently a constant (`tau/6`). Instead, it can be moved into the `Letter` data type, which allows it to be changed by the production rules:
561+
1. (Medium) The angle of the corners is currently a constant \\( \\tau / 6 \\). Instead, it can be moved into the `Letter` data type, which allows it to be changed by the production rules:
562562

563563
```haskell
564564
type Angle = Number

text/chapter4.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ This means that if the guard fails, then the current branch of the array compreh
364364

365365
1. (Easy) Write a function `isPrime`, which tests whether its integer argument is prime. _Hint_: Use the `factors` function.
366366
1. (Medium) Write a function `cartesianProduct` which uses do notation to find the _cartesian product_ of two arrays, i.e., the set of all pairs of elements `a`, `b`, where `a` is an element of the first array, and `b` is an element of the second.
367-
1. (Medium) Write a function `triples :: Int -> Array (Array Int)`, which takes a number `n` and returns all Pythagorean triples whose components (the `a`, `b`, and `c` values) are each less than or equal to `n`. A _Pythagorean triple_ is an array of numbers `[a, b, c]` such that `+ b² = c²`. _Hint_: Use the `guard` function in an array comprehension.
367+
1. (Medium) Write a function `triples :: Int -> Array (Array Int)`, which takes a number \\( n \\) and returns all Pythagorean triples whose components (the \\( a \\), \\( b \\), and \\( c \\) values) are each less than or equal to \\( n \\). A _Pythagorean triple_ is an array of numbers \\( [ a, b, c ] \\) such that \\( a ^ 2 + b ^ 2 = c ^ 2 \\). _Hint_: Use the `guard` function in an array comprehension.
368368
1. (Difficult) Write a function `primeFactors` which produces the [prime factorization](https://www.mathsisfun.com/prime-factorization.html) of `n`, i.e., the array of prime integers whose product is `n`. _Hint_: for an integer greater than 1, break the problem into two subproblems: finding the first factor and the remaining factors.
369369

370370
## Folds

text/chapter5.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ This example demonstrates that guards appear on the left of the equals symbol, s
9999
## Exercises
100100

101101
1. (Easy) Write the `factorial` function using pattern matching. _Hint_: Consider the two corner cases of zero and non-zero inputs. _Note_: This is a repeat of an example from the previous chapter, but see if you can rewrite it here on your own.
102-
1. (Medium) Write a function `binomial` which finds the coefficient of the x^`k`th term in the polynomial expansion of (1 + x)^`n`. This is the same as the number of ways to choose a subset of `k` elements from a set of `n` elements. Use the formula `n! / k! (n - k)!`, where `!` is the factorial function written earlier. _Hint_: Use pattern matching to handle corner cases. If it takes a long time to complete or crashes with an error about the call stack, try adding more corner cases.
102+
1. (Medium) Write a function `binomial` which finds the coefficient of the \\( x ^ k \\)th term in the polynomial expansion of \\( ( 1 + x ) ^ n \\). This is the same as the number of ways to choose a subset of \\( k \\) elements from a set of \\( n \\) elements. Use the formula \\( n! \\: / \\: k! \\, (n - k)! \\), where \\( ! \\) is the factorial function written earlier. _Hint_: Use pattern matching to handle corner cases. If it takes a long time to complete or crashes with an error about the call stack, try adding more corner cases.
103103
1. (Medium) Write a function `pascal` which uses [_Pascal`s Rule_](https://en.wikipedia.org/wiki/Pascal%27s_rule) for computing the same binomial coefficients as the previous exercise.
104104

105105
## Array Patterns

0 commit comments

Comments
 (0)