
(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 4 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 (- (* 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%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1100000.0) (not (<= y 6.5e+69))) (* 3.0 (* y x)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1100000.0) || !(y <= 6.5e+69)) {
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 ((y <= (-1100000.0d0)) .or. (.not. (y <= 6.5d+69))) 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 ((y <= -1100000.0) || !(y <= 6.5e+69)) {
tmp = 3.0 * (y * x);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1100000.0) or not (y <= 6.5e+69): tmp = 3.0 * (y * x) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1100000.0) || !(y <= 6.5e+69)) 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 ((y <= -1100000.0) || ~((y <= 6.5e+69))) tmp = 3.0 * (y * x); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1100000.0], N[Not[LessEqual[y, 6.5e+69]], $MachinePrecision]], N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1100000 \lor \neg \left(y \leq 6.5 \cdot 10^{+69}\right):\\
\;\;\;\;3 \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -1.1e6 or 6.5000000000000001e69 < y Initial program 99.7%
add-sqr-sqrt43.7%
associate-*r*43.7%
fma-neg43.7%
add-sqr-sqrt25.7%
sqrt-unprod32.0%
sqr-neg32.0%
sqrt-unprod12.8%
add-sqr-sqrt32.1%
Applied egg-rr32.1%
fma-udef32.1%
flip-+11.4%
Applied egg-rr26.1%
fma-neg26.1%
Simplified26.1%
clear-num26.1%
associate-/r/26.1%
associate-*r*26.0%
*-commutative26.0%
*-commutative26.0%
metadata-eval26.0%
unpow226.0%
swap-sqr26.0%
pow226.0%
associate-*r*26.1%
*-commutative26.1%
Applied egg-rr26.1%
Taylor expanded in x around inf 73.3%
if -1.1e6 < y < 6.5000000000000001e69Initial program 99.9%
Taylor expanded in x around 0 74.4%
mul-1-neg74.4%
Simplified74.4%
Final simplification73.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%
Taylor expanded in x around 0 52.5%
mul-1-neg52.5%
Simplified52.5%
Final simplification52.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.8%
add-sqr-sqrt46.3%
associate-*r*46.3%
fma-neg46.3%
add-sqr-sqrt25.2%
sqrt-unprod29.6%
sqr-neg29.6%
sqrt-unprod10.7%
add-sqr-sqrt22.9%
Applied egg-rr22.9%
Taylor expanded in x 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 2023229
(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))