
(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 5 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 3.0 (* y x) (- z)))
double code(double x, double y, double z) {
return fma(3.0, (y * x), -z);
}
function code(x, y, z) return fma(3.0, Float64(y * x), Float64(-z)) end
code[x_, y_, z_] := N[(3.0 * N[(y * x), $MachinePrecision] + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(3, y \cdot x, -z\right)
\end{array}
Initial program 99.9%
associate-*l*99.8%
fma-neg99.8%
Simplified99.8%
fma-udef99.8%
add-sqr-sqrt54.8%
sqrt-unprod61.3%
sqr-neg61.3%
sqrt-unprod22.0%
add-sqr-sqrt47.4%
Applied egg-rr47.4%
*-commutative47.4%
associate-*r*47.4%
*-commutative47.4%
fma-def47.4%
*-commutative47.4%
Simplified47.4%
add-sqr-sqrt22.0%
sqrt-unprod61.3%
add-sqr-sqrt20.7%
add-sqr-sqrt20.7%
sqr-neg20.7%
neg-mul-120.7%
neg-mul-120.7%
swap-sqr20.7%
sqrt-unprod0.0%
add-sqr-sqrt44.7%
neg-mul-144.7%
distribute-rgt-neg-out44.7%
add-sqr-sqrt99.9%
fma-neg99.9%
add-sqr-sqrt44.7%
sqrt-unprod56.8%
add-sqr-sqrt32.5%
add-sqr-sqrt32.4%
sqr-neg32.4%
neg-mul-132.4%
neg-mul-132.4%
Applied egg-rr44.7%
associate-*r*44.7%
fma-udef44.7%
distribute-rgt-out44.7%
distribute-lft-out44.7%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.2e+116) (not (<= x 8e-93))) (* 3.0 (* y x)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.2e+116) || !(x <= 8e-93)) {
tmp = 3.0 * (y * x);
} 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 <= (-7.2d+116)) .or. (.not. (x <= 8d-93))) then
tmp = 3.0d0 * (y * x)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7.2e+116) || !(x <= 8e-93)) {
tmp = 3.0 * (y * x);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.2e+116) or not (x <= 8e-93): tmp = 3.0 * (y * x) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.2e+116) || !(x <= 8e-93)) tmp = Float64(3.0 * Float64(y * x)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.2e+116) || ~((x <= 8e-93))) tmp = 3.0 * (y * x); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.2e+116], N[Not[LessEqual[x, 8e-93]], $MachinePrecision]], N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{+116} \lor \neg \left(x \leq 8 \cdot 10^{-93}\right):\\
\;\;\;\;3 \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -7.19999999999999941e116 or 7.9999999999999992e-93 < x Initial program 99.8%
associate-*l*99.7%
fma-neg99.7%
Simplified99.7%
fma-udef99.7%
add-sqr-sqrt53.3%
sqrt-unprod80.1%
sqr-neg80.1%
sqrt-unprod39.3%
add-sqr-sqrt74.0%
Applied egg-rr74.0%
*-commutative74.0%
associate-*r*74.1%
*-commutative74.1%
fma-def74.0%
*-commutative74.0%
Simplified74.0%
fma-udef74.1%
flip-+32.0%
*-commutative32.0%
*-commutative32.0%
swap-sqr31.9%
pow231.9%
metadata-eval31.9%
*-commutative31.9%
associate-*l*31.8%
fma-neg31.8%
add-sqr-sqrt13.5%
distribute-rgt-neg-out13.5%
neg-mul-113.5%
add-sqr-sqrt0.0%
sqrt-unprod17.0%
swap-sqr17.0%
add-sqr-sqrt17.0%
neg-mul-117.0%
Applied egg-rr45.0%
Taylor expanded in y around inf 74.7%
if -7.19999999999999941e116 < x < 7.9999999999999992e-93Initial program 99.9%
associate-*l*99.9%
fma-neg99.9%
Simplified99.9%
Taylor expanded in x around 0 73.6%
mul-1-neg73.6%
Simplified73.6%
Final simplification74.0%
(FPCore (x y z) :precision binary64 (- (* 3.0 (* y x)) z))
double code(double x, double y, double z) {
return (3.0 * (y * x)) - 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 * (y * x)) - z
end function
public static double code(double x, double y, double z) {
return (3.0 * (y * x)) - z;
}
def code(x, y, z): return (3.0 * (y * x)) - z
function code(x, y, z) return Float64(Float64(3.0 * Float64(y * x)) - z) end
function tmp = code(x, y, z) tmp = (3.0 * (y * x)) - z; end
code[x_, y_, z_] := N[(N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
3 \cdot \left(y \cdot x\right) - 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%
associate-*l*99.8%
fma-neg99.8%
Simplified99.8%
Taylor expanded in x around 0 53.2%
mul-1-neg53.2%
Simplified53.2%
Final simplification53.2%
(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%
associate-*l*99.8%
fma-neg99.8%
Simplified99.8%
fma-udef99.8%
add-sqr-sqrt54.8%
sqrt-unprod61.3%
sqr-neg61.3%
sqrt-unprod22.0%
add-sqr-sqrt47.4%
Applied egg-rr47.4%
*-commutative47.4%
associate-*r*47.4%
*-commutative47.4%
fma-def47.4%
*-commutative47.4%
Simplified47.4%
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 2023257
(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))