
(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.9%
Taylor expanded in x around 0 99.9%
*-commutative99.9%
fma-neg99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (fma (* x 3.0) y (- z)))
double code(double x, double y, double z) {
return fma((x * 3.0), y, -z);
}
function code(x, y, z) return fma(Float64(x * 3.0), y, Float64(-z)) end
code[x_, y_, z_] := N[(N[(x * 3.0), $MachinePrecision] * y + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot 3, y, -z\right)
\end{array}
Initial program 99.9%
fma-neg99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (or (<= y -1.5e-138)
(and (not (<= y 300000000.0))
(or (<= y 2.55e+72) (not (<= y 1.75e+115)))))
(* (* y x) 3.0)
(- z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.5e-138) || (!(y <= 300000000.0) && ((y <= 2.55e+72) || !(y <= 1.75e+115)))) {
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 <= (-1.5d-138)) .or. (.not. (y <= 300000000.0d0)) .and. (y <= 2.55d+72) .or. (.not. (y <= 1.75d+115))) 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 <= -1.5e-138) || (!(y <= 300000000.0) && ((y <= 2.55e+72) || !(y <= 1.75e+115)))) {
tmp = (y * x) * 3.0;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.5e-138) or (not (y <= 300000000.0) and ((y <= 2.55e+72) or not (y <= 1.75e+115))): tmp = (y * x) * 3.0 else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.5e-138) || (!(y <= 300000000.0) && ((y <= 2.55e+72) || !(y <= 1.75e+115)))) 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 <= -1.5e-138) || (~((y <= 300000000.0)) && ((y <= 2.55e+72) || ~((y <= 1.75e+115))))) tmp = (y * x) * 3.0; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.5e-138], And[N[Not[LessEqual[y, 300000000.0]], $MachinePrecision], Or[LessEqual[y, 2.55e+72], N[Not[LessEqual[y, 1.75e+115]], $MachinePrecision]]]], N[(N[(y * x), $MachinePrecision] * 3.0), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{-138} \lor \neg \left(y \leq 300000000\right) \land \left(y \leq 2.55 \cdot 10^{+72} \lor \neg \left(y \leq 1.75 \cdot 10^{+115}\right)\right):\\
\;\;\;\;\left(y \cdot x\right) \cdot 3\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -1.5e-138 or 3e8 < y < 2.54999999999999989e72 or 1.75000000000000003e115 < y Initial program 99.9%
Taylor expanded in x around 0 99.9%
Taylor expanded in y around inf 67.7%
if -1.5e-138 < y < 3e8 or 2.54999999999999989e72 < y < 1.75000000000000003e115Initial program 99.9%
Taylor expanded in x around 0 72.8%
mul-1-neg72.8%
Simplified72.8%
Final simplification70.3%
(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.9%
Taylor expanded in x around 0 99.9%
Final simplification99.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 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.9%
Taylor expanded in x around 0 53.6%
mul-1-neg53.6%
Simplified53.6%
Final simplification53.6%
(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.9%
*-commutative99.9%
add-cube-cbrt99.2%
associate-*l*99.2%
fma-neg99.2%
add-sqr-sqrt45.2%
sqrt-unprod57.7%
sqr-neg57.7%
sqrt-unprod27.3%
add-sqr-sqrt46.7%
pow246.7%
Applied egg-rr46.7%
Taylor expanded in y around 0 2.2%
Final simplification2.2%
(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 2023174
(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))