
(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 -5e+115) (fma y (* x (- z)) x) (* x (- 1.0 (* y z)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -5e+115) {
tmp = fma(y, (x * -z), x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (y <= -5e+115) tmp = fma(y, Float64(x * Float64(-z)), x); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); end return tmp end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[y, -5e+115], N[(y * N[(x * (-z)), $MachinePrecision] + x), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+115}:\\
\;\;\;\;\mathsf{fma}\left(y, x \cdot \left(-z\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if y < -5.00000000000000008e115Initial program 83.6%
Taylor expanded in x around 0 83.6%
sub-neg83.6%
distribute-rgt-neg-out83.6%
+-commutative83.6%
distribute-lft1-in83.6%
associate-*l*99.8%
fma-def99.8%
*-commutative99.8%
Simplified99.8%
if -5.00000000000000008e115 < y Initial program 98.2%
Final simplification98.4%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= (* y z) -5.0) (not (<= (* y z) 5e-13))) (* x (* y (- z))) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -5.0) || !((y * z) <= 5e-13)) {
tmp = x * (y * -z);
} 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 (((y * z) <= (-5.0d0)) .or. (.not. ((y * z) <= 5d-13))) then
tmp = x * (y * -z)
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 (((y * z) <= -5.0) || !((y * z) <= 5e-13)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -5.0) or not ((y * z) <= 5e-13): tmp = x * (y * -z) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -5.0) || !(Float64(y * z) <= 5e-13)) tmp = Float64(x * Float64(y * Float64(-z))); else tmp = x; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (((y * z) <= -5.0) || ~(((y * z) <= 5e-13)))
tmp = x * (y * -z);
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[N[(y * z), $MachinePrecision], -5.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 5e-13]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \lor \neg \left(y \cdot z \leq 5 \cdot 10^{-13}\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -5 or 4.9999999999999999e-13 < (*.f64 y z) Initial program 92.0%
Taylor expanded in y around inf 90.0%
mul-1-neg90.0%
associate-*r*90.7%
distribute-lft-neg-in90.7%
distribute-rgt-neg-out90.7%
*-commutative90.7%
Simplified90.7%
if -5 < (*.f64 y z) < 4.9999999999999999e-13Initial program 100.0%
Taylor expanded in y around 0 97.5%
Final simplification94.3%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= (* y z) -5.0) (not (<= (* y z) 5e-13))) (* y (* x (- z))) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -5.0) || !((y * z) <= 5e-13)) {
tmp = y * (x * -z);
} 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 (((y * z) <= (-5.0d0)) .or. (.not. ((y * z) <= 5d-13))) then
tmp = y * (x * -z)
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 (((y * z) <= -5.0) || !((y * z) <= 5e-13)) {
tmp = y * (x * -z);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -5.0) or not ((y * z) <= 5e-13): tmp = y * (x * -z) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -5.0) || !(Float64(y * z) <= 5e-13)) tmp = Float64(y * Float64(x * Float64(-z))); else tmp = x; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (((y * z) <= -5.0) || ~(((y * z) <= 5e-13)))
tmp = y * (x * -z);
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[N[(y * z), $MachinePrecision], -5.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 5e-13]], $MachinePrecision]], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \lor \neg \left(y \cdot z \leq 5 \cdot 10^{-13}\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -5 or 4.9999999999999999e-13 < (*.f64 y z) Initial program 92.0%
Taylor expanded in y around inf 90.0%
mul-1-neg90.0%
distribute-rgt-neg-in90.0%
distribute-lft-neg-out90.0%
*-commutative90.0%
Simplified90.0%
if -5 < (*.f64 y z) < 4.9999999999999999e-13Initial program 100.0%
Taylor expanded in y around 0 97.5%
Final simplification94.0%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) 4e+254) (* x (- 1.0 (* y z))) (* y (* x (- z)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 4e+254) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (x * -z);
}
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 ((y * z) <= 4d+254) then
tmp = x * (1.0d0 - (y * z))
else
tmp = y * (x * -z)
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 4e+254) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (x * -z);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 4e+254: tmp = x * (1.0 - (y * z)) else: tmp = y * (x * -z) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 4e+254) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(y * Float64(x * Float64(-z))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= 4e+254)
tmp = x * (1.0 - (y * z));
else
tmp = y * (x * -z);
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], 4e+254], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 4 \cdot 10^{+254}:\\
\;\;\;\;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) < 3.9999999999999997e254Initial program 98.6%
if 3.9999999999999997e254 < (*.f64 y z) Initial program 77.6%
Taylor expanded in y around inf 99.9%
mul-1-neg99.9%
distribute-rgt-neg-in99.9%
distribute-lft-neg-out99.9%
*-commutative99.9%
Simplified99.9%
Final simplification98.7%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -6e+114) (- x (* y (* x z))) (* x (- 1.0 (* y z)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -6e+114) {
tmp = x - (y * (x * z));
} else {
tmp = x * (1.0 - (y * z));
}
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 (y <= (-6d+114)) then
tmp = x - (y * (x * z))
else
tmp = x * (1.0d0 - (y * z))
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if (y <= -6e+114) {
tmp = x - (y * (x * z));
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if y <= -6e+114: tmp = x - (y * (x * z)) else: tmp = x * (1.0 - (y * z)) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (y <= -6e+114) tmp = Float64(x - Float64(y * Float64(x * z))); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= -6e+114)
tmp = x - (y * (x * z));
else
tmp = x * (1.0 - (y * z));
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[y, -6e+114], N[(x - N[(y * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{+114}:\\
\;\;\;\;x - y \cdot \left(x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if y < -6.0000000000000001e114Initial program 83.6%
Taylor expanded in x around 0 83.6%
*-commutative83.6%
distribute-rgt-out--83.6%
associate-*r*99.8%
*-lft-identity99.8%
Simplified99.8%
if -6.0000000000000001e114 < y Initial program 98.2%
Final simplification98.4%
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 96.2%
Taylor expanded in y around 0 53.4%
Final simplification53.4%
herbie shell --seed 2023278
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))