
(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 y) x (- z)))
double code(double x, double y, double z) {
return fma((3.0 * y), x, -z);
}
function code(x, y, z) return fma(Float64(3.0 * y), x, Float64(-z)) end
code[x_, y_, z_] := N[(N[(3.0 * y), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(3 \cdot y, x, -z\right)
\end{array}
Initial program 99.8%
associate-*l*99.8%
*-commutative99.8%
fma-neg99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.8e+59) (not (<= x 9.8e-107))) (* 3.0 (* y x)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e+59) || !(x <= 9.8e-107)) {
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 ((x <= (-3.8d+59)) .or. (.not. (x <= 9.8d-107))) 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 ((x <= -3.8e+59) || !(x <= 9.8e-107)) {
tmp = 3.0 * (y * x);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.8e+59) or not (x <= 9.8e-107): tmp = 3.0 * (y * x) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.8e+59) || !(x <= 9.8e-107)) 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 ((x <= -3.8e+59) || ~((x <= 9.8e-107))) tmp = 3.0 * (y * x); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.8e+59], N[Not[LessEqual[x, 9.8e-107]], $MachinePrecision]], N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{+59} \lor \neg \left(x \leq 9.8 \cdot 10^{-107}\right):\\
\;\;\;\;3 \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -3.8000000000000001e59 or 9.79999999999999959e-107 < x Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 71.8%
if -3.8000000000000001e59 < x < 9.79999999999999959e-107Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 73.1%
mul-1-neg73.1%
Simplified73.1%
Final simplification72.3%
(FPCore (x y z) :precision binary64 (if (<= x -1.25e+48) (* (* 3.0 y) x) (if (<= x 1.4e-104) (- z) (* 3.0 (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.25e+48) {
tmp = (3.0 * y) * x;
} else if (x <= 1.4e-104) {
tmp = -z;
} else {
tmp = 3.0 * (y * x);
}
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 (x <= (-1.25d+48)) then
tmp = (3.0d0 * y) * x
else if (x <= 1.4d-104) then
tmp = -z
else
tmp = 3.0d0 * (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.25e+48) {
tmp = (3.0 * y) * x;
} else if (x <= 1.4e-104) {
tmp = -z;
} else {
tmp = 3.0 * (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.25e+48: tmp = (3.0 * y) * x elif x <= 1.4e-104: tmp = -z else: tmp = 3.0 * (y * x) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.25e+48) tmp = Float64(Float64(3.0 * y) * x); elseif (x <= 1.4e-104) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.25e+48) tmp = (3.0 * y) * x; elseif (x <= 1.4e-104) tmp = -z; else tmp = 3.0 * (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.25e+48], N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, 1.4e-104], (-z), N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{+48}:\\
\;\;\;\;\left(3 \cdot y\right) \cdot x\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{-104}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if x < -1.24999999999999993e48Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 72.5%
associate-*r*72.5%
*-commutative72.5%
associate-*r*72.6%
Simplified72.6%
if -1.24999999999999993e48 < x < 1.4e-104Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 74.9%
mul-1-neg74.9%
Simplified74.9%
if 1.4e-104 < x Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 71.5%
Final simplification73.1%
(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%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
(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(Float64(3.0 * y) * x) - z) end
function tmp = code(x, y, z) tmp = ((3.0 * y) * x) - z; end
code[x_, y_, z_] := N[(N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(3 \cdot y\right) \cdot x - z
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Final simplification99.8%
(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.1%
mul-1-neg48.1%
Simplified48.1%
Final simplification48.1%
(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%
add-sqr-sqrt51.8%
associate-*r*51.8%
fma-neg51.8%
add-sqr-sqrt25.2%
sqrt-unprod31.8%
sqr-neg31.8%
sqrt-unprod16.0%
add-sqr-sqrt27.2%
Applied egg-rr27.2%
Taylor expanded in x around 0 2.1%
Final simplification2.1%
(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 2023334
(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))