
(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 (* x y) (- z)))
double code(double x, double y, double z) {
return fma(3.0, (x * y), -z);
}
function code(x, y, z) return fma(3.0, Float64(x * y), Float64(-z)) end
code[x_, y_, z_] := N[(3.0 * N[(x * y), $MachinePrecision] + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(3, x \cdot y, -z\right)
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -205000000.0) (not (<= z 4.1e+38))) (- z) (* 3.0 (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -205000000.0) || !(z <= 4.1e+38)) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
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 <= (-205000000.0d0)) .or. (.not. (z <= 4.1d+38))) then
tmp = -z
else
tmp = 3.0d0 * (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -205000000.0) || !(z <= 4.1e+38)) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -205000000.0) or not (z <= 4.1e+38): tmp = -z else: tmp = 3.0 * (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -205000000.0) || !(z <= 4.1e+38)) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -205000000.0) || ~((z <= 4.1e+38))) tmp = -z; else tmp = 3.0 * (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -205000000.0], N[Not[LessEqual[z, 4.1e+38]], $MachinePrecision]], (-z), N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -205000000 \lor \neg \left(z \leq 4.1 \cdot 10^{+38}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -2.05e8 or 4.1000000000000003e38 < z Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 75.4%
mul-1-neg75.4%
Simplified75.4%
if -2.05e8 < z < 4.1000000000000003e38Initial program 99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.6%
mul-1-neg99.6%
+-commutative99.6%
fma-def99.8%
Simplified99.8%
Taylor expanded in x around inf 73.3%
Final simplification74.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -14000000.0) (not (<= z 4.2e+38))) (- z) (* x (* 3.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -14000000.0) || !(z <= 4.2e+38)) {
tmp = -z;
} else {
tmp = x * (3.0 * y);
}
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 <= (-14000000.0d0)) .or. (.not. (z <= 4.2d+38))) then
tmp = -z
else
tmp = x * (3.0d0 * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -14000000.0) || !(z <= 4.2e+38)) {
tmp = -z;
} else {
tmp = x * (3.0 * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -14000000.0) or not (z <= 4.2e+38): tmp = -z else: tmp = x * (3.0 * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -14000000.0) || !(z <= 4.2e+38)) tmp = Float64(-z); else tmp = Float64(x * Float64(3.0 * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -14000000.0) || ~((z <= 4.2e+38))) tmp = -z; else tmp = x * (3.0 * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -14000000.0], N[Not[LessEqual[z, 4.2e+38]], $MachinePrecision]], (-z), N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -14000000 \lor \neg \left(z \leq 4.2 \cdot 10^{+38}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\end{array}
\end{array}
if z < -1.4e7 or 4.2e38 < z Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 75.4%
mul-1-neg75.4%
Simplified75.4%
if -1.4e7 < z < 4.2e38Initial program 99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.6%
mul-1-neg99.6%
+-commutative99.6%
fma-def99.8%
Simplified99.8%
Taylor expanded in x around inf 73.3%
*-commutative73.3%
associate-*r*73.4%
*-commutative73.4%
Simplified73.4%
Final simplification74.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -19000000.0) (not (<= z 4.1e+38))) (- z) (* y (* 3.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -19000000.0) || !(z <= 4.1e+38)) {
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 <= (-19000000.0d0)) .or. (.not. (z <= 4.1d+38))) 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 <= -19000000.0) || !(z <= 4.1e+38)) {
tmp = -z;
} else {
tmp = y * (3.0 * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -19000000.0) or not (z <= 4.1e+38): tmp = -z else: tmp = y * (3.0 * x) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -19000000.0) || !(z <= 4.1e+38)) 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 <= -19000000.0) || ~((z <= 4.1e+38))) tmp = -z; else tmp = y * (3.0 * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -19000000.0], N[Not[LessEqual[z, 4.1e+38]], $MachinePrecision]], (-z), N[(y * N[(3.0 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -19000000 \lor \neg \left(z \leq 4.1 \cdot 10^{+38}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(3 \cdot x\right)\\
\end{array}
\end{array}
if z < -1.9e7 or 4.1000000000000003e38 < z Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 75.4%
mul-1-neg75.4%
Simplified75.4%
if -1.9e7 < z < 4.1000000000000003e38Initial program 99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.6%
mul-1-neg99.6%
+-commutative99.6%
fma-def99.8%
Simplified99.8%
Taylor expanded in x around inf 73.3%
add-sqr-sqrt34.1%
unpow234.1%
associate-*r*34.0%
*-commutative34.0%
Applied egg-rr34.0%
unpow234.0%
add-sqr-sqrt73.4%
*-commutative73.4%
Applied egg-rr73.4%
Final simplification74.4%
(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 (- (* y (* 3.0 x)) z))
double code(double x, double y, double z) {
return (y * (3.0 * 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 = (y * (3.0d0 * x)) - z
end function
public static double code(double x, double y, double z) {
return (y * (3.0 * x)) - z;
}
def code(x, y, z): return (y * (3.0 * x)) - z
function code(x, y, z) return Float64(Float64(y * Float64(3.0 * x)) - z) end
function tmp = code(x, y, z) tmp = (y * (3.0 * x)) - z; end
code[x_, y_, z_] := N[(N[(y * N[(3.0 * x), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(3 \cdot x\right) - 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 50.1%
mul-1-neg50.1%
Simplified50.1%
Final simplification50.1%
(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%
associate-*r*99.8%
*-commutative99.8%
associate-*r*99.8%
fma-neg99.8%
add-sqr-sqrt57.1%
sqrt-unprod61.0%
sqr-neg61.0%
sqrt-unprod22.4%
add-sqr-sqrt49.0%
Applied egg-rr49.0%
Taylor expanded in y around 0 2.4%
Final simplification2.4%
(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 2024011
(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))