
(FPCore (x y) :precision binary64 (* (* (- x (/ 16.0 116.0)) 3.0) y))
double code(double x, double y) {
return ((x - (16.0 / 116.0)) * 3.0) * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x - (16.0d0 / 116.0d0)) * 3.0d0) * y
end function
public static double code(double x, double y) {
return ((x - (16.0 / 116.0)) * 3.0) * y;
}
def code(x, y): return ((x - (16.0 / 116.0)) * 3.0) * y
function code(x, y) return Float64(Float64(Float64(x - Float64(16.0 / 116.0)) * 3.0) * y) end
function tmp = code(x, y) tmp = ((x - (16.0 / 116.0)) * 3.0) * y; end
code[x_, y_] := N[(N[(N[(x - N[(16.0 / 116.0), $MachinePrecision]), $MachinePrecision] * 3.0), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x - \frac{16}{116}\right) \cdot 3\right) \cdot y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* (* (- x (/ 16.0 116.0)) 3.0) y))
double code(double x, double y) {
return ((x - (16.0 / 116.0)) * 3.0) * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x - (16.0d0 / 116.0d0)) * 3.0d0) * y
end function
public static double code(double x, double y) {
return ((x - (16.0 / 116.0)) * 3.0) * y;
}
def code(x, y): return ((x - (16.0 / 116.0)) * 3.0) * y
function code(x, y) return Float64(Float64(Float64(x - Float64(16.0 / 116.0)) * 3.0) * y) end
function tmp = code(x, y) tmp = ((x - (16.0 / 116.0)) * 3.0) * y; end
code[x_, y_] := N[(N[(N[(x - N[(16.0 / 116.0), $MachinePrecision]), $MachinePrecision] * 3.0), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x - \frac{16}{116}\right) \cdot 3\right) \cdot y
\end{array}
(FPCore (x y) :precision binary64 (* (* (- x (/ 16.0 116.0)) 3.0) y))
double code(double x, double y) {
return ((x - (16.0 / 116.0)) * 3.0) * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x - (16.0d0 / 116.0d0)) * 3.0d0) * y
end function
public static double code(double x, double y) {
return ((x - (16.0 / 116.0)) * 3.0) * y;
}
def code(x, y): return ((x - (16.0 / 116.0)) * 3.0) * y
function code(x, y) return Float64(Float64(Float64(x - Float64(16.0 / 116.0)) * 3.0) * y) end
function tmp = code(x, y) tmp = ((x - (16.0 / 116.0)) * 3.0) * y; end
code[x_, y_] := N[(N[(N[(x - N[(16.0 / 116.0), $MachinePrecision]), $MachinePrecision] * 3.0), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x - \frac{16}{116}\right) \cdot 3\right) \cdot y
\end{array}
Initial program 99.4%
(FPCore (x y) :precision binary64 (if (<= y 4e-246) (/ 16.0 116.0) (- x (/ 16.0 116.0))))
double code(double x, double y) {
double tmp;
if (y <= 4e-246) {
tmp = 16.0 / 116.0;
} else {
tmp = x - (16.0 / 116.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 4d-246) then
tmp = 16.0d0 / 116.0d0
else
tmp = x - (16.0d0 / 116.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 4e-246) {
tmp = 16.0 / 116.0;
} else {
tmp = x - (16.0 / 116.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 4e-246: tmp = 16.0 / 116.0 else: tmp = x - (16.0 / 116.0) return tmp
function code(x, y) tmp = 0.0 if (y <= 4e-246) tmp = Float64(16.0 / 116.0); else tmp = Float64(x - Float64(16.0 / 116.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 4e-246) tmp = 16.0 / 116.0; else tmp = x - (16.0 / 116.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 4e-246], N[(16.0 / 116.0), $MachinePrecision], N[(x - N[(16.0 / 116.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4 \cdot 10^{-246}:\\
\;\;\;\;\frac{16}{116}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{16}{116}\\
\end{array}
\end{array}
if y < 3.99999999999999982e-246Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites28.6%
Taylor expanded in x around 0
Applied rewrites1.5%
Taylor expanded in x around 0
Applied rewrites4.5%
if 3.99999999999999982e-246 < y Initial program 99.0%
Taylor expanded in x around 0
Applied rewrites30.8%
Taylor expanded in x around 0
Applied rewrites6.1%
(FPCore (x y) :precision binary64 (* (- x (/ 16.0 116.0)) y))
double code(double x, double y) {
return (x - (16.0 / 116.0)) * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x - (16.0d0 / 116.0d0)) * y
end function
public static double code(double x, double y) {
return (x - (16.0 / 116.0)) * y;
}
def code(x, y): return (x - (16.0 / 116.0)) * y
function code(x, y) return Float64(Float64(x - Float64(16.0 / 116.0)) * y) end
function tmp = code(x, y) tmp = (x - (16.0 / 116.0)) * y; end
code[x_, y_] := N[(N[(x - N[(16.0 / 116.0), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(x - \frac{16}{116}\right) \cdot y
\end{array}
Initial program 99.4%
Taylor expanded in x around 0
Applied rewrites29.6%
(FPCore (x y) :precision binary64 (/ 16.0 116.0))
double code(double x, double y) {
return 16.0 / 116.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 16.0d0 / 116.0d0
end function
public static double code(double x, double y) {
return 16.0 / 116.0;
}
def code(x, y): return 16.0 / 116.0
function code(x, y) return Float64(16.0 / 116.0) end
function tmp = code(x, y) tmp = 16.0 / 116.0; end
code[x_, y_] := N[(16.0 / 116.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{16}{116}
\end{array}
Initial program 99.4%
Taylor expanded in x around 0
Applied rewrites29.6%
Taylor expanded in x around 0
Applied rewrites3.7%
Taylor expanded in x around 0
Applied rewrites3.4%
(FPCore (x y) :precision binary64 (* y (- (* x 3.0) 0.41379310344827586)))
double code(double x, double y) {
return y * ((x * 3.0) - 0.41379310344827586);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * ((x * 3.0d0) - 0.41379310344827586d0)
end function
public static double code(double x, double y) {
return y * ((x * 3.0) - 0.41379310344827586);
}
def code(x, y): return y * ((x * 3.0) - 0.41379310344827586)
function code(x, y) return Float64(y * Float64(Float64(x * 3.0) - 0.41379310344827586)) end
function tmp = code(x, y) tmp = y * ((x * 3.0) - 0.41379310344827586); end
code[x_, y_] := N[(y * N[(N[(x * 3.0), $MachinePrecision] - 0.41379310344827586), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(x \cdot 3 - 0.41379310344827586\right)
\end{array}
herbie shell --seed 2024321
(FPCore (x y)
:name "Data.Colour.CIE:cieLAB from colour-2.3.3, A"
:precision binary64
:pre (TRUE)
:alt
(! :herbie-platform default (* y (- (* x 3) 20689655172413793/50000000000000000)))
(* (* (- x (/ 16.0 116.0)) 3.0) y))