
(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.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (or (<= y -1.4e-155)
(and (not (<= y 3.6e-17)) (or (<= y 3.2e-8) (not (<= y 1.1e+15)))))
(* 3.0 (* y x))
(- z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.4e-155) || (!(y <= 3.6e-17) && ((y <= 3.2e-8) || !(y <= 1.1e+15)))) {
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 <= (-1.4d-155)) .or. (.not. (y <= 3.6d-17)) .and. (y <= 3.2d-8) .or. (.not. (y <= 1.1d+15))) 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 <= -1.4e-155) || (!(y <= 3.6e-17) && ((y <= 3.2e-8) || !(y <= 1.1e+15)))) {
tmp = 3.0 * (y * x);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.4e-155) or (not (y <= 3.6e-17) and ((y <= 3.2e-8) or not (y <= 1.1e+15))): tmp = 3.0 * (y * x) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.4e-155) || (!(y <= 3.6e-17) && ((y <= 3.2e-8) || !(y <= 1.1e+15)))) 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 <= -1.4e-155) || (~((y <= 3.6e-17)) && ((y <= 3.2e-8) || ~((y <= 1.1e+15))))) tmp = 3.0 * (y * x); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.4e-155], And[N[Not[LessEqual[y, 3.6e-17]], $MachinePrecision], Or[LessEqual[y, 3.2e-8], N[Not[LessEqual[y, 1.1e+15]], $MachinePrecision]]]], N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-155} \lor \neg \left(y \leq 3.6 \cdot 10^{-17}\right) \land \left(y \leq 3.2 \cdot 10^{-8} \lor \neg \left(y \leq 1.1 \cdot 10^{+15}\right)\right):\\
\;\;\;\;3 \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -1.4e-155 or 3.59999999999999995e-17 < y < 3.2000000000000002e-8 or 1.1e15 < y Initial program 99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in y around inf 69.7%
if -1.4e-155 < y < 3.59999999999999995e-17 or 3.2000000000000002e-8 < y < 1.1e15Initial program 99.8%
Taylor expanded in x around 0 70.8%
mul-1-neg70.8%
Simplified70.8%
Final simplification70.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 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 46.9%
mul-1-neg46.9%
Simplified46.9%
Final simplification46.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%
*-commutative99.8%
associate-*r*99.9%
fma-neg99.8%
add-sqr-sqrt52.1%
sqrt-unprod60.8%
sqr-neg60.8%
sqrt-unprod24.8%
add-sqr-sqrt53.8%
Applied egg-rr53.8%
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 2023217
(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))