
(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}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* y (* x 3.0)) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (y * (x * 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 = (y * (x * 3.0d0)) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (y * (x * 3.0)) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (y * (x * 3.0)) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(y * Float64(x * 3.0)) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (y * (x * 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[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
y \cdot \left(x \cdot 3\right) - z
\end{array}
Initial program 99.9%
Final simplification99.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 -1.95e+72) (not (<= z 2.9e-53))) (- z) (* y (* x 3.0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.95e+72) || !(z <= 2.9e-53)) {
tmp = -z;
} else {
tmp = y * (x * 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 <= (-1.95d+72)) .or. (.not. (z <= 2.9d-53))) then
tmp = -z
else
tmp = y * (x * 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 <= -1.95e+72) || !(z <= 2.9e-53)) {
tmp = -z;
} else {
tmp = y * (x * 3.0);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -1.95e+72) or not (z <= 2.9e-53): tmp = -z else: tmp = y * (x * 3.0) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -1.95e+72) || !(z <= 2.9e-53)) tmp = Float64(-z); else tmp = Float64(y * Float64(x * 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 <= -1.95e+72) || ~((z <= 2.9e-53)))
tmp = -z;
else
tmp = y * (x * 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, -1.95e+72], N[Not[LessEqual[z, 2.9e-53]], $MachinePrecision]], (-z), N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.95 \cdot 10^{+72} \lor \neg \left(z \leq 2.9 \cdot 10^{-53}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot 3\right)\\
\end{array}
\end{array}
if z < -1.94999999999999996e72 or 2.8999999999999998e-53 < z Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
add-sqr-sqrt55.0%
sqrt-unprod86.4%
pow286.4%
*-commutative86.4%
associate-*l*86.4%
unpow-prod-down86.3%
metadata-eval86.3%
Applied egg-rr86.3%
Taylor expanded in y around 0 77.7%
neg-mul-177.7%
Simplified77.7%
if -1.94999999999999996e72 < z < 2.8999999999999998e-53Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
add-sqr-sqrt53.3%
sqrt-unprod53.2%
pow253.2%
*-commutative53.2%
associate-*l*53.2%
unpow-prod-down53.3%
metadata-eval53.3%
Applied egg-rr53.3%
Taylor expanded in z around inf 81.2%
Taylor expanded in z around 0 77.6%
associate-*r*77.7%
Simplified77.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 -1.28e+72) (not (<= z 1.15e-52))) (- z) (* x (* 3.0 y))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.28e+72) || !(z <= 1.15e-52)) {
tmp = -z;
} else {
tmp = x * (3.0 * y);
}
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 <= (-1.28d+72)) .or. (.not. (z <= 1.15d-52))) then
tmp = -z
else
tmp = x * (3.0d0 * y)
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 <= -1.28e+72) || !(z <= 1.15e-52)) {
tmp = -z;
} else {
tmp = x * (3.0 * y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -1.28e+72) or not (z <= 1.15e-52): tmp = -z else: tmp = x * (3.0 * y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -1.28e+72) || !(z <= 1.15e-52)) tmp = Float64(-z); else tmp = Float64(x * Float64(3.0 * y)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -1.28e+72) || ~((z <= 1.15e-52)))
tmp = -z;
else
tmp = x * (3.0 * y);
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, -1.28e+72], N[Not[LessEqual[z, 1.15e-52]], $MachinePrecision]], (-z), N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.28 \cdot 10^{+72} \lor \neg \left(z \leq 1.15 \cdot 10^{-52}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\end{array}
\end{array}
if z < -1.28000000000000009e72 or 1.14999999999999997e-52 < z Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
add-sqr-sqrt55.0%
sqrt-unprod86.4%
pow286.4%
*-commutative86.4%
associate-*l*86.4%
unpow-prod-down86.3%
metadata-eval86.3%
Applied egg-rr86.3%
Taylor expanded in y around 0 77.7%
neg-mul-177.7%
Simplified77.7%
if -1.28000000000000009e72 < z < 1.14999999999999997e-52Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
add-sqr-sqrt53.3%
sqrt-unprod53.2%
pow253.2%
*-commutative53.2%
associate-*l*53.2%
unpow-prod-down53.3%
metadata-eval53.3%
Applied egg-rr53.3%
Taylor expanded in z around inf 81.2%
Taylor expanded in z around 0 77.6%
*-commutative77.6%
associate-*r*77.7%
*-commutative77.7%
Simplified77.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 -1.28e+72) (not (<= z 1.06e-52))) (- z) (* 3.0 (* x y))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.28e+72) || !(z <= 1.06e-52)) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
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 <= (-1.28d+72)) .or. (.not. (z <= 1.06d-52))) then
tmp = -z
else
tmp = 3.0d0 * (x * y)
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 <= -1.28e+72) || !(z <= 1.06e-52)) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -1.28e+72) or not (z <= 1.06e-52): tmp = -z else: tmp = 3.0 * (x * y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -1.28e+72) || !(z <= 1.06e-52)) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(x * y)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -1.28e+72) || ~((z <= 1.06e-52)))
tmp = -z;
else
tmp = 3.0 * (x * y);
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, -1.28e+72], N[Not[LessEqual[z, 1.06e-52]], $MachinePrecision]], (-z), N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.28 \cdot 10^{+72} \lor \neg \left(z \leq 1.06 \cdot 10^{-52}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -1.28000000000000009e72 or 1.06e-52 < z Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
add-sqr-sqrt55.0%
sqrt-unprod86.4%
pow286.4%
*-commutative86.4%
associate-*l*86.4%
unpow-prod-down86.3%
metadata-eval86.3%
Applied egg-rr86.3%
Taylor expanded in y around 0 77.7%
neg-mul-177.7%
Simplified77.7%
if -1.28000000000000009e72 < z < 1.06e-52Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
add-sqr-sqrt53.3%
sqrt-unprod53.2%
pow253.2%
*-commutative53.2%
associate-*l*53.2%
unpow-prod-down53.3%
metadata-eval53.3%
Applied egg-rr53.3%
Taylor expanded in z around inf 81.2%
Taylor expanded in z around 0 77.6%
Final simplification77.7%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* x (* 3.0 y)) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (x * (3.0 * y)) - 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 * (3.0d0 * y)) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (x * (3.0 * y)) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (x * (3.0 * y)) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(x * Float64(3.0 * y)) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (x * (3.0 * y)) - 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[(3.0 * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x \cdot \left(3 \cdot y\right) - z
\end{array}
Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* 3.0 (* x y)) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (3.0 * (x * y)) - 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 * (x * y)) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (3.0 * (x * y)) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (3.0 * (x * y)) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(3.0 * Float64(x * y)) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (3.0 * (x * y)) - 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[(x * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
3 \cdot \left(x \cdot y\right) - z
\end{array}
Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.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.9%
Simplified99.9%
add-sqr-sqrt54.1%
sqrt-unprod69.9%
pow269.9%
*-commutative69.9%
associate-*l*69.9%
unpow-prod-down69.9%
metadata-eval69.9%
Applied egg-rr69.9%
Taylor expanded in y around 0 51.0%
neg-mul-151.0%
Simplified51.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 2024086
(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))