
(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}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (fma x (* y -3.0) z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return -fma(x, (y * -3.0), z);
}
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(-fma(x, Float64(y * -3.0), z)) end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := (-N[(x * N[(y * -3.0), $MachinePrecision] + z), $MachinePrecision])
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
-\mathsf{fma}\left(x, y \cdot -3, z\right)
\end{array}
Initial program 99.5%
sub-neg99.5%
+-commutative99.5%
cancel-sign-sub99.5%
distribute-lft-neg-out99.5%
unsub-neg99.5%
distribute-neg-out99.5%
+-commutative99.5%
distribute-lft-neg-out99.5%
distribute-lft-neg-in99.5%
distribute-rgt-neg-out99.5%
associate-*l*99.4%
fma-def99.4%
neg-mul-199.4%
associate-*r*99.4%
*-commutative99.4%
metadata-eval99.4%
Simplified99.4%
Final simplification99.4%
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.4e+137)
(not
(or (<= z -5.2e+75) (and (not (<= z -2.8e-16)) (<= z 3.35e+53)))))
(- z)
(* (* x y) (- -3.0))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.4e+137) || !((z <= -5.2e+75) || (!(z <= -2.8e-16) && (z <= 3.35e+53)))) {
tmp = -z;
} else {
tmp = (x * y) * -(-3.0);
}
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.4d+137)) .or. (.not. (z <= (-5.2d+75)) .or. (.not. (z <= (-2.8d-16))) .and. (z <= 3.35d+53))) then
tmp = -z
else
tmp = (x * y) * -(-3.0d0)
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.4e+137) || !((z <= -5.2e+75) || (!(z <= -2.8e-16) && (z <= 3.35e+53)))) {
tmp = -z;
} else {
tmp = (x * y) * -(-3.0);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -2.4e+137) or not ((z <= -5.2e+75) or (not (z <= -2.8e-16) and (z <= 3.35e+53))): tmp = -z else: tmp = (x * y) * -(-3.0) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -2.4e+137) || !((z <= -5.2e+75) || (!(z <= -2.8e-16) && (z <= 3.35e+53)))) tmp = Float64(-z); else tmp = Float64(Float64(x * y) * Float64(-(-3.0))); 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.4e+137) || ~(((z <= -5.2e+75) || (~((z <= -2.8e-16)) && (z <= 3.35e+53)))))
tmp = -z;
else
tmp = (x * y) * -(-3.0);
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.4e+137], N[Not[Or[LessEqual[z, -5.2e+75], And[N[Not[LessEqual[z, -2.8e-16]], $MachinePrecision], LessEqual[z, 3.35e+53]]]], $MachinePrecision]], (-z), N[(N[(x * y), $MachinePrecision] * (--3.0)), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{+137} \lor \neg \left(z \leq -5.2 \cdot 10^{+75} \lor \neg \left(z \leq -2.8 \cdot 10^{-16}\right) \land z \leq 3.35 \cdot 10^{+53}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot y\right) \cdot \left(--3\right)\\
\end{array}
\end{array}
if z < -2.39999999999999983e137 or -5.1999999999999997e75 < z < -2.8000000000000001e-16 or 3.3499999999999999e53 < z Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
unsub-neg100.0%
distribute-neg-out100.0%
+-commutative100.0%
distribute-lft-neg-out100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
associate-*l*100.0%
fma-def100.0%
neg-mul-1100.0%
associate-*r*100.0%
*-commutative100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 85.2%
if -2.39999999999999983e137 < z < -5.1999999999999997e75 or -2.8000000000000001e-16 < z < 3.3499999999999999e53Initial program 99.1%
sub-neg99.1%
+-commutative99.1%
cancel-sign-sub99.1%
distribute-lft-neg-out99.1%
unsub-neg99.1%
distribute-neg-out99.1%
+-commutative99.1%
distribute-lft-neg-out99.1%
distribute-lft-neg-in99.1%
distribute-rgt-neg-out99.1%
associate-*l*99.1%
fma-def99.1%
neg-mul-199.1%
associate-*r*99.1%
*-commutative99.1%
metadata-eval99.1%
Simplified99.1%
Taylor expanded in x around inf 72.7%
Final simplification77.7%
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.4e+137)
(and (not (<= z -1.35e+75))
(or (<= z -2.05e-16) (not (<= z 5.8e+52)))))
(- z)
(* (* y -3.0) (- x))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.4e+137) || (!(z <= -1.35e+75) && ((z <= -2.05e-16) || !(z <= 5.8e+52)))) {
tmp = -z;
} else {
tmp = (y * -3.0) * -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.4d+137)) .or. (.not. (z <= (-1.35d+75))) .and. (z <= (-2.05d-16)) .or. (.not. (z <= 5.8d+52))) then
tmp = -z
else
tmp = (y * (-3.0d0)) * -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.4e+137) || (!(z <= -1.35e+75) && ((z <= -2.05e-16) || !(z <= 5.8e+52)))) {
tmp = -z;
} else {
tmp = (y * -3.0) * -x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -2.4e+137) or (not (z <= -1.35e+75) and ((z <= -2.05e-16) or not (z <= 5.8e+52))): tmp = -z else: tmp = (y * -3.0) * -x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -2.4e+137) || (!(z <= -1.35e+75) && ((z <= -2.05e-16) || !(z <= 5.8e+52)))) tmp = Float64(-z); else tmp = Float64(Float64(y * -3.0) * Float64(-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.4e+137) || (~((z <= -1.35e+75)) && ((z <= -2.05e-16) || ~((z <= 5.8e+52)))))
tmp = -z;
else
tmp = (y * -3.0) * -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.4e+137], And[N[Not[LessEqual[z, -1.35e+75]], $MachinePrecision], Or[LessEqual[z, -2.05e-16], N[Not[LessEqual[z, 5.8e+52]], $MachinePrecision]]]], (-z), N[(N[(y * -3.0), $MachinePrecision] * (-x)), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{+137} \lor \neg \left(z \leq -1.35 \cdot 10^{+75}\right) \land \left(z \leq -2.05 \cdot 10^{-16} \lor \neg \left(z \leq 5.8 \cdot 10^{+52}\right)\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot -3\right) \cdot \left(-x\right)\\
\end{array}
\end{array}
if z < -2.39999999999999983e137 or -1.34999999999999999e75 < z < -2.05000000000000003e-16 or 5.8e52 < z Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
unsub-neg100.0%
distribute-neg-out100.0%
+-commutative100.0%
distribute-lft-neg-out100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
associate-*l*100.0%
fma-def100.0%
neg-mul-1100.0%
associate-*r*100.0%
*-commutative100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 85.2%
if -2.39999999999999983e137 < z < -1.34999999999999999e75 or -2.05000000000000003e-16 < z < 5.8e52Initial program 99.1%
sub-neg99.1%
+-commutative99.1%
cancel-sign-sub99.1%
distribute-lft-neg-out99.1%
unsub-neg99.1%
distribute-neg-out99.1%
+-commutative99.1%
distribute-lft-neg-out99.1%
distribute-lft-neg-in99.1%
distribute-rgt-neg-out99.1%
associate-*l*99.1%
fma-def99.1%
neg-mul-199.1%
associate-*r*99.1%
*-commutative99.1%
metadata-eval99.1%
Simplified99.1%
Taylor expanded in x around inf 72.7%
*-commutative72.7%
associate-*r*72.1%
*-commutative72.1%
Simplified72.1%
Final simplification77.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* x (* y 3.0)) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (x * (y * 3.0)) - 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 = (x * (y * 3.0d0)) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (x * (y * 3.0)) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (x * (y * 3.0)) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(x * Float64(y * 3.0)) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (x * (y * 3.0)) - z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(x * N[(y * 3.0), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x \cdot \left(y \cdot 3\right) - z
\end{array}
Initial program 99.5%
*-commutative99.5%
*-commutative99.5%
associate-*l*99.4%
*-commutative99.4%
*-commutative99.4%
Simplified99.4%
Final simplification99.4%
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.5%
sub-neg99.5%
+-commutative99.5%
cancel-sign-sub99.5%
distribute-lft-neg-out99.5%
unsub-neg99.5%
distribute-neg-out99.5%
+-commutative99.5%
distribute-lft-neg-out99.5%
distribute-lft-neg-in99.5%
distribute-rgt-neg-out99.5%
associate-*l*99.4%
fma-def99.4%
neg-mul-199.4%
associate-*r*99.4%
*-commutative99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in x around 0 51.6%
Final simplification51.6%
(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 2023336
(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))