
(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 8 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 (- y x) (* 6.0 z) x))
double code(double x, double y, double z) {
return fma((y - x), (6.0 * z), x);
}
function code(x, y, z) return fma(Float64(y - x), Float64(6.0 * z), x) end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * N[(6.0 * z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - x, 6 \cdot z, x\right)
\end{array}
Initial program 99.5%
+-commutative99.5%
associate-*l*99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.8e-92) (not (<= y 6.2e-15))) (+ x (* 6.0 (* y z))) (+ x (* -6.0 (* x z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.8e-92) || !(y <= 6.2e-15)) {
tmp = x + (6.0 * (y * z));
} else {
tmp = x + (-6.0 * (x * z));
}
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 ((y <= (-5.8d-92)) .or. (.not. (y <= 6.2d-15))) then
tmp = x + (6.0d0 * (y * z))
else
tmp = x + ((-6.0d0) * (x * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5.8e-92) || !(y <= 6.2e-15)) {
tmp = x + (6.0 * (y * z));
} else {
tmp = x + (-6.0 * (x * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.8e-92) or not (y <= 6.2e-15): tmp = x + (6.0 * (y * z)) else: tmp = x + (-6.0 * (x * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.8e-92) || !(y <= 6.2e-15)) tmp = Float64(x + Float64(6.0 * Float64(y * z))); else tmp = Float64(x + Float64(-6.0 * Float64(x * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.8e-92) || ~((y <= 6.2e-15))) tmp = x + (6.0 * (y * z)); else tmp = x + (-6.0 * (x * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.8e-92], N[Not[LessEqual[y, 6.2e-15]], $MachinePrecision]], N[(x + N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(-6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{-92} \lor \neg \left(y \leq 6.2 \cdot 10^{-15}\right):\\
\;\;\;\;x + 6 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x + -6 \cdot \left(x \cdot z\right)\\
\end{array}
\end{array}
if y < -5.79999999999999969e-92 or 6.1999999999999998e-15 < y Initial program 99.2%
Taylor expanded in y around inf 91.3%
*-commutative91.3%
Simplified91.3%
if -5.79999999999999969e-92 < y < 6.1999999999999998e-15Initial program 99.9%
Taylor expanded in y around 0 87.0%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.5e-93) (not (<= y 1.08e-13))) (+ x (* y (* 6.0 z))) (+ x (* -6.0 (* x z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.5e-93) || !(y <= 1.08e-13)) {
tmp = x + (y * (6.0 * z));
} else {
tmp = x + (-6.0 * (x * z));
}
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 ((y <= (-9.5d-93)) .or. (.not. (y <= 1.08d-13))) then
tmp = x + (y * (6.0d0 * z))
else
tmp = x + ((-6.0d0) * (x * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -9.5e-93) || !(y <= 1.08e-13)) {
tmp = x + (y * (6.0 * z));
} else {
tmp = x + (-6.0 * (x * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9.5e-93) or not (y <= 1.08e-13): tmp = x + (y * (6.0 * z)) else: tmp = x + (-6.0 * (x * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9.5e-93) || !(y <= 1.08e-13)) tmp = Float64(x + Float64(y * Float64(6.0 * z))); else tmp = Float64(x + Float64(-6.0 * Float64(x * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -9.5e-93) || ~((y <= 1.08e-13))) tmp = x + (y * (6.0 * z)); else tmp = x + (-6.0 * (x * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.5e-93], N[Not[LessEqual[y, 1.08e-13]], $MachinePrecision]], N[(x + N[(y * N[(6.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(-6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{-93} \lor \neg \left(y \leq 1.08 \cdot 10^{-13}\right):\\
\;\;\;\;x + y \cdot \left(6 \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x + -6 \cdot \left(x \cdot z\right)\\
\end{array}
\end{array}
if y < -9.5000000000000001e-93 or 1.0799999999999999e-13 < y Initial program 99.2%
associate-*r*99.8%
*-commutative99.8%
flip--68.9%
associate-*r/64.3%
Applied egg-rr64.3%
associate-/l*68.8%
*-commutative68.8%
associate-/l*68.8%
difference-of-squares73.0%
associate-/r*99.7%
*-inverses99.7%
Simplified99.7%
Taylor expanded in y around inf 91.3%
*-commutative91.3%
associate-*l*91.3%
*-commutative91.3%
Simplified91.3%
if -9.5000000000000001e-93 < y < 1.0799999999999999e-13Initial program 99.9%
Taylor expanded in y around 0 87.0%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.5e-93) (not (<= y 1.5e-14))) (+ x (* y (* 6.0 z))) (+ x (* z (* x -6.0)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.5e-93) || !(y <= 1.5e-14)) {
tmp = x + (y * (6.0 * z));
} else {
tmp = x + (z * (x * -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 ((y <= (-3.5d-93)) .or. (.not. (y <= 1.5d-14))) then
tmp = x + (y * (6.0d0 * z))
else
tmp = x + (z * (x * (-6.0d0)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.5e-93) || !(y <= 1.5e-14)) {
tmp = x + (y * (6.0 * z));
} else {
tmp = x + (z * (x * -6.0));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.5e-93) or not (y <= 1.5e-14): tmp = x + (y * (6.0 * z)) else: tmp = x + (z * (x * -6.0)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.5e-93) || !(y <= 1.5e-14)) tmp = Float64(x + Float64(y * Float64(6.0 * z))); else tmp = Float64(x + Float64(z * Float64(x * -6.0))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.5e-93) || ~((y <= 1.5e-14))) tmp = x + (y * (6.0 * z)); else tmp = x + (z * (x * -6.0)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.5e-93], N[Not[LessEqual[y, 1.5e-14]], $MachinePrecision]], N[(x + N[(y * N[(6.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(x * -6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{-93} \lor \neg \left(y \leq 1.5 \cdot 10^{-14}\right):\\
\;\;\;\;x + y \cdot \left(6 \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(x \cdot -6\right)\\
\end{array}
\end{array}
if y < -3.5e-93 or 1.4999999999999999e-14 < y Initial program 99.2%
associate-*r*99.8%
*-commutative99.8%
flip--68.9%
associate-*r/64.3%
Applied egg-rr64.3%
associate-/l*68.8%
*-commutative68.8%
associate-/l*68.8%
difference-of-squares73.0%
associate-/r*99.7%
*-inverses99.7%
Simplified99.7%
Taylor expanded in y around inf 91.3%
*-commutative91.3%
associate-*l*91.3%
*-commutative91.3%
Simplified91.3%
if -3.5e-93 < y < 1.4999999999999999e-14Initial program 99.9%
Taylor expanded in y around 0 87.1%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (+ x (* z (* (- y x) 6.0))))
double code(double x, double y, double z) {
return x + (z * ((y - x) * 6.0));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (z * ((y - x) * 6.0d0))
end function
public static double code(double x, double y, double z) {
return x + (z * ((y - x) * 6.0));
}
def code(x, y, z): return x + (z * ((y - x) * 6.0))
function code(x, y, z) return Float64(x + Float64(z * Float64(Float64(y - x) * 6.0))) end
function tmp = code(x, y, z) tmp = x + (z * ((y - x) * 6.0)); end
code[x_, y_, z_] := N[(x + N[(z * N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + z \cdot \left(\left(y - x\right) \cdot 6\right)
\end{array}
Initial program 99.5%
Final simplification99.5%
(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(y - x) * Float64(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[(y - x), $MachinePrecision] * N[(6.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot \left(6 \cdot z\right)
\end{array}
Initial program 99.5%
associate-*l*99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ x (* -6.0 (* x z))))
double code(double x, double y, double z) {
return x + (-6.0 * (x * 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 + ((-6.0d0) * (x * z))
end function
public static double code(double x, double y, double z) {
return x + (-6.0 * (x * z));
}
def code(x, y, z): return x + (-6.0 * (x * z))
function code(x, y, z) return Float64(x + Float64(-6.0 * Float64(x * z))) end
function tmp = code(x, y, z) tmp = x + (-6.0 * (x * z)); end
code[x_, y_, z_] := N[(x + N[(-6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + -6 \cdot \left(x \cdot z\right)
\end{array}
Initial program 99.5%
Taylor expanded in y around 0 55.9%
Final simplification55.9%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.5%
Taylor expanded in z around 0 30.6%
Final simplification30.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 2023287
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, E"
:precision binary64
:herbie-target
(- x (* (* 6.0 z) (- x y)))
(+ x (* (* (- y x) 6.0) z)))