
(FPCore (x) :precision binary64 (/ (+ x 16.0) 116.0))
double code(double x) {
return (x + 16.0) / 116.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x + 16.0d0) / 116.0d0
end function
public static double code(double x) {
return (x + 16.0) / 116.0;
}
def code(x): return (x + 16.0) / 116.0
function code(x) return Float64(Float64(x + 16.0) / 116.0) end
function tmp = code(x) tmp = (x + 16.0) / 116.0; end
code[x_] := N[(N[(x + 16.0), $MachinePrecision] / 116.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + 16}{116}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (+ x 16.0) 116.0))
double code(double x) {
return (x + 16.0) / 116.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x + 16.0d0) / 116.0d0
end function
public static double code(double x) {
return (x + 16.0) / 116.0;
}
def code(x): return (x + 16.0) / 116.0
function code(x) return Float64(Float64(x + 16.0) / 116.0) end
function tmp = code(x) tmp = (x + 16.0) / 116.0; end
code[x_] := N[(N[(x + 16.0), $MachinePrecision] / 116.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + 16}{116}
\end{array}
(FPCore (x) :precision binary64 (/ (+ x 16.0) 116.0))
double code(double x) {
return (x + 16.0) / 116.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x + 16.0d0) / 116.0d0
end function
public static double code(double x) {
return (x + 16.0) / 116.0;
}
def code(x): return (x + 16.0) / 116.0
function code(x) return Float64(Float64(x + 16.0) / 116.0) end
function tmp = code(x) tmp = (x + 16.0) / 116.0; end
code[x_] := N[(N[(x + 16.0), $MachinePrecision] / 116.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + 16}{116}
\end{array}
Initial program 100.0%
(FPCore (x) :precision binary64 (if (or (<= (+ x 16.0) -20000.0) (not (<= (+ x 16.0) 40.0))) (* 0.008620689655172414 x) 0.13793103448275862))
double code(double x) {
double tmp;
if (((x + 16.0) <= -20000.0) || !((x + 16.0) <= 40.0)) {
tmp = 0.008620689655172414 * x;
} else {
tmp = 0.13793103448275862;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((x + 16.0d0) <= (-20000.0d0)) .or. (.not. ((x + 16.0d0) <= 40.0d0))) then
tmp = 0.008620689655172414d0 * x
else
tmp = 0.13793103448275862d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((x + 16.0) <= -20000.0) || !((x + 16.0) <= 40.0)) {
tmp = 0.008620689655172414 * x;
} else {
tmp = 0.13793103448275862;
}
return tmp;
}
def code(x): tmp = 0 if ((x + 16.0) <= -20000.0) or not ((x + 16.0) <= 40.0): tmp = 0.008620689655172414 * x else: tmp = 0.13793103448275862 return tmp
function code(x) tmp = 0.0 if ((Float64(x + 16.0) <= -20000.0) || !(Float64(x + 16.0) <= 40.0)) tmp = Float64(0.008620689655172414 * x); else tmp = 0.13793103448275862; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((x + 16.0) <= -20000.0) || ~(((x + 16.0) <= 40.0))) tmp = 0.008620689655172414 * x; else tmp = 0.13793103448275862; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[N[(x + 16.0), $MachinePrecision], -20000.0], N[Not[LessEqual[N[(x + 16.0), $MachinePrecision], 40.0]], $MachinePrecision]], N[(0.008620689655172414 * x), $MachinePrecision], 0.13793103448275862]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + 16 \leq -20000 \lor \neg \left(x + 16 \leq 40\right):\\
\;\;\;\;0.008620689655172414 \cdot x\\
\mathbf{else}:\\
\;\;\;\;0.13793103448275862\\
\end{array}
\end{array}
if (+.f64 x #s(literal 16 binary64)) < -2e4 or 40 < (+.f64 x #s(literal 16 binary64)) Initial program 100.0%
Taylor expanded in x around inf
lower-*.f6498.5
Applied rewrites98.5%
if -2e4 < (+.f64 x #s(literal 16 binary64)) < 40Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites96.6%
Final simplification97.5%
(FPCore (x) :precision binary64 (fma x 0.008620689655172414 0.13793103448275862))
double code(double x) {
return fma(x, 0.008620689655172414, 0.13793103448275862);
}
function code(x) return fma(x, 0.008620689655172414, 0.13793103448275862) end
code[x_] := N[(x * 0.008620689655172414 + 0.13793103448275862), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, 0.008620689655172414, 0.13793103448275862\right)
\end{array}
Initial program 100.0%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lift-+.f64N/A
distribute-rgt-inN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-evalN/A
metadata-evalN/A
metadata-eval99.9
Applied rewrites99.9%
(FPCore (x) :precision binary64 0.13793103448275862)
double code(double x) {
return 0.13793103448275862;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.13793103448275862d0
end function
public static double code(double x) {
return 0.13793103448275862;
}
def code(x): return 0.13793103448275862
function code(x) return 0.13793103448275862 end
function tmp = code(x) tmp = 0.13793103448275862; end
code[x_] := 0.13793103448275862
\begin{array}{l}
\\
0.13793103448275862
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites50.4%
herbie shell --seed 2024313
(FPCore (x)
:name "Data.Colour.CIE:cieLAB from colour-2.3.3, B"
:precision binary64
(/ (+ x 16.0) 116.0))