Skip to content

Commit

Permalink
Add taylorterm(), the n-th term in Taylor series
Browse files Browse the repository at this point in the history
Also, correct innerproduct to the more usual form <u,v>.
  • Loading branch information
Leedehai committed Dec 10, 2023
1 parent 142fbde commit faaacd6
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:green_book: The [manual](https://github.com/Leedehai/typst-physics/blob/master/physica-manual.pdf).
<p align="center">
<img width="545" alt="logo" src="https://github.com/Leedehai/typst-physics/assets/18319900/781d5747-4842-49f6-bb41-a1fd4d17a1ff">
<img width="545" alt="logo" src="https://github.com/Leedehai/typst-physics/assets/18319900/c703f3db-1b84-4187-ab5f-3929febc89ac">
</p>

# The physica package for Typst
Expand All @@ -21,7 +21,7 @@ natural sciences, including:
* Dirac braket notations,
* Common math functions,
* Differentials and derivatives, including partial derivatives of mixed orders with automatic order summation,
* Familiar "h-bar", tensor abstract index notations, isotopes,
* Familiar "h-bar", tensor abstract index notations, isotopes, Taylor series term,
* Signal sequences i.e. digital timing diagrams.

:warning: [Typst](https://typst.app) is in beta and evolving, and this package
Expand Down
Binary file added background3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified physica-manual.pdf
Binary file not shown.
73 changes: 55 additions & 18 deletions physica-manual.typ
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

#align(center)[
Leedehai \
#linkurl("GitHub repo", "https://github.com/leedehai/typst-physics") |
#linkurl("Typst index", "https://typst.app/docs/packages/")
#linkurl("GitHub", "https://github.com/leedehai/typst-physics") |
#linkurl("Typst", "https://typst.app/docs/packages/")
]

#set par(justify: true)
Expand Down Expand Up @@ -211,6 +211,14 @@ All symbols need to be used in *math mode* `$...$`.
[`cprod`],
[`a cprod b` #sym.arrow $a cprod b$],
[cross product],

[`innerproduct`],
[`iprod`],
[
`iprod(u, v)` #sym.arrow $iprod(u, v)$ \
`iprod(sum_i a_i, b)` \ #sym.arrow $iprod(sum_i a_i, b)$
],
[inner product],
)

== Matrix notations
Expand Down Expand Up @@ -399,22 +407,6 @@ xmat(2, 2, #g)`)
],
[ketbra],

[`innerproduct(`_a_, _b_`)`],
[`iprod`],
[
`iprod(a), iprod(u, v)` \ #sym.arrow $iprod(a), iprod(u, v)$ \
`iprod(a, vec(1,2))` #sym.arrow $iprod(a, vec(1,2))$
],
[innerproduct\ = braket],

[`outerproduct(`_a_, _b_`)`],
[`oprod`],
[
`oprod(a), oprod(u, v)` \ #sym.arrow $oprod(a), oprod(u, v)$ \
`oprod(a, vec(1,2))` #sym.arrow $oprod(a, vec(1,2))$
],
[outerproduct\ = ketbra],

[`matrixelement(`_n_, _M_, _m_`)`],
[`mel`],
[
Expand Down Expand Up @@ -852,6 +844,51 @@ $ isotope("Bi",a:211,z:83) --> isotope("Tl",a:207,z:81) + isotope("He",a:4,z:2)
*(4)* #hl(`isotope("Tl",a:207,z:81) --> isotope("Pb",a:207,z:82) + isotope(e,a:0,z:-1)`)
$ isotope("Tl",a:207,z:81) --> isotope("Pb",a:207,z:82) + isotope(e,a:0,z:-1) $

=== The n-th term in Taylor series

#v(1em)

Function: `taylorterm(`_func_, _x_, _x0_, _idx_`)`.
- _func_: the function e.g. `f`, `(f+g)`,
- _x_: the variable name e.g. `x`,
- _x0_: the variable value at the expansion point e.g. `x_0`, `(1+a)`,
- _idx_: the index of the term, e.g. `0`, `1`, `2`, `n`, `(n+1)`.
If _x0_ or _idx_ is in a parenthesis e.g. `(1+k)`, then the function
automatically removes the outer parenthesis where appropriate.

#align(center, [*Examples*])

#grid(
columns: (50%, 50%),
row-gutter: 1em,
column-gutter: 2em,
[
*(1)* #hl(`taylorterm(f,x,x_0,0)`) \
$ taylorterm(f,x,x_0,0) $
],
[
*(2)* #hl(`taylorterm(f,x,x_0,1)`) \
$ taylorterm(f,x,x_0,1) $
],
[
*(3)* #hl(`taylorterm(f,x,(1+a),2)`) \
$ taylorterm(f,x,(1+a),2) $
],
[
*(4)* #hl(`taylorterm(f,x,x_0,n)`) \
$ taylorterm(f,x,x_0,n) $
],
[
*(5)* #hl(`taylorterm(F,x^nu,x^nu_0,n)`) \
$ taylorterm(F,x^nu,x^nu_0,n) $
],
[
*(6)* #hl(`taylorterm(f_p,x,x_0,(n+1))`) \
$ taylorterm(f_p,x,x_0,(n+1)) $
],
)


=== Signal sequences (digital timing diagrams)

In engineering, people often need to draw digital timing diagrams for signals, like $signals("1|0|1|0")$.
Expand Down
27 changes: 27 additions & 0 deletions physica.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<html>
<head>
<style>
.parent {
position: relative;
top: 0;
left: 0;
}
.image1 {
position: relative;
top: 0;
left: 0;
}
.image2 {
position: absolute;
top: 100px;
left: 195px;
border: 2px solid white;
}
</style>
</head>
<body>
<div class="parent">
<img class="image1" src="./background3.png" />
<img class="image2" src="./physica_thin.png" />
</div>
</body>
33 changes: 26 additions & 7 deletions physica.typ
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@
#let crossproduct = $times$
#let cprod = crossproduct

#let innerproduct(u, v) = {
$lr(angle.l #u, #v angle.r)$
}
#let iprod = innerproduct

// == Matrices

#let matrixdet(..sink) = {
Expand Down Expand Up @@ -288,8 +293,8 @@
#let jmat = jacobianmatrix

#let hessianmatrix(fs, xs, delim:"(") = {
assert(type(fs) == array, message: "expecting a one-element array")
assert(fs.len() == 1, message: "expecting only one function name")
assert(type(fs) == array, message: "usage: hessianmatrix(f; x, y...)")
assert(fs.len() == 1, message: "usage: hessianmatrix(f; x, y...)")
let f = fs.at(0)
assert(type(xs) == array, message: "expecting an array of variable names")
let row_arrays = () // array of arrays
Expand Down Expand Up @@ -364,11 +369,6 @@
$ lr(bar.v ket#h(0pt)mid(angle.r#h(0pt)angle.l)#h(0pt)bra bar.v) $
})

