
(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) 2e+165) (- x (* (* y z) x)) (* z (* x (- y)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 2e+165) {
tmp = x - ((y * z) * 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) <= 2d+165) then
tmp = x - ((y * z) * 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) <= 2e+165) {
tmp = x - ((y * z) * 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) <= 2e+165: tmp = x - ((y * z) * 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) <= 2e+165) tmp = Float64(x - Float64(Float64(y * z) * 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) <= 2e+165)
tmp = x - ((y * z) * 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], 2e+165], N[(x - N[(N[(y * z), $MachinePrecision] * x), $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 2 \cdot 10^{+165}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 1.9999999999999998e165Initial program 98.1%
flip--85.6%
associate-*r/82.7%
metadata-eval82.7%
pow282.7%
+-commutative82.7%
fma-define82.7%
Applied egg-rr82.7%
*-commutative82.7%
associate-/l*82.5%
Simplified82.5%
Taylor expanded in y around 0 98.2%
associate-*r*98.2%
neg-mul-198.2%
cancel-sign-sub-inv98.2%
Simplified98.2%
if 1.9999999999999998e165 < (*.f64 y z) Initial program 73.5%
Taylor expanded in y around inf 73.5%
mul-1-neg73.5%
associate-*r*97.0%
Simplified97.0%
Final simplification98.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (* y z) (- x))))
(if (<= (* y z) -20.0)
t_0
(if (<= (* y z) 5e-5) x (if (<= (* y z) 2e+165) t_0 (* z (* x (- y))))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = (y * z) * -x;
double tmp;
if ((y * z) <= -20.0) {
tmp = t_0;
} else if ((y * z) <= 5e-5) {
tmp = x;
} else if ((y * z) <= 2e+165) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = (y * z) * -x
if ((y * z) <= (-20.0d0)) then
tmp = t_0
else if ((y * z) <= 5d-5) then
tmp = x
else if ((y * z) <= 2d+165) then
tmp = t_0
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 t_0 = (y * z) * -x;
double tmp;
if ((y * z) <= -20.0) {
tmp = t_0;
} else if ((y * z) <= 5e-5) {
tmp = x;
} else if ((y * z) <= 2e+165) {
tmp = t_0;
} else {
tmp = z * (x * -y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = (y * z) * -x tmp = 0 if (y * z) <= -20.0: tmp = t_0 elif (y * z) <= 5e-5: tmp = x elif (y * z) <= 2e+165: tmp = t_0 else: tmp = z * (x * -y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(y * z) * Float64(-x)) tmp = 0.0 if (Float64(y * z) <= -20.0) tmp = t_0; elseif (Float64(y * z) <= 5e-5) tmp = x; elseif (Float64(y * z) <= 2e+165) tmp = t_0; 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)
t_0 = (y * z) * -x;
tmp = 0.0;
if ((y * z) <= -20.0)
tmp = t_0;
elseif ((y * z) <= 5e-5)
tmp = x;
elseif ((y * z) <= 2e+165)
tmp = t_0;
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_] := Block[{t$95$0 = N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision]}, If[LessEqual[N[(y * z), $MachinePrecision], -20.0], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], 5e-5], x, If[LessEqual[N[(y * z), $MachinePrecision], 2e+165], t$95$0, N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{if}\;y \cdot z \leq -20:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot z \leq 5 \cdot 10^{-5}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \cdot z \leq 2 \cdot 10^{+165}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -20 or 5.00000000000000024e-5 < (*.f64 y z) < 1.9999999999999998e165Initial program 95.9%
Taylor expanded in y around inf 93.9%
mul-1-neg93.9%
associate-*r*86.9%
Simplified86.9%
Taylor expanded in x around 0 93.9%
if -20 < (*.f64 y z) < 5.00000000000000024e-5Initial program 100.0%
Taylor expanded in y around 0 96.6%
if 1.9999999999999998e165 < (*.f64 y z) Initial program 73.5%
Taylor expanded in y around inf 73.5%
mul-1-neg73.5%
associate-*r*97.0%
Simplified97.0%
Final simplification95.6%
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 (* x (- z)))
(if (<= (* y z) 5e-5)
x
(if (<= (* y z) 2e+165) (* (* y z) (- 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 * (x * -z);
} else if ((y * z) <= 5e-5) {
tmp = x;
} else if ((y * z) <= 2e+165) {
tmp = (y * z) * -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 * (x * -z)
else if ((y * z) <= 5d-5) then
tmp = x
else if ((y * z) <= 2d+165) then
tmp = (y * z) * -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 * (x * -z);
} else if ((y * z) <= 5e-5) {
tmp = x;
} else if ((y * z) <= 2e+165) {
tmp = (y * z) * -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 * (x * -z) elif (y * z) <= 5e-5: tmp = x elif (y * z) <= 2e+165: tmp = (y * z) * -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(x * Float64(-z))); elseif (Float64(y * z) <= 5e-5) tmp = x; elseif (Float64(y * z) <= 2e+165) tmp = Float64(Float64(y * z) * Float64(-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 * (x * -z);
elseif ((y * z) <= 5e-5)
tmp = x;
elseif ((y * z) <= 2e+165)
tmp = (y * z) * -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[(x * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 5e-5], x, If[LessEqual[N[(y * z), $MachinePrecision], 2e+165], N[(N[(y * z), $MachinePrecision] * (-x)), $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 -2000000:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 5 \cdot 10^{-5}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \cdot z \leq 2 \cdot 10^{+165}:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -2e6Initial program 94.1%
Taylor expanded in y around inf 93.4%
mul-1-neg93.4%
associate-*r*91.9%
distribute-rgt-neg-in91.9%
*-commutative91.9%
associate-*l*96.1%
Simplified96.1%
if -2e6 < (*.f64 y z) < 5.00000000000000024e-5Initial program 100.0%
Taylor expanded in y around 0 95.9%
if 5.00000000000000024e-5 < (*.f64 y z) < 1.9999999999999998e165Initial program 99.6%
Taylor expanded in y around inf 97.2%
mul-1-neg97.2%
associate-*r*78.2%
Simplified78.2%
Taylor expanded in x around 0 97.2%
if 1.9999999999999998e165 < (*.f64 y z) Initial program 73.5%
Taylor expanded in y around inf 73.5%
mul-1-neg73.5%
associate-*r*97.0%
Simplified97.0%
Final simplification96.3%
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) -20.0) (not (<= (* y z) 5e-5))) (* (* y z) (- x)) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -20.0) || !((y * z) <= 5e-5)) {
tmp = (y * z) * -x;
} 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) <= (-20.0d0)) .or. (.not. ((y * z) <= 5d-5))) then
tmp = (y * z) * -x
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) <= -20.0) || !((y * z) <= 5e-5)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -20.0) or not ((y * z) <= 5e-5): tmp = (y * z) * -x else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -20.0) || !(Float64(y * z) <= 5e-5)) tmp = Float64(Float64(y * z) * Float64(-x)); 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) <= -20.0) || ~(((y * z) <= 5e-5)))
tmp = (y * z) * -x;
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], -20.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 5e-5]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -20 \lor \neg \left(y \cdot z \leq 5 \cdot 10^{-5}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -20 or 5.00000000000000024e-5 < (*.f64 y z) Initial program 90.0%
Taylor expanded in y around inf 88.5%
mul-1-neg88.5%
associate-*r*89.6%
Simplified89.6%
Taylor expanded in x around 0 88.5%
if -20 < (*.f64 y z) < 5.00000000000000024e-5Initial program 100.0%
Taylor expanded in y around 0 96.6%
Final simplification92.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) 2e+165) (* 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) <= 2e+165) {
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) <= 2d+165) 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) <= 2e+165) {
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) <= 2e+165: 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) <= 2e+165) 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) <= 2e+165)
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], 2e+165], 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 2 \cdot 10^{+165}:\\
\;\;\;\;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) < 1.9999999999999998e165Initial program 98.1%
if 1.9999999999999998e165 < (*.f64 y z) Initial program 73.5%
Taylor expanded in y around inf 73.5%
mul-1-neg73.5%
associate-*r*97.0%
Simplified97.0%
Final simplification98.0%
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.7%
Taylor expanded in y around 0 47.2%
Final simplification47.2%
herbie shell --seed 2024080
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))