| Alternative 1 | |
|---|---|
| Accuracy | 97.1% |
| Cost | 14272 |
(FPCore (wj x) :precision binary64 (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))
(FPCore (wj x) :precision binary64 (if (<= wj -5.5e-9) (- (/ (/ x (exp wj)) (+ wj 1.0)) (- (/ wj (+ wj 1.0)) wj)) (+ (* wj wj) (+ x (* -2.0 (* x wj))))))
double code(double wj, double x) {
return wj - (((wj * exp(wj)) - x) / (exp(wj) + (wj * exp(wj))));
}
double code(double wj, double x) {
double tmp;
if (wj <= -5.5e-9) {
tmp = ((x / exp(wj)) / (wj + 1.0)) - ((wj / (wj + 1.0)) - wj);
} else {
tmp = (wj * wj) + (x + (-2.0 * (x * wj)));
}
return tmp;
}
real(8) function code(wj, x)
real(8), intent (in) :: wj
real(8), intent (in) :: x
code = wj - (((wj * exp(wj)) - x) / (exp(wj) + (wj * exp(wj))))
end function
real(8) function code(wj, x)
real(8), intent (in) :: wj
real(8), intent (in) :: x
real(8) :: tmp
if (wj <= (-5.5d-9)) then
tmp = ((x / exp(wj)) / (wj + 1.0d0)) - ((wj / (wj + 1.0d0)) - wj)
else
tmp = (wj * wj) + (x + ((-2.0d0) * (x * wj)))
end if
code = tmp
end function
public static double code(double wj, double x) {
return wj - (((wj * Math.exp(wj)) - x) / (Math.exp(wj) + (wj * Math.exp(wj))));
}
public static double code(double wj, double x) {
double tmp;
if (wj <= -5.5e-9) {
tmp = ((x / Math.exp(wj)) / (wj + 1.0)) - ((wj / (wj + 1.0)) - wj);
} else {
tmp = (wj * wj) + (x + (-2.0 * (x * wj)));
}
return tmp;
}
def code(wj, x): return wj - (((wj * math.exp(wj)) - x) / (math.exp(wj) + (wj * math.exp(wj))))
def code(wj, x): tmp = 0 if wj <= -5.5e-9: tmp = ((x / math.exp(wj)) / (wj + 1.0)) - ((wj / (wj + 1.0)) - wj) else: tmp = (wj * wj) + (x + (-2.0 * (x * wj))) return tmp
function code(wj, x) return Float64(wj - Float64(Float64(Float64(wj * exp(wj)) - x) / Float64(exp(wj) + Float64(wj * exp(wj))))) end
function code(wj, x) tmp = 0.0 if (wj <= -5.5e-9) tmp = Float64(Float64(Float64(x / exp(wj)) / Float64(wj + 1.0)) - Float64(Float64(wj / Float64(wj + 1.0)) - wj)); else tmp = Float64(Float64(wj * wj) + Float64(x + Float64(-2.0 * Float64(x * wj)))); end return tmp end
function tmp = code(wj, x) tmp = wj - (((wj * exp(wj)) - x) / (exp(wj) + (wj * exp(wj)))); end
function tmp_2 = code(wj, x) tmp = 0.0; if (wj <= -5.5e-9) tmp = ((x / exp(wj)) / (wj + 1.0)) - ((wj / (wj + 1.0)) - wj); else tmp = (wj * wj) + (x + (-2.0 * (x * wj))); end tmp_2 = tmp; end
code[wj_, x_] := N[(wj - N[(N[(N[(wj * N[Exp[wj], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision] / N[(N[Exp[wj], $MachinePrecision] + N[(wj * N[Exp[wj], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[wj_, x_] := If[LessEqual[wj, -5.5e-9], N[(N[(N[(x / N[Exp[wj], $MachinePrecision]), $MachinePrecision] / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(wj / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision] - wj), $MachinePrecision]), $MachinePrecision], N[(N[(wj * wj), $MachinePrecision] + N[(x + N[(-2.0 * N[(x * wj), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\begin{array}{l}
\mathbf{if}\;wj \leq -5.5 \cdot 10^{-9}:\\
\;\;\;\;\frac{\frac{x}{e^{wj}}}{wj + 1} - \left(\frac{wj}{wj + 1} - wj\right)\\
\mathbf{else}:\\
\;\;\;\;wj \cdot wj + \left(x + -2 \cdot \left(x \cdot wj\right)\right)\\
\end{array}
Results
| Original | 79.3% |
|---|---|
| Target | 80.3% |
| Herbie | 97.5% |
if wj < -5.4999999999999996e-9Initial program 91.5%
Simplified91.5%
[Start]91.5 | \[ wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\] |
|---|---|
sub-neg [=>]91.5 | \[ \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)}
\] |
neg-mul-1 [=>]91.5 | \[ wj + \color{blue}{-1 \cdot \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}}
\] |
*-commutative [=>]91.5 | \[ wj + \color{blue}{\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \cdot -1}
\] |
*-commutative [<=]91.5 | \[ wj + \color{blue}{-1 \cdot \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}}
\] |
neg-mul-1 [<=]91.5 | \[ wj + \color{blue}{\left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)}
\] |
neg-sub0 [=>]91.5 | \[ wj + \color{blue}{\left(0 - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)}
\] |
div-sub [=>]91.4 | \[ wj + \left(0 - \color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right)
\] |
associate--r- [=>]91.4 | \[ wj + \color{blue}{\left(\left(0 - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}
\] |
+-commutative [=>]91.4 | \[ wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} + \left(0 - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)}
\] |
sub0-neg [=>]91.4 | \[ wj + \left(\frac{x}{e^{wj} + wj \cdot e^{wj}} + \color{blue}{\left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right)
\] |
sub-neg [<=]91.4 | \[ wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}
\] |
Applied egg-rr91.5%
[Start]91.5 | \[ wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}
\] |
|---|---|
+-commutative [=>]91.5 | \[ \color{blue}{\frac{\frac{x}{e^{wj}} - wj}{wj + 1} + wj}
\] |
div-sub [=>]91.5 | \[ \color{blue}{\left(\frac{\frac{x}{e^{wj}}}{wj + 1} - \frac{wj}{wj + 1}\right)} + wj
\] |
associate-+l- [=>]91.5 | \[ \color{blue}{\frac{\frac{x}{e^{wj}}}{wj + 1} - \left(\frac{wj}{wj + 1} - wj\right)}
\] |
if -5.4999999999999996e-9 < wj Initial program 79.0%
Simplified80.0%
[Start]79.0 | \[ wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\] |
|---|---|
sub-neg [=>]79.0 | \[ \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)}
\] |
neg-mul-1 [=>]79.0 | \[ wj + \color{blue}{-1 \cdot \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}}
\] |
*-commutative [=>]79.0 | \[ wj + \color{blue}{\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \cdot -1}
\] |
*-commutative [<=]79.0 | \[ wj + \color{blue}{-1 \cdot \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}}
\] |
neg-mul-1 [<=]79.0 | \[ wj + \color{blue}{\left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)}
\] |
neg-sub0 [=>]79.0 | \[ wj + \color{blue}{\left(0 - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)}
\] |
div-sub [=>]79.0 | \[ wj + \left(0 - \color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right)
\] |
associate--r- [=>]79.0 | \[ wj + \color{blue}{\left(\left(0 - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}
\] |
+-commutative [=>]79.0 | \[ wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} + \left(0 - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)}
\] |
sub0-neg [=>]79.0 | \[ wj + \left(\frac{x}{e^{wj} + wj \cdot e^{wj}} + \color{blue}{\left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right)
\] |
sub-neg [<=]79.0 | \[ wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}
\] |
Taylor expanded in wj around 0 78.9%
Simplified78.9%
[Start]78.9 | \[ wj + \frac{\left(-1 \cdot \left(wj \cdot x\right) + x\right) - wj}{wj + 1}
\] |
|---|---|
+-commutative [=>]78.9 | \[ wj + \frac{\color{blue}{\left(x + -1 \cdot \left(wj \cdot x\right)\right)} - wj}{wj + 1}
\] |
mul-1-neg [=>]78.9 | \[ wj + \frac{\left(x + \color{blue}{\left(-wj \cdot x\right)}\right) - wj}{wj + 1}
\] |
unsub-neg [=>]78.9 | \[ wj + \frac{\color{blue}{\left(x - wj \cdot x\right)} - wj}{wj + 1}
\] |
*-commutative [<=]78.9 | \[ wj + \frac{\left(x - \color{blue}{x \cdot wj}\right) - wj}{wj + 1}
\] |
Taylor expanded in wj around 0 97.6%
Taylor expanded in x around 0 97.7%
Simplified97.7%
[Start]97.7 | \[ {wj}^{2} + \left(-2 \cdot \left(wj \cdot x\right) + x\right)
\] |
|---|---|
unpow2 [=>]97.7 | \[ \color{blue}{wj \cdot wj} + \left(-2 \cdot \left(wj \cdot x\right) + x\right)
\] |
Final simplification97.5%
| Alternative 1 | |
|---|---|
| Accuracy | 97.1% |
| Cost | 14272 |
| Alternative 2 | |
|---|---|
| Accuracy | 97.1% |
| Cost | 14016 |
| Alternative 3 | |
|---|---|
| Accuracy | 96.8% |
| Cost | 7424 |
| Alternative 4 | |
|---|---|
| Accuracy | 97.5% |
| Cost | 7236 |
| Alternative 5 | |
|---|---|
| Accuracy | 96.3% |
| Cost | 704 |
| Alternative 6 | |
|---|---|
| Accuracy | 87.2% |
| Cost | 576 |
| Alternative 7 | |
|---|---|
| Accuracy | 85.5% |
| Cost | 448 |
| Alternative 8 | |
|---|---|
| Accuracy | 4.3% |
| Cost | 64 |
| Alternative 9 | |
|---|---|
| Accuracy | 85.0% |
| Cost | 64 |
herbie shell --seed 2023135
(FPCore (wj x)
:name "Jmat.Real.lambertw, newton loop step"
:precision binary64
:herbie-target
(- wj (- (/ wj (+ wj 1.0)) (/ x (+ (exp wj) (* wj (exp wj))))))
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))