
(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 (<= (* x (- 1.0 (* y z))) 5e+281) (- x (* x (* y z))) (* z (/ x (/ -1.0 y)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((x * (1.0 - (y * z))) <= 5e+281) {
tmp = x - (x * (y * z));
} else {
tmp = z * (x / (-1.0 / y));
}
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 ((x * (1.0d0 - (y * z))) <= 5d+281) then
tmp = x - (x * (y * z))
else
tmp = z * (x / ((-1.0d0) / y))
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((x * (1.0 - (y * z))) <= 5e+281) {
tmp = x - (x * (y * z));
} else {
tmp = z * (x / (-1.0 / y));
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (x * (1.0 - (y * z))) <= 5e+281: tmp = x - (x * (y * z)) else: tmp = z * (x / (-1.0 / y)) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x * Float64(1.0 - Float64(y * z))) <= 5e+281) tmp = Float64(x - Float64(x * Float64(y * z))); else tmp = Float64(z * Float64(x / Float64(-1.0 / y))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((x * (1.0 - (y * z))) <= 5e+281)
tmp = x - (x * (y * z));
else
tmp = z * (x / (-1.0 / y));
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[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+281], N[(x - N[(x * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(x / N[(-1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot \left(1 - y \cdot z\right) \leq 5 \cdot 10^{+281}:\\
\;\;\;\;x - x \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{x}{\frac{-1}{y}}\\
\end{array}
\end{array}
if (*.f64 x (-.f64 1 (*.f64 y z))) < 5.00000000000000016e281Initial program 99.0%
flip--84.0%
associate-*r/80.7%
metadata-eval80.7%
pow280.7%
Applied egg-rr80.7%
associate-/l*84.0%
Simplified84.0%
Taylor expanded in x around 0 67.5%
fma-def67.5%
associate-/l*67.1%
div-sub67.1%
unpow267.1%
unpow267.1%
swap-sqr81.9%
unpow281.9%
div-sub81.9%
unpow281.9%
swap-sqr67.1%
Simplified67.1%
Taylor expanded in y around 0 94.6%
+-commutative94.6%
neg-mul-194.6%
unsub-neg94.6%
associate-*r*99.0%
*-commutative99.0%
Simplified99.0%
if 5.00000000000000016e281 < (*.f64 x (-.f64 1 (*.f64 y z))) Initial program 81.1%
flip--41.7%
associate-*r/41.7%
metadata-eval41.7%
pow241.7%
Applied egg-rr41.7%
associate-/l*41.7%
Simplified41.7%
Taylor expanded in y around inf 81.1%
associate-/r*81.1%
Simplified81.1%
add-cube-cbrt81.1%
div-inv81.1%
times-frac99.4%
pow299.4%
Applied egg-rr99.4%
associate-/r/99.3%
/-rgt-identity99.3%
associate-*r*99.3%
associate-*l/99.3%
unpow299.3%
rem-3cbrt-lft99.8%
Simplified99.8%
Final simplification99.1%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- 1.0 (* y z))))) (if (<= t_0 4e+287) t_0 (* y (* x (- z))))))
assert(y < z);
double code(double x, double y, double z) {
double t_0 = x * (1.0 - (y * z));
double tmp;
if (t_0 <= 4e+287) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = x * (1.0d0 - (y * z))
if (t_0 <= 4d+287) then
tmp = t_0
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 t_0 = x * (1.0 - (y * z));
double tmp;
if (t_0 <= 4e+287) {
tmp = t_0;
} else {
tmp = y * (x * -z);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): t_0 = x * (1.0 - (y * z)) tmp = 0 if t_0 <= 4e+287: tmp = t_0 else: tmp = y * (x * -z) return tmp
y, z = sort([y, z]) function code(x, y, z) t_0 = Float64(x * Float64(1.0 - Float64(y * z))) tmp = 0.0 if (t_0 <= 4e+287) tmp = t_0; 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)
t_0 = x * (1.0 - (y * z));
tmp = 0.0;
if (t_0 <= 4e+287)
tmp = t_0;
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_] := Block[{t$95$0 = N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 4e+287], t$95$0, N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - y \cdot z\right)\\
\mathbf{if}\;t_0 \leq 4 \cdot 10^{+287}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\end{array}
\end{array}
if (*.f64 x (-.f64 1 (*.f64 y z))) < 4.0000000000000003e287Initial program 99.0%
if 4.0000000000000003e287 < (*.f64 x (-.f64 1 (*.f64 y z))) Initial program 80.5%
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 simplification99.1%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- 1.0 (* y z))))) (if (<= t_0 5e+281) t_0 (* z (/ x (/ -1.0 y))))))
assert(y < z);
double code(double x, double y, double z) {
double t_0 = x * (1.0 - (y * z));
double tmp;
if (t_0 <= 5e+281) {
tmp = t_0;
} else {
tmp = z * (x / (-1.0 / y));
}
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) :: t_0
real(8) :: tmp
t_0 = x * (1.0d0 - (y * z))
if (t_0 <= 5d+281) then
tmp = t_0
else
tmp = z * (x / ((-1.0d0) / y))
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double t_0 = x * (1.0 - (y * z));
double tmp;
if (t_0 <= 5e+281) {
tmp = t_0;
} else {
tmp = z * (x / (-1.0 / y));
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): t_0 = x * (1.0 - (y * z)) tmp = 0 if t_0 <= 5e+281: tmp = t_0 else: tmp = z * (x / (-1.0 / y)) return tmp
y, z = sort([y, z]) function code(x, y, z) t_0 = Float64(x * Float64(1.0 - Float64(y * z))) tmp = 0.0 if (t_0 <= 5e+281) tmp = t_0; else tmp = Float64(z * Float64(x / Float64(-1.0 / y))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = x * (1.0 - (y * z));
tmp = 0.0;
if (t_0 <= 5e+281)
tmp = t_0;
else
tmp = z * (x / (-1.0 / y));
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 5e+281], t$95$0, N[(z * N[(x / N[(-1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - y \cdot z\right)\\
\mathbf{if}\;t_0 \leq 5 \cdot 10^{+281}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{x}{\frac{-1}{y}}\\
\end{array}
\end{array}
if (*.f64 x (-.f64 1 (*.f64 y z))) < 5.00000000000000016e281Initial program 99.0%
if 5.00000000000000016e281 < (*.f64 x (-.f64 1 (*.f64 y z))) Initial program 81.1%
flip--41.7%
associate-*r/41.7%
metadata-eval41.7%
pow241.7%
Applied egg-rr41.7%
associate-/l*41.7%
Simplified41.7%
Taylor expanded in y around inf 81.1%
associate-/r*81.1%
Simplified81.1%
add-cube-cbrt81.1%
div-inv81.1%
times-frac99.4%
pow299.4%
Applied egg-rr99.4%
associate-/r/99.3%
/-rgt-identity99.3%
associate-*r*99.3%
associate-*l/99.3%
unpow299.3%
rem-3cbrt-lft99.8%
Simplified99.8%
Final simplification99.1%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -1.7e+79) (not (<= y 7e-151))) (* x (* y (- z))) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.7e+79) || !(y <= 7e-151)) {
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 <= (-1.7d+79)) .or. (.not. (y <= 7d-151))) 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 <= -1.7e+79) || !(y <= 7e-151)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y <= -1.7e+79) or not (y <= 7e-151): tmp = x * (y * -z) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -1.7e+79) || !(y <= 7e-151)) 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 <= -1.7e+79) || ~((y <= 7e-151)))
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[y, -1.7e+79], N[Not[LessEqual[y, 7e-151]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{+79} \lor \neg \left(y \leq 7 \cdot 10^{-151}\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.70000000000000016e79 or 6.99999999999999991e-151 < y Initial program 94.6%
Taylor expanded in y around inf 59.3%
mul-1-neg59.3%
associate-*r*60.4%
distribute-lft-neg-in60.4%
distribute-rgt-neg-out60.4%
*-commutative60.4%
Simplified60.4%
if -1.70000000000000016e79 < y < 6.99999999999999991e-151Initial program 99.9%
Taylor expanded in y around 0 75.4%
Final simplification67.2%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -5e+78) (* x (* y (- z))) (if (<= y 1.55e-145) x (* y (* x (- z))))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -5e+78) {
tmp = x * (y * -z);
} else if (y <= 1.55e-145) {
tmp = x;
} 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 <= (-5d+78)) then
tmp = x * (y * -z)
else if (y <= 1.55d-145) then
tmp = x
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 <= -5e+78) {
tmp = x * (y * -z);
} else if (y <= 1.55e-145) {
tmp = x;
} else {
tmp = y * (x * -z);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if y <= -5e+78: tmp = x * (y * -z) elif y <= 1.55e-145: tmp = x else: tmp = y * (x * -z) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (y <= -5e+78) tmp = Float64(x * Float64(y * Float64(-z))); elseif (y <= 1.55e-145) tmp = x; 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 <= -5e+78)
tmp = x * (y * -z);
elseif (y <= 1.55e-145)
tmp = x;
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[y, -5e+78], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.55e-145], x, N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+78}:\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{-145}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\end{array}
\end{array}
if y < -4.99999999999999984e78Initial program 94.5%
Taylor expanded in y around inf 72.7%
mul-1-neg72.7%
associate-*r*77.0%
distribute-lft-neg-in77.0%
distribute-rgt-neg-out77.0%
*-commutative77.0%
Simplified77.0%
if -4.99999999999999984e78 < y < 1.55e-145Initial program 99.9%
Taylor expanded in y around 0 75.4%
if 1.55e-145 < y Initial program 94.4%
Taylor expanded in y around inf 54.3%
mul-1-neg54.3%
distribute-rgt-neg-in54.3%
distribute-lft-neg-out54.3%
*-commutative54.3%
Simplified54.3%
Final simplification68.5%
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 97.0%
Taylor expanded in y around 0 54.2%
Final simplification54.2%
herbie shell --seed 2023279
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))