
(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}
(FPCore (x y z) :precision binary64 (fma (* y x) 3.0 (- z)))
double code(double x, double y, double z) {
return fma((y * x), 3.0, -z);
}
function code(x, y, z) return fma(Float64(y * x), 3.0, Float64(-z)) end
code[x_, y_, z_] := N[(N[(y * x), $MachinePrecision] * 3.0 + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y \cdot x, 3, -z\right)
\end{array}
Initial program 99.5%
associate-*l*99.8%
Simplified99.8%
associate-*r*99.5%
*-commutative99.5%
associate-*r*99.8%
fma-neg99.8%
Applied egg-rr99.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.7e-126) (not (<= y 3.8e+112))) (* (* y x) 3.0) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.7e-126) || !(y <= 3.8e+112)) {
tmp = (y * x) * 3.0;
} else {
tmp = -z;
}
return tmp;
}
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 <= (-2.7d-126)) .or. (.not. (y <= 3.8d+112))) then
tmp = (y * x) * 3.0d0
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.7e-126) || !(y <= 3.8e+112)) {
tmp = (y * x) * 3.0;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.7e-126) or not (y <= 3.8e+112): tmp = (y * x) * 3.0 else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.7e-126) || !(y <= 3.8e+112)) tmp = Float64(Float64(y * x) * 3.0); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.7e-126) || ~((y <= 3.8e+112))) tmp = (y * x) * 3.0; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.7e-126], N[Not[LessEqual[y, 3.8e+112]], $MachinePrecision]], N[(N[(y * x), $MachinePrecision] * 3.0), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.7 \cdot 10^{-126} \lor \neg \left(y \leq 3.8 \cdot 10^{+112}\right):\\
\;\;\;\;\left(y \cdot x\right) \cdot 3\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -2.69999999999999995e-126 or 3.80000000000000008e112 < y Initial program 99.1%
associate-*l*99.8%
Simplified99.8%
associate-*r*99.1%
*-commutative99.1%
associate-*r*99.8%
fma-neg99.8%
Applied egg-rr99.8%
Taylor expanded in y around inf 60.5%
if -2.69999999999999995e-126 < y < 3.80000000000000008e112Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 70.4%
neg-mul-170.4%
Simplified70.4%
Final simplification65.6%
(FPCore (x y z) :precision binary64 (- (* y (* x 3.0)) z))
double code(double x, double y, double z) {
return (y * (x * 3.0)) - z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y * (x * 3.0d0)) - z
end function
public static double code(double x, double y, double z) {
return (y * (x * 3.0)) - z;
}
def code(x, y, z): return (y * (x * 3.0)) - z
function code(x, y, z) return Float64(Float64(y * Float64(x * 3.0)) - z) end
function tmp = code(x, y, z) tmp = (y * (x * 3.0)) - z; end
code[x_, y_, z_] := N[(N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(x \cdot 3\right) - z
\end{array}
Initial program 99.5%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (- (* (* y x) 3.0) z))
double code(double x, double y, double z) {
return ((y * x) * 3.0) - z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((y * x) * 3.0d0) - z
end function
public static double code(double x, double y, double z) {
return ((y * x) * 3.0) - z;
}
def code(x, y, z): return ((y * x) * 3.0) - z
function code(x, y, z) return Float64(Float64(Float64(y * x) * 3.0) - z) end
function tmp = code(x, y, z) tmp = ((y * x) * 3.0) - z; end
code[x_, y_, z_] := N[(N[(N[(y * x), $MachinePrecision] * 3.0), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(y \cdot x\right) \cdot 3 - z
\end{array}
Initial program 99.5%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
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
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 99.5%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 55.9%
neg-mul-155.9%
Simplified55.9%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
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
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.5%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
sub-neg99.8%
associate-*r*99.5%
*-commutative99.5%
add-sqr-sqrt52.9%
associate-*r*53.0%
fma-undefine53.0%
add-sqr-sqrt27.9%
sqrt-unprod30.0%
sqr-neg30.0%
sqrt-unprod9.1%
add-sqr-sqrt24.2%
Applied egg-rr24.2%
Taylor expanded in x around 0 2.3%
(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 2024105
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, B"
:precision binary64
:alt
(- (* x (* 3.0 y)) z)
(- (* (* x 3.0) y) z))