| Alternative 1 | |
|---|---|
| Accuracy | 69.9% |
| Cost | 7248 |
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
(FPCore (x y z) :precision binary64 (if (or (<= x -5e+48) (not (<= x 3.2e-5))) (fabs (* (/ x y) (+ z -1.0))) (fabs (/ (- (+ x 4.0) (* x z)) y))))
double code(double x, double y, double z) {
return fabs((((x + 4.0) / y) - ((x / y) * z)));
}
double code(double x, double y, double z) {
double tmp;
if ((x <= -5e+48) || !(x <= 3.2e-5)) {
tmp = fabs(((x / y) * (z + -1.0)));
} else {
tmp = fabs((((x + 4.0) - (x * z)) / 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
code = abs((((x + 4.0d0) / y) - ((x / y) * z)))
end 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 ((x <= (-5d+48)) .or. (.not. (x <= 3.2d-5))) then
tmp = abs(((x / y) * (z + (-1.0d0))))
else
tmp = abs((((x + 4.0d0) - (x * z)) / y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
return Math.abs((((x + 4.0) / y) - ((x / y) * z)));
}
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5e+48) || !(x <= 3.2e-5)) {
tmp = Math.abs(((x / y) * (z + -1.0)));
} else {
tmp = Math.abs((((x + 4.0) - (x * z)) / y));
}
return tmp;
}
def code(x, y, z): return math.fabs((((x + 4.0) / y) - ((x / y) * z)))
def code(x, y, z): tmp = 0 if (x <= -5e+48) or not (x <= 3.2e-5): tmp = math.fabs(((x / y) * (z + -1.0))) else: tmp = math.fabs((((x + 4.0) - (x * z)) / y)) return tmp
function code(x, y, z) return abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(x / y) * z))) end
function code(x, y, z) tmp = 0.0 if ((x <= -5e+48) || !(x <= 3.2e-5)) tmp = abs(Float64(Float64(x / y) * Float64(z + -1.0))); else tmp = abs(Float64(Float64(Float64(x + 4.0) - Float64(x * z)) / y)); end return tmp end
function tmp = code(x, y, z) tmp = abs((((x + 4.0) / y) - ((x / y) * z))); end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5e+48) || ~((x <= 3.2e-5))) tmp = abs(((x / y) * (z + -1.0))); else tmp = abs((((x + 4.0) - (x * z)) / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_, y_, z_] := If[Or[LessEqual[x, -5e+48], N[Not[LessEqual[x, 3.2e-5]], $MachinePrecision]], N[Abs[N[(N[(x / y), $MachinePrecision] * N[(z + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] - N[(x * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{+48} \lor \neg \left(x \leq 3.2 \cdot 10^{-5}\right):\\
\;\;\;\;\left|\frac{x}{y} \cdot \left(z + -1\right)\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\
\end{array}
Results
if x < -4.99999999999999973e48 or 3.19999999999999986e-5 < x Initial program 99.8%
Simplified99.8%
[Start]99.8 | \[ \left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\] |
|---|---|
fabs-sub [=>]99.8 | \[ \color{blue}{\left|\frac{x}{y} \cdot z - \frac{x + 4}{y}\right|}
\] |
associate-*l/ [=>]85.9 | \[ \left|\color{blue}{\frac{x \cdot z}{y}} - \frac{x + 4}{y}\right|
\] |
*-commutative [=>]85.9 | \[ \left|\frac{\color{blue}{z \cdot x}}{y} - \frac{x + 4}{y}\right|
\] |
associate-*l/ [<=]99.8 | \[ \left|\color{blue}{\frac{z}{y} \cdot x} - \frac{x + 4}{y}\right|
\] |
*-commutative [=>]99.8 | \[ \left|\color{blue}{x \cdot \frac{z}{y}} - \frac{x + 4}{y}\right|
\] |
fma-neg [=>]99.8 | \[ \left|\color{blue}{\mathsf{fma}\left(x, \frac{z}{y}, -\frac{x + 4}{y}\right)}\right|
\] |
distribute-neg-frac [=>]99.8 | \[ \left|\mathsf{fma}\left(x, \frac{z}{y}, \color{blue}{\frac{-\left(x + 4\right)}{y}}\right)\right|
\] |
+-commutative [=>]99.8 | \[ \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{-\color{blue}{\left(4 + x\right)}}{y}\right)\right|
\] |
distribute-neg-in [=>]99.8 | \[ \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{\color{blue}{\left(-4\right) + \left(-x\right)}}{y}\right)\right|
\] |
unsub-neg [=>]99.8 | \[ \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{\color{blue}{\left(-4\right) - x}}{y}\right)\right|
\] |
metadata-eval [=>]99.8 | \[ \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{\color{blue}{-4} - x}{y}\right)\right|
\] |
Taylor expanded in x around inf 97.6%
Simplified97.9%
[Start]97.6 | \[ \left|\left(\frac{z}{y} - \frac{1}{y}\right) \cdot x\right|
\] |
|---|---|
*-commutative [=>]97.6 | \[ \left|\color{blue}{x \cdot \left(\frac{z}{y} - \frac{1}{y}\right)}\right|
\] |
sub-neg [=>]97.6 | \[ \left|x \cdot \color{blue}{\left(\frac{z}{y} + \left(-\frac{1}{y}\right)\right)}\right|
\] |
+-commutative [=>]97.6 | \[ \left|x \cdot \color{blue}{\left(\left(-\frac{1}{y}\right) + \frac{z}{y}\right)}\right|
\] |
distribute-rgt-out [<=]97.6 | \[ \left|\color{blue}{\left(-\frac{1}{y}\right) \cdot x + \frac{z}{y} \cdot x}\right|
\] |
distribute-neg-frac [=>]97.6 | \[ \left|\color{blue}{\frac{-1}{y}} \cdot x + \frac{z}{y} \cdot x\right|
\] |
metadata-eval [=>]97.6 | \[ \left|\frac{\color{blue}{-1}}{y} \cdot x + \frac{z}{y} \cdot x\right|
\] |
associate-*l/ [=>]97.9 | \[ \left|\color{blue}{\frac{-1 \cdot x}{y}} + \frac{z}{y} \cdot x\right|
\] |
associate-*r/ [<=]97.9 | \[ \left|\color{blue}{-1 \cdot \frac{x}{y}} + \frac{z}{y} \cdot x\right|
\] |
*-commutative [=>]97.9 | \[ \left|\color{blue}{\frac{x}{y} \cdot -1} + \frac{z}{y} \cdot x\right|
\] |
*-commutative [<=]97.9 | \[ \left|\frac{x}{y} \cdot -1 + \color{blue}{x \cdot \frac{z}{y}}\right|
\] |
associate-*r/ [=>]84.0 | \[ \left|\frac{x}{y} \cdot -1 + \color{blue}{\frac{x \cdot z}{y}}\right|
\] |
associate-/l* [=>]97.9 | \[ \left|\frac{x}{y} \cdot -1 + \color{blue}{\frac{x}{\frac{y}{z}}}\right|
\] |
associate-/r/ [=>]97.9 | \[ \left|\frac{x}{y} \cdot -1 + \color{blue}{\frac{x}{y} \cdot z}\right|
\] |
distribute-lft-out [=>]97.9 | \[ \left|\color{blue}{\frac{x}{y} \cdot \left(-1 + z\right)}\right|
\] |
if -4.99999999999999973e48 < x < 3.19999999999999986e-5Initial program 96.5%
Applied egg-rr99.6%
[Start]96.5 | \[ \left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\] |
|---|---|
associate-*l/ [=>]99.6 | \[ \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right|
\] |
sub-div [=>]99.6 | \[ \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right|
\] |
Final simplification99.0%
| Alternative 1 | |
|---|---|
| Accuracy | 69.9% |
| Cost | 7248 |
| Alternative 2 | |
|---|---|
| Accuracy | 69.9% |
| Cost | 7248 |
| Alternative 3 | |
|---|---|
| Accuracy | 69.9% |
| Cost | 7248 |
| Alternative 4 | |
|---|---|
| Accuracy | 86.5% |
| Cost | 7113 |
| Alternative 5 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 7104 |
| Alternative 6 | |
|---|---|
| Accuracy | 81.6% |
| Cost | 6984 |
| Alternative 7 | |
|---|---|
| Accuracy | 70.8% |
| Cost | 6857 |
| Alternative 8 | |
|---|---|
| Accuracy | 49.5% |
| Cost | 6592 |
herbie shell --seed 2023146
(FPCore (x y z)
:name "fabs fraction 1"
:precision binary64
(fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))