exp neg sub

Percentage Accurate: 100.0% → 100.0%
Time: 2.4s
Alternatives: 10
Speedup: 0.5×

Specification

?
\[\begin{array}{l} \\ e^{-\left(1 - x \cdot x\right)} \end{array} \]
(FPCore (x) :precision binary64 (exp (- (- 1.0 (* x x)))))
double code(double x) {
	return exp(-(1.0 - (x * x)));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = exp(-(1.0d0 - (x * x)))
end function
public static double code(double x) {
	return Math.exp(-(1.0 - (x * x)));
}
def code(x):
	return math.exp(-(1.0 - (x * x)))
function code(x)
	return exp(Float64(-Float64(1.0 - Float64(x * x))))
end
function tmp = code(x)
	tmp = exp(-(1.0 - (x * x)));
end
code[x_] := N[Exp[(-N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision])], $MachinePrecision]
\begin{array}{l}

\\
e^{-\left(1 - x \cdot x\right)}
\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 10 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ e^{-\left(1 - x \cdot x\right)} \end{array} \]
(FPCore (x) :precision binary64 (exp (- (- 1.0 (* x x)))))
double code(double x) {
	return exp(-(1.0 - (x * x)));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = exp(-(1.0d0 - (x * x)))
end function
public static double code(double x) {
	return Math.exp(-(1.0 - (x * x)));
}
def code(x):
	return math.exp(-(1.0 - (x * x)))
function code(x)
	return exp(Float64(-Float64(1.0 - Float64(x * x))))
end
function tmp = code(x)
	tmp = exp(-(1.0 - (x * x)));
end
code[x_] := N[Exp[(-N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision])], $MachinePrecision]
\begin{array}{l}

\\
e^{-\left(1 - x \cdot x\right)}
\end{array}

Alternative 1: 100.0% accurate, 0.5× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \frac{{\left(e^{-x\_m}\right)}^{\left(-x\_m\right)}}{e} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m) :precision binary64 (/ (pow (exp (- x_m)) (- x_m)) E))
x_m = fabs(x);
double code(double x_m) {
	return pow(exp(-x_m), -x_m) / ((double) M_E);
}
x_m = Math.abs(x);
public static double code(double x_m) {
	return Math.pow(Math.exp(-x_m), -x_m) / Math.E;
}
x_m = math.fabs(x)
def code(x_m):
	return math.pow(math.exp(-x_m), -x_m) / math.e
x_m = abs(x)
function code(x_m)
	return Float64((exp(Float64(-x_m)) ^ Float64(-x_m)) / exp(1))
end
x_m = abs(x);
function tmp = code(x_m)
	tmp = (exp(-x_m) ^ -x_m) / 2.71828182845904523536;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := N[(N[Power[N[Exp[(-x$95$m)], $MachinePrecision], (-x$95$m)], $MachinePrecision] / E), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|

\\
\frac{{\left(e^{-x\_m}\right)}^{\left(-x\_m\right)}}{e}
\end{array}
Derivation
  1. Initial program 100.0%

    \[e^{-\left(1 - x \cdot x\right)} \]
  2. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \color{blue}{e^{-\left(1 - x \cdot x\right)}} \]
    2. lift-neg.f64N/A

      \[\leadsto e^{\color{blue}{\mathsf{neg}\left(\left(1 - x \cdot x\right)\right)}} \]
    3. lift--.f64N/A

      \[\leadsto e^{\mathsf{neg}\left(\color{blue}{\left(1 - x \cdot x\right)}\right)} \]
    4. lift-*.f64N/A

      \[\leadsto e^{\mathsf{neg}\left(\left(1 - \color{blue}{x \cdot x}\right)\right)} \]
    5. exp-negN/A

      \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
    6. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
    7. pow2N/A

      \[\leadsto \frac{1}{e^{1 - \color{blue}{{x}^{2}}}} \]
    8. exp-diffN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
    9. lower-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
    10. exp-1-eN/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{E}\left(\right)}}{e^{{x}^{2}}}} \]
    11. lower-E.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{e}}{e^{{x}^{2}}}} \]
    12. pow2N/A

      \[\leadsto \frac{1}{\frac{e}{e^{\color{blue}{x \cdot x}}}} \]
    13. exp-prodN/A

      \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    14. lower-pow.f64N/A

      \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    15. lower-exp.f64100.0

      \[\leadsto \frac{1}{\frac{e}{{\color{blue}{\left(e^{x}\right)}}^{x}}} \]
  3. Applied rewrites100.0%

    \[\leadsto \color{blue}{\frac{1}{\frac{e}{{\left(e^{x}\right)}^{x}}}} \]
  4. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{e}{{\left(e^{x}\right)}^{x}}}} \]
    2. lift-E.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{E}\left(\right)}}{{\left(e^{x}\right)}^{x}}} \]
    3. lift-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{E}\left(\right)}{{\left(e^{x}\right)}^{x}}}} \]
    4. lift-exp.f64N/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{{\color{blue}{\left(e^{x}\right)}}^{x}}} \]
    5. lift-pow.f64N/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    6. pow-expN/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{\color{blue}{e^{x \cdot x}}}} \]
    7. pow2N/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{e^{\color{blue}{{x}^{2}}}}} \]
    8. e-exp-1N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{e^{1}}}{e^{{x}^{2}}}} \]
    9. div-expN/A

      \[\leadsto \frac{1}{\color{blue}{e^{1 - {x}^{2}}}} \]
    10. pow2N/A

      \[\leadsto \frac{1}{e^{1 - \color{blue}{x \cdot x}}} \]
    11. exp-negN/A

      \[\leadsto \color{blue}{e^{\mathsf{neg}\left(\left(1 - x \cdot x\right)\right)}} \]
    12. fp-cancel-sub-sign-invN/A

      \[\leadsto e^{\mathsf{neg}\left(\color{blue}{\left(1 + \left(\mathsf{neg}\left(x\right)\right) \cdot x\right)}\right)} \]
    13. distribute-lft-neg-inN/A

      \[\leadsto e^{\mathsf{neg}\left(\left(1 + \color{blue}{\left(\mathsf{neg}\left(x \cdot x\right)\right)}\right)\right)} \]
    14. pow2N/A

      \[\leadsto e^{\mathsf{neg}\left(\left(1 + \left(\mathsf{neg}\left(\color{blue}{{x}^{2}}\right)\right)\right)\right)} \]
    15. distribute-neg-inN/A

      \[\leadsto e^{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left({x}^{2}\right)\right)\right)\right)}} \]
    16. metadata-evalN/A

      \[\leadsto e^{\color{blue}{-1} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left({x}^{2}\right)\right)\right)\right)} \]
    17. mul-1-negN/A

      \[\leadsto e^{-1 + \left(\mathsf{neg}\left(\color{blue}{-1 \cdot {x}^{2}}\right)\right)} \]
    18. distribute-lft-neg-outN/A

      \[\leadsto e^{-1 + \color{blue}{\left(\mathsf{neg}\left(-1\right)\right) \cdot {x}^{2}}} \]
    19. metadata-evalN/A

      \[\leadsto e^{-1 + \color{blue}{1} \cdot {x}^{2}} \]
    20. *-lft-identityN/A

      \[\leadsto e^{-1 + \color{blue}{{x}^{2}}} \]
    21. +-commutativeN/A

      \[\leadsto e^{\color{blue}{{x}^{2} + -1}} \]
    22. pow2N/A

      \[\leadsto e^{\color{blue}{x \cdot x} + -1} \]
  5. Applied rewrites100.0%

    \[\leadsto \color{blue}{\frac{{\left(e^{x}\right)}^{x}}{e}} \]
  6. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \frac{{\color{blue}{\left(e^{x}\right)}}^{x}}{e} \]
    2. lift-pow.f64N/A

      \[\leadsto \frac{\color{blue}{{\left(e^{x}\right)}^{x}}}{e} \]
    3. pow-expN/A

      \[\leadsto \frac{\color{blue}{e^{x \cdot x}}}{e} \]
    4. sqr-neg-revN/A

      \[\leadsto \frac{e^{\color{blue}{\left(\mathsf{neg}\left(x\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right)}}}{e} \]
    5. pow-expN/A

      \[\leadsto \frac{\color{blue}{{\left(e^{\mathsf{neg}\left(x\right)}\right)}^{\left(\mathsf{neg}\left(x\right)\right)}}}{e} \]
    6. lower-pow.f64N/A

      \[\leadsto \frac{\color{blue}{{\left(e^{\mathsf{neg}\left(x\right)}\right)}^{\left(\mathsf{neg}\left(x\right)\right)}}}{e} \]
    7. lower-exp.f64N/A

      \[\leadsto \frac{{\color{blue}{\left(e^{\mathsf{neg}\left(x\right)}\right)}}^{\left(\mathsf{neg}\left(x\right)\right)}}{e} \]
    8. lower-neg.f64N/A

      \[\leadsto \frac{{\left(e^{\color{blue}{-x}}\right)}^{\left(\mathsf{neg}\left(x\right)\right)}}{e} \]
    9. lower-neg.f64100.0

      \[\leadsto \frac{{\left(e^{-x}\right)}^{\color{blue}{\left(-x\right)}}}{e} \]
  7. Applied rewrites100.0%

    \[\leadsto \frac{\color{blue}{{\left(e^{-x}\right)}^{\left(-x\right)}}}{e} \]
  8. Add Preprocessing

Alternative 2: 100.0% accurate, 0.5× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \frac{{\left(e^{x\_m}\right)}^{x\_m}}{e} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m) :precision binary64 (/ (pow (exp x_m) x_m) E))
x_m = fabs(x);
double code(double x_m) {
	return pow(exp(x_m), x_m) / ((double) M_E);
}
x_m = Math.abs(x);
public static double code(double x_m) {
	return Math.pow(Math.exp(x_m), x_m) / Math.E;
}
x_m = math.fabs(x)
def code(x_m):
	return math.pow(math.exp(x_m), x_m) / math.e
