
(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 5 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) -1e+247) (- (* z (* y x))) (if (<= (* y z) 5e+192) (- 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) <= -1e+247) {
tmp = -(z * (y * x));
} else if ((y * z) <= 5e+192) {
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) <= (-1d+247)) then
tmp = -(z * (y * x))
else if ((y * z) <= 5d+192) 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) <= -1e+247) {
tmp = -(z * (y * x));
} else if ((y * z) <= 5e+192) {
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) <= -1e+247: tmp = -(z * (y * x)) elif (y * z) <= 5e+192: 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) <= -1e+247) tmp = Float64(-Float64(z * Float64(y * x))); elseif (Float64(y * z) <= 5e+192) 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) <= -1e+247)
tmp = -(z * (y * x));
elseif ((y * z) <= 5e+192)
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], -1e+247], (-N[(z * N[(y * x), $MachinePrecision]), $MachinePrecision]), If[LessEqual[N[(y * z), $MachinePrecision], 5e+192], 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 -1 \cdot 10^{+247}:\\
\;\;\;\;-z \cdot \left(y \cdot x\right)\\
\mathbf{elif}\;y \cdot z \leq 5 \cdot 10^{+192}:\\
\;\;\;\;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) < -9.99999999999999952e246Initial program 57.3%
Taylor expanded in y around inf 57.3%
mul-1-neg57.3%
associate-*r*99.6%
Simplified99.6%
if -9.99999999999999952e246 < (*.f64 y z) < 5.00000000000000033e192Initial program 99.9%
sub-neg99.9%
distribute-rgt-in99.9%
*-un-lft-identity99.9%
distribute-rgt-neg-in99.9%
Applied egg-rr99.9%
if 5.00000000000000033e192 < (*.f64 y z) Initial program 82.8%
Taylor expanded in y around inf 82.8%
mul-1-neg82.8%
associate-*r*99.8%
distribute-rgt-neg-in99.8%
*-commutative99.8%
associate-*r*97.1%
distribute-rgt-neg-out97.1%
Simplified97.1%
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) -1e+247) (- (* z (* y x))) (if (<= (* y z) 5e+192) (* 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) <= -1e+247) {
tmp = -(z * (y * x));
} else if ((y * z) <= 5e+192) {
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) <= (-1d+247)) then
tmp = -(z * (y * x))
else if ((y * z) <= 5d+192) 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) <= -1e+247) {
tmp = -(z * (y * x));
} else if ((y * z) <= 5e+192) {
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) <= -1e+247: tmp = -(z * (y * x)) elif (y * z) <= 5e+192: 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) <= -1e+247) tmp = Float64(-Float64(z * Float64(y * x))); elseif (Float64(y * z) <= 5e+192) 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) <= -1e+247)
tmp = -(z * (y * x));
elseif ((y * z) <= 5e+192)
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], -1e+247], (-N[(z * N[(y * x), $MachinePrecision]), $MachinePrecision]), If[LessEqual[N[(y * z), $MachinePrecision], 5e+192], 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 -1 \cdot 10^{+247}:\\
\;\;\;\;-z \cdot \left(y \cdot x\right)\\
\mathbf{elif}\;y \cdot z \leq 5 \cdot 10^{+192}:\\
\;\;\;\;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) < -9.99999999999999952e246Initial program 57.3%
Taylor expanded in y around inf 57.3%
mul-1-neg57.3%
associate-*r*99.6%
Simplified99.6%
if -9.99999999999999952e246 < (*.f64 y z) < 5.00000000000000033e192Initial program 99.9%
if 5.00000000000000033e192 < (*.f64 y z) Initial program 82.8%
Taylor expanded in y around inf 82.8%
mul-1-neg82.8%
associate-*r*99.8%
distribute-rgt-neg-in99.8%
*-commutative99.8%
associate-*r*97.1%
distribute-rgt-neg-out97.1%
Simplified97.1%
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 (<= z -3.3e-90) (not (<= z 9e+110))) (- (* z (* y x))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.3e-90) || !(z <= 9e+110)) {
tmp = -(z * (y * 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 ((z <= (-3.3d-90)) .or. (.not. (z <= 9d+110))) then
tmp = -(z * (y * 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 ((z <= -3.3e-90) || !(z <= 9e+110)) {
tmp = -(z * (y * x));
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -3.3e-90) or not (z <= 9e+110): tmp = -(z * (y * x)) else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -3.3e-90) || !(z <= 9e+110)) tmp = Float64(-Float64(z * Float64(y * 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 ((z <= -3.3e-90) || ~((z <= 9e+110)))
tmp = -(z * (y * 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[z, -3.3e-90], N[Not[LessEqual[z, 9e+110]], $MachinePrecision]], (-N[(z * N[(y * x), $MachinePrecision]), $MachinePrecision]), x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{-90} \lor \neg \left(z \leq 9 \cdot 10^{+110}\right):\\
\;\;\;\;-z \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.3e-90 or 9.0000000000000005e110 < z Initial program 89.9%
Taylor expanded in y around inf 62.7%
mul-1-neg62.7%
associate-*r*68.6%
Simplified68.6%
if -3.3e-90 < z < 9.0000000000000005e110Initial program 99.2%
Taylor expanded in y around 0 80.3%
Final simplification74.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z -1.75e-90) (* y (* z (- x))) (if (<= z 9.8e+112) x (- (* z (* y x))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (z <= -1.75e-90) {
tmp = y * (z * -x);
} else if (z <= 9.8e+112) {
tmp = x;
} else {
tmp = -(z * (y * 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 (z <= (-1.75d-90)) then
tmp = y * (z * -x)
else if (z <= 9.8d+112) then
tmp = x
else
tmp = -(z * (y * 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 (z <= -1.75e-90) {
tmp = y * (z * -x);
} else if (z <= 9.8e+112) {
tmp = x;
} else {
tmp = -(z * (y * x));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if z <= -1.75e-90: tmp = y * (z * -x) elif z <= 9.8e+112: tmp = x else: tmp = -(z * (y * x)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (z <= -1.75e-90) tmp = Float64(y * Float64(z * Float64(-x))); elseif (z <= 9.8e+112) tmp = x; else tmp = Float64(-Float64(z * Float64(y * x))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= -1.75e-90)
tmp = y * (z * -x);
elseif (z <= 9.8e+112)
tmp = x;
else
tmp = -(z * (y * 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[z, -1.75e-90], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 9.8e+112], x, (-N[(z * N[(y * x), $MachinePrecision]), $MachinePrecision])]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.75 \cdot 10^{-90}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{elif}\;z \leq 9.8 \cdot 10^{+112}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;-z \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if z < -1.7499999999999999e-90Initial program 91.2%
Taylor expanded in y around inf 60.0%
mul-1-neg60.0%
associate-*r*65.1%
distribute-rgt-neg-in65.1%
*-commutative65.1%
associate-*r*64.1%
distribute-rgt-neg-out64.1%
Simplified64.1%
if -1.7499999999999999e-90 < z < 9.80000000000000008e112Initial program 99.2%
Taylor expanded in y around 0 80.3%
if 9.80000000000000008e112 < z Initial program 86.2%
Taylor expanded in y around inf 70.2%
mul-1-neg70.2%
associate-*r*78.4%
Simplified78.4%
Final simplification73.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 94.3%
Taylor expanded in y around 0 52.8%
Final simplification52.8%
herbie shell --seed 2024011
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))