|  | 
|  | 1 | +<!-- This is a program-generated file. Do not edit it directly. --> | 
|  | 2 | + | 
|  | 3 | +# Typst package: `peano` | 
|  | 4 | + | 
|  | 5 | +`peano` is a math utility package that provides you with representations of specialized number types, mathematic special functions, number theory related operations and so on. The name of the package comes from [Peano axioms](https://en.wikipedia.org/wiki/Peano_axioms), which builds up the framework of [natural numbers](https://en.wikipedia.org/wiki/Natural_number) ℕ, one of the the most elementary concepts in mathematics, aiming to convey this package's orientation as a simple utility package. | 
|  | 6 | + | 
|  | 7 | +## Number types | 
|  | 8 | + | 
|  | 9 | +`peano` currently supports two number types and their arithmetics: | 
|  | 10 | + | 
|  | 11 | +- `rational`: representation of [rational numbers](https://en.wikipedia.org/wiki/Rational_number) ℚ in the form of fractions | 
|  | 12 | +- `complex`: representation of[ complex numbers](https://en.wikipedia.org/wiki/Complex_number) ℂ | 
|  | 13 | + | 
|  | 14 | +It is a pity that Typst doesn't currently support custom types and overloading operators, so actually these numbers are represented by Typst's `dictionary` type, and you have to invoke specialized methods in the corresponding sub-module to perform arithmetic operations over these numbers. | 
|  | 15 | + | 
|  | 16 | +To use these number types you have to first import the corresponding sub-module: | 
|  | 17 | + | 
|  | 18 | +```typ | 
|  | 19 | +#import "@preview/peano:0.1.0" | 
|  | 20 | +#import peano.number: rational as q, complex as c | 
|  | 21 | +``` | 
|  | 22 | + | 
|  | 23 | +Each sub-module contains a method called `from`, by which you can directly create a number instance from a string or a built-in Typst number type. Arithmetic methods in these modules will automatically convert all parameters to the expected number type by this `from` method, so you can simply input strings and built-in number types as parameters. | 
|  | 24 | + | 
|  | 25 | +### Rational numbers | 
|  | 26 | + | 
|  | 27 | +```typ | 
|  | 28 | +#import "@preview/peano:0.1.0" | 
|  | 29 | +#import peano.number: rational as q | 
|  | 30 | +
 | 
|  | 31 | +#q.from("1/2") // from string | 
|  | 32 | +#q.from(2, 3) // from numerator and denominator | 
|  | 33 | +#q.add("1/2", "1/3", "-1/5") // addition | 
|  | 34 | +#q.sub("2/3", "1/4") // subtraction | 
|  | 35 | +#q.mul("3/4", "2/3", "4/5") // multiplication | 
|  | 36 | +#q.div("5/6", "3/2") // division | 
|  | 37 | +#q.limit-den(calc.pi, 10000) // limiting maximum denominator | 
|  | 38 | +#q.pow("3/2", 5) // raising to an integer power | 
|  | 39 | +
 | 
|  | 40 | +#q.to-str(q.from(113, 355)) // convert to string | 
|  | 41 | +#q.to-math(q.from(113, 355)) // convert to formatted `math.equation` element | 
|  | 42 | +``` | 
|  | 43 | + | 
|  | 44 | +Currently, `rational.from` supports fraction notation and decimal notation with an optional set of [repeating digits](https://en.wikipedia.org/wiki/Repeating_decimal) enclosed in square brackets. | 
|  | 45 | + | 
|  | 46 | +```typ | 
|  | 47 | +#import "@preview/peano:0.1.0" | 
|  | 48 | +#import peano.number: rational as q | 
|  | 49 | +
 | 
|  | 50 | +// normal values | 
|  | 51 | +
 | 
|  | 52 | +#q.from("1/2") | 
|  | 53 | +#q.from("-2/3") // sign before numerator | 
|  | 54 | +#q.from("5/-4") // sign before denominator | 
|  | 55 | +
 | 
|  | 56 | +// infinity or indeterminate values | 
|  | 57 | +
 | 
|  | 58 | +#q.from("1/0")  // infinity | 
|  | 59 | +#q.from("-1/0") // negative infinity | 
|  | 60 | +#q.from("1/-0") // also negative infinity | 
|  | 61 | +#q.from("0/0")  // NaN | 
|  | 62 | +
 | 
|  | 63 | +// decimal notation | 
|  | 64 | +
 | 
|  | 65 | +#q.from("0.25") | 
|  | 66 | +#q.from("0.[3]") // repeating part wrapped in bracket | 
|  | 67 | +#q.from("3.[142857]") | 
|  | 68 | +#q.from("1.14[514]") | 
|  | 69 | +#q.from("1[2.3]") // repeating part can cross decimal point | 
|  | 70 | +``` | 
|  | 71 | + | 
|  | 72 | +A rational number can be displayed in both string and math format by using the `rational.to-str` and `rational.to-math` methods. | 
|  | 73 | + | 
|  | 74 | +```typ | 
|  | 75 | +#import "@preview/peano:0.1.0" | 
|  | 76 | +#import peano.number: rational as q | 
|  | 77 | +
 | 
|  | 78 | +#let value = q.from(113, 355) | 
|  | 79 | +
 | 
|  | 80 | +#q.to-str(value) | 
|  | 81 | +#q.to-math(value) | 
|  | 82 | +``` | 
|  | 83 | + | 
|  | 84 | +### Complex numbers | 
|  | 85 | + | 
|  | 86 | +```typ | 
|  | 87 | +#import "@preview/peano:0.1.0" | 
|  | 88 | +#import peano.number: complex as c | 
|  | 89 | +
 | 
|  | 90 | +#c.from("1+2i") // from string | 
|  | 91 | +#c.from(3, 4) // from real and imaginary parts | 
|  | 92 | +#c.add("1+2i", "3+4i", "-2+3i", "6-5i", "2i") | 
|  | 93 | +``` | 
|  | 94 | + | 
|  | 95 | +## Number theory | 
|  | 96 | + | 
|  | 97 | +The number theory sub module `peano.ntheory` currently supports prime factorization and the extended Euclidean algorithm that gives out the coefficients $u$ and $v$ in Bézout's identity $\gcd (a, b) = u a + v b$. | 
|  | 98 | + | 
|  | 99 | +## Mathematic functions | 
|  | 100 | + | 
|  | 101 | +The `peano.func` sub-module provides a collection of basic mathematic functions. Some of them are also included in Typst's `calc` module, but extended to support complex number input. Other self-defined functions also support function input if they can be defined in the complex field Ȑ. | 
|  | 102 | + | 
|  | 103 | +### Special functions | 
|  | 104 | + | 
|  | 105 | +The `peano.func.special` sub-module include special functions such as the gamma function, zeta function, Gauss error function. | 
0 commit comments