
(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 8 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 (* x y) 3.0 (- z)))
double code(double x, double y, double z) {
return fma((x * y), 3.0, -z);
}
function code(x, y, z) return fma(Float64(x * y), 3.0, Float64(-z)) end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] * 3.0 + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot y, 3, -z\right)
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
*-commutative99.8%
fmm-def99.8%
Applied egg-rr99.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.4e-141) (not (<= y 7.4e-13))) (* (* x y) 3.0) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.4e-141) || !(y <= 7.4e-13)) {
tmp = (x * y) * 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 <= (-4.4d-141)) .or. (.not. (y <= 7.4d-13))) then
tmp = (x * y) * 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 <= -4.4e-141) || !(y <= 7.4e-13)) {
tmp = (x * y) * 3.0;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.4e-141) or not (y <= 7.4e-13): tmp = (x * y) * 3.0 else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.4e-141) || !(y <= 7.4e-13)) tmp = Float64(Float64(x * y) * 3.0); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.4e-141) || ~((y <= 7.4e-13))) tmp = (x * y) * 3.0; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.4e-141], N[Not[LessEqual[y, 7.4e-13]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] * 3.0), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{-141} \lor \neg \left(y \leq 7.4 \cdot 10^{-13}\right):\\
\;\;\;\;\left(x \cdot y\right) \cdot 3\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -4.40000000000000018e-141 or 7.39999999999999977e-13 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around inf 86.6%
+-commutative86.6%
distribute-rgt-in86.7%
*-commutative86.7%
*-commutative86.7%
associate-*r*86.7%
metadata-eval86.7%
distribute-rgt-neg-in86.7%
*-commutative86.7%
*-commutative86.7%
associate-*r*86.7%
mul-1-neg86.7%
distribute-lft-neg-out86.7%
distribute-neg-in86.7%
distribute-rgt-in86.6%
distribute-rgt-neg-in86.6%
*-commutative86.6%
fma-define86.6%
Simplified86.6%
Taylor expanded in x around inf 66.2%
if -4.40000000000000018e-141 < y < 7.39999999999999977e-13Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 82.6%
mul-1-neg82.6%
Simplified82.6%
Final simplification71.5%
(FPCore (x y z) :precision binary64 (if (<= y -2.4e-141) (* (* x y) 3.0) (if (<= y 5400000.0) (- z) (* x (* y 3.0)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.4e-141) {
tmp = (x * y) * 3.0;
} else if (y <= 5400000.0) {
tmp = -z;
} else {
tmp = x * (y * 3.0);
}
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.4d-141)) then
tmp = (x * y) * 3.0d0
else if (y <= 5400000.0d0) then
tmp = -z
else
tmp = x * (y * 3.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.4e-141) {
tmp = (x * y) * 3.0;
} else if (y <= 5400000.0) {
tmp = -z;
} else {
tmp = x * (y * 3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.4e-141: tmp = (x * y) * 3.0 elif y <= 5400000.0: tmp = -z else: tmp = x * (y * 3.0) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.4e-141) tmp = Float64(Float64(x * y) * 3.0); elseif (y <= 5400000.0) tmp = Float64(-z); else tmp = Float64(x * Float64(y * 3.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.4e-141) tmp = (x * y) * 3.0; elseif (y <= 5400000.0) tmp = -z; else tmp = x * (y * 3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.4e-141], N[(N[(x * y), $MachinePrecision] * 3.0), $MachinePrecision], If[LessEqual[y, 5400000.0], (-z), N[(x * N[(y * 3.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{-141}:\\
\;\;\;\;\left(x \cdot y\right) \cdot 3\\
\mathbf{elif}\;y \leq 5400000:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot 3\right)\\
\end{array}
\end{array}
if y < -2.4000000000000001e-141Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around inf 86.7%
+-commutative86.7%
distribute-rgt-in86.7%
*-commutative86.7%
*-commutative86.7%
associate-*r*86.8%
metadata-eval86.8%
distribute-rgt-neg-in86.8%
*-commutative86.8%
*-commutative86.8%
associate-*r*86.7%
mul-1-neg86.7%
distribute-lft-neg-out86.7%
distribute-neg-in86.7%
distribute-rgt-in86.7%
distribute-rgt-neg-in86.7%
*-commutative86.7%
fma-define86.7%
Simplified86.7%
Taylor expanded in x around inf 59.5%
if -2.4000000000000001e-141 < y < 5.4e6Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 81.6%
mul-1-neg81.6%
Simplified81.6%
if 5.4e6 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around inf 86.4%
+-commutative86.4%
distribute-rgt-in86.4%
*-commutative86.4%
*-commutative86.4%
associate-*r*86.3%
metadata-eval86.3%
distribute-rgt-neg-in86.3%
*-commutative86.3%
*-commutative86.3%
associate-*r*86.4%
mul-1-neg86.4%
distribute-lft-neg-out86.4%
distribute-neg-in86.4%
distribute-rgt-in86.4%
distribute-rgt-neg-in86.4%
*-commutative86.4%
fma-define86.4%
Simplified86.4%
Taylor expanded in y around inf 75.3%
Final simplification71.2%
(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.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (- (* x (* y 3.0)) z))
double code(double x, double y, double z) {
return (x * (y * 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 = (x * (y * 3.0d0)) - z
end function
public static double code(double x, double y, double z) {
return (x * (y * 3.0)) - z;
}
def code(x, y, z): return (x * (y * 3.0)) - z
function code(x, y, z) return Float64(Float64(x * Float64(y * 3.0)) - z) end
function tmp = code(x, y, z) tmp = (x * (y * 3.0)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(y * 3.0), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y \cdot 3\right) - z
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (- (* (* x y) 3.0) z))
double code(double x, double y, double z) {
return ((x * y) * 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 = ((x * y) * 3.0d0) - z
end function
public static double code(double x, double y, double z) {
return ((x * y) * 3.0) - z;
}
def code(x, y, z): return ((x * y) * 3.0) - z
function code(x, y, z) return Float64(Float64(Float64(x * y) * 3.0) - z) end
function tmp = code(x, y, z) tmp = ((x * y) * 3.0) - z; end
code[x_, y_, z_] := N[(N[(N[(x * y), $MachinePrecision] * 3.0), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y\right) \cdot 3 - z
\end{array}
Initial program 99.8%
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.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 51.0%
mul-1-neg51.0%
Simplified51.0%
(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.8%
associate-*l*99.8%
Simplified99.8%
associate-*r*99.8%
*-commutative99.8%
associate-*r*99.8%
fmm-def99.8%
add-sqr-sqrt48.2%
sqrt-unprod58.7%
sqr-neg58.7%
sqrt-unprod23.6%
add-sqr-sqrt50.0%
Applied egg-rr50.0%
Taylor expanded in y around 0 2.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 2024191
(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))