
(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 5 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 (* y (fma x 3.0 -0.41379310344827586)))
double code(double x, double y) {
return y * fma(x, 3.0, -0.41379310344827586);
}
function code(x, y) return Float64(y * fma(x, 3.0, -0.41379310344827586)) end
code[x_, y_] := N[(y * N[(x * 3.0 + -0.41379310344827586), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \mathsf{fma}\left(x, 3, -0.41379310344827586\right)
\end{array}
Initial program 99.8%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
sub-negN/A
distribute-lft-inN/A
*-commutativeN/A
lower-fma.f64N/A
lift-/.f64N/A
metadata-evalN/A
metadata-evalN/A
metadata-eval99.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y) :precision binary64 (let* ((t_0 (- x (/ 16.0 116.0))) (t_1 (* (* 3.0 x) y))) (if (<= t_0 -0.5) t_1 (if (<= t_0 -0.1) (* -0.41379310344827586 y) t_1))))
double code(double x, double y) {
double t_0 = x - (16.0 / 116.0);
double t_1 = (3.0 * x) * y;
double tmp;
if (t_0 <= -0.5) {
tmp = t_1;
} else if (t_0 <= -0.1) {
tmp = -0.41379310344827586 * y;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x - (16.0d0 / 116.0d0)
t_1 = (3.0d0 * x) * y
if (t_0 <= (-0.5d0)) then
tmp = t_1
else if (t_0 <= (-0.1d0)) then
tmp = (-0.41379310344827586d0) * y
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x - (16.0 / 116.0);
double t_1 = (3.0 * x) * y;
double tmp;
if (t_0 <= -0.5) {
tmp = t_1;
} else if (t_0 <= -0.1) {
tmp = -0.41379310344827586 * y;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y): t_0 = x - (16.0 / 116.0) t_1 = (3.0 * x) * y tmp = 0 if t_0 <= -0.5: tmp = t_1 elif t_0 <= -0.1: tmp = -0.41379310344827586 * y else: tmp = t_1 return tmp
function code(x, y) t_0 = Float64(x - Float64(16.0 / 116.0)) t_1 = Float64(Float64(3.0 * x) * y) tmp = 0.0 if (t_0 <= -0.5) tmp = t_1; elseif (t_0 <= -0.1) tmp = Float64(-0.41379310344827586 * y); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y) t_0 = x - (16.0 / 116.0); t_1 = (3.0 * x) * y; tmp = 0.0; if (t_0 <= -0.5) tmp = t_1; elseif (t_0 <= -0.1) tmp = -0.41379310344827586 * y; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x - N[(16.0 / 116.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(3.0 * x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -0.5], t$95$1, If[LessEqual[t$95$0, -0.1], N[(-0.41379310344827586 * y), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \frac{16}{116}\\
t_1 := \left(3 \cdot x\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -0.5:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq -0.1:\\
\;\;\;\;-0.41379310344827586 \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 x (/.f64 #s(literal 16 binary64) #s(literal 116 binary64))) < -0.5 or -0.10000000000000001 < (-.f64 x (/.f64 #s(literal 16 binary64) #s(literal 116 binary64))) Initial program 99.8%
Taylor expanded in x around inf
lower-*.f6496.3
Applied rewrites96.3%
if -0.5 < (-.f64 x (/.f64 #s(literal 16 binary64) #s(literal 116 binary64))) < -0.10000000000000001Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites98.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- x (/ 16.0 116.0))))
(if (<= t_0 -0.5)
(* (* y 3.0) x)
(if (<= t_0 -0.1) (* -0.41379310344827586 y) (* (* y x) 3.0)))))
double code(double x, double y) {
double t_0 = x - (16.0 / 116.0);
double tmp;
if (t_0 <= -0.5) {
tmp = (y * 3.0) * x;
} else if (t_0 <= -0.1) {
tmp = -0.41379310344827586 * y;
} else {
tmp = (y * x) * 3.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = x - (16.0d0 / 116.0d0)
if (t_0 <= (-0.5d0)) then
tmp = (y * 3.0d0) * x
else if (t_0 <= (-0.1d0)) then
tmp = (-0.41379310344827586d0) * y
else
tmp = (y * x) * 3.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x - (16.0 / 116.0);
double tmp;
if (t_0 <= -0.5) {
tmp = (y * 3.0) * x;
} else if (t_0 <= -0.1) {
tmp = -0.41379310344827586 * y;
} else {
tmp = (y * x) * 3.0;
}
return tmp;
}
def code(x, y): t_0 = x - (16.0 / 116.0) tmp = 0 if t_0 <= -0.5: tmp = (y * 3.0) * x elif t_0 <= -0.1: tmp = -0.41379310344827586 * y else: tmp = (y * x) * 3.0 return tmp
function code(x, y) t_0 = Float64(x - Float64(16.0 / 116.0)) tmp = 0.0 if (t_0 <= -0.5) tmp = Float64(Float64(y * 3.0) * x); elseif (t_0 <= -0.1) tmp = Float64(-0.41379310344827586 * y); else tmp = Float64(Float64(y * x) * 3.0); end return tmp end
function tmp_2 = code(x, y) t_0 = x - (16.0 / 116.0); tmp = 0.0; if (t_0 <= -0.5) tmp = (y * 3.0) * x; elseif (t_0 <= -0.1) tmp = -0.41379310344827586 * y; else tmp = (y * x) * 3.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x - N[(16.0 / 116.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.5], N[(N[(y * 3.0), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$0, -0.1], N[(-0.41379310344827586 * y), $MachinePrecision], N[(N[(y * x), $MachinePrecision] * 3.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \frac{16}{116}\\
\mathbf{if}\;t\_0 \leq -0.5:\\
\;\;\;\;\left(y \cdot 3\right) \cdot x\\
\mathbf{elif}\;t\_0 \leq -0.1:\\
\;\;\;\;-0.41379310344827586 \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot x\right) \cdot 3\\
\end{array}
\end{array}
if (-.f64 x (/.f64 #s(literal 16 binary64) #s(literal 116 binary64))) < -0.5Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6496.9
Applied rewrites96.9%
if -0.5 < (-.f64 x (/.f64 #s(literal 16 binary64) #s(literal 116 binary64))) < -0.10000000000000001Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites98.0%
if -0.10000000000000001 < (-.f64 x (/.f64 #s(literal 16 binary64) #s(literal 116 binary64))) Initial program 99.8%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
sub-negN/A
distribute-lft-inN/A
*-commutativeN/A
lower-fma.f64N/A
lift-/.f64N/A
metadata-evalN/A
metadata-evalN/A
metadata-eval99.8
Applied rewrites99.8%
lift-*.f64N/A
lift-fma.f64N/A
metadata-evalN/A
distribute-rgt-inN/A
metadata-evalN/A
metadata-evalN/A
sub-negN/A
lift--.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval99.6
Applied rewrites99.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6495.2
Applied rewrites95.2%
Final simplification97.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (- x (/ 16.0 116.0))) (t_1 (* (* y 3.0) x))) (if (<= t_0 -0.5) t_1 (if (<= t_0 -0.1) (* -0.41379310344827586 y) t_1))))
double code(double x, double y) {
double t_0 = x - (16.0 / 116.0);
double t_1 = (y * 3.0) * x;
double tmp;
if (t_0 <= -0.5) {
tmp = t_1;
} else if (t_0 <= -0.1) {
tmp = -0.41379310344827586 * y;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x - (16.0d0 / 116.0d0)
t_1 = (y * 3.0d0) * x
if (t_0 <= (-0.5d0)) then
tmp = t_1
else if (t_0 <= (-0.1d0)) then
tmp = (-0.41379310344827586d0) * y
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x - (16.0 / 116.0);
double t_1 = (y * 3.0) * x;
double tmp;
if (t_0 <= -0.5) {
tmp = t_1;
} else if (t_0 <= -0.1) {
tmp = -0.41379310344827586 * y;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y): t_0 = x - (16.0 / 116.0) t_1 = (y * 3.0) * x tmp = 0 if t_0 <= -0.5: tmp = t_1 elif t_0 <= -0.1: tmp = -0.41379310344827586 * y else: tmp = t_1 return tmp
function code(x, y) t_0 = Float64(x - Float64(16.0 / 116.0)) t_1 = Float64(Float64(y * 3.0) * x) tmp = 0.0 if (t_0 <= -0.5) tmp = t_1; elseif (t_0 <= -0.1) tmp = Float64(-0.41379310344827586 * y); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y) t_0 = x - (16.0 / 116.0); t_1 = (y * 3.0) * x; tmp = 0.0; if (t_0 <= -0.5) tmp = t_1; elseif (t_0 <= -0.1) tmp = -0.41379310344827586 * y; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x - N[(16.0 / 116.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(y * 3.0), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[t$95$0, -0.5], t$95$1, If[LessEqual[t$95$0, -0.1], N[(-0.41379310344827586 * y), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \frac{16}{116}\\
t_1 := \left(y \cdot 3\right) \cdot x\\
\mathbf{if}\;t\_0 \leq -0.5:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq -0.1:\\
\;\;\;\;-0.41379310344827586 \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 x (/.f64 #s(literal 16 binary64) #s(literal 116 binary64))) < -0.5 or -0.10000000000000001 < (-.f64 x (/.f64 #s(literal 16 binary64) #s(literal 116 binary64))) Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6496.1
Applied rewrites96.1%
if -0.5 < (-.f64 x (/.f64 #s(literal 16 binary64) #s(literal 116 binary64))) < -0.10000000000000001Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites98.0%
Final simplification97.0%
(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.8%
Taylor expanded in x around 0
Applied rewrites50.5%
(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 2024295
(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))