
(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 8 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 (+ 1.0 (/ (+ x -1.0) y))))
(if (<= y -1.0)
t_0
(if (<= y 2.65e-45)
(* x (- 1.0 y))
(if (<= y 1800000.0) (/ y (+ y 1.0)) t_0)))))
double code(double x, double y) {
double t_0 = 1.0 + ((x + -1.0) / y);
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 2.65e-45) {
tmp = x * (1.0 - y);
} else if (y <= 1800000.0) {
tmp = y / (y + 1.0);
} 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) :: tmp
t_0 = 1.0d0 + ((x + (-1.0d0)) / y)
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 2.65d-45) then
tmp = x * (1.0d0 - y)
else if (y <= 1800000.0d0) then
tmp = y / (y + 1.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 + ((x + -1.0) / y);
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 2.65e-45) {
tmp = x * (1.0 - y);
} else if (y <= 1800000.0) {
tmp = y / (y + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 + ((x + -1.0) / y) tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 2.65e-45: tmp = x * (1.0 - y) elif y <= 1800000.0: tmp = y / (y + 1.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(Float64(x + -1.0) / y)) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 2.65e-45) tmp = Float64(x * Float64(1.0 - y)); elseif (y <= 1800000.0) tmp = Float64(y / Float64(y + 1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + ((x + -1.0) / y); tmp = 0.0; if (y <= -1.0) tmp = t_0; elseif (y <= 2.65e-45) tmp = x * (1.0 - y); elseif (y <= 1800000.0) tmp = y / (y + 1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 2.65e-45], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1800000.0], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{x + -1}{y}\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{-45}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{elif}\;y \leq 1800000:\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 1.8e6 < y Initial program 99.9%
Taylor expanded in y around inf 99.0%
associate--l+99.0%
div-sub99.0%
sub-neg99.0%
metadata-eval99.0%
Simplified99.0%
if -1 < y < 2.6499999999999999e-45Initial program 100.0%
Taylor expanded in x around inf 81.5%
+-commutative81.5%
Simplified81.5%
Taylor expanded in y around 0 81.5%
+-commutative81.5%
mul-1-neg81.5%
remove-double-neg81.5%
distribute-neg-out81.5%
neg-mul-181.5%
*-commutative81.5%
distribute-lft-in81.5%
distribute-rgt-neg-in81.5%
sub0-neg81.5%
metadata-eval81.5%
sub-neg81.5%
associate-+l-81.5%
neg-sub081.5%
+-commutative81.5%
unsub-neg81.5%
Simplified81.5%
if 2.6499999999999999e-45 < y < 1.8e6Initial program 100.0%
Taylor expanded in x around 0 75.9%
+-commutative75.9%
Simplified75.9%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (+ 1.0 (/ (+ x -1.0) y)) (+ x (* y (- 1.0 x)))))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = 1.0 + ((x + -1.0) / y);
} else {
tmp = x + (y * (1.0 - x));
}
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)) .or. (.not. (y <= 1.0d0))) then
tmp = 1.0d0 + ((x + (-1.0d0)) / y)
else
tmp = x + (y * (1.0d0 - x))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = 1.0 + ((x + -1.0) / y);
} else {
tmp = x + (y * (1.0 - x));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = 1.0 + ((x + -1.0) / y) else: tmp = x + (y * (1.0 - x)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(1.0 + Float64(Float64(x + -1.0) / y)); else tmp = Float64(x + Float64(y * Float64(1.0 - x))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = 1.0 + ((x + -1.0) / y); else tmp = x + (y * (1.0 - x)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;1 + \frac{x + -1}{y}\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 99.9%
Taylor expanded in y around inf 98.5%
associate--l+98.5%
div-sub98.5%
sub-neg98.5%
metadata-eval98.5%
Simplified98.5%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0 99.2%
Final simplification98.8%
(FPCore (x y) :precision binary64 (if (or (<= x -9e+15) (not (<= x 1.06e+37))) (/ x (+ y 1.0)) (/ y (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -9e+15) || !(x <= 1.06e+37)) {
tmp = x / (y + 1.0);
} else {
tmp = y / (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 ((x <= (-9d+15)) .or. (.not. (x <= 1.06d+37))) then
tmp = x / (y + 1.0d0)
else
tmp = y / (y + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -9e+15) || !(x <= 1.06e+37)) {
tmp = x / (y + 1.0);
} else {
tmp = y / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -9e+15) or not (x <= 1.06e+37): tmp = x / (y + 1.0) else: tmp = y / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -9e+15) || !(x <= 1.06e+37)) tmp = Float64(x / Float64(y + 1.0)); else tmp = Float64(y / Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -9e+15) || ~((x <= 1.06e+37))) tmp = x / (y + 1.0); else tmp = y / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -9e+15], N[Not[LessEqual[x, 1.06e+37]], $MachinePrecision]], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{+15} \lor \neg \left(x \leq 1.06 \cdot 10^{+37}\right):\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y + 1}\\
\end{array}
\end{array}
if x < -9e15 or 1.06e37 < x Initial program 99.9%
Taylor expanded in x around inf 79.4%
+-commutative79.4%
Simplified79.4%
if -9e15 < x < 1.06e37Initial program 100.0%
Taylor expanded in x around 0 78.0%
+-commutative78.0%
Simplified78.0%
Final simplification78.6%
(FPCore (x y) :precision binary64 (if (<= y -3.4e+50) 1.0 (if (<= y 0.0016) (/ x (+ y 1.0)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -3.4e+50) {
tmp = 1.0;
} else if (y <= 0.0016) {
tmp = x / (y + 1.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) :: tmp
if (y <= (-3.4d+50)) then
tmp = 1.0d0
else if (y <= 0.0016d0) then
tmp = x / (y + 1.0d0)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3.4e+50) {
tmp = 1.0;
} else if (y <= 0.0016) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.4e+50: tmp = 1.0 elif y <= 0.0016: tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -3.4e+50) tmp = 1.0; elseif (y <= 0.0016) tmp = Float64(x / Float64(y + 1.0)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.4e+50) tmp = 1.0; elseif (y <= 0.0016) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.4e+50], 1.0, If[LessEqual[y, 0.0016], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{+50}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 0.0016:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.3999999999999998e50 or 0.00160000000000000008 < y Initial program 99.9%
Taylor expanded in y around inf 77.8%
if -3.3999999999999998e50 < y < 0.00160000000000000008Initial program 100.0%
Taylor expanded in x around inf 74.1%
+-commutative74.1%
Simplified74.1%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 0.0016) (* x (- 1.0 y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 0.0016) {
tmp = x * (1.0 - y);
} 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.0016d0) then
tmp = x * (1.0d0 - y)
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.0016) {
tmp = x * (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 0.0016: tmp = x * (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 0.0016) tmp = Float64(x * Float64(1.0 - y)); 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.0016) tmp = x * (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 0.0016], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 0.0016:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 0.00160000000000000008 < y Initial program 99.9%
Taylor expanded in y around inf 73.2%
if -1 < y < 0.00160000000000000008Initial program 100.0%
Taylor expanded in x around inf 78.0%
+-commutative78.0%
Simplified78.0%
Taylor expanded in y around 0 78.0%
+-commutative78.0%
mul-1-neg78.0%
remove-double-neg78.0%
distribute-neg-out78.0%
neg-mul-178.0%
*-commutative78.0%
distribute-lft-in78.0%
distribute-rgt-neg-in78.0%
sub0-neg78.0%
metadata-eval78.0%
sub-neg78.0%
associate-+l-78.0%
neg-sub078.0%
+-commutative78.0%
unsub-neg78.0%
Simplified78.0%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 0.0016) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 0.0016) {
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.0016d0) 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.0016) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 0.0016: 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.0016) 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.0016) 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.0016], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 0.0016:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 0.00160000000000000008 < y Initial program 99.9%
Taylor expanded in y around inf 73.2%
if -1 < y < 0.00160000000000000008Initial program 100.0%
Taylor expanded in y around 0 77.3%
(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 42.0%
herbie shell --seed 2024170
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))