
(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 7 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 (fma (* x y) 3.0 (- z)))
double code(double x, double y, double z) {
return fma((x * y), 3.0, -z);
}
function code(x, y, z) return fma(Float64(x * y), 3.0, Float64(-z)) end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] * 3.0 + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot y, 3, -z\right)
\end{array}
Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.9%
*-commutative99.9%
fma-neg99.9%
Applied egg-rr99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.15e-172) (not (<= y 4.2e+45))) (* (* x y) 3.0) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.15e-172) || !(y <= 4.2e+45)) {
tmp = (x * y) * 3.0;
} 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 <= (-2.15d-172)) .or. (.not. (y <= 4.2d+45))) then
tmp = (x * y) * 3.0d0
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.15e-172) || !(y <= 4.2e+45)) {
tmp = (x * y) * 3.0;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.15e-172) or not (y <= 4.2e+45): tmp = (x * y) * 3.0 else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.15e-172) || !(y <= 4.2e+45)) tmp = Float64(Float64(x * y) * 3.0); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.15e-172) || ~((y <= 4.2e+45))) tmp = (x * y) * 3.0; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.15e-172], N[Not[LessEqual[y, 4.2e+45]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] * 3.0), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.15 \cdot 10^{-172} \lor \neg \left(y \leq 4.2 \cdot 10^{+45}\right):\\
\;\;\;\;\left(x \cdot y\right) \cdot 3\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -2.1499999999999999e-172 or 4.1999999999999999e45 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 69.2%
if -2.1499999999999999e-172 < y < 4.1999999999999999e45Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 77.2%
mul-1-neg77.2%
Simplified77.2%
Final simplification72.5%
(FPCore (x y z) :precision binary64 (if (<= y -5.4e-176) (* y (* x 3.0)) (if (<= y 2.8e+43) (- z) (* (* x y) 3.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.4e-176) {
tmp = y * (x * 3.0);
} else if (y <= 2.8e+43) {
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) :: tmp
if (y <= (-5.4d-176)) then
tmp = y * (x * 3.0d0)
else if (y <= 2.8d+43) 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 tmp;
if (y <= -5.4e-176) {
tmp = y * (x * 3.0);
} else if (y <= 2.8e+43) {
tmp = -z;
} else {
tmp = (x * y) * 3.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.4e-176: tmp = y * (x * 3.0) elif y <= 2.8e+43: tmp = -z else: tmp = (x * y) * 3.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.4e-176) tmp = Float64(y * Float64(x * 3.0)); elseif (y <= 2.8e+43) tmp = Float64(-z); else tmp = Float64(Float64(x * y) * 3.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.4e-176) tmp = y * (x * 3.0); elseif (y <= 2.8e+43) tmp = -z; else tmp = (x * y) * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.4e-176], N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.8e+43], (-z), N[(N[(x * y), $MachinePrecision] * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.4 \cdot 10^{-176}:\\
\;\;\;\;y \cdot \left(x \cdot 3\right)\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{+43}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot y\right) \cdot 3\\
\end{array}
\end{array}
if y < -5.3999999999999997e-176Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 64.7%
*-commutative64.7%
associate-*l*64.7%
*-commutative64.7%
Simplified64.7%
Taylor expanded in x around 0 64.7%
associate-*r*64.6%
Simplified64.6%
if -5.3999999999999997e-176 < y < 2.80000000000000019e43Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 77.0%
mul-1-neg77.0%
Simplified77.0%
if 2.80000000000000019e43 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 75.9%
Final simplification72.1%
(FPCore (x y z) :precision binary64 (if (<= y -5.4e-176) (* x (* y 3.0)) (if (<= y 4.8e+45) (- z) (* (* x y) 3.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.4e-176) {
tmp = x * (y * 3.0);
} else if (y <= 4.8e+45) {
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) :: tmp
if (y <= (-5.4d-176)) then
tmp = x * (y * 3.0d0)
else if (y <= 4.8d+45) 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 tmp;
if (y <= -5.4e-176) {
tmp = x * (y * 3.0);
} else if (y <= 4.8e+45) {
tmp = -z;
} else {
tmp = (x * y) * 3.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.4e-176: tmp = x * (y * 3.0) elif y <= 4.8e+45: tmp = -z else: tmp = (x * y) * 3.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.4e-176) tmp = Float64(x * Float64(y * 3.0)); elseif (y <= 4.8e+45) tmp = Float64(-z); else tmp = Float64(Float64(x * y) * 3.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.4e-176) tmp = x * (y * 3.0); elseif (y <= 4.8e+45) tmp = -z; else tmp = (x * y) * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.4e-176], N[(x * N[(y * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.8e+45], (-z), N[(N[(x * y), $MachinePrecision] * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.4 \cdot 10^{-176}:\\
\;\;\;\;x \cdot \left(y \cdot 3\right)\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{+45}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot y\right) \cdot 3\\
\end{array}
\end{array}
if y < -5.3999999999999997e-176Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 64.7%
*-commutative64.7%
associate-*l*64.7%
*-commutative64.7%
Simplified64.7%
if -5.3999999999999997e-176 < y < 4.79999999999999979e45Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 77.0%
mul-1-neg77.0%
Simplified77.0%
if 4.79999999999999979e45 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 75.9%
Final simplification72.2%
(FPCore (x y z) :precision binary64 (- (* y (* x 3.0)) z))
double code(double x, double y, double z) {
return (y * (x * 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 = (y * (x * 3.0d0)) - z
end function
public static double code(double x, double y, double z) {
return (y * (x * 3.0)) - z;
}
def code(x, y, z): return (y * (x * 3.0)) - z
function code(x, y, z) return Float64(Float64(y * Float64(x * 3.0)) - z) end
function tmp = code(x, y, z) tmp = (y * (x * 3.0)) - z; end
code[x_, y_, z_] := N[(N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(x \cdot 3\right) - z
\end{array}
Initial program 99.8%
Final simplification99.8%
(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%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.9%
Final simplification99.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.9%
Simplified99.9%
Taylor expanded in x around 0 50.7%
mul-1-neg50.7%
Simplified50.7%
(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 2024096
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, B"
:precision binary64
:alt
(- (* x (* 3.0 y)) z)
(- (* (* x 3.0) y) z))