
(FPCore (x y) :precision binary64 (* 200.0 (- x y)))
double code(double x, double y) {
return 200.0 * (x - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 200.0d0 * (x - y)
end function
public static double code(double x, double y) {
return 200.0 * (x - y);
}
def code(x, y): return 200.0 * (x - y)
function code(x, y) return Float64(200.0 * Float64(x - y)) end
function tmp = code(x, y) tmp = 200.0 * (x - y); end
code[x_, y_] := N[(200.0 * N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
200 \cdot \left(x - y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* 200.0 (- x y)))
double code(double x, double y) {
return 200.0 * (x - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 200.0d0 * (x - y)
end function
public static double code(double x, double y) {
return 200.0 * (x - y);
}
def code(x, y): return 200.0 * (x - y)
function code(x, y) return Float64(200.0 * Float64(x - y)) end
function tmp = code(x, y) tmp = 200.0 * (x - y); end
code[x_, y_] := N[(200.0 * N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
200 \cdot \left(x - y\right)
\end{array}
(FPCore (x y) :precision binary64 (fma -200.0 y (* x 200.0)))
double code(double x, double y) {
return fma(-200.0, y, (x * 200.0));
}
function code(x, y) return fma(-200.0, y, Float64(x * 200.0)) end
code[x_, y_] := N[(-200.0 * y + N[(x * 200.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-200, y, x \cdot 200\right)
\end{array}
Initial program 100.0%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
neg-mul-1N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
metadata-evalN/A
lower-*.f64100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (if (or (<= x -8.8e-47) (not (<= x 2.6e-34))) (* 200.0 x) (* -200.0 y)))
double code(double x, double y) {
double tmp;
if ((x <= -8.8e-47) || !(x <= 2.6e-34)) {
tmp = 200.0 * x;
} else {
tmp = -200.0 * y;
}
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-47)) .or. (.not. (x <= 2.6d-34))) then
tmp = 200.0d0 * x
else
tmp = (-200.0d0) * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -8.8e-47) || !(x <= 2.6e-34)) {
tmp = 200.0 * x;
} else {
tmp = -200.0 * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -8.8e-47) or not (x <= 2.6e-34): tmp = 200.0 * x else: tmp = -200.0 * y return tmp
function code(x, y) tmp = 0.0 if ((x <= -8.8e-47) || !(x <= 2.6e-34)) tmp = Float64(200.0 * x); else tmp = Float64(-200.0 * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -8.8e-47) || ~((x <= 2.6e-34))) tmp = 200.0 * x; else tmp = -200.0 * y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -8.8e-47], N[Not[LessEqual[x, 2.6e-34]], $MachinePrecision]], N[(200.0 * x), $MachinePrecision], N[(-200.0 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.8 \cdot 10^{-47} \lor \neg \left(x \leq 2.6 \cdot 10^{-34}\right):\\
\;\;\;\;200 \cdot x\\
\mathbf{else}:\\
\;\;\;\;-200 \cdot y\\
\end{array}
\end{array}
if x < -8.80000000000000075e-47 or 2.5999999999999999e-34 < x Initial program 100.0%
Taylor expanded in x around inf
lower-*.f6479.2
Applied rewrites79.2%
if -8.80000000000000075e-47 < x < 2.5999999999999999e-34Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6484.7
Applied rewrites84.7%
Final simplification81.7%
(FPCore (x y) :precision binary64 (* 200.0 (- x y)))
double code(double x, double y) {
return 200.0 * (x - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 200.0d0 * (x - y)
end function
public static double code(double x, double y) {
return 200.0 * (x - y);
}
def code(x, y): return 200.0 * (x - y)
function code(x, y) return Float64(200.0 * Float64(x - y)) end
function tmp = code(x, y) tmp = 200.0 * (x - y); end
code[x_, y_] := N[(200.0 * N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
200 \cdot \left(x - y\right)
\end{array}
Initial program 100.0%
(FPCore (x y) :precision binary64 (* -200.0 y))
double code(double x, double y) {
return -200.0 * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (-200.0d0) * y
end function
public static double code(double x, double y) {
return -200.0 * y;
}
def code(x, y): return -200.0 * y
function code(x, y) return Float64(-200.0 * y) end
function tmp = code(x, y) tmp = -200.0 * y; end
code[x_, y_] := N[(-200.0 * y), $MachinePrecision]
\begin{array}{l}
\\
-200 \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6449.9
Applied rewrites49.9%
herbie shell --seed 2024313
(FPCore (x y)
:name "Data.Colour.CIE:cieLABView from colour-2.3.3, C"
:precision binary64
(* 200.0 (- x y)))