1 | 10 | 2.59374246 |
2 | 100 | 2.70481383 |
3 | 1000 | 2.71692393 |
4 | 10000 | 2.71814593 |
5 | 100000 | 2.71826824 |
Very slow. After 10⁵ iterations, it's correct only up to 4d.p.
1 | 1.0000000000 | 2.0000000000 |
2 | 0.5000000000 | 2.5000000000 |
3 | 0.1666666667 | 2.6666666667 |
4 | 0.0416666667 | 2.7083333333 |
5 | 0.0083333333 | 2.7166666667 |
6 | 0.0013888889 | 2.7180555556 |
7 | 0.0001984127 | 2.7182539683 |
8 | 0.0000248016 | 2.7182787698 |
9 | 0.0000027557 | 2.7182815256 |
10 | 0.0000002756 | 2.7182818011 |
11 | 0.0000000251 | 2.7182818262 |
12 | 0.0000000021 | 2.7182818283 |
13 | 0.0000000002 | 2.7182818284 |
14 | 0.0000000000 | 2.7182818285 |
15 | 0.0000000000 | 2.7182818285 |
16 | 0.0000000000 | 2.7182818285 |
17 | 0.0000000000 | 2.7182818285 |
18 | 0.0000000000 | 2.7182818285 |
19 | 0.0000000000 | 2.7182818285 |
20 | 0.0000000000 | 2.7182818285 |
A slight modification to curFrac
(by adding *myR
to lastFrac/i
) will give a basic numerical scheme for the exponential function.
In my original code, in the intrinsic filter, I've forgotten to use absolute value in abs(an) < myepsilon
.
It's not interesting too see so many rows of zero, so I've changed it to \ifnum \i < 21
. Note that neither <=
nor break
won't work. A more efficient way would be to use a while
loop on counter myrows
, but there're better tech for this, so I'm not spending time on this.
I tried LaTeX's calculations at first, but it's too inaccurate. I've to use fpu
package for more accurate calculations.
Just a recollection of what I've said on Discord.
The most noticeable advantage of typst over LaTeX is that you don't have to type that much \
, say beta
for β instead of \beta
The second would be more intuitive syntax. for some symbols, their typst syntax is nearer to English than LaTeX, like A union B
for A ∪ B instead of A cup B
LaTeX's programming isn't quite easy. the expansion rules can be quite hard to understand. typst was developed in Rust, and programmers should be no problem writing typst functions to make code reusable.
If you care about compilation speed (say you've made a 100-page document or more), then typst's advantage would surface up
So what're LaTeX advantages? Some "soft" answers include popularity, worldwide acceptance (say in all big math online communities, even on GitHub & GitLab, LaTeX rendering is supported). Its long history indicates a great community support (on TeX.SE, etc) and pool of packages. It can handle complex situations. (↑ disturbances, ↑ complexity)
I'm sure that users will have their own strategy to make use of these technologies and it'll be great to have them available
Here's a simple example of LaTeX programming
To do recursion in LaTeX, we often need to think about text expansion, cuz this langauge is about text substitution. I have to rely on ChatGPT to understand how \expandafter
, \xappto
, \gappto
work. The final code would have bunch of syntax that has nothing to do with the core logic.
\newcommand\unions[2]{
\ifnum#1>1 \expandafter\unions\expandafter{\number\numexpr#1-1\relax}{#2} \cup {#2}_{#1}
\else
{#2}_1
\fi
}
$\unions{6}{S}$
If you're interested in typst, here's a demo from Evan Chen. Hope that would motivate you to a typst tutorial.
Looking back at what I've written, I found that I've overlooked \tikzmath
's function
However, while writing in LaTeX, I found it difficult to separate "logic" & "display"
LaTeX does have arrays, but it's less operable than those in typst
I don't wanna spam this chat, so I'll be posting examples below.
See how i separated
- input
- logic (to construct the table array)
- display into three parts in my code
rows
contains the table rows for display.
After each iteration, I rows.push((n, an, sn))
← ofc i rounded those cells
The display part is a bit tricky, but once you've figured out the logic, it's easy to write.
Our target is to feed typst's table()
function with cell contents separated with comma ,
,
like row1 cell 1, row 1 cell 2, row 2 cell 1, row 2 cell 2, …
Any developer will have no problem understanding these steps:
rows
is an array of array, sth like((a, b, c), (d, e, f), …)
rows.flatten()
return another array without the inner()
:(a, b, c, d, e, f, …)
- this is followed by
.map(str)
, so that the functionstr
is applied to each element of the above array in step 2, i.e.(str(a), str(b), str(c), …)
- the above array is prepended by the spreading operator
..
, which takes away the()
wrapping the input (e.g...(1, 2)
→1, 2
), so that it's ready fortable()