
(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 7 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 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.8%
fma-neg99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (<= z -6.8e+56) (- z) (if (<= z 0.106) (* 3.0 (* x y)) (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.8e+56) {
tmp = -z;
} else if (z <= 0.106) {
tmp = 3.0 * (x * y);
} 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 (z <= (-6.8d+56)) then
tmp = -z
else if (z <= 0.106d0) then
tmp = 3.0d0 * (x * y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -6.8e+56) {
tmp = -z;
} else if (z <= 0.106) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.8e+56: tmp = -z elif z <= 0.106: tmp = 3.0 * (x * y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.8e+56) tmp = Float64(-z); elseif (z <= 0.106) tmp = Float64(3.0 * Float64(x * y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6.8e+56) tmp = -z; elseif (z <= 0.106) tmp = 3.0 * (x * y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.8e+56], (-z), If[LessEqual[z, 0.106], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.8 \cdot 10^{+56}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq 0.106:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if z < -6.80000000000000002e56 or 0.105999999999999997 < z Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 79.1%
mul-1-neg79.1%
Simplified79.1%
if -6.80000000000000002e56 < z < 0.105999999999999997Initial program 99.7%
associate-*l*99.6%
Simplified99.6%
*-commutative99.6%
add-sqr-sqrt48.3%
associate-*r*48.3%
fma-neg48.3%
add-sqr-sqrt24.8%
sqrt-unprod42.1%
sqr-neg42.1%
sqrt-unprod17.9%
add-sqr-sqrt37.6%
Applied egg-rr37.6%
Taylor expanded in y around inf 77.6%
Final simplification78.3%
(FPCore (x y z) :precision binary64 (if (<= z -1.6e+57) (- z) (if (<= z 0.93) (* (* x 3.0) y) (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.6e+57) {
tmp = -z;
} else if (z <= 0.93) {
tmp = (x * 3.0) * y;
} 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 (z <= (-1.6d+57)) then
tmp = -z
else if (z <= 0.93d0) then
tmp = (x * 3.0d0) * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.6e+57) {
tmp = -z;
} else if (z <= 0.93) {
tmp = (x * 3.0) * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.6e+57: tmp = -z elif z <= 0.93: tmp = (x * 3.0) * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.6e+57) tmp = Float64(-z); elseif (z <= 0.93) tmp = Float64(Float64(x * 3.0) * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.6e+57) tmp = -z; elseif (z <= 0.93) tmp = (x * 3.0) * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.6e+57], (-z), If[LessEqual[z, 0.93], N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.6 \cdot 10^{+57}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq 0.93:\\
\;\;\;\;\left(x \cdot 3\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if z < -1.60000000000000015e57 or 0.930000000000000049 < z Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 79.1%
mul-1-neg79.1%
Simplified79.1%
if -1.60000000000000015e57 < z < 0.930000000000000049Initial program 99.7%
associate-*l*99.6%
Simplified99.6%
*-commutative99.6%
add-sqr-sqrt48.3%
associate-*r*48.3%
fma-neg48.3%
add-sqr-sqrt24.8%
sqrt-unprod42.1%
sqr-neg42.1%
sqrt-unprod17.9%
add-sqr-sqrt37.6%
Applied egg-rr37.6%
Taylor expanded in y around inf 77.6%
associate-*r*77.6%
*-commutative77.6%
associate-*r*77.5%
Simplified77.5%
add-sqr-sqrt43.6%
pow243.6%
Applied egg-rr43.6%
unpow243.6%
add-sqr-sqrt77.5%
associate-*r*77.6%
*-commutative77.6%
Applied egg-rr77.6%
Final simplification78.3%
(FPCore (x y z) :precision binary64 (- (* 3.0 (* x y)) z))
double code(double x, double y, double z) {
return (3.0 * (x * 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 = (3.0d0 * (x * y)) - z
end function
public static double code(double x, double y, double z) {
return (3.0 * (x * y)) - z;
}
def code(x, y, z): return (3.0 * (x * y)) - z
function code(x, y, z) return Float64(Float64(3.0 * Float64(x * y)) - z) end
function tmp = code(x, y, z) tmp = (3.0 * (x * y)) - z; end
code[x_, y_, z_] := N[(N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
3 \cdot \left(x \cdot y\right) - 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 (- (* (* 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}
Initial program 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 48.8%
mul-1-neg48.8%
Simplified48.8%
Final simplification48.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 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%
*-commutative99.8%
add-sqr-sqrt52.9%
associate-*r*52.9%
fma-neg52.9%
add-sqr-sqrt23.7%
sqrt-unprod30.1%
sqr-neg30.1%
sqrt-unprod13.0%
add-sqr-sqrt26.4%
Applied egg-rr26.4%
Taylor expanded in y around 0 2.3%
Final simplification2.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 2023292
(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))