
(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
(let* ((t_0 (- 1.0 (* y z))))
(if (or (<= t_0 -2e+294) (not (<= t_0 5e+230)))
(fma (* x z) (- y) x)
(* x t_0))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if ((t_0 <= -2e+294) || !(t_0 <= 5e+230)) {
tmp = fma((x * z), -y, x);
} else {
tmp = x * t_0;
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(1.0 - Float64(y * z)) tmp = 0.0 if ((t_0 <= -2e+294) || !(t_0 <= 5e+230)) tmp = fma(Float64(x * z), Float64(-y), x); else tmp = Float64(x * t_0); end return 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[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -2e+294], N[Not[LessEqual[t$95$0, 5e+230]], $MachinePrecision]], N[(N[(x * z), $MachinePrecision] * (-y) + x), $MachinePrecision], N[(x * t$95$0), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+294} \lor \neg \left(t\_0 \leq 5 \cdot 10^{+230}\right):\\
\;\;\;\;\mathsf{fma}\left(x \cdot z, -y, x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot t\_0\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -2.00000000000000013e294 or 5.0000000000000003e230 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 70.1%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6499.8
Applied rewrites99.8%
if -2.00000000000000013e294 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 5.0000000000000003e230Initial program 99.9%
Final simplification99.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 (- 1.0 (* y z))))
(if (or (<= t_0 -4e+143) (not (<= t_0 5e+215)))
(* (- z) (* y x))
(* x t_0))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if ((t_0 <= -4e+143) || !(t_0 <= 5e+215)) {
tmp = -z * (y * x);
} else {
tmp = x * 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 = 1.0d0 - (y * z)
if ((t_0 <= (-4d+143)) .or. (.not. (t_0 <= 5d+215))) then
tmp = -z * (y * x)
else
tmp = x * 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 = 1.0 - (y * z);
double tmp;
if ((t_0 <= -4e+143) || !(t_0 <= 5e+215)) {
tmp = -z * (y * x);
} else {
tmp = x * t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = 1.0 - (y * z) tmp = 0 if (t_0 <= -4e+143) or not (t_0 <= 5e+215): tmp = -z * (y * x) else: tmp = x * t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(1.0 - Float64(y * z)) tmp = 0.0 if ((t_0 <= -4e+143) || !(t_0 <= 5e+215)) tmp = Float64(Float64(-z) * Float64(y * x)); else tmp = Float64(x * t_0); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = 1.0 - (y * z);
tmp = 0.0;
if ((t_0 <= -4e+143) || ~((t_0 <= 5e+215)))
tmp = -z * (y * x);
else
tmp = x * 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[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -4e+143], N[Not[LessEqual[t$95$0, 5e+215]], $MachinePrecision]], N[((-z) * N[(y * x), $MachinePrecision]), $MachinePrecision], N[(x * t$95$0), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
\mathbf{if}\;t\_0 \leq -4 \cdot 10^{+143} \lor \neg \left(t\_0 \leq 5 \cdot 10^{+215}\right):\\
\;\;\;\;\left(-z\right) \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot t\_0\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -4.0000000000000001e143 or 5.0000000000000001e215 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 80.0%
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
lift-*.f64N/A
associate-*r*N/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f6411.1
Applied rewrites11.1%
Taylor expanded in y around -inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f640.4
Applied rewrites0.4%
Applied rewrites0.4%
Taylor expanded in z around -inf
associate-*r*N/A
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
mul-1-negN/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6498.4
Applied rewrites98.4%
if -4.0000000000000001e143 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 5.0000000000000001e215Initial program 99.9%
Final simplification99.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (- 1.0 (* y z)))) (if (or (<= t_0 -2.0) (not (<= t_0 2.0))) (* (- z) (* y x)) (* x 1.0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if ((t_0 <= -2.0) || !(t_0 <= 2.0)) {
tmp = -z * (y * x);
} else {
tmp = x * 1.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 = 1.0d0 - (y * z)
if ((t_0 <= (-2.0d0)) .or. (.not. (t_0 <= 2.0d0))) then
tmp = -z * (y * x)
else
tmp = x * 1.0d0
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if ((t_0 <= -2.0) || !(t_0 <= 2.0)) {
tmp = -z * (y * x);
} else {
tmp = x * 1.0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = 1.0 - (y * z) tmp = 0 if (t_0 <= -2.0) or not (t_0 <= 2.0): tmp = -z * (y * x) else: tmp = x * 1.0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(1.0 - Float64(y * z)) tmp = 0.0 if ((t_0 <= -2.0) || !(t_0 <= 2.0)) tmp = Float64(Float64(-z) * Float64(y * x)); else tmp = Float64(x * 1.0); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = 1.0 - (y * z);
tmp = 0.0;
if ((t_0 <= -2.0) || ~((t_0 <= 2.0)))
tmp = -z * (y * x);
else
tmp = x * 1.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[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -2.0], N[Not[LessEqual[t$95$0, 2.0]], $MachinePrecision]], N[((-z) * N[(y * x), $MachinePrecision]), $MachinePrecision], N[(x * 1.0), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
\mathbf{if}\;t\_0 \leq -2 \lor \neg \left(t\_0 \leq 2\right):\\
\;\;\;\;\left(-z\right) \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -2 or 2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 89.8%
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
lift-*.f64N/A
associate-*r*N/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f6413.3
Applied rewrites13.3%
Taylor expanded in y around -inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f641.0
Applied rewrites1.0%
Applied rewrites1.0%
Taylor expanded in z around -inf
associate-*r*N/A
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
mul-1-negN/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6491.6
Applied rewrites91.6%
if -2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites97.0%
Final simplification94.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x 2e-36) (fma (* x (- y)) z x) (* x (- 1.0 (* y z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= 2e-36) {
tmp = fma((x * -y), z, x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= 2e-36) tmp = fma(Float64(x * Float64(-y)), z, x); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); end return tmp end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[x, 2e-36], N[(N[(x * (-y)), $MachinePrecision] * z + x), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2 \cdot 10^{-36}:\\
\;\;\;\;\mathsf{fma}\left(x \cdot \left(-y\right), z, x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if x < 1.9999999999999999e-36Initial program 92.7%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6491.5
Applied rewrites91.5%
if 1.9999999999999999e-36 < x Initial program 99.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* x 1.0))
assert(x < y && y < z);
double code(double x, double y, double z) {
return x * 1.0;
}
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 * 1.0d0
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x * 1.0;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x * 1.0
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(x * 1.0) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x * 1.0;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * 1.0), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x \cdot 1
\end{array}
Initial program 94.7%
Taylor expanded in y around 0
Applied rewrites48.9%
herbie shell --seed 2024339
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))