x_m = abs(x)
function code(x_m)
	return Float64((exp(x_m) ^ x_m) / exp(1))
end
x_m = abs(x);
function tmp = code(x_m)
	tmp = (exp(x_m) ^ x_m) / 2.71828182845904523536;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := N[(N[Power[N[Exp[x$95$m], $MachinePrecision], x$95$m], $MachinePrecision] / E), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|

\\
\frac{{\left(e^{x\_m}\right)}^{x\_m}}{e}
\end{array}
Derivation
  1. Initial program 100.0%

    \[e^{-\left(1 - x \cdot x\right)} \]
  2. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \color{blue}{e^{-\left(1 - x \cdot x\right)}} \]
    2. lift-neg.f64N/A

      \[\leadsto e^{\color{blue}{\mathsf{neg}\left(\left(1 - x \cdot x\right)\right)}} \]
    3. lift--.f64N/A

      \[\leadsto e^{\mathsf{neg}\left(\color{blue}{\left(1 - x \cdot x\right)}\right)} \]
    4. lift-*.f64N/A

      \[\leadsto e^{\mathsf{neg}\left(\left(1 - \color{blue}{x \cdot x}\right)\right)} \]
    5. exp-negN/A

      \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
    6. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
    7. pow2N/A

      \[\leadsto \frac{1}{e^{1 - \color{blue}{{x}^{2}}}} \]
    8. exp-diffN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
    9. lower-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
    10. exp-1-eN/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{E}\left(\right)}}{e^{{x}^{2}}}} \]
    11. lower-E.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{e}}{e^{{x}^{2}}}} \]
    12. pow2N/A

      \[\leadsto \frac{1}{\frac{e}{e^{\color{blue}{x \cdot x}}}} \]
    13. exp-prodN/A

      \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    14. lower-pow.f64N/A

      \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    15. lower-exp.f64100.0

      \[\leadsto \frac{1}{\frac{e}{{\color{blue}{\left(e^{x}\right)}}^{x}}} \]
  3. Applied rewrites100.0%

    \[\leadsto \color{blue}{\frac{1}{\frac{e}{{\left(e^{x}\right)}^{x}}}} \]
  4. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{e}{{\left(e^{x}\right)}^{x}}}} \]
    2. lift-E.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{E}\left(\right)}}{{\left(e^{x}\right)}^{x}}} \]
    3. lift-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{E}\left(\right)}{{\left(e^{x}\right)}^{x}}}} \]
    4. lift-exp.f64N/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{{\color{blue}{\left(e^{x}\right)}}^{x}}} \]
    5. lift-pow.f64N/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    6. pow-expN/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{\color{blue}{e^{x \cdot x}}}} \]
    7. pow2N/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{e^{\color{blue}{{x}^{2}}}}} \]
    8. e-exp-1N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{e^{1}}}{e^{{x}^{2}}}} \]
    9. div-expN/A

      \[\leadsto \frac{1}{\color{blue}{e^{1 - {x}^{2}}}} \]
    10. pow2N/A

      \[\leadsto \frac{1}{e^{1 - \color{blue}{x \cdot x}}} \]
    11. exp-negN/A

      \[\leadsto \color{blue}{e^{\mathsf{neg}\left(\left(1 - x \cdot x\right)\right)}} \]
    12. fp-cancel-sub-sign-invN/A

      \[\leadsto e^{\mathsf{neg}\left(\color{blue}{\left(1 + \left(\mathsf{neg}\left(x\right)\right) \cdot x\right)}\right)} \]
    13. distribute-lft-neg-inN/A

      \[\leadsto e^{\mathsf{neg}\left(\left(1 + \color{blue}{\left(\mathsf{neg}\left(x \cdot x\right)\right)}\right)\right)} \]
    14. pow2N/A

      \[\leadsto e^{\mathsf{neg}\left(\left(1 + \left(\mathsf{neg}\left(\color{blue}{{x}^{2}}\right)\right)\right)\right)} \]
    15. distribute-neg-inN/A

      \[\leadsto e^{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left({x}^{2}\right)\right)\right)\right)}} \]
    16. metadata-evalN/A

      \[\leadsto e^{\color{blue}{-1} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left({x}^{2}\right)\right)\right)\right)} \]
    17. mul-1-negN/A

      \[\leadsto e^{-1 + \left(\mathsf{neg}\left(\color{blue}{-1 \cdot {x}^{2}}\right)\right)} \]
    18. distribute-lft-neg-outN/A

      \[\leadsto e^{-1 + \color{blue}{\left(\mathsf{neg}\left(-1\right)\right) \cdot {x}^{2}}} \]
    19. metadata-evalN/A

      \[\leadsto e^{-1 + \color{blue}{1} \cdot {x}^{2}} \]
    20. *-lft-identityN/A

      \[\leadsto e^{-1 + \color{blue}{{x}^{2}}} \]
    21. +-commutativeN/A

      \[\leadsto e^{\color{blue}{{x}^{2} + -1}} \]
    22. pow2N/A

      \[\leadsto e^{\color{blue}{x \cdot x} + -1} \]
  5. Applied rewrites100.0%

    \[\leadsto \color{blue}{\frac{{\left(e^{x}\right)}^{x}}{e}} \]
  6. Add Preprocessing

Alternative 3: 100.0% accurate, 0.9× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \frac{e^{x\_m \cdot x\_m}}{e} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m) :precision binary64 (/ (exp (* x_m x_m)) E))
x_m = fabs(x);
double code(double x_m) {
	return exp((x_m * x_m)) / ((double) M_E);
}
x_m = Math.abs(x);
public static double code(double x_m) {
	return Math.exp((x_m * x_m)) / Math.E;
}
x_m = math.fabs(x)
def code(x_m):
	return math.exp((x_m * x_m)) / math.e
x_m = abs(x)
function code(x_m)
	return Float64(exp(Float64(x_m * x_m)) / exp(1))
