Table Of Contents

This Page

Appendix A. List of functions

The list of all functions can be obtained using i+ types. Some formulae here have long parameter names (like “height”, “center” and “hwhm”) replaced with a_i

Gaussian:

y = a_0
    \exp\left[-\ln(2)\left(\frac{x-a_1}{a_2}\right)^{2}\right]

SplitGaussian:

y(x;a_0,a_1,a_2,a_3) = \begin{cases}
\textrm{Gaussian}(x;a_0,a_1,a_2) & x\leq a_1\\
\textrm{Gaussian}(x;a_0,a_1,a_3) & x>a_1\end{cases}

GaussianA:

y = \sqrt{\frac{\ln(2)}{\pi}}\frac{a_0}{a_2}
    \exp\left[-\ln(2)\left(\frac{x-a_1}{a_2}\right)^{2}\right]

Lorentzian:

y = \frac{a_0}{1+\left(\frac{x-a_1}{a_2}\right)^2}

SplitLorentzian:

y(x;a_0,a_1,a_2,a_3) = \begin{cases}
\textrm{Lorentzian}(x;a_0,a_1,a_2) & x\leq a_1\\
\textrm{Lorentzian}(x;a_0,a_1,a_3) & x>a_1\end{cases}

LorentzianA:

y = \frac{a_0}{\pi a_2\left[1+\left(\frac{x-a_1}{a_2}\right)^2\right]}

Pearson VII (Pearson7):

y = \frac{a_0} {\left[1+\left(\frac{x-a_1}{a_2}\right)^2
                        \left(2^{\frac{1}{a_3}}-1\right)\right]^{a_3}}

split Pearson VII (SplitPearson7):

y(x;a_{0},a_{1},a_{2},a_{3},a_{4},a_{5}) = \begin{cases}
 \textrm{Pearson7}(x;a_0,a_1,a_2,a_4) & x\leq a_1\\
 \textrm{Pearson7}(x;a_0,a_1,a_3,a_5) & x>a_1\end{cases}

Pearson VII Area (Pearson7A):

y = \frac{a_0\Gamma(a_3)\sqrt{2^{\frac{1}{a_3}}-1}}
         {a_2\Gamma(a_3-\frac{1}{2})\sqrt{\pi} \left[
            1 + \left(\frac{x-a_1}{a_2}\right)^2
                \left(2^{\frac{1}{a_3}}-1\right)
         \right]^{a_3}}

Pseudo-Voigt (PseudoVoigt):

y = a_0 \left[(1-a_3)\exp\left(-\ln(2)\left(\frac{x-a_1}{a_2}\right)^2\right)
              + \frac{a_3}{1+\left(\frac{x-a_1}{a_2}\right)^2}
        \right]

Pseudo-Voigt is a name given to the sum of Gaussian and Lorentzian. a_3 parameters in Pearson VII and Pseudo-Voigt are not related.

split Pseudo-Voigt (SplitPseudoVoigt):

y(x;a_{0},a_{1},a_{2},a_{3},a_{4},a_{5}) = \begin{cases}
 \textrm{PseudoVoigt}(x;a_0,a_1,a_2,a_4) & x\leq a_1\\
 \textrm{PseudoVoigt}(x;a_0,a_1,a_3,a_5) & x>a_1\end{cases}

Pseudo-Voigt Area (PseudoVoigtA):

y = a_0 \left[\frac{(1-a_3)\sqrt{\ln(2)}}{a_2\sqrt{\pi}}
              \exp\left(-\ln2\left(\frac{x-a_1}{a_2}\right)^2\right)
              + \frac{a_3}{\pi a_2
                           \left[1+\left(\frac{x-a_1}{a_2}\right)^2\right]}
        \right]

Voigt:

y = \frac
    {a_0 \int_{-\infty}^{+\infty}
             \frac{\exp(-t^2)}{a_3^2+(\frac{x-a_1}{a_2}-t)^2} dt}
    {\int_{-\infty}^{+\infty}
             \frac{\exp(-t^2)}{a_3^2+t^2} dt}

The Voigt function is a convolution of Gaussian and Lorentzian functions. a_0 = heigth, a_1 = center, a_2 is proportional to the Gaussian width, and a_3 is proportional to the ratio of Lorentzian and Gaussian widths.

