
(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+99) (* x (- 1.0 (* y z))) (* y (* x (- z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 2e+99) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (x * -z);
}
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+99) then
tmp = x * (1.0d0 - (y * z))
else
tmp = y * (x * -z)
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+99) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (x * -z);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 2e+99: tmp = x * (1.0 - (y * z)) else: tmp = y * (x * -z) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 2e+99) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(y * Float64(x * Float64(-z))); 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+99)
tmp = x * (1.0 - (y * z));
else
tmp = y * (x * -z);
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+99], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(x * (-z)), $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^{+99}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 1.9999999999999999e99Initial program 98.4%
if 1.9999999999999999e99 < (*.f64 y z) Initial program 81.9%
Taylor expanded in y around inf 81.9%
mul-1-neg81.9%
associate-*r*99.8%
distribute-rgt-neg-in99.8%
*-commutative99.8%
associate-*l*99.9%
Simplified99.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (* y (- z)))))
(if (<= (* y z) -4e+35)
t_0
(if (<= (* y z) 2e-8) x (if (<= (* y z) 1e+186) t_0 (* z (* x (- y))))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = x * (y * -z);
double tmp;
if ((y * z) <= -4e+35) {
tmp = t_0;
} else if ((y * z) <= 2e-8) {
tmp = x;
} else if ((y * z) <= 1e+186) {
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 = x * (y * -z)
if ((y * z) <= (-4d+35)) then
tmp = t_0
else if ((y * z) <= 2d-8) then
tmp = x
else if ((y * z) <= 1d+186) 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 = x * (y * -z);
double tmp;
if ((y * z) <= -4e+35) {
tmp = t_0;
} else if ((y * z) <= 2e-8) {
tmp = x;
} else if ((y * z) <= 1e+186) {
tmp = t_0;
} else {
tmp = z * (x * -y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = x * (y * -z) tmp = 0 if (y * z) <= -4e+35: tmp = t_0 elif (y * z) <= 2e-8: tmp = x elif (y * z) <= 1e+186: 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(x * Float64(y * Float64(-z))) tmp = 0.0 if (Float64(y * z) <= -4e+35) tmp = t_0; elseif (Float64(y * z) <= 2e-8) tmp = x; elseif (Float64(y * z) <= 1e+186) 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 = x * (y * -z);
tmp = 0.0;
if ((y * z) <= -4e+35)
tmp = t_0;
elseif ((y * z) <= 2e-8)
tmp = x;
elseif ((y * z) <= 1e+186)
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[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y * z), $MachinePrecision], -4e+35], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], 2e-8], x, If[LessEqual[N[(y * z), $MachinePrecision], 1e+186], 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 := x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{if}\;y \cdot z \leq -4 \cdot 10^{+35}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot z \leq 2 \cdot 10^{-8}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \cdot z \leq 10^{+186}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -3.9999999999999999e35 or 2e-8 < (*.f64 y z) < 9.9999999999999998e185Initial program 97.0%
Taylor expanded in y around inf 96.1%
mul-1-neg96.1%
associate-*r*89.7%
Simplified89.7%
Taylor expanded in x around 0 96.1%
if -3.9999999999999999e35 < (*.f64 y z) < 2e-8Initial program 100.0%
Taylor expanded in y around 0 98.9%
if 9.9999999999999998e185 < (*.f64 y z) Initial program 75.5%
Taylor expanded in y around inf 75.5%
mul-1-neg75.5%
associate-*r*99.7%
Simplified99.7%
Final simplification97.9%
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) -4e+35) (not (<= (* y z) 2e-8))) (* y (* x (- z))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -4e+35) || !((y * z) <= 2e-8)) {
tmp = y * (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) <= (-4d+35)) .or. (.not. ((y * z) <= 2d-8))) then
tmp = y * (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) <= -4e+35) || !((y * z) <= 2e-8)) {
tmp = y * (x * -z);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -4e+35) or not ((y * z) <= 2e-8): tmp = y * (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) <= -4e+35) || !(Float64(y * z) <= 2e-8)) tmp = Float64(y * Float64(x * 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) <= -4e+35) || ~(((y * z) <= 2e-8)))
tmp = y * (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[Or[LessEqual[N[(y * z), $MachinePrecision], -4e+35], N[Not[LessEqual[N[(y * z), $MachinePrecision], 2e-8]], $MachinePrecision]], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -4 \cdot 10^{+35} \lor \neg \left(y \cdot z \leq 2 \cdot 10^{-8}\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -3.9999999999999999e35 or 2e-8 < (*.f64 y z) Initial program 90.6%
Taylor expanded in y around inf 90.0%
mul-1-neg90.0%
associate-*r*92.7%
distribute-rgt-neg-in92.7%
*-commutative92.7%
associate-*l*93.1%
Simplified93.1%
if -3.9999999999999999e35 < (*.f64 y z) < 2e-8Initial program 100.0%
Taylor expanded in y around 0 98.9%
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 (or (<= (* y z) -1.0) (not (<= (* y z) 1.0))) (* x (* y (- z))) 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 = 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) <= (-1.0d0)) .or. (.not. ((y * z) <= 1.0d0))) 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) <= -1.0) || !((y * z) <= 1.0)) {
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) <= -1.0) or not ((y * z) <= 1.0): 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) <= -1.0) || !(Float64(y * z) <= 1.0)) 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) <= -1.0) || ~(((y * z) <= 1.0)))
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], -1.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 1.0]], $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 -1 \lor \neg \left(y \cdot z \leq 1\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\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 90.0%
mul-1-neg90.0%
associate-*r*92.7%
Simplified92.7%
Taylor expanded in x around 0 90.0%
if -1 < (*.f64 y z) < 1Initial program 100.0%
Taylor expanded in y around 0 98.9%
Final simplification93.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- x (* y (* x z))))
assert(x < y && y < z);
double code(double x, double y, double z) {
return x - (y * (x * z));
}
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 - (y * (x * z))
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x - (y * (x * z));
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x - (y * (x * z))
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(x - Float64(y * Float64(x * z))) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x - (y * (x * z));
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x - N[(y * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x - y \cdot \left(x \cdot z\right)
\end{array}
Initial program 94.7%
sub-neg94.7%
distribute-rgt-in94.7%
*-un-lft-identity94.7%
distribute-rgt-neg-in94.7%
Applied egg-rr94.7%
add-sqr-sqrt55.8%
sqrt-unprod63.4%
distribute-rgt-neg-out63.4%
distribute-rgt-neg-out63.4%
sqr-neg63.4%
sqrt-prod26.7%
add-sqr-sqrt43.4%
cancel-sign-sub43.4%
distribute-rgt-neg-out43.4%
associate-*l*43.1%
add-sqr-sqrt22.8%
sqrt-unprod60.4%
sqr-neg60.4%
sqrt-unprod48.2%
add-sqr-sqrt95.9%
Applied egg-rr95.9%
Final simplification95.9%
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 44.8%
herbie shell --seed 2024091
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))