
(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 3.0 (* x y) (- z)))
double code(double x, double y, double z) {
return fma(3.0, (x * y), -z);
}
function code(x, y, z) return fma(3.0, Float64(x * y), Float64(-z)) end
code[x_, y_, z_] := N[(3.0 * N[(x * y), $MachinePrecision] + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(3, x \cdot y, -z\right)
\end{array}
Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.9%
mul-1-neg99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.2e-89) (not (<= y 6e+50))) (* 3.0 (* x y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.2e-89) || !(y <= 6e+50)) {
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 <= (-2.2d-89)) .or. (.not. (y <= 6d+50))) 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 <= -2.2e-89) || !(y <= 6e+50)) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.2e-89) or not (y <= 6e+50): tmp = 3.0 * (x * y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.2e-89) || !(y <= 6e+50)) 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 <= -2.2e-89) || ~((y <= 6e+50))) tmp = 3.0 * (x * y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.2e-89], N[Not[LessEqual[y, 6e+50]], $MachinePrecision]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{-89} \lor \neg \left(y \leq 6 \cdot 10^{+50}\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -2.20000000000000012e-89 or 5.9999999999999996e50 < y Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
+-commutative99.8%
fma-def99.9%
Simplified99.9%
Taylor expanded in x around inf 67.7%
if -2.20000000000000012e-89 < y < 5.9999999999999996e50Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 74.9%
mul-1-neg74.9%
Simplified74.9%
Final simplification71.4%
(FPCore (x y z) :precision binary64 (if (<= y -1.55e-88) (* 3.0 (* x y)) (if (<= y 8.5e+51) (- z) (* x (* 3.0 y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.55e-88) {
tmp = 3.0 * (x * y);
} else if (y <= 8.5e+51) {
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 <= (-1.55d-88)) then
tmp = 3.0d0 * (x * y)
else if (y <= 8.5d+51) 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 <= -1.55e-88) {
tmp = 3.0 * (x * y);
} else if (y <= 8.5e+51) {
tmp = -z;
} else {
tmp = x * (3.0 * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.55e-88: tmp = 3.0 * (x * y) elif y <= 8.5e+51: tmp = -z else: tmp = x * (3.0 * y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.55e-88) tmp = Float64(3.0 * Float64(x * y)); elseif (y <= 8.5e+51) tmp = Float64(-z); else tmp = Float64(x * Float64(3.0 * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.55e-88) tmp = 3.0 * (x * y); elseif (y <= 8.5e+51) tmp = -z; else tmp = x * (3.0 * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.55e-88], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 8.5e+51], (-z), N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.55 \cdot 10^{-88}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{+51}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\end{array}
\end{array}
if y < -1.5499999999999999e-88Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.9%
mul-1-neg99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in x around inf 66.7%
if -1.5499999999999999e-88 < y < 8.4999999999999999e51Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 74.9%
mul-1-neg74.9%
Simplified74.9%
if 8.4999999999999999e51 < y Initial program 99.7%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.7%
mul-1-neg99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in x around inf 69.3%
*-commutative69.3%
associate-*r*69.4%
*-commutative69.4%
Simplified69.4%
Final simplification71.4%
(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.9%
Simplified99.9%
Taylor expanded in x around 0 99.9%
Final simplification99.9%
(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}
Initial program 99.8%
associate-*l*99.9%
Simplified99.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 53.6%
mul-1-neg53.6%
Simplified53.6%
Final simplification53.6%
(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.9%
Simplified99.9%
associate-*r*99.8%
*-commutative99.8%
associate-*r*99.9%
fma-neg99.9%
add-sqr-sqrt50.1%
sqrt-unprod57.1%
sqr-neg57.1%
sqrt-unprod22.8%
add-sqr-sqrt45.3%
Applied egg-rr45.3%
Taylor expanded in y around 0 2.2%
Final simplification2.2%
(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 2024027
(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))