
(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 5 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 (* 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 (if (or (<= y -1.75e-141) (not (<= y 2.35e-20))) (* 3.0 (* x y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.75e-141) || !(y <= 2.35e-20)) {
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 <= (-1.75d-141)) .or. (.not. (y <= 2.35d-20))) 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 <= -1.75e-141) || !(y <= 2.35e-20)) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.75e-141) or not (y <= 2.35e-20): tmp = 3.0 * (x * y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.75e-141) || !(y <= 2.35e-20)) 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 <= -1.75e-141) || ~((y <= 2.35e-20))) tmp = 3.0 * (x * y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.75e-141], N[Not[LessEqual[y, 2.35e-20]], $MachinePrecision]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.75 \cdot 10^{-141} \lor \neg \left(y \leq 2.35 \cdot 10^{-20}\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -1.7500000000000001e-141 or 2.35000000000000007e-20 < y Initial program 99.8%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 70.3%
if -1.7500000000000001e-141 < y < 2.35000000000000007e-20Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 80.8%
neg-mul-180.8%
Simplified80.8%
Final simplification73.9%
(FPCore (x y z) :precision binary64 (if (<= y -2e-141) (* y (* 3.0 x)) (if (<= y 2.65e-20) (- z) (* 3.0 (* x y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2e-141) {
tmp = y * (3.0 * x);
} else if (y <= 2.65e-20) {
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 (y <= (-2d-141)) then
tmp = y * (3.0d0 * x)
else if (y <= 2.65d-20) 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 (y <= -2e-141) {
tmp = y * (3.0 * x);
} else if (y <= 2.65e-20) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2e-141: tmp = y * (3.0 * x) elif y <= 2.65e-20: tmp = -z else: tmp = 3.0 * (x * y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2e-141) tmp = Float64(y * Float64(3.0 * x)); elseif (y <= 2.65e-20) 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 (y <= -2e-141) tmp = y * (3.0 * x); elseif (y <= 2.65e-20) tmp = -z; else tmp = 3.0 * (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2e-141], N[(y * N[(3.0 * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.65e-20], (-z), N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{-141}:\\
\;\;\;\;y \cdot \left(3 \cdot x\right)\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{-20}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if y < -2.0000000000000001e-141Initial program 99.8%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 66.0%
*-commutative66.0%
associate-*l*66.0%
*-commutative66.0%
Simplified66.0%
Taylor expanded in x around 0 66.0%
*-commutative66.0%
associate-*r*66.0%
*-commutative66.0%
associate-*r*66.1%
Simplified66.1%
if -2.0000000000000001e-141 < y < 2.6500000000000001e-20Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 80.8%
neg-mul-180.8%
Simplified80.8%
if 2.6500000000000001e-20 < y Initial program 99.8%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.9%
Taylor expanded in x around inf 76.3%
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%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 48.4%
neg-mul-148.4%
Simplified48.4%
Final simplification48.4%
(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%
Taylor expanded in x around 0 99.8%
*-commutative99.8%
fma-neg99.8%
add-sqr-sqrt48.6%
sqrt-unprod58.0%
sqr-neg58.0%
sqrt-unprod25.6%
add-sqr-sqrt52.7%
Applied egg-rr52.7%
Taylor expanded in x 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 2024039
(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))