end
x_m = abs(x);
function tmp = code(x_m)
	tmp = exp((x_m * x_m)) / 2.71828182845904523536;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := N[(N[Exp[N[(x$95$m * x$95$m), $MachinePrecision]], $MachinePrecision] / E), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|

\\
\frac{e^{x\_m \cdot x\_m}}{e}
\end{array}
Derivation
  1. Initial program 100.0%

    \[e^{-\left(1 - x \cdot x\right)} \]
  2. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \color{blue}{e^{-\left(1 - x \cdot x\right)}} \]
    2. lift-neg.f64N/A

      \[\leadsto e^{\color{blue}{\mathsf{neg}\left(\left(1 - x \cdot x\right)\right)}} \]
    3. lift--.f64N/A

      \[\leadsto e^{\mathsf{neg}\left(\color{blue}{\left(1 - x \cdot x\right)}\right)} \]
    4. lift-*.f64N/A

      \[\leadsto e^{\mathsf{neg}\left(\left(1 - \color{blue}{x \cdot x}\right)\right)} \]
    5. exp-negN/A

      \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
    6. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
    7. pow2N/A

      \[\leadsto \frac{1}{e^{1 - \color{blue}{{x}^{2}}}} \]
    8. exp-diffN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
    9. lower-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
    10. exp-1-eN/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{E}\left(\right)}}{e^{{x}^{2}}}} \]
    11. lower-E.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{e}}{e^{{x}^{2}}}} \]
    12. pow2N/A

      \[\leadsto \frac{1}{\frac{e}{e^{\color{blue}{x \cdot x}}}} \]
    13. exp-prodN/A

      \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    14. lower-pow.f64N/A

      \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    15. lower-exp.f64100.0

      \[\leadsto \frac{1}{\frac{e}{{\color{blue}{\left(e^{x}\right)}}^{x}}} \]
  3. Applied rewrites100.0%

    \[\leadsto \color{blue}{\frac{1}{\frac{e}{{\left(e^{x}\right)}^{x}}}} \]
  4. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{e}{{\left(e^{x}\right)}^{x}}}} \]
    2. lift-E.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{E}\left(\right)}}{{\left(e^{x}\right)}^{x}}} \]
    3. lift-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{E}\left(\right)}{{\left(e^{x}\right)}^{x}}}} \]
    4. lift-exp.f64N/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{{\color{blue}{\left(e^{x}\right)}}^{x}}} \]
    5. lift-pow.f64N/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    6. pow-expN/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{\color{blue}{e^{x \cdot x}}}} \]
    7. pow2N/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{e^{\color{blue}{{x}^{2}}}}} \]
    8. e-exp-1N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{e^{1}}}{e^{{x}^{2}}}} \]
    9. div-expN/A

      \[\leadsto \frac{1}{\color{blue}{e^{1 - {x}^{2}}}} \]
    10. pow2N/A

      \[\leadsto \frac{1}{e^{1 - \color{blue}{x \cdot x}}} \]
    11. exp-negN/A

      \[\leadsto \color{blue}{e^{\mathsf{neg}\left(\left(1 - x \cdot x\right)\right)}} \]
    12. fp-cancel-sub-sign-invN/A

      \[\leadsto e^{\mathsf{neg}\left(\color{blue}{\left(1 + \left(\mathsf{neg}\left(x\right)\right) \cdot x\right)}\right)} \]
    13. distribute-lft-neg-inN/A

      \[\leadsto e^{\mathsf{neg}\left(\left(1 + \color{blue}{\left(\mathsf{neg}\left(x \cdot x\right)\right)}\right)\right)} \]
    14. pow2N/A

      \[\leadsto e^{\mathsf{neg}\left(\left(1 + \left(\mathsf{neg}\left(\color{blue}{{x}^{2}}\right)\right)\right)\right)} \]
    15. distribute-neg-inN/A

      \[\leadsto e^{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left({x}^{2}\right)\right)\right)\right)}} \]
    16. metadata-evalN/A

      \[\leadsto e^{\color{blue}{-1} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left({x}^{2}\right)\right)\right)\right)} \]
    17. mul-1-negN/A

      \[\leadsto e^{-1 + \left(\mathsf{neg}\left(\color{blue}{-1 \cdot {x}^{2}}\right)\right)} \]
    18. distribute-lft-neg-outN/A

      \[\leadsto e^{-1 + \color{blue}{\left(\mathsf{neg}\left(-1\right)\right) \cdot {x}^{2}}} \]
    19. metadata-evalN/A

      \[\leadsto e^{-1 + \color{blue}{1} \cdot {x}^{2}} \]
    20. *-lft-identityN/A

      \[\leadsto e^{-1 + \color{blue}{{x}^{2}}} \]
    21. +-commutativeN/A

      \[\leadsto e^{\color{blue}{{x}^{2} + -1}} \]
    22. pow2N/A

      \[\leadsto e^{\color{blue}{x \cdot x} + -1} \]
  5. Applied rewrites100.0%

    \[\leadsto \color{blue}{\frac{{\left(e^{x}\right)}^{x}}{e}} \]
  6. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \frac{{\color{blue}{\left(e^{x}\right)}}^{x}}{e} \]
    2. lift-pow.f64N/A

      \[\leadsto \frac{\color{blue}{{\left(e^{x}\right)}^{x}}}{e} \]
    3. pow-expN/A

      \[\leadsto \frac{\color{blue}{e^{x \cdot x}}}{e} \]
    4. pow2N/A

      \[\leadsto \frac{e^{\color{blue}{{x}^{2}}}}{e} \]
    5. lower-exp.f64N/A

      \[\leadsto \frac{\color{blue}{e^{{x}^{2}}}}{e} \]
    6. pow2N/A

      \[\leadsto \frac{e^{\color{blue}{x \cdot x}}}{e} \]
    7. lift-*.f64100.0

      \[\leadsto \frac{e^{\color{blue}{x \cdot x}}}{e} \]
  7. Applied rewrites100.0%

    \[\leadsto \frac{\color{blue}{e^{x \cdot x}}}{e} \]
  8. Add Preprocessing

Alternative 4: 99.6% accurate, 1.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x\_m \leq 2.1:\\ \;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x\_m \cdot x\_m, 0.5\right), x\_m \cdot x\_m, 1\right), x\_m \cdot x\_m, 1\right)}{e}\\ \mathbf{else}:\\ \;\;\;\;e^{x\_m \cdot x\_m}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (if (<= x_m 2.1)
   (/
    (fma
     (fma (fma 0.16666666666666666 (* x_m x_m) 0.5) (* x_m x_m) 1.0)
     (* x_m x_m)
     1.0)
    E)
   (exp (* x_m x_m))))
x_m = fabs(x);
double code(double x_m) {
	double tmp;
	if (x_m <= 2.1) {
		tmp = fma(fma(fma(0.16666666666666666, (x_m * x_m), 0.5), (x_m * x_m), 1.0), (x_m * x_m), 1.0) / ((double) M_E);
	} else {
		tmp = exp((x_m * x_m));
	}
	return tmp;
}
x_m = abs(x)
function code(x_m)
	tmp = 0.0
	if (x_m <= 2.1)
		tmp = Float64(fma(fma(fma(0.16666666666666666, Float64(x_m * x_m), 0.5), Float64(x_m * x_m), 1.0), Float64(x_m * x_m), 1.0) / exp(1));
	else
		tmp = exp(Float64(x_m * x_m));
	end
	return tmp
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := If[LessEqual[x$95$m, 2.1], N[(N[(N[(N[(0.16666666666666666 * N[(x$95$m * x$95$m), $MachinePrecision] + 0.5), $MachinePrecision] * N[(x$95$m * x$95$m), $MachinePrecision] + 1.0), $MachinePrecision] * N[(x$95$m * x$95$m), $MachinePrecision] + 1.0), $MachinePrecision] / E), $MachinePrecision], N[Exp[N[(x$95$m * x$95$m), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 2.1:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x\_m \cdot x\_m, 0.5\right), x\_m \cdot x\_m, 1\right), x\_m \cdot x\_m, 1\right)}{e}\\

