
(FPCore (x y) :precision binary64 (- x (/ y 200.0)))
double code(double x, double y) {
return x - (y / 200.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x - (y / 200.0d0)
end function
public static double code(double x, double y) {
return x - (y / 200.0);
}
def code(x, y): return x - (y / 200.0)
function code(x, y) return Float64(x - Float64(y / 200.0)) end
function tmp = code(x, y) tmp = x - (y / 200.0); end
code[x_, y_] := N[(x - N[(y / 200.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{y}{200}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- x (/ y 200.0)))
double code(double x, double y) {
return x - (y / 200.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x - (y / 200.0d0)
end function
public static double code(double x, double y) {
return x - (y / 200.0);
}
def code(x, y): return x - (y / 200.0)
function code(x, y) return Float64(x - Float64(y / 200.0)) end
function tmp = code(x, y) tmp = x - (y / 200.0); end
code[x_, y_] := N[(x - N[(y / 200.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{y}{200}
\end{array}
(FPCore (x y) :precision binary64 (- x (/ y 200.0)))
double code(double x, double y) {
return x - (y / 200.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x - (y / 200.0d0)
end function
public static double code(double x, double y) {
return x - (y / 200.0);
}
def code(x, y): return x - (y / 200.0)
function code(x, y) return Float64(x - Float64(y / 200.0)) end
function tmp = code(x, y) tmp = x - (y / 200.0); end
code[x_, y_] := N[(x - N[(y / 200.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{y}{200}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= x -7e+54)
x
(if (or (<= x -1.56e+18) (and (not (<= x -2.3e-30)) (<= x 7.4e-9)))
(* y -0.005)
x)))
double code(double x, double y) {
double tmp;
if (x <= -7e+54) {
tmp = x;
} else if ((x <= -1.56e+18) || (!(x <= -2.3e-30) && (x <= 7.4e-9))) {
tmp = y * -0.005;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-7d+54)) then
tmp = x
else if ((x <= (-1.56d+18)) .or. (.not. (x <= (-2.3d-30))) .and. (x <= 7.4d-9)) then
tmp = y * (-0.005d0)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -7e+54) {
tmp = x;
} else if ((x <= -1.56e+18) || (!(x <= -2.3e-30) && (x <= 7.4e-9))) {
tmp = y * -0.005;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -7e+54: tmp = x elif (x <= -1.56e+18) or (not (x <= -2.3e-30) and (x <= 7.4e-9)): tmp = y * -0.005 else: tmp = x return tmp
function code(x, y) tmp = 0.0 if (x <= -7e+54) tmp = x; elseif ((x <= -1.56e+18) || (!(x <= -2.3e-30) && (x <= 7.4e-9))) tmp = Float64(y * -0.005); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -7e+54) tmp = x; elseif ((x <= -1.56e+18) || (~((x <= -2.3e-30)) && (x <= 7.4e-9))) tmp = y * -0.005; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -7e+54], x, If[Or[LessEqual[x, -1.56e+18], And[N[Not[LessEqual[x, -2.3e-30]], $MachinePrecision], LessEqual[x, 7.4e-9]]], N[(y * -0.005), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{+54}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -1.56 \cdot 10^{+18} \lor \neg \left(x \leq -2.3 \cdot 10^{-30}\right) \land x \leq 7.4 \cdot 10^{-9}:\\
\;\;\;\;y \cdot -0.005\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -7.0000000000000002e54 or -1.56e18 < x < -2.29999999999999984e-30 or 7.4e-9 < x Initial program 100.0%
Taylor expanded in x around inf 86.8%
if -7.0000000000000002e54 < x < -1.56e18 or -2.29999999999999984e-30 < x < 7.4e-9Initial program 100.0%
Taylor expanded in x around 0 82.6%
Final simplification84.5%
(FPCore (x y) :precision binary64 0.0)
double code(double x, double y) {
return 0.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.0d0
end function
public static double code(double x, double y) {
return 0.0;
}
def code(x, y): return 0.0
function code(x, y) return 0.0 end
function tmp = code(x, y) tmp = 0.0; end
code[x_, y_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 51.3%
expm1-log1p-u31.7%
expm1-udef21.4%
sub-neg21.4%
log1p-udef21.4%
rem-exp-log41.0%
+-commutative41.0%
metadata-eval41.0%
Applied egg-rr41.0%
Simplified2.6%
Final simplification2.6%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 49.6%
Final simplification49.6%
herbie shell --seed 2024021
(FPCore (x y)
:name "Data.Colour.CIE:cieLAB from colour-2.3.3, D"
:precision binary64
(- x (/ y 200.0)))