
(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 (* 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(Float64(3.0 * y), x, Float64(-z)) end
code[x_, y_, z_] := N[(N[(3.0 * y), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(3 \cdot y, x, -z\right)
\end{array}
Initial program 99.8%
associate-*l*99.9%
*-commutative99.9%
fma-neg99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.6e-64) (not (<= z 9e-6))) (- z) (* 3.0 (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.6e-64) || !(z <= 9e-6)) {
tmp = -z;
} else {
tmp = 3.0 * (y * x);
}
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 <= (-4.6d-64)) .or. (.not. (z <= 9d-6))) then
tmp = -z
else
tmp = 3.0d0 * (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4.6e-64) || !(z <= 9e-6)) {
tmp = -z;
} else {
tmp = 3.0 * (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.6e-64) or not (z <= 9e-6): tmp = -z else: tmp = 3.0 * (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.6e-64) || !(z <= 9e-6)) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.6e-64) || ~((z <= 9e-6))) tmp = -z; else tmp = 3.0 * (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.6e-64], N[Not[LessEqual[z, 9e-6]], $MachinePrecision]], (-z), N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.6 \cdot 10^{-64} \lor \neg \left(z \leq 9 \cdot 10^{-6}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if z < -4.6000000000000003e-64 or 9.00000000000000023e-6 < z Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 78.1%
mul-1-neg78.1%
Simplified78.1%
if -4.6000000000000003e-64 < z < 9.00000000000000023e-6Initial program 99.7%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 77.0%
Final simplification77.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.8e-65) (not (<= z 0.078))) (- z) (* (* 3.0 y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.8e-65) || !(z <= 0.078)) {
tmp = -z;
} else {
tmp = (3.0 * y) * x;
}
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 <= (-2.8d-65)) .or. (.not. (z <= 0.078d0))) then
tmp = -z
else
tmp = (3.0d0 * y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.8e-65) || !(z <= 0.078)) {
tmp = -z;
} else {
tmp = (3.0 * y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.8e-65) or not (z <= 0.078): tmp = -z else: tmp = (3.0 * y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.8e-65) || !(z <= 0.078)) tmp = Float64(-z); else tmp = Float64(Float64(3.0 * y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.8e-65) || ~((z <= 0.078))) tmp = -z; else tmp = (3.0 * y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.8e-65], N[Not[LessEqual[z, 0.078]], $MachinePrecision]], (-z), N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{-65} \lor \neg \left(z \leq 0.078\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(3 \cdot y\right) \cdot x\\
\end{array}
\end{array}
if z < -2.8e-65 or 0.0779999999999999999 < z Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 78.1%
mul-1-neg78.1%
Simplified78.1%
if -2.8e-65 < z < 0.0779999999999999999Initial program 99.7%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 77.0%
associate-*r*77.0%
*-commutative77.0%
associate-*r*77.0%
Simplified77.0%
Final simplification77.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.9e-64) (not (<= z 1.25e-5))) (- z) (* y (* 3.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.9e-64) || !(z <= 1.25e-5)) {
tmp = -z;
} else {
tmp = y * (3.0 * x);
}
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 <= (-4.9d-64)) .or. (.not. (z <= 1.25d-5))) then
tmp = -z
else
tmp = y * (3.0d0 * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4.9e-64) || !(z <= 1.25e-5)) {
tmp = -z;
} else {
tmp = y * (3.0 * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.9e-64) or not (z <= 1.25e-5): tmp = -z else: tmp = y * (3.0 * x) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.9e-64) || !(z <= 1.25e-5)) tmp = Float64(-z); else tmp = Float64(y * Float64(3.0 * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.9e-64) || ~((z <= 1.25e-5))) tmp = -z; else tmp = y * (3.0 * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.9e-64], N[Not[LessEqual[z, 1.25e-5]], $MachinePrecision]], (-z), N[(y * N[(3.0 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.9 \cdot 10^{-64} \lor \neg \left(z \leq 1.25 \cdot 10^{-5}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(3 \cdot x\right)\\
\end{array}
\end{array}
if z < -4.9000000000000002e-64 or 1.25000000000000006e-5 < z Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 78.1%
mul-1-neg78.1%
Simplified78.1%
if -4.9000000000000002e-64 < z < 1.25000000000000006e-5Initial program 99.7%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 77.0%
associate-*r*77.0%
Simplified77.0%
Final simplification77.6%
(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.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
(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(Float64(3.0 * y) * x) - z) end
function tmp = code(x, y, z) tmp = ((3.0 * y) * x) - z; end
code[x_, y_, z_] := N[(N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(3 \cdot y\right) \cdot x - z
\end{array}
Initial program 99.8%
associate-*l*99.9%
Simplified99.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.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 53.9%
mul-1-neg53.9%
Simplified53.9%
Final simplification53.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 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.9%
Simplified99.9%
associate-*r*99.8%
*-commutative99.8%
associate-*r*99.8%
fma-neg99.9%
add-sqr-sqrt54.0%
sqrt-unprod60.8%
sqr-neg60.8%
sqrt-unprod22.9%
add-sqr-sqrt46.7%
Applied egg-rr46.7%
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 2023306
(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))