\mathbf{else}:\\
\;\;\;\;e^{x\_m \cdot x\_m}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 2.10000000000000009

    1. Initial program 100.0%

      \[e^{-\left(1 - x \cdot x\right)} \]
    2. Step-by-step derivation
      1. lift-exp.f64N/A

        \[\leadsto \color{blue}{e^{-\left(1 - x \cdot x\right)}} \]
      2. lift-neg.f64N/A

        \[\leadsto e^{\color{blue}{\mathsf{neg}\left(\left(1 - x \cdot x\right)\right)}} \]
      3. lift--.f64N/A

        \[\leadsto e^{\mathsf{neg}\left(\color{blue}{\left(1 - x \cdot x\right)}\right)} \]
      4. lift-*.f64N/A

        \[\leadsto e^{\mathsf{neg}\left(\left(1 - \color{blue}{x \cdot x}\right)\right)} \]
      5. exp-negN/A

        \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
      6. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
      7. pow2N/A

        \[\leadsto \frac{1}{e^{1 - \color{blue}{{x}^{2}}}} \]
      8. exp-diffN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
      9. lower-/.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
      10. exp-1-eN/A

        \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{E}\left(\right)}}{e^{{x}^{2}}}} \]
      11. lower-E.f64N/A

        \[\leadsto \frac{1}{\frac{\color{blue}{e}}{e^{{x}^{2}}}} \]
      12. pow2N/A

        \[\leadsto \frac{1}{\frac{e}{e^{\color{blue}{x \cdot x}}}} \]
      13. exp-prodN/A

        \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
      14. lower-pow.f64N/A

        \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
      15. lower-exp.f64100.0

        \[\leadsto \frac{1}{\frac{e}{{\color{blue}{\left(e^{x}\right)}}^{x}}} \]
    3. Applied rewrites100.0%

      \[\leadsto \color{blue}{\frac{1}{\frac{e}{{\left(e^{x}\right)}^{x}}}} \]
    4. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{\frac{e}{{\left(e^{x}\right)}^{x}}}} \]
      2. lift-E.f64N/A

        \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{E}\left(\right)}}{{\left(e^{x}\right)}^{x}}} \]
      3. lift-/.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{E}\left(\right)}{{\left(e^{x}\right)}^{x}}}} \]
      4. lift-exp.f64N/A

        \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{{\color{blue}{\left(e^{x}\right)}}^{x}}} \]
      5. lift-pow.f64N/A

        \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
      6. pow-expN/A

        \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{\color{blue}{e^{x \cdot x}}}} \]
      7. pow2N/A

        \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{e^{\color{blue}{{x}^{2}}}}} \]
      8. e-exp-1N/A

        \[\leadsto \frac{1}{\frac{\color{blue}{e^{1}}}{e^{{x}^{2}}}} \]
      9. div-expN/A

        \[\leadsto \frac{1}{\color{blue}{e^{1 - {x}^{2}}}} \]
      10. pow2N/A

        \[\leadsto \frac{1}{e^{1 - \color{blue}{x \cdot x}}} \]
      11. exp-negN/A

        \[\leadsto \color{blue}{e^{\mathsf{neg}\left(\left(1 - x \cdot x\right)\right)}} \]
      12. fp-cancel-sub-sign-invN/A

        \[\leadsto e^{\mathsf{neg}\left(\color{blue}{\left(1 + \left(\mathsf{neg}\left(x\right)\right) \cdot x\right)}\right)} \]
      13. distribute-lft-neg-inN/A

        \[\leadsto e^{\mathsf{neg}\left(\left(1 + \color{blue}{\left(\mathsf{neg}\left(x \cdot x\right)\right)}\right)\right)} \]
      14. pow2N/A

        \[\leadsto e^{\mathsf{neg}\left(\left(1 + \left(\mathsf{neg}\left(\color{blue}{{x}^{2}}\right)\right)\right)\right)} \]
      15. distribute-neg-inN/A

        \[\leadsto e^{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left({x}^{2}\right)\right)\right)\right)}} \]
      16. metadata-evalN/A

        \[\leadsto e^{\color{blue}{-1} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left({x}^{2}\right)\right)\right)\right)} \]
      17. mul-1-negN/A

        \[\leadsto e^{-1 + \left(\mathsf{neg}\left(\color{blue}{-1 \cdot {x}^{2}}\right)\right)} \]
      18. distribute-lft-neg-outN/A

        \[\leadsto e^{-1 + \color{blue}{\left(\mathsf{neg}\left(-1\right)\right) \cdot {x}^{2}}} \]
      19. metadata-evalN/A

        \[\leadsto e^{-1 + \color{blue}{1} \cdot {x}^{2}} \]
      20. *-lft-identityN/A

        \[\leadsto e^{-1 + \color{blue}{{x}^{2}}} \]
      21. +-commutativeN/A

        \[\leadsto e^{\color{blue}{{x}^{2} + -1}} \]
      22. pow2N/A

        \[\leadsto e^{\color{blue}{x \cdot x} + -1} \]
    5. Applied rewrites100.0%

      \[\leadsto \color{blue}{\frac{{\left(e^{x}\right)}^{x}}{e}} \]
    6. Taylor expanded in x around 0

      \[\leadsto \frac{\color{blue}{1 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right)\right)}}{e} \]
    7. Step-by-step derivation
      1. pow-expN/A

        \[\leadsto \frac{\color{blue}{1} + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right)\right)}{e} \]
      2. sqr-neg-revN/A

        \[\leadsto \frac{1 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right)\right)}{e} \]
      3. pow-expN/A

        \[\leadsto \frac{\color{blue}{1} + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right)\right)}{e} \]
      4. +-commutativeN/A

        \[\leadsto \frac{{x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right)\right) + \color{blue}{1}}{e} \]
      5. *-commutativeN/A

        \[\leadsto \frac{\left(1 + {x}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right)\right) \cdot {x}^{2} + 1}{e} \]
      6. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(1 + {x}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right), \color{blue}{{x}^{2}}, 1\right)}{e} \]
      7. +-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right) + 1, {\color{blue}{x}}^{2}, 1\right)}{e} \]
      8. *-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(\left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right) \cdot {x}^{2} + 1, {x}^{2}, 1\right)}{e} \]
      9. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}, {x}^{2}, 1\right), {\color{blue}{x}}^{2}, 1\right)}{e} \]
      10. +-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6} \cdot {x}^{2} + \frac{1}{2}, {x}^{2}, 1\right), {x}^{2}, 1\right)}{e} \]
      11. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, {x}^{2}, \frac{1}{2}\right), {x}^{2}, 1\right), {x}^{2}, 1\right)}{e} \]
      12. pow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, x \cdot x, \frac{1}{2}\right), {x}^{2}, 1\right), {x}^{2}, 1\right)}{e} \]
      13. lift-*.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, x \cdot x, \frac{1}{2}\right), {x}^{2}, 1\right), {x}^{2}, 1\right)}{e} \]
      14. pow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, x \cdot x, \frac{1}{2}\right), x \cdot x, 1\right), {x}^{2}, 1\right)}{e} \]
      15. lift-*.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, x \cdot x, \frac{1}{2}\right), x \cdot x, 1\right), {x}^{2}, 1\right)}{e} \]
      16. pow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, x \cdot x, \frac{1}{2}\right), x \cdot x, 1\right), x \cdot \color{blue}{x}, 1\right)}{e} \]
      17. lift-*.f6499.7

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x \cdot x, 0.5\right), x \cdot x, 1\right), x \cdot \color{blue}{x}, 1\right)}{e} \]
    8. Applied rewrites99.7%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x \cdot x, 0.5\right), x \cdot x, 1\right), x \cdot x, 1\right)}}{e} \]

    if 2.10000000000000009 < x

    1. Initial program 100.0%

      \[e^{-\left(1 - x \cdot x\right)} \]
    2. Taylor expanded in x around inf

      \[\leadsto e^{\color{blue}{{x}^{2}}} \]
    3. Step-by-step derivation
      1. pow2N/A

        \[\leadsto e^{x \cdot \color{blue}{x}} \]
      2. lift-*.f6499.5

        \[\leadsto e^{x \cdot \color{blue}{x}} \]
    4. Applied rewrites99.5%

      \[\leadsto e^{\color{blue}{x \cdot x}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ e^{\mathsf{fma}\left(x\_m, x\_m, -1\right)} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m) :precision binary64 (exp (fma x_m x_m -1.0)))
