
(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%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= y -130000.0) (not (<= y 38000.0))) (- 1.0 (/ (- 1.0 x) y)) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -130000.0) || !(y <= 38000.0)) {
tmp = 1.0 - ((1.0 - x) / 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 <= (-130000.0d0)) .or. (.not. (y <= 38000.0d0))) then
tmp = 1.0d0 - ((1.0d0 - x) / 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 <= -130000.0) || !(y <= 38000.0)) {
tmp = 1.0 - ((1.0 - x) / y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -130000.0) or not (y <= 38000.0): tmp = 1.0 - ((1.0 - x) / y) else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -130000.0) || !(y <= 38000.0)) tmp = Float64(1.0 - Float64(Float64(1.0 - x) / y)); else tmp = Float64(x / Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -130000.0) || ~((y <= 38000.0))) tmp = 1.0 - ((1.0 - x) / y); else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -130000.0], N[Not[LessEqual[y, 38000.0]], $MachinePrecision]], N[(1.0 - N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -130000 \lor \neg \left(y \leq 38000\right):\\
\;\;\;\;1 - \frac{1 - x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -1.3e5 or 38000 < y Initial program 100.0%
Taylor expanded in y around -inf 99.3%
mul-1-neg99.3%
unsub-neg99.3%
mul-1-neg99.3%
sub-neg99.3%
Simplified99.3%
if -1.3e5 < y < 38000Initial program 100.0%
Taylor expanded in x around inf 70.4%
+-commutative70.4%
Simplified70.4%
Final simplification83.9%
(FPCore (x y) :precision binary64 (if (or (<= y -180000.0) (not (<= y 150000.0))) (- 1.0 (/ x (- y))) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -180000.0) || !(y <= 150000.0)) {
tmp = 1.0 - (x / -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 <= (-180000.0d0)) .or. (.not. (y <= 150000.0d0))) then
tmp = 1.0d0 - (x / -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 <= -180000.0) || !(y <= 150000.0)) {
tmp = 1.0 - (x / -y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -180000.0) or not (y <= 150000.0): tmp = 1.0 - (x / -y) else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -180000.0) || !(y <= 150000.0)) tmp = Float64(1.0 - Float64(x / Float64(-y))); else tmp = Float64(x / Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -180000.0) || ~((y <= 150000.0))) tmp = 1.0 - (x / -y); else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -180000.0], N[Not[LessEqual[y, 150000.0]], $MachinePrecision]], N[(1.0 - N[(x / (-y)), $MachinePrecision]), $MachinePrecision], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -180000 \lor \neg \left(y \leq 150000\right):\\
\;\;\;\;1 - \frac{x}{-y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -1.8e5 or 1.5e5 < y Initial program 100.0%
Taylor expanded in y around -inf 99.3%
mul-1-neg99.3%
unsub-neg99.3%
mul-1-neg99.3%
sub-neg99.3%
Simplified99.3%
Taylor expanded in x around inf 98.8%
metadata-eval98.8%
times-frac98.8%
*-commutative98.8%
*-rgt-identity98.8%
neg-mul-198.8%
Simplified98.8%
if -1.8e5 < y < 1.5e5Initial program 100.0%
Taylor expanded in x around inf 70.4%
+-commutative70.4%
Simplified70.4%
Final simplification83.7%
(FPCore (x y) :precision binary64 (if (or (<= x -8.8e-44) (not (<= x 5e+61))) (/ x (+ y 1.0)) (/ y (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -8.8e-44) || !(x <= 5e+61)) {
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 <= (-8.8d-44)) .or. (.not. (x <= 5d+61))) 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 <= -8.8e-44) || !(x <= 5e+61)) {
tmp = x / (y + 1.0);
} else {
tmp = y / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -8.8e-44) or not (x <= 5e+61): tmp = x / (y + 1.0) else: tmp = y / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -8.8e-44) || !(x <= 5e+61)) 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 <= -8.8e-44) || ~((x <= 5e+61))) tmp = x / (y + 1.0); else tmp = y / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -8.8e-44], N[Not[LessEqual[x, 5e+61]], $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 -8.8 \cdot 10^{-44} \lor \neg \left(x \leq 5 \cdot 10^{+61}\right):\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y + 1}\\
\end{array}
\end{array}
if x < -8.80000000000000048e-44 or 5.00000000000000018e61 < x Initial program 100.0%
Taylor expanded in x around inf 80.1%
+-commutative80.1%
Simplified80.1%
if -8.80000000000000048e-44 < x < 5.00000000000000018e61Initial program 100.0%
Taylor expanded in x around 0 75.7%
+-commutative75.7%
Simplified75.7%
Final simplification77.8%
(FPCore (x y) :precision binary64 (if (<= y -5.2e+138) 1.0 (if (<= y 4.5e+35) (/ x (+ y 1.0)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -5.2e+138) {
tmp = 1.0;
} else if (y <= 4.5e+35) {
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 <= (-5.2d+138)) then
tmp = 1.0d0
else if (y <= 4.5d+35) 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 <= -5.2e+138) {
tmp = 1.0;
} else if (y <= 4.5e+35) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -5.2e+138: tmp = 1.0 elif y <= 4.5e+35: tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -5.2e+138) tmp = 1.0; elseif (y <= 4.5e+35) 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 <= -5.2e+138) tmp = 1.0; elseif (y <= 4.5e+35) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -5.2e+138], 1.0, If[LessEqual[y, 4.5e+35], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{+138}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{+35}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -5.2000000000000002e138 or 4.4999999999999997e35 < y Initial program 100.0%
Taylor expanded in y around inf 79.5%
if -5.2000000000000002e138 < y < 4.4999999999999997e35Initial program 100.0%
Taylor expanded in x around inf 69.7%
+-commutative69.7%
Simplified69.7%
Final simplification73.2%
(FPCore (x y) :precision binary64 (if (<= y -9.2e+138) 1.0 (if (<= y -1750.0) (/ x y) (if (<= y 26000.0) x 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -9.2e+138) {
tmp = 1.0;
} else if (y <= -1750.0) {
tmp = x / y;
} else if (y <= 26000.0) {
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 <= (-9.2d+138)) then
tmp = 1.0d0
else if (y <= (-1750.0d0)) then
tmp = x / y
else if (y <= 26000.0d0) 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 <= -9.2e+138) {
tmp = 1.0;
} else if (y <= -1750.0) {
tmp = x / y;
} else if (y <= 26000.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -9.2e+138: tmp = 1.0 elif y <= -1750.0: tmp = x / y elif y <= 26000.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -9.2e+138) tmp = 1.0; elseif (y <= -1750.0) tmp = Float64(x / y); elseif (y <= 26000.0) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -9.2e+138) tmp = 1.0; elseif (y <= -1750.0) tmp = x / y; elseif (y <= 26000.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -9.2e+138], 1.0, If[LessEqual[y, -1750.0], N[(x / y), $MachinePrecision], If[LessEqual[y, 26000.0], x, 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.2 \cdot 10^{+138}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -1750:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 26000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -9.2000000000000003e138 or 26000 < y Initial program 100.0%
Taylor expanded in y around inf 75.4%
if -9.2000000000000003e138 < y < -1750Initial program 100.0%
Taylor expanded in x around inf 67.6%
+-commutative67.6%
Simplified67.6%
Taylor expanded in y around inf 62.7%
if -1750 < y < 26000Initial program 100.0%
Taylor expanded in y around 0 67.3%
Final simplification70.0%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 26000.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 26000.0) {
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 <= 26000.0d0) 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 <= 26000.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 26000.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 26000.0) 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 <= 26000.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 26000.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 26000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 26000 < y Initial program 100.0%
Taylor expanded in y around inf 66.9%
if -1 < y < 26000Initial program 100.0%
Taylor expanded in y around 0 67.8%
Final simplification67.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 34.0%
Final simplification34.0%
herbie shell --seed 2023268
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))