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
|
||||
it is:
|
||||
<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>
|
||||
|
||||
|
||||
@ -78,13 +78,13 @@ Let's dissect what's going on:
|
||||
|
||||
= Fibonacci sequence
|
||||
The Fibonacci sequence is defined through the
|
||||
_recurrence relation_ $F_n = F_(n-1) + F_(n-2)$.
|
||||
It can also be expressed in closed form:
|
||||
recurrence relation $F_n = F_(n-1) + F_(n-2)$.
|
||||
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 $
|
||||
|
||||
#let count = 10
|
||||
#let count = 8
|
||||
#let nums = range(1, count + 1)
|
||||
#let fib(n) = (
|
||||
if n <= 2 { 1 }
|
||||
|
@ -18,11 +18,12 @@ description: |
|
||||
- Fixed [matrices]($func/mat) with explicit delimiter
|
||||
- Fixed build of CLI if `git` is not installed
|
||||
- Links in bibliographies are now affected by link styling
|
||||
`[#counter(..).update(0)]`
|
||||
- Added support for disabling [matrix]($func/mat) and [vector]($func/vec)
|
||||
delimiters. Generally with `[#set math.mat(delim: none)]` or one-off with
|
||||
`[$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
|
||||
`[#counter(..).update(0)]`
|
||||
- Added `--font-path` argument for CLI
|
||||
- Added Nix flake
|
||||
- Numerous documentation fixes
|
||||
|
@ -141,6 +141,24 @@ pub fn ceil(
|
||||
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.
|
||||
///
|
||||
/// ## Example
|
||||
|
@ -57,6 +57,7 @@ pub fn module() -> Module {
|
||||
math.define("norm", norm);
|
||||
math.define("floor", floor);
|
||||
math.define("ceil", ceil);
|
||||
math.define("round", round);
|
||||
|
||||
// Attachments and accents.
|
||||
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>
|
||||
|
||||
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