
(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 6 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}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (fma (* 3.0 y) x (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma((3.0 * y), x, -z);
}
x, y, z = sort([x, y, z]) function code(x, y, z) return fma(Float64(3.0 * y), x, Float64(-z)) end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(3.0 * y), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(3 \cdot y, x, -z\right)
\end{array}
Initial program 99.9%
associate-*l*99.8%
*-commutative99.8%
fma-neg99.9%
Simplified99.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -2.2e+35) (not (<= z 5.2e-73))) (- z) (* (* 3.0 y) x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.2e+35) || !(z <= 5.2e-73)) {
tmp = -z;
} else {
tmp = (3.0 * y) * x;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 ((z <= (-2.2d+35)) .or. (.not. (z <= 5.2d-73))) then
tmp = -z
else
tmp = (3.0d0 * y) * x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.2e+35) || !(z <= 5.2e-73)) {
tmp = -z;
} else {
tmp = (3.0 * y) * x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -2.2e+35) or not (z <= 5.2e-73): tmp = -z else: tmp = (3.0 * y) * x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -2.2e+35) || !(z <= 5.2e-73)) tmp = Float64(-z); else tmp = Float64(Float64(3.0 * y) * x); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -2.2e+35) || ~((z <= 5.2e-73)))
tmp = -z;
else
tmp = (3.0 * y) * x;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[z, -2.2e+35], N[Not[LessEqual[z, 5.2e-73]], $MachinePrecision]], (-z), N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{+35} \lor \neg \left(z \leq 5.2 \cdot 10^{-73}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(3 \cdot y\right) \cdot x\\
\end{array}
\end{array}
if z < -2.1999999999999999e35 or 5.2000000000000002e-73 < z Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 77.2%
mul-1-neg77.2%
Simplified77.2%
if -2.1999999999999999e35 < z < 5.2000000000000002e-73Initial program 99.8%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around inf 98.0%
+-commutative98.0%
mul-1-neg98.0%
unsub-neg98.0%
Simplified98.0%
Taylor expanded in x around inf 73.7%
associate-*r*73.8%
*-commutative73.8%
associate-*r*73.7%
Simplified73.7%
Final simplification75.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -4.8e+29) (not (<= z 6.6e-73))) (- z) (* 3.0 (* y x))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.8e+29) || !(z <= 6.6e-73)) {
tmp = -z;
} else {
tmp = 3.0 * (y * x);
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 ((z <= (-4.8d+29)) .or. (.not. (z <= 6.6d-73))) then
tmp = -z
else
tmp = 3.0d0 * (y * x)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4.8e+29) || !(z <= 6.6e-73)) {
tmp = -z;
} else {
tmp = 3.0 * (y * x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -4.8e+29) or not (z <= 6.6e-73): tmp = -z else: tmp = 3.0 * (y * x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -4.8e+29) || !(z <= 6.6e-73)) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(y * x)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -4.8e+29) || ~((z <= 6.6e-73)))
tmp = -z;
else
tmp = 3.0 * (y * x);
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[z, -4.8e+29], N[Not[LessEqual[z, 6.6e-73]], $MachinePrecision]], (-z), N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.8 \cdot 10^{+29} \lor \neg \left(z \leq 6.6 \cdot 10^{-73}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if z < -4.8000000000000002e29 or 6.60000000000000007e-73 < z Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 76.8%
mul-1-neg76.8%
Simplified76.8%
if -4.8000000000000002e29 < z < 6.60000000000000007e-73Initial program 99.8%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around inf 98.8%
+-commutative98.8%
mul-1-neg98.8%
unsub-neg98.8%
Simplified98.8%
Taylor expanded in x around inf 74.1%
Final simplification75.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* (* 3.0 y) x) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return ((3.0 * y) * x) - z;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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
assert x < y && y < z;
public static double code(double x, double y, double z) {
return ((3.0 * y) * x) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return ((3.0 * y) * x) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(Float64(3.0 * y) * x) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = ((3.0 * y) * x) - z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\left(3 \cdot y\right) \cdot x - z
\end{array}
Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Final simplification99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* 3.0 (* y x)) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (3.0 * (y * x)) - z;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (3.0 * (y * x)) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (3.0 * (y * x)) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(3.0 * Float64(y * x)) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (3.0 * (y * x)) - z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
3 \cdot \left(y \cdot x\right) - z
\end{array}
Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return -z;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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
assert x < y && y < z;
public static double code(double x, double y, double z) {
return -z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return -z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(-z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = -z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := (-z)
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
-z
\end{array}
Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 54.0%
mul-1-neg54.0%
Simplified54.0%
(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 2024101
(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))