
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))
double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.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) * ((2.0d0 / 3.0d0) - z))
end function
public static double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z));
}
def code(x, y, z): return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z))
function code(x, y, z) return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * Float64(Float64(2.0 / 3.0) - z))) end
function tmp = code(x, y, z) tmp = x + (((y - x) * 6.0) * ((2.0 / 3.0) - z)); end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))
double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.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) * ((2.0d0 / 3.0d0) - z))
end function
public static double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z));
}
def code(x, y, z): return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z))
function code(x, y, z) return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * Float64(Float64(2.0 / 3.0) - z))) end
function tmp = code(x, y, z) tmp = x + (((y - x) * 6.0) * ((2.0 / 3.0) - z)); end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right)
\end{array}
(FPCore (x y z) :precision binary64 (+ x (fma 6.0 (* z (- x y)) (* 4.0 (- y x)))))
double code(double x, double y, double z) {
return x + fma(6.0, (z * (x - y)), (4.0 * (y - x)));
}
function code(x, y, z) return Float64(x + fma(6.0, Float64(z * Float64(x - y)), Float64(4.0 * Float64(y - x)))) end
code[x_, y_, z_] := N[(x + N[(6.0 * N[(z * N[(x - y), $MachinePrecision]), $MachinePrecision] + N[(4.0 * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \mathsf{fma}\left(6, z \cdot \left(x - y\right), 4 \cdot \left(y - x\right)\right)
\end{array}
Initial program 99.3%
metadata-eval99.3%
Simplified99.3%
flip--89.4%
associate-*r/85.8%
metadata-eval85.8%
pow285.8%
Applied egg-rr85.8%
*-commutative85.8%
associate-/l*89.0%
*-commutative89.0%
associate-/r*89.3%
Simplified89.3%
Taylor expanded in z around 0 99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (fma (- y x) (+ 4.0 (* z -6.0)) x))
double code(double x, double y, double z) {
return fma((y - x), (4.0 + (z * -6.0)), x);
}
function code(x, y, z) return fma(Float64(y - x), Float64(4.0 + Float64(z * -6.0)), x) end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * N[(4.0 + N[(z * -6.0), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - x, 4 + z \cdot -6, x\right)
\end{array}
Initial program 99.3%
+-commutative99.3%
associate-*l*99.7%
fma-def99.7%
sub-neg99.7%
distribute-rgt-in99.7%
metadata-eval99.7%
metadata-eval99.7%
distribute-lft-neg-out99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (+ x (* (* 6.0 (- y x)) (- 0.6666666666666666 z))))
double code(double x, double y, double z) {
return x + ((6.0 * (y - x)) * (0.6666666666666666 - 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 * (y - x)) * (0.6666666666666666d0 - z))
end function
public static double code(double x, double y, double z) {
return x + ((6.0 * (y - x)) * (0.6666666666666666 - z));
}
def code(x, y, z): return x + ((6.0 * (y - x)) * (0.6666666666666666 - z))
function code(x, y, z) return Float64(x + Float64(Float64(6.0 * Float64(y - x)) * Float64(0.6666666666666666 - z))) end
function tmp = code(x, y, z) tmp = x + ((6.0 * (y - x)) * (0.6666666666666666 - z)); end
code[x_, y_, z_] := N[(x + N[(N[(6.0 * N[(y - x), $MachinePrecision]), $MachinePrecision] * N[(0.6666666666666666 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(6 \cdot \left(y - x\right)\right) \cdot \left(0.6666666666666666 - z\right)
\end{array}
Initial program 99.3%
metadata-eval99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (* 6.0 (* z (- x y))))
double code(double x, double y, double z) {
return 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 = 6.0d0 * (z * (x - y))
end function
public static double code(double x, double y, double z) {
return 6.0 * (z * (x - y));
}
def code(x, y, z): return 6.0 * (z * (x - y))
function code(x, y, z) return Float64(6.0 * Float64(z * Float64(x - y))) end
function tmp = code(x, y, z) tmp = 6.0 * (z * (x - y)); end
code[x_, y_, z_] := N[(6.0 * N[(z * N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
6 \cdot \left(z \cdot \left(x - y\right)\right)
\end{array}
Initial program 99.3%
metadata-eval99.3%
Simplified99.3%
flip--89.4%
associate-*r/85.8%
metadata-eval85.8%
pow285.8%
Applied egg-rr85.8%
*-commutative85.8%
associate-/l*89.0%
*-commutative89.0%
associate-/r*89.3%
Simplified89.3%
Taylor expanded in z around 0 99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in z around inf 49.5%
Final simplification49.5%
(FPCore (x y z) :precision binary64 (* x (+ -3.0 (* 6.0 z))))
double code(double x, double y, double z) {
return x * (-3.0 + (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 * ((-3.0d0) + (6.0d0 * z))
end function
public static double code(double x, double y, double z) {
return x * (-3.0 + (6.0 * z));
}
def code(x, y, z): return x * (-3.0 + (6.0 * z))
function code(x, y, z) return Float64(x * Float64(-3.0 + Float64(6.0 * z))) end
function tmp = code(x, y, z) tmp = x * (-3.0 + (6.0 * z)); end
code[x_, y_, z_] := N[(x * N[(-3.0 + N[(6.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(-3 + 6 \cdot z\right)
\end{array}
Initial program 99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in x around inf 53.3%
sub-neg53.3%
distribute-rgt-in53.3%
metadata-eval53.3%
metadata-eval53.3%
distribute-lft-neg-in53.3%
associate-+r+53.3%
metadata-eval53.3%
metadata-eval53.3%
distribute-rgt-neg-in53.3%
metadata-eval53.3%
Simplified53.3%
Final simplification53.3%
(FPCore (x y z) :precision binary64 (* 6.0 (* x z)))
double code(double x, double y, double z) {
return 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 = 6.0d0 * (x * z)
end function
public static double code(double x, double y, double z) {
return 6.0 * (x * z);
}
def code(x, y, z): return 6.0 * (x * z)
function code(x, y, z) return Float64(6.0 * Float64(x * z)) end
function tmp = code(x, y, z) tmp = 6.0 * (x * z); end
code[x_, y_, z_] := N[(6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
6 \cdot \left(x \cdot z\right)
\end{array}
Initial program 99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in x around inf 53.3%
sub-neg53.3%
distribute-rgt-in53.3%
metadata-eval53.3%
metadata-eval53.3%
distribute-lft-neg-in53.3%
associate-+r+53.3%
metadata-eval53.3%
metadata-eval53.3%
distribute-rgt-neg-in53.3%
metadata-eval53.3%
Simplified53.3%
Taylor expanded in z around inf 28.1%
*-commutative28.1%
Simplified28.1%
Final simplification28.1%
(FPCore (x y z) :precision binary64 (* x -3.0))
double code(double x, double y, double z) {
return x * -3.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 * (-3.0d0)
end function
public static double code(double x, double y, double z) {
return x * -3.0;
}
def code(x, y, z): return x * -3.0
function code(x, y, z) return Float64(x * -3.0) end
function tmp = code(x, y, z) tmp = x * -3.0; end
code[x_, y_, z_] := N[(x * -3.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot -3
\end{array}
Initial program 99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in x around inf 53.3%
sub-neg53.3%
distribute-rgt-in53.3%
metadata-eval53.3%
metadata-eval53.3%
distribute-lft-neg-in53.3%
associate-+r+53.3%
metadata-eval53.3%
metadata-eval53.3%
distribute-rgt-neg-in53.3%
metadata-eval53.3%
Simplified53.3%
Taylor expanded in z around 0 27.6%
*-commutative27.6%
Simplified27.6%
Final simplification27.6%
herbie shell --seed 2024033
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, D"
:precision binary64
(+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))