
(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: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) (- INFINITY)) (- x (* z (* y x))) (if (<= (* y z) 5e+257) (- x (* (* y z) x)) (- x (* y (* z x))))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -((double) INFINITY)) {
tmp = x - (z * (y * x));
} else if ((y * z) <= 5e+257) {
tmp = x - ((y * z) * x);
} else {
tmp = x - (y * (z * x));
}
return tmp;
}
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -Double.POSITIVE_INFINITY) {
tmp = x - (z * (y * x));
} else if ((y * z) <= 5e+257) {
tmp = x - ((y * z) * x);
} else {
tmp = x - (y * (z * x));
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -math.inf: tmp = x - (z * (y * x)) elif (y * z) <= 5e+257: tmp = x - ((y * z) * x) else: tmp = x - (y * (z * x)) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= Float64(-Inf)) tmp = Float64(x - Float64(z * Float64(y * x))); elseif (Float64(y * z) <= 5e+257) tmp = Float64(x - Float64(Float64(y * z) * x)); else tmp = Float64(x - Float64(y * Float64(z * x))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= -Inf)
tmp = x - (z * (y * x));
elseif ((y * z) <= 5e+257)
tmp = x - ((y * z) * x);
else
tmp = x - (y * (z * x));
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], (-Infinity)], N[(x - N[(z * N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 5e+257], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(x - N[(y * N[(z * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -\infty:\\
\;\;\;\;x - z \cdot \left(y \cdot x\right)\\
\mathbf{elif}\;y \cdot z \leq 5 \cdot 10^{+257}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot \left(z \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0Initial program 58.2%
Taylor expanded in y around 0 58.2%
mul-1-neg58.2%
Simplified58.2%
expm1-log1p-u23.7%
expm1-udef23.7%
Applied egg-rr23.7%
expm1-def23.7%
expm1-log1p58.2%
associate-*r*99.7%
Simplified99.7%
if -inf.0 < (*.f64 y z) < 5.00000000000000028e257Initial program 99.9%
Taylor expanded in y around 0 99.9%
mul-1-neg99.9%
Simplified99.9%
if 5.00000000000000028e257 < (*.f64 y z) Initial program 57.4%
Taylor expanded in y around 0 57.4%
mul-1-neg57.4%
Simplified57.4%
add-sqr-sqrt37.5%
pow237.5%
Applied egg-rr37.5%
unpow237.5%
add-sqr-sqrt57.4%
associate-*r*99.8%
*-commutative99.8%
associate-*r*99.8%
Applied egg-rr99.8%
Final simplification99.9%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= (* y z) (- INFINITY)) (not (<= (* y z) 5e+288))) (- x (* z (* y x))) (- x (* (* y z) x))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -((double) INFINITY)) || !((y * z) <= 5e+288)) {
tmp = x - (z * (y * x));
} else {
tmp = x - ((y * z) * x);
}
return tmp;
}
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -Double.POSITIVE_INFINITY) || !((y * z) <= 5e+288)) {
tmp = x - (z * (y * x));
} else {
tmp = x - ((y * z) * x);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -math.inf) or not ((y * z) <= 5e+288): tmp = x - (z * (y * x)) else: tmp = x - ((y * z) * x) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= Float64(-Inf)) || !(Float64(y * z) <= 5e+288)) tmp = Float64(x - Float64(z * Float64(y * x))); else tmp = Float64(x - Float64(Float64(y * z) * x)); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (((y * z) <= -Inf) || ~(((y * z) <= 5e+288)))
tmp = x - (z * (y * x));
else
tmp = x - ((y * z) * x);
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], (-Infinity)], N[Not[LessEqual[N[(y * z), $MachinePrecision], 5e+288]], $MachinePrecision]], N[(x - N[(z * N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -\infty \lor \neg \left(y \cdot z \leq 5 \cdot 10^{+288}\right):\\
\;\;\;\;x - z \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0 or 5.0000000000000003e288 < (*.f64 y z) Initial program 54.3%
Taylor expanded in y around 0 54.3%
mul-1-neg54.3%
Simplified54.3%
expm1-log1p-u28.3%
expm1-udef28.3%
Applied egg-rr28.3%
expm1-def28.3%
expm1-log1p54.3%
associate-*r*99.7%
Simplified99.7%
if -inf.0 < (*.f64 y z) < 5.0000000000000003e288Initial program 99.9%
Taylor expanded in y around 0 99.9%
mul-1-neg99.9%
Simplified99.9%
Final simplification99.9%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -8.5e-131) (not (<= z 1.25e+151))) (* (* y z) (- x)) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.5e-131) || !(z <= 1.25e+151)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
NOTE: 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 <= (-8.5d-131)) .or. (.not. (z <= 1.25d+151))) then
tmp = (y * z) * -x
else
tmp = x
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -8.5e-131) || !(z <= 1.25e+151)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (z <= -8.5e-131) or not (z <= 1.25e+151): tmp = (y * z) * -x else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -8.5e-131) || !(z <= 1.25e+151)) tmp = Float64(Float64(y * z) * Float64(-x)); else tmp = x; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -8.5e-131) || ~((z <= 1.25e+151)))
tmp = (y * z) * -x;
else
tmp = x;
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[z, -8.5e-131], N[Not[LessEqual[z, 1.25e+151]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{-131} \lor \neg \left(z \leq 1.25 \cdot 10^{+151}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.50000000000000013e-131 or 1.2500000000000001e151 < z Initial program 87.4%
Taylor expanded in y around inf 60.4%
mul-1-neg60.4%
distribute-rgt-neg-in60.4%
distribute-rgt-neg-in60.4%
Simplified60.4%
if -8.50000000000000013e-131 < z < 1.2500000000000001e151Initial program 98.5%
Taylor expanded in y around 0 71.4%
Final simplification66.2%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
assert(y < z);
double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
NOTE: 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 * (1.0d0 - (y * z))
end function
assert y < z;
public static double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
[y, z] = sort([y, z]) def code(x, y, z): return x * (1.0 - (y * z))
y, z = sort([y, z]) function code(x, y, z) return Float64(x * Float64(1.0 - Float64(y * z))) end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = x * (1.0 - (y * z));
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x \cdot \left(1 - y \cdot z\right)
\end{array}
Initial program 93.3%
Final simplification93.3%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- x (* (* y z) x)))
assert(y < z);
double code(double x, double y, double z) {
return x - ((y * z) * x);
}
NOTE: 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 * z) * x)
end function
assert y < z;
public static double code(double x, double y, double z) {
return x - ((y * z) * x);
}
[y, z] = sort([y, z]) def code(x, y, z): return x - ((y * z) * x)
y, z = sort([y, z]) function code(x, y, z) return Float64(x - Float64(Float64(y * z) * x)) end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = x - ((y * z) * x);
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x - \left(y \cdot z\right) \cdot x
\end{array}
Initial program 93.3%
Taylor expanded in y around 0 93.3%
mul-1-neg93.3%
Simplified93.3%
Final simplification93.3%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 x)
assert(y < z);
double code(double x, double y, double z) {
return x;
}
NOTE: 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 y < z;
public static double code(double x, double y, double z) {
return x;
}
[y, z] = sort([y, z]) def code(x, y, z): return x
y, z = sort([y, z]) function code(x, y, z) return x end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = x;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := x
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x
\end{array}
Initial program 93.3%
Taylor expanded in y around 0 51.9%
Final simplification51.9%
herbie shell --seed 2023336
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))