
(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) -5e+101) (* (* y x) (- z)) (if (<= (* y z) 4e+222) (- x (* (* y z) x)) (* y (* z (- x))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+101) {
tmp = (y * x) * -z;
} else if ((y * z) <= 4e+222) {
tmp = x - ((y * z) * x);
} else {
tmp = y * (z * -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) <= (-5d+101)) then
tmp = (y * x) * -z
else if ((y * z) <= 4d+222) then
tmp = x - ((y * z) * x)
else
tmp = y * (z * -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) <= -5e+101) {
tmp = (y * x) * -z;
} else if ((y * z) <= 4e+222) {
tmp = x - ((y * z) * x);
} else {
tmp = y * (z * -x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -5e+101: tmp = (y * x) * -z elif (y * z) <= 4e+222: tmp = x - ((y * z) * x) else: tmp = y * (z * -x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -5e+101) tmp = Float64(Float64(y * x) * Float64(-z)); elseif (Float64(y * z) <= 4e+222) tmp = Float64(x - Float64(Float64(y * z) * x)); else tmp = Float64(y * Float64(z * Float64(-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) <= -5e+101)
tmp = (y * x) * -z;
elseif ((y * z) <= 4e+222)
tmp = x - ((y * z) * x);
else
tmp = y * (z * -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], -5e+101], N[(N[(y * x), $MachinePrecision] * (-z)), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 4e+222], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+101}:\\
\;\;\;\;\left(y \cdot x\right) \cdot \left(-z\right)\\
\mathbf{elif}\;y \cdot z \leq 4 \cdot 10^{+222}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -4.99999999999999989e101Initial program 86.1%
Taylor expanded in y around inf 86.1%
mul-1-neg86.1%
associate-*r*97.8%
Simplified97.8%
if -4.99999999999999989e101 < (*.f64 y z) < 4.0000000000000002e222Initial program 99.9%
sub-neg99.9%
distribute-rgt-in99.9%
*-un-lft-identity99.9%
distribute-rgt-neg-in99.9%
Applied egg-rr99.9%
add-sqr-sqrt51.8%
sqrt-unprod78.2%
distribute-rgt-neg-out78.2%
distribute-rgt-neg-out78.2%
sqr-neg78.2%
sqrt-prod39.1%
add-sqr-sqrt66.2%
cancel-sign-sub66.2%
distribute-rgt-neg-out66.2%
associate-*l*62.2%
add-sqr-sqrt29.6%
sqrt-unprod65.7%
sqr-neg65.7%
sqrt-unprod43.5%
add-sqr-sqrt90.8%
Applied egg-rr90.8%
Taylor expanded in y around 0 99.9%
if 4.0000000000000002e222 < (*.f64 y z) Initial program 79.7%
Taylor expanded in y around inf 79.7%
mul-1-neg79.7%
associate-*r*99.9%
distribute-rgt-neg-in99.9%
*-commutative99.9%
associate-*l*100.0%
Simplified100.0%
Final simplification99.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= (* y z) -5000000000000.0)
(* (* y x) (- z))
(if (<= (* y z) 0.1)
x
(if (<= (* y z) 4e+222) (* (* y z) (- x)) (* y (* z (- x)))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5000000000000.0) {
tmp = (y * x) * -z;
} else if ((y * z) <= 0.1) {
tmp = x;
} else if ((y * z) <= 4e+222) {
tmp = (y * z) * -x;
} else {
tmp = y * (z * -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) <= (-5000000000000.0d0)) then
tmp = (y * x) * -z
else if ((y * z) <= 0.1d0) then
tmp = x
else if ((y * z) <= 4d+222) then
tmp = (y * z) * -x
else
tmp = y * (z * -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) <= -5000000000000.0) {
tmp = (y * x) * -z;
} else if ((y * z) <= 0.1) {
tmp = x;
} else if ((y * z) <= 4e+222) {
tmp = (y * z) * -x;
} else {
tmp = y * (z * -x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -5000000000000.0: tmp = (y * x) * -z elif (y * z) <= 0.1: tmp = x elif (y * z) <= 4e+222: tmp = (y * z) * -x else: tmp = y * (z * -x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -5000000000000.0) tmp = Float64(Float64(y * x) * Float64(-z)); elseif (Float64(y * z) <= 0.1) tmp = x; elseif (Float64(y * z) <= 4e+222) tmp = Float64(Float64(y * z) * Float64(-x)); else tmp = Float64(y * Float64(z * Float64(-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) <= -5000000000000.0)
tmp = (y * x) * -z;
elseif ((y * z) <= 0.1)
tmp = x;
elseif ((y * z) <= 4e+222)
tmp = (y * z) * -x;
else
tmp = y * (z * -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], -5000000000000.0], N[(N[(y * x), $MachinePrecision] * (-z)), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 0.1], x, If[LessEqual[N[(y * z), $MachinePrecision], 4e+222], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5000000000000:\\
\;\;\;\;\left(y \cdot x\right) \cdot \left(-z\right)\\
\mathbf{elif}\;y \cdot z \leq 0.1:\\
\;\;\;\;x\\
\mathbf{elif}\;y \cdot z \leq 4 \cdot 10^{+222}:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -5e12Initial program 89.8%
Taylor expanded in y around inf 89.5%
mul-1-neg89.5%
associate-*r*95.1%
Simplified95.1%
if -5e12 < (*.f64 y z) < 0.10000000000000001Initial program 100.0%
Taylor expanded in y around 0 94.7%
if 0.10000000000000001 < (*.f64 y z) < 4.0000000000000002e222Initial program 99.7%
Taylor expanded in y around inf 99.7%
mul-1-neg99.7%
associate-*r*87.9%
Simplified87.9%
Taylor expanded in x around 0 99.7%
if 4.0000000000000002e222 < (*.f64 y z) Initial program 79.7%
Taylor expanded in y around inf 79.7%
mul-1-neg79.7%
associate-*r*99.9%
distribute-rgt-neg-in99.9%
*-commutative99.9%
associate-*l*100.0%
Simplified100.0%
Final simplification96.1%
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 x) (- z))))
(if (<= (* y z) -5000000000000.0)
t_0
(if (<= (* y z) 0.1) x (if (<= (* y z) 4e+222) (* (* y z) (- x)) t_0)))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = (y * x) * -z;
double tmp;
if ((y * z) <= -5000000000000.0) {
tmp = t_0;
} else if ((y * z) <= 0.1) {
tmp = x;
} else if ((y * z) <= 4e+222) {
tmp = (y * z) * -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 = (y * x) * -z
if ((y * z) <= (-5000000000000.0d0)) then
tmp = t_0
else if ((y * z) <= 0.1d0) then
tmp = x
else if ((y * z) <= 4d+222) then
tmp = (y * z) * -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 = (y * x) * -z;
double tmp;
if ((y * z) <= -5000000000000.0) {
tmp = t_0;
} else if ((y * z) <= 0.1) {
tmp = x;
} else if ((y * z) <= 4e+222) {
tmp = (y * z) * -x;
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = (y * x) * -z tmp = 0 if (y * z) <= -5000000000000.0: tmp = t_0 elif (y * z) <= 0.1: tmp = x elif (y * z) <= 4e+222: tmp = (y * z) * -x else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(y * x) * Float64(-z)) tmp = 0.0 if (Float64(y * z) <= -5000000000000.0) tmp = t_0; elseif (Float64(y * z) <= 0.1) tmp = x; elseif (Float64(y * z) <= 4e+222) tmp = Float64(Float64(y * z) * Float64(-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 = (y * x) * -z;
tmp = 0.0;
if ((y * z) <= -5000000000000.0)
tmp = t_0;
elseif ((y * z) <= 0.1)
tmp = x;
elseif ((y * z) <= 4e+222)
tmp = (y * z) * -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[(N[(y * x), $MachinePrecision] * (-z)), $MachinePrecision]}, If[LessEqual[N[(y * z), $MachinePrecision], -5000000000000.0], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], 0.1], x, If[LessEqual[N[(y * z), $MachinePrecision], 4e+222], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(y \cdot x\right) \cdot \left(-z\right)\\
\mathbf{if}\;y \cdot z \leq -5000000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot z \leq 0.1:\\
\;\;\;\;x\\
\mathbf{elif}\;y \cdot z \leq 4 \cdot 10^{+222}:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -5e12 or 4.0000000000000002e222 < (*.f64 y z) Initial program 86.8%
Taylor expanded in y around inf 86.6%
mul-1-neg86.6%
associate-*r*96.5%
Simplified96.5%
if -5e12 < (*.f64 y z) < 0.10000000000000001Initial program 100.0%
Taylor expanded in y around 0 94.7%
if 0.10000000000000001 < (*.f64 y z) < 4.0000000000000002e222Initial program 99.7%
Taylor expanded in y around inf 99.7%
mul-1-neg99.7%
associate-*r*87.9%
Simplified87.9%
Taylor expanded in x around 0 99.7%
Final simplification96.1%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) -5e+101) (* (* y x) (- z)) (if (<= (* y z) 4e+222) (* x (- 1.0 (* y z))) (* y (* z (- x))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+101) {
tmp = (y * x) * -z;
} else if ((y * z) <= 4e+222) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (z * -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) <= (-5d+101)) then
tmp = (y * x) * -z
else if ((y * z) <= 4d+222) then
tmp = x * (1.0d0 - (y * z))
else
tmp = y * (z * -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) <= -5e+101) {
tmp = (y * x) * -z;
} else if ((y * z) <= 4e+222) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (z * -x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -5e+101: tmp = (y * x) * -z elif (y * z) <= 4e+222: tmp = x * (1.0 - (y * z)) else: tmp = y * (z * -x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -5e+101) tmp = Float64(Float64(y * x) * Float64(-z)); elseif (Float64(y * z) <= 4e+222) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(y * Float64(z * Float64(-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) <= -5e+101)
tmp = (y * x) * -z;
elseif ((y * z) <= 4e+222)
tmp = x * (1.0 - (y * z));
else
tmp = y * (z * -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], -5e+101], N[(N[(y * x), $MachinePrecision] * (-z)), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 4e+222], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+101}:\\
\;\;\;\;\left(y \cdot x\right) \cdot \left(-z\right)\\
\mathbf{elif}\;y \cdot z \leq 4 \cdot 10^{+222}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -4.99999999999999989e101Initial program 86.1%
Taylor expanded in y around inf 86.1%
mul-1-neg86.1%
associate-*r*97.8%
Simplified97.8%
if -4.99999999999999989e101 < (*.f64 y z) < 4.0000000000000002e222Initial program 99.9%
if 4.0000000000000002e222 < (*.f64 y z) Initial program 79.7%
Taylor expanded in y around inf 79.7%
mul-1-neg79.7%
associate-*r*99.9%
distribute-rgt-neg-in99.9%
*-commutative99.9%
associate-*l*100.0%
Simplified100.0%
Final simplification99.5%
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) -1.0) (not (<= (* y z) 1.0))) (* (* y z) (- x)) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -1.0) || !((y * z) <= 1.0)) {
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) <= (-1.0d0)) .or. (.not. ((y * z) <= 1.0d0))) 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) <= -1.0) || !((y * z) <= 1.0)) {
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) <= -1.0) or not ((y * z) <= 1.0): 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) <= -1.0) || !(Float64(y * z) <= 1.0)) 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) <= -1.0) || ~(((y * z) <= 1.0)))
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], -1.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 1.0]], $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 -1 \lor \neg \left(y \cdot z \leq 1\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -1 or 1 < (*.f64 y z) Initial program 90.6%
Taylor expanded in y around inf 89.7%
mul-1-neg89.7%
associate-*r*93.1%
Simplified93.1%
Taylor expanded in x around 0 89.7%
if -1 < (*.f64 y z) < 1Initial program 100.0%
Taylor expanded in y around 0 96.1%
Final simplification92.8%
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 95.1%
Taylor expanded in y around 0 48.3%
herbie shell --seed 2024085
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))