Difference between revisions of "Timescalecalculus python library documentation"

From timescalewiki
Jump to: navigation, search
(Delta exponential $e_p(t,s)$)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{lowercase}}
 
{{lowercase}}
 +
 +
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].
  
 
=The basics=
 
=The basics=
After extracting the files, open a Python instance in its folder and type
+
After extracting the files (or cloning the repository), open a Python instance in its folder and type
<pre> >>> from timescalecalculus import *</pre>
+
<pre> >>> import timescalecalculus as tsc</pre>
  
 
Right now, a [[time scale]] in this library can consist of only a finite list of numbers. Fraction types are available.  
 
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\}$.<br />
 
Let $\mathbb{T}=\left\{0,\dfrac{1}{3},\dfrac{1}{2},\dfrac{7}{9},1,2,3,4,5,6,7 \right\}$.<br />
<pre>>>> ts=[0,Fraction(1,3),Fraction(1,2),Fraction(7,9),1,2,3,4,5,6,7]</pre>
+
<pre>
 +
>>> 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]
 +
</pre>
  
 
==Forward jump and graininess==
 
==Forward jump and graininess==
 
The [[forward jump]] $\sigma$ can be computed:<br />
 
The [[forward jump]] $\sigma$ can be computed:<br />
 
$\sigma(0)=\dfrac{1}{3}$
 
$\sigma(0)=\dfrac{1}{3}$
<pre>>>> sigma(0,ts)
+
<pre>>>> ts.sigma(0)
 
Fraction(1, 3)</pre>
 
Fraction(1, 3)</pre>
 
$\sigma(4)=5$
 
$\sigma(4)=5$
<pre>>>> sigma(4,ts)
+
<pre>>>> ts.sigma(4)
 
5</pre>
 
5</pre>
 
$\sigma(7)=7$
 
$\sigma(7)=7$
<pre>>>> sigma(7,ts)
+
<pre>>>> ts.sigma(7)
 
7</pre>
 
7</pre>
 
The [[forward graininess]] $\mu$ can be computed:<br />
 
The [[forward graininess]] $\mu$ can be computed:<br />
 
$\mu \left( \dfrac{1}{3} \right)=\dfrac{1}{2}-\dfrac{1}{3}=\dfrac{1}{6}$
 
$\mu \left( \dfrac{1}{3} \right)=\dfrac{1}{2}-\dfrac{1}{3}=\dfrac{1}{6}$
<pre>>>> mu(Fraction(1,3),ts)
+
<pre>>>> ts.mu(Fraction(1,3))
 
Fraction(1, 6)</pre>
 
Fraction(1, 6)</pre>
  
Line 30: Line 40:
 
The [[backward jump]] $\rho$ can be used:<br />
 
The [[backward jump]] $\rho$ can be used:<br />
 
$\rho(1)=\dfrac{7}{9}$
 
$\rho(1)=\dfrac{7}{9}$
<pre>>>> rho(1,ts)
+
<pre>>>> ts.rho(1)
 
Fraction(7, 9)</pre>
 
Fraction(7, 9)</pre>
 
$\rho(3)=2$
 
$\rho(3)=2$
<pre>>>> rho(3,ts)
+
<pre>>>> ts.rho(3)
 
2</pre>
 
2</pre>
 
$\rho(0)=0$
 
$\rho(0)=0$
<pre>>>> rho(0,ts)
+
<pre>>>> ts.rho(0)
 
0</pre>
 
0</pre>
  
 
The [[backward graininess]] $\nu$ can be computed:<br />
 
The [[backward graininess]] $\nu$ can be computed:<br />
 
$\nu\left( \dfrac{7}{9} \right)=\dfrac{7}{9}-\dfrac{1}{2}=\dfrac{5}{18}$
 
$\nu\left( \dfrac{7}{9} \right)=\dfrac{7}{9}-\dfrac{1}{2}=\dfrac{5}{18}$
<pre>>>> nu(Fraction(7,9),ts)
+
<pre>>>> ts.nu(Fraction(7,9))
 
