
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) z)))
double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (((y - x) * 6.0d0) * z)
end function
public static double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * z);
}
def code(x, y, z): return x + (((y - x) * 6.0) * z)
function code(x, y, z) return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * z)) end
function tmp = code(x, y, z) tmp = x + (((y - x) * 6.0) * z); end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(y - x\right) \cdot 6\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) z)))
double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (((y - x) * 6.0d0) * z)
end function
public static double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * z);
}
def code(x, y, z): return x + (((y - x) * 6.0) * z)
function code(x, y, z) return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * z)) end
function tmp = code(x, y, z) tmp = x + (((y - x) * 6.0) * z); end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(y - x\right) \cdot 6\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (* z (- y x)) 6.0 x))
double code(double x, double y, double z) {
return fma((z * (y - x)), 6.0, x);
}
function code(x, y, z) return fma(Float64(z * Float64(y - x)), 6.0, x) end
code[x_, y_, z_] := N[(N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision] * 6.0 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z \cdot \left(y - x\right), 6, x\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.16) (not (<= z 0.075))) (* (* (- y x) z) 6.0) (fma (* y z) 6.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.16) || !(z <= 0.075)) {
tmp = ((y - x) * z) * 6.0;
} else {
tmp = fma((y * z), 6.0, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -0.16) || !(z <= 0.075)) tmp = Float64(Float64(Float64(y - x) * z) * 6.0); else tmp = fma(Float64(y * z), 6.0, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.16], N[Not[LessEqual[z, 0.075]], $MachinePrecision]], N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] * 6.0), $MachinePrecision], N[(N[(y * z), $MachinePrecision] * 6.0 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.16 \lor \neg \left(z \leq 0.075\right):\\
\;\;\;\;\left(\left(y - x\right) \cdot z\right) \cdot 6\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot z, 6, x\right)\\
\end{array}
\end{array}
if z < -0.160000000000000003 or 0.0749999999999999972 < z Initial program 99.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.7
Applied rewrites99.7%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
lift-neg.f64N/A
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6497.5
Applied rewrites97.5%
Taylor expanded in z around inf
*-commutativeN/A
mul-1-negN/A
sub-negN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6499.4
Applied rewrites99.4%
if -0.160000000000000003 < z < 0.0749999999999999972Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around 0
lower-*.f6498.7
Applied rewrites98.7%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.8e-54) (not (<= x 1.7e-99))) (fma (* -6.0 x) z x) (* (* 6.0 z) y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.8e-54) || !(x <= 1.7e-99)) {
tmp = fma((-6.0 * x), z, x);
} else {
tmp = (6.0 * z) * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -6.8e-54) || !(x <= 1.7e-99)) tmp = fma(Float64(-6.0 * x), z, x); else tmp = Float64(Float64(6.0 * z) * y); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.8e-54], N[Not[LessEqual[x, 1.7e-99]], $MachinePrecision]], N[(N[(-6.0 * x), $MachinePrecision] * z + x), $MachinePrecision], N[(N[(6.0 * z), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.8 \cdot 10^{-54} \lor \neg \left(x \leq 1.7 \cdot 10^{-99}\right):\\
\;\;\;\;\mathsf{fma}\left(-6 \cdot x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(6 \cdot z\right) \cdot y\\
\end{array}
\end{array}
if x < -6.79999999999999975e-54 or 1.70000000000000003e-99 < x Initial program 99.8%
Taylor expanded in x around inf
distribute-rgt-inN/A
*-lft-identityN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6483.9
Applied rewrites83.9%
if -6.79999999999999975e-54 < x < 1.70000000000000003e-99Initial program 99.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6475.3
Applied rewrites75.3%
Applied rewrites75.3%
Final simplification80.8%
(FPCore (x y z) :precision binary64 (if (<= x -1.06e+115) (fma (* -6.0 x) z x) (if (<= x 1.1e+92) (fma (* y z) 6.0 x) (fma (* -6.0 z) x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.06e+115) {
tmp = fma((-6.0 * x), z, x);
} else if (x <= 1.1e+92) {
tmp = fma((y * z), 6.0, x);
} else {
tmp = fma((-6.0 * z), x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.06e+115) tmp = fma(Float64(-6.0 * x), z, x); elseif (x <= 1.1e+92) tmp = fma(Float64(y * z), 6.0, x); else tmp = fma(Float64(-6.0 * z), x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.06e+115], N[(N[(-6.0 * x), $MachinePrecision] * z + x), $MachinePrecision], If[LessEqual[x, 1.1e+92], N[(N[(y * z), $MachinePrecision] * 6.0 + x), $MachinePrecision], N[(N[(-6.0 * z), $MachinePrecision] * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.06 \cdot 10^{+115}:\\
\;\;\;\;\mathsf{fma}\left(-6 \cdot x, z, x\right)\\
\mathbf{elif}\;x \leq 1.1 \cdot 10^{+92}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot z, 6, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-6 \cdot z, x, x\right)\\
\end{array}
\end{array}
if x < -1.06e115Initial program 99.9%
Taylor expanded in x around inf
distribute-rgt-inN/A
*-lft-identityN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6492.5
Applied rewrites92.5%
if -1.06e115 < x < 1.09999999999999996e92Initial program 99.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.7
Applied rewrites99.7%
Taylor expanded in x around 0
lower-*.f6485.7
Applied rewrites85.7%
if 1.09999999999999996e92 < x Initial program 99.9%
Taylor expanded in x around inf
distribute-rgt-inN/A
*-lft-identityN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6494.1
Applied rewrites94.1%
Applied rewrites94.1%
(FPCore (x y z) :precision binary64 (if (<= x -6.8e-54) (fma (* -6.0 x) z x) (if (<= x 1.7e-99) (* (* 6.0 z) y) (fma (* x z) -6.0 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.8e-54) {
tmp = fma((-6.0 * x), z, x);
} else if (x <= 1.7e-99) {
tmp = (6.0 * z) * y;
} else {
tmp = fma((x * z), -6.0, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -6.8e-54) tmp = fma(Float64(-6.0 * x), z, x); elseif (x <= 1.7e-99) tmp = Float64(Float64(6.0 * z) * y); else tmp = fma(Float64(x * z), -6.0, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -6.8e-54], N[(N[(-6.0 * x), $MachinePrecision] * z + x), $MachinePrecision], If[LessEqual[x, 1.7e-99], N[(N[(6.0 * z), $MachinePrecision] * y), $MachinePrecision], N[(N[(x * z), $MachinePrecision] * -6.0 + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.8 \cdot 10^{-54}:\\
\;\;\;\;\mathsf{fma}\left(-6 \cdot x, z, x\right)\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{-99}:\\
\;\;\;\;\left(6 \cdot z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x \cdot z, -6, x\right)\\
\end{array}
\end{array}
if x < -6.79999999999999975e-54Initial program 99.9%
Taylor expanded in x around inf
distribute-rgt-inN/A
*-lft-identityN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6482.2
Applied rewrites82.2%
if -6.79999999999999975e-54 < x < 1.70000000000000003e-99Initial program 99.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6475.3
Applied rewrites75.3%
Applied rewrites75.3%
if 1.70000000000000003e-99 < x Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f6485.1
Applied rewrites85.1%
Final simplification80.8%
(FPCore (x y z) :precision binary64 (if (<= x -6.8e-54) (fma (* -6.0 x) z x) (if (<= x 1.7e-99) (* (* 6.0 z) y) (fma (* -6.0 z) x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.8e-54) {
tmp = fma((-6.0 * x), z, x);
} else if (x <= 1.7e-99) {
tmp = (6.0 * z) * y;
} else {
tmp = fma((-6.0 * z), x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -6.8e-54) tmp = fma(Float64(-6.0 * x), z, x); elseif (x <= 1.7e-99) tmp = Float64(Float64(6.0 * z) * y); else tmp = fma(Float64(-6.0 * z), x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -6.8e-54], N[(N[(-6.0 * x), $MachinePrecision] * z + x), $MachinePrecision], If[LessEqual[x, 1.7e-99], N[(N[(6.0 * z), $MachinePrecision] * y), $MachinePrecision], N[(N[(-6.0 * z), $MachinePrecision] * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.8 \cdot 10^{-54}:\\
\;\;\;\;\mathsf{fma}\left(-6 \cdot x, z, x\right)\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{-99}:\\
\;\;\;\;\left(6 \cdot z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-6 \cdot z, x, x\right)\\
\end{array}
\end{array}
if x < -6.79999999999999975e-54Initial program 99.9%
Taylor expanded in x around inf
distribute-rgt-inN/A
*-lft-identityN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6482.2
Applied rewrites82.2%
if -6.79999999999999975e-54 < x < 1.70000000000000003e-99Initial program 99.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6475.3
Applied rewrites75.3%
Applied rewrites75.3%
if 1.70000000000000003e-99 < x Initial program 99.8%
Taylor expanded in x around inf
distribute-rgt-inN/A
*-lft-identityN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6485.0
Applied rewrites85.0%
Applied rewrites85.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.06e+115) (not (<= x 1.2e+95))) (* (* -6.0 x) z) (* (* z y) 6.0)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.06e+115) || !(x <= 1.2e+95)) {
tmp = (-6.0 * x) * z;
} else {
tmp = (z * y) * 6.0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-1.06d+115)) .or. (.not. (x <= 1.2d+95))) then
tmp = ((-6.0d0) * x) * z
else
tmp = (z * y) * 6.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.06e+115) || !(x <= 1.2e+95)) {
tmp = (-6.0 * x) * z;
} else {
tmp = (z * y) * 6.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.06e+115) or not (x <= 1.2e+95): tmp = (-6.0 * x) * z else: tmp = (z * y) * 6.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.06e+115) || !(x <= 1.2e+95)) tmp = Float64(Float64(-6.0 * x) * z); else tmp = Float64(Float64(z * y) * 6.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.06e+115) || ~((x <= 1.2e+95))) tmp = (-6.0 * x) * z; else tmp = (z * y) * 6.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.06e+115], N[Not[LessEqual[x, 1.2e+95]], $MachinePrecision]], N[(N[(-6.0 * x), $MachinePrecision] * z), $MachinePrecision], N[(N[(z * y), $MachinePrecision] * 6.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.06 \cdot 10^{+115} \lor \neg \left(x \leq 1.2 \cdot 10^{+95}\right):\\
\;\;\;\;\left(-6 \cdot x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot y\right) \cdot 6\\
\end{array}
\end{array}
if x < -1.06e115 or 1.2e95 < x Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f6493.4
Applied rewrites93.4%
Taylor expanded in z around inf
Applied rewrites47.6%
if -1.06e115 < x < 1.2e95Initial program 99.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6460.4
Applied rewrites60.4%
Final simplification55.2%
(FPCore (x y z) :precision binary64 (* (* 6.0 z) y))
double code(double x, double y, double z) {
return (6.0 * z) * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (6.0d0 * z) * y
end function
public static double code(double x, double y, double z) {
return (6.0 * z) * y;
}
def code(x, y, z): return (6.0 * z) * y
function code(x, y, z) return Float64(Float64(6.0 * z) * y) end
function tmp = code(x, y, z) tmp = (6.0 * z) * y; end
code[x_, y_, z_] := N[(N[(6.0 * z), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(6 \cdot z\right) \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6441.6
Applied rewrites41.6%
Applied rewrites41.7%
(FPCore (x y z) :precision binary64 (* (* 6.0 y) z))
double code(double x, double y, double z) {
return (6.0 * y) * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (6.0d0 * y) * z
end function
public static double code(double x, double y, double z) {
return (6.0 * y) * z;
}
def code(x, y, z): return (6.0 * y) * z
function code(x, y, z) return Float64(Float64(6.0 * y) * z) end
function tmp = code(x, y, z) tmp = (6.0 * y) * z; end
code[x_, y_, z_] := N[(N[(6.0 * y), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\left(6 \cdot y\right) \cdot z
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6441.6
Applied rewrites41.6%
Applied rewrites41.6%
(FPCore (x y z) :precision binary64 (- x (* (* 6.0 z) (- x y))))
double code(double x, double y, double z) {
return x - ((6.0 * z) * (x - y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x - ((6.0d0 * z) * (x - y))
end function
public static double code(double x, double y, double z) {
return x - ((6.0 * z) * (x - y));
}
def code(x, y, z): return x - ((6.0 * z) * (x - y))
function code(x, y, z) return Float64(x - Float64(Float64(6.0 * z) * Float64(x - y))) end
function tmp = code(x, y, z) tmp = x - ((6.0 * z) * (x - y)); end
code[x_, y_, z_] := N[(x - N[(N[(6.0 * z), $MachinePrecision] * N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \left(6 \cdot z\right) \cdot \left(x - y\right)
\end{array}
herbie shell --seed 2024315
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, E"
:precision binary64
:alt
(! :herbie-platform default (- x (* (* 6 z) (- x y))))
(+ x (* (* (- y x) 6.0) z)))