
(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 (* (* (+ x -0.13793103448275862) y) 3.0))
double code(double x, double y) {
return ((x + -0.13793103448275862) * y) * 3.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x + (-0.13793103448275862d0)) * y) * 3.0d0
end function
public static double code(double x, double y) {
return ((x + -0.13793103448275862) * y) * 3.0;
}
def code(x, y): return ((x + -0.13793103448275862) * y) * 3.0
function code(x, y) return Float64(Float64(Float64(x + -0.13793103448275862) * y) * 3.0) end
function tmp = code(x, y) tmp = ((x + -0.13793103448275862) * y) * 3.0; end
code[x_, y_] := N[(N[(N[(x + -0.13793103448275862), $MachinePrecision] * y), $MachinePrecision] * 3.0), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x + -0.13793103448275862\right) \cdot y\right) \cdot 3
\end{array}
Initial program 99.4%
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
metadata-evalN/A
metadata-eval99.4%
Simplified99.4%
*-commutativeN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f6499.6%
Applied egg-rr99.6%
(FPCore (x y) :precision binary64 (if (<= x -0.135) (* x (* y 3.0)) (if (<= x 0.14) (* y -0.41379310344827586) (* y (* x 3.0)))))
double code(double x, double y) {
double tmp;
if (x <= -0.135) {
tmp = x * (y * 3.0);
} else if (x <= 0.14) {
tmp = y * -0.41379310344827586;
} 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) :: tmp
if (x <= (-0.135d0)) then
tmp = x * (y * 3.0d0)
else if (x <= 0.14d0) then
tmp = y * (-0.41379310344827586d0)
else
tmp = y * (x * 3.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -0.135) {
tmp = x * (y * 3.0);
} else if (x <= 0.14) {
tmp = y * -0.41379310344827586;
} else {
tmp = y * (x * 3.0);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -0.135: tmp = x * (y * 3.0) elif x <= 0.14: tmp = y * -0.41379310344827586 else: tmp = y * (x * 3.0) return tmp
function code(x, y) tmp = 0.0 if (x <= -0.135) tmp = Float64(x * Float64(y * 3.0)); elseif (x <= 0.14) tmp = Float64(y * -0.41379310344827586); else tmp = Float64(y * Float64(x * 3.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -0.135) tmp = x * (y * 3.0); elseif (x <= 0.14) tmp = y * -0.41379310344827586; else tmp = y * (x * 3.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -0.135], N[(x * N[(y * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.14], N[(y * -0.41379310344827586), $MachinePrecision], N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.135:\\
\;\;\;\;x \cdot \left(y \cdot 3\right)\\
\mathbf{elif}\;x \leq 0.14:\\
\;\;\;\;y \cdot -0.41379310344827586\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot 3\right)\\
\end{array}
\end{array}
if x < -0.13500000000000001Initial program 98.4%
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
metadata-evalN/A
metadata-eval98.4%
Simplified98.4%
Taylor expanded in x around inf
Simplified96.6%
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6497.8%
Applied egg-rr97.8%
if -0.13500000000000001 < x < 0.14000000000000001Initial program 99.9%
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
metadata-evalN/A
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around 0
*-lowering-*.f6496.9%
Simplified96.9%
if 0.14000000000000001 < x Initial program 99.8%
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
metadata-evalN/A
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around inf
Simplified99.6%
Final simplification97.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (* y (* x 3.0)))) (if (<= x -0.135) t_0 (if (<= x 0.14) (* y -0.41379310344827586) t_0))))
double code(double x, double y) {
double t_0 = y * (x * 3.0);
double tmp;
if (x <= -0.135) {
tmp = t_0;
} else if (x <= 0.14) {
tmp = y * -0.41379310344827586;
} else {
tmp = t_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 = y * (x * 3.0d0)
if (x <= (-0.135d0)) then
tmp = t_0
else if (x <= 0.14d0) then
tmp = y * (-0.41379310344827586d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * (x * 3.0);
double tmp;
if (x <= -0.135) {
tmp = t_0;
} else if (x <= 0.14) {
tmp = y * -0.41379310344827586;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = y * (x * 3.0) tmp = 0 if x <= -0.135: tmp = t_0 elif x <= 0.14: tmp = y * -0.41379310344827586 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(y * Float64(x * 3.0)) tmp = 0.0 if (x <= -0.135) tmp = t_0; elseif (x <= 0.14) tmp = Float64(y * -0.41379310344827586); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = y * (x * 3.0); tmp = 0.0; if (x <= -0.135) tmp = t_0; elseif (x <= 0.14) tmp = y * -0.41379310344827586; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.135], t$95$0, If[LessEqual[x, 0.14], N[(y * -0.41379310344827586), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x \cdot 3\right)\\
\mathbf{if}\;x \leq -0.135:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.14:\\
\;\;\;\;y \cdot -0.41379310344827586\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -0.13500000000000001 or 0.14000000000000001 < x Initial program 99.0%
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
metadata-evalN/A
metadata-eval99.0%
Simplified99.0%
Taylor expanded in x around inf
Simplified97.9%
if -0.13500000000000001 < x < 0.14000000000000001Initial program 99.9%
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
metadata-evalN/A
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around 0
*-lowering-*.f6496.9%
Simplified96.9%
Final simplification97.5%
(FPCore (x y) :precision binary64 (* y (* (+ x -0.13793103448275862) 3.0)))
double code(double x, double y) {
return y * ((x + -0.13793103448275862) * 3.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * ((x + (-0.13793103448275862d0)) * 3.0d0)
end function
public static double code(double x, double y) {
return y * ((x + -0.13793103448275862) * 3.0);
}
def code(x, y): return y * ((x + -0.13793103448275862) * 3.0)
function code(x, y) return Float64(y * Float64(Float64(x + -0.13793103448275862) * 3.0)) end
function tmp = code(x, y) tmp = y * ((x + -0.13793103448275862) * 3.0); end
code[x_, y_] := N[(y * N[(N[(x + -0.13793103448275862), $MachinePrecision] * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(\left(x + -0.13793103448275862\right) \cdot 3\right)
\end{array}
Initial program 99.4%
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
metadata-evalN/A
metadata-eval99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (x y) :precision binary64 (* y -0.41379310344827586))
double code(double x, double y) {
return y * -0.41379310344827586;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * (-0.41379310344827586d0)
end function
public static double code(double x, double y) {
return y * -0.41379310344827586;
}
def code(x, y): return y * -0.41379310344827586
function code(x, y) return Float64(y * -0.41379310344827586) end
function tmp = code(x, y) tmp = y * -0.41379310344827586; end
code[x_, y_] := N[(y * -0.41379310344827586), $MachinePrecision]
\begin{array}{l}
\\
y \cdot -0.41379310344827586
\end{array}
Initial program 99.4%
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
metadata-evalN/A
metadata-eval99.4%
Simplified99.4%
Taylor expanded in x around 0
*-lowering-*.f6445.7%
Simplified45.7%
Final simplification45.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 2024138
(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))