| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 832 |
\[x \cdot \frac{1}{\frac{x + 1}{1 + \frac{x}{y}}}
\]
(FPCore (x y) :precision binary64 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))
(FPCore (x y)
:precision binary64
(if (<= x -1.2416205935406405e+37)
(+ 1.0 (/ x y))
(if (<= x 18765545754966.2)
(/ (+ x (* x (/ x y))) (+ x 1.0))
(+ 1.0 (/ (+ x -1.0) 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.2416205935406405e+37) {
tmp = 1.0 + (x / y);
} else if (x <= 18765545754966.2) {
tmp = (x + (x * (x / y))) / (x + 1.0);
} else {
tmp = 1.0 + ((x + -1.0) / 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.2416205935406405d+37)) then
tmp = 1.0d0 + (x / y)
else if (x <= 18765545754966.2d0) then
tmp = (x + (x * (x / y))) / (x + 1.0d0)
else
tmp = 1.0d0 + ((x + (-1.0d0)) / 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.2416205935406405e+37) {
tmp = 1.0 + (x / y);
} else if (x <= 18765545754966.2) {
tmp = (x + (x * (x / y))) / (x + 1.0);
} else {
tmp = 1.0 + ((x + -1.0) / 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.2416205935406405e+37: tmp = 1.0 + (x / y) elif x <= 18765545754966.2: tmp = (x + (x * (x / y))) / (x + 1.0) else: tmp = 1.0 + ((x + -1.0) / 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.2416205935406405e+37) tmp = Float64(1.0 + Float64(x / y)); elseif (x <= 18765545754966.2) tmp = Float64(Float64(x + Float64(x * Float64(x / y))) / Float64(x + 1.0)); else tmp = Float64(1.0 + Float64(Float64(x + -1.0) / 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.2416205935406405e+37) tmp = 1.0 + (x / y); elseif (x <= 18765545754966.2) tmp = (x + (x * (x / y))) / (x + 1.0); else tmp = 1.0 + ((x + -1.0) / 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.2416205935406405e+37], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 18765545754966.2], N[(N[(x + N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]
\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\begin{array}{l}
\mathbf{if}\;x \leq -1.2416205935406405 \cdot 10^{+37}:\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{elif}\;x \leq 18765545754966.2:\\
\;\;\;\;\frac{x + x \cdot \frac{x}{y}}{x + 1}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{x + -1}{y}\\
\end{array}
Results
| Original | 9.0 |
|---|---|
| Target | 0.1 |
| Herbie | 0.1 |
if x < -1.2416205935406405e37Initial program 24.3
Applied egg-rr0.2
Taylor expanded in x around inf 0.0
Applied egg-rr0.0
Taylor expanded in x around inf 0.0
if -1.2416205935406405e37 < x < 18765545754966.1992Initial program 0.2
Applied egg-rr0.2
if 18765545754966.1992 < x Initial program 22.7
Applied egg-rr0.2
Taylor expanded in x around inf 0.0
Applied egg-rr0.0
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 832 |
| Alternative 2 | |
|---|---|
| Error | 10.1 |
| Cost | 712 |
| Alternative 3 | |
|---|---|
| Error | 10.5 |
| Cost | 584 |
| Alternative 4 | |
|---|---|
| Error | 10.0 |
| Cost | 584 |
| Alternative 5 | |
|---|---|
| Error | 19.5 |
| Cost | 456 |
| Alternative 6 | |
|---|---|
| Error | 28.0 |
| Cost | 328 |
| Alternative 7 | |
|---|---|
| Error | 53.4 |
| Cost | 64 |

herbie shell --seed 2022301
(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)))