Voigt is computed according to R.J.Wells, Rapid approximation to the Voigt/Faddeeva function and its derivatives, Journal of Quantitative Spectroscopy & Radiative Transfer 62 (1999) 29-48. (See also: http://www.atm.ox.ac.uk/user/wells/voigt.html). The approximation is very fast, but not very exact.

FWHM is estimated using the approximation by Olivero and Longbothum (JQSRT 17, 233 (1977)): 0.5346 w_L + \sqrt{0.2169 w_L^2 + w_G^2}.

VoigtA:

y = \frac{a_0}{\sqrt{\pi}a_2}
    \int_{-\infty}^{+\infty}
        \frac{\exp(-t^2)}{a_3^2+(\frac{x-a_1}{a_2}-t)^2} dt

Exponentially Modified Gaussian (EMG):

y = \frac{ac\sqrt{2\pi}}{2d}
    \exp\left(\frac{b-x}{d}+\frac{c^2}{2d^2}\right)
    \left[\frac{d}{\left|d\right|}
          -\textrm{erf}\left(\frac{b-x}{\sqrt{2}c}
                             + \frac{c}{\sqrt{2}d}\right)
    \right]

LogNormal:

y = h \exp\left\{ -\ln(2) \left[
                                \frac{\ln\left(1+2b\frac{x-c}{w}\right)}{b}
                         \right]^{2} \right\}

Doniach-Sunjic (DoniachSunjic):

y = \frac{h\left[\frac{\pi a}{2}
                 + (1-a)\arctan\left(\frac{x-E}{F}\right)\right]}
         {F+(x-E)^2}

Polynomial5:

y = a_0 + a_1 x +a_2 x^2 + a_3 x^3 + a_4 x^4 + a_5 x^5

Appendix B. Grammar

The fityk mini-language (or domain-specific language) was designed to perform easily most common tasks. The language has no flow control (but that’s what Python, Lua and other bindings are for). Each line is parsed and executed separately. Typically, one line contains one statement. It can also be empty or contain multiple ‘;’-separated statements.

The grammar below is not complete and may change in the future.

The grammar is expressed in EBNF-like notation:

  • (*this is a comment*)
  • A* means 0 or more occurrences of A.
  • A+ means 1 or more occurrences of A.
  • A % B means A (B A)* and the % operator has the highest precedence. For example: statement % ";" comment is the same as statement (";" statement)* comment.
  • The colon ‘:’ in quoted string means that the string can be shortened, e.g. "del:ete" mean that any of del, dele, delet and delete can be used.

The functions that can be used in p_expr and v_expr are available here and here, respectively. var_rhs contains only a subset of functions from p_expr (partly, because we need to calculate symbolical derivatives of var_rhs)

(*
planned changes (already included in the grammar below):
commands > file            ->   set logfile file
commands < file            ->   exec file
commands ! shell-command   ->   exec ! shell-command
dump > file                ->   info state > file
guess Func [:] center=30   ->   guess Func(center=30) [:]

%f = guess Func in @0      ->   guess %f=Func in @0

numarea(%f, 10, 30, 100)   ->   %f.numarea(10, 30, 100)

cmd in @m, @n              -> @m @n: cmd
* )

Line structure

line      ::=  statement % ";" [comment]
statement ::=  [Dataset+ ":"] [options] command
options   ::=  "w:ith" set % ","
comment   ::=  "#" AllChars*

Commands

The kCmd* names in the comments correspond to constants in the code.

command ::=  (
             "debug" RestOfLine            | (*kCmdDebug*)
             "def:ine" define              | (*kCmdDefine*)
             "del:ete" delete              | (*kCmdDelete*)
             "del:ete" delete_points       | (*kCmdDeleteP*)
             "e:xecute" exec               | (*kCmdExec*)
             "f:it" fit                    | (*kCmdFit*)
             "g:uess" guess                | (*kCmdGuess*)
             "i:nfo" info_arg % "," redir  | (*kCmdInfo*)
             "p:lot" [range [range]]       | (*kCmdPlot*)
             "pr:int" print redir          | (*kCmdPrint*)
             "quit"                        | (*kCmdQuit*)
             "reset"                       | (*kCmdReset*)
             "s:et" set % ","              | (*kCmdSet*)
             "sleep" expr                  | (*kCmdSleep*)
             "title" "=" filename          | (*kCmdTitle*)
             "undef:ine" Uname % ","       | (*kCmdUndef*)
             "!" RestOfLine                    | (*kCmdShell*)
             Dataset "<" load_arg          | (*kCmdLoad*)
             Dataset "=" dataset_tr_arg    | (*kCmdDatasetTr*)
             Funcname "=" func_rhs         | (*kCmdNameFunc*)
             param "=" v_expr              | (*kCmdAssignParam*)
             Varname "=" v_expr            | (*kCmdNameVar*)
             model_id ("="|"+=") model_rhs | (*kCmdChangeModel*)
             model_id "-=" func_id         | (*also kCmdChangeModel*)
             (p_attr "[" expr "]" "=" p_expr) % "," | (*kCmdPointTr*)
             (p_attr "=" p_expr) % ","     | (*kCmdAllPointsTr*)
             "M" "=" expr                  | (*kCmdResizeP*)
             ""                            ) (*kCmdNull*)

Other rules

define         ::=  Uname "(" (Lname [ "=" v_expr]) % "," ")" "="
                       ( v_expr |
                         type_inst % "+" |
                         "x" "<" v_expr "?" type_inst ":" type_inst
                       )
delete         ::=  (Varname | func_id | Dataset) % ","
delete_points  ::=  "(" p_expr ")"
exec           ::=  filename |
                    "!" RestOfLine
fit            ::=  ["+"] `Number` |
                    "undo" |
                    "redo" |
                    "history" `Number` |
                    "clear_history"
guess          ::=  [Funcname "="] Uname ["(" (Lname "=" v_expr) % "," ")"] [range]
info_arg       ::=  ...TODO
print          ::=  ...TODO
redir          ::=  [(">" | ">>") filename]
set            ::=  Lname "=" (Lname | QuotedString | expr)
param          ::=  func_id "." Lname |
                    model_id "." Lname
model_rhs      ::=  "0" |
                    func_id |
                    func_rhs |
                    model_id |
                    "copy" "(" model_id ")"
func_rhs       ::=  type_inst |
                    "copy" "(" func_id ")"
type_inst      ::=  Uname "(" ([Lname "="] v_expr) % "," ")" |
load_arg       ::=  filename Lname* |
                      "."
dataset_tr_arg ::=  [Lname] (Dataset | "0") % "+"
p_attr         ::=  ("X" | "Y" | "S" | "A")
point_lhs      ::=   point_attr [ "[" expr `"]"` ]
model_id       ::=  [Dataset "."] ("F"|"Z")
func_id        ::=  Funcname |
                    model_id "[" Number "]"
var_id         ::=  Varname |
                    func_id "." Lname
range          ::=  "[" [expr|"."] ":" [expr|"."] "]" | "."
filename       ::=  QuotedString | NonblankString

Mathematical expressions

expr        ::=  expr_or ? expr_or : expr_or
expr_or     ::=  expr_and % "or"
expr_and    ::=  expr_not % "and"
expr_not    ::=  "not" expr_not | comparison
comparison  ::=  arith % ("<"|">"|"=="|">="|"<="|"!=")
arith       ::=  term % ("+"|"-")
term        ::=  factor % ("*"|"/")
factor      ::=  ('+'|'-') factor | power
power       ::=  atom ['**' factor]
atom        ::=  Number | "true" | "false" | "pi" |
                 math_func | braced_expr | ?others?
math_func   ::=  "sqrt" "(" expr ")" |
                 "gamma" "(" expr ")" |
                  ...
braced_expr ::=  "{" [Dataset+ ":"] p_expr "}"

The atom rule also accepts some fityk expressions, such as $variable, %function.parameter, %function(expr), etc.

p_expr and v_expr are similar to expr, but they use additional variables in the atom rule.

p_expr recognizes n, M, x, y, s, a, X, Y, S and A. All of them but n and M can be indexed (e.g. x[4]), and any expression can be given as an index. Example: (x+x[n-1])/2.

v_expr uses all unknown names (Lname) as variables. The tilde (~) can be used to create simple-variables. Only a subset of functions (math_func) from expr is supported. Examples: a+b*x^2, ~5.

Since v_expr is used to define variables and user-defined functions, the program calculates symbolically derivatives of v_expr. That is why not all the function from expr are supported (they may be added in the future).

Lexer

Below, some of the tokens produced by the lexer (a.k.a scanner or tokenizer) are defined.

In the code, there is one token for Dataset* and it is then checked in the parser.

Lexer is context-dependend: NonblankString and RestOfLine are produced only when they are expected in the grammar.

Uname is used only for type names (Gaussian) and pseudo-parameters (%f.Area).

Dataset        ::=  "@"(Digit+|"+"|"*")
Varname        ::=  "$" Lname
Funcname       ::=  "%" Lname
QuotedString   ::=  "'" (AllChars - "'")* "'"
Lname          ::=  (Lowercase | "_") (Lowercase | Digit | "_")*
Uname          ::=  Uppercase AlphaNum+
Number         ::=  ?number in format supported by strtod()?
ShellCommand   ::=  "!" AllChars*
NonblankString ::=  (AllChars - (Whitespace | ";" | "#" ))*
RestOfLine     ::=  AllChars*

Appendix C. License

Fityk is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Text of the license is distributed with the program in the file COPYING.

Appendix D. About this manual

This manual is written using ReStructuredText. All changes, improvements, corrections, etc. are welcome. Use the Show Source link to get the source of the page, save it, edit, and send me either modified version or patch containing changes.

Following people have contributed to this manual (in chronological order): Marcin Wojdyr (maintainer), Stan Gierlotka, Jaap Folmer, Michael Richardson.