
(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}
(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.4%
associate-*l*99.8%
Simplified99.8%
associate-*r*99.4%
*-commutative99.4%
associate-*r*99.8%
fma-neg99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -9e-30) (not (<= x 2.4e-107))) (* (* y x) 3.0) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9e-30) || !(x <= 2.4e-107)) {
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 ((x <= (-9d-30)) .or. (.not. (x <= 2.4d-107))) 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 ((x <= -9e-30) || !(x <= 2.4e-107)) {
tmp = (y * x) * 3.0;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9e-30) or not (x <= 2.4e-107): tmp = (y * x) * 3.0 else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9e-30) || !(x <= 2.4e-107)) 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 ((x <= -9e-30) || ~((x <= 2.4e-107))) tmp = (y * x) * 3.0; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9e-30], N[Not[LessEqual[x, 2.4e-107]], $MachinePrecision]], N[(N[(y * x), $MachinePrecision] * 3.0), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{-30} \lor \neg \left(x \leq 2.4 \cdot 10^{-107}\right):\\
\;\;\;\;\left(y \cdot x\right) \cdot 3\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -8.99999999999999935e-30 or 2.39999999999999994e-107 < x 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 72.1%
if -8.99999999999999935e-30 < x < 2.39999999999999994e-107Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 70.4%
neg-mul-170.4%
Simplified70.4%
Final simplification71.4%
(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.4%
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.4%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 45.1%
neg-mul-145.1%
Simplified45.1%
Final simplification45.1%
(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 2024021
(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))