
(FPCore (x) :precision binary64 (- (* x 116.0) 16.0))
double code(double x) {
return (x * 116.0) - 16.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * 116.0d0) - 16.0d0
end function
public static double code(double x) {
return (x * 116.0) - 16.0;
}
def code(x): return (x * 116.0) - 16.0
function code(x) return Float64(Float64(x * 116.0) - 16.0) end
function tmp = code(x) tmp = (x * 116.0) - 16.0; end
code[x_] := N[(N[(x * 116.0), $MachinePrecision] - 16.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 116 - 16
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (* x 116.0) 16.0))
double code(double x) {
return (x * 116.0) - 16.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * 116.0d0) - 16.0d0
end function
public static double code(double x) {
return (x * 116.0) - 16.0;
}
def code(x): return (x * 116.0) - 16.0
function code(x) return Float64(Float64(x * 116.0) - 16.0) end
function tmp = code(x) tmp = (x * 116.0) - 16.0; end
code[x_] := N[(N[(x * 116.0), $MachinePrecision] - 16.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 116 - 16
\end{array}
(FPCore (x) :precision binary64 (fma 116.0 x -16.0))
double code(double x) {
return fma(116.0, x, -16.0);
}
function code(x) return fma(116.0, x, -16.0) end
code[x_] := N[(116.0 * x + -16.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(116, x, -16\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lft-mult-inverseN/A
fp-cancel-sign-sub-invN/A
lft-mult-inverseN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-eval100.0
Applied rewrites100.0%
(FPCore (x) :precision binary64 (if (or (<= (* x 116.0) -5e+15) (not (<= (* x 116.0) 5e-6))) (* 116.0 x) -16.0))
double code(double x) {
double tmp;
if (((x * 116.0) <= -5e+15) || !((x * 116.0) <= 5e-6)) {
tmp = 116.0 * x;
} else {
tmp = -16.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((x * 116.0d0) <= (-5d+15)) .or. (.not. ((x * 116.0d0) <= 5d-6))) then
tmp = 116.0d0 * x
else
tmp = -16.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((x * 116.0) <= -5e+15) || !((x * 116.0) <= 5e-6)) {
tmp = 116.0 * x;
} else {
tmp = -16.0;
}
return tmp;
}
def code(x): tmp = 0 if ((x * 116.0) <= -5e+15) or not ((x * 116.0) <= 5e-6): tmp = 116.0 * x else: tmp = -16.0 return tmp
function code(x) tmp = 0.0 if ((Float64(x * 116.0) <= -5e+15) || !(Float64(x * 116.0) <= 5e-6)) tmp = Float64(116.0 * x); else tmp = -16.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((x * 116.0) <= -5e+15) || ~(((x * 116.0) <= 5e-6))) tmp = 116.0 * x; else tmp = -16.0; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[N[(x * 116.0), $MachinePrecision], -5e+15], N[Not[LessEqual[N[(x * 116.0), $MachinePrecision], 5e-6]], $MachinePrecision]], N[(116.0 * x), $MachinePrecision], -16.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot 116 \leq -5 \cdot 10^{+15} \lor \neg \left(x \cdot 116 \leq 5 \cdot 10^{-6}\right):\\
\;\;\;\;116 \cdot x\\
\mathbf{else}:\\
\;\;\;\;-16\\
\end{array}
\end{array}
if (*.f64 x #s(literal 116 binary64)) < -5e15 or 5.00000000000000041e-6 < (*.f64 x #s(literal 116 binary64)) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites3.0%
Taylor expanded in x around inf
lower-*.f6499.2
Applied rewrites99.2%
if -5e15 < (*.f64 x #s(literal 116 binary64)) < 5.00000000000000041e-6Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites97.6%
Final simplification98.4%
(FPCore (x) :precision binary64 -16.0)
double code(double x) {
return -16.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = -16.0d0
end function
public static double code(double x) {
return -16.0;
}
def code(x): return -16.0
function code(x) return -16.0 end
function tmp = code(x) tmp = -16.0; end
code[x_] := -16.0
\begin{array}{l}
\\
-16
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites49.2%
herbie shell --seed 2024320
(FPCore (x)
:name "Data.Colour.CIE:lightness from colour-2.3.3"
:precision binary64
(- (* x 116.0) 16.0))