
(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 (* (fma 3.0 x -0.41379310344827586) y))
double code(double x, double y) {
return fma(3.0, x, -0.41379310344827586) * y;
}
function code(x, y) return Float64(fma(3.0, x, -0.41379310344827586) * y) end
code[x_, y_] := N[(N[(3.0 * x + -0.41379310344827586), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(3, x, -0.41379310344827586\right) \cdot y
\end{array}
Initial program 99.7%
Taylor expanded in x around 0
metadata-evalN/A
metadata-evalN/A
lft-mult-inverseN/A
fp-cancel-sign-sub-invN/A
associate-*l*N/A
metadata-evalN/A
metadata-evalN/A
associate-*l*N/A
lft-mult-inverseN/A
metadata-evalN/A
lower-fma.f6499.8
Applied rewrites99.8%
(FPCore (x y) :precision binary64 (if (or (<= x -0.14) (not (<= x 0.14))) (* (* y x) 3.0) (* -0.41379310344827586 y)))
double code(double x, double y) {
double tmp;
if ((x <= -0.14) || !(x <= 0.14)) {
tmp = (y * x) * 3.0;
} else {
tmp = -0.41379310344827586 * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-0.14d0)) .or. (.not. (x <= 0.14d0))) then
tmp = (y * x) * 3.0d0
else
tmp = (-0.41379310344827586d0) * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -0.14) || !(x <= 0.14)) {
tmp = (y * x) * 3.0;
} else {
tmp = -0.41379310344827586 * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -0.14) or not (x <= 0.14): tmp = (y * x) * 3.0 else: tmp = -0.41379310344827586 * y return tmp
function code(x, y) tmp = 0.0 if ((x <= -0.14) || !(x <= 0.14)) tmp = Float64(Float64(y * x) * 3.0); else tmp = Float64(-0.41379310344827586 * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -0.14) || ~((x <= 0.14))) tmp = (y * x) * 3.0; else tmp = -0.41379310344827586 * y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -0.14], N[Not[LessEqual[x, 0.14]], $MachinePrecision]], N[(N[(y * x), $MachinePrecision] * 3.0), $MachinePrecision], N[(-0.41379310344827586 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.14 \lor \neg \left(x \leq 0.14\right):\\
\;\;\;\;\left(y \cdot x\right) \cdot 3\\
\mathbf{else}:\\
\;\;\;\;-0.41379310344827586 \cdot y\\
\end{array}
\end{array}
if x < -0.14000000000000001 or 0.14000000000000001 < x Initial program 99.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6497.0
Applied rewrites97.0%
if -0.14000000000000001 < x < 0.14000000000000001Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites97.4%
Final simplification97.2%
(FPCore (x y) :precision binary64 (if (or (<= x -0.14) (not (<= x 0.14))) (* (* y 3.0) x) (* -0.41379310344827586 y)))
double code(double x, double y) {
double tmp;
if ((x <= -0.14) || !(x <= 0.14)) {
tmp = (y * 3.0) * x;
} else {
tmp = -0.41379310344827586 * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-0.14d0)) .or. (.not. (x <= 0.14d0))) then
tmp = (y * 3.0d0) * x
else
tmp = (-0.41379310344827586d0) * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -0.14) || !(x <= 0.14)) {
tmp = (y * 3.0) * x;
} else {
tmp = -0.41379310344827586 * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -0.14) or not (x <= 0.14): tmp = (y * 3.0) * x else: tmp = -0.41379310344827586 * y return tmp
function code(x, y) tmp = 0.0 if ((x <= -0.14) || !(x <= 0.14)) tmp = Float64(Float64(y * 3.0) * x); else tmp = Float64(-0.41379310344827586 * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -0.14) || ~((x <= 0.14))) tmp = (y * 3.0) * x; else tmp = -0.41379310344827586 * y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -0.14], N[Not[LessEqual[x, 0.14]], $MachinePrecision]], N[(N[(y * 3.0), $MachinePrecision] * x), $MachinePrecision], N[(-0.41379310344827586 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.14 \lor \neg \left(x \leq 0.14\right):\\
\;\;\;\;\left(y \cdot 3\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;-0.41379310344827586 \cdot y\\
\end{array}
\end{array}
if x < -0.14000000000000001 or 0.14000000000000001 < x Initial program 99.6%
Taylor expanded in x around 0
metadata-evalN/A
metadata-evalN/A
lft-mult-inverseN/A
fp-cancel-sign-sub-invN/A
associate-*l*N/A
metadata-evalN/A
metadata-evalN/A
associate-*l*N/A
lft-mult-inverseN/A
metadata-evalN/A
lower-fma.f6499.7
Applied rewrites99.7%
Taylor expanded in x around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6496.8
Applied rewrites96.8%
if -0.14000000000000001 < x < 0.14000000000000001Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites97.4%
Final simplification97.1%
(FPCore (x y) :precision binary64 (* -0.41379310344827586 y))
double code(double x, double y) {
return -0.41379310344827586 * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (-0.41379310344827586d0) * y
end function
public static double code(double x, double y) {
return -0.41379310344827586 * y;
}
def code(x, y): return -0.41379310344827586 * y
function code(x, y) return Float64(-0.41379310344827586 * y) end
function tmp = code(x, y) tmp = -0.41379310344827586 * y; end
code[x_, y_] := N[(-0.41379310344827586 * y), $MachinePrecision]
\begin{array}{l}
\\
-0.41379310344827586 \cdot y
\end{array}
Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites48.7%
(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 2024337
(FPCore (x y)
:name "Data.Colour.CIE:cieLAB from colour-2.3.3, A"
:precision binary64
:alt
(! :herbie-platform default (* y (- (* x 3) 20689655172413793/50000000000000000)))
(* (* (- x (/ 16.0 116.0)) 3.0) y))