Update fibonacci example and add round
function
This commit is contained in:
parent
f33103cf58
commit
66de90437f
10
README.md
10
README.md
@ -37,7 +37,7 @@ A [gentle introduction][tutorial] to Typst is available in our documentation.
|
|||||||
However, if you want to see the power of Typst encapsulated in one image, here
|
However, if you want to see the power of Typst encapsulated in one image, here
|
||||||
it is:
|
it is:
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img alt="Example" width="900" src="https://user-images.githubusercontent.com/38260698/226794868-90911832-433a-4575-be88-42d582589403.png"/>
|
<img alt="Example" width="900" src="https://user-images.githubusercontent.com/17899797/228031796-ced0e452-fcee-4ae9-92da-b9287764ff25.png"/>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
@ -78,13 +78,13 @@ Let's dissect what's going on:
|
|||||||
|
|
||||||
= Fibonacci sequence
|
= Fibonacci sequence
|
||||||
The Fibonacci sequence is defined through the
|
The Fibonacci sequence is defined through the
|
||||||
_recurrence relation_ $F_n = F_(n-1) + F_(n-2)$.
|
recurrence relation $F_n = F_(n-1) + F_(n-2)$.
|
||||||
It can also be expressed in closed form:
|
It can also be expressed in _closed form:_
|
||||||
|
|
||||||
$ F_n = floor(1 / sqrt(5) phi.alt^n), quad
|
$ F_n = round(1 / sqrt(5) phi.alt^n), quad
|
||||||
phi.alt = (1 + sqrt(5)) / 2 $
|
phi.alt = (1 + sqrt(5)) / 2 $
|
||||||
|
|
||||||
#let count = 10
|
#let count = 8
|
||||||
#let nums = range(1, count + 1)
|
#let nums = range(1, count + 1)
|
||||||
#let fib(n) = (
|
#let fib(n) = (
|
||||||
if n <= 2 { 1 }
|
if n <= 2 { 1 }
|
||||||
|
@ -18,11 +18,12 @@ description: |
|
|||||||
- Fixed [matrices]($func/mat) with explicit delimiter
|
- Fixed [matrices]($func/mat) with explicit delimiter
|
||||||
- Fixed build of CLI if `git` is not installed
|
- Fixed build of CLI if `git` is not installed
|
||||||
- Links in bibliographies are now affected by link styling
|
- Links in bibliographies are now affected by link styling
|
||||||
`[#counter(..).update(0)]`
|
|
||||||
- Added support for disabling [matrix]($func/mat) and [vector]($func/vec)
|
- Added support for disabling [matrix]($func/mat) and [vector]($func/vec)
|
||||||
delimiters. Generally with `[#set math.mat(delim: none)]` or one-off with
|
delimiters. Generally with `[#set math.mat(delim: none)]` or one-off with
|
||||||
`[$mat(delim: #none, 1, 2; 3, 4)$]`.
|
`[$mat(delim: #none, 1, 2; 3, 4)$]`.
|
||||||
|
- Added [`round`]($func/round) function for equations
|
||||||
- Numberings now allow zeros. To reset a counter, you can write
|
- Numberings now allow zeros. To reset a counter, you can write
|
||||||
|
`[#counter(..).update(0)]`
|
||||||
- Added `--font-path` argument for CLI
|
- Added `--font-path` argument for CLI
|
||||||
- Added Nix flake
|
- Added Nix flake
|
||||||
- Numerous documentation fixes
|
- Numerous documentation fixes
|
||||||
|
@ -141,6 +141,24 @@ pub fn ceil(
|
|||||||
delimited(body, '⌈', '⌉')
|
delimited(body, '⌈', '⌉')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Round an expression.
|
||||||
|
///
|
||||||
|
/// ## Example
|
||||||
|
/// ```example
|
||||||
|
/// $ round(x/2) $
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// Display: Round
|
||||||
|
/// Category: math
|
||||||
|
/// Returns: content
|
||||||
|
#[func]
|
||||||
|
pub fn round(
|
||||||
|
/// The expression to round.
|
||||||
|
body: Content,
|
||||||
|
) -> Value {
|
||||||
|
delimited(body, '⌊', '⌉')
|
||||||
|
}
|
||||||
|
|
||||||
/// Take the absolute value of an expression.
|
/// Take the absolute value of an expression.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
|
@ -57,6 +57,7 @@ pub fn module() -> Module {
|
|||||||
math.define("norm", norm);
|
math.define("norm", norm);
|
||||||
math.define("floor", floor);
|
math.define("floor", floor);
|
||||||
math.define("ceil", ceil);
|
math.define("ceil", ceil);
|
||||||
|
math.define("round", round);
|
||||||
|
|
||||||
// Attachments and accents.
|
// Attachments and accents.
|
||||||
math.define("attach", AttachElem::func());
|
math.define("attach", AttachElem::func());
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
@ -8,4 +8,4 @@ We define $x$ in preparation of @fib:
|
|||||||
$ phi.alt := (1 + sqrt(5)) / 2 $ <ratio>
|
$ phi.alt := (1 + sqrt(5)) / 2 $ <ratio>
|
||||||
|
|
||||||
With @ratio, we get
|
With @ratio, we get
|
||||||
$ F_n = floor(1 / sqrt(5) phi.alt^n) $ <fib>
|
$ F_n = round(1 / sqrt(5) phi.alt^n) $ <fib>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user