CamiXon.jl

A package for image analysis of backscattered light


Table of contents

Strings

CamiXon.supMethod
sup(i)

Superscript notation for integers and rational numbers

Examples:

sup(3) * 'P'
 "³P"
source
CamiXon.subMethod
sub(i)

Subscript notation for integers and rational numbers

Examples:

'D' * sub(5//2)
 "D₅⸝₂"
source
CamiXon.fracMethod
frac(i)

Fraction notation for rational numbers

Examples:

frac(-5//2)
 "-⁵/₂"
source

Atomic properties

CamiXon.mendeleevMethod
mendeleev(Z::Int)

The properties name and symbol of the element with atomic number Z.

Example:

mendeleev(11)
 ("Sodium", "Na")
source
CamiXon.AtomType
Atom(name::String, symbol::String, Z::Int, Q::Int, M::Float64, I::Real, gI::Float64)

Type to specify the atomic species with fields name::String (name of element), symbol::String (symbol of element), Z::Int (atomic number), Q::Int (ionic charge in a.u.), M::Float6 (nuclear mass in amu), I::Rational{Int} (nuclear spin as integer or rational number), gI::Float64 (nuclear g-factor)

Note: the type Atom is best created by the function createAtom.

Examples:

Hydrogen = Atom("Hydrogen", "¹H", 1, 0, 1.00782503223, 1//2, 5.585694713)

name = Hydrogen.name
symbol = Hydrogen.symbol
Z = Hydrogen.Z
Q = Hydrogen.Q
M = Hydrogen.M
I = Hydrogen.I
gI = Hydrogen.gI
println("name = $(name), symbol = $(symbol), Z = $Z, Q = $Q, M = $M, I = $I, gI = $gI")
 name = Hydrogen, symbol = ¹H, Z = 1, Q = 0, M = 1.00782503223, I = 1//2, gI = 5.585694713
source
CamiXon.createAtomMethod
createAtom(Z::Int, Q::Int, M::Float64, I::Real, gI::Float64)

Create Atom Type with fields name::String (name of element), symbol::String (symbol of element), Z::Int (atomic number), Q::Int (ionic charge in a.u.), M::Float6 (nuclear mass in amu), I::Real (nuclear spin as integer or rational number), gI::Float64 (nuclear g-factor).

Examples:

createAtom(1,0,1.00782503223,1//2,5.585694713)
 Atom created: Hydrogen, symbol = ¹H, Z = 1, Q = 0, M = 1.00782503223, I = 1//2, gI = 5.585694713
 Atom("Hydrogen", "¹H", 1, 0, 1.00782503223, 1//2, 5.585694713)

createAtom(2,1,4.00260325413,1//2,0.0)
 Atom created: Helium ion, symbol = ⁴Heᐩ, Z = 2, Q = 1, M = 4.00260325413, I = 1//2, gI = 0.0
 Atom("Helium ion", "⁴Heᐩ", 2, 1, 4.00260325413, 1//2, 0.0)
source
CamiXon.TermType
Term(name::String, n::Int, ℓ::Int, S::Real, L::Int, J::Real)

Type to specify the fine-structure Term in Russell-Saunders notation with fields name::String, n::Int (principal quantum number), ℓ::Int (orbital angular momentum valence electron), S::Real (total electron spin as integer or rational number), L::Int (total orbital angular momentum), J::Real (total electronic angular momentum as integer or rational number).

Note: the type Term is best created by the function createTerm.

Examples:

Term_H1I = Term("1s ²S₁⸝₂", 1, 0, 1//2, 0, 1//2)
 Term("1s ²S₁⸝₂", 1, 0, 1//2, 0, 1//2)

name = Term_H1I.name
n = Term_H1I.n
ℓ = Term_H1I.ℓ
S = Term_H1I.S
L = Term_H1I.L
J = Term_H1I.J
println("name = $(name, n = $n, ℓ = $ℓ, S = $S, L = $L, J = $J")
 name = "1s ²S₁⸝₂", n = 1, ℓ = 0, S = 1//2, L = 0, J = 1//2
source
CamiXon.createTermMethod
createTerm(n::Int, ℓ::Int, S::Real, L::Int, J::Real)

Specify Term Type in the Term notatation with fields n::Int (principal quantum number), ℓ::Int (orbital angular momentum valence electron), S::Rational (total electron spin), L::Int (total orbital angular momentum), J::Rational (total electronic angular momentum).

Examples:

term_H1I = createTerm(1, 0, 1//2, 0, 1//2)
 Term created: 1s ²S₁⸝₂, n = 1, ℓ = 0, S = 1//2, L = 0, J = 1//2
 Term("1s ²S₁⸝₂", 1, 0, 1//2, 0, 1//2)
source

Finite-difference methods

Finite differences

Consider the analytic function $f$ tabulated in forward order (growing index) at $n$ positions on a grid. The finite difference of two adjacent values on a uniform grid is defined by the relation

\[\nabla f[n] = f[n]-f[n-1].\]

This is called the finite difference in backward difference notation. In this notation the $k^{th}$-order backward difference (which involves $k+1$ points) is defined by a weighted sum over the function values in backward order, $f[n],\ \ldots,\ f[n-k]$,

\[\nabla^k f[n] = f[n] + c_1^kf[n-1] + \cdots + c_k^kf[n-k] = \sum_{j=0}^{k} c_j^kf[n-j].\]

The $k+1$ coefficients $c_{j}^{k}=(-1)^{j}\binom{k}{j}$ are weight factors (short: weights) defining the summation. Note that $c_{0}^{k}\equiv1$ and $c_{k}^{k}=(-1)^{k}$. As the function $f$ is tabulated in forward order it is good practice to change dummy index to also write the summation in forward order (coefficients in backward order),

\[\nabla^k f[n] = \sum_{j=0}^{k} c^k[j]f[n-k+j],\]

where $c^k[j] \equiv c_{k-j}^k$.

Functions:

f_diff_weight(k,j) $\rightarrow c_j^k$

f_diff_weights(k) $\rightarrow \ c^k ≡ [c_k^k,\ c_1^k,\ldots,\ c_0^k]$

f_diff_weights_array(kmax) $\rightarrow \ [\ c^0,\ c^1,\ \ldots,\ c^{kmax} ]$

CamiXon.f_diff_weightMethod
f_diff_weight(k, j)

Weight coefficient

\[c_{j}^{k}=(-1)^{j}\binom{k}{j},\]

of the $k^{th}$-order finite difference operator $\nabla^k$ and corresponding to the function value $f[n-j]$.

Example:

k = 5; j = 3
f_diff_weight(k, j)
 -10
source
CamiXon.f_diff_weightsMethod
f_diff_weights(k)

Weight vector $[c_k^k,\ \ldots,\ c_0^k]$ defining the $k^{th}$-order finite difference operator,

\[\nabla^{k}f[n] =[c_{k}^{k},\thinspace c_{k-1}^{k},\thinspace\ldots,c_{0}^{k}]\left[\begin{array}{c} f[n-k]\\ \vdots\\ f[n] \end{array}\right]=\sum_{j=0}^{k}c^k[j]f[n-k+j],\]

where $c^k[j] ≡ c_{k-j}^{k}$. This form is designed for use with analytic functions, $f$, tabulated in forward order, $f[n-k], ...,f[n]$.

Example:

k = 3
f_diff_weights(k)
4-element Vector{Int64}:
  1
 -3
  3
 -1
source
CamiXon.f_diff_weights_arrayMethod
f_diff_weights_array(kmax)

Collection of weight vectors, $c^0,\ \ldots,\ c^k$, defining the finite difference operators $\nabla^0,\ \ldots,\ \nabla^k$ under the convention $c^k ≡ [c_k^k,\ c_1^k,\ldots,\ c_0^k])$.

Example:

kmax = 3
∇ = f_diff_weights_array(kmax)
4-element Vector{Vector{Int64}}:
 [1]
 [-1, 1]
 [1, -2, 1]
 [-1, 3, -3, 1]
source

Finite difference expansion

Finite-difference calculus builds on the finite-difference expansion, in practice truncated at order $k$,

\[\sum_{p=0}^{\infty}a_{p}\nabla^{p}f[n]=\sum_{p=0}^{k}a_{p}\nabla^{p}f[n]+\cdots.\]

By choosing the order sufficiently high the expansion can be approximated to any desired level of accuracy. A finite-difference expansion of order $k$ is defined by $k+1$ finite-difference expansion coefficients, above denoted by $a_{0},\ \ldots,\ a_{k}$. Note that both the coefficients and the operators appear in forward order. It takes some bookkeeping to rewrite the expansion in the form of a weighted sum over the $k+1$ function values $f[n],\ldots,f[n-k]$ (note the backward order). Substituting the finite-difference expression for $\nabla^k$, we obtain

\[\sum_{p=0}^{k}a_{p}\nabla^{p}f[n]=\sum_{p=0}^{k}a_{p}\sum_{j=0}^{p}c_{j}^{i}f[n-j]=\sum_{j=0}^{k}\sum_{p=j}^{k}a_{p}c_{j}^{p}f[n-j]=\sum_{j=0}^{k}b_{j}^{k}f[n-j],\]

where the weighted summation is defined by the weights $b_{j}^{k}=\sum_{p=j}^{k}a_{p}c_{j}^{p}$, with $j=0,\ \ldots,\ k$. By a change of dummy index we write the summation in forward order

\[\sum_{p=0}^{k}a_{p}\nabla^{p}f[n]=\sum_{j=0}^{k}b^k[j]f[n-k+j],\]

where $b^k[j] \equiv b_{k-j}^k$. Note that the weights vector $b^k$ contains the weights in backward order. It is generated by the function f_diff_expansion_weights(coeffs,∇), where ∇ =f_diff_weights_array(kmax).

Functions:

coeffs = $[a_0,\ \ldots,\ a_k]$

f_diff_expansion_weights(coeffs,∇) $\rightarrow b^k \equiv [b_k^k,\ ,\ldots,\ b_0^k]$

CamiXon.f_diff_expansion_weightsMethod
f_diff_expansion_weights(a, ∇)

Weight vector $b^k ≡ [b_k^k,\ ,\ldots,\ b_0^k]$ corresponding to the expansion coefficients $[a_0^k,\ ,\ldots,\ a_k^k]$ of the $k^{th}$-order finite-difference expansion,

\[\sum_{p=0}^{k}a_{p}\nabla^{p}f[n]=\sum_{j=0}^{k}b^k[j]f[n-k+j],\]

where $b^k[j] \equiv b_{k-j}^k$ and $f[n-k], ...,f[n]$ are elements of the analytic function $f$ tabulated in forward order. Note the difference in ordering between the finite-difference expansion coefficients, $a_{0},\ \ldots,\ a_{k}$, and the finite-difference expansion weights, $b_k^{k},\ \ldots,\ b_0^{k}$. Note further the difference in $k$ dependence: the weights, $b_j^k$, are $k$-dependent, whereas the coefficients, $a_j$, are not.

Example:

k=5
∇ = f_diff_weights_array(k)
a = UnitRange(0,k)
b = f_diff_expansion_weights(a, ∇)
6-element Vector{Int64}:
  -5
  29
 -69
  85
 -55
  15
source

Lagrangian interpolation

Using the definition of the finite difference we can express the relation between $f[n]$ and $f[n+1]$ in operator form,

\[f[n]=(1-\nabla)f[n+1].\]

By formal inversion of the operator we have

\[f[n+1] = (1 - \nabla)^{-1} f[n] \equiv \sum_{p=0}^{\infty}∇^p f[n],\]

\[f[n+2] = (1 - \nabla)^{-2} f[n] \equiv \sum_{p=0}^{\infty}p∇^p f[n],\]

\[\vdots\]

which can be generalized to the form of lagrangian interpolation,

\[f[n+x] = (1 - \nabla)^{-x} f[n] \equiv \sum_{p=0}^{\infty}l_p(x)∇^p f[n],\]

where $l_0\equiv 1$ and $l_p(x) = x(x+1)(x+2)\cdots(x+p-1)/p!$ for $p>0$ are the finite-difference expansion coefficients for lagrangian interpolation. These are generated by the function f_diff_expansion_coeffs_lagrange(k,x). Evaluating the finite-difference expansion up to order $k$ we obtain

\[f[n+x] =\sum_{p=0}^{k}l_p(x)\nabla^pf[n]= \sum_{j=0}^{k}r_j^k(x)f[n-j],\]

where the $k+1$ weights $r_j^k(x)= \sum_{p=j}^{k} l_p(x) c_j^p$ are the lagrangian interpolation weights. After changing dummy index to bring the summation in forward order the expansion becomes

\[f[n+x] =\sum_{p=0}^{k}l_p(x)\nabla^pf[n]= \sum_{j=0}^{k}r_x^k[j]f[n-k+j],\]

where $r^k_x[j] ≡ r_{k-j}^k(x)$. The weights vector $r^k_x$ is generated by the function f_diff_expansion_weights(coeffs,∇), with ∇ = f_diff_weights_array(k).

Functions:

coeffs = f_diff_expansion_coeffs_lagrange(k,x) $\rightarrow [l_0(x),\ \ldots,\ l_k(x)]$

lagrangian interpolation weights = f_diff_expansion_weights(coeffs,∇) $\rightarrow r^k_x ≡ [r_k^k(x),\ ,\ldots,\ r_0^k(x)]$

CamiXon.f_diff_expansion_coeffs_lagrangeMethod
f_diff_expansion_coeffs_lagrange(k::Int, x::T) where T<:Real

Finite-difference expansion coefficient vector $[l_0(x),\ \ldots,\ l_p(x)]$ defining $k^{th}$-order lagrangian interpolation of the tabulated analytic function $f(n+x)$ at offset position $x$ with respect to position $n$,

\[f[n+x] = (1 - \nabla)^{-x} f[n] \equiv \sum_{p=0}^{\infty}l_p(x)∇^p f[n],\]

where $l_0\equiv 1$ and $l_p(x) = x(x+1)(x+2)\cdots(x+p-1)/p!$. Interpolation corresponds to the interval $-k\le\ x\le 0$; extrapolation to $x\ge 0$.

Examples:

k = 5; x = 1
l = f_diff_expansion_coeffs_lagrange(k,x); println(l)
 [1, 1, 1, 1, 1, 1]
source
CamiXon.summation_rangeMethod
summation_range(n, i, k, m)

Summation range for interpolation position $0\le i/m \le 1$ used in $k^{th}$-order lagrangian interpolation of the anaytic function $f$ tabulated in forward order on a uniform grid of $n$ points, $f[1],\ \ldots,\ f[n]$; $m$ is the multiplier defining the interpolation grid size.

Examples:

n = 7; k = 2; m = 1
o = [summation_range(n,i,k,m) for i=0:(n-1)*m]; println(o)
 UnitRange{Int64}[1:3, 2:4, 3:5, 4:6, 5:7, 5:7, 5:7]
source
CamiXon.f_diff_function_sequencesFunction
f_diff_function_sequences(f, k::Int, m=1)

Finite-difference summation sequences of function values given in forward order for use in $k^{th}$-order lagrangian interpolation of the anaytic function $f$ tabulated in forward order on a regular grid of $n$ points, $f[1], ...,f[n]$; $m$ is the multiplier defining the interpolation grid size. Each sequence consists of $k⋅m+1$ function values.

Example:

f = [0,1,2,3,4,5,6]
k = 2
o = f_diff_function_sequences(f, k); println(o)
 [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [4, 5, 6], [4, 5, 6]]
source
CamiXon.lagrange_interpolationMethod
lagrangian_interpolation(f::Vector{Float64}, domain::ClosedInterval{Float64}; k=1, m=1)

$k^{th}$-order lagrangian interpolation of the analytic function $f$ tabulated in forward order on a regular grid of $n$ points, $f[1],\ \ldots,\ f[n]$; $m$ is the multiplier defining the interpolation grid size.

Example:

f = [0.0,1,2,3,4,5,6,7]
domain = 0.0..1.0
(X,Y) = lagrangian_interpolation(f, domain; k=2, m=2); println((X,Y))
 (0.0:0.07142857142857142:1.0, [0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0])
source
CamiXon.lagrange_extrapolationMethod
lagrangian_extrapolation(f::Vector{Float64}, domain::ClosedInterval{Float64}; k=1, e=1, m=1)

$k^{th}$-order lagrangian extrapolation up to position $n+e$ of the analytic function $f$ tabulated in forward order at $n$ points, $f[1],\ \ldots,\ f[n]$; $m$ is the multiplier defining the interpolation grid size.

Example:

f = [0.0,1,2,3,4,5,6,7]
domain = 0.0..1.0
(X,Y) = lagrangian_extrapolation(f, domain; k=2, e=1, m=2); println((X,Y))
 (0.0:0.07142857142857142:1.0, [0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0])
source

Lagrangian differentiation

To derive the lagrangian differentiation formulas we formally differentiate

\[f[n+x] = (1 - \nabla)^{-x} f[n]\]

with respect to $x$.

\[\frac{df}{dx}[n+x]=-ln(1-\nabla)\ (1-\nabla)^{-x}f[n]=\sum_{q=1}^{k}\tfrac{1}{q}∇^{q}\sum_{p=0}^{k}l_{p}(x)∇^{p}f[n]+\cdots.\]

Rewriting the r.h.s. as a single summation in powers of $\nabla$ for given values of $n$ and $x$ we obtain an expression of the form

\[\frac{df}{dx}[n+x]=\sum_{p=1}^{k}l_{p}^{\prime}(x)\nabla^{p}f[n]+\cdots,\]

where $l_{p}^{\prime}(x)$ represents the finite-difference expansion coefficients for lagrangian differentiation at position $n+x$. These coefficients are determined numerically by polynomial multiplication after adding the $p=0$ term, $l_{0}^{\prime}(x)\equiv 0$, to the first sum. The corresponding coefficient vector is generated in forward order by the function f_diff_expansion_coeffs_differentiation(k,x). Evaluating the finite-difference expansion up to order $k$ we obtain

\[\frac{df}{dx}[n+x]=\sum_{p=0}^{k}l_{p}^{\prime}(x)\nabla^{p}f[n]=\sum_{j=0}^{k}s_{j}^{k}(x)f[n-j],\]

where the $s_{j}^{k}(x)=\sum_{p=j}^{k}l_{p}^{\prime}(x)c_{j}^{p}$ are the $k^{th}$-order lagrangian differentiation weights. After changing dummy index to reverse the summation from backward to forward order the expansion becomes

\[\frac{df}{dx}[n+x]]= \sum_{j=0}^{k}s^k_x[j]f[n-k+j],\]

where $s^k_x[j] ≡ s^k_{k-j}(x)$. The weights vector $s^k_x$ is generated by the function f_diff_expansion_weights(coeffs,∇), with ∇ = f_diff_weights_array(k).

Functions:

coeffs = f_diff_expansion_coeffs_differentiation(k,x) $\rightarrow [l_0^{\prime}(x),\ \ldots,\ l_k^{\prime}(x)]$

Lagrange differentiation weights = f_diff_expansion_weights(coeffs,∇) $s^k_x[j] ≡ \rightarrow [s_k^k(x),\ ,\ldots,\ s_0^k(x)]$

Lagrange differentiation weights = create_lagrange_differentiation_weights(k,x) $s^k_x[j] ≡ \rightarrow [s_k^k(x),\ ,\ldots,\ s_0^k(x)]$

CamiXon.f_diff_expansion_coeffs_differentiationMethod
f_diff_expansion_coeffs_differentiation(k::Int, x::T) where T<:Real

Finite-difference expansion coefficient vector $[l_0^{\prime}(x),\ \ldots,\ l_p^{\prime}(x)]$ defining $k^{th}$-order lagrangian differentiation of the tabulated analytic function $f(n+x)$ at position $x$,

\[\frac{df}{dx}[n+x]=\sum_{p=0}^{k}l_{p}^{\prime}(x)\nabla^{p}f[n]\]

Example:

k = 2; x = 0
o = f_diff_expansion_coeffs_differentiation(k,x); println(o)
 [0.0, 1.0, -1.5]
source
CamiXon.create_lagrange_differentiation_weightsMethod
create_lagrange_differentiation_weights(k::Int, x::T) where T<:Real

$k^{th}$-order Lagrange differentiation weights vector, $s^k(x) ≡ [s_k^k(x),\ ,\ldots,\ s_0^k(x)]$, where $x$ is the position relative point $n$.

\[\frac{df}{dx}[n+x]= \sum_{j=0}^{k}s_{k-j}^k(x)f[n-k+j],\]

where $s^k_x[j] ≡ s_{k-j}(x)^k$.

Example:

k = 3
x = 0
ldw = create_lagrange_differentiation_weights(k,x); println(ldw)
source
CamiXon.create_lagrange_differentiation_matrixMethod
create_lagrange_differentiation_matrix(k::Int)

Lagrange differentiation matrix, $m[i,j]=s_{k-j}^k(i)$, for $k^{th}$-order lagrangian differentiation,

\[\frac{dy}{dx}[i]= \sum_{j=0}^{k}m[i,j]y[j],\]

Example:

k = 3
create_lagrange_differentiation_matrix(k)
 4×4 Matrix{Rational{Int64}}:
  -11//6   3//1  -3//2   1//3
   -1//3  -1//2   1//1  -1//6
    1//6  -1//1   1//2   1//3
   -1//3   3//2  -3//1  11//6
source
CamiXon.lagrange_differentiationMethod
lagrange_differentiation(f::Vector{Float64}, domain::ClosedInterval{Float64}; k=1, m=1)

$k^{th}$-order lagrangian differentiation of the analytic function $f$, tabulated in forward order on a regular grid of $n$ points, $f[1],\ \ldots,\ f[n]$; $m$ is the multiplier for intermediate positions

Example:

f = [0.0,1,2,3,4,5]
domain = 0.0..5.0
X,Y = lagrangian_differentiation(f, domain; k=2, i = 0); println(X,Y)
 (0.0:1.0:5.0, [1.0, 1.0, 1.0, 1.0, 1.0, 1.0])
source

Integration

CamiXon.trapezoidal_weightsMethod
trapezoidal_weights(k::Int [; rationalize=false [, devisor=false]])

Weight coefficient vector $a=[a_1,\cdots,\ a_k]$ of trapeziodal rule optimized for functions of polynomial form,

\[ ∫_0^n f(x) dx = a_1 (f_0+f_n)+\cdots+a_k (f_{k-1}+f_{n-k+1}) + (f_k+\cdots+f_{n-k}),\]

where $k$ is odd. The rule is exact for polynonials of degree $d=0,\ 1,\cdots,\ k-1$. For $k=1$ the rule reduces to the ordinary trapezoidal rule. By default the output is in Float64, optionally the output is rational, with or without specification of the gcd devisor.

Example::

[trapezoidal_weights(k; rationalize=true, devisor=true) for k=1:2:9]
5-element Vector{Tuple{Int64, Int64, Vector{Int64}}}:
 (1, 2, [1])
 (3, 24, [9, 28, 23])
 (5, 1440, [475, 1902, 1104, 1586, 1413])
 (7, 120960, [36799, 176648, 54851, 177984, 89437, 130936, 119585])
 (9, 7257600, [2082753, 11532470, 261166, 16263486, -1020160, 12489922, 5095890, 7783754, 7200319])
source
CamiXon.trapezoidal_integrationMethod
trapezoidal_integration(f, domain, weights)

Integral of the tabulated function $f=[f_0,\cdots,\ f_n]$ over the domain $a..b$ using the optimized trapezoidal rule with endpoint correction by the weightsvector weights,

\[ ∫_0^n f(x) dx = a_1 (f_0+f_n)+\cdots+a_k (f_{k-1}+f_{n-k+1}) + (f_k+\cdots+f_{n-k}).\]

The rule is exact for polynonials of degree $d=0,\ 1,\cdots,\ k-1$. For $k=1$ the rule reduces to the ordinary trapezoidal rule (weights = [1/2]).

Examples::

p = 3
c = [1 for i=0:p]
pol = ImmutablePolynomial(c,:z)
Ipol = integrate(pol)
n = 10

domain = 0.0..5.0
x = collect(range(domain, n))
f = pol.(x .-2.5)

w3 = trapezoidal_weights(3)
trapezoidal_integration(f, domain, w3)
 15.416666666666673

Ipol(2.5)-Ipol(-2.5)
 15.41666666666666
source

Adams Method

Adams-Bashford expansion

The Adams-Bashford integration step is given by the expansion

\[y[n+1]-y[n] = -\frac{h \nabla}{(1-\nabla)ln(1-\nabla)}f[n+1]=h (\sum_{p=0}^{\infty}B_p\nabla^p)f[n+1].\]

A closed expression for the Adams-Bashford expansion coefficients, $B_k$, is not available. As we already have a finite-difference expansion for the operator $(1-∇)^{-1}$,

\[\frac{1}{1-∇}\equiv\sum_{p=0}^{\infty}\nabla^p,\]

we ask for the expansion of

\[-\frac{∇}{ln(1-∇)}=(1-\frac{1}{2}∇-\frac{1}{24}∇^2-\frac{1}{12}∇^3+\cdots)f[n+1]= (\sum_{p=0}^{\infty}b_p\nabla^p)f[n+1].\]

This is known as the Adams-Moulton expansion. Its coefficients are calculated numerically by the function f_diff_expansion_adams_moulton_coeffs(k). The Adams-Bashford expansion is obtained as the polynomial product of the two expansions,

\[(\sum_{p=0}^{\infty}B_p∇^p)f[n+1]=(\sum_{p=0}^{\infty}∇^p)(\sum_{p=0}^{\infty}b_p∇^p)f[n+1]=\ ( 1 + \frac{1}{2}\nabla + \frac{5}{12}\nabla^2 + \cdots)f[n+1].\]

The coefficients $B_p$ are calculated numerically with the function f_diff_expansion_adams_bashford_coeffs(k). Evaluating the finite-difference expansion up to order $k$ we obtain (after changing dummy index bring the summation in forward order)

\[\sum_{p=0}^{k}B_p\nabla^pf[n]=\sum_{p=0}^{k}B_p\sum_{j=0}^{p} c_j^if[n-j]= \sum_{j=0}^{k}A_j^k(x)f[n-j]= \sum_{j=0}^{k}A_{k-j}^k(x)f[n-k+j],\]

where the $A_j^k(x)= \sum_{p=j}^{k} B_pc_j^p$ are the $(k+1)$-point Adams-Bashford integration weights.

Function:

coeffs = f_diff_expansion_coeffs_adams_bashford(k) $\rightarrow [B_k^k(x),\ ,\ldots,\ B_0^k(x)]$

adams_bashford_integration_weights = f_diff_expansion_weights(coeffs,∇) $\rightarrow [A_k^k(x),\ ,\ldots,\ A_0^k(x)]$

CamiXon.f_diff_expansion_coeffs_adams_bashfordMethod
f_diff_expansion_coeffs_adams_bashford(k [, T=Int])

$(k+1)$-point Adams-Bashford expansion coefficients $B_p$.

\[-\frac{\nabla}{(1-\nabla)ln(1-\nabla)}=\sum_{p=0}^{\infty}B_p\nabla^p=1+\ \frac{1}{2}∇+\ \frac{5}{12}∇^2+\ \cdots.\]

The weights are stored in forward order: $[B_0^k,\ \cdots,\ B_k^k]$ - order of use in summation.

Examples:

k = 5
o = f_diff_expansion_coeffs_adams_bashford(k::Int); println(o)
 Rational{Int64}[1//1, 1//2, 5//12, 3//8, 251//720, 95//288]
source

Adams-Moulton expansion

The Adams-Moulton integration step is given by the expansion

\[y[n+1]-y[n] = -\frac{\nabla}{ln(1-\nabla)}f[n+1] = ( 1 - \frac{1}{2}\nabla - \frac{1}{12}\nabla^2 - \frac{1}{24}\nabla^3 +\cdots)f[n+1].\]

For the evaluation of the integration step we limit the summation to $k+1$ terms (order $k$),

\[y[n+1]-y[n]= (\sum_{p=0}^{k}b_p\nabla^p)f[n+1]+\cdots.\]

where $b_0,\ldots,b_k$ are the Adams-Moulton expansion coefficients, rational numbers generated numerically by the function f_diff_expansion_coeffs_adams_moulton(k). Extracting the greatest common denominator, $1/D$, the step becomes

\[y[n+1]-y[n]= \frac{1}{D}(\sum_{p=0}^{k}b_p^{\prime}\nabla^p)f[n+1]+\cdots,\]

where $b_0^{\prime},\ldots,b_k^{\prime}$ are integers and $b_p=b_p^{\prime}/D$. In practice the expansion is restricted to $k<18$ (as limited by integer overflow). Note that this limit is much higher than values used in calculations (typically up to $k = 10$). Evaluating the finite-difference expansion up to order $k$ we obtain (after changing dummy index bring the summation in forward order)

\[\sum_{p=0}^{k}b_p\nabla^pf[n]=\sum_{p=0}^{k}b_p\sum_{j=0}^{p} c_j^if[n-j]= \sum_{j=0}^{k}a_j^k(x)f[n-j]= \sum_{j=0}^{k}a_{k-j}^k(x)f[n-k+j],\]

where the $a_j^k(x)= \sum_{p=j}^{k} b_pc_j^p$ are the $(k+1)$-point Adams-Moulton integration weights. These are generated in backward order by the function f_diff_expansion_weights(coeffs,∇), with ∇ =f_diff_weights_array(k).

Functions:

coeffs = f_diff_expansion_coeffs_adams_moulton(k) $\rightarrow [b_0,\ldots,b_k]$

adams_moulton_weights = f_diff_expansion_weights(coeffs,∇)$\rightarrow [a_k^k,\ ,\ldots,\ a_0^k]$

adams_moulton_weights = create_adams_moulton_weights(k)$\rightarrow [a_k^k,\ ,\ldots,\ a_0^k]$

CamiXon.f_diff_expansion_coeffs_adams_moultonMethod
f_diff_expansion_coeffs_adams_moulton(k [, T=Int])

$k^{th}$-order Adams-Moulton expansion coefficients,

\[-\frac{\nabla}{ln(1-\nabla)} = \sum_{p=0}^{\infty}b_p\nabla^p= 1 - \frac{1}{2}\nabla - \frac{1}{12}\nabla^2 - \frac{1}{24}\nabla^3 +\cdots.\]

The weights are stored in forward order: $[b_0^k,\ \cdots,\ b_k^k]$ - order of use in summation.

Examples:

k = 5
b = f_diff_expansion_coeffs_adams_moulton(k::Int); println(b)
 Rational[1//1, -1//2, -1//12, -1//24, -19//720, -3//160]

D = denominator(gcd(b)); println(D)
 1440

o = convert(Vector{Int},(b .* D)); println(o)
 [1440, -720, -120, -60, -38, -27]
source
CamiXon.create_adams_moulton_weightsMethod
create_adams_moulton_weights(k::Int [; rationalize=false [, devisor=false [, T=Int]]])

$k^{th}$-order Adams-Moulton weights vector,

\[y[n+1] = y[n] + \frac{1}{D}\sum_{j=0}^{k}a^k[j]f[n+1-k+j]\]

The weights are stored in the vector $a^k \equiv[a_k^k/D,\ \cdots,\ a_0^k/D]$ under the convention $a^k[j] \equiv a_{k-j}^k/D$, where $a_j^k$ are the Adams-Moulton weight coefficients and $D$ the corresponding Adams-Moulton divisor. By default the output is in Float64, optionally the output is rational, with or without specification of the gcd devisor.

Example:

[create_adams_moulton_weights(k::Int; rationalize=true, devisor=true, T=Int) for k=1:8]
8-element Vector{Tuple{Int64, Int64, Vector{Int64}}}:
 (1, 2, [1, 1])
 (2, 12, [-1, 8, 5])
 (3, 24, [1, -5, 19, 9])
 (4, 720, [-19, 106, -264, 646, 251])
 (5, 1440, [27, -173, 482, -798, 1427, 475])
 (6, 60480, [-863, 6312, -20211, 37504, -46461, 65112, 19087])
 (7, 120960, [1375, -11351, 41499, -88547, 123133, -121797, 139849, 36799])
 (8, 3628800, [-33953, 312874, -1291214, 3146338, -5033120, 5595358, -4604594, 4467094, 1070017])
source

FITS

FITS stands for 'Flexible Image Transport System'. This is an open standard origionally developed for the astronomy community to store telescope images together with tables of spectral information. Over the years it has developed into a scientific standard - http://fits.gsfc.nasa.gov/iaufwg.

Within CamiXion only the basic FITS functionality is implemented for users not requiring celestal coordinates. The user can create, read and extend .fits files as well as create, edit and delete user-defined metainformation.

A FITS file consists of a sequence of one or more header-data-units (HDUs), each containing a data block preceeded by header records of metainformation.

By the command f = fits_read(filnam) we asign a collection of FITS_HDU objects from the file filnam to the variable f.

FITS - Types

CamiXon.FITS_HDUType
FITS_HDU

Object to hold a single "Header-Data Unit" (HDU).

The fields are

  • .filename::String: name of the corresponding FITS file
  • .hduindex::Int: identifier (a file may contain more than one HDU)
  • .header::T, where T=FITS_header: the header object
  • .dataobject::V, where V=FITS_data: the data object
source
CamiXon.FITS_headerType
FITS_header

Object to hold the header information of a FITS_HDU.

The fields are:

  • .hduindex::Int: identifier (a file may contain more than one HDU)
  • .records::Array{String,1}: the header formated as an array of strings of 80 ASCII characters
  • .keys::Array{String,1}: keys[i] - key corresponding to records[i] (record of index i)
  • .values::Array{Any,1}: value[i] - corresponding to records[i]
  • .comments: comments[i] - comment corresponding to records[i]
  • .dict::Dict{String,Any}: Dictionary key[i] => value[i]
  • .maps::Dict{String,Int}: Dictionary key[i] => i
source
CamiXon.FITS_dataType
FITS_data

Object to hold the data of the FITS_HDU of given hduindex and hdutype.

The fields are:

  • .hduindex::Int: identifier (a file may contain more than one HDU)
  • .hdutype::String: accepted types are 'PRIMARY', 'IMAGE' and 'TABLE'
  • .data::Any: in the from appropriate for the hdutype
source
CamiXon.FITS_tableType
FITS_table

Object to hold the data of a TABLE HDU (a FITS_HDU for ASCII tables). It contains the data in the form of records (rows) of ASCII strings.

The fields are:

  • .hduindex::Int: identifier (a file may contain more than one HDU)
  • .rows::Array{String,1}: the table formated as an array of rows of ASCII strings
source
CamiXon.FITS_nameType
FITS_name

FITS object to decompose the names of .fits files.

The fields are:

  • .name::String: for filename 'p#.fits' this is 'p#.fits'
  • .prefix::String: for filename 'p#.fits' this is 'p'
  • .numerator::String: for filename 'p#.fits' this is '#', a serial number (e.g., '3') or a range (e.g., '3-7')
  • .extension::String: for filename 'p#.fits' this is '.fits'.
source

FITS - HDU Methods

CamiXon.fits_infoMethod
fits_info(hdu)

Print metafinformation and data of given FITS_HDU

Example:

strExample = "remove.fits"
data = [11,21,31,12,22,23,13,23,33]
data = reshape(data,(3,3,1))
fits_create(strExample, data; protect=false)

f = fits_read(strExample)
fits_info(f[1])

  File: remove.fits
  hdu: 1
  hdutype: PRIMARY
  DataType: Int64
  Datasize: (3, 3, 1)

  Metainformation:
  SIMPLE  =                    T / file does conform to FITS standard
  BITPIX  =                   64 / number of bits per data pixel
  NAXIS   =                    3 / number of data axes
  NAXIS1  =                    3 / length of data axis 1
  NAXIS2  =                    3 / length of data axis 2
  NAXIS3  =                    1 / length of data axis 3
  BZERO   =                  0.0 / offset data range to that of unsigned integer
  BSCALE  =                  1.0 / default scaling factor
  EXTEND  =                    T / FITS dataset may contain extensions
  COMMENT    Primary FITS HDU    / http://fits.gsfc.nasa.gov/iaufwg
  END

  3×3×1 Array{Int64, 3}:
  [:, :, 1] =
   11  12  13
   21  22  23
   31  23  33
source
CamiXon.parse_FITS_TABLEMethod
parse_FITS_TABLE(hdu)

Parse FITS_TABLE (ASCII table) into a Vector of its columns for further processing by the user. Default formatting in ISO 2004 FORTRAN data format specified by keys "TFORMS1" - "TFORMSn") Display formatting in ISO 2004 FORTRAN data format ("TDISP1" - "TDISPn") prepared for user editing.

Example:

strExample = "example.fits"
data = [10, 20, 30]
fits_create(strExample, data; protect=false)

t1 = Float16[1.01E-6,2.0E-6,3.0E-6,4.0E-6,5.0E-6]
t2 = [0x0000043e, 0x0000040c, 0x0000041f, 0x0000042e, 0x0000042f]
t3 = [1.23,2.12,3.,4.,5.]
t4 = ['a','b','c','d','e']
t5 = ["a","bb","ccc","dddd","ABCeeaeeEEEEEEEEEEEE"]
data = [t1,t2,t3,t4,t5]
fits_extend(strExample, data, "TABLE")

f = fits_read(strExample)
d = f[2].header.dict
d = [get(d,"TFORM$i",0) for i=1:5]; println(strip.(d))
  SubString{String}["'E6.1    '", "'I4      '", "'F4.2    '", "'A1      '", "'A20     '"]

f[2].dataobject.data                            # this is the table hdu
  5-element Vector{String}:
   "1.0e-6 1086 1.23 a a                    "
   "2.0e-6 1036 2.12 b bb                   "
   "3.0e-6 1055 3.0  c ccc                  "
   "4.0e-6 1070 4.0  d dddd                 "
   "5.0e-6 1071 5.0  e ABCeeaeeEEEEEEEEEEEE "

parse_FITS_TABLE(f[2])
  5-element Vector{Vector{T} where T}:
   [1.0e-6, 2.0e-6, 3.0e-6, 4.0e-6, 5.0e-6]
   [1086, 1036, 1055, 1070, 1071]
   [1.23, 2.12, 3.0, 4.0, 5.0]
   ["a", "b", "c", "d", "e"]
   ["a                   ", "bb                  ", "ccc                 ", "dddd                ", "ABCeeaeeEEEEEEEEEEEE"]
source

FITS - File Methods

CamiXon.cast_FITS_nameMethod
cast_FITS_name(filename::String)

Decompose the FITS filename 'filnam.fits' into its name, prefix, numerator and extension.

Examples:

strExample = "T23.01.fits"
f = cast_FITS_name(strExample)
FITS_name("T23.01", "T23.", "01", ".fits")

f.name, f.prefix, f.numerator, f.extension
("T23.01", "T23.", "01", ".fits")
source
CamiXon.fits_combineMethod
fits_combine(strFirst, strLast [; protect=true])

Copy "filenameFirst" to "filenameLast" (with mandatory ".fits" extension)

Key:

  • protect::Bool: overwrite protection

Example:

fits_combine("T01.fits", "T22.fits")
  'T01-T22.fits': file created
source
CamiXon.fits_copyFunction
fits_copy(filenameA [, filenameB="" [; protect=true]])

Copy "filenameA" to "filenameB" (with mandatory ".fits" extension) Key:

  • protect::Bool: overwrite protection

Examples:

fits_copy("T01.fits")
  'T01.fits' was saved as 'T01 - Copy.fits'

fits_copy("T01.fits", "T01a.fits")
  FitsError: 'T01a.fits' in use (set ';protect=false' to lift overwrite protection)

fits_copy("T01.fits", "T01a.fits"; protect=false)
  'T01.fits' was saved as 'T01a.fits'
source
CamiXon.fits_createFunction
fits_create(filename [, data [; protect=true]])

Create FITS file of given filename [, optional data block [, default overwrite protection]] and return Array of HDUs. Key:

  • protect::Bool: overwrite protection

Examples:

strExample = "minimal.fits"
fits_create(strExample;protect=false)

f = fits_read(strExample)
a = f[1].dataobject.data
b = f[1].header.keys
println(a);println(b)
  Any[]
  ["SIMPLE", "NAXIS", "EXTEND", "COMMENT", "END"]

strExample = "remove.fits"
data = [11,21,31,12,22,23,13,23,33]
data = reshape(data,(3,3,1))
fits_create(strExample, data; protect=false)

f = fits_read(strExample)
fits_info(f[1])

  File: remove.fits
  hdu: 1
  hdutype: PRIMARY
  DataType: Int64
  Datasize: (3, 3, 1)

  Metainformation:
  SIMPLE  =                    T / file does conform to FITS standard
  BITPIX  =                   64 / number of bits per data pixel
  NAXIS   =                    3 / number of data axes
  NAXIS1  =                    3 / length of data axis 1
  NAXIS2  =                    3 / length of data axis 2
  NAXIS3  =                    1 / length of data axis 3
  BZERO   =                  0.0 / offset data range to that of unsigned integer
  BSCALE  =                  1.0 / default scaling factor
  EXTEND  =                    T / FITS dataset may contain extensions
  COMMENT    Primary FITS HDU    / http://fits.gsfc.nasa.gov/iaufwg
  END

  3×3×1 Array{Int64, 3}:
  [:, :, 1] =
   11  12  13
   21  22  23
   31  23  33
source
CamiXon.fits_extendFunction
fits_extend(filename, data_extend, hdutype="IMAGE")

Extend the FITS file of given filename with the data of hdutype from data_extend and return Array of HDUs.

Examples:

strExample = "test_example.fits"
data = [0x0000043e, 0x0000040c, 0x0000041f]
fits_create(strExample, data, protect=false)

f = fits_read(strExample)
a = Float16[1.01E-6,2.0E-6,3.0E-6,4.0E-6,5.0E-6]
b = [0x0000043e, 0x0000040c, 0x0000041f, 0x0000042e, 0x0000042f]
c = [1.23,2.12,3.,4.,5.]
d = ['a','b','c','d','e']
e = ["a","bb","ccc","dddd","ABCeeaeeEEEEEEEEEEEE"]
data = [a,b,c,d,e]
fits_extend(strExample, data, "TABLE")

f = fits_read(strExample)
f[2].dataobject.data
  5-element Vector{String}:
   "1.0e-6 1086 1.23 a a                    "
   "2.0e-6 1036 2.12 b bb                   "
   "3.0e-6 1055 3.0  c ccc                  "
   "4.0e-6 1070 4.0  d dddd                 "
   "5.0e-6 1071 5.0  e ABCeeaeeEEEEEEEEEEEE "

rm(strExample); f = data = a = b = c = d = e = nothing
source
CamiXon.fits_readMethod
fits_read(filename)

Read FITS file and return Array of FITS_HDUs

Example:

strExample = "minimal.fits"
fits_create(strExample;protect=false)

f = fits_read(strExample)
f[1].dataobject.data
  Any[]

rm(strExample); f = nothing
source

FITS - Key Methods

CamiXon.fits_add_keyMethod
fits_add_key(filename, hduindex, key, value, comment)

Add a header record of given 'key, value and comment' to 'HDU[hduindex]' of file with name 'filename'

Example:

strExample="minimal.fits"
fits_create(strExample;protect=false)
fits_add_key(strExample, 1, "KEYNEW1", true, "FITS dataset may contain extension")

f = fits_read(strExample)
fits_info(f[1])

  File: minimal.fits
  hdu: 1
  hdutype: PRIMARY
  DataType: Any
  Datasize: (0,)

  Metainformation:
  SIMPLE  =                    T / file does conform to FITS standard
  NAXIS   =                    0 / number of data axes
  EXTEND  =                    T / FITS dataset may contain extensions
  COMMENT    Primary FITS HDU    / http://fits.gsfc.nasa.gov/iaufwg
  KEYNEW1 =                    T / FITS dataset may contain extension
  END

  Any[]
source
CamiXon.fits_delete_keyMethod
fits_delete_key(filename, hduindex, key)

Delete a header record of given key, value and comment to FITS_HDU[hduindex] of file with name 'filename'

Examples:

strExample="minimal.fits"
fits_create(strExample;protect=false)
fits_add_key(strExample, 1, "KEYNEW1", true, "this is record 5")

f = fits_read(strExample)
get(f[1].header.maps,"KEYNEW1",0)
  5

fits_delete_key(strExample, 1, "KEYNEW1")

f = fits_read(strExample)
get(f[1].header.maps,"KEYNEW1",0)
  0

fits_delete_key(filnam, 1, "NAXIS")
 'NAXIS': cannot be deleted (key protected under FITS standard)
source
CamiXon.fits_edit_keyMethod
fits_edit_key(filename, hduindex, key, value, comment)

Edit a header record of given 'key, value and comment' to 'HDU[hduindex]' of file with name 'filename'

Example:

data = DateTime("2020-01-01T00:00:00.000")
strExample="minimal.fits"
fits_create(strExample;protect=false)
fits_add_key(strExample, 1, "KEYNEW1", true, "this is record 5")
fits_edit_key(strExample, 1, "KEYNEW1", data, "record 5 changed to a DateTime type")

f = fits_read(strExample)
fits_info(f[1])

  File: minimal.fits
  hdu: 1
  hdutype: PRIMARY
  DataType: Any
  Datasize: (0,)

  Metainformation:
  SIMPLE  =                    T / file does conform to FITS standard
  NAXIS   =                    0 / number of data axes
  EXTEND  =                    T / FITS dataset may contain extensions
  COMMENT    Primary FITS HDU    / http://fits.gsfc.nasa.gov/iaufwg
  KEYNEW1 = '2020-01-01T00:00:00' / record 5 changed to a DateTime type
  END

  Any[]
source
CamiXon.fits_rename_keyMethod
fits_rename_key(filename, hduindex, keyold, kewnew)

Rename the key of a header record of file with name 'filename'

Example:

strExample="minimal.fits"
fits_create(strExample;protect=false)
fits_add_key(strExample, 1, "KEYNEW1", true, "this is record 5")
fits_rename_key(strExample, 1, "KEYNEW1",  "KEYNEW2")

f = fits_read(strExample)
fits_info(f[1])

  File: minimal.fits
  hdu: 1
  hdutype: PRIMARY
  DataType: Any
  Datasize: (0,)

  Metainformation:
  SIMPLE  =                    T / file does conform to FITS standard
  NAXIS   =                    0 / number of data axes
  EXTEND  =                    T / FITS dataset may contain extensions
  COMMENT    Primary FITS HDU    / http://fits.gsfc.nasa.gov/iaufwg
  KEYNEW2 =                    T / this is record 5
  END

  Any[]
source

FORTRAN

CamiXon.FORTRAN_formatType
FORTRAN_format

Object to hold a FORTRAN format specifier decomposed into its fields. Accepted datatype specifiers are: Aw, Iw, Fw.d, Ew.d, Dw.d. Accepted output formating specifiers are: Aw, Iw.m, Bw.m, Ow.m, Zw.m, Fw.d, Ew.dEe, ENw.d, ESw.d, Gw.dEe, Dw.dEe. Notation: 'w' - width, 'm' (optional) - minimum number of digits, 'd' - number of digits to right of decimal, 'e' - number of digits in exponent; 'N'/'S' (optional) - switch for engineering/scientific formating of the 'E' type.

The fields are:

  • Type::String: primary FORTRAN datatype
  • TypeChar::Char: primary FORTRAN datatype character
  • EngSci::Union{Char,Nothing}: secundary datatype character (N for engineering, S for scientific)
  • width::Int: width of numeric field
  • nmin::Int: minimum number of digits displayed
  • ndec::Int: number of digits to right of decimal
  • nexp::Int: number of digits in exponent
source
CamiXon.cast_FORTRAN_formatMethod
cast_FORTRAN_format(format::String)

Decompose the format specifier 'format' into its fields and cast this into the FORTRAN_format object. Allowed format specifiers are of the types: Aw, Iw.m, Bw.m, Ow.m, Zw.m, Fw.d, Ew.dEe, ENw.d, ESw.d, Gw.dEe, Dw.dEe, with: 'w' - width, 'm' (optional) - minimum number of digits, 'd' - number of digits to right of decimal, 'e' - number of digits in exponent; 'N'/'S' (optional) - switch for engineering/scientific formating of the 'E' type.

Examples:

t = cast_FORTRAN_format("I10")
FORTRAN_format("Iw", 'I', nothing, 10, 0, 0, 0)

t = cast_FORTRAN_format("I10.12")
FORTRAN_format("Iw.m", 'I', nothing, 10, 12, 0, 0)

t = cast_FORTRAN_format("E10.5E3")
FORTRAN_format("Ew.dEe", 'E', nothing, 10, 0, 5, 3)

t.Type, t.TypeChar, t.EngSci, t.width, t.nmin, t.ndec, t.nexp
("Ew.dEe", 'E', nothing, 10, 0, 5, 3)
source
CamiXon.cast_FORTRAN_datatypeMethod
cast_FORTRAN_datatype(format::String)

Decompose the format specifier 'format' into its fields and cast this into the FORTRAN_format object. Allowed format specifiers are of the types: Aw, Iw, Fw.d, Ew.d, Dw.d, where: 'w' - width, 'd' - number of digits to right of decimal point.

Examples:

f = cast_FORTRAN_datatype("I10")
FORTRAN_format("Iw", 'I', nothing, 10, 0, 0, 0)

f = cast_FORTRAN_datatypet("F10.4")
FORTRAN_format("Fw.d", 'F', nothing, 10, 0, 4, 0)

f = cast_FORTRAN_datatype("E10.5")
FORTRAN_format("Ew.d", 'E', nothing, 10, 0, 5, 0)

t.Type, t.TypeChar, t.EngSci, t.width, t.nmin, t.ndec, t.nexp
("Ew.d", 'E', nothing, 10, 0, 5, 0)
source

Plotting

CamiXon.step125Method
step125(x)

Step used for deviding the number x in steps according to 1-2-5 scheme

Examples:

step125.([5,10,21.3,50,100.1])
5-element Vector{Int64}:
  1
  2
  5
 10
 20
source
CamiXon.select125Method
select125(x)

Select elements of the collection x by index according to 1-2-5 scheme

Examples:

x = [1,2,4,6,8,10,13,16,18,20,40,60,80,100]
select125(x)
 [2, 6, 10, 16, 20, 60, 100]

x = string.(x)
select125(x)
 ["2", "6", "10", "16", "20", "60", "100"]

x = 1:100
select125(x)
 [20, 40, 60, 80, 100]
source
CamiXon.stepsMethod
steps(x)

Heatmap range transformation for steplength specification vector x

Examples:

x = [4,2,6]
steps(x)
 [0, 4, 6, 12]
source
CamiXon.stepcentersMethod
stepcenters(x)

Stepcenter positions for steplength specification vector x

Examples:

x = [4,2,6]
stepcenters(x)
 [2.0, 5.0, 9.0]
source
CamiXon.stepedgesMethod
stepedges(x)

Stepedges for steplength specification vector x

Examples:

x = [4,2,6]
stepedges(x)
 [0, 4, 6, 12]
source
CamiXon.edgesFunction
edges(px [, Δx[, x0]])

Heatmap range transformation from pixel coordinates to physical coordinates, with pixelsize Δx and offset x0, both in physical units.

Examples:

px = 1:5
Δx = 2.5
x0 = 2.5
edges(px)
 [0.5, 1.5, 2.5, 3.5, 4.5]

edges(px, Δx)
 [1.25, 3.75, 6.25, 8.75, 11.25]

edges(px, Δx, x0)
 [-1.25, 1.25, 3.75, 6.25, 8.75]
source

Search algorithms

CamiXon.find_allMethod
find_all(A [,a...]; count=false)

A: string/array of elements of the same type

default : Array containing the index (indices) of selected elements of A (default: all elements)

count=true: The number of indices found for selected elements of A (default: all elements)

Examples:

A = [:📑,:📌,:📢,:📌,:📞]
B = [1,2,3,2,5]
str = "aβcβd";
find_all(A) == find_all(B) == find_all(str)
true

find_all(A,:📌)
1-element Array{Array{Int64,1},1}:
 [2, 4]

find_all(str)
4-element Array{Array{Int64,1},1}:
 [1]
 [2, 4]
 [3]
 [5]

find_all(A; count=true)
4-element Array{Int64,1}:
 1
 2
 1
 1

str = "📑📌📢📌📞"
find_all(str,'📌')
1-element Array{Array{Int64,1},1}:
 [2, 4]
source
CamiXon.find_firstMethod
find_first(A [,a...]; dict=false)

The first index of selected Array element

A: string/array of elements of the same type

default : Array containing the first index (indices) of selected elements of A (default: all elements)

dict=true: Dict for the first index (indices) of selected elements of A (default: all elements)

Examples:

A = [:📑,:📌,:📢,:📌,:📞]
B = [1,2,3,2,5]
str = "aβcβd";

find_first(A) == find_first(B) == find_first(str)
true

find_first(A,:📌)
1-element Array{Array{Int64,1},1}:
 2

find_last(A,:📌; dict=true)
1-element Array{Pair{Symbol,Int64},1}:
 :📌 => 2

find_last(A; dict=true)
4-element Array{Pair{Symbol,Int64},1}:
 :📑 => 1
 :📌 => 2
 :📢 => 3
 :📞 => 5

find_first(str)
4-element Array{Int64,1}:
 1
 2
 3
 5
source
CamiXon.find_lastMethod
find_last(A [,a...]; dict=false)

The last index of selected Array element

A: string/array of elements of the same type

default : Array containing the lasst index (indices) of selected elements of A (default: all elements)

dict=true: Dict for the lasst index (indices) of selected elements of A (default: all elements)

Examples:

A = [:📑,:📌,:📢,:📌,:📞]
B = [1,2,3,2,5]
str = "aβcβd";
find_last(A) == find_first(B) == find_first(str)
true

find_last(A,:📌)
1-element Array{Array{Int64,1},1}:
 4

find_last(A,:📌; dict=true)
1-element Array{Pair{Symbol,Int64},1}:
 :📌 => 4

find_last(A; dict=true)
4-element Array{Pair{Symbol,Int64},1}:
 :📑 => 1
 :📌 => 4
 :📢 => 3
 :📞 => 5

find_last(str)
4-element Array{Int64,1}:
 1
 4
 3
 5
source

Math

CamiXon.bernoulli_numbersMethod
bernoulli_numbers(nmax [, T=Int])

Bernoulli numbers $B_0,\ \cdots,\ B_{nmax}$ calculated by repetative use of the recurrence relation

\[ B_n = - \frac{1}{n+1}\sum_{k=0}^{n-1}\frac{(n+1)!}{k!(n+1-k)}B_k.\]

Special numbers: $B_0=1,\ B_1=-1/2,\ B_{2n+1}=0\ (\rm{for}\ n>1)$.

Examples:

bernoulli_numbers(10)
11-element Vector{Rational{Int64}}:
  1//1
 -1//2
  1//6
  0//1
 -1//30
  0//1
  1//42
  0//1
 -1//30
  0//1
  5//66
source
CamiXon.canonical_partitionsFunction
canonical_partitions(n; header=false, reverse=true)

The canonical partition in integers of the integer n

header=true : unit patition included in output

Examples:

canonical_partitions(6; header=true, reverse=false)
6-element Array{Array{Int64,1},1}:
 [6]
 [5, 1]
 [4, 2]
 [3, 3]
 [2, 2, 2]
 [1, 1, 1, 1, 1, 1]

canonical_partitions(6; header=true)
6-element Array{Array{Int64,1},1}:
 [1, 1, 1, 1, 1, 1]
 [2, 2, 2]
 [3, 3]
 [4, 2]
 [5, 1]
 [6]

canonical_partitions(6)
5-element Array{Array{Int64,1},1}:
 [1, 1, 1, 1, 1, 1]
 [2, 2, 2]
 [3, 3]
 [4, 2]
 [5, 1]
source
CamiXon.faulhaber_polynomMethod
faulhaber_polynom(p [, T=Int])

Vector representation of the Faulhaber polynomial of degree $p$,

\[ F(n,p)=\frac{1}{p}\sum_{j=1}^{p}{\binom {p}{p-j}}B_{p-j}n^{j}.\]

$F(n,p)=$ polynom(c,n), where $c=[c_0,\cdots,\ c_p]$ is the coefficient vector, with

\[ c_0=0,\ c_j=\frac{1}{p}{\binom {p}{p-j}}B_{p-j},\]

with $j∈\{ 1,\cdots,\ p\}$. The $B_0,\cdots,\ B_{p-1}$ are Bernoulli numbers (but with $B_1=+\frac{1}{2}$ rather than $-\frac{1}{2}$).

Example:

faulhaber_polynom(6)
7-element Vector{Rational{Int64}}:
  0//1
  0//1
 -1//12
  0//1
  5//12
  1//2
  1//6
source
CamiXon.faulhaber_summationMethod
faulhaber_summation(n, p [, T=Int])

Sum of powers of natural numbers $1,\ \cdots,\ n$,

\[ FS(n,p)=\sum_{k=1}^{n}k^{p}=F(n,p+1).\]

where $F(n,p)$ is the Faulhamer polynomial of degree $p$.

Examples:

faulhaber_summation(5,1)
 15

faulhaber_summation(3,60; T=BigInt)
  42391158276369125018901280178
source
CamiXon.harmonic_numberMethod
harmonic_number(n, p [, T=Int])

Sum of the $p_{th}$ power of reciprocals of the first $n$ numbers

\[ H_{n,p}=\sum_{k=1}^{n}\frac{1}{k^p}.\]

Examples:

harmonic_number(12, 3)
 25535765062457//21300003648000

harmonic_number(12, 5; T=BigInt)
 16971114472329088045481//16366888723117363200000

harmonic_number(12, -3) == faulhaber_summation(12, 3)
  true
source
CamiXon.harmonic_numberMethod
harmonic_number(n [, T=Int])

Sum of the reciprocals of the first $n$ natural numbers

\[ H_n=\sum_{k=1}^{n}\frac{1}{k}.\]

Examples:

o = [harmonic_number(i) for i=1:10]; println(o)
 [1//1, 3//2, 11//6, 25//12, 137//60, 49//20, 363//140, 761//280, 7129//2520, 7381//2520]

harmonic_number(60; T=BigInt)
 15117092380124150817026911//3230237388259077233637600

harmonic_number(12) == harmonic_number(12, 1)
 true
source
CamiXon.integer_partitionsFunction
integer_partitions(n [,m]; transpose=false, count=false)

default : The integer partitions of n

count=true : The number of integer partitions of n

transpose=false/true : for m>0 restricted to partitions with maximum part/length m

definitions:

The integer partition of the positive integer n is a nonincreasing sequence of positive integers p1, p2,... pk whose sum is n.

The elements of the sequence are called the parts of the partition.

Examples:

integer_partitions(7)
15-element Array{Array{Int64,1},1}:
 [1, 1, 1, 1, 1, 1, 1]
 [2, 2, 2, 1]
 [3, 3, 1]
 [4, 3]
 [5, 2]
 [6, 1]
 [7]
 [2, 2, 1, 1, 1]
 [3, 2, 2]
 [4, 2, 1]
 [5, 1, 1]
 [2, 1, 1, 1, 1, 1]
 [3, 2, 1, 1]
 [4, 1, 1, 1]
 [3, 1, 1, 1, 1]

integer_partitions(7; count=true)
15

integer_partitions(7,4; count=true)
3

integer_partitions(7,4)
3-element Array{Array{Int64,1},1}:
 [4, 3]
 [4, 2, 1]
 [4, 1, 1, 1]

integer_partitions(7,4; transpose=true)
3-element Array{Array{Int64,1},1}:
 [2, 2, 2, 1]
 [3, 2, 1, 1]
 [4, 1, 1, 1]
source
CamiXon.log10_characteristic_powerMethod
log10_characteristic_power(x)

characteristic power-of-10 of the number x

Examples:

log10_characteristic_power.([3,30,300])
3-element Vector{Int64}:
 0
 1
 2
source
CamiXon.log10_mantissaMethod
log10_mantissa(x)

log10 mantissa of the number x

Examples:

log10_mantissa.([3,30,300])
3-element Vector{Float64}:
 0.47712125471966244
 0.4771212547196624
 0.4771212547196626
source
CamiXon.permutations_unique_countMethod
permutations_unique_count(p::Array{Array{Int64,1},1}, i::Int)

Number of unique permutations of the subarray $p[i]$.

Example:

p = [[1,2,3],[2,3,1,4,3]]
permutations_unique_count(p,2)
 60
source
CamiXon.pascal_triangleMethod
pascal_triangle(nmax [, T=Int])

Pascal triangle of binomial coefficients $\binom{n}{k}$ for $n=0,\ 1,\ \cdots,\ nmax$

Example:

pascal_triangle(5)
6-element Vector{Vector{Int64}}:
 [1]
 [1, 1]
 [1, 2, 1]
 [1, 3, 3, 1]
 [1, 4, 6, 4, 1]
 [1, 5, 10, 10, 5, 1]
source
CamiXon.pascal_nextMethod
pascal_next(nmax)

Next row of Pascal triangle

Example:

a = [1, 4, 6, 4, 1]
pascal_next(a)
 [1, 5, 10, 10, 5, 1]
source
CamiXon.polynomMethod
polynom(coords,x)

Method to evaluate the function $f(x)=polynom(c,x)$, where $c=[c_0,\ \ldots,\ c_d]$ is the vector representation of a polynomial of degree $d$.

\[ p(c,x)=c_0 + c_1 x + \cdots + c_d x^d.\]

Examples:

coords = ones(6)             # for polynomial of degree 5 with unit coefficients
f(x) = polynom(coords,x)
println([f(1.0),f(2.0)])     # values of polynomial for x = 1.0 and x = 2.0
 [6.0, 63.0]
source
CamiXon.polynom_derivativeMethod
polynom_derivative(coords)

Vector representation of the first derivative of the polynomial coords,

\[ p'(c,x)=c_1 + 2 c_2 x + \cdots + d c_d x^{d-1},\]

Polynomials of degree $d$ are represented by a vector in a vector space of dimension $d+1$. The polynomial coords is specified by the coordinates vector $c=[c_0,\ \ldots,\ c_d]$ consisting of the polynomial coefficients.

Examples:

coords=[1,1,1,1,1]                 # vector representation of polynomial of degree d=4
polynom_derivative(coords)         # (first) derivative of polynomial `coords`
4-element Vector{Int64}:
 1
 2
 3
 4
source
CamiXon.polynom_derivativesMethod
polynom_derivatives(coords[,deriv=0])

Vector representation of derivatives of the polynomial coords.

Polynomials of degree $d$ are represented by a vector in a vector space of dimension $d+1$. The polynomial coords is specified by the coordinates vector $c=[c_0,\ \ldots,\ c_d]$ consisting of the polynomial coefficients.

deriv: derivative of choice; default: collection of all (nontrivial) derivatives.

Examples:

coords=[1,1,1,1,1]               # vector representation of a polynomial of degree d=4
polynom_derivatives(coords)      # `all' (nontrivial) derivatives of polynomial `coords`
5-element Vector{Vector{Int64}}:
 [1, 2, 3, 4]
 [2, 6, 12]
 [6, 24]
 [24]
 [0]

polynom_derivatives(coords; deriv=2)          # second derivative of polynomial `coords`
3-element Vector{Int64}:
  2
  6
 12
source
CamiXon.polynom_powerMethod
polynom_power(coords, p)

Vector representation of the polynomial coords raised to the power p which results in a polynomial in a vector space of dimension $p d + 1$.

Polynomials of degree $d$ are represented by a vector in a vector space of dimension $d+1$. The polynomial coords is specified by the coordinates vector $c=[c_0,\ \ldots,\ c_d]$ consisting of the polynomial coefficients.

Examples:

coords=[1,1,1]             # vector representation of polynomial of degree ``d=2``
polynom_power(coords,2)
5-element Vector{Int64}:
 1
 2
 3
 2
 1
source
CamiXon.polynom_powersMethod
polynom_powers(coords, pmax)

The polynomial coords raised to the powers 1,...,pmax which results in a collection of polynomials in vector spaces of dimension $d+1$ tot $p d + 1$.

Polynomials of degree $d$ are represented by a vector in a vector space of dimension $d+1$. The polynomial coords is specified by the coordinates vector $c=[c_0,\ \ldots,\ c_d]$ consisting of the polynomial coefficients.

Examples:

coords=[1,1,1]                   # vector representation of polynomial of degree d=2
polynom_powers(coords,3)
3-element Vector{Vector{Int64}}:
 [1, 1, 1]
 [1, 2, 3, 2, 1]
 [1, 3, 6, 7, 6, 3, 1]
source
CamiXon.polynom_primitiveMethod
polynom_primitive(coords)

Vector representation of the primitive of the polynomial coords which is a polynomial in a vector space of dimension $p d + 1$.

\[ P(c,x)=c_{int} +c_0 x + \frac{1}{2} c_1 x^2 + \frac{1}{3} c_2 x^3 + \cdots + \frac{1}{d+1} c_d x^{d+1},\]

The constant of integration is set to zero, $c_{int} = 0$.

Polynomials of degree $d$ are represented by a vector in a vector space of dimension $d+1$. The polynomial coords is specified by the coordinates vector $c=[c_0,\ \ldots,\ c_d]$ consisting of the polynomial coefficients.

Examples:

coords=[1,1,1,1,1]         # vector representation of polynomial of degree ``d=4``
polynom_primitive(coords)
6-element Vector{Rational{Int64}}:
 0//1
 1//1
 1//2
 1//3
 1//4
 1//5
source
CamiXon.polynom_productMethod
polynom_product(a::Vector{<:Number}, b::Vector{<:Number})

Vector representation of the product of two polynomials, $a$ and $b$ which is a polynomial in a vector space of dimension $d=m+n$,

\[ p(c,x)=a_0b_0 + (a_0b_1 + b_0a_1)x + \cdots + a_n b_m x^{n+m}.\]

Polynomials of degree $d$ are represented by a vector in a vector space of dimension $d+1$ The polynomial coords is specified by the coordinates vector $c=[c_0,\ \ldots,\ c_d]$ consisting of the polynomial coefficients.

a = [1,1]
b = [1,- 1]
o = polynomial_product(a, b); println(o)
 [1, 0, -1]
source
CamiXon.polynom_product_expansionMethod
polynom_product_expansion(a::Vector{<:Number}, b::Vector{<:Number}, p::Int)

Vector representation of the product of two polynomials, $a$ (of degree $n$) and $b$ (of degree $m$), with $m≤n$ truncated at the order $p$ is a polynomial in a vector space of dimension $d=p+1$. If $ab$ is the polynom_product, the polynom_product_expansion is $ab[1:p+1]$

a = [1,-1,1]
b = [1,1,-1,1,1,1]
o = polynom_product(a, b); println(o)
 [1, 0, -1, 3, -1, 1, 0, 1]

o = expand_product(a, b, 4); println(o)
 [1, 0, -1, 3, -1]
source
CamiXon.VectorRationalType
VectorRational

Object to decompose a vector of rational numbers

The fields are:

  • .num::Vector{Int}`: vector of normalized numerators
  • .den::Int: common denominator
  • .val::Vector{Rational}: vector of rational numbers (simplified = not normalized)
source
CamiXon.normalize_VectorRationalMethod
normalize_VectorRational(vec::Vector{Rational{Int}})

Decompose vector of rational numbers.

Example:

v = [2//3,4//5]
normalize_VectorRational(v)
 VectorRational([10, 12], 15, Rational{Int64}[2//3, 4//5])
source

Index