
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
return x * (1.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 * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
def code(x, y, z): return x * (1.0 - (y * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(y * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - (y * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - y \cdot z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
return x * (1.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 * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
def code(x, y, z): return x * (1.0 - (y * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(y * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - (y * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - y \cdot z\right)
\end{array}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) -4e+271) (* y (* z (- x))) (if (<= (* y z) 5e+270) (* x (- 1.0 (* y z))) (* z (* x (- y))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -4e+271) {
tmp = y * (z * -x);
} else if ((y * z) <= 5e+270) {
tmp = x * (1.0 - (y * z));
} else {
tmp = z * (x * -y);
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 * z) <= (-4d+271)) then
tmp = y * (z * -x)
else if ((y * z) <= 5d+270) then
tmp = x * (1.0d0 - (y * z))
else
tmp = z * (x * -y)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -4e+271) {
tmp = y * (z * -x);
} else if ((y * z) <= 5e+270) {
tmp = x * (1.0 - (y * z));
} else {
tmp = z * (x * -y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -4e+271: tmp = y * (z * -x) elif (y * z) <= 5e+270: tmp = x * (1.0 - (y * z)) else: tmp = z * (x * -y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -4e+271) tmp = Float64(y * Float64(z * Float64(-x))); elseif (Float64(y * z) <= 5e+270) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(z * Float64(x * Float64(-y))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= -4e+271)
tmp = y * (z * -x);
elseif ((y * z) <= 5e+270)
tmp = x * (1.0 - (y * z));
else
tmp = z * (x * -y);
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -4e+271], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 5e+270], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -4 \cdot 10^{+271}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 5 \cdot 10^{+270}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -3.99999999999999981e271Initial program 67.0%
Taylor expanded in y around inf 67.0%
mul-1-neg67.0%
*-commutative67.0%
associate-*r*99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
if -3.99999999999999981e271 < (*.f64 y z) < 4.99999999999999976e270Initial program 99.9%
if 4.99999999999999976e270 < (*.f64 y z) Initial program 71.0%
Taylor expanded in z around inf 99.8%
Taylor expanded in y around inf 99.8%
neg-mul-199.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
Final simplification99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (* x (- y)))))
(if (<= (* y z) -4e+271)
t_0
(if (<= (* y z) -2000000.0)
(* x (* y (- z)))
(if (<= (* y z) 0.5) x t_0)))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = z * (x * -y);
double tmp;
if ((y * z) <= -4e+271) {
tmp = t_0;
} else if ((y * z) <= -2000000.0) {
tmp = x * (y * -z);
} else if ((y * z) <= 0.5) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 = z * (x * -y)
if ((y * z) <= (-4d+271)) then
tmp = t_0
else if ((y * z) <= (-2000000.0d0)) then
tmp = x * (y * -z)
else if ((y * z) <= 0.5d0) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = z * (x * -y);
double tmp;
if ((y * z) <= -4e+271) {
tmp = t_0;
} else if ((y * z) <= -2000000.0) {
tmp = x * (y * -z);
} else if ((y * z) <= 0.5) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = z * (x * -y) tmp = 0 if (y * z) <= -4e+271: tmp = t_0 elif (y * z) <= -2000000.0: tmp = x * (y * -z) elif (y * z) <= 0.5: tmp = x else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(z * Float64(x * Float64(-y))) tmp = 0.0 if (Float64(y * z) <= -4e+271) tmp = t_0; elseif (Float64(y * z) <= -2000000.0) tmp = Float64(x * Float64(y * Float64(-z))); elseif (Float64(y * z) <= 0.5) tmp = x; else tmp = t_0; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = z * (x * -y);
tmp = 0.0;
if ((y * z) <= -4e+271)
tmp = t_0;
elseif ((y * z) <= -2000000.0)
tmp = x * (y * -z);
elseif ((y * z) <= 0.5)
tmp = x;
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y * z), $MachinePrecision], -4e+271], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], -2000000.0], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 0.5], x, t$95$0]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := z \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{if}\;y \cdot z \leq -4 \cdot 10^{+271}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot z \leq -2000000:\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 0.5:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -3.99999999999999981e271 or 0.5 < (*.f64 y z) Initial program 85.0%
Taylor expanded in z around inf 92.4%
Taylor expanded in y around inf 92.4%
neg-mul-192.4%
distribute-rgt-neg-in92.4%
Simplified92.4%
if -3.99999999999999981e271 < (*.f64 y z) < -2e6Initial program 99.8%
Taylor expanded in y around inf 95.3%
mul-1-neg95.3%
distribute-rgt-neg-out95.3%
Simplified95.3%
if -2e6 < (*.f64 y z) < 0.5Initial program 99.9%
Taylor expanded in y around 0 98.1%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= (* y z) -2000000.0) (not (<= (* y z) 0.5))) (* x (* y (- z))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -2000000.0) || !((y * z) <= 0.5)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 * z) <= (-2000000.0d0)) .or. (.not. ((y * z) <= 0.5d0))) then
tmp = x * (y * -z)
else
tmp = x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -2000000.0) || !((y * z) <= 0.5)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -2000000.0) or not ((y * z) <= 0.5): tmp = x * (y * -z) else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -2000000.0) || !(Float64(y * z) <= 0.5)) tmp = Float64(x * Float64(y * Float64(-z))); else tmp = x; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (((y * z) <= -2000000.0) || ~(((y * z) <= 0.5)))
tmp = x * (y * -z);
else
tmp = x;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -2000000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.5]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -2000000 \lor \neg \left(y \cdot z \leq 0.5\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -2e6 or 0.5 < (*.f64 y z) Initial program 89.5%
Taylor expanded in y around inf 87.3%
mul-1-neg87.3%
distribute-rgt-neg-out87.3%
Simplified87.3%
if -2e6 < (*.f64 y z) < 0.5Initial program 99.9%
Taylor expanded in y around 0 98.1%
Final simplification92.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) -2000000.0) (* y (* z (- x))) (if (<= (* y z) 0.5) x (* z (* x (- y))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -2000000.0) {
tmp = y * (z * -x);
} else if ((y * z) <= 0.5) {
tmp = x;
} else {
tmp = z * (x * -y);
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 * z) <= (-2000000.0d0)) then
tmp = y * (z * -x)
else if ((y * z) <= 0.5d0) then
tmp = x
else
tmp = z * (x * -y)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -2000000.0) {
tmp = y * (z * -x);
} else if ((y * z) <= 0.5) {
tmp = x;
} else {
tmp = z * (x * -y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -2000000.0: tmp = y * (z * -x) elif (y * z) <= 0.5: tmp = x else: tmp = z * (x * -y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -2000000.0) tmp = Float64(y * Float64(z * Float64(-x))); elseif (Float64(y * z) <= 0.5) tmp = x; else tmp = Float64(z * Float64(x * Float64(-y))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= -2000000.0)
tmp = y * (z * -x);
elseif ((y * z) <= 0.5)
tmp = x;
else
tmp = z * (x * -y);
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -2000000.0], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 0.5], x, N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -2000000:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 0.5:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -2e6Initial program 88.0%
Taylor expanded in y around inf 85.1%
mul-1-neg85.1%
*-commutative85.1%
associate-*r*95.3%
distribute-rgt-neg-in95.3%
Simplified95.3%
if -2e6 < (*.f64 y z) < 0.5Initial program 99.9%
Taylor expanded in y around 0 98.1%
if 0.5 < (*.f64 y z) Initial program 90.8%
Taylor expanded in z around inf 90.0%
Taylor expanded in y around inf 90.1%
neg-mul-190.1%
distribute-rgt-neg-in90.1%
Simplified90.1%
Final simplification95.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) -2000000000.0) (/ (* z x) z) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -2000000000.0) {
tmp = (z * x) / z;
} else {
tmp = x;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 * z) <= (-2000000000.0d0)) then
tmp = (z * x) / z
else
tmp = x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -2000000000.0) {
tmp = (z * x) / z;
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -2000000000.0: tmp = (z * x) / z else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -2000000000.0) tmp = Float64(Float64(z * x) / z); else tmp = x; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= -2000000000.0)
tmp = (z * x) / z;
else
tmp = x;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -2000000000.0], N[(N[(z * x), $MachinePrecision] / z), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -2000000000:\\
\;\;\;\;\frac{z \cdot x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -2e9Initial program 87.4%
Taylor expanded in z around inf 92.3%
Taylor expanded in y around 0 11.1%
*-commutative11.1%
associate-*l/14.5%
Applied egg-rr14.5%
if -2e9 < (*.f64 y z) Initial program 96.6%
Taylor expanded in y around 0 61.7%
Final simplification50.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 x)
assert(x < y && y < z);
double code(double x, double y, double z) {
return x;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x
x, y, z = sort([x, y, z]) function code(x, y, z) return x end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := x
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x
\end{array}
Initial program 94.4%
Taylor expanded in y around 0 48.2%
herbie shell --seed 2024130
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))