Exponential function is very important to evaluate activation functions (Sigmoid, hyperbolic tangent, SoftMax etc.) used in machine learning (ML) algorithms. Thus, efficient hardware implementation of exponential function very important. In this post, we have discussed detailed FPGA Implementation of Taylor Series Based Exponential function.
Many techniques are reported in literature to compute exponential function. Taylor series expansion is one of the popular technique to approximate exponential function. Taylor series expansion of exponential function for positive value of x is
(1) ![Rendered by QuickLaTeX.com \begin{equation*} e^{x} = 1+x+\frac{x^2}{2!}+\frac{x^3}{3!}+\cdots \end{equation*}](https://digitalsystemdesign.in/wp-content/ql-cache/quicklatex.com-d370589a7b0c4dec632fd42e1907f34e_l3.png)
Taylor series expansion of exponential function for negative value of x is
(2) ![Rendered by QuickLaTeX.com \begin{equation*} e^{-x} = 1-x+\frac{x^2}{2!}-\frac{x^3}{3!}+\cdots \end{equation*}](https://digitalsystemdesign.in/wp-content/ql-cache/quicklatex.com-cc45518fbba98edef0b8403e48b0ecfd_l3.png)
Exponential function can be approximated by taking 4 terms of Taylor series only. The above equations can be evaluated by serial computation step by step. Taking only 4 terms, the above equation for positive exponential can be written as
(3) ![Rendered by QuickLaTeX.com \begin{equation*} e^{x} = 1 + x(1 + \frac{x}{2}(1+\frac{x}{3})) \end{equation*}](https://digitalsystemdesign.in/wp-content/ql-cache/quicklatex.com-b7f3d4c37f2bf5f72d6d3876d0ddadc0_l3.png)
Similarly, the negative exponential can be written as
(4) ![Rendered by QuickLaTeX.com \begin{equation*} e^{-x} = 1 - x(1 - \frac{x}{2}(1-\frac{x}{3})) \end{equation*}](https://digitalsystemdesign.in/wp-content/ql-cache/quicklatex.com-777fa6dba5bb0c2e2160a0390950eee3_l3.png)
The range of exponential function is an issue in implementing the activation functions in ML algos. All the algorithms for exponential calculates for input range of -1 to 1. Beyond this range it is not possible to compute exponential function. Thus adjusting input data range is important. But in some applications it is required to extend the range of exponential function. Range can be extended by expressing the input data as
(5) ![Rendered by QuickLaTeX.com \begin{equation*} x = p\times log^2_e + q \end{equation*}](https://digitalsystemdesign.in/wp-content/ql-cache/quicklatex.com-f03b1981ac8fb03e133f2673ee00ce90_l3.png)
Thus q will in the range -1 to 1 and the exponential block will find the exponential of q. At the output exponential of x is computed as
(6) ![Rendered by QuickLaTeX.com \begin{equation*} e^{x} = 2^p \times e^q \end{equation*}](https://digitalsystemdesign.in/wp-content/ql-cache/quicklatex.com-38a05e9041e8ae444fd7811c51edc313_l3.png)
The exponential block architecture should be designed such a way that it can compute exponential for both positive and negative values. A parralel and pipelined architecture is designed here and shown in Figure 1. The computation of x/3 is performed by a scale block. More about the scale block architecture is given in our earlier post. The architecture uses precision of 9 bits. Means 9 bits are used for fractional part. Total 12 bits are enough to accommodate the whole range of exponential function when input range is from -1 to 1. An ctrl signal is used to control the operation of adder/subtracters. If the ctrl signal is high, then subtraction is performed. The architecture has total latency of 7 clock cycles and achieves more than 200 MHz frequency.
![](https://digitalsystemdesign.in/wp-content/uploads/2025/02/exp1_1-1024x463.png)
The scale block architecture to divide input data by 3 is shown in Figure 2. The red colored texts are intermediate wires shown
![](https://digitalsystemdesign.in/wp-content/uploads/2025/02/scale.png)
The architecture has acceptable accuracy. The error is introduced is due to avoidance of few terms on Taylor series and having precision of 9 bits. The simulation for FPGA Implementation of Taylor Series Based Exponential is shown below
![](https://digitalsystemdesign.in/wp-content/uploads/2025/02/simulation-1024x311.png)
The Verilog code can be found here
Verilog Code for FPGA Implementation of Taylor Series Based Exponential (28 downloads )