
(FPCore (x y) :precision binary64 (* 500.0 (- x y)))
double code(double x, double y) {
return 500.0 * (x - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 500.0d0 * (x - y)
end function
public static double code(double x, double y) {
return 500.0 * (x - y);
}
def code(x, y): return 500.0 * (x - y)
function code(x, y) return Float64(500.0 * Float64(x - y)) end
function tmp = code(x, y) tmp = 500.0 * (x - y); end
code[x_, y_] := N[(500.0 * N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
500 \cdot \left(x - y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* 500.0 (- x y)))
double code(double x, double y) {
return 500.0 * (x - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 500.0d0 * (x - y)
end function
public static double code(double x, double y) {
return 500.0 * (x - y);
}
def code(x, y): return 500.0 * (x - y)
function code(x, y) return Float64(500.0 * Float64(x - y)) end
function tmp = code(x, y) tmp = 500.0 * (x - y); end
code[x_, y_] := N[(500.0 * N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
500 \cdot \left(x - y\right)
\end{array}
(FPCore (x y) :precision binary64 (fma y -500.0 (* 500.0 x)))
double code(double x, double y) {
return fma(y, -500.0, (500.0 * x));
}
function code(x, y) return fma(y, -500.0, Float64(500.0 * x)) end
code[x_, y_] := N[(y * -500.0 + N[(500.0 * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, -500, 500 \cdot x\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
*-commutative100.0%
fma-def100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (or (<= x -3.1e-52)
(and (not (<= x 3.5e-64)) (or (<= x 5.5e-22) (not (<= x 2.6e+17)))))
(* 500.0 x)
(* y -500.0)))
double code(double x, double y) {
double tmp;
if ((x <= -3.1e-52) || (!(x <= 3.5e-64) && ((x <= 5.5e-22) || !(x <= 2.6e+17)))) {
tmp = 500.0 * x;
} else {
tmp = y * -500.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-3.1d-52)) .or. (.not. (x <= 3.5d-64)) .and. (x <= 5.5d-22) .or. (.not. (x <= 2.6d+17))) then
tmp = 500.0d0 * x
else
tmp = y * (-500.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -3.1e-52) || (!(x <= 3.5e-64) && ((x <= 5.5e-22) || !(x <= 2.6e+17)))) {
tmp = 500.0 * x;
} else {
tmp = y * -500.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -3.1e-52) or (not (x <= 3.5e-64) and ((x <= 5.5e-22) or not (x <= 2.6e+17))): tmp = 500.0 * x else: tmp = y * -500.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -3.1e-52) || (!(x <= 3.5e-64) && ((x <= 5.5e-22) || !(x <= 2.6e+17)))) tmp = Float64(500.0 * x); else tmp = Float64(y * -500.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -3.1e-52) || (~((x <= 3.5e-64)) && ((x <= 5.5e-22) || ~((x <= 2.6e+17))))) tmp = 500.0 * x; else tmp = y * -500.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -3.1e-52], And[N[Not[LessEqual[x, 3.5e-64]], $MachinePrecision], Or[LessEqual[x, 5.5e-22], N[Not[LessEqual[x, 2.6e+17]], $MachinePrecision]]]], N[(500.0 * x), $MachinePrecision], N[(y * -500.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{-52} \lor \neg \left(x \leq 3.5 \cdot 10^{-64}\right) \land \left(x \leq 5.5 \cdot 10^{-22} \lor \neg \left(x \leq 2.6 \cdot 10^{+17}\right)\right):\\
\;\;\;\;500 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot -500\\
\end{array}
\end{array}
if x < -3.0999999999999999e-52 or 3.5000000000000003e-64 < x < 5.5000000000000001e-22 or 2.6e17 < x Initial program 99.9%
Taylor expanded in x around inf 76.5%
if -3.0999999999999999e-52 < x < 3.5000000000000003e-64 or 5.5000000000000001e-22 < x < 2.6e17Initial program 100.0%
Taylor expanded in x around 0 83.6%
Final simplification79.9%
(FPCore (x y) :precision binary64 (+ (* 500.0 x) (* y -500.0)))
double code(double x, double y) {
return (500.0 * x) + (y * -500.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (500.0d0 * x) + (y * (-500.0d0))
end function
public static double code(double x, double y) {
return (500.0 * x) + (y * -500.0);
}
def code(x, y): return (500.0 * x) + (y * -500.0)
function code(x, y) return Float64(Float64(500.0 * x) + Float64(y * -500.0)) end
function tmp = code(x, y) tmp = (500.0 * x) + (y * -500.0); end
code[x_, y_] := N[(N[(500.0 * x), $MachinePrecision] + N[(y * -500.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
500 \cdot x + y \cdot -500
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (* 500.0 (- x y)))
double code(double x, double y) {
return 500.0 * (x - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 500.0d0 * (x - y)
end function
public static double code(double x, double y) {
return 500.0 * (x - y);
}
def code(x, y): return 500.0 * (x - y)
function code(x, y) return Float64(500.0 * Float64(x - y)) end
function tmp = code(x, y) tmp = 500.0 * (x - y); end
code[x_, y_] := N[(500.0 * N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
500 \cdot \left(x - y\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (* y -500.0))
double code(double x, double y) {
return y * -500.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * (-500.0d0)
end function
public static double code(double x, double y) {
return y * -500.0;
}
def code(x, y): return y * -500.0
function code(x, y) return Float64(y * -500.0) end
function tmp = code(x, y) tmp = y * -500.0; end
code[x_, y_] := N[(y * -500.0), $MachinePrecision]
\begin{array}{l}
\\
y \cdot -500
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 52.6%
Final simplification52.6%
herbie shell --seed 2023221
(FPCore (x y)
:name "Data.Colour.CIE:cieLABView from colour-2.3.3, B"
:precision binary64
(* 500.0 (- x y)))