
(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 10 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 (* (* (- 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}
Initial program 99.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (/ 2.0 3.0) z)) (t_1 (+ x (* (- y x) t_0))))
(if (<= t_0 0.17)
t_1
(if (<= t_0 5.2) (+ x (+ x (+ x (* (- y x) 6.0)))) t_1))))
double code(double x, double y, double z) {
double t_0 = (2.0 / 3.0) - z;
double t_1 = x + ((y - x) * t_0);
double tmp;
if (t_0 <= 0.17) {
tmp = t_1;
} else if (t_0 <= 5.2) {
tmp = x + (x + (x + ((y - x) * 6.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 = (2.0d0 / 3.0d0) - z
t_1 = x + ((y - x) * t_0)
if (t_0 <= 0.17d0) then
tmp = t_1
else if (t_0 <= 5.2d0) then
tmp = x + (x + (x + ((y - x) * 6.0d0)))
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (2.0 / 3.0) - z;
double t_1 = x + ((y - x) * t_0);
double tmp;
if (t_0 <= 0.17) {
tmp = t_1;
} else if (t_0 <= 5.2) {
tmp = x + (x + (x + ((y - x) * 6.0)));
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = (2.0 / 3.0) - z t_1 = x + ((y - x) * t_0) tmp = 0 if t_0 <= 0.17: tmp = t_1 elif t_0 <= 5.2: tmp = x + (x + (x + ((y - x) * 6.0))) else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(Float64(2.0 / 3.0) - z) t_1 = Float64(x + Float64(Float64(y - x) * t_0)) tmp = 0.0 if (t_0 <= 0.17) tmp = t_1; elseif (t_0 <= 5.2) tmp = Float64(x + Float64(x + Float64(x + Float64(Float64(y - x) * 6.0)))); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (2.0 / 3.0) - z; t_1 = x + ((y - x) * t_0); tmp = 0.0; if (t_0 <= 0.17) tmp = t_1; elseif (t_0 <= 5.2) tmp = x + (x + (x + ((y - x) * 6.0))); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]}, Block[{t$95$1 = N[(x + N[(N[(y - x), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.17], t$95$1, If[LessEqual[t$95$0, 5.2], N[(x + N[(x + N[(x + N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{3} - z\\
t_1 := x + \left(y - x\right) \cdot t\_0\\
\mathbf{if}\;t\_0 \leq 0.17:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 5.2:\\
\;\;\;\;x + \left(x + \left(x + \left(y - x\right) \cdot 6\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 0.170000000000000012 or 5.20000000000000018 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites54.0%
if 0.170000000000000012 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 5.20000000000000018Initial program 99.3%
Taylor expanded in x around 0
Applied rewrites19.7%
Taylor expanded in x around 0
Applied rewrites48.6%
Taylor expanded in x around inf
Applied rewrites56.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (/ 2.0 3.0) z)) (t_1 (* (- y x) t_0)))
(if (<= t_0 0.21)
t_1
(if (<= t_0 4.8) (+ x (+ x (+ x (* (- y x) 6.0)))) t_1))))
double code(double x, double y, double z) {
double t_0 = (2.0 / 3.0) - z;
double t_1 = (y - x) * t_0;
double tmp;
if (t_0 <= 0.21) {
tmp = t_1;
} else if (t_0 <= 4.8) {
tmp = x + (x + (x + ((y - x) * 6.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 = (2.0d0 / 3.0d0) - z
t_1 = (y - x) * t_0
if (t_0 <= 0.21d0) then
tmp = t_1
else if (t_0 <= 4.8d0) then
tmp = x + (x + (x + ((y - x) * 6.0d0)))
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (2.0 / 3.0) - z;
double t_1 = (y - x) * t_0;
double tmp;
if (t_0 <= 0.21) {
tmp = t_1;
} else if (t_0 <= 4.8) {
tmp = x + (x + (x + ((y - x) * 6.0)));
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = (2.0 / 3.0) - z t_1 = (y - x) * t_0 tmp = 0 if t_0 <= 0.21: tmp = t_1 elif t_0 <= 4.8: tmp = x + (x + (x + ((y - x) * 6.0))) else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(Float64(2.0 / 3.0) - z) t_1 = Float64(Float64(y - x) * t_0) tmp = 0.0 if (t_0 <= 0.21) tmp = t_1; elseif (t_0 <= 4.8) tmp = Float64(x + Float64(x + Float64(x + Float64(Float64(y - x) * 6.0)))); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (2.0 / 3.0) - z; t_1 = (y - x) * t_0; tmp = 0.0; if (t_0 <= 0.21) tmp = t_1; elseif (t_0 <= 4.8) tmp = x + (x + (x + ((y - x) * 6.0))); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]}, Block[{t$95$1 = N[(N[(y - x), $MachinePrecision] * t$95$0), $MachinePrecision]}, If[LessEqual[t$95$0, 0.21], t$95$1, If[LessEqual[t$95$0, 4.8], N[(x + N[(x + N[(x + N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{3} - z\\
t_1 := \left(y - x\right) \cdot t\_0\\
\mathbf{if}\;t\_0 \leq 0.21:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 4.8:\\
\;\;\;\;x + \left(x + \left(x + \left(y - x\right) \cdot 6\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 0.209999999999999992 or 4.79999999999999982 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites98.5%
Taylor expanded in x around 0
Applied rewrites54.0%
if 0.209999999999999992 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 4.79999999999999982Initial program 99.3%
Taylor expanded in x around 0
Applied rewrites19.7%
Taylor expanded in x around 0
Applied rewrites48.6%
Taylor expanded in x around inf
Applied rewrites56.6%
(FPCore (x y z) :precision binary64 (if (<= x -3.2e+237) (+ x (+ x (+ x (* (- y x) 6.0)))) (* (* (- y x) (- (/ 2.0 3.0) z)) 6.0)))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.2e+237) {
tmp = x + (x + (x + ((y - x) * 6.0)));
} else {
tmp = ((y - x) * ((2.0 / 3.0) - 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 (x <= (-3.2d+237)) then
tmp = x + (x + (x + ((y - x) * 6.0d0)))
else
tmp = ((y - x) * ((2.0d0 / 3.0d0) - z)) * 6.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3.2e+237) {
tmp = x + (x + (x + ((y - x) * 6.0)));
} else {
tmp = ((y - x) * ((2.0 / 3.0) - z)) * 6.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.2e+237: tmp = x + (x + (x + ((y - x) * 6.0))) else: tmp = ((y - x) * ((2.0 / 3.0) - z)) * 6.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.2e+237) tmp = Float64(x + Float64(x + Float64(x + Float64(Float64(y - x) * 6.0)))); else tmp = Float64(Float64(Float64(y - x) * Float64(Float64(2.0 / 3.0) - z)) * 6.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.2e+237) tmp = x + (x + (x + ((y - x) * 6.0))); else tmp = ((y - x) * ((2.0 / 3.0) - z)) * 6.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.2e+237], N[(x + N[(x + N[(x + N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y - x), $MachinePrecision] * N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] * 6.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.2 \cdot 10^{+237}:\\
\;\;\;\;x + \left(x + \left(x + \left(y - x\right) \cdot 6\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(y - x\right) \cdot \left(\frac{2}{3} - z\right)\right) \cdot 6\\
\end{array}
\end{array}
if x < -3.20000000000000017e237Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites18.5%
Taylor expanded in x around 0
Applied rewrites9.2%
Taylor expanded in x around inf
Applied rewrites82.7%
if -3.20000000000000017e237 < x Initial program 99.5%
Taylor expanded in x around 0
Applied rewrites11.3%
Taylor expanded in x around 0
Applied rewrites75.8%
Taylor expanded in x around inf
Applied rewrites99.5%
Taylor expanded in x around 0
Applied rewrites80.4%
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) (- (/ 2.0 3.0) z)) 6.0)))
double code(double x, double y, double z) {
return x + (((y - x) * ((2.0 / 3.0) - z)) * 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 + (((y - x) * ((2.0d0 / 3.0d0) - z)) * 6.0d0)
end function
public static double code(double x, double y, double z) {
return x + (((y - x) * ((2.0 / 3.0) - z)) * 6.0);
}
def code(x, y, z): return x + (((y - x) * ((2.0 / 3.0) - z)) * 6.0)
function code(x, y, z) return Float64(x + Float64(Float64(Float64(y - x) * Float64(Float64(2.0 / 3.0) - z)) * 6.0)) end
function tmp = code(x, y, z) tmp = x + (((y - x) * ((2.0 / 3.0) - z)) * 6.0); end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] * 6.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(y - x\right) \cdot \left(\frac{2}{3} - z\right)\right) \cdot 6
\end{array}
Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites11.6%
Taylor expanded in x around 0
Applied rewrites73.0%
Taylor expanded in x around inf
Applied rewrites99.5%
(FPCore (x y z) :precision binary64 (+ x (+ x (+ x (* (- y x) 6.0)))))
double code(double x, double y, double z) {
return x + (x + (x + ((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 + (x + (x + ((y - x) * 6.0d0)))
end function
public static double code(double x, double y, double z) {
return x + (x + (x + ((y - x) * 6.0)));
}
def code(x, y, z): return x + (x + (x + ((y - x) * 6.0)))
function code(x, y, z) return Float64(x + Float64(x + Float64(x + Float64(Float64(y - x) * 6.0)))) end
function tmp = code(x, y, z) tmp = x + (x + (x + ((y - x) * 6.0))); end
code[x_, y_, z_] := N[(x + N[(x + N[(x + N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(x + \left(x + \left(y - x\right) \cdot 6\right)\right)
\end{array}
Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites11.6%
Taylor expanded in x around 0
Applied rewrites73.0%
Taylor expanded in x around inf
Applied rewrites30.5%
(FPCore (x y z) :precision binary64 (+ x (+ x (* (- y x) 6.0))))
double code(double x, double y, double z) {
return x + (x + ((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 + (x + ((y - x) * 6.0d0))
end function
public static double code(double x, double y, double z) {
return x + (x + ((y - x) * 6.0));
}
def code(x, y, z): return x + (x + ((y - x) * 6.0))
function code(x, y, z) return Float64(x + Float64(x + Float64(Float64(y - x) * 6.0))) end
function tmp = code(x, y, z) tmp = x + (x + ((y - x) * 6.0)); end
code[x_, y_, z_] := N[(x + N[(x + N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(x + \left(y - x\right) \cdot 6\right)
\end{array}
Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites11.6%
Taylor expanded in x around 0
Applied rewrites12.0%
(FPCore (x y z) :precision binary64 (+ x (* (- y x) 6.0)))
double code(double x, double y, double z) {
return x + ((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 + ((y - x) * 6.0d0)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) * 6.0);
}
def code(x, y, z): return x + ((y - x) * 6.0)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) * 6.0)) end
function tmp = code(x, y, z) tmp = x + ((y - x) * 6.0); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot 6
\end{array}
Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites11.6%
(FPCore (x y z) :precision binary64 (* (- y x) 6.0))
double code(double x, double y, double z) {
return (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 = (y - x) * 6.0d0
end function
public static double code(double x, double y, double z) {
return (y - x) * 6.0;
}
def code(x, y, z): return (y - x) * 6.0
function code(x, y, z) return Float64(Float64(y - x) * 6.0) end
function tmp = code(x, y, z) tmp = (y - x) * 6.0; end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision]
\begin{array}{l}
\\
\left(y - x\right) \cdot 6
\end{array}
Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites78.1%
Taylor expanded in x around 0
Applied rewrites11.4%
(FPCore (x y z) :precision binary64 (- y x))
double code(double x, double y, double z) {
return y - x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y - x
end function
public static double code(double x, double y, double z) {
return y - x;
}
def code(x, y, z): return y - x
function code(x, y, z) return Float64(y - x) end
function tmp = code(x, y, z) tmp = y - x; end
code[x_, y_, z_] := N[(y - x), $MachinePrecision]
\begin{array}{l}
\\
y - x
\end{array}
Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites78.1%
Taylor expanded in x around inf
Applied rewrites10.5%
herbie shell --seed 2024321
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, D"
:precision binary64
:pre (TRUE)
(+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))