#let innerproduct = braket
#let iprod = innerproduct
#let outerproduct = ketbra
#let oprod = outerproduct

#let matrixelement(n, M, m) = style(styles => {
$ lr(angle.l #n#h(0pt)mid(bar.v)#h(0pt)#M#h(0pt)mid(bar.v)#h(0pt)#m angle.r) $
})
Expand Down Expand Up @@ -663,6 +663,25 @@
math.attach((T,hphantom(sym.zwj)).join(), t: uppers.join(), b: lowers.join())
}

#let taylorterm(fn, xv, x0, idx) = {
let noparen(expr) = {
if type(expr) == content and expr.func() == math.lr {
let children = expr.at("body").at("children")
children.slice(1, children.len() - 1).join()
} else {
expr
}
}

if idx == [0] or idx == 0 {
$fn (noparen(x0))$
} else if idx == [1] or idx == 1 {
$fn^((1)) (noparen(x0))(xv - x0)$
} else {
$frac(fn^((noparen(idx))) (noparen(x0)), idx !)(xv - x0)^noparen(idx)$
}
}

#let isotope(element, /*atomic mass*/a: none, /*atomic number*/z: none) = {
$attach(upright(element), tl: #a, bl: #z)$
}
Expand Down
Binary file added physica_thin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit faaacd6

Please sign in to comment.