
(FPCore (x y) :precision binary64 (/ (+ x y) (+ y 1.0)))
double code(double x, double y) {
return (x + y) / (y + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / (y + 1.0d0)
end function
public static double code(double x, double y) {
return (x + y) / (y + 1.0);
}
def code(x, y): return (x + y) / (y + 1.0)
function code(x, y) return Float64(Float64(x + y) / Float64(y + 1.0)) end
function tmp = code(x, y) tmp = (x + y) / (y + 1.0); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{y + 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (+ x y) (+ y 1.0)))
double code(double x, double y) {
return (x + y) / (y + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / (y + 1.0d0)
end function
public static double code(double x, double y) {
return (x + y) / (y + 1.0);
}
def code(x, y): return (x + y) / (y + 1.0)
function code(x, y) return Float64(Float64(x + y) / Float64(y + 1.0)) end
function tmp = code(x, y) tmp = (x + y) / (y + 1.0); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{y + 1}
\end{array}
(FPCore (x y) :precision binary64 (/ (+ x y) (+ y 1.0)))
double code(double x, double y) {
return (x + y) / (y + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / (y + 1.0d0)
end function
public static double code(double x, double y) {
return (x + y) / (y + 1.0);
}
def code(x, y): return (x + y) / (y + 1.0)
function code(x, y) return Float64(Float64(x + y) / Float64(y + 1.0)) end
function tmp = code(x, y) tmp = (x + y) / (y + 1.0); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{y + 1}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ x (+ y 1.0))))
(if (<= y -95.0)
1.0
(if (<= y -7.4e-33)
t_0
(if (<= y -1.15e-125) (* x (/ y x)) (if (<= y 1.65e+112) t_0 1.0))))))
double code(double x, double y) {
double t_0 = x / (y + 1.0);
double tmp;
if (y <= -95.0) {
tmp = 1.0;
} else if (y <= -7.4e-33) {
tmp = t_0;
} else if (y <= -1.15e-125) {
tmp = x * (y / x);
} else if (y <= 1.65e+112) {
tmp = t_0;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = x / (y + 1.0d0)
if (y <= (-95.0d0)) then
tmp = 1.0d0
else if (y <= (-7.4d-33)) then
tmp = t_0
else if (y <= (-1.15d-125)) then
tmp = x * (y / x)
else if (y <= 1.65d+112) then
tmp = t_0
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x / (y + 1.0);
double tmp;
if (y <= -95.0) {
tmp = 1.0;
} else if (y <= -7.4e-33) {
tmp = t_0;
} else if (y <= -1.15e-125) {
tmp = x * (y / x);
} else if (y <= 1.65e+112) {
tmp = t_0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): t_0 = x / (y + 1.0) tmp = 0 if y <= -95.0: tmp = 1.0 elif y <= -7.4e-33: tmp = t_0 elif y <= -1.15e-125: tmp = x * (y / x) elif y <= 1.65e+112: tmp = t_0 else: tmp = 1.0 return tmp
function code(x, y) t_0 = Float64(x / Float64(y + 1.0)) tmp = 0.0 if (y <= -95.0) tmp = 1.0; elseif (y <= -7.4e-33) tmp = t_0; elseif (y <= -1.15e-125) tmp = Float64(x * Float64(y / x)); elseif (y <= 1.65e+112) tmp = t_0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) t_0 = x / (y + 1.0); tmp = 0.0; if (y <= -95.0) tmp = 1.0; elseif (y <= -7.4e-33) tmp = t_0; elseif (y <= -1.15e-125) tmp = x * (y / x); elseif (y <= 1.65e+112) tmp = t_0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -95.0], 1.0, If[LessEqual[y, -7.4e-33], t$95$0, If[LessEqual[y, -1.15e-125], N[(x * N[(y / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.65e+112], t$95$0, 1.0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{y + 1}\\
\mathbf{if}\;y \leq -95:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -7.4 \cdot 10^{-33}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.15 \cdot 10^{-125}:\\
\;\;\;\;x \cdot \frac{y}{x}\\
\mathbf{elif}\;y \leq 1.65 \cdot 10^{+112}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -95 or 1.64999999999999995e112 < y Initial program 100.0%
Taylor expanded in y around inf 72.8%
if -95 < y < -7.40000000000000028e-33 or -1.15e-125 < y < 1.64999999999999995e112Initial program 100.0%
Taylor expanded in x around inf 81.4%
+-commutative81.4%
Simplified81.4%
if -7.40000000000000028e-33 < y < -1.15e-125Initial program 100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in x around 0 64.5%
associate-/r*64.5%
+-commutative64.5%
Simplified64.5%
Taylor expanded in y around 0 64.5%
Final simplification76.5%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ x (+ y 1.0))) (t_1 (/ y (+ y 1.0))))
(if (<= x -4.6e-9)
t_0
(if (<= x 6e-107)
t_1
(if (<= x 7.8e-44) x (if (<= x 6.2e+63) t_1 t_0))))))
double code(double x, double y) {
double t_0 = x / (y + 1.0);
double t_1 = y / (y + 1.0);
double tmp;
if (x <= -4.6e-9) {
tmp = t_0;
} else if (x <= 6e-107) {
tmp = t_1;
} else if (x <= 7.8e-44) {
tmp = x;
} else if (x <= 6.2e+63) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x / (y + 1.0d0)
t_1 = y / (y + 1.0d0)
if (x <= (-4.6d-9)) then
tmp = t_0
else if (x <= 6d-107) then
tmp = t_1
else if (x <= 7.8d-44) then
tmp = x
else if (x <= 6.2d+63) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x / (y + 1.0);
double t_1 = y / (y + 1.0);
double tmp;
if (x <= -4.6e-9) {
tmp = t_0;
} else if (x <= 6e-107) {
tmp = t_1;
} else if (x <= 7.8e-44) {
tmp = x;
} else if (x <= 6.2e+63) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x / (y + 1.0) t_1 = y / (y + 1.0) tmp = 0 if x <= -4.6e-9: tmp = t_0 elif x <= 6e-107: tmp = t_1 elif x <= 7.8e-44: tmp = x elif x <= 6.2e+63: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x / Float64(y + 1.0)) t_1 = Float64(y / Float64(y + 1.0)) tmp = 0.0 if (x <= -4.6e-9) tmp = t_0; elseif (x <= 6e-107) tmp = t_1; elseif (x <= 7.8e-44) tmp = x; elseif (x <= 6.2e+63) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x / (y + 1.0); t_1 = y / (y + 1.0); tmp = 0.0; if (x <= -4.6e-9) tmp = t_0; elseif (x <= 6e-107) tmp = t_1; elseif (x <= 7.8e-44) tmp = x; elseif (x <= 6.2e+63) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -4.6e-9], t$95$0, If[LessEqual[x, 6e-107], t$95$1, If[LessEqual[x, 7.8e-44], x, If[LessEqual[x, 6.2e+63], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{y + 1}\\
t_1 := \frac{y}{y + 1}\\
\mathbf{if}\;x \leq -4.6 \cdot 10^{-9}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 6 \cdot 10^{-107}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 7.8 \cdot 10^{-44}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 6.2 \cdot 10^{+63}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -4.5999999999999998e-9 or 6.2000000000000001e63 < x Initial program 100.0%
Taylor expanded in x around inf 82.6%
+-commutative82.6%
Simplified82.6%
if -4.5999999999999998e-9 < x < 5.9999999999999994e-107 or 7.8000000000000004e-44 < x < 6.2000000000000001e63Initial program 100.0%
Taylor expanded in x around 0 79.1%
+-commutative79.1%
Simplified79.1%
if 5.9999999999999994e-107 < x < 7.8000000000000004e-44Initial program 100.0%
Taylor expanded in y around 0 77.7%
Final simplification80.7%
(FPCore (x y) :precision binary64 (if (or (<= y -66.0) (not (<= y 155000.0))) (+ 1.0 (/ (+ x -1.0) y)) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -66.0) || !(y <= 155000.0)) {
tmp = 1.0 + ((x + -1.0) / y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-66.0d0)) .or. (.not. (y <= 155000.0d0))) then
tmp = 1.0d0 + ((x + (-1.0d0)) / y)
else
tmp = x / (y + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -66.0) || !(y <= 155000.0)) {
tmp = 1.0 + ((x + -1.0) / y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -66.0) or not (y <= 155000.0): tmp = 1.0 + ((x + -1.0) / y) else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -66.0) || !(y <= 155000.0)) tmp = Float64(1.0 + Float64(Float64(x + -1.0) / y)); else tmp = Float64(x / Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -66.0) || ~((y <= 155000.0))) tmp = 1.0 + ((x + -1.0) / y); else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -66.0], N[Not[LessEqual[y, 155000.0]], $MachinePrecision]], N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -66 \lor \neg \left(y \leq 155000\right):\\
\;\;\;\;1 + \frac{x + -1}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -66 or 155000 < y Initial program 100.0%
Taylor expanded in y around inf 98.9%
associate--l+98.9%
div-sub98.9%
sub-neg98.9%
metadata-eval98.9%
Simplified98.9%
if -66 < y < 155000Initial program 100.0%
Taylor expanded in x around inf 75.6%
+-commutative75.6%
Simplified75.6%
Final simplification86.9%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 0.18) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 0.18) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.0d0)) then
tmp = 1.0d0
else if (y <= 0.18d0) then
tmp = x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 0.18) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 0.18: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 0.18) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = 1.0; elseif (y <= 0.18) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 0.18], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 0.18:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 0.17999999999999999 < y Initial program 100.0%
Taylor expanded in y around inf 65.9%
if -1 < y < 0.17999999999999999Initial program 100.0%
Taylor expanded in y around 0 75.2%
Final simplification70.5%
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
return 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
Taylor expanded in y around inf 34.7%
Final simplification34.7%
herbie shell --seed 2024079
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))