| Alternative 1 | |
|---|---|
| Error | 12.3 |
| Cost | 7248 |
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
(FPCore (x y z)
:precision binary64
(if (<= x -2.4e+201)
(fabs (/ x (/ y (+ z -1.0))))
(if (<= x 2e+29)
(fabs (- (/ (+ x 4.0) y) (/ (* x z) y)))
(fabs (* (/ x y) (+ z -1.0))))))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 <= -2.4e+201) {
tmp = fabs((x / (y / (z + -1.0))));
} else if (x <= 2e+29) {
tmp = fabs((((x + 4.0) / y) - ((x * z) / y)));
} else {
tmp = fabs(((x / y) * (z + -1.0)));
}
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 <= (-2.4d+201)) then
tmp = abs((x / (y / (z + (-1.0d0)))))
else if (x <= 2d+29) then
tmp = abs((((x + 4.0d0) / y) - ((x * z) / y)))
else
tmp = abs(((x / y) * (z + (-1.0d0))))
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 <= -2.4e+201) {
tmp = Math.abs((x / (y / (z + -1.0))));
} else if (x <= 2e+29) {
tmp = Math.abs((((x + 4.0) / y) - ((x * z) / y)));
} else {
tmp = Math.abs(((x / y) * (z + -1.0)));
}
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 <= -2.4e+201: tmp = math.fabs((x / (y / (z + -1.0)))) elif x <= 2e+29: tmp = math.fabs((((x + 4.0) / y) - ((x * z) / y))) else: tmp = math.fabs(((x / y) * (z + -1.0))) 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 <= -2.4e+201) tmp = abs(Float64(x / Float64(y / Float64(z + -1.0)))); elseif (x <= 2e+29) tmp = abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(x * z) / y))); else tmp = abs(Float64(Float64(x / y) * Float64(z + -1.0))); 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 <= -2.4e+201) tmp = abs((x / (y / (z + -1.0)))); elseif (x <= 2e+29) tmp = abs((((x + 4.0) / y) - ((x * z) / y))); else tmp = abs(((x / y) * (z + -1.0))); 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[LessEqual[x, -2.4e+201], N[Abs[N[(x / N[(y / N[(z + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, 2e+29], N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(N[(x * z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(x / y), $MachinePrecision] * N[(z + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{+201}:\\
\;\;\;\;\left|\frac{x}{\frac{y}{z + -1}}\right|\\
\mathbf{elif}\;x \leq 2 \cdot 10^{+29}:\\
\;\;\;\;\left|\frac{x + 4}{y} - \frac{x \cdot z}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{x}{y} \cdot \left(z + -1\right)\right|\\
\end{array}
Results
if x < -2.39999999999999993e201Initial program 0.1
Simplified0.1
[Start]0.1 | \[ \left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\] |
|---|---|
fabs-sub [=>]0.1 | \[ \color{blue}{\left|\frac{x}{y} \cdot z - \frac{x + 4}{y}\right|}
\] |
associate-*l/ [=>]17.0 | \[ \left|\color{blue}{\frac{x \cdot z}{y}} - \frac{x + 4}{y}\right|
\] |
associate-*r/ [<=]0.1 | \[ \left|\color{blue}{x \cdot \frac{z}{y}} - \frac{x + 4}{y}\right|
\] |
*-commutative [<=]0.1 | \[ \left|\color{blue}{\frac{z}{y} \cdot x} - \frac{x + 4}{y}\right|
\] |
*-commutative [=>]0.1 | \[ \left|\color{blue}{x \cdot \frac{z}{y}} - \frac{x + 4}{y}\right|
\] |
fma-neg [=>]0.1 | \[ \left|\color{blue}{\mathsf{fma}\left(x, \frac{z}{y}, -\frac{x + 4}{y}\right)}\right|
\] |
distribute-neg-frac [=>]0.1 | \[ \left|\mathsf{fma}\left(x, \frac{z}{y}, \color{blue}{\frac{-\left(x + 4\right)}{y}}\right)\right|
\] |
neg-sub0 [=>]0.1 | \[ \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{\color{blue}{0 - \left(x + 4\right)}}{y}\right)\right|
\] |
+-commutative [=>]0.1 | \[ \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{0 - \color{blue}{\left(4 + x\right)}}{y}\right)\right|
\] |
associate--r+ [=>]0.1 | \[ \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{\color{blue}{\left(0 - 4\right) - x}}{y}\right)\right|
\] |
metadata-eval [=>]0.1 | \[ \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{\color{blue}{-4} - x}{y}\right)\right|
\] |
Taylor expanded in x around inf 0.3
Simplified0.1
[Start]0.3 | \[ \left|\left(\frac{z}{y} - \frac{1}{y}\right) \cdot x\right|
\] |
|---|---|
*-commutative [=>]0.3 | \[ \left|\color{blue}{x \cdot \left(\frac{z}{y} - \frac{1}{y}\right)}\right|
\] |
sub-neg [=>]0.3 | \[ \left|x \cdot \color{blue}{\left(\frac{z}{y} + \left(-\frac{1}{y}\right)\right)}\right|
\] |
distribute-lft-in [=>]0.3 | \[ \left|\color{blue}{x \cdot \frac{z}{y} + x \cdot \left(-\frac{1}{y}\right)}\right|
\] |
distribute-neg-frac [=>]0.3 | \[ \left|x \cdot \frac{z}{y} + x \cdot \color{blue}{\frac{-1}{y}}\right|
\] |
metadata-eval [=>]0.3 | \[ \left|x \cdot \frac{z}{y} + x \cdot \frac{\color{blue}{-1}}{y}\right|
\] |
associate-*r/ [=>]0.1 | \[ \left|x \cdot \frac{z}{y} + \color{blue}{\frac{x \cdot -1}{y}}\right|
\] |
*-commutative [<=]0.1 | \[ \left|x \cdot \frac{z}{y} + \frac{\color{blue}{-1 \cdot x}}{y}\right|
\] |
associate-*r/ [<=]0.1 | \[ \left|x \cdot \frac{z}{y} + \color{blue}{-1 \cdot \frac{x}{y}}\right|
\] |
mul-1-neg [=>]0.1 | \[ \left|x \cdot \frac{z}{y} + \color{blue}{\left(-\frac{x}{y}\right)}\right|
\] |
sub-neg [<=]0.1 | \[ \left|\color{blue}{x \cdot \frac{z}{y} - \frac{x}{y}}\right|
\] |
*-commutative [=>]0.1 | \[ \left|\color{blue}{\frac{z}{y} \cdot x} - \frac{x}{y}\right|
\] |
associate-/r/ [<=]0.1 | \[ \left|\color{blue}{\frac{z}{\frac{y}{x}}} - \frac{x}{y}\right|
\] |
Applied egg-rr0.3
Applied egg-rr0.1
if -2.39999999999999993e201 < x < 1.99999999999999983e29Initial program 2.2
Taylor expanded in x around 0 1.2
if 1.99999999999999983e29 < x Initial program 0.1
Simplified0.1
[Start]0.1 | \[ \left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\] |
|---|---|
fabs-sub [=>]0.1 | \[ \color{blue}{\left|\frac{x}{y} \cdot z - \frac{x + 4}{y}\right|}
\] |
associate-*l/ [=>]9.1 | \[ \left|\color{blue}{\frac{x \cdot z}{y}} - \frac{x + 4}{y}\right|
\] |
associate-*r/ [<=]0.1 | \[ \left|\color{blue}{x \cdot \frac{z}{y}} - \frac{x + 4}{y}\right|
\] |
*-commutative [<=]0.1 | \[ \left|\color{blue}{\frac{z}{y} \cdot x} - \frac{x + 4}{y}\right|
\] |
*-commutative [=>]0.1 | \[ \left|\color{blue}{x \cdot \frac{z}{y}} - \frac{x + 4}{y}\right|
\] |
fma-neg [=>]0.1 | \[ \left|\color{blue}{\mathsf{fma}\left(x, \frac{z}{y}, -\frac{x + 4}{y}\right)}\right|
\] |
distribute-neg-frac [=>]0.1 | \[ \left|\mathsf{fma}\left(x, \frac{z}{y}, \color{blue}{\frac{-\left(x + 4\right)}{y}}\right)\right|
\] |
neg-sub0 [=>]0.1 | \[ \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{\color{blue}{0 - \left(x + 4\right)}}{y}\right)\right|
\] |
+-commutative [=>]0.1 | \[ \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{0 - \color{blue}{\left(4 + x\right)}}{y}\right)\right|
\] |
associate--r+ [=>]0.1 | \[ \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{\color{blue}{\left(0 - 4\right) - x}}{y}\right)\right|
\] |
metadata-eval [=>]0.1 | \[ \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{\color{blue}{-4} - x}{y}\right)\right|
\] |
Taylor expanded in x around inf 0.3
Simplified0.1
[Start]0.3 | \[ \left|\left(\frac{z}{y} - \frac{1}{y}\right) \cdot x\right|
\] |
|---|---|
*-commutative [=>]0.3 | \[ \left|\color{blue}{x \cdot \left(\frac{z}{y} - \frac{1}{y}\right)}\right|
\] |
sub-neg [=>]0.3 | \[ \left|x \cdot \color{blue}{\left(\frac{z}{y} + \left(-\frac{1}{y}\right)\right)}\right|
\] |
distribute-lft-in [=>]0.3 | \[ \left|\color{blue}{x \cdot \frac{z}{y} + x \cdot \left(-\frac{1}{y}\right)}\right|
\] |
distribute-neg-frac [=>]0.3 | \[ \left|x \cdot \frac{z}{y} + x \cdot \color{blue}{\frac{-1}{y}}\right|
\] |
metadata-eval [=>]0.3 | \[ \left|x \cdot \frac{z}{y} + x \cdot \frac{\color{blue}{-1}}{y}\right|
\] |
associate-*r/ [=>]0.1 | \[ \left|x \cdot \frac{z}{y} + \color{blue}{\frac{x \cdot -1}{y}}\right|
\] |
*-commutative [<=]0.1 | \[ \left|x \cdot \frac{z}{y} + \frac{\color{blue}{-1 \cdot x}}{y}\right|
\] |
associate-*r/ [<=]0.1 | \[ \left|x \cdot \frac{z}{y} + \color{blue}{-1 \cdot \frac{x}{y}}\right|
\] |
mul-1-neg [=>]0.1 | \[ \left|x \cdot \frac{z}{y} + \color{blue}{\left(-\frac{x}{y}\right)}\right|
\] |
sub-neg [<=]0.1 | \[ \left|\color{blue}{x \cdot \frac{z}{y} - \frac{x}{y}}\right|
\] |
*-commutative [=>]0.1 | \[ \left|\color{blue}{\frac{z}{y} \cdot x} - \frac{x}{y}\right|
\] |
associate-/r/ [<=]0.1 | \[ \left|\color{blue}{\frac{z}{\frac{y}{x}}} - \frac{x}{y}\right|
\] |
Applied egg-rr0.1
Final simplification0.9
| Alternative 1 | |
|---|---|
| Error | 12.3 |
| Cost | 7248 |
| Alternative 2 | |
|---|---|
| Error | 0.9 |
| Cost | 7240 |
| Alternative 3 | |
|---|---|
| Error | 0.9 |
| Cost | 7240 |
| Alternative 4 | |
|---|---|
| Error | 0.4 |
| Cost | 7240 |
| Alternative 5 | |
|---|---|
| Error | 8.8 |
| Cost | 7113 |
| Alternative 6 | |
|---|---|
| Error | 8.8 |
| Cost | 7113 |
| Alternative 7 | |
|---|---|
| Error | 8.8 |
| Cost | 7112 |
| Alternative 8 | |
|---|---|
| Error | 0.9 |
| Cost | 7112 |
| Alternative 9 | |
|---|---|
| Error | 18.9 |
| Cost | 6857 |
| Alternative 10 | |
|---|---|
| Error | 32.4 |
| Cost | 6592 |
herbie shell --seed 2023027
(FPCore (x y z)
:name "fabs fraction 1"
:precision binary64
(fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))