
(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 6 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 and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (fma x (* 3.0 y) (- z)))
assert(x < y);
double code(double x, double y, double z) {
return fma(x, (3.0 * y), -z);
}
x, y = sort([x, y]) function code(x, y, z) return fma(x, Float64(3.0 * y), Float64(-z)) end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * N[(3.0 * y), $MachinePrecision] + (-z)), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\mathsf{fma}\left(x, 3 \cdot y, -z\right)
\end{array}
Initial program 99.8%
associate-*l*99.8%
fma-neg99.8%
Simplified99.8%
Final simplification99.8%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= z -6e-9)
(- z)
(if (or (<= z -5.4e-44) (and (not (<= z -9.4e-94)) (<= z 1.18e+87)))
(* 3.0 (* x y))
(- z))))assert(x < y);
double code(double x, double y, double z) {
double tmp;
if (z <= -6e-9) {
tmp = -z;
} else if ((z <= -5.4e-44) || (!(z <= -9.4e-94) && (z <= 1.18e+87))) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
NOTE: x and y 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 <= (-6d-9)) then
tmp = -z
else if ((z <= (-5.4d-44)) .or. (.not. (z <= (-9.4d-94))) .and. (z <= 1.18d+87)) then
tmp = 3.0d0 * (x * y)
else
tmp = -z
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if (z <= -6e-9) {
tmp = -z;
} else if ((z <= -5.4e-44) || (!(z <= -9.4e-94) && (z <= 1.18e+87))) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if z <= -6e-9: tmp = -z elif (z <= -5.4e-44) or (not (z <= -9.4e-94) and (z <= 1.18e+87)): tmp = 3.0 * (x * y) else: tmp = -z return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (z <= -6e-9) tmp = Float64(-z); elseif ((z <= -5.4e-44) || (!(z <= -9.4e-94) && (z <= 1.18e+87))) tmp = Float64(3.0 * Float64(x * y)); else tmp = Float64(-z); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= -6e-9)
tmp = -z;
elseif ((z <= -5.4e-44) || (~((z <= -9.4e-94)) && (z <= 1.18e+87)))
tmp = 3.0 * (x * y);
else
tmp = -z;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[z, -6e-9], (-z), If[Or[LessEqual[z, -5.4e-44], And[N[Not[LessEqual[z, -9.4e-94]], $MachinePrecision], LessEqual[z, 1.18e+87]]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{-9}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq -5.4 \cdot 10^{-44} \lor \neg \left(z \leq -9.4 \cdot 10^{-94}\right) \land z \leq 1.18 \cdot 10^{+87}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if z < -5.99999999999999996e-9 or -5.3999999999999998e-44 < z < -9.40000000000000007e-94 or 1.1799999999999999e87 < z Initial program 100.0%
Taylor expanded in x around 0 83.7%
mul-1-neg83.7%
Simplified83.7%
if -5.99999999999999996e-9 < z < -5.3999999999999998e-44 or -9.40000000000000007e-94 < z < 1.1799999999999999e87Initial program 99.7%
Taylor expanded in x around 0 99.7%
Taylor expanded in y around inf 81.0%
Final simplification82.4%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* 3.0 (* x y)) z))
assert(x < y);
double code(double x, double y, double z) {
return (3.0 * (x * y)) - z;
}
NOTE: x and y 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 = (3.0d0 * (x * y)) - z
end function
assert x < y;
public static double code(double x, double y, double z) {
return (3.0 * (x * y)) - z;
}
[x, y] = sort([x, y]) def code(x, y, z): return (3.0 * (x * y)) - z
x, y = sort([x, y]) function code(x, y, z) return Float64(Float64(3.0 * Float64(x * y)) - z) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = (3.0 * (x * y)) - z;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
3 \cdot \left(x \cdot y\right) - z
\end{array}
Initial program 99.8%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* x (* 3.0 y)) z))
assert(x < y);
double code(double x, double y, double z) {
return (x * (3.0 * y)) - z;
}
NOTE: x and y 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;
public static double code(double x, double y, double z) {
return (x * (3.0 * y)) - z;
}
[x, y] = sort([x, y]) def code(x, y, z): return (x * (3.0 * y)) - z
x, y = sort([x, y]) function code(x, y, z) return Float64(Float64(x * Float64(3.0 * y)) - z) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = (x * (3.0 * y)) - z;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x \cdot \left(3 \cdot y\right) - z
\end{array}
Initial program 99.8%
associate-*l*99.8%
fma-neg99.8%
Simplified99.8%
fma-neg99.8%
Applied egg-rr99.8%
Final simplification99.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- z))
assert(x < y);
double code(double x, double y, double z) {
return -z;
}
NOTE: x and y 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;
public static double code(double x, double y, double z) {
return -z;
}
[x, y] = sort([x, y]) def code(x, y, z): return -z
x, y = sort([x, y]) function code(x, y, z) return Float64(-z) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = -z;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := (-z)
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
-z
\end{array}
Initial program 99.8%
Taylor expanded in x around 0 53.8%
mul-1-neg53.8%
Simplified53.8%
Final simplification53.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 z)
assert(x < y);
double code(double x, double y, double z) {
return z;
}
NOTE: x and y 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;
public static double code(double x, double y, double z) {
return z;
}
[x, y] = sort([x, y]) def code(x, y, z): return z
x, y = sort([x, y]) function code(x, y, z) return z end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = z;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := z
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
z
\end{array}
Initial program 99.8%
*-commutative99.8%
associate-*r*99.8%
fma-neg99.8%
add-sqr-sqrt53.2%
sqrt-unprod61.6%
sqr-neg61.6%
sqrt-unprod22.8%
add-sqr-sqrt47.6%
Applied egg-rr47.6%
Taylor expanded in y around 0 2.0%
Final simplification2.0%
(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 2023252
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, B"
:precision binary64
:herbie-target
(- (* x (* 3.0 y)) z)
(- (* (* x 3.0) y) z))