x_m = fabs(x);
double code(double x_m) {
	return exp(fma(x_m, x_m, -1.0));
}
x_m = abs(x)
function code(x_m)
	return exp(fma(x_m, x_m, -1.0))
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := N[Exp[N[(x$95$m * x$95$m + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|

\\
e^{\mathsf{fma}\left(x\_m, x\_m, -1\right)}
\end{array}
Derivation
  1. Initial program 100.0%

    \[e^{-\left(1 - x \cdot x\right)} \]
  2. Taylor expanded in x around 0

    \[\leadsto e^{\color{blue}{{x}^{2} - 1}} \]
  3. Step-by-step derivation
    1. metadata-evalN/A

      \[\leadsto e^{{x}^{2} - 1 \cdot \color{blue}{1}} \]
    2. fp-cancel-sub-sign-invN/A

      \[\leadsto e^{{x}^{2} + \color{blue}{\left(\mathsf{neg}\left(1\right)\right) \cdot 1}} \]
    3. pow2N/A

      \[\leadsto e^{x \cdot x + \color{blue}{\left(\mathsf{neg}\left(1\right)\right)} \cdot 1} \]
    4. metadata-evalN/A

      \[\leadsto e^{x \cdot x + -1 \cdot 1} \]
    5. metadata-evalN/A

      \[\leadsto e^{x \cdot x + -1} \]
    6. lower-fma.f64100.0

      \[\leadsto e^{\mathsf{fma}\left(x, \color{blue}{x}, -1\right)} \]
  4. Applied rewrites100.0%

    \[\leadsto e^{\color{blue}{\mathsf{fma}\left(x, x, -1\right)}} \]
  5. Add Preprocessing

Alternative 6: 92.0% accurate, 2.5× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x\_m \cdot x\_m, 0.5\right), x\_m \cdot x\_m, 1\right), x\_m \cdot x\_m, 1\right)}{e} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (/
  (fma
   (fma (fma 0.16666666666666666 (* x_m x_m) 0.5) (* x_m x_m) 1.0)
   (* x_m x_m)
   1.0)
  E))
x_m = fabs(x);
double code(double x_m) {
	return fma(fma(fma(0.16666666666666666, (x_m * x_m), 0.5), (x_m * x_m), 1.0), (x_m * x_m), 1.0) / ((double) M_E);
}
x_m = abs(x)
function code(x_m)
	return Float64(fma(fma(fma(0.16666666666666666, Float64(x_m * x_m), 0.5), Float64(x_m * x_m), 1.0), Float64(x_m * x_m), 1.0) / exp(1))
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := N[(N[(N[(N[(0.16666666666666666 * N[(x$95$m * x$95$m), $MachinePrecision] + 0.5), $MachinePrecision] * N[(x$95$m * x$95$m), $MachinePrecision] + 1.0), $MachinePrecision] * N[(x$95$m * x$95$m), $MachinePrecision] + 1.0), $MachinePrecision] / E), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|

\\
\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x\_m \cdot x\_m, 0.5\right), x\_m \cdot x\_m, 1\right), x\_m \cdot x\_m, 1\right)}{e}
\end{array}
Derivation
  1. Initial program 100.0%

    \[e^{-\left(1 - x \cdot x\right)} \]
  2. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \color{blue}{e^{-\left(1 - x \cdot x\right)}} \]
    2. lift-neg.f64N/A

      \[\leadsto e^{\color{blue}{\mathsf{neg}\left(\left(1 - x \cdot x\right)\right)}} \]
    3. lift--.f64N/A

      \[\leadsto e^{\mathsf{neg}\left(\color{blue}{\left(1 - x \cdot x\right)}\right)} \]
    4. lift-*.f64N/A

      \[\leadsto e^{\mathsf{neg}\left(\left(1 - \color{blue}{x \cdot x}\right)\right)} \]
    5. exp-negN/A

      \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
    6. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
    7. pow2N/A

      \[\leadsto \frac{1}{e^{1 - \color{blue}{{x}^{2}}}} \]
    8. exp-diffN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
    9. lower-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
    10. exp-1-eN/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{E}\left(\right)}}{e^{{x}^{2}}}} \]
    11. lower-E.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{e}}{e^{{x}^{2}}}} \]
    12. pow2N/A

      \[\leadsto \frac{1}{\frac{e}{e^{\color{blue}{x \cdot x}}}} \]
    13. exp-prodN/A

      \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    14. lower-pow.f64N/A

      \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    15. lower-exp.f64100.0

      \[\leadsto \frac{1}{\frac{e}{{\color{blue}{\left(e^{x}\right)}}^{x}}} \]
  3. Applied rewrites100.0%

    \[\leadsto \color{blue}{\frac{1}{\frac{e}{{\left(e^{x}\right)}^{x}}}} \]
  4. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{e}{{\left(e^{x}\right)}^{x}}}} \]
    2. lift-E.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{E}\left(\right)}}{{\left(e^{x}\right)}^{x}}} \]
    3. lift-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{E}\left(\right)}{{\left(e^{x}\right)}^{x}}}} \]
    4. lift-exp.f64N/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{{\color{blue}{\left(e^{x}\right)}}^{x}}} \]
    5. lift-pow.f64N/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    6. pow-expN/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{\color{blue}{e^{x \cdot x}}}} \]
    7. pow2N/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{e^{\color{blue}{{x}^{2}}}}} \]
    8. e-exp-1N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{e^{1}}}{e^{{x}^{2}}}} \]
    9. div-expN/A

      \[\leadsto \frac{1}{\color{blue}{e^{1 - {x}^{2}}}} \]
    10. pow2N/A

      \[\leadsto \frac{1}{e^{1 - \color{blue}{x \cdot x}}} \]
    11. exp-negN/A

      \[\leadsto \color{blue}{e^{\mathsf{neg}\left(\left(1 - x \cdot x\right)\right)}} \]
    12. fp-cancel-sub-sign-invN/A

      \[\leadsto e^{\mathsf{neg}\left(\color{blue}{\left(1 + \left(\mathsf{neg}\left(x\right)\right) \cdot x\right)}\right)} \]
    13. distribute-lft-neg-inN/A

      \[\leadsto e^{\mathsf{neg}\left(\left(1 + \color{blue}{\left(\mathsf{neg}\left(x \cdot x\right)\right)}\right)\right)} \]
    14. pow2N/A

      \[\leadsto e^{\mathsf{neg}\left(\left(1 + \left(\mathsf{neg}\left(\color{blue}{{x}^{2}}\right)\right)\right)\right)} \]
    15. distribute-neg-inN/A

      \[\leadsto e^{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left({x}^{2}\right)\right)\right)\right)}} \]
    16. metadata-evalN/A

      \[\leadsto e^{\color{blue}{-1} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left({x}^{2}\right)\right)\right)\right)} \]
    17. mul-1-negN/A

      \[\leadsto e^{-1 + \left(\mathsf{neg}\left(\color{blue}{-1 \cdot {x}^{2}}\right)\right)} \]
    18. distribute-lft-neg-outN/A

      \[\leadsto e^{-1 + \color{blue}{\left(\mathsf{neg}\left(-1\right)\right) \cdot {x}^{2}}} \]
    19. metadata-evalN/A

      \[\leadsto e^{-1 + \color{blue}{1} \cdot {x}^{2}} \]
    20. *-lft-identityN/A

      \[\leadsto e^{-1 + \color{blue}{{x}^{2}}} \]
    21. +-commutativeN/A

      \[\leadsto e^{\color{blue}{{x}^{2} + -1}} \]
    22. pow2N/A

      \[\leadsto e^{\color{blue}{x \cdot x} + -1} \]
  5. Applied rewrites100.0%

    \[\leadsto \color{blue}{\frac{{\left(e^{x}\right)}^{x}}{e}} \]
  6. Taylor expanded in x around 0

    \[\leadsto \frac{\color{blue}{1 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right)\right)}}{e} \]
  7. Step-by-step derivation
    1. pow-expN/A

      \[\leadsto \frac{\color{blue}{1} + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right)\right)}{e} \]
    2. sqr-neg-revN/A

      \[\leadsto \frac{1 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right)\right)}{e} \]
    3. pow-expN/A

      \[\leadsto \frac{\color{blue}{1} + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right)\right)}{e} \]
    4. +-commutativeN/A

      \[\leadsto \frac{{x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right)\right) + \color{blue}{1}}{e} \]
    5. *-commutativeN/A

      \[\leadsto \frac{\left(1 + {x}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right)\right) \cdot {x}^{2} + 1}{e} \]
    6. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(1 + {x}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right), \color{blue}{{x}^{2}}, 1\right)}{e} \]
    7. +-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left({x}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right) + 1, {\color{blue}{x}}^{2}, 1\right)}{e} \]
    8. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right) \cdot {x}^{2} + 1, {x}^{2}, 1\right)}{e} \]
    9. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2} + \frac{1}{6} \cdot {x}^{2}, {x}^{2}, 1\right), {\color{blue}{x}}^{2}, 1\right)}{e} \]
    10. +-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6} \cdot {x}^{2} + \frac{1}{2}, {x}^{2}, 1\right), {x}^{2}, 1\right)}{e} \]
    11. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, {x}^{2}, \frac{1}{2}\right), {x}^{2}, 1\right), {x}^{2}, 1\right)}{e} \]
    12. pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, x \cdot x, \frac{1}{2}\right), {x}^{2}, 1\right), {x}^{2}, 1\right)}{e} \]
    13. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, x \cdot x, \frac{1}{2}\right), {x}^{2}, 1\right), {x}^{2}, 1\right)}{e} \]
    14. pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, x \cdot x, \frac{1}{2}\right), x \cdot x, 1\right), {x}^{2}, 1\right)}{e} \]
    15. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, x \cdot x, \frac{1}{2}\right), x \cdot x, 1\right), {x}^{2}, 1\right)}{e} \]
    16. pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, x \cdot x, \frac{1}{2}\right), x \cdot x, 1\right), x \cdot \color{blue}{x}, 1\right)}{e} \]
    17. lift-*.f6492.0

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x \cdot x, 0.5\right), x \cdot x, 1\right), x \cdot \color{blue}{x}, 1\right)}{e} \]
  8. Applied rewrites92.0%

    \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x \cdot x, 0.5\right), x \cdot x, 1\right), x \cdot x, 1\right)}}{e} \]
  9. Add Preprocessing

