
(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 (<= (- 1.0 (* y z)) -1e+75) (- (* z (* y x))) (/ x (/ -1.0 (fma y z -1.0)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((1.0 - (y * z)) <= -1e+75) {
tmp = -(z * (y * x));
} else {
tmp = x / (-1.0 / fma(y, z, -1.0));
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(1.0 - Float64(y * z)) <= -1e+75) tmp = Float64(-Float64(z * Float64(y * x))); else tmp = Float64(x / Float64(-1.0 / fma(y, z, -1.0))); 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[N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision], -1e+75], (-N[(z * N[(y * x), $MachinePrecision]), $MachinePrecision]), N[(x / N[(-1.0 / N[(y * z + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;1 - y \cdot z \leq -1 \cdot 10^{+75}:\\
\;\;\;\;-z \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{-1}{\mathsf{fma}\left(y, z, -1\right)}}\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -9.99999999999999927e74Initial program 87.0%
Taylor expanded in y around inf
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6496.1
Simplified96.1%
*-commutativeN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
neg-lowering-neg.f6496.1
Applied egg-rr96.1%
if -9.99999999999999927e74 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 98.9%
flip--N/A
metadata-evalN/A
div-subN/A
swap-sqrN/A
associate-/l*N/A
cancel-sign-sub-invN/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
neg-lowering-neg.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f6475.8
Applied egg-rr75.8%
flip3-+N/A
clear-numN/A
un-div-invN/A
Applied egg-rr98.9%
Final simplification98.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (* (* y z) x))))
(if (<= (* y z) -500.0)
t_0
(if (<= (* y z) 2e-5) x (if (<= (* y z) 5e+121) t_0 (- (* y (* z x))))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = -((y * z) * x);
double tmp;
if ((y * z) <= -500.0) {
tmp = t_0;
} else if ((y * z) <= 2e-5) {
tmp = x;
} else if ((y * z) <= 5e+121) {
tmp = t_0;
} else {
tmp = -(y * (z * 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) :: t_0
real(8) :: tmp
t_0 = -((y * z) * x)
if ((y * z) <= (-500.0d0)) then
tmp = t_0
else if ((y * z) <= 2d-5) then
tmp = x
else if ((y * z) <= 5d+121) then
tmp = t_0
else
tmp = -(y * (z * x))
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = -((y * z) * x);
double tmp;
if ((y * z) <= -500.0) {
tmp = t_0;
} else if ((y * z) <= 2e-5) {
tmp = x;
} else if ((y * z) <= 5e+121) {
tmp = t_0;
} else {
tmp = -(y * (z * x));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = -((y * z) * x) tmp = 0 if (y * z) <= -500.0: tmp = t_0 elif (y * z) <= 2e-5: tmp = x elif (y * z) <= 5e+121: tmp = t_0 else: tmp = -(y * (z * x)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(-Float64(Float64(y * z) * x)) tmp = 0.0 if (Float64(y * z) <= -500.0) tmp = t_0; elseif (Float64(y * z) <= 2e-5) tmp = x; elseif (Float64(y * z) <= 5e+121) tmp = t_0; else tmp = Float64(-Float64(y * Float64(z * x))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = -((y * z) * x);
tmp = 0.0;
if ((y * z) <= -500.0)
tmp = t_0;
elseif ((y * z) <= 2e-5)
tmp = x;
elseif ((y * z) <= 5e+121)
tmp = t_0;
else
tmp = -(y * (z * 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_] := Block[{t$95$0 = (-N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision])}, If[LessEqual[N[(y * z), $MachinePrecision], -500.0], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], 2e-5], x, If[LessEqual[N[(y * z), $MachinePrecision], 5e+121], t$95$0, (-N[(y * N[(z * x), $MachinePrecision]), $MachinePrecision])]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := -\left(y \cdot z\right) \cdot x\\
\mathbf{if}\;y \cdot z \leq -500:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot z \leq 2 \cdot 10^{-5}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \cdot z \leq 5 \cdot 10^{+121}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;-y \cdot \left(z \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -500 or 2.00000000000000016e-5 < (*.f64 y z) < 5.00000000000000007e121Initial program 97.2%
Taylor expanded in y around inf
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6494.2
Simplified94.2%
if -500 < (*.f64 y z) < 2.00000000000000016e-5Initial program 100.0%
Taylor expanded in y around 0
Simplified98.6%
if 5.00000000000000007e121 < (*.f64 y z) Initial program 84.3%
Taylor expanded in y around inf
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6499.8
Simplified99.8%
Final simplification97.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (- (* z (* y x))))) (if (<= (* y z) -500.0) t_0 (if (<= (* y z) 2e-5) x t_0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = -(z * (y * x));
double tmp;
if ((y * z) <= -500.0) {
tmp = t_0;
} else if ((y * z) <= 2e-5) {
tmp = x;
} else {
tmp = 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 = -(z * (y * x))
if ((y * z) <= (-500.0d0)) then
tmp = t_0
else if ((y * z) <= 2d-5) then
tmp = x
else
tmp = 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 = -(z * (y * x));
double tmp;
if ((y * z) <= -500.0) {
tmp = t_0;
} else if ((y * z) <= 2e-5) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = -(z * (y * x)) tmp = 0 if (y * z) <= -500.0: tmp = t_0 elif (y * z) <= 2e-5: tmp = x else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(-Float64(z * Float64(y * x))) tmp = 0.0 if (Float64(y * z) <= -500.0) tmp = t_0; elseif (Float64(y * z) <= 2e-5) tmp = x; else tmp = t_0; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = -(z * (y * x));
tmp = 0.0;
if ((y * z) <= -500.0)
tmp = t_0;
elseif ((y * z) <= 2e-5)
tmp = x;
else
tmp = 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[(z * N[(y * x), $MachinePrecision]), $MachinePrecision])}, If[LessEqual[N[(y * z), $MachinePrecision], -500.0], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], 2e-5], x, t$95$0]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := -z \cdot \left(y \cdot x\right)\\
\mathbf{if}\;y \cdot z \leq -500:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot z \leq 2 \cdot 10^{-5}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -500 or 2.00000000000000016e-5 < (*.f64 y z) Initial program 92.7%
Taylor expanded in y around inf
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6489.8
Simplified89.8%
*-commutativeN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
neg-lowering-neg.f6493.7
Applied egg-rr93.7%
if -500 < (*.f64 y z) < 2.00000000000000016e-5Initial program 100.0%
Taylor expanded in y around 0
Simplified98.6%
Final simplification96.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (- (* (* y z) x)))) (if (<= (* y z) -500.0) t_0 (if (<= (* y z) 2e-5) x t_0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = -((y * z) * x);
double tmp;
if ((y * z) <= -500.0) {
tmp = t_0;
} else if ((y * z) <= 2e-5) {
tmp = x;
} else {
tmp = 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 = -((y * z) * x)
if ((y * z) <= (-500.0d0)) then
tmp = t_0
else if ((y * z) <= 2d-5) then
tmp = x
else
tmp = 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 = -((y * z) * x);
double tmp;
if ((y * z) <= -500.0) {
tmp = t_0;
} else if ((y * z) <= 2e-5) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = -((y * z) * x) tmp = 0 if (y * z) <= -500.0: tmp = t_0 elif (y * z) <= 2e-5: tmp = x else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(-Float64(Float64(y * z) * x)) tmp = 0.0 if (Float64(y * z) <= -500.0) tmp = t_0; elseif (Float64(y * z) <= 2e-5) tmp = x; else tmp = t_0; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = -((y * z) * x);
tmp = 0.0;
if ((y * z) <= -500.0)
tmp = t_0;
elseif ((y * z) <= 2e-5)
tmp = x;
else
tmp = 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[(N[(y * z), $MachinePrecision] * x), $MachinePrecision])}, If[LessEqual[N[(y * z), $MachinePrecision], -500.0], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], 2e-5], x, t$95$0]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := -\left(y \cdot z\right) \cdot x\\
\mathbf{if}\;y \cdot z \leq -500:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot z \leq 2 \cdot 10^{-5}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -500 or 2.00000000000000016e-5 < (*.f64 y z) Initial program 92.7%
Taylor expanded in y around inf
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6490.8
Simplified90.8%
if -500 < (*.f64 y z) < 2.00000000000000016e-5Initial program 100.0%
Taylor expanded in y around 0
Simplified98.6%
Final simplification94.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 (<= t_0 -5e+94) (- (* z (* y x))) (* t_0 x))))
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 <= -5e+94) {
tmp = -(z * (y * x));
} else {
tmp = t_0 * 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) :: t_0
real(8) :: tmp
t_0 = 1.0d0 - (y * z)
if (t_0 <= (-5d+94)) then
tmp = -(z * (y * x))
else
tmp = t_0 * x
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 <= -5e+94) {
tmp = -(z * (y * x));
} else {
tmp = t_0 * x;
}
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 <= -5e+94: tmp = -(z * (y * x)) else: tmp = t_0 * x 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 <= -5e+94) tmp = Float64(-Float64(z * Float64(y * x))); else tmp = Float64(t_0 * x); 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 <= -5e+94)
tmp = -(z * (y * x));
else
tmp = t_0 * 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_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+94], (-N[(z * N[(y * x), $MachinePrecision]), $MachinePrecision]), N[(t$95$0 * x), $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 -5 \cdot 10^{+94}:\\
\;\;\;\;-z \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot x\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -5.0000000000000001e94Initial program 86.2%
Taylor expanded in y around inf
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6495.9
Simplified95.9%
*-commutativeN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
neg-lowering-neg.f6495.9
Applied egg-rr95.9%
if -5.0000000000000001e94 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 98.9%
Final simplification98.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 x)
assert(x < y && y < z);
double code(double x, double y, double z) {
return x;
}
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
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x
x, y, z = sort([x, y, z]) function code(x, y, z) return x end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := x
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x
\end{array}
Initial program 96.5%
Taylor expanded in y around 0
Simplified53.7%
herbie shell --seed 2024204
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))