Fraction(5, 18)</pre>
 
Fraction(5, 18)</pre>
  
 
==Delta-derivative==
 
==Delta-derivative==
 
The [[delta derivative]] works as expected. The delta derivative of a constant is zero:
 
The [[delta derivative]] works as expected. The delta derivative of a constant is zero:
<pre>>>> dderivative(lambda x: 1,5,ts)
+
<pre>>>> ts.dderivative(lambda x: 1,5)
 
0</pre>
 
0</pre>
 
and obeying the [[delta derivative of squaring function]], we see
 
and obeying the [[delta derivative of squaring function]], we see
<pre>>>> dderivative(lambda x: x*x,5,ts)
+
<pre>>>> ts.dderivative(lambda x: x*x,5)
 
11</pre>
 
11</pre>
 
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:
 
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:
<pre>>>> dexpf(lambda x: 1, 3, 1, ts)
+
<pre>>>> ts.dexpf(lambda x: 1, 3, 1)
 
4</pre>
 
4</pre>
  
Line 60: Line 70:
 
Then the [[delta exponential]] $e_1(3,1)$ is given by
 
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$$
 
$$e_1(3,1) = \displaystyle\prod_{k=1}^2 1+\mu(k)(1)=2^{2}=4$$
<pre>>>> ts=[1,2,3,4,5]
+
<pre>>>> ts=timescale([1,2,3,4,5])
>>> dexpf(3,1,ts)
+
>>> ts.dexpf(lambda x: 1,3,1)
>>> dexpf(lambda x: 1,3,1,ts)
 
 
4</pre>
 
4</pre>
 
The function $e_2(3,1)$ is given by
 
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$$
 
$$e_2(3,1) = \displaystyle\prod_{k=1}^2 1+\mu(k)(2)=3^2=9$$
<pre>>>> dexpf(lambda x: 2,3,1,ts)
+
<pre>>>> ts.dexpf(lambda x: 2,3,1)
 
9</pre>
 
9</pre>
 
The function $e_{\mathrm{id}}(3,1)$ (where $\mathrm{id}$ is the [http://specialfunctionswiki.org/index.php/Identity_function identity function] on $\mathbb{T}$) is given by
 
The function $e_{\mathrm{id}}(3,1)$ (where $\mathrm{id}$ is the [http://specialfunctionswiki.org/index.php/Identity_function 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$$
 
$$e_{\mathrm{id}}(3,1)=\displaystyle\prod_{k=1}^2 1+\mu(k)k=(1+(1)(1))(1+(1)(2))=6$$
<pre>>>> dexpf(lambda x: x,3,1,ts)
+
<pre>>>> ts.dexpf(lambda x: x,3,1)
 
6</pre>
 
6</pre>
 
The function $e_{e_1(\cdot,1)}(3,1)$ is given by
 
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$$
 
$$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$$
<pre>>>> dexpf(lambda x: dexpf(lambda x: 1,x,1,ts),4,1,ts)
+
<pre>>>> ts.dexpf(lambda x: ts.dexpf(lambda x: 1,x,1),4,1)
 
30</pre>
 
30</pre>
 +
 +
===On $\mathbb{T}=\{2,3,5,7,11,13,17\}$===
 +
Let $p_k$ denote the $k$th prime number. Then<br />
 +
$e_1(5,2)=\displaystyle\prod_{k=1}^2 1+\mu(p_k)(1)=(1+(1)(1))(1+(2)(1))=6$
 +
<pre>>>> ts=tsc.timescale([2,3,5,7,11,13,17],'primes')
 +
>>> ts.dexpf(lambda x: 1, 5,2)
 +
6</pre>
 +
$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$
 +
<pre>>>> ts.dexpf(lambda x: 1,11,2)
 +
90</pre>
 +
$e_{\mathrm{id}}(5,2)=\displaystyle\prod_{k=1}^2 1+\mu(p_k)p_k=(1+(1)(2))(1+2(3))=21$
 +
<pre>>>> ts.dexpf(lambda x: x,5,2)
 +
21</pre>

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.

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