
(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 (if (<= (* y z) 5e+292) (- x (* (* y z) x)) (* z (* y (- x)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 5e+292) {
tmp = x - ((y * z) * x);
} 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+292) then
tmp = x - ((y * z) * x)
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+292) {
tmp = x - ((y * z) * x);
} 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+292: tmp = x - ((y * z) * x) 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+292) tmp = Float64(x - Float64(Float64(y * z) * x)); else tmp = Float64(z * Float64(y * Float64(-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+292)
tmp = x - ((y * z) * x);
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+292], N[(x - N[(N[(y * z), $MachinePrecision] * x), $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^{+292}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 4.9999999999999996e292Initial program 98.3%
sub-neg98.3%
distribute-rgt-in98.4%
*-un-lft-identity98.4%
distribute-rgt-neg-in98.4%
Applied egg-rr98.4%
if 4.9999999999999996e292 < (*.f64 y z) Initial program 68.3%
Taylor expanded in y around inf 68.3%
mul-1-neg68.3%
associate-*r*99.9%
Simplified99.9%
Final simplification98.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 (* z (* y (- x)))))
(if (<= (* y z) -40.0)
t_0
(if (<= (* y z) 0.02) x (if (<= (* y z) 5e+292) (* (* y z) (- 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) <= -40.0) {
tmp = t_0;
} else if ((y * z) <= 0.02) {
tmp = x;
} else if ((y * z) <= 5e+292) {
tmp = (y * z) * -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) <= (-40.0d0)) then
tmp = t_0
else if ((y * z) <= 0.02d0) then
tmp = x
else if ((y * z) <= 5d+292) then
tmp = (y * z) * -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) <= -40.0) {
tmp = t_0;
} else if ((y * z) <= 0.02) {
tmp = x;
} else if ((y * z) <= 5e+292) {
tmp = (y * z) * -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) <= -40.0: tmp = t_0 elif (y * z) <= 0.02: tmp = x elif (y * z) <= 5e+292: tmp = (y * z) * -x else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(z * Float64(y * Float64(-x))) tmp = 0.0 if (Float64(y * z) <= -40.0) tmp = t_0; elseif (Float64(y * z) <= 0.02) tmp = x; elseif (Float64(y * z) <= 5e+292) tmp = Float64(Float64(y * z) * Float64(-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) <= -40.0)
tmp = t_0;
elseif ((y * z) <= 0.02)
tmp = x;
elseif ((y * z) <= 5e+292)
tmp = (y * z) * -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], -40.0], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], 0.02], x, If[LessEqual[N[(y * z), $MachinePrecision], 5e+292], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{if}\;y \cdot z \leq -40:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot z \leq 0.02:\\
\;\;\;\;x\\
\mathbf{elif}\;y \cdot z \leq 5 \cdot 10^{+292}:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -40 or 4.9999999999999996e292 < (*.f64 y z) Initial program 87.3%
Taylor expanded in y around inf 85.4%
mul-1-neg85.4%
associate-*r*89.9%
Simplified89.9%
if -40 < (*.f64 y z) < 0.0200000000000000004Initial program 100.0%
Taylor expanded in y around 0 97.8%
if 0.0200000000000000004 < (*.f64 y z) < 4.9999999999999996e292Initial program 99.8%
Taylor expanded in y around inf 98.0%
mul-1-neg98.0%
associate-*r*83.7%
Simplified83.7%
Taylor expanded in x around 0 98.0%
Final simplification95.5%
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) -40.0) (not (<= (* y z) 0.02))) (* (* y z) (- x)) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -40.0) || !((y * z) <= 0.02)) {
tmp = (y * z) * -x;
} else {
tmp = 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) <= (-40.0d0)) .or. (.not. ((y * z) <= 0.02d0))) then
tmp = (y * z) * -x
else
tmp = 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) <= -40.0) || !((y * z) <= 0.02)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -40.0) or not ((y * z) <= 0.02): tmp = (y * z) * -x else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -40.0) || !(Float64(y * z) <= 0.02)) tmp = Float64(Float64(y * z) * Float64(-x)); else tmp = 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) <= -40.0) || ~(((y * z) <= 0.02)))
tmp = (y * z) * -x;
else
tmp = 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[Or[LessEqual[N[(y * z), $MachinePrecision], -40.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.02]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -40 \lor \neg \left(y \cdot z \leq 0.02\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -40 or 0.0200000000000000004 < (*.f64 y z) Initial program 92.6%
Taylor expanded in y around inf 90.8%
mul-1-neg90.8%
associate-*r*87.3%
Simplified87.3%
Taylor expanded in x around 0 90.8%
if -40 < (*.f64 y z) < 0.0200000000000000004Initial program 100.0%
Taylor expanded in y around 0 97.8%
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 (<= (* y z) 5e+292) (* 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+292) {
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+292) 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+292) {
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+292: 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+292) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(z * Float64(y * Float64(-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+292)
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+292], 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^{+292}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 4.9999999999999996e292Initial program 98.3%
if 4.9999999999999996e292 < (*.f64 y z) Initial program 68.3%
Taylor expanded in y around inf 68.3%
mul-1-neg68.3%
associate-*r*99.9%
Simplified99.9%
Final simplification98.5%
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.2%
Taylor expanded in y around 0 49.8%
herbie shell --seed 2024103
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))