
(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 (* 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.9%
associate-*l*99.5%
Simplified99.5%
associate-*r*99.9%
*-commutative99.9%
associate-*r*99.9%
fma-neg99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.25e+60) (not (<= x 185000000.0))) (* (* y x) 3.0) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.25e+60) || !(x <= 185000000.0)) {
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 <= (-1.25d+60)) .or. (.not. (x <= 185000000.0d0))) 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 <= -1.25e+60) || !(x <= 185000000.0)) {
tmp = (y * x) * 3.0;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.25e+60) or not (x <= 185000000.0): tmp = (y * x) * 3.0 else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.25e+60) || !(x <= 185000000.0)) 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 <= -1.25e+60) || ~((x <= 185000000.0))) tmp = (y * x) * 3.0; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.25e+60], N[Not[LessEqual[x, 185000000.0]], $MachinePrecision]], N[(N[(y * x), $MachinePrecision] * 3.0), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{+60} \lor \neg \left(x \leq 185000000\right):\\
\;\;\;\;\left(y \cdot x\right) \cdot 3\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.24999999999999994e60 or 1.85e8 < x Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 75.0%
if -1.24999999999999994e60 < x < 1.85e8Initial program 99.9%
associate-*l*99.3%
Simplified99.3%
Taylor expanded in x around 0 72.1%
neg-mul-172.1%
Simplified72.1%
Final simplification73.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.8e+59) (not (<= x 1550000000000.0))) (* x (* y 3.0)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.8e+59) || !(x <= 1550000000000.0)) {
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 ((x <= (-6.8d+59)) .or. (.not. (x <= 1550000000000.0d0))) 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 ((x <= -6.8e+59) || !(x <= 1550000000000.0)) {
tmp = x * (y * 3.0);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.8e+59) or not (x <= 1550000000000.0): tmp = x * (y * 3.0) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.8e+59) || !(x <= 1550000000000.0)) tmp = Float64(x * Float64(y * 3.0)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.8e+59) || ~((x <= 1550000000000.0))) tmp = x * (y * 3.0); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.8e+59], N[Not[LessEqual[x, 1550000000000.0]], $MachinePrecision]], N[(x * N[(y * 3.0), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.8 \cdot 10^{+59} \lor \neg \left(x \leq 1550000000000\right):\\
\;\;\;\;x \cdot \left(y \cdot 3\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -6.80000000000000012e59 or 1.55e12 < x Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 75.0%
*-commutative75.0%
associate-*r*75.1%
Simplified75.1%
if -6.80000000000000012e59 < x < 1.55e12Initial program 99.9%
associate-*l*99.3%
Simplified99.3%
Taylor expanded in x around 0 72.1%
neg-mul-172.1%
Simplified72.1%
Final simplification73.5%
(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.9%
associate-*l*99.5%
Simplified99.5%
Taylor expanded in x around 0 99.9%
Final simplification99.9%
(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.9%
associate-*l*99.5%
Simplified99.5%
Final simplification99.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 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.5%
Simplified99.5%
Taylor expanded in x around 0 50.3%
neg-mul-150.3%
Simplified50.3%
Final simplification50.3%
(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.5%
Simplified99.5%
Taylor expanded in x around 0 99.9%
*-commutative99.9%
fma-neg99.9%
add-sqr-sqrt54.9%
sqrt-unprod57.7%
sqr-neg57.7%
sqrt-unprod18.8%
add-sqr-sqrt49.1%
Applied egg-rr49.1%
Taylor expanded in x around 0 2.1%
Final simplification2.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 2023305
(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))