Difference between revisions of "Timescalecalculus python library documentation"
Line 1: | Line 1: | ||
{{lowercase}} | {{lowercase}} | ||
− | Note: this documentation applies to commit 4c23e99ab3b10fd13c30e485fa8a14973ac333c5 of the repo. There has been a lot of | + | Note: this documentation applies to commit 4c23e99ab3b10fd13c30e485fa8a14973ac333c5 of the repo. There has been a lot of development recently and the documentation is now out-of-date. Please e-mail tomcuchta@gmail.com for questions until the documentation is updated. |
This is the documentation for the Python repository [https://github.com/tomcuchta/timescalecalculus timescalecalculus]. | This is the documentation for the Python repository [https://github.com/tomcuchta/timescalecalculus timescalecalculus]. |
Latest revision as of 14:41, 4 December 2018
Note: this documentation applies to commit 4c23e99ab3b10fd13c30e485fa8a14973ac333c5 of the repo. There has been a lot of development recently and the documentation is now out-of-date. Please e-mail tomcuchta@gmail.com for questions until the documentation is updated.
This is the documentation for the Python repository timescalecalculus.
Contents
The basics
After extracting the files (or cloning the repository), open a Python instance in its folder and type
>>> import timescalecalculus as tsc
Right now, a time scale in this library can consist of only a finite list of numbers. Fraction types are available.
Let $\mathbb{T}=\left\{0,\dfrac{1}{3},\dfrac{1}{2},\dfrac{7}{9},1,2,3,4,5,6,7 \right\}$.
>>> import timescalecalculus as tsc >>> from fractions import Fraction >>> ts=tsc.timescale([0,Fraction(1,3),Fraction(1,2),Fraction(7,9),1,2,3,4,5,6,7],'documentation example') >>> ts.name 'documentation example' >>> ts.ts [0, Fraction(1, 3), Fraction(1, 2), Fraction(7, 9), 1, 2, 3, 4, 5, 6, 7]
Forward jump and graininess
The forward jump $\sigma$ can be computed:
$\sigma(0)=\dfrac{1}{3}$
>>> ts.sigma(0) Fraction(1, 3)
$\sigma(4)=5$
>>> ts.sigma(4) 5
$\sigma(7)=7$
>>> ts.sigma(7) 7
The forward graininess $\mu$ can be computed:
$\mu \left( \dfrac{1}{3} \right)=\dfrac{1}{2}-\dfrac{1}{3}=\dfrac{1}{6}$
>>> ts.mu(Fraction(1,3)) Fraction(1, 6)
Backward jump and graininess
The backward jump $\rho$ can be used:
$\rho(1)=\dfrac{7}{9}$
>>> ts.rho(1) Fraction(7, 9)
$\rho(3)=2$
>>> ts.rho(3) 2
$\rho(0)=0$
>>> ts.rho(0) 0
The backward graininess $\nu$ can be computed:
$\nu\left( \dfrac{7}{9} \right)=\dfrac{7}{9}-\dfrac{1}{2}=\dfrac{5}{18}$
>>> ts.nu(Fraction(7,9)) Fraction(5, 18)
Delta-derivative
The delta derivative works as expected. The delta derivative of a constant is zero:
>>> ts.dderivative(lambda x: 1,5) 0
and obeying the delta derivative of squaring function, we see
>>> ts.dderivative(lambda x: x*x,5) 11
The delta exponential is supported. For example if $\mathbb{T}=\{1,2,3,4,5,6,7\}$ then $e_1(3,1)=(1+\mu(1))(1+\mu(2))=(2)(2)=4$ which is correctly computed:
>>> ts.dexpf(lambda x: 1, 3, 1) 4
Special functions
Delta exponential $e_p(t,s)$
On $\mathbb{T}=\{1,2,3,4,5\}$
Then the delta exponential $e_1(3,1)$ is given by $$e_1(3,1) = \displaystyle\prod_{k=1}^2 1+\mu(k)(1)=2^{2}=4$$
>>> ts=timescale([1,2,3,4,5]) >>> ts.dexpf(lambda x: 1,3,1) 4
The function $e_2(3,1)$ is given by $$e_2(3,1) = \displaystyle\prod_{k=1}^2 1+\mu(k)(2)=3^2=9$$
>>> ts.dexpf(lambda x: 2,3,1) 9
The function $e_{\mathrm{id}}(3,1)$ (where $\mathrm{id}$ is the identity function on $\mathbb{T}$) is given by $$e_{\mathrm{id}}(3,1)=\displaystyle\prod_{k=1}^2 1+\mu(k)k=(1+(1)(1))(1+(1)(2))=6$$
>>> ts.dexpf(lambda x: x,3,1) 6
The function $e_{e_1(\cdot,1)}(3,1)$ is given by $$e_{e_1(\cdot,1)}(4,1)=\displaystyle\prod_{k=1}^3 1+\mu(k)e_1(k,1)=(1+(1)e_1(1,1))(1+(1)e_1(2,1))(1+(1)e_1(3,1))=(2)(3)(5)=30$$
>>> ts.dexpf(lambda x: ts.dexpf(lambda x: 1,x,1),4,1) 30
On $\mathbb{T}=\{2,3,5,7,11,13,17\}$
Let $p_k$ denote the $k$th prime number. Then
$e_1(5,2)=\displaystyle\prod_{k=1}^2 1+\mu(p_k)(1)=(1+(1)(1))(1+(2)(1))=6$
>>> ts=tsc.timescale([2,3,5,7,11,13,17],'primes') >>> ts.dexpf(lambda x: 1, 5,2) 6
$e_1(11,2)=\displaystyle\prod_{k=1}^4 1+\mu(p_k)(1)=(1+(1)(1))(1+2(1))(1+2(1))(1+4(1))=90$
>>> ts.dexpf(lambda x: 1,11,2) 90
$e_{\mathrm{id}}(5,2)=\displaystyle\prod_{k=1}^2 1+\mu(p_k)p_k=(1+(1)(2))(1+2(3))=21$
>>> ts.dexpf(lambda x: x,5,2) 21