# Universal Approach to Solution of Optimization Problems by Symbolic Regression
## 4 Small Variations for Symbolic Regression Methods
### Variational Complete Binary Genetic Programming  
Complete binary genetic programming (CBGP) encodes mathematical expressions as complete binary trees. For this structure, only functions with one or two arguments are used. Functions with two arguments are associated with tree nodes, functions with one argument are are associated with tree branches. Arguments of mathematical expressions and unit elements for functions with two arguments are placed on the leaves of the tree. Since the tree is complete, the number of elements at each level is known. There is no need to specify the number of arguments for the function when writing code to store it in computer memory. The quantity of arguments is determined by the position of the function in the code. Unit elements for functions with two arguments are added to the set of arguments.  
To encode a mathematical expression (38) by CBGP, we use sets of elementary functions with one and two arguments (40) and (41). We add unit elements for functions with two arguments in the set of arguments (39), i.e. zero for addition and one for multiplication  
\[\mathrm{F}_{0}=(f_{1}=x_{1},f_{2}=x_{2},f_{3}=q_{1},f_{4}=q_{2},f_{5}=0,f_{6}=1). \tag{64}\]  
A CBGP computational tree for mathematical expression (38) is given in Figures 3 and 4.  
CBGP code is an ordered set of function indices from a tree, written sequentially from left to right. At the last level, the indices of arguments from the set (64) are indicated.  
The CBGP code for mathematical expression (38) is  
\[\begin{array}{rcl}\mathrm{S}&=&(1,\,1,\\ &&3,5,\,1,\\ &&4,1,2,1,\,1,2,2,1,\\ &&1,1,1,1,1,1,1,\,2,1,2,2,1,1,2,\\ &&1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,\,3,1,4,5,6,5,6,5,2,5,4,5,6,5,6,5). \end{array} \tag{65}\]  
Here, for convenience, the CBGP code is presented on different lines according to the levels of the tree. Each level \(k\) contains \(2^{k}\) number of functions with one argument and the same number of functions with two arguments. Altogether, there are \(2^{k+1}\) elements at the level \(k\). The total number of elements \(L\) in the CBGP code for a binary tree with \(K\) levels is calculated as  
\[L=\sum_{k=0}^{K}2^{k+1}=2^{1}+2^{2}+\ldots+2^{K+1}=2^{K+2}-2. \tag{66}\]  
In the considered example, we have \(K=4\) levels and thus \(2^{4+2}-2=62\) elements.  
To determine whether element \(f_{s_{k}}\), where \(\alpha\) is an index of element in the code, belongs to one of the sets \(\mathrm{F}_{0}\), \(\mathrm{F}_{1}\), or \(\mathrm{F}_{2}\), we use the following relations  
\[f_{s_{k}}\in\left\{\begin{array}{ll}\mathrm{F}_{0},\;\mathrm{if}\;2^{k+2}-2 ^{k}\leqslant\alpha\leqslant 2^{k+2}-2\;\mathrm{and}\;\;k=K\\ \mathrm{F}_{1},\;\mathrm{if}\;2^{k+1}-1\leqslant\alpha\leqslant 2^{k+2}-2^{k}-2\\ \mathrm{F}_{2},\;\mathrm{if}\;2^{k+2}-2^{k}\leqslant\alpha\leqslant 2^{k+2}-2 \;\mathrm{and}\;k<K\end{array}\right., \tag{67}\]  
Figure 4: CBGP computational tree for mathematical expression (38) (continued).  
Figure 3: CBGP computational tree for mathematical expression (38).  
where \(k\) is the smallest number, that satisfies inequality  
\[\alpha\leqslant 2^{k+2}-2. \tag{68}\]  
To present a small variation of CBGP code, let us use a vector of two elements  
\[\mathbf{w}=[w_{1}\ w_{2}]^{T}, \tag{69}\]  
where \(w_{1}\) is an index of element position and \(w_{2}\) is a new value of element.  
Consider an example of small variations of CBGP code (65) that describes the mathematical expression (38)  
\[\begin{array}{rcl}\mathbf{w}^{1}&=&[12\ 1]^{T},\\ \mathbf{w}^{2}&=&[55\ 3]\\ \mathbf{w}^{3}&=&[7\ 5]^{T}\\ \mathbf{w}^{4}&=&[50\ 1]\end{array}. \tag{70}\]  
Having performed variations (70), we obtain a new CBGP code  
\[\begin{array}{rcl}\mathrm{S}&=&(1,\,1,\\ &3,5,\,1,1,\\ &&5,1,2,1,\,1,1,2,1,\\ &&1,1,1,1,1,1,1,1,\,2,1,2,2,1,1,2,\\ &&1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,\,3,1,4,1,6,5,6,5,3,5,4,5,6,5,6,5). \end{array} \tag{71}\]  
This code presents a new mathematical expression  
\[y=\sin(\exp(q_{1}x_{1}+q_{2}+x_{1}))+\exp(-(q_{1}+q_{2})). \tag{72}\]