exp-w (used to crash)

Percentage Accurate: 99.4% → 99.4%
Time: 12.0s
Alternatives: 8
Speedup: N/A×

Specification

?
\[\begin{array}{l} \\ e^{-w} \cdot {\ell}^{\left(e^{w}\right)} \end{array} \]
(FPCore (w l) :precision binary64 (* (exp (- w)) (pow l (exp w))))
double code(double w, double l) {
	return exp(-w) * pow(l, exp(w));
}
real(8) function code(w, l)
    real(8), intent (in) :: w
    real(8), intent (in) :: l
    code = exp(-w) * (l ** exp(w))
end function
public static double code(double w, double l) {
	return Math.exp(-w) * Math.pow(l, Math.exp(w));
}
def code(w, l):
	return math.exp(-w) * math.pow(l, math.exp(w))
function code(w, l)
	return Float64(exp(Float64(-w)) * (l ^ exp(w)))
end
function tmp = code(w, l)
	tmp = exp(-w) * (l ^ exp(w));
end
code[w_, l_] := N[(N[Exp[(-w)], $MachinePrecision] * N[Power[l, N[Exp[w], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
e^{-w} \cdot {\ell}^{\left(e^{w}\right)}
\end{array}

Sampling outcomes in binary64 precision:

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 8 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: 99.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ e^{-w} \cdot {\ell}^{\left(e^{w}\right)} \end{array} \]
(FPCore (w l) :precision binary64 (* (exp (- w)) (pow l (exp w))))
double code(double w, double l) {
	return exp(-w) * pow(l, exp(w));
}
real(8) function code(w, l)
    real(8), intent (in) :: w
    real(8), intent (in) :: l
    code = exp(-w) * (l ** exp(w))
end function
public static double code(double w, double l) {
	return Math.exp(-w) * Math.pow(l, Math.exp(w));
}
def code(w, l):
	return math.exp(-w) * math.pow(l, math.exp(w))
function code(w, l)
	return Float64(exp(Float64(-w)) * (l ^ exp(w)))
end
function tmp = code(w, l)
	tmp = exp(-w) * (l ^ exp(w));
end
code[w_, l_] := N[(N[Exp[(-w)], $MachinePrecision] * N[Power[l, N[Exp[w], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
e^{-w} \cdot {\ell}^{\left(e^{w}\right)}
\end{array}

Alternative 1: 99.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ {\ell}^{\left(e^{w}\right)} \cdot \frac{--1}{e^{w}} \end{array} \]
(FPCore (w l) :precision binary64 (* (pow l (exp w)) (/ (- -1.0) (exp w))))
double code(double w, double l) {
	return pow(l, exp(w)) * (-(-1.0) / exp(w));
}
real(8) function code(w, l)
    real(8), intent (in) :: w
    real(8), intent (in) :: l
    code = (l ** exp(w)) * (-(-1.0d0) / exp(w))
end function
public static double code(double w, double l) {
	return Math.pow(l, Math.exp(w)) * (-(-1.0) / Math.exp(w));
}
def code(w, l):
	return math.pow(l, math.exp(w)) * (-(-1.0) / math.exp(w))
function code(w, l)
	return Float64((l ^ exp(w)) * Float64(Float64(-(-1.0)) / exp(w)))
end
function tmp = code(w, l)
	tmp = (l ^ exp(w)) * (-(-1.0) / exp(w));
end
code[w_, l_] := N[(N[Power[l, N[Exp[w], $MachinePrecision]], $MachinePrecision] * N[((--1.0) / N[Exp[w], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
{\ell}^{\left(e^{w}\right)} \cdot \frac{--1}{e^{w}}
\end{array}
Derivation
  1. Initial program 99.0%

    \[e^{-w} \cdot {\ell}^{\left(e^{w}\right)} \]
  2. Step-by-step derivation
    1. exp-neg99.0%

      \[\leadsto \color{blue}{\frac{1}{e^{w}}} \cdot {\ell}^{\left(e^{w}\right)} \]
    2. associate-*l/99.0%

      \[\leadsto \color{blue}{\frac{1 \cdot {\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
    3. *-lft-identity99.0%

      \[\leadsto \frac{\color{blue}{{\ell}^{\left(e^{w}\right)}}}{e^{w}} \]
  3. Simplified99.0%

    \[\leadsto \color{blue}{\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
  4. Step-by-step derivation
    1. frac-2neg99.0%

      \[\leadsto \color{blue}{\frac{-{\ell}^{\left(e^{w}\right)}}{-e^{w}}} \]
    2. div-inv99.0%

      \[\leadsto \color{blue}{\left(-{\ell}^{\left(e^{w}\right)}\right) \cdot \frac{1}{-e^{w}}} \]
  5. Applied egg-rr99.0%

    \[\leadsto \color{blue}{\left(-{\ell}^{\left(e^{w}\right)}\right) \cdot \frac{1}{-e^{w}}} \]
  6. Taylor expanded in w around inf 99.0%

    \[\leadsto \left(-{\ell}^{\left(e^{w}\right)}\right) \cdot \color{blue}{\frac{-1}{e^{w}}} \]
  7. Final simplification99.0%

    \[\leadsto {\ell}^{\left(e^{w}\right)} \cdot \frac{--1}{e^{w}} \]

Alternative 2: 99.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{{\ell}^{\left(e^{w}\right)}}{e^{w}} \end{array} \]
(FPCore (w l) :precision binary64 (/ (pow l (exp w)) (exp w)))
double code(double w, double l) {
	return pow(l, exp(w)) / exp(w);
}
real(8) function code(w, l)
    real(8), intent (in) :: w
    real(8), intent (in) :: l
    code = (l ** exp(w)) / exp(w)
end function
public static double code(double w, double l) {
	return Math.pow(l, Math.exp(w)) / Math.exp(w);
}
def code(w, l):
	return math.pow(l, math.exp(w)) / math.exp(w)
function code(w, l)
	return Float64((l ^ exp(w)) / exp(w))
end
function tmp = code(w, l)
	tmp = (l ^ exp(w)) / exp(w);
end
code[w_, l_] := N[(N[Power[l, N[Exp[w], $MachinePrecision]], $MachinePrecision] / N[Exp[w], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}
\end{array}
Derivation
  1. Initial program 99.0%

    \[e^{-w} \cdot {\ell}^{\left(e^{w}\right)} \]
  2. Step-by-step derivation
    1. exp-neg99.0%

      \[\leadsto \color{blue}{\frac{1}{e^{w}}} \cdot {\ell}^{\left(e^{w}\right)} \]
    2. associate-*l/99.0%

      \[\leadsto \color{blue}{\frac{1 \cdot {\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
    3. *-lft-identity99.0%

      \[\leadsto \frac{\color{blue}{{\ell}^{\left(e^{w}\right)}}}{e^{w}} \]
  3. Simplified99.0%

    \[\leadsto \color{blue}{\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
  4. Final simplification99.0%

    \[\leadsto \frac{{\ell}^{\left(e^{w}\right)}}{e^{w}} \]

Alternative 3: 98.4% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;w \leq -0.062:\\ \;\;\;\;e^{-w}\\ \mathbf{elif}\;w \leq 0.0076:\\ \;\;\;\;\left(\ell + \ell \cdot \left(w \cdot \log \ell\right)\right) \cdot \left(\left(-w\right) - -1\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\log \ell - w}\\ \end{array} \end{array} \]
(FPCore (w l)
 :precision binary64
 (if (<= w -0.062)
   (exp (- w))
   (if (<= w 0.0076)
     (* (+ l (* l (* w (log l)))) (- (- w) -1.0))
     (exp (- (log l) w)))))
double code(double w, double l) {
	double tmp;
	if (w <= -0.062) {
		tmp = exp(-w);
	} else if (w <= 0.0076) {
		tmp = (l + (l * (w * log(l)))) * (-w - -1.0);
	} else {
		tmp = exp((log(l) - w));
	}
	return tmp;
}
real(8) function code(w, l)
    real(8), intent (in) :: w
    real(8), intent (in) :: l
    real(8) :: tmp
    if (w <= (-0.062d0)) then
        tmp = exp(-w)
    else if (w <= 0.0076d0) then
        tmp = (l + (l * (w * log(l)))) * (-w - (-1.0d0))
    else
        tmp = exp((log(l) - w))
    end if
    code = tmp
end function
public static double code(double w, double l) {
	double tmp;
	if (w <= -0.062) {
		tmp = Math.exp(-w);
	} else if (w <= 0.0076) {
		tmp = (l + (l * (w * Math.log(l)))) * (-w - -1.0);
	} else {
		tmp = Math.exp((Math.log(l) - w));
	}
	return tmp;
}
def code(w, l):
	tmp = 0
	if w <= -0.062:
		tmp = math.exp(-w)
	elif w <= 0.0076:
		tmp = (l + (l * (w * math.log(l)))) * (-w - -1.0)
	else:
		tmp = math.exp((math.log(l) - w))
	return tmp
function code(w, l)
	tmp = 0.0
	if (w <= -0.062)
		tmp = exp(Float64(-w));
	elseif (w <= 0.0076)
		tmp = Float64(Float64(l + Float64(l * Float64(w * log(l)))) * Float64(Float64(-w) - -1.0));
	else
		tmp = exp(Float64(log(l) - w));
	end
	return tmp
end
function tmp_2 = code(w, l)
	tmp = 0.0;
	if (w <= -0.062)
		tmp = exp(-w);
	elseif (w <= 0.0076)
		tmp = (l + (l * (w * log(l)))) * (-w - -1.0);
	else
		tmp = exp((log(l) - w));
	end
	tmp_2 = tmp;
end
code[w_, l_] := If[LessEqual[w, -0.062], N[Exp[(-w)], $MachinePrecision], If[LessEqual[w, 0.0076], N[(N[(l + N[(l * N[(w * N[Log[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[((-w) - -1.0), $MachinePrecision]), $MachinePrecision], N[Exp[N[(N[Log[l], $MachinePrecision] - w), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;w \leq -0.062:\\
\;\;\;\;e^{-w}\\

\mathbf{elif}\;w \leq 0.0076:\\
\;\;\;\;\left(\ell + \ell \cdot \left(w \cdot \log \ell\right)\right) \cdot \left(\left(-w\right) - -1\right)\\

\mathbf{else}:\\
\;\;\;\;e^{\log \ell - w}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if w < -0.062

    1. Initial program 99.7%

      \[e^{-w} \cdot {\ell}^{\left(e^{w}\right)} \]
    2. Step-by-step derivation
      1. exp-neg99.7%

        \[\leadsto \color{blue}{\frac{1}{e^{w}}} \cdot {\ell}^{\left(e^{w}\right)} \]
      2. associate-*l/99.7%

        \[\leadsto \color{blue}{\frac{1 \cdot {\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
      3. *-lft-identity99.7%

        \[\leadsto \frac{\color{blue}{{\ell}^{\left(e^{w}\right)}}}{e^{w}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
    4. Step-by-step derivation
      1. add-exp-log99.6%

        \[\leadsto \color{blue}{e^{\log \left(\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}\right)}} \]
      2. log-div99.6%

        \[\leadsto e^{\color{blue}{\log \left({\ell}^{\left(e^{w}\right)}\right) - \log \left(e^{w}\right)}} \]
      3. log-pow99.6%

        \[\leadsto e^{\color{blue}{e^{w} \cdot \log \ell} - \log \left(e^{w}\right)} \]
      4. add-log-exp99.6%

        \[\leadsto e^{e^{w} \cdot \log \ell - \color{blue}{w}} \]
    5. Applied egg-rr99.6%

      \[\leadsto \color{blue}{e^{e^{w} \cdot \log \ell - w}} \]
    6. Taylor expanded in w around inf 96.4%

      \[\leadsto e^{\color{blue}{-1 \cdot w}} \]
    7. Step-by-step derivation
      1. neg-mul-196.4%

        \[\leadsto e^{\color{blue}{-w}} \]
    8. Simplified96.4%

      \[\leadsto e^{\color{blue}{-w}} \]

    if -0.062 < w < 0.00759999999999999998

    1. Initial program 99.7%

      \[e^{-w} \cdot {\ell}^{\left(e^{w}\right)} \]
    2. Step-by-step derivation
      1. exp-neg99.7%

        \[\leadsto \color{blue}{\frac{1}{e^{w}}} \cdot {\ell}^{\left(e^{w}\right)} \]
      2. associate-*l/99.7%

        \[\leadsto \color{blue}{\frac{1 \cdot {\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
      3. *-lft-identity99.7%

        \[\leadsto \frac{\color{blue}{{\ell}^{\left(e^{w}\right)}}}{e^{w}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
    4. Step-by-step derivation
      1. frac-2neg99.7%

        \[\leadsto \color{blue}{\frac{-{\ell}^{\left(e^{w}\right)}}{-e^{w}}} \]
      2. div-inv99.7%

        \[\leadsto \color{blue}{\left(-{\ell}^{\left(e^{w}\right)}\right) \cdot \frac{1}{-e^{w}}} \]
    5. Applied egg-rr99.7%

      \[\leadsto \color{blue}{\left(-{\ell}^{\left(e^{w}\right)}\right) \cdot \frac{1}{-e^{w}}} \]
    6. Taylor expanded in w around 0 99.3%

      \[\leadsto \left(-{\ell}^{\left(e^{w}\right)}\right) \cdot \color{blue}{\left(w - 1\right)} \]
    7. Taylor expanded in w around 0 99.0%

      \[\leadsto \left(-\color{blue}{\left(\ell + \ell \cdot \left(w \cdot \log \ell\right)\right)}\right) \cdot \left(w - 1\right) \]
    8. Step-by-step derivation
      1. *-commutative99.0%

        \[\leadsto \left(-\left(\ell + \ell \cdot \color{blue}{\left(\log \ell \cdot w\right)}\right)\right) \cdot \left(w - 1\right) \]
    9. Simplified99.0%

      \[\leadsto \left(-\color{blue}{\left(\ell + \ell \cdot \left(\log \ell \cdot w\right)\right)}\right) \cdot \left(w - 1\right) \]

    if 0.00759999999999999998 < w

    1. Initial program 94.7%

      \[e^{-w} \cdot {\ell}^{\left(e^{w}\right)} \]
    2. Step-by-step derivation
      1. exp-neg94.7%

        \[\leadsto \color{blue}{\frac{1}{e^{w}}} \cdot {\ell}^{\left(e^{w}\right)} \]
      2. associate-*l/94.7%

        \[\leadsto \color{blue}{\frac{1 \cdot {\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
      3. *-lft-identity94.7%

        \[\leadsto \frac{\color{blue}{{\ell}^{\left(e^{w}\right)}}}{e^{w}} \]
    3. Simplified94.7%

      \[\leadsto \color{blue}{\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
    4. Step-by-step derivation
      1. add-exp-log94.7%

        \[\leadsto \color{blue}{e^{\log \left(\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}\right)}} \]
      2. log-div94.6%

        \[\leadsto e^{\color{blue}{\log \left({\ell}^{\left(e^{w}\right)}\right) - \log \left(e^{w}\right)}} \]
      3. log-pow94.6%

        \[\leadsto e^{\color{blue}{e^{w} \cdot \log \ell} - \log \left(e^{w}\right)} \]
      4. add-log-exp99.7%

        \[\leadsto e^{e^{w} \cdot \log \ell - \color{blue}{w}} \]
    5. Applied egg-rr99.7%

      \[\leadsto \color{blue}{e^{e^{w} \cdot \log \ell - w}} \]
    6. Taylor expanded in w around 0 90.3%

      \[\leadsto e^{\color{blue}{\log \ell} - w} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification96.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;w \leq -0.062:\\ \;\;\;\;e^{-w}\\ \mathbf{elif}\;w \leq 0.0076:\\ \;\;\;\;\left(\ell + \ell \cdot \left(w \cdot \log \ell\right)\right) \cdot \left(\left(-w\right) - -1\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\log \ell - w}\\ \end{array} \]

Alternative 4: 98.6% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;w \leq -4.1:\\ \;\;\;\;e^{-w}\\ \mathbf{else}:\\ \;\;\;\;{\ell}^{\left(e^{w}\right)}\\ \end{array} \end{array} \]
(FPCore (w l) :precision binary64 (if (<= w -4.1) (exp (- w)) (pow l (exp w))))
double code(double w, double l) {
	double tmp;
	if (w <= -4.1) {
		tmp = exp(-w);
	} else {
		tmp = pow(l, exp(w));
	}
	return tmp;
}
real(8) function code(w, l)
    real(8), intent (in) :: w
    real(8), intent (in) :: l
    real(8) :: tmp
    if (w <= (-4.1d0)) then
        tmp = exp(-w)
    else
        tmp = l ** exp(w)
    end if
    code = tmp
end function
public static double code(double w, double l) {
	double tmp;
	if (w <= -4.1) {
		tmp = Math.exp(-w);
	} else {
		tmp = Math.pow(l, Math.exp(w));
	}
	return tmp;
}
def code(w, l):
	tmp = 0
	if w <= -4.1:
		tmp = math.exp(-w)
	else:
		tmp = math.pow(l, math.exp(w))
	return tmp
function code(w, l)
	tmp = 0.0
	if (w <= -4.1)
		tmp = exp(Float64(-w));
	else
		tmp = l ^ exp(w);
	end
	return tmp
end
function tmp_2 = code(w, l)
	tmp = 0.0;
	if (w <= -4.1)
		tmp = exp(-w);
	else
		tmp = l ^ exp(w);
	end
	tmp_2 = tmp;
end
code[w_, l_] := If[LessEqual[w, -4.1], N[Exp[(-w)], $MachinePrecision], N[Power[l, N[Exp[w], $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;w \leq -4.1:\\
\;\;\;\;e^{-w}\\

\mathbf{else}:\\
\;\;\;\;{\ell}^{\left(e^{w}\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if w < -4.0999999999999996

    1. Initial program 100.0%

      \[e^{-w} \cdot {\ell}^{\left(e^{w}\right)} \]
    2. Step-by-step derivation
      1. exp-neg100.0%

        \[\leadsto \color{blue}{\frac{1}{e^{w}}} \cdot {\ell}^{\left(e^{w}\right)} \]
      2. associate-*l/100.0%

        \[\leadsto \color{blue}{\frac{1 \cdot {\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
      3. *-lft-identity100.0%

        \[\leadsto \frac{\color{blue}{{\ell}^{\left(e^{w}\right)}}}{e^{w}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
    4. Step-by-step derivation
      1. add-exp-log99.9%

        \[\leadsto \color{blue}{e^{\log \left(\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}\right)}} \]
      2. log-div99.9%

        \[\leadsto e^{\color{blue}{\log \left({\ell}^{\left(e^{w}\right)}\right) - \log \left(e^{w}\right)}} \]
      3. log-pow99.9%

        \[\leadsto e^{\color{blue}{e^{w} \cdot \log \ell} - \log \left(e^{w}\right)} \]
      4. add-log-exp99.9%

        \[\leadsto e^{e^{w} \cdot \log \ell - \color{blue}{w}} \]
    5. Applied egg-rr99.9%

      \[\leadsto \color{blue}{e^{e^{w} \cdot \log \ell - w}} \]
    6. Taylor expanded in w around inf 99.0%

      \[\leadsto e^{\color{blue}{-1 \cdot w}} \]
    7. Step-by-step derivation
      1. neg-mul-199.0%

        \[\leadsto e^{\color{blue}{-w}} \]
    8. Simplified99.0%

      \[\leadsto e^{\color{blue}{-w}} \]

    if -4.0999999999999996 < w

    1. Initial program 98.6%

      \[e^{-w} \cdot {\ell}^{\left(e^{w}\right)} \]
    2. Step-by-step derivation
      1. exp-neg98.6%

        \[\leadsto \color{blue}{\frac{1}{e^{w}}} \cdot {\ell}^{\left(e^{w}\right)} \]
      2. associate-*l/98.6%

        \[\leadsto \color{blue}{\frac{1 \cdot {\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
      3. *-lft-identity98.6%

        \[\leadsto \frac{\color{blue}{{\ell}^{\left(e^{w}\right)}}}{e^{w}} \]
    3. Simplified98.6%

      \[\leadsto \color{blue}{\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
    4. Step-by-step derivation
      1. frac-2neg98.6%

        \[\leadsto \color{blue}{\frac{-{\ell}^{\left(e^{w}\right)}}{-e^{w}}} \]
      2. div-inv98.6%

        \[\leadsto \color{blue}{\left(-{\ell}^{\left(e^{w}\right)}\right) \cdot \frac{1}{-e^{w}}} \]
    5. Applied egg-rr98.6%

      \[\leadsto \color{blue}{\left(-{\ell}^{\left(e^{w}\right)}\right) \cdot \frac{1}{-e^{w}}} \]
    6. Taylor expanded in w around 0 97.6%

      \[\leadsto \left(-{\ell}^{\left(e^{w}\right)}\right) \cdot \color{blue}{-1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;w \leq -4.1:\\ \;\;\;\;e^{-w}\\ \mathbf{else}:\\ \;\;\;\;{\ell}^{\left(e^{w}\right)}\\ \end{array} \]

Alternative 5: 97.9% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;w \leq -0.122 \lor \neg \left(w \leq 5000000\right):\\ \;\;\;\;e^{-w}\\ \mathbf{else}:\\ \;\;\;\;\ell + w \cdot \left(\ell \cdot \log \ell - \ell\right)\\ \end{array} \end{array} \]
(FPCore (w l)
 :precision binary64
 (if (or (<= w -0.122) (not (<= w 5000000.0)))
   (exp (- w))
   (+ l (* w (- (* l (log l)) l)))))
double code(double w, double l) {
	double tmp;
	if ((w <= -0.122) || !(w <= 5000000.0)) {
		tmp = exp(-w);
	} else {
		tmp = l + (w * ((l * log(l)) - l));
	}
	return tmp;
}
real(8) function code(w, l)
    real(8), intent (in) :: w
    real(8), intent (in) :: l
    real(8) :: tmp
    if ((w <= (-0.122d0)) .or. (.not. (w <= 5000000.0d0))) then
        tmp = exp(-w)
    else
        tmp = l + (w * ((l * log(l)) - l))
    end if
    code = tmp
end function
public static double code(double w, double l) {
	double tmp;
	if ((w <= -0.122) || !(w <= 5000000.0)) {
		tmp = Math.exp(-w);
	} else {
		tmp = l + (w * ((l * Math.log(l)) - l));
	}
	return tmp;
}
def code(w, l):
	tmp = 0
	if (w <= -0.122) or not (w <= 5000000.0):
		tmp = math.exp(-w)
	else:
		tmp = l + (w * ((l * math.log(l)) - l))
	return tmp
function code(w, l)
	tmp = 0.0
	if ((w <= -0.122) || !(w <= 5000000.0))
		tmp = exp(Float64(-w));
	else
		tmp = Float64(l + Float64(w * Float64(Float64(l * log(l)) - l)));
	end
	return tmp
end
function tmp_2 = code(w, l)
	tmp = 0.0;
	if ((w <= -0.122) || ~((w <= 5000000.0)))
		tmp = exp(-w);
	else
		tmp = l + (w * ((l * log(l)) - l));
	end
	tmp_2 = tmp;
end
code[w_, l_] := If[Or[LessEqual[w, -0.122], N[Not[LessEqual[w, 5000000.0]], $MachinePrecision]], N[Exp[(-w)], $MachinePrecision], N[(l + N[(w * N[(N[(l * N[Log[l], $MachinePrecision]), $MachinePrecision] - l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;w \leq -0.122 \lor \neg \left(w \leq 5000000\right):\\
\;\;\;\;e^{-w}\\

\mathbf{else}:\\
\;\;\;\;\ell + w \cdot \left(\ell \cdot \log \ell - \ell\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if w < -0.122 or 5e6 < w

    1. Initial program 99.8%

      \[e^{-w} \cdot {\ell}^{\left(e^{w}\right)} \]
    2. Step-by-step derivation
      1. exp-neg99.8%

        \[\leadsto \color{blue}{\frac{1}{e^{w}}} \cdot {\ell}^{\left(e^{w}\right)} \]
      2. associate-*l/99.8%

        \[\leadsto \color{blue}{\frac{1 \cdot {\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
      3. *-lft-identity99.8%

        \[\leadsto \frac{\color{blue}{{\ell}^{\left(e^{w}\right)}}}{e^{w}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
    4. Step-by-step derivation
      1. add-exp-log99.8%

        \[\leadsto \color{blue}{e^{\log \left(\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}\right)}} \]
      2. log-div99.8%

        \[\leadsto e^{\color{blue}{\log \left({\ell}^{\left(e^{w}\right)}\right) - \log \left(e^{w}\right)}} \]
      3. log-pow99.7%

        \[\leadsto e^{\color{blue}{e^{w} \cdot \log \ell} - \log \left(e^{w}\right)} \]
      4. add-log-exp99.7%

        \[\leadsto e^{e^{w} \cdot \log \ell - \color{blue}{w}} \]
    5. Applied egg-rr99.7%

      \[\leadsto \color{blue}{e^{e^{w} \cdot \log \ell - w}} \]
    6. Taylor expanded in w around inf 97.6%

      \[\leadsto e^{\color{blue}{-1 \cdot w}} \]
    7. Step-by-step derivation
      1. neg-mul-197.6%

        \[\leadsto e^{\color{blue}{-w}} \]
    8. Simplified97.6%

      \[\leadsto e^{\color{blue}{-w}} \]

    if -0.122 < w < 5e6

    1. Initial program 98.3%

      \[e^{-w} \cdot {\ell}^{\left(e^{w}\right)} \]
    2. Step-by-step derivation
      1. exp-neg98.3%

        \[\leadsto \color{blue}{\frac{1}{e^{w}}} \cdot {\ell}^{\left(e^{w}\right)} \]
      2. associate-*l/98.3%

        \[\leadsto \color{blue}{\frac{1 \cdot {\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
      3. *-lft-identity98.3%

        \[\leadsto \frac{\color{blue}{{\ell}^{\left(e^{w}\right)}}}{e^{w}} \]
    3. Simplified98.3%

      \[\leadsto \color{blue}{\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
    4. Taylor expanded in w around 0 95.9%

      \[\leadsto \color{blue}{\ell + w \cdot \left(\ell \cdot \log \ell - \ell\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;w \leq -0.122 \lor \neg \left(w \leq 5000000\right):\\ \;\;\;\;e^{-w}\\ \mathbf{else}:\\ \;\;\;\;\ell + w \cdot \left(\ell \cdot \log \ell - \ell\right)\\ \end{array} \]

Alternative 6: 98.2% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;w \leq -0.075 \lor \neg \left(w \leq 5000000\right):\\ \;\;\;\;e^{-w}\\ \mathbf{else}:\\ \;\;\;\;\ell + \left(-1 + \log \ell\right) \cdot \left(\ell \cdot w\right)\\ \end{array} \end{array} \]
(FPCore (w l)
 :precision binary64
 (if (or (<= w -0.075) (not (<= w 5000000.0)))
   (exp (- w))
   (+ l (* (+ -1.0 (log l)) (* l w)))))
double code(double w, double l) {
	double tmp;
	if ((w <= -0.075) || !(w <= 5000000.0)) {
		tmp = exp(-w);
	} else {
		tmp = l + ((-1.0 + log(l)) * (l * w));
	}
	return tmp;
}
real(8) function code(w, l)
    real(8), intent (in) :: w
    real(8), intent (in) :: l
    real(8) :: tmp
    if ((w <= (-0.075d0)) .or. (.not. (w <= 5000000.0d0))) then
        tmp = exp(-w)
    else
        tmp = l + (((-1.0d0) + log(l)) * (l * w))
    end if
    code = tmp
end function
public static double code(double w, double l) {
	double tmp;
	if ((w <= -0.075) || !(w <= 5000000.0)) {
		tmp = Math.exp(-w);
	} else {
		tmp = l + ((-1.0 + Math.log(l)) * (l * w));
	}
	return tmp;
}
def code(w, l):
	tmp = 0
	if (w <= -0.075) or not (w <= 5000000.0):
		tmp = math.exp(-w)
	else:
		tmp = l + ((-1.0 + math.log(l)) * (l * w))
	return tmp
function code(w, l)
	tmp = 0.0
	if ((w <= -0.075) || !(w <= 5000000.0))
		tmp = exp(Float64(-w));
	else
		tmp = Float64(l + Float64(Float64(-1.0 + log(l)) * Float64(l * w)));
	end
	return tmp
end
function tmp_2 = code(w, l)
	tmp = 0.0;
	if ((w <= -0.075) || ~((w <= 5000000.0)))
		tmp = exp(-w);
	else
		tmp = l + ((-1.0 + log(l)) * (l * w));
	end
	tmp_2 = tmp;
end
code[w_, l_] := If[Or[LessEqual[w, -0.075], N[Not[LessEqual[w, 5000000.0]], $MachinePrecision]], N[Exp[(-w)], $MachinePrecision], N[(l + N[(N[(-1.0 + N[Log[l], $MachinePrecision]), $MachinePrecision] * N[(l * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;w \leq -0.075 \lor \neg \left(w \leq 5000000\right):\\
\;\;\;\;e^{-w}\\

\mathbf{else}:\\
\;\;\;\;\ell + \left(-1 + \log \ell\right) \cdot \left(\ell \cdot w\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if w < -0.0749999999999999972 or 5e6 < w

    1. Initial program 99.8%

      \[e^{-w} \cdot {\ell}^{\left(e^{w}\right)} \]
    2. Step-by-step derivation
      1. exp-neg99.8%

        \[\leadsto \color{blue}{\frac{1}{e^{w}}} \cdot {\ell}^{\left(e^{w}\right)} \]
      2. associate-*l/99.8%

        \[\leadsto \color{blue}{\frac{1 \cdot {\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
      3. *-lft-identity99.8%

        \[\leadsto \frac{\color{blue}{{\ell}^{\left(e^{w}\right)}}}{e^{w}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
    4. Step-by-step derivation
      1. add-exp-log99.8%

        \[\leadsto \color{blue}{e^{\log \left(\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}\right)}} \]
      2. log-div99.8%

        \[\leadsto e^{\color{blue}{\log \left({\ell}^{\left(e^{w}\right)}\right) - \log \left(e^{w}\right)}} \]
      3. log-pow99.7%

        \[\leadsto e^{\color{blue}{e^{w} \cdot \log \ell} - \log \left(e^{w}\right)} \]
      4. add-log-exp99.7%

        \[\leadsto e^{e^{w} \cdot \log \ell - \color{blue}{w}} \]
    5. Applied egg-rr99.7%

      \[\leadsto \color{blue}{e^{e^{w} \cdot \log \ell - w}} \]
    6. Taylor expanded in w around inf 97.6%

      \[\leadsto e^{\color{blue}{-1 \cdot w}} \]
    7. Step-by-step derivation
      1. neg-mul-197.6%

        \[\leadsto e^{\color{blue}{-w}} \]
    8. Simplified97.6%

      \[\leadsto e^{\color{blue}{-w}} \]

    if -0.0749999999999999972 < w < 5e6

    1. Initial program 98.3%

      \[e^{-w} \cdot {\ell}^{\left(e^{w}\right)} \]
    2. Step-by-step derivation
      1. exp-neg98.3%

        \[\leadsto \color{blue}{\frac{1}{e^{w}}} \cdot {\ell}^{\left(e^{w}\right)} \]
      2. associate-*l/98.3%

        \[\leadsto \color{blue}{\frac{1 \cdot {\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
      3. *-lft-identity98.3%

        \[\leadsto \frac{\color{blue}{{\ell}^{\left(e^{w}\right)}}}{e^{w}} \]
    3. Simplified98.3%

      \[\leadsto \color{blue}{\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
    4. Taylor expanded in w around 0 95.9%

      \[\leadsto \color{blue}{\ell + w \cdot \left(\ell \cdot \log \ell - \ell\right)} \]
    5. Taylor expanded in l around 0 96.4%

      \[\leadsto \ell + \color{blue}{\left(\log \ell - 1\right) \cdot \left(\ell \cdot w\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;w \leq -0.075 \lor \neg \left(w \leq 5000000\right):\\ \;\;\;\;e^{-w}\\ \mathbf{else}:\\ \;\;\;\;\ell + \left(-1 + \log \ell\right) \cdot \left(\ell \cdot w\right)\\ \end{array} \]

Alternative 7: 97.5% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;w \leq -0.69 \lor \neg \left(w \leq 5000000\right):\\ \;\;\;\;e^{-w}\\ \mathbf{else}:\\ \;\;\;\;\ell\\ \end{array} \end{array} \]
(FPCore (w l)
 :precision binary64
 (if (or (<= w -0.69) (not (<= w 5000000.0))) (exp (- w)) l))
double code(double w, double l) {
	double tmp;
	if ((w <= -0.69) || !(w <= 5000000.0)) {
		tmp = exp(-w);
	} else {
		tmp = l;
	}
	return tmp;
}
real(8) function code(w, l)
    real(8), intent (in) :: w
    real(8), intent (in) :: l
    real(8) :: tmp
    if ((w <= (-0.69d0)) .or. (.not. (w <= 5000000.0d0))) then
        tmp = exp(-w)
    else
        tmp = l
    end if
    code = tmp
end function
public static double code(double w, double l) {
	double tmp;
	if ((w <= -0.69) || !(w <= 5000000.0)) {
		tmp = Math.exp(-w);
	} else {
		tmp = l;
	}
	return tmp;
}
def code(w, l):
	tmp = 0
	if (w <= -0.69) or not (w <= 5000000.0):
		tmp = math.exp(-w)
	else:
		tmp = l
	return tmp
function code(w, l)
	tmp = 0.0
	if ((w <= -0.69) || !(w <= 5000000.0))
		tmp = exp(Float64(-w));
	else
		tmp = l;
	end
	return tmp
end
function tmp_2 = code(w, l)
	tmp = 0.0;
	if ((w <= -0.69) || ~((w <= 5000000.0)))
		tmp = exp(-w);
	else
		tmp = l;
	end
	tmp_2 = tmp;
end
code[w_, l_] := If[Or[LessEqual[w, -0.69], N[Not[LessEqual[w, 5000000.0]], $MachinePrecision]], N[Exp[(-w)], $MachinePrecision], l]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;w \leq -0.69 \lor \neg \left(w \leq 5000000\right):\\
\;\;\;\;e^{-w}\\

\mathbf{else}:\\
\;\;\;\;\ell\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if w < -0.68999999999999995 or 5e6 < w

    1. Initial program 100.0%

      \[e^{-w} \cdot {\ell}^{\left(e^{w}\right)} \]
    2. Step-by-step derivation
      1. exp-neg100.0%

        \[\leadsto \color{blue}{\frac{1}{e^{w}}} \cdot {\ell}^{\left(e^{w}\right)} \]
      2. associate-*l/100.0%

        \[\leadsto \color{blue}{\frac{1 \cdot {\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
      3. *-lft-identity100.0%

        \[\leadsto \frac{\color{blue}{{\ell}^{\left(e^{w}\right)}}}{e^{w}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
    4. Step-by-step derivation
      1. add-exp-log100.0%

        \[\leadsto \color{blue}{e^{\log \left(\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}\right)}} \]
      2. log-div100.0%

        \[\leadsto e^{\color{blue}{\log \left({\ell}^{\left(e^{w}\right)}\right) - \log \left(e^{w}\right)}} \]
      3. log-pow100.0%

        \[\leadsto e^{\color{blue}{e^{w} \cdot \log \ell} - \log \left(e^{w}\right)} \]
      4. add-log-exp100.0%

        \[\leadsto e^{e^{w} \cdot \log \ell - \color{blue}{w}} \]
    5. Applied egg-rr100.0%

      \[\leadsto \color{blue}{e^{e^{w} \cdot \log \ell - w}} \]
    6. Taylor expanded in w around inf 99.3%

      \[\leadsto e^{\color{blue}{-1 \cdot w}} \]
    7. Step-by-step derivation
      1. neg-mul-199.3%

        \[\leadsto e^{\color{blue}{-w}} \]
    8. Simplified99.3%

      \[\leadsto e^{\color{blue}{-w}} \]

    if -0.68999999999999995 < w < 5e6

    1. Initial program 98.2%

      \[e^{-w} \cdot {\ell}^{\left(e^{w}\right)} \]
    2. Step-by-step derivation
      1. exp-neg98.2%

        \[\leadsto \color{blue}{\frac{1}{e^{w}}} \cdot {\ell}^{\left(e^{w}\right)} \]
      2. associate-*l/98.2%

        \[\leadsto \color{blue}{\frac{1 \cdot {\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
      3. *-lft-identity98.2%

        \[\leadsto \frac{\color{blue}{{\ell}^{\left(e^{w}\right)}}}{e^{w}} \]
    3. Simplified98.2%

      \[\leadsto \color{blue}{\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
    4. Taylor expanded in w around 0 94.5%

      \[\leadsto \color{blue}{\ell} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;w \leq -0.69 \lor \neg \left(w \leq 5000000\right):\\ \;\;\;\;e^{-w}\\ \mathbf{else}:\\ \;\;\;\;\ell\\ \end{array} \]

Alternative 8: 56.6% accurate, 305.0× speedup?

\[\begin{array}{l} \\ \ell \end{array} \]
(FPCore (w l) :precision binary64 l)
double code(double w, double l) {
	return l;
}
real(8) function code(w, l)
    real(8), intent (in) :: w
    real(8), intent (in) :: l
    code = l
end function
public static double code(double w, double l) {
	return l;
}
def code(w, l):
	return l
function code(w, l)
	return l
end
function tmp = code(w, l)
	tmp = l;
end
code[w_, l_] := l
\begin{array}{l}

\\
\ell
\end{array}
Derivation
  1. Initial program 99.0%

    \[e^{-w} \cdot {\ell}^{\left(e^{w}\right)} \]
  2. Step-by-step derivation
    1. exp-neg99.0%

      \[\leadsto \color{blue}{\frac{1}{e^{w}}} \cdot {\ell}^{\left(e^{w}\right)} \]
    2. associate-*l/99.0%

      \[\leadsto \color{blue}{\frac{1 \cdot {\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
    3. *-lft-identity99.0%

      \[\leadsto \frac{\color{blue}{{\ell}^{\left(e^{w}\right)}}}{e^{w}} \]
  3. Simplified99.0%

    \[\leadsto \color{blue}{\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}} \]
  4. Taylor expanded in w around 0 57.6%

    \[\leadsto \color{blue}{\ell} \]
  5. Final simplification57.6%

    \[\leadsto \ell \]

Reproduce

?
herbie shell --seed 2023215 
(FPCore (w l)
  :name "exp-w (used to crash)"
  :precision binary64
  (* (exp (- w)) (pow l (exp w))))