
(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 7 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%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (+ x y) (+ y 1.0))) (t_1 (/ x (- y -1.0))))
(if (<= t_0 -4e+16)
t_1
(if (<= t_0 0.02) (fma 1.0 y x) (if (<= t_0 4.0) (/ y (- y -1.0)) t_1)))))
double code(double x, double y) {
double t_0 = (x + y) / (y + 1.0);
double t_1 = x / (y - -1.0);
double tmp;
if (t_0 <= -4e+16) {
tmp = t_1;
} else if (t_0 <= 0.02) {
tmp = fma(1.0, y, x);
} else if (t_0 <= 4.0) {
tmp = y / (y - -1.0);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x + y) / Float64(y + 1.0)) t_1 = Float64(x / Float64(y - -1.0)) tmp = 0.0 if (t_0 <= -4e+16) tmp = t_1; elseif (t_0 <= 0.02) tmp = fma(1.0, y, x); elseif (t_0 <= 4.0) tmp = Float64(y / Float64(y - -1.0)); else tmp = t_1; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x / N[(y - -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -4e+16], t$95$1, If[LessEqual[t$95$0, 0.02], N[(1.0 * y + x), $MachinePrecision], If[LessEqual[t$95$0, 4.0], N[(y / N[(y - -1.0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x + y}{y + 1}\\
t_1 := \frac{x}{y - -1}\\
\mathbf{if}\;t\_0 \leq -4 \cdot 10^{+16}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 0.02:\\
\;\;\;\;\mathsf{fma}\left(1, y, x\right)\\
\mathbf{elif}\;t\_0 \leq 4:\\
\;\;\;\;\frac{y}{y - -1}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (+.f64 x y) (+.f64 y #s(literal 1 binary64))) < -4e16 or 4 < (/.f64 (+.f64 x y) (+.f64 y #s(literal 1 binary64))) Initial program 100.0%
Taylor expanded in x around inf
lower-/.f64N/A
+-commutativeN/A
rgt-mult-inverseN/A
cancel-sign-subN/A
distribute-lft-neg-outN/A
rgt-mult-inverseN/A
metadata-evalN/A
lower--.f6498.7
Applied rewrites98.7%
if -4e16 < (/.f64 (+.f64 x y) (+.f64 y #s(literal 1 binary64))) < 0.0200000000000000004Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-fma.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites99.9%
if 0.0200000000000000004 < (/.f64 (+.f64 x y) (+.f64 y #s(literal 1 binary64))) < 4Initial program 100.0%
Taylor expanded in x around 0
lower-/.f64N/A
+-commutativeN/A
rgt-mult-inverseN/A
cancel-sign-subN/A
distribute-lft-neg-outN/A
rgt-mult-inverseN/A
metadata-evalN/A
lower--.f64100.0
Applied rewrites100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (+ x y) (+ y 1.0))))
(if (or (<= t_0 -4e+16) (not (<= t_0 0.9999999999977595)))
(/ x (- y -1.0))
(fma 1.0 y x))))
double code(double x, double y) {
double t_0 = (x + y) / (y + 1.0);
double tmp;
if ((t_0 <= -4e+16) || !(t_0 <= 0.9999999999977595)) {
tmp = x / (y - -1.0);
} else {
tmp = fma(1.0, y, x);
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x + y) / Float64(y + 1.0)) tmp = 0.0 if ((t_0 <= -4e+16) || !(t_0 <= 0.9999999999977595)) tmp = Float64(x / Float64(y - -1.0)); else tmp = fma(1.0, y, x); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -4e+16], N[Not[LessEqual[t$95$0, 0.9999999999977595]], $MachinePrecision]], N[(x / N[(y - -1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x + y}{y + 1}\\
\mathbf{if}\;t\_0 \leq -4 \cdot 10^{+16} \lor \neg \left(t\_0 \leq 0.9999999999977595\right):\\
\;\;\;\;\frac{x}{y - -1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, y, x\right)\\
\end{array}
\end{array}
if (/.f64 (+.f64 x y) (+.f64 y #s(literal 1 binary64))) < -4e16 or 0.999999999997759459 < (/.f64 (+.f64 x y) (+.f64 y #s(literal 1 binary64))) Initial program 100.0%
Taylor expanded in x around inf
lower-/.f64N/A
+-commutativeN/A
rgt-mult-inverseN/A
cancel-sign-subN/A
distribute-lft-neg-outN/A
rgt-mult-inverseN/A
metadata-evalN/A
lower--.f6458.5
Applied rewrites58.5%
if -4e16 < (/.f64 (+.f64 x y) (+.f64 y #s(literal 1 binary64))) < 0.999999999997759459Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-fma.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6498.7
Applied rewrites98.7%
Taylor expanded in x around 0
Applied rewrites98.7%
Final simplification69.7%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (/ x y) (fma (- 1.0 x) y x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = x / y;
} else {
tmp = fma((1.0 - x), y, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(x / y); else tmp = fma(Float64(1.0 - x), y, x); end return tmp end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(x / y), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1 - x, y, x\right)\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in x around inf
lower-/.f64N/A
+-commutativeN/A
rgt-mult-inverseN/A
cancel-sign-subN/A
distribute-lft-neg-outN/A
rgt-mult-inverseN/A
metadata-evalN/A
lower--.f6431.3
Applied rewrites31.3%
Taylor expanded in y around inf
Applied rewrites29.5%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-fma.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6499.6
Applied rewrites99.6%
Final simplification68.7%
(FPCore (x y) :precision binary64 (if (or (<= x -1.55e-134) (not (<= x 1.15e-239))) (* 1.0 x) (* 1.0 y)))
double code(double x, double y) {
double tmp;
if ((x <= -1.55e-134) || !(x <= 1.15e-239)) {
tmp = 1.0 * x;
} else {
tmp = 1.0 * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-1.55d-134)) .or. (.not. (x <= 1.15d-239))) then
tmp = 1.0d0 * x
else
tmp = 1.0d0 * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.55e-134) || !(x <= 1.15e-239)) {
tmp = 1.0 * x;
} else {
tmp = 1.0 * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.55e-134) or not (x <= 1.15e-239): tmp = 1.0 * x else: tmp = 1.0 * y return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.55e-134) || !(x <= 1.15e-239)) tmp = Float64(1.0 * x); else tmp = Float64(1.0 * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.55e-134) || ~((x <= 1.15e-239))) tmp = 1.0 * x; else tmp = 1.0 * y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.55e-134], N[Not[LessEqual[x, 1.15e-239]], $MachinePrecision]], N[(1.0 * x), $MachinePrecision], N[(1.0 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55 \cdot 10^{-134} \lor \neg \left(x \leq 1.15 \cdot 10^{-239}\right):\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot y\\
\end{array}
\end{array}
if x < -1.55000000000000003e-134 or 1.1499999999999999e-239 < x Initial program 100.0%
Taylor expanded in x around inf
lower-/.f64N/A
+-commutativeN/A
rgt-mult-inverseN/A
cancel-sign-subN/A
distribute-lft-neg-outN/A
rgt-mult-inverseN/A
metadata-evalN/A
lower--.f6469.2
Applied rewrites69.2%
Taylor expanded in y around 0
Applied rewrites53.4%
Taylor expanded in y around inf
Applied rewrites2.9%
Taylor expanded in y around 0
Applied rewrites53.8%
if -1.55000000000000003e-134 < x < 1.1499999999999999e-239Initial program 100.0%
Taylor expanded in x around 0
lower-/.f64N/A
+-commutativeN/A
rgt-mult-inverseN/A
cancel-sign-subN/A
distribute-lft-neg-outN/A
rgt-mult-inverseN/A
metadata-evalN/A
lower--.f6489.9
Applied rewrites89.9%
Taylor expanded in y around 0
Applied rewrites44.6%
Taylor expanded in y around inf
Applied rewrites3.4%
Taylor expanded in y around 0
Applied rewrites45.5%
Final simplification52.3%
(FPCore (x y) :precision binary64 (fma 1.0 y x))
double code(double x, double y) {
return fma(1.0, y, x);
}
function code(x, y) return fma(1.0, y, x) end
code[x_, y_] := N[(1.0 * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(1, y, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-fma.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6456.6
Applied rewrites56.6%
Taylor expanded in x around 0
Applied rewrites56.7%
(FPCore (x y) :precision binary64 (* 1.0 x))
double code(double x, double y) {
return 1.0 * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 * x
end function
public static double code(double x, double y) {
return 1.0 * x;
}
def code(x, y): return 1.0 * x
function code(x, y) return Float64(1.0 * x) end
function tmp = code(x, y) tmp = 1.0 * x; end
code[x_, y_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot x
\end{array}
Initial program 100.0%
Taylor expanded in x around inf
lower-/.f64N/A
+-commutativeN/A
rgt-mult-inverseN/A
cancel-sign-subN/A
distribute-lft-neg-outN/A
rgt-mult-inverseN/A
metadata-evalN/A
lower--.f6459.3
Applied rewrites59.3%
Taylor expanded in y around 0
Applied rewrites46.4%
Taylor expanded in y around inf
Applied rewrites3.2%
Taylor expanded in y around 0
Applied rewrites46.7%
herbie shell --seed 2024339
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))