
(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) -5e+139) (* (* (- z) x) y) (if (<= (* y z) 4e+266) (* x (- 1.0 (* y z))) (* (- z) (* y x)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+139) {
tmp = (-z * x) * y;
} else if ((y * z) <= 4e+266) {
tmp = x * (1.0 - (y * z));
} 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 ((y * z) <= (-5d+139)) then
tmp = (-z * x) * y
else if ((y * z) <= 4d+266) then
tmp = x * (1.0d0 - (y * z))
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 ((y * z) <= -5e+139) {
tmp = (-z * x) * y;
} else if ((y * z) <= 4e+266) {
tmp = x * (1.0 - (y * z));
} else {
tmp = -z * (y * x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -5e+139: tmp = (-z * x) * y elif (y * z) <= 4e+266: tmp = x * (1.0 - (y * z)) else: tmp = -z * (y * x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -5e+139) tmp = Float64(Float64(Float64(-z) * x) * y); elseif (Float64(y * z) <= 4e+266) tmp = Float64(x * Float64(1.0 - Float64(y * z))); 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 ((y * z) <= -5e+139)
tmp = (-z * x) * y;
elseif ((y * z) <= 4e+266)
tmp = x * (1.0 - (y * z));
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[N[(y * z), $MachinePrecision], -5e+139], N[(N[((-z) * x), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 4e+266], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-z) * N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+139}:\\
\;\;\;\;\left(\left(-z\right) \cdot x\right) \cdot y\\
\mathbf{elif}\;y \cdot z \leq 4 \cdot 10^{+266}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -5.0000000000000003e139Initial program 83.2%
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.f6499.8
Applied rewrites99.8%
Applied rewrites99.9%
Taylor expanded in y around inf
mul-1-negN/A
associate-*r*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Applied rewrites99.9%
if -5.0000000000000003e139 < (*.f64 y z) < 4.0000000000000001e266Initial program 99.9%
if 4.0000000000000001e266 < (*.f64 y z) Initial program 81.2%
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.f6499.9
Applied rewrites99.9%
Applied rewrites99.9%
Taylor expanded in y around inf
mul-1-negN/A
associate-*r*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.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) -20.0) (not (<= (* y z) 0.005))) (* (- z) (* y x)) (* x 1.0)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -20.0) || !((y * z) <= 0.005)) {
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) :: tmp
if (((y * z) <= (-20.0d0)) .or. (.not. ((y * z) <= 0.005d0))) 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 tmp;
if (((y * z) <= -20.0) || !((y * z) <= 0.005)) {
tmp = -z * (y * x);
} else {
tmp = x * 1.0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -20.0) or not ((y * z) <= 0.005): tmp = -z * (y * x) else: tmp = x * 1.0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -20.0) || !(Float64(y * z) <= 0.005)) 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)
tmp = 0.0;
if (((y * z) <= -20.0) || ~(((y * z) <= 0.005)))
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_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -20.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.005]], $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}
\mathbf{if}\;y \cdot z \leq -20 \lor \neg \left(y \cdot z \leq 0.005\right):\\
\;\;\;\;\left(-z\right) \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1\\
\end{array}
\end{array}
if (*.f64 y z) < -20 or 0.0050000000000000001 < (*.f64 y z) Initial program 91.1%
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.f6495.1
Applied rewrites95.1%
Applied rewrites91.6%
Taylor expanded in y around inf
mul-1-negN/A
associate-*r*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6492.1
Applied rewrites92.1%
if -20 < (*.f64 y z) < 0.0050000000000000001Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites96.8%
Final simplification94.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) -2.0) (* (* (- z) x) y) (if (<= (* y z) 0.005) (* x 1.0) (* (- z) (* y x)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -2.0) {
tmp = (-z * x) * y;
} else if ((y * z) <= 0.005) {
tmp = x * 1.0;
} 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 ((y * z) <= (-2.0d0)) then
tmp = (-z * x) * y
else if ((y * z) <= 0.005d0) then
tmp = x * 1.0d0
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 ((y * z) <= -2.0) {
tmp = (-z * x) * y;
} else if ((y * z) <= 0.005) {
tmp = x * 1.0;
} else {
tmp = -z * (y * x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -2.0: tmp = (-z * x) * y elif (y * z) <= 0.005: tmp = x * 1.0 else: tmp = -z * (y * x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -2.0) tmp = Float64(Float64(Float64(-z) * x) * y); elseif (Float64(y * z) <= 0.005) tmp = Float64(x * 1.0); 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 ((y * z) <= -2.0)
tmp = (-z * x) * y;
elseif ((y * z) <= 0.005)
tmp = x * 1.0;
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[N[(y * z), $MachinePrecision], -2.0], N[(N[((-z) * x), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 0.005], N[(x * 1.0), $MachinePrecision], N[((-z) * N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -2:\\
\;\;\;\;\left(\left(-z\right) \cdot x\right) \cdot y\\
\mathbf{elif}\;y \cdot z \leq 0.005:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -2Initial program 90.6%
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.f6492.7
Applied rewrites92.7%
Applied rewrites93.9%
Taylor expanded in y around inf
mul-1-negN/A
associate-*r*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6488.9
Applied rewrites88.9%
Applied rewrites91.5%
if -2 < (*.f64 y z) < 0.0050000000000000001Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites97.4%
if 0.0050000000000000001 < (*.f64 y z) Initial program 91.9%
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.f6497.8
Applied rewrites97.8%
Applied rewrites87.9%
Taylor expanded in y around inf
mul-1-negN/A
associate-*r*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6494.3
Applied rewrites94.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z 4.2e+112) (* x (- 1.0 (* y z))) (fma (* x z) (- y) x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (z <= 4.2e+112) {
tmp = x * (1.0 - (y * z));
} else {
tmp = fma((x * z), -y, x);
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (z <= 4.2e+112) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = fma(Float64(x * z), Float64(-y), x); 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[z, 4.2e+112], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * z), $MachinePrecision] * (-y) + x), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.2 \cdot 10^{+112}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x \cdot z, -y, x\right)\\
\end{array}
\end{array}
if z < 4.1999999999999998e112Initial program 97.3%
if 4.1999999999999998e112 < z Initial program 85.7%
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.f64100.0
Applied rewrites100.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z 4.2e+112) (* x (- 1.0 (* y z))) (- x (* (* z x) y))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (z <= 4.2e+112) {
tmp = x * (1.0 - (y * z));
} else {
tmp = x - ((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) :: tmp
if (z <= 4.2d+112) then
tmp = x * (1.0d0 - (y * z))
else
tmp = x - ((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 tmp;
if (z <= 4.2e+112) {
tmp = x * (1.0 - (y * z));
} else {
tmp = x - ((z * x) * y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if z <= 4.2e+112: tmp = x * (1.0 - (y * z)) else: tmp = x - ((z * x) * y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (z <= 4.2e+112) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(x - Float64(Float64(z * x) * y)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= 4.2e+112)
tmp = x * (1.0 - (y * z));
else
tmp = x - ((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_] := If[LessEqual[z, 4.2e+112], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(z * x), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.2 \cdot 10^{+112}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x - \left(z \cdot x\right) \cdot y\\
\end{array}
\end{array}
if z < 4.1999999999999998e112Initial program 97.3%
if 4.1999999999999998e112 < z Initial program 85.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.f6496.1
Applied rewrites96.1%
Applied rewrites100.0%
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 95.8%
Taylor expanded in y around 0
Applied rewrites53.2%
herbie shell --seed 2024326
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))