
(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 6 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 (- (* (* 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}
Initial program 99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.2e-154) (not (<= y 2.4e+65))) (* 3.0 (* x y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.2e-154) || !(y <= 2.4e+65)) {
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 ((y <= (-9.2d-154)) .or. (.not. (y <= 2.4d+65))) 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 ((y <= -9.2e-154) || !(y <= 2.4e+65)) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9.2e-154) or not (y <= 2.4e+65): tmp = 3.0 * (x * y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9.2e-154) || !(y <= 2.4e+65)) 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 ((y <= -9.2e-154) || ~((y <= 2.4e+65))) tmp = 3.0 * (x * y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.2e-154], N[Not[LessEqual[y, 2.4e+65]], $MachinePrecision]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.2 \cdot 10^{-154} \lor \neg \left(y \leq 2.4 \cdot 10^{+65}\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -9.1999999999999999e-154 or 2.4000000000000002e65 < y Initial program 99.9%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 60.9%
if -9.1999999999999999e-154 < y < 2.4000000000000002e65Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 72.7%
neg-mul-172.7%
Simplified72.7%
Final simplification66.2%
(FPCore (x y z) :precision binary64 (if (<= y -9e-154) (* 3.0 (* x y)) (if (<= y 4.2e+65) (- z) (* (* x 3.0) y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9e-154) {
tmp = 3.0 * (x * y);
} else if (y <= 4.2e+65) {
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 (y <= (-9d-154)) then
tmp = 3.0d0 * (x * y)
else if (y <= 4.2d+65) 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 (y <= -9e-154) {
tmp = 3.0 * (x * y);
} else if (y <= 4.2e+65) {
tmp = -z;
} else {
tmp = (x * 3.0) * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9e-154: tmp = 3.0 * (x * y) elif y <= 4.2e+65: tmp = -z else: tmp = (x * 3.0) * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9e-154) tmp = Float64(3.0 * Float64(x * y)); elseif (y <= 4.2e+65) tmp = Float64(-z); else tmp = Float64(Float64(x * 3.0) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -9e-154) tmp = 3.0 * (x * y); elseif (y <= 4.2e+65) tmp = -z; else tmp = (x * 3.0) * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9e-154], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.2e+65], (-z), N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-154}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{+65}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot 3\right) \cdot y\\
\end{array}
\end{array}
if y < -8.9999999999999994e-154Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.9%
Taylor expanded in x around inf 52.9%
if -8.9999999999999994e-154 < y < 4.19999999999999983e65Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 72.7%
neg-mul-172.7%
Simplified72.7%
if 4.19999999999999983e65 < y Initial program 99.8%
associate-*l*99.5%
Simplified99.5%
Taylor expanded in y around inf 99.8%
+-commutative99.8%
fma-define99.8%
mul-1-neg99.8%
fmm-def99.8%
Simplified99.8%
Taylor expanded in x around inf 81.5%
Final simplification66.2%
(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.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.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.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 54.2%
neg-mul-154.2%
Simplified54.2%
(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.8%
Simplified99.8%
Taylor expanded in x around 0 54.2%
neg-mul-154.2%
Simplified54.2%
neg-sub054.2%
sub-neg54.2%
add-sqr-sqrt28.2%
sqrt-unprod19.1%
sqr-neg19.1%
sqrt-unprod0.9%
add-sqr-sqrt2.0%
Applied egg-rr2.0%
+-lft-identity2.0%
Simplified2.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 2024170
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, B"
:precision binary64
:alt
(! :herbie-platform default (- (* x (* 3 y)) z))
(- (* (* x 3.0) y) z))