
(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 (- (* (* x y) 3.0) z))
double code(double x, double y, double z) {
return ((x * y) * 3.0) - 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 * y) * 3.0d0) - z
end function
public static double code(double x, double y, double z) {
return ((x * y) * 3.0) - z;
}
def code(x, y, z): return ((x * y) * 3.0) - z
function code(x, y, z) return Float64(Float64(Float64(x * y) * 3.0) - z) end
function tmp = code(x, y, z) tmp = ((x * y) * 3.0) - z; end
code[x_, y_, z_] := N[(N[(N[(x * y), $MachinePrecision] * 3.0), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y\right) \cdot 3 - z
\end{array}
Initial program 99.8%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (* x 3.0))))
(if (<= t_0 -4e-25)
(* x (* y 3.0))
(if (<= t_0 2e+95) (- z) (* (* x y) 3.0)))))
double code(double x, double y, double z) {
double t_0 = y * (x * 3.0);
double tmp;
if (t_0 <= -4e-25) {
tmp = x * (y * 3.0);
} else if (t_0 <= 2e+95) {
tmp = -z;
} else {
tmp = (x * y) * 3.0;
}
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) :: t_0
real(8) :: tmp
t_0 = y * (x * 3.0d0)
if (t_0 <= (-4d-25)) then
tmp = x * (y * 3.0d0)
else if (t_0 <= 2d+95) then
tmp = -z
else
tmp = (x * y) * 3.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (x * 3.0);
double tmp;
if (t_0 <= -4e-25) {
tmp = x * (y * 3.0);
} else if (t_0 <= 2e+95) {
tmp = -z;
} else {
tmp = (x * y) * 3.0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x * 3.0) tmp = 0 if t_0 <= -4e-25: tmp = x * (y * 3.0) elif t_0 <= 2e+95: tmp = -z else: tmp = (x * y) * 3.0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x * 3.0)) tmp = 0.0 if (t_0 <= -4e-25) tmp = Float64(x * Float64(y * 3.0)); elseif (t_0 <= 2e+95) tmp = Float64(-z); else tmp = Float64(Float64(x * y) * 3.0); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x * 3.0); tmp = 0.0; if (t_0 <= -4e-25) tmp = x * (y * 3.0); elseif (t_0 <= 2e+95) tmp = -z; else tmp = (x * y) * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -4e-25], N[(x * N[(y * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e+95], (-z), N[(N[(x * y), $MachinePrecision] * 3.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x \cdot 3\right)\\
\mathbf{if}\;t\_0 \leq -4 \cdot 10^{-25}:\\
\;\;\;\;x \cdot \left(y \cdot 3\right)\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+95}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot y\right) \cdot 3\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -4.00000000000000015e-25Initial program 99.7%
Taylor expanded in x around inf
*-commutativeN/A
associate-*r*N/A
metadata-evalN/A
distribute-lft-neg-inN/A
*-commutativeN/A
lower-*.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f6476.1
Applied rewrites76.1%
if -4.00000000000000015e-25 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 2.00000000000000004e95Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6475.6
Applied rewrites75.6%
if 2.00000000000000004e95 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 99.8%
+-rgt-identityN/A
flip-+N/A
--rgt-identityN/A
lower-/.f64N/A
metadata-evalN/A
lower--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
swap-sqrN/A
lower-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
swap-sqrN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f6411.7
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
Applied rewrites11.7%
Taylor expanded in x around inf
lower-*.f64N/A
lower-*.f6486.9
Applied rewrites86.9%
Final simplification77.8%
(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 2024229
(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))