Alternative 7: 88.0% accurate, 3.3× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \frac{\mathsf{fma}\left(\mathsf{fma}\left(x\_m \cdot x\_m, 0.5, 1\right), x\_m \cdot x\_m, 1\right)}{e} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (/ (fma (fma (* x_m x_m) 0.5 1.0) (* x_m x_m) 1.0) E))
x_m = fabs(x);
double code(double x_m) {
	return fma(fma((x_m * x_m), 0.5, 1.0), (x_m * x_m), 1.0) / ((double) M_E);
}
x_m = abs(x)
function code(x_m)
	return Float64(fma(fma(Float64(x_m * x_m), 0.5, 1.0), Float64(x_m * x_m), 1.0) / exp(1))
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := N[(N[(N[(N[(x$95$m * x$95$m), $MachinePrecision] * 0.5 + 1.0), $MachinePrecision] * N[(x$95$m * x$95$m), $MachinePrecision] + 1.0), $MachinePrecision] / E), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|

\\
\frac{\mathsf{fma}\left(\mathsf{fma}\left(x\_m \cdot x\_m, 0.5, 1\right), x\_m \cdot x\_m, 1\right)}{e}
\end{array}
Derivation
  1. Initial program 100.0%

    \[e^{-\left(1 - x \cdot x\right)} \]
  2. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \color{blue}{e^{-\left(1 - x \cdot x\right)}} \]
    2. lift-neg.f64N/A

      \[\leadsto e^{\color{blue}{\mathsf{neg}\left(\left(1 - x \cdot x\right)\right)}} \]
    3. lift--.f64N/A

      \[\leadsto e^{\mathsf{neg}\left(\color{blue}{\left(1 - x \cdot x\right)}\right)} \]
    4. lift-*.f64N/A

      \[\leadsto e^{\mathsf{neg}\left(\left(1 - \color{blue}{x \cdot x}\right)\right)} \]
    5. exp-negN/A

      \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
    6. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
    7. pow2N/A

      \[\leadsto \frac{1}{e^{1 - \color{blue}{{x}^{2}}}} \]
    8. exp-diffN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
    9. lower-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
    10. exp-1-eN/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{E}\left(\right)}}{e^{{x}^{2}}}} \]
    11. lower-E.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{e}}{e^{{x}^{2}}}} \]
    12. pow2N/A

      \[\leadsto \frac{1}{\frac{e}{e^{\color{blue}{x \cdot x}}}} \]
    13. exp-prodN/A

      \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    14. lower-pow.f64N/A

      \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    15. lower-exp.f64100.0

      \[\leadsto \frac{1}{\frac{e}{{\color{blue}{\left(e^{x}\right)}}^{x}}} \]
  3. Applied rewrites100.0%

    \[\leadsto \color{blue}{\frac{1}{\frac{e}{{\left(e^{x}\right)}^{x}}}} \]
  4. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{e}{{\left(e^{x}\right)}^{x}}}} \]
    2. lift-E.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{E}\left(\right)}}{{\left(e^{x}\right)}^{x}}} \]
    3. lift-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{E}\left(\right)}{{\left(e^{x}\right)}^{x}}}} \]
    4. lift-exp.f64N/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{{\color{blue}{\left(e^{x}\right)}}^{x}}} \]
    5. lift-pow.f64N/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    6. pow-expN/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{\color{blue}{e^{x \cdot x}}}} \]
    7. pow2N/A

      \[\leadsto \frac{1}{\frac{\mathsf{E}\left(\right)}{e^{\color{blue}{{x}^{2}}}}} \]
    8. e-exp-1N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{e^{1}}}{e^{{x}^{2}}}} \]
    9. div-expN/A

      \[\leadsto \frac{1}{\color{blue}{e^{1 - {x}^{2}}}} \]
    10. pow2N/A

      \[\leadsto \frac{1}{e^{1 - \color{blue}{x \cdot x}}} \]
    11. exp-negN/A

      \[\leadsto \color{blue}{e^{\mathsf{neg}\left(\left(1 - x \cdot x\right)\right)}} \]
    12. fp-cancel-sub-sign-invN/A

      \[\leadsto e^{\mathsf{neg}\left(\color{blue}{\left(1 + \left(\mathsf{neg}\left(x\right)\right) \cdot x\right)}\right)} \]
    13. distribute-lft-neg-inN/A

      \[\leadsto e^{\mathsf{neg}\left(\left(1 + \color{blue}{\left(\mathsf{neg}\left(x \cdot x\right)\right)}\right)\right)} \]
    14. pow2N/A

      \[\leadsto e^{\mathsf{neg}\left(\left(1 + \left(\mathsf{neg}\left(\color{blue}{{x}^{2}}\right)\right)\right)\right)} \]
    15. distribute-neg-inN/A

      \[\leadsto e^{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left({x}^{2}\right)\right)\right)\right)}} \]
    16. metadata-evalN/A

      \[\leadsto e^{\color{blue}{-1} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left({x}^{2}\right)\right)\right)\right)} \]
    17. mul-1-negN/A

      \[\leadsto e^{-1 + \left(\mathsf{neg}\left(\color{blue}{-1 \cdot {x}^{2}}\right)\right)} \]
    18. distribute-lft-neg-outN/A

      \[\leadsto e^{-1 + \color{blue}{\left(\mathsf{neg}\left(-1\right)\right) \cdot {x}^{2}}} \]
    19. metadata-evalN/A

      \[\leadsto e^{-1 + \color{blue}{1} \cdot {x}^{2}} \]
    20. *-lft-identityN/A

      \[\leadsto e^{-1 + \color{blue}{{x}^{2}}} \]
    21. +-commutativeN/A

      \[\leadsto e^{\color{blue}{{x}^{2} + -1}} \]
    22. pow2N/A

      \[\leadsto e^{\color{blue}{x \cdot x} + -1} \]
  5. Applied rewrites100.0%

    \[\leadsto \color{blue}{\frac{{\left(e^{x}\right)}^{x}}{e}} \]
  6. Taylor expanded in x around 0

    \[\leadsto \frac{\color{blue}{1 + {x}^{2} \cdot \left(1 + \frac{1}{2} \cdot {x}^{2}\right)}}{e} \]
  7. Step-by-step derivation
    1. pow-expN/A

      \[\leadsto \frac{\color{blue}{1} + {x}^{2} \cdot \left(1 + \frac{1}{2} \cdot {x}^{2}\right)}{e} \]
    2. sqr-neg-revN/A

      \[\leadsto \frac{1 + {x}^{2} \cdot \left(1 + \frac{1}{2} \cdot {x}^{2}\right)}{e} \]
    3. pow-expN/A

      \[\leadsto \frac{\color{blue}{1} + {x}^{2} \cdot \left(1 + \frac{1}{2} \cdot {x}^{2}\right)}{e} \]
    4. +-commutativeN/A

      \[\leadsto \frac{{x}^{2} \cdot \left(1 + \frac{1}{2} \cdot {x}^{2}\right) + \color{blue}{1}}{e} \]
    5. *-commutativeN/A

      \[\leadsto \frac{\left(1 + \frac{1}{2} \cdot {x}^{2}\right) \cdot {x}^{2} + 1}{e} \]
    6. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(1 + \frac{1}{2} \cdot {x}^{2}, \color{blue}{{x}^{2}}, 1\right)}{e} \]
    7. +-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\frac{1}{2} \cdot {x}^{2} + 1, {\color{blue}{x}}^{2}, 1\right)}{e} \]
    8. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left({x}^{2} \cdot \frac{1}{2} + 1, {x}^{2}, 1\right)}{e} \]
    9. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left({x}^{2}, \frac{1}{2}, 1\right), {\color{blue}{x}}^{2}, 1\right)}{e} \]
    10. pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right), {x}^{2}, 1\right)}{e} \]
    11. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right), {x}^{2}, 1\right)}{e} \]
    12. pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right), x \cdot \color{blue}{x}, 1\right)}{e} \]
    13. lift-*.f6488.0

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.5, 1\right), x \cdot \color{blue}{x}, 1\right)}{e} \]
  8. Applied rewrites88.0%

    \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.5, 1\right), x \cdot x, 1\right)}}{e} \]
  9. Add Preprocessing

