
(FPCore (x y z) :precision binary64 (- (* (* x 3.0) y) z))
double code(double x, double y, double z) {
return ((x * 3.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 * 3.0d0) * y) - z
end function
public static double code(double x, double y, double z) {
return ((x * 3.0) * y) - z;
}
def code(x, y, z): return ((x * 3.0) * y) - z
function code(x, y, z) return Float64(Float64(Float64(x * 3.0) * y) - z) end
function tmp = code(x, y, z) tmp = ((x * 3.0) * y) - z; end
code[x_, y_, z_] := N[(N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 3\right) \cdot y - z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (* (* x 3.0) y) z))
double code(double x, double y, double z) {
return ((x * 3.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 * 3.0d0) * y) - z
end function
public static double code(double x, double y, double z) {
return ((x * 3.0) * y) - z;
}
def code(x, y, z): return ((x * 3.0) * y) - z
function code(x, y, z) return Float64(Float64(Float64(x * 3.0) * y) - z) end
function tmp = code(x, y, z) tmp = ((x * 3.0) * y) - z; end
code[x_, y_, z_] := N[(N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 3\right) \cdot y - z
\end{array}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* (* x 3.0) y) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return ((x * 3.0) * y) - z;
}
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 * 3.0d0) * y) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return ((x * 3.0) * y) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return ((x * 3.0) * y) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(Float64(x * 3.0) * y) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = ((x * 3.0) * y) - z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\left(x \cdot 3\right) \cdot y - z
\end{array}
Initial program 99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (* (* x 3.0) y)) (t_1 (* x (* 3.0 y)))) (if (<= t_0 -0.1) t_1 (if (<= t_0 1e-39) (- 0.0 z) t_1))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double t_1 = x * (3.0 * y);
double tmp;
if (t_0 <= -0.1) {
tmp = t_1;
} else if (t_0 <= 1e-39) {
tmp = 0.0 - z;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = (x * 3.0d0) * y
t_1 = x * (3.0d0 * y)
if (t_0 <= (-0.1d0)) then
tmp = t_1
else if (t_0 <= 1d-39) then
tmp = 0.0d0 - z
else
tmp = t_1
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double t_1 = x * (3.0 * y);
double tmp;
if (t_0 <= -0.1) {
tmp = t_1;
} else if (t_0 <= 1e-39) {
tmp = 0.0 - z;
} else {
tmp = t_1;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = (x * 3.0) * y t_1 = x * (3.0 * y) tmp = 0 if t_0 <= -0.1: tmp = t_1 elif t_0 <= 1e-39: tmp = 0.0 - z else: tmp = t_1 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(x * 3.0) * y) t_1 = Float64(x * Float64(3.0 * y)) tmp = 0.0 if (t_0 <= -0.1) tmp = t_1; elseif (t_0 <= 1e-39) tmp = Float64(0.0 - z); else tmp = t_1; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = (x * 3.0) * y;
t_1 = x * (3.0 * y);
tmp = 0.0;
if (t_0 <= -0.1)
tmp = t_1;
elseif (t_0 <= 1e-39)
tmp = 0.0 - z;
else
tmp = t_1;
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[(x * 3.0), $MachinePrecision] * y), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.1], t$95$1, If[LessEqual[t$95$0, 1e-39], N[(0.0 - z), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(x \cdot 3\right) \cdot y\\
t_1 := x \cdot \left(3 \cdot y\right)\\
\mathbf{if}\;t\_0 \leq -0.1:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 10^{-39}:\\
\;\;\;\;0 - z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -0.10000000000000001 or 9.99999999999999929e-40 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 99.7%
Taylor expanded in x around inf
*-commutativeN/A
associate-*r*N/A
metadata-evalN/A
distribute-lft-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lowering-*.f6483.8%
Simplified83.8%
if -0.10000000000000001 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 9.99999999999999929e-40Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6482.7%
Simplified82.7%
sub0-negN/A
neg-lowering-neg.f6482.7%
Applied egg-rr82.7%
Final simplification83.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- 0.0 z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return 0.0 - z;
}
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 = 0.0d0 - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return 0.0 - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return 0.0 - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(0.0 - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = 0.0 - z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(0.0 - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
0 - z
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6451.7%
Simplified51.7%
sub0-negN/A
neg-lowering-neg.f6451.7%
Applied egg-rr51.7%
Final simplification51.7%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 z)
assert(x < y && y < z);
double code(double x, double y, double z) {
return z;
}
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 = z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return z
x, y, z = sort([x, y, z]) function code(x, y, z) return z end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := z
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
z
\end{array}
Initial program 99.8%
Applied egg-rr5.2%
Taylor expanded in x around 0
Simplified2.5%
(FPCore (x y z) :precision binary64 (- (* x (* 3.0 y)) z))
double code(double x, double y, double z) {
return (x * (3.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 * (3.0d0 * y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (3.0 * y)) - z;
}
def code(x, y, z): return (x * (3.0 * y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(3.0 * y)) - z) end
function tmp = code(x, y, z) tmp = (x * (3.0 * y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(3 \cdot y\right) - z
\end{array}
herbie shell --seed 2024192
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, B"
:precision binary64
:alt
(! :herbie-platform default (- (* x (* 3 y)) z))
(- (* (* x 3.0) y) z))