
(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 -1.0) (not (<= y 0.76))) (+ 1.0 (/ x y)) (* (+ x y) (- 1.0 y))))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 0.76)) {
tmp = 1.0 + (x / y);
} else {
tmp = (x + y) * (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 ((y <= (-1.0d0)) .or. (.not. (y <= 0.76d0))) then
tmp = 1.0d0 + (x / y)
else
tmp = (x + y) * (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 0.76)) {
tmp = 1.0 + (x / y);
} else {
tmp = (x + y) * (1.0 - y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 0.76): tmp = 1.0 + (x / y) else: tmp = (x + y) * (1.0 - y) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 0.76)) tmp = Float64(1.0 + Float64(x / y)); else tmp = Float64(Float64(x + y) * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 0.76))) tmp = 1.0 + (x / y); else tmp = (x + y) * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 0.76]], $MachinePrecision]], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], N[(N[(x + y), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 0.76\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\left(x + y\right) \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -1 or 0.76000000000000001 < y Initial program 100.0%
Taylor expanded in y around inf 98.3%
+-commutative98.3%
associate--l+98.3%
+-commutative98.3%
associate--r-98.3%
div-sub98.3%
Simplified98.3%
Taylor expanded in x around inf 97.9%
neg-mul-197.9%
distribute-neg-frac97.9%
Simplified97.9%
if -1 < y < 0.76000000000000001Initial program 100.0%
clear-num99.8%
associate-/r/100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 99.0%
neg-mul-199.0%
sub-neg99.0%
Simplified99.0%
Final simplification98.4%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (- 1.0 (/ (- 1.0 x) y)) (* (+ x y) (- 1.0 y))))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = 1.0 - ((1.0 - x) / y);
} else {
tmp = (x + y) * (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 ((y <= (-1.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = 1.0d0 - ((1.0d0 - x) / y)
else
tmp = (x + y) * (1.0d0 - y)
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 - ((1.0 - x) / y);
} else {
tmp = (x + y) * (1.0 - y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = 1.0 - ((1.0 - x) / y) else: tmp = (x + y) * (1.0 - y) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(1.0 - Float64(Float64(1.0 - x) / y)); else tmp = Float64(Float64(x + y) * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = 1.0 - ((1.0 - x) / y); else tmp = (x + y) * (1.0 - y); 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[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(N[(x + y), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;1 - \frac{1 - x}{y}\\
\mathbf{else}:\\
\;\;\;\;\left(x + y\right) \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 98.3%
+-commutative98.3%
associate--l+98.3%
+-commutative98.3%
associate--r-98.3%
div-sub98.3%
Simplified98.3%
if -1 < y < 1Initial program 100.0%
clear-num99.8%
associate-/r/100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 99.0%
neg-mul-199.0%
sub-neg99.0%
Simplified99.0%
Final simplification98.6%
(FPCore (x y) :precision binary64 (if (or (<= y -4.2e-11) (not (<= y 3e+27))) (/ y (+ y 1.0)) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -4.2e-11) || !(y <= 3e+27)) {
tmp = y / (y + 1.0);
} 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 <= (-4.2d-11)) .or. (.not. (y <= 3d+27))) then
tmp = y / (y + 1.0d0)
else
tmp = x / (y + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -4.2e-11) || !(y <= 3e+27)) {
tmp = y / (y + 1.0);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4.2e-11) or not (y <= 3e+27): tmp = y / (y + 1.0) else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -4.2e-11) || !(y <= 3e+27)) tmp = Float64(y / Float64(y + 1.0)); else tmp = Float64(x / Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -4.2e-11) || ~((y <= 3e+27))) tmp = y / (y + 1.0); else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4.2e-11], N[Not[LessEqual[y, 3e+27]], $MachinePrecision]], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{-11} \lor \neg \left(y \leq 3 \cdot 10^{+27}\right):\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -4.1999999999999997e-11 or 2.99999999999999976e27 < y Initial program 100.0%
Taylor expanded in x around 0 81.6%
+-commutative81.6%
Simplified81.6%
if -4.1999999999999997e-11 < y < 2.99999999999999976e27Initial program 100.0%
Taylor expanded in x around inf 75.9%
+-commutative75.9%
Simplified75.9%
Final simplification78.8%
(FPCore (x y) :precision binary64 (if (or (<= y -38000.0) (not (<= y 270000000000.0))) (+ 1.0 (/ x y)) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -38000.0) || !(y <= 270000000000.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 <= (-38000.0d0)) .or. (.not. (y <= 270000000000.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 <= -38000.0) || !(y <= 270000000000.0)) {
tmp = 1.0 + (x / y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -38000.0) or not (y <= 270000000000.0): tmp = 1.0 + (x / y) else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -38000.0) || !(y <= 270000000000.0)) tmp = Float64(1.0 + Float64(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 <= -38000.0) || ~((y <= 270000000000.0))) tmp = 1.0 + (x / y); else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -38000.0], N[Not[LessEqual[y, 270000000000.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 -38000 \lor \neg \left(y \leq 270000000000\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -38000 or 2.7e11 < y Initial program 100.0%
Taylor expanded in y around inf 99.6%
+-commutative99.6%
associate--l+99.6%
+-commutative99.6%
associate--r-99.6%
div-sub99.6%
Simplified99.6%
Taylor expanded in x around inf 99.3%
neg-mul-199.3%
distribute-neg-frac99.3%
Simplified99.3%
if -38000 < y < 2.7e11Initial program 99.9%
Taylor expanded in x around inf 75.7%
+-commutative75.7%
Simplified75.7%
Final simplification87.9%
(FPCore (x y) :precision binary64 (if (<= y -4200000000.0) 1.0 (if (<= y 6.9e+28) (/ x (+ y 1.0)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -4200000000.0) {
tmp = 1.0;
} else if (y <= 6.9e+28) {
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 <= (-4200000000.0d0)) then
tmp = 1.0d0
else if (y <= 6.9d+28) 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 <= -4200000000.0) {
tmp = 1.0;
} else if (y <= 6.9e+28) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4200000000.0: tmp = 1.0 elif y <= 6.9e+28: tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -4200000000.0) tmp = 1.0; elseif (y <= 6.9e+28) 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 <= -4200000000.0) tmp = 1.0; elseif (y <= 6.9e+28) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4200000000.0], 1.0, If[LessEqual[y, 6.9e+28], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4200000000:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 6.9 \cdot 10^{+28}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -4.2e9 or 6.9e28 < y Initial program 100.0%
Taylor expanded in y around inf 82.5%
if -4.2e9 < y < 6.9e28Initial program 100.0%
Taylor expanded in x around inf 74.6%
+-commutative74.6%
Simplified74.6%
Final simplification78.5%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 2.35) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 2.35) {
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 <= 2.35d0) 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 <= 2.35) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 2.35: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 2.35) 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 <= 2.35) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 2.35], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.35:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 2.35000000000000009 < y Initial program 100.0%
Taylor expanded in y around inf 78.9%
if -1 < y < 2.35000000000000009Initial program 100.0%
Taylor expanded in y around 0 74.4%
Final simplification76.8%
(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 43.5%
Final simplification43.5%
herbie shell --seed 2024010
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))