
(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 (* 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(x, Float64(3.0 * y), Float64(-z)) end
code[x_, y_, z_] := N[(x * N[(3.0 * y), $MachinePrecision] + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, 3 \cdot y, -z\right)
\end{array}
Initial program 99.4%
associate-*l*99.9%
fma-neg99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= z -1.25e+105) (- z) (if (<= z 2e-76) (* 3.0 (* x y)) (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.25e+105) {
tmp = -z;
} else if (z <= 2e-76) {
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 <= (-1.25d+105)) then
tmp = -z
else if (z <= 2d-76) 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 <= -1.25e+105) {
tmp = -z;
} else if (z <= 2e-76) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.25e+105: tmp = -z elif z <= 2e-76: tmp = 3.0 * (x * y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.25e+105) tmp = Float64(-z); elseif (z <= 2e-76) 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 <= -1.25e+105) tmp = -z; elseif (z <= 2e-76) tmp = 3.0 * (x * y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.25e+105], (-z), If[LessEqual[z, 2e-76], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.25 \cdot 10^{+105}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq 2 \cdot 10^{-76}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if z < -1.25000000000000011e105 or 1.99999999999999985e-76 < z Initial program 99.1%
associate-*l*100.0%
fma-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 77.8%
mul-1-neg77.8%
Simplified77.8%
if -1.25000000000000011e105 < z < 1.99999999999999985e-76Initial program 99.8%
associate-*l*99.8%
fma-neg99.8%
Simplified99.8%
add-sqr-sqrt36.1%
sqrt-unprod82.7%
sqr-neg82.7%
sqrt-unprod48.4%
add-sqr-sqrt79.1%
fma-neg79.1%
add-cube-cbrt79.1%
distribute-rgt-neg-in79.1%
associate-*l*79.0%
add-cube-cbrt77.9%
associate-*l*77.9%
prod-diff77.9%
Applied egg-rr55.1%
Simplified55.2%
Taylor expanded in x around inf 79.3%
Applied egg-rr79.6%
neg-sub079.6%
distribute-rgt-neg-in79.6%
distribute-rgt-neg-in79.6%
metadata-eval79.6%
Simplified79.6%
Taylor expanded in x around 0 79.5%
Final simplification78.7%
(FPCore (x y z) :precision binary64 (if (<= z -1.7e+105) (- z) (if (<= z 2e-76) (* x (* 3.0 y)) (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.7e+105) {
tmp = -z;
} else if (z <= 2e-76) {
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.7d+105)) then
tmp = -z
else if (z <= 2d-76) 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.7e+105) {
tmp = -z;
} else if (z <= 2e-76) {
tmp = x * (3.0 * y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.7e+105: tmp = -z elif z <= 2e-76: tmp = x * (3.0 * y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.7e+105) tmp = Float64(-z); elseif (z <= 2e-76) tmp = Float64(x * Float64(3.0 * y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.7e+105) tmp = -z; elseif (z <= 2e-76) tmp = x * (3.0 * y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.7e+105], (-z), If[LessEqual[z, 2e-76], N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{+105}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq 2 \cdot 10^{-76}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if z < -1.7e105 or 1.99999999999999985e-76 < z Initial program 99.1%
associate-*l*100.0%
fma-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 77.8%
mul-1-neg77.8%
Simplified77.8%
if -1.7e105 < z < 1.99999999999999985e-76Initial program 99.8%
associate-*l*99.8%
fma-neg99.8%
Simplified99.8%
add-sqr-sqrt36.1%
sqrt-unprod82.7%
sqr-neg82.7%
sqrt-unprod48.4%
add-sqr-sqrt79.1%
fma-neg79.1%
add-cube-cbrt79.1%
distribute-rgt-neg-in79.1%
associate-*l*79.0%
add-cube-cbrt77.9%
associate-*l*77.9%
prod-diff77.9%
Applied egg-rr55.1%
Simplified55.2%
Taylor expanded in x around inf 79.3%
Applied egg-rr79.6%
neg-sub079.6%
distribute-rgt-neg-in79.6%
distribute-rgt-neg-in79.6%
metadata-eval79.6%
Simplified79.6%
Final simplification78.8%
(FPCore (x y z) :precision binary64 (if (<= z -1.25e+105) (- z) (if (<= z 2e-76) (* y (* x 3.0)) (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.25e+105) {
tmp = -z;
} else if (z <= 2e-76) {
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 (z <= (-1.25d+105)) then
tmp = -z
else if (z <= 2d-76) 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 (z <= -1.25e+105) {
tmp = -z;
} else if (z <= 2e-76) {
tmp = y * (x * 3.0);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.25e+105: tmp = -z elif z <= 2e-76: tmp = y * (x * 3.0) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.25e+105) tmp = Float64(-z); elseif (z <= 2e-76) tmp = Float64(y * Float64(x * 3.0)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.25e+105) tmp = -z; elseif (z <= 2e-76) tmp = y * (x * 3.0); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.25e+105], (-z), If[LessEqual[z, 2e-76], N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.25 \cdot 10^{+105}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq 2 \cdot 10^{-76}:\\
\;\;\;\;y \cdot \left(x \cdot 3\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if z < -1.25000000000000011e105 or 1.99999999999999985e-76 < z Initial program 99.1%
associate-*l*100.0%
fma-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 77.8%
mul-1-neg77.8%
Simplified77.8%
if -1.25000000000000011e105 < z < 1.99999999999999985e-76Initial program 99.8%
associate-*l*99.8%
fma-neg99.8%
Simplified99.8%
add-sqr-sqrt36.1%
sqrt-unprod82.7%
sqr-neg82.7%
sqrt-unprod48.4%
add-sqr-sqrt79.1%
fma-neg79.1%
add-cube-cbrt79.1%
distribute-rgt-neg-in79.1%
associate-*l*79.0%
add-cube-cbrt77.9%
associate-*l*77.9%
prod-diff77.9%
Applied egg-rr55.1%
Simplified55.2%
Taylor expanded in x around inf 79.3%
Applied egg-rr79.6%
neg-sub079.6%
associate-*r*79.5%
*-commutative79.5%
distribute-rgt-neg-in79.5%
metadata-eval79.5%
associate-*l*79.6%
Simplified79.6%
Final simplification78.7%
(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.4%
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(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}
Initial program 99.4%
associate-*l*99.9%
fma-neg99.9%
Simplified99.9%
fma-udef99.9%
associate-*l*99.4%
unsub-neg99.4%
associate-*l*99.9%
Applied egg-rr99.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.4%
associate-*l*99.9%
fma-neg99.9%
Simplified99.9%
Taylor expanded in x around 0 48.5%
mul-1-neg48.5%
Simplified48.5%
Final simplification48.5%
(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.4%
associate-*l*99.9%
fma-neg99.9%
Simplified99.9%
add-sqr-sqrt50.5%
sqrt-unprod64.9%
sqr-neg64.9%
sqrt-unprod29.9%
add-sqr-sqrt52.6%
fma-neg52.6%
add-cube-cbrt52.6%
distribute-rgt-neg-in52.6%
associate-*l*52.5%
add-cube-cbrt51.9%
associate-*l*51.9%
prod-diff51.9%
Applied egg-rr36.2%
Simplified36.3%
Taylor expanded in y around 0 2.0%
Final simplification2.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 2023230
(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))