Alternative 8: 75.8% accurate, 3.6× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;1 - x\_m \cdot x\_m \leq -2:\\ \;\;\;\;\frac{x\_m \cdot x\_m}{e}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (if (<= (- 1.0 (* x_m x_m)) -2.0) (/ (* x_m x_m) E) (/ 1.0 E)))
x_m = fabs(x);
double code(double x_m) {
	double tmp;
	if ((1.0 - (x_m * x_m)) <= -2.0) {
		tmp = (x_m * x_m) / ((double) M_E);
	} else {
		tmp = 1.0 / ((double) M_E);
	}
	return tmp;
}
x_m = Math.abs(x);
public static double code(double x_m) {
	double tmp;
	if ((1.0 - (x_m * x_m)) <= -2.0) {
		tmp = (x_m * x_m) / Math.E;
	} else {
		tmp = 1.0 / Math.E;
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m):
	tmp = 0
	if (1.0 - (x_m * x_m)) <= -2.0:
		tmp = (x_m * x_m) / math.e
	else:
		tmp = 1.0 / math.e
	return tmp
x_m = abs(x)
function code(x_m)
	tmp = 0.0
	if (Float64(1.0 - Float64(x_m * x_m)) <= -2.0)
		tmp = Float64(Float64(x_m * x_m) / exp(1));
	else
		tmp = Float64(1.0 / exp(1));
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m)
	tmp = 0.0;
	if ((1.0 - (x_m * x_m)) <= -2.0)
		tmp = (x_m * x_m) / 2.71828182845904523536;
	else
		tmp = 1.0 / 2.71828182845904523536;
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := If[LessEqual[N[(1.0 - N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision], -2.0], N[(N[(x$95$m * x$95$m), $MachinePrecision] / E), $MachinePrecision], N[(1.0 / E), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;1 - x\_m \cdot x\_m \leq -2:\\
\;\;\;\;\frac{x\_m \cdot x\_m}{e}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{e}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 #s(literal 1 binary64) (*.f64 x x)) < -2

    1. Initial program 100.0%

      \[e^{-\left(1 - x \cdot x\right)} \]
    2. Step-by-step derivation
      1. lift-exp.f64N/A

        \[\leadsto \color{blue}{e^{-\left(1 - x \cdot x\right)}} \]
      2. lift-neg.f64N/A

        \[\leadsto e^{\color{blue}{\mathsf{neg}\left(\left(1 - x \cdot x\right)\right)}} \]
      3. lift--.f64N/A

        \[\leadsto e^{\mathsf{neg}\left(\color{blue}{\left(1 - x \cdot x\right)}\right)} \]
      4. lift-*.f64N/A

        \[\leadsto e^{\mathsf{neg}\left(\left(1 - \color{blue}{x \cdot x}\right)\right)} \]
      5. exp-negN/A

        \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
      6. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
      7. pow2N/A

        \[\leadsto \frac{1}{e^{1 - \color{blue}{{x}^{2}}}} \]
      8. exp-diffN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
      9. lower-/.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
      10. exp-1-eN/A

        \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{E}\left(\right)}}{e^{{x}^{2}}}} \]
      11. lower-E.f64N/A

        \[\leadsto \frac{1}{\frac{\color{blue}{e}}{e^{{x}^{2}}}} \]
      12. pow2N/A

        \[\leadsto \frac{1}{\frac{e}{e^{\color{blue}{x \cdot x}}}} \]
      13. exp-prodN/A

        \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
      14. lower-pow.f64N/A

        \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
      15. lower-exp.f64100.0

        \[\leadsto \frac{1}{\frac{e}{{\color{blue}{\left(e^{x}\right)}}^{x}}} \]
    3. Applied rewrites100.0%

      \[\leadsto \color{blue}{\frac{1}{\frac{e}{{\left(e^{x}\right)}^{x}}}} \]
    4. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{1}{\mathsf{E}\left(\right)} + \frac{{x}^{2}}{\mathsf{E}\left(\right)}} \]
    5. Step-by-step derivation
      1. div-add-revN/A

        \[\leadsto \frac{1 + {x}^{2}}{\color{blue}{\mathsf{E}\left(\right)}} \]
      2. lower-/.f64N/A

        \[\leadsto \frac{1 + {x}^{2}}{\color{blue}{\mathsf{E}\left(\right)}} \]
      3. +-commutativeN/A

        \[\leadsto \frac{{x}^{2} + 1}{\mathsf{E}\left(\right)} \]
      4. pow2N/A

        \[\leadsto \frac{x \cdot x + 1}{\mathsf{E}\left(\right)} \]
      5. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(x, x, 1\right)}{\mathsf{E}\left(\right)} \]
      6. lift-E.f6452.0

        \[\leadsto \frac{\mathsf{fma}\left(x, x, 1\right)}{e} \]
    6. Applied rewrites52.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, x, 1\right)}{e}} \]
    7. Taylor expanded in x around inf

      \[\leadsto \frac{{x}^{2}}{e} \]
    8. Step-by-step derivation
      1. pow2N/A

        \[\leadsto \frac{x \cdot x}{e} \]
      2. lift-*.f6452.0

        \[\leadsto \frac{x \cdot x}{e} \]
    9. Applied rewrites52.0%

      \[\leadsto \frac{x \cdot x}{e} \]

    if -2 < (-.f64 #s(literal 1 binary64) (*.f64 x x))

    1. Initial program 100.0%

      \[e^{-\left(1 - x \cdot x\right)} \]
    2. Step-by-step derivation
      1. lift-exp.f64N/A

        \[\leadsto \color{blue}{e^{-\left(1 - x \cdot x\right)}} \]
      2. lift-neg.f64N/A

        \[\leadsto e^{\color{blue}{\mathsf{neg}\left(\left(1 - x \cdot x\right)\right)}} \]
      3. lift--.f64N/A

        \[\leadsto e^{\mathsf{neg}\left(\color{blue}{\left(1 - x \cdot x\right)}\right)} \]
      4. lift-*.f64N/A

        \[\leadsto e^{\mathsf{neg}\left(\left(1 - \color{blue}{x \cdot x}\right)\right)} \]
      5. exp-negN/A

        \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
      6. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
      7. pow2N/A

        \[\leadsto \frac{1}{e^{1 - \color{blue}{{x}^{2}}}} \]
      8. exp-diffN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
      9. lower-/.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
      10. exp-1-eN/A

        \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{E}\left(\right)}}{e^{{x}^{2}}}} \]
      11. lower-E.f64N/A

        \[\leadsto \frac{1}{\frac{\color{blue}{e}}{e^{{x}^{2}}}} \]
      12. pow2N/A

        \[\leadsto \frac{1}{\frac{e}{e^{\color{blue}{x \cdot x}}}} \]
      13. exp-prodN/A

        \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
      14. lower-pow.f64N/A

        \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
      15. lower-exp.f64100.0

        \[\leadsto \frac{1}{\frac{e}{{\color{blue}{\left(e^{x}\right)}}^{x}}} \]
    3. Applied rewrites100.0%

      \[\leadsto \color{blue}{\frac{1}{\frac{e}{{\left(e^{x}\right)}^{x}}}} \]
    4. Taylor expanded in x around 0

      \[\leadsto \frac{1}{\color{blue}{\mathsf{E}\left(\right)}} \]
    5. Step-by-step derivation
      1. lift-E.f6498.9

        \[\leadsto \frac{1}{e} \]
    6. Applied rewrites98.9%

      \[\leadsto \frac{1}{\color{blue}{e}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 9: 76.1% accurate, 6.2× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \frac{\mathsf{fma}\left(x\_m, x\_m, 1\right)}{e} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m) :precision binary64 (/ (fma x_m x_m 1.0) E))
