| Alternative 1 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 840 |

(FPCore (x y) :precision binary64 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))
(FPCore (x y) :precision binary64 (if (<= x -1.4e-13) (/ x (/ (+ x 1.0) (/ x y))) (if (<= x 6.2e-23) (+ x (* x (- (/ x y) x))) (* x (/ x (+ y (* x y)))))))
double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
double code(double x, double y) {
double tmp;
if (x <= -1.4e-13) {
tmp = x / ((x + 1.0) / (x / y));
} else if (x <= 6.2e-23) {
tmp = x + (x * ((x / y) - x));
} else {
tmp = x * (x / (y + (x * y)));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * ((x / y) + 1.0d0)) / (x + 1.0d0)
end function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.4d-13)) then
tmp = x / ((x + 1.0d0) / (x / y))
else if (x <= 6.2d-23) then
tmp = x + (x * ((x / y) - x))
else
tmp = x * (x / (y + (x * y)))
end if
code = tmp
end function
public static double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
public static double code(double x, double y) {
double tmp;
if (x <= -1.4e-13) {
tmp = x / ((x + 1.0) / (x / y));
} else if (x <= 6.2e-23) {
tmp = x + (x * ((x / y) - x));
} else {
tmp = x * (x / (y + (x * y)));
}
return tmp;
}
def code(x, y): return (x * ((x / y) + 1.0)) / (x + 1.0)
def code(x, y): tmp = 0 if x <= -1.4e-13: tmp = x / ((x + 1.0) / (x / y)) elif x <= 6.2e-23: tmp = x + (x * ((x / y) - x)) else: tmp = x * (x / (y + (x * y))) return tmp
function code(x, y) return Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) end
function code(x, y) tmp = 0.0 if (x <= -1.4e-13) tmp = Float64(x / Float64(Float64(x + 1.0) / Float64(x / y))); elseif (x <= 6.2e-23) tmp = Float64(x + Float64(x * Float64(Float64(x / y) - x))); else tmp = Float64(x * Float64(x / Float64(y + Float64(x * y)))); end return tmp end
function tmp = code(x, y) tmp = (x * ((x / y) + 1.0)) / (x + 1.0); end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.4e-13) tmp = x / ((x + 1.0) / (x / y)); elseif (x <= 6.2e-23) tmp = x + (x * ((x / y) - x)); else tmp = x * (x / (y + (x * y))); end tmp_2 = tmp; end
code[x_, y_] := N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[LessEqual[x, -1.4e-13], N[(x / N[(N[(x + 1.0), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 6.2e-23], N[(x + N[(x * N[(N[(x / y), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(x / N[(y + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{-13}:\\
\;\;\;\;\frac{x}{\frac{x + 1}{\frac{x}{y}}}\\
\mathbf{elif}\;x \leq 6.2 \cdot 10^{-23}:\\
\;\;\;\;x + x \cdot \left(\frac{x}{y} - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{x}{y + x \cdot y}\\
\end{array}
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 99.6% |
|---|---|
| Target | 99.8% |
| Herbie | 99.1% |
if x < -1.4000000000000001e-13Initial program 83.6%
Simplified99.6%
[Start]83.6% | \[ \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\] |
|---|---|
associate-/l* [=>]99.6% | \[ \color{blue}{\frac{x}{\frac{x + 1}{\frac{x}{y} + 1}}}
\] |
Taylor expanded in y around 0 99.3%
Simplified99.6%
[Start]99.3% | \[ \frac{x}{\frac{y \cdot \left(1 + x\right)}{x}}
\] |
|---|---|
+-commutative [<=]99.3% | \[ \frac{x}{\frac{y \cdot \color{blue}{\left(x + 1\right)}}{x}}
\] |
*-commutative [=>]99.3% | \[ \frac{x}{\frac{\color{blue}{\left(x + 1\right) \cdot y}}{x}}
\] |
+-commutative [=>]99.3% | \[ \frac{x}{\frac{\color{blue}{\left(1 + x\right)} \cdot y}{x}}
\] |
associate-/l* [=>]99.6% | \[ \frac{x}{\color{blue}{\frac{1 + x}{\frac{x}{y}}}}
\] |
if -1.4000000000000001e-13 < x < 6.1999999999999998e-23Initial program 99.8%
Applied egg-rr88.6%
[Start]99.8% | \[ \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\] |
|---|---|
flip-+ [=>]88.7% | \[ \frac{x \cdot \color{blue}{\frac{\frac{x}{y} \cdot \frac{x}{y} - 1 \cdot 1}{\frac{x}{y} - 1}}}{x + 1}
\] |
associate-*r/ [=>]88.6% | \[ \frac{\color{blue}{\frac{x \cdot \left(\frac{x}{y} \cdot \frac{x}{y} - 1 \cdot 1\right)}{\frac{x}{y} - 1}}}{x + 1}
\] |
metadata-eval [=>]88.6% | \[ \frac{\frac{x \cdot \left(\frac{x}{y} \cdot \frac{x}{y} - \color{blue}{1}\right)}{\frac{x}{y} - 1}}{x + 1}
\] |
sub-neg [=>]88.6% | \[ \frac{\frac{x \cdot \color{blue}{\left(\frac{x}{y} \cdot \frac{x}{y} + \left(-1\right)\right)}}{\frac{x}{y} - 1}}{x + 1}
\] |
pow2 [=>]88.6% | \[ \frac{\frac{x \cdot \left(\color{blue}{{\left(\frac{x}{y}\right)}^{2}} + \left(-1\right)\right)}{\frac{x}{y} - 1}}{x + 1}
\] |
metadata-eval [=>]88.6% | \[ \frac{\frac{x \cdot \left({\left(\frac{x}{y}\right)}^{2} + \color{blue}{-1}\right)}{\frac{x}{y} - 1}}{x + 1}
\] |
sub-neg [=>]88.6% | \[ \frac{\frac{x \cdot \left({\left(\frac{x}{y}\right)}^{2} + -1\right)}{\color{blue}{\frac{x}{y} + \left(-1\right)}}}{x + 1}
\] |
metadata-eval [=>]88.6% | \[ \frac{\frac{x \cdot \left({\left(\frac{x}{y}\right)}^{2} + -1\right)}{\frac{x}{y} + \color{blue}{-1}}}{x + 1}
\] |
Simplified88.5%
[Start]88.6% | \[ \frac{\frac{x \cdot \left({\left(\frac{x}{y}\right)}^{2} + -1\right)}{\frac{x}{y} + -1}}{x + 1}
\] |
|---|---|
*-commutative [=>]88.6% | \[ \frac{\frac{\color{blue}{\left({\left(\frac{x}{y}\right)}^{2} + -1\right) \cdot x}}{\frac{x}{y} + -1}}{x + 1}
\] |
associate-/l* [=>]88.5% | \[ \frac{\color{blue}{\frac{{\left(\frac{x}{y}\right)}^{2} + -1}{\frac{\frac{x}{y} + -1}{x}}}}{x + 1}
\] |
+-commutative [=>]88.5% | \[ \frac{\frac{\color{blue}{-1 + {\left(\frac{x}{y}\right)}^{2}}}{\frac{\frac{x}{y} + -1}{x}}}{x + 1}
\] |
+-commutative [=>]88.5% | \[ \frac{\frac{-1 + {\left(\frac{x}{y}\right)}^{2}}{\frac{\color{blue}{-1 + \frac{x}{y}}}{x}}}{x + 1}
\] |
Taylor expanded in x around 0 87.8%
Simplified99.9%
[Start]87.8% | \[ \left(\frac{1}{y} - 1\right) \cdot {x}^{2} + x
\] |
|---|---|
+-commutative [=>]87.8% | \[ \color{blue}{x + \left(\frac{1}{y} - 1\right) \cdot {x}^{2}}
\] |
*-commutative [=>]87.8% | \[ x + \color{blue}{{x}^{2} \cdot \left(\frac{1}{y} - 1\right)}
\] |
sub-neg [=>]87.8% | \[ x + {x}^{2} \cdot \color{blue}{\left(\frac{1}{y} + \left(-1\right)\right)}
\] |
metadata-eval [=>]87.8% | \[ x + {x}^{2} \cdot \left(\frac{1}{y} + \color{blue}{-1}\right)
\] |
distribute-rgt-in [=>]87.8% | \[ x + \color{blue}{\left(\frac{1}{y} \cdot {x}^{2} + -1 \cdot {x}^{2}\right)}
\] |
associate-*l/ [=>]87.9% | \[ x + \left(\color{blue}{\frac{1 \cdot {x}^{2}}{y}} + -1 \cdot {x}^{2}\right)
\] |
*-lft-identity [=>]87.9% | \[ x + \left(\frac{\color{blue}{{x}^{2}}}{y} + -1 \cdot {x}^{2}\right)
\] |
unpow2 [=>]87.9% | \[ x + \left(\frac{\color{blue}{x \cdot x}}{y} + -1 \cdot {x}^{2}\right)
\] |
associate-/l* [=>]99.8% | \[ x + \left(\color{blue}{\frac{x}{\frac{y}{x}}} + -1 \cdot {x}^{2}\right)
\] |
associate-/r/ [=>]99.9% | \[ x + \left(\color{blue}{\frac{x}{y} \cdot x} + -1 \cdot {x}^{2}\right)
\] |
neg-mul-1 [<=]99.9% | \[ x + \left(\frac{x}{y} \cdot x + \color{blue}{\left(-{x}^{2}\right)}\right)
\] |
unpow2 [=>]99.9% | \[ x + \left(\frac{x}{y} \cdot x + \left(-\color{blue}{x \cdot x}\right)\right)
\] |
distribute-lft-neg-in [=>]99.9% | \[ x + \left(\frac{x}{y} \cdot x + \color{blue}{\left(-x\right) \cdot x}\right)
\] |
distribute-rgt-in [<=]99.9% | \[ x + \color{blue}{x \cdot \left(\frac{x}{y} + \left(-x\right)\right)}
\] |
unsub-neg [=>]99.9% | \[ x + x \cdot \color{blue}{\left(\frac{x}{y} - x\right)}
\] |
if 6.1999999999999998e-23 < x Initial program 99.2%
Simplified99.2%
[Start]99.2% | \[ \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\] |
|---|---|
associate-/l* [=>]99.2% | \[ \color{blue}{\frac{x}{\frac{x + 1}{\frac{x}{y} + 1}}}
\] |
Taylor expanded in y around 0 99.6%
Applied egg-rr99.6%
[Start]99.6% | \[ \frac{x}{\frac{y \cdot \left(1 + x\right)}{x}}
\] |
|---|---|
associate-/r/ [=>]99.4% | \[ \color{blue}{\frac{x}{y \cdot \left(1 + x\right)} \cdot x}
\] |
distribute-lft-in [=>]99.6% | \[ \frac{x}{\color{blue}{y \cdot 1 + y \cdot x}} \cdot x
\] |
*-rgt-identity [=>]99.6% | \[ \frac{x}{\color{blue}{y} + y \cdot x} \cdot x
\] |
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 840 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 841 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 841 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 841 |
| Alternative 5 | |
|---|---|
| Accuracy | 70.6% |
| Cost | 713 |
| Alternative 6 | |
|---|---|
| Accuracy | 96.9% |
| Cost | 713 |
| Alternative 7 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 713 |
| Alternative 8 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 704 |
| Alternative 9 | |
|---|---|
| Accuracy | 70.7% |
| Cost | 585 |
| Alternative 10 | |
|---|---|
| Accuracy | 52.8% |
| Cost | 584 |
| Alternative 11 | |
|---|---|
| Accuracy | 52.8% |
| Cost | 456 |
| Alternative 12 | |
|---|---|
| Accuracy | 3.7% |
| Cost | 64 |
| Alternative 13 | |
|---|---|
| Accuracy | 50.3% |
| Cost | 64 |
herbie shell --seed 2023277
(FPCore (x y)
:name "Codec.Picture.Types:toneMapping from JuicyPixels-3.2.6.1"
:precision binary64
:herbie-target
(* (/ x 1.0) (/ (+ (/ x y) 1.0) (+ x 1.0)))
(/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))