
(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 7 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 (+ 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.8%
associate-*l*99.8%
Simplified99.8%
(FPCore (x y z)
:precision binary64
(if (or (<= y -2e-55)
(and (not (<= y -9.5e-95))
(or (<= y -5.3e-132) (not (<= y 4.1e+42)))))
(+ x (* 6.0 (* y z)))
(+ x (* x (* z -6.0)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2e-55) || (!(y <= -9.5e-95) && ((y <= -5.3e-132) || !(y <= 4.1e+42)))) {
tmp = x + (6.0 * (y * z));
} else {
tmp = x + (x * (z * -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 <= (-2d-55)) .or. (.not. (y <= (-9.5d-95))) .and. (y <= (-5.3d-132)) .or. (.not. (y <= 4.1d+42))) then
tmp = x + (6.0d0 * (y * z))
else
tmp = x + (x * (z * (-6.0d0)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2e-55) || (!(y <= -9.5e-95) && ((y <= -5.3e-132) || !(y <= 4.1e+42)))) {
tmp = x + (6.0 * (y * z));
} else {
tmp = x + (x * (z * -6.0));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2e-55) or (not (y <= -9.5e-95) and ((y <= -5.3e-132) or not (y <= 4.1e+42))): tmp = x + (6.0 * (y * z)) else: tmp = x + (x * (z * -6.0)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2e-55) || (!(y <= -9.5e-95) && ((y <= -5.3e-132) || !(y <= 4.1e+42)))) tmp = Float64(x + Float64(6.0 * Float64(y * z))); else tmp = Float64(x + Float64(x * Float64(z * -6.0))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2e-55) || (~((y <= -9.5e-95)) && ((y <= -5.3e-132) || ~((y <= 4.1e+42))))) tmp = x + (6.0 * (y * z)); else tmp = x + (x * (z * -6.0)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2e-55], And[N[Not[LessEqual[y, -9.5e-95]], $MachinePrecision], Or[LessEqual[y, -5.3e-132], N[Not[LessEqual[y, 4.1e+42]], $MachinePrecision]]]], N[(x + N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(x * N[(z * -6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{-55} \lor \neg \left(y \leq -9.5 \cdot 10^{-95}\right) \land \left(y \leq -5.3 \cdot 10^{-132} \lor \neg \left(y \leq 4.1 \cdot 10^{+42}\right)\right):\\
\;\;\;\;x + 6 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot \left(z \cdot -6\right)\\
\end{array}
\end{array}
if y < -1.99999999999999999e-55 or -9.49999999999999998e-95 < y < -5.3000000000000003e-132 or 4.1e42 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in y around inf 91.2%
*-commutative91.2%
Simplified91.2%
if -1.99999999999999999e-55 < y < -9.49999999999999998e-95 or -5.3000000000000003e-132 < y < 4.1e42Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in y around 0 89.8%
*-commutative89.8%
associate-*r*89.9%
*-commutative89.9%
Simplified89.9%
Final simplification90.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (* x (* z -6.0)))))
(if (<= y -1.65e-55)
(+ x (* y (* 6.0 z)))
(if (<= y -4e-97)
t_0
(if (<= y -9.2e-132)
(+ x (* 6.0 (* y z)))
(if (<= y 4e+42) t_0 (+ x (* z (* y 6.0)))))))))
double code(double x, double y, double z) {
double t_0 = x + (x * (z * -6.0));
double tmp;
if (y <= -1.65e-55) {
tmp = x + (y * (6.0 * z));
} else if (y <= -4e-97) {
tmp = t_0;
} else if (y <= -9.2e-132) {
tmp = x + (6.0 * (y * z));
} else if (y <= 4e+42) {
tmp = t_0;
} else {
tmp = x + (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) :: t_0
real(8) :: tmp
t_0 = x + (x * (z * (-6.0d0)))
if (y <= (-1.65d-55)) then
tmp = x + (y * (6.0d0 * z))
else if (y <= (-4d-97)) then
tmp = t_0
else if (y <= (-9.2d-132)) then
tmp = x + (6.0d0 * (y * z))
else if (y <= 4d+42) then
tmp = t_0
else
tmp = x + (z * (y * 6.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + (x * (z * -6.0));
double tmp;
if (y <= -1.65e-55) {
tmp = x + (y * (6.0 * z));
} else if (y <= -4e-97) {
tmp = t_0;
} else if (y <= -9.2e-132) {
tmp = x + (6.0 * (y * z));
} else if (y <= 4e+42) {
tmp = t_0;
} else {
tmp = x + (z * (y * 6.0));
}
return tmp;
}
def code(x, y, z): t_0 = x + (x * (z * -6.0)) tmp = 0 if y <= -1.65e-55: tmp = x + (y * (6.0 * z)) elif y <= -4e-97: tmp = t_0 elif y <= -9.2e-132: tmp = x + (6.0 * (y * z)) elif y <= 4e+42: tmp = t_0 else: tmp = x + (z * (y * 6.0)) return tmp
function code(x, y, z) t_0 = Float64(x + Float64(x * Float64(z * -6.0))) tmp = 0.0 if (y <= -1.65e-55) tmp = Float64(x + Float64(y * Float64(6.0 * z))); elseif (y <= -4e-97) tmp = t_0; elseif (y <= -9.2e-132) tmp = Float64(x + Float64(6.0 * Float64(y * z))); elseif (y <= 4e+42) tmp = t_0; else tmp = Float64(x + Float64(z * Float64(y * 6.0))); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (x * (z * -6.0)); tmp = 0.0; if (y <= -1.65e-55) tmp = x + (y * (6.0 * z)); elseif (y <= -4e-97) tmp = t_0; elseif (y <= -9.2e-132) tmp = x + (6.0 * (y * z)); elseif (y <= 4e+42) tmp = t_0; else tmp = x + (z * (y * 6.0)); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(x * N[(z * -6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.65e-55], N[(x + N[(y * N[(6.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -4e-97], t$95$0, If[LessEqual[y, -9.2e-132], N[(x + N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4e+42], t$95$0, N[(x + N[(z * N[(y * 6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + x \cdot \left(z \cdot -6\right)\\
\mathbf{if}\;y \leq -1.65 \cdot 10^{-55}:\\
\;\;\;\;x + y \cdot \left(6 \cdot z\right)\\
\mathbf{elif}\;y \leq -4 \cdot 10^{-97}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -9.2 \cdot 10^{-132}:\\
\;\;\;\;x + 6 \cdot \left(y \cdot z\right)\\
\mathbf{elif}\;y \leq 4 \cdot 10^{+42}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(y \cdot 6\right)\\
\end{array}
\end{array}
if y < -1.65e-55Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in y around inf 88.0%
if -1.65e-55 < y < -4.00000000000000014e-97 or -9.20000000000000012e-132 < y < 4.00000000000000018e42Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in y around 0 89.8%
*-commutative89.8%
associate-*r*89.9%
*-commutative89.9%
Simplified89.9%
if -4.00000000000000014e-97 < y < -9.20000000000000012e-132Initial program 99.6%
associate-*l*99.5%
Simplified99.5%
Taylor expanded in y around inf 92.6%
*-commutative92.6%
Simplified92.6%
if 4.00000000000000018e42 < y Initial program 99.8%
Taylor expanded in y around inf 94.5%
Final simplification90.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (* x (* z -6.0)))) (t_1 (+ x (* y (* 6.0 z)))))
(if (<= y -2.5e-55)
t_1
(if (<= y -4.4e-97)
t_0
(if (<= y -9.2e-132)
(+ x (* 6.0 (* y z)))
(if (<= y 3.6e+42) t_0 t_1))))))
double code(double x, double y, double z) {
double t_0 = x + (x * (z * -6.0));
double t_1 = x + (y * (6.0 * z));
double tmp;
if (y <= -2.5e-55) {
tmp = t_1;
} else if (y <= -4.4e-97) {
tmp = t_0;
} else if (y <= -9.2e-132) {
tmp = x + (6.0 * (y * z));
} else if (y <= 3.6e+42) {
tmp = t_0;
} else {
tmp = t_1;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x + (x * (z * (-6.0d0)))
t_1 = x + (y * (6.0d0 * z))
if (y <= (-2.5d-55)) then
tmp = t_1
else if (y <= (-4.4d-97)) then
tmp = t_0
else if (y <= (-9.2d-132)) then
tmp = x + (6.0d0 * (y * z))
else if (y <= 3.6d+42) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + (x * (z * -6.0));
double t_1 = x + (y * (6.0 * z));
double tmp;
if (y <= -2.5e-55) {
tmp = t_1;
} else if (y <= -4.4e-97) {
tmp = t_0;
} else if (y <= -9.2e-132) {
tmp = x + (6.0 * (y * z));
} else if (y <= 3.6e+42) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = x + (x * (z * -6.0)) t_1 = x + (y * (6.0 * z)) tmp = 0 if y <= -2.5e-55: tmp = t_1 elif y <= -4.4e-97: tmp = t_0 elif y <= -9.2e-132: tmp = x + (6.0 * (y * z)) elif y <= 3.6e+42: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(x + Float64(x * Float64(z * -6.0))) t_1 = Float64(x + Float64(y * Float64(6.0 * z))) tmp = 0.0 if (y <= -2.5e-55) tmp = t_1; elseif (y <= -4.4e-97) tmp = t_0; elseif (y <= -9.2e-132) tmp = Float64(x + Float64(6.0 * Float64(y * z))); elseif (y <= 3.6e+42) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (x * (z * -6.0)); t_1 = x + (y * (6.0 * z)); tmp = 0.0; if (y <= -2.5e-55) tmp = t_1; elseif (y <= -4.4e-97) tmp = t_0; elseif (y <= -9.2e-132) tmp = x + (6.0 * (y * z)); elseif (y <= 3.6e+42) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(x * N[(z * -6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x + N[(y * N[(6.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.5e-55], t$95$1, If[LessEqual[y, -4.4e-97], t$95$0, If[LessEqual[y, -9.2e-132], N[(x + N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.6e+42], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + x \cdot \left(z \cdot -6\right)\\
t_1 := x + y \cdot \left(6 \cdot z\right)\\
\mathbf{if}\;y \leq -2.5 \cdot 10^{-55}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -4.4 \cdot 10^{-97}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -9.2 \cdot 10^{-132}:\\
\;\;\;\;x + 6 \cdot \left(y \cdot z\right)\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{+42}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -2.5000000000000001e-55 or 3.6000000000000001e42 < y Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in y around inf 91.1%
if -2.5000000000000001e-55 < y < -4.3999999999999998e-97 or -9.20000000000000012e-132 < y < 3.6000000000000001e42Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in y around 0 89.8%
*-commutative89.8%
associate-*r*89.9%
*-commutative89.9%
Simplified89.9%
if -4.3999999999999998e-97 < y < -9.20000000000000012e-132Initial program 99.6%
associate-*l*99.5%
Simplified99.5%
Taylor expanded in y around inf 92.6%
*-commutative92.6%
Simplified92.6%
Final simplification90.7%
(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.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ x (* 6.0 (* y z))))
double code(double x, double y, double z) {
return x + (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 = x + (6.0d0 * (y * z))
end function
public static double code(double x, double y, double z) {
return x + (6.0 * (y * z));
}
def code(x, y, z): return x + (6.0 * (y * z))
function code(x, y, z) return Float64(x + Float64(6.0 * Float64(y * z))) end
function tmp = code(x, y, z) tmp = x + (6.0 * (y * z)); end
code[x_, y_, z_] := N[(x + N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + 6 \cdot \left(y \cdot z\right)
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in y around inf 75.3%
*-commutative75.3%
Simplified75.3%
Final simplification75.3%
(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.8%
associate-*l*99.8%
Simplified99.8%
flip3--36.6%
associate-*l/34.7%
+-commutative34.7%
distribute-rgt-out34.7%
+-commutative34.7%
fma-define34.7%
pow234.7%
Applied egg-rr34.7%
Taylor expanded in y around inf 35.7%
Taylor expanded in x around inf 36.4%
(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 2024111
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, E"
:precision binary64
:alt
(- x (* (* 6.0 z) (- x y)))
(+ x (* (* (- y x) 6.0) z)))