x_m = fabs(x);
double code(double x_m) {
	return fma(x_m, x_m, 1.0) / ((double) M_E);
}
x_m = abs(x)
function code(x_m)
	return Float64(fma(x_m, x_m, 1.0) / exp(1))
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := N[(N[(x$95$m * x$95$m + 1.0), $MachinePrecision] / E), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|

\\
\frac{\mathsf{fma}\left(x\_m, x\_m, 1\right)}{e}
\end{array}
Derivation
  1. Initial program 100.0%

    \[e^{-\left(1 - x \cdot x\right)} \]
  2. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \color{blue}{e^{-\left(1 - x \cdot x\right)}} \]
    2. lift-neg.f64N/A

      \[\leadsto e^{\color{blue}{\mathsf{neg}\left(\left(1 - x \cdot x\right)\right)}} \]
    3. lift--.f64N/A

      \[\leadsto e^{\mathsf{neg}\left(\color{blue}{\left(1 - x \cdot x\right)}\right)} \]
    4. lift-*.f64N/A

      \[\leadsto e^{\mathsf{neg}\left(\left(1 - \color{blue}{x \cdot x}\right)\right)} \]
    5. exp-negN/A

      \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
    6. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
    7. pow2N/A

      \[\leadsto \frac{1}{e^{1 - \color{blue}{{x}^{2}}}} \]
    8. exp-diffN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
    9. lower-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
    10. exp-1-eN/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{E}\left(\right)}}{e^{{x}^{2}}}} \]
    11. lower-E.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{e}}{e^{{x}^{2}}}} \]
    12. pow2N/A

      \[\leadsto \frac{1}{\frac{e}{e^{\color{blue}{x \cdot x}}}} \]
    13. exp-prodN/A

      \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    14. lower-pow.f64N/A

      \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    15. lower-exp.f64100.0

      \[\leadsto \frac{1}{\frac{e}{{\color{blue}{\left(e^{x}\right)}}^{x}}} \]
  3. Applied rewrites100.0%

    \[\leadsto \color{blue}{\frac{1}{\frac{e}{{\left(e^{x}\right)}^{x}}}} \]
  4. Taylor expanded in x around 0

    \[\leadsto \color{blue}{\frac{1}{\mathsf{E}\left(\right)} + \frac{{x}^{2}}{\mathsf{E}\left(\right)}} \]
  5. Step-by-step derivation
    1. div-add-revN/A

      \[\leadsto \frac{1 + {x}^{2}}{\color{blue}{\mathsf{E}\left(\right)}} \]
    2. lower-/.f64N/A

      \[\leadsto \frac{1 + {x}^{2}}{\color{blue}{\mathsf{E}\left(\right)}} \]
    3. +-commutativeN/A

      \[\leadsto \frac{{x}^{2} + 1}{\mathsf{E}\left(\right)} \]
    4. pow2N/A

      \[\leadsto \frac{x \cdot x + 1}{\mathsf{E}\left(\right)} \]
    5. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(x, x, 1\right)}{\mathsf{E}\left(\right)} \]
    6. lift-E.f6476.1

      \[\leadsto \frac{\mathsf{fma}\left(x, x, 1\right)}{e} \]
  6. Applied rewrites76.1%

    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, x, 1\right)}{e}} \]
  7. Add Preprocessing

Alternative 10: 51.7% accurate, 9.3× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \frac{1}{e} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m) :precision binary64 (/ 1.0 E))
x_m = fabs(x);
double code(double x_m) {
	return 1.0 / ((double) M_E);
}
x_m = Math.abs(x);
public static double code(double x_m) {
	return 1.0 / Math.E;
}
x_m = math.fabs(x)
def code(x_m):
	return 1.0 / math.e
x_m = abs(x)
function code(x_m)
	return Float64(1.0 / exp(1))
end
x_m = abs(x);
function tmp = code(x_m)
	tmp = 1.0 / 2.71828182845904523536;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := N[(1.0 / E), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|

\\
\frac{1}{e}
\end{array}
Derivation
  1. Initial program 100.0%

    \[e^{-\left(1 - x \cdot x\right)} \]
  2. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \color{blue}{e^{-\left(1 - x \cdot x\right)}} \]
    2. lift-neg.f64N/A

      \[\leadsto e^{\color{blue}{\mathsf{neg}\left(\left(1 - x \cdot x\right)\right)}} \]
    3. lift--.f64N/A

      \[\leadsto e^{\mathsf{neg}\left(\color{blue}{\left(1 - x \cdot x\right)}\right)} \]
    4. lift-*.f64N/A

      \[\leadsto e^{\mathsf{neg}\left(\left(1 - \color{blue}{x \cdot x}\right)\right)} \]
    5. exp-negN/A

      \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
    6. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{e^{1 - x \cdot x}}} \]
    7. pow2N/A

      \[\leadsto \frac{1}{e^{1 - \color{blue}{{x}^{2}}}} \]
    8. exp-diffN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
    9. lower-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{1}}{e^{{x}^{2}}}}} \]
    10. exp-1-eN/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{E}\left(\right)}}{e^{{x}^{2}}}} \]
    11. lower-E.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{e}}{e^{{x}^{2}}}} \]
    12. pow2N/A

      \[\leadsto \frac{1}{\frac{e}{e^{\color{blue}{x \cdot x}}}} \]
    13. exp-prodN/A

      \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    14. lower-pow.f64N/A

      \[\leadsto \frac{1}{\frac{e}{\color{blue}{{\left(e^{x}\right)}^{x}}}} \]
    15. lower-exp.f64100.0

      \[\leadsto \frac{1}{\frac{e}{{\color{blue}{\left(e^{x}\right)}}^{x}}} \]
  3. Applied rewrites100.0%

    \[\leadsto \color{blue}{\frac{1}{\frac{e}{{\left(e^{x}\right)}^{x}}}} \]
  4. Taylor expanded in x around 0

    \[\leadsto \frac{1}{\color{blue}{\mathsf{E}\left(\right)}} \]
  5. Step-by-step derivation
    1. lift-E.f6451.7

      \[\leadsto \frac{1}{e} \]
  6. Applied rewrites51.7%

    \[\leadsto \frac{1}{\color{blue}{e}} \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2025097 
(FPCore (x)
  :name "exp neg sub"
  :precision binary64
  (exp (- (- 1.0 (* x x)))))