| Alternative 1 | |
|---|---|
| Accuracy | 69.3% |
| Cost | 7380 |
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
(FPCore (x y z) :precision binary64 (if (or (<= x -3.6e+50) (not (<= x 3.3e+74))) (fabs (* (/ x y) (- 1.0 z))) (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 <= -3.6e+50) || !(x <= 3.3e+74)) {
tmp = fabs(((x / y) * (1.0 - z)));
} 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 <= (-3.6d+50)) .or. (.not. (x <= 3.3d+74))) then
tmp = abs(((x / y) * (1.0d0 - z)))
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 <= -3.6e+50) || !(x <= 3.3e+74)) {
tmp = Math.abs(((x / y) * (1.0 - z)));
} 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 <= -3.6e+50) or not (x <= 3.3e+74): tmp = math.fabs(((x / y) * (1.0 - z))) 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 <= -3.6e+50) || !(x <= 3.3e+74)) tmp = abs(Float64(Float64(x / y) * Float64(1.0 - z))); 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 <= -3.6e+50) || ~((x <= 3.3e+74))) tmp = abs(((x / y) * (1.0 - z))); 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, -3.6e+50], N[Not[LessEqual[x, 3.3e+74]], $MachinePrecision]], N[Abs[N[(N[(x / y), $MachinePrecision] * N[(1.0 - z), $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 -3.6 \cdot 10^{+50} \lor \neg \left(x \leq 3.3 \cdot 10^{+74}\right):\\
\;\;\;\;\left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\
\end{array}
Results
if x < -3.59999999999999986e50 or 3.3000000000000002e74 < x Initial program 99.8%
Simplified99.8%
[Start]99.8 | \[ \left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\] |
|---|---|
*-lft-identity [<=]99.8 | \[ \color{blue}{1 \cdot \left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|}
\] |
metadata-eval [<=]99.8 | \[ \color{blue}{\left|-1\right|} \cdot \left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\] |
fabs-sub [=>]99.8 | \[ \left|-1\right| \cdot \color{blue}{\left|\frac{x}{y} \cdot z - \frac{x + 4}{y}\right|}
\] |
fabs-mul [<=]99.8 | \[ \color{blue}{\left|-1 \cdot \left(\frac{x}{y} \cdot z - \frac{x + 4}{y}\right)\right|}
\] |
neg-mul-1 [<=]99.8 | \[ \left|\color{blue}{-\left(\frac{x}{y} \cdot z - \frac{x + 4}{y}\right)}\right|
\] |
sub0-neg [<=]99.8 | \[ \left|\color{blue}{0 - \left(\frac{x}{y} \cdot z - \frac{x + 4}{y}\right)}\right|
\] |
associate-+l- [<=]99.8 | \[ \left|\color{blue}{\left(0 - \frac{x}{y} \cdot z\right) + \frac{x + 4}{y}}\right|
\] |
neg-sub0 [<=]99.8 | \[ \left|\color{blue}{\left(-\frac{x}{y} \cdot z\right)} + \frac{x + 4}{y}\right|
\] |
+-commutative [<=]99.8 | \[ \left|\color{blue}{\frac{x + 4}{y} + \left(-\frac{x}{y} \cdot z\right)}\right|
\] |
sub-neg [<=]99.8 | \[ \left|\color{blue}{\frac{x + 4}{y} - \frac{x}{y} \cdot z}\right|
\] |
associate-*l/ [=>]82.7 | \[ \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right|
\] |
*-commutative [=>]82.7 | \[ \left|\frac{x + 4}{y} - \frac{\color{blue}{z \cdot x}}{y}\right|
\] |
associate-/l* [=>]99.8 | \[ \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right|
\] |
Taylor expanded in x around inf 99.6%
Simplified99.8%
[Start]99.6 | \[ \left|\left(\frac{1}{y} - \frac{z}{y}\right) \cdot x\right|
\] |
|---|---|
*-commutative [=>]99.6 | \[ \left|\color{blue}{x \cdot \left(\frac{1}{y} - \frac{z}{y}\right)}\right|
\] |
sub-neg [=>]99.6 | \[ \left|x \cdot \color{blue}{\left(\frac{1}{y} + \left(-\frac{z}{y}\right)\right)}\right|
\] |
mul-1-neg [<=]99.6 | \[ \left|x \cdot \left(\frac{1}{y} + \color{blue}{-1 \cdot \frac{z}{y}}\right)\right|
\] |
+-commutative [=>]99.6 | \[ \left|x \cdot \color{blue}{\left(-1 \cdot \frac{z}{y} + \frac{1}{y}\right)}\right|
\] |
associate-*r/ [=>]99.6 | \[ \left|x \cdot \left(\color{blue}{\frac{-1 \cdot z}{y}} + \frac{1}{y}\right)\right|
\] |
neg-mul-1 [<=]99.6 | \[ \left|x \cdot \left(\frac{\color{blue}{-z}}{y} + \frac{1}{y}\right)\right|
\] |
remove-double-neg [<=]99.6 | \[ \left|x \cdot \left(\frac{-z}{\color{blue}{-\left(-y\right)}} + \frac{1}{y}\right)\right|
\] |
distribute-rgt-in [=>]99.6 | \[ \left|\color{blue}{\frac{-z}{-\left(-y\right)} \cdot x + \frac{1}{y} \cdot x}\right|
\] |
neg-mul-1 [=>]99.6 | \[ \left|\frac{\color{blue}{-1 \cdot z}}{-\left(-y\right)} \cdot x + \frac{1}{y} \cdot x\right|
\] |
remove-double-neg [=>]99.6 | \[ \left|\frac{-1 \cdot z}{\color{blue}{y}} \cdot x + \frac{1}{y} \cdot x\right|
\] |
associate-*r/ [<=]99.6 | \[ \left|\color{blue}{\left(-1 \cdot \frac{z}{y}\right)} \cdot x + \frac{1}{y} \cdot x\right|
\] |
associate-*r* [<=]99.6 | \[ \left|\color{blue}{-1 \cdot \left(\frac{z}{y} \cdot x\right)} + \frac{1}{y} \cdot x\right|
\] |
associate-*l/ [=>]82.5 | \[ \left|-1 \cdot \color{blue}{\frac{z \cdot x}{y}} + \frac{1}{y} \cdot x\right|
\] |
associate-*l/ [=>]82.7 | \[ \left|-1 \cdot \frac{z \cdot x}{y} + \color{blue}{\frac{1 \cdot x}{y}}\right|
\] |
associate-*r/ [<=]82.7 | \[ \left|-1 \cdot \frac{z \cdot x}{y} + \color{blue}{1 \cdot \frac{x}{y}}\right|
\] |
*-lft-identity [=>]82.7 | \[ \left|-1 \cdot \frac{z \cdot x}{y} + \color{blue}{\frac{x}{y}}\right|
\] |
associate-*r/ [<=]99.8 | \[ \left|-1 \cdot \color{blue}{\left(z \cdot \frac{x}{y}\right)} + \frac{x}{y}\right|
\] |
associate-*r* [=>]99.8 | \[ \left|\color{blue}{\left(-1 \cdot z\right) \cdot \frac{x}{y}} + \frac{x}{y}\right|
\] |
neg-mul-1 [<=]99.8 | \[ \left|\color{blue}{\left(-z\right)} \cdot \frac{x}{y} + \frac{x}{y}\right|
\] |
distribute-lft1-in [=>]99.8 | \[ \left|\color{blue}{\left(\left(-z\right) + 1\right) \cdot \frac{x}{y}}\right|
\] |
if -3.59999999999999986e50 < x < 3.3000000000000002e74Initial program 96.9%
Applied egg-rr99.3%
[Start]96.9 | \[ \left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\] |
|---|---|
associate-*l/ [=>]99.3 | \[ \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right|
\] |
sub-div [=>]99.3 | \[ \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right|
\] |
Final simplification99.5%
| Alternative 1 | |
|---|---|
| Accuracy | 69.3% |
| Cost | 7380 |
| Alternative 2 | |
|---|---|
| Accuracy | 69.3% |
| Cost | 7380 |
| Alternative 3 | |
|---|---|
| Accuracy | 85.1% |
| Cost | 7113 |
| Alternative 4 | |
|---|---|
| Accuracy | 85.2% |
| Cost | 7112 |
| Alternative 5 | |
|---|---|
| Accuracy | 85.2% |
| Cost | 7112 |
| Alternative 6 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 7104 |
| Alternative 7 | |
|---|---|
| Accuracy | 81.9% |
| Cost | 6984 |
| Alternative 8 | |
|---|---|
| Accuracy | 70.1% |
| Cost | 6857 |
| Alternative 9 | |
|---|---|
| Accuracy | 48.8% |
| Cost | 6592 |
herbie shell --seed 2023137
(FPCore (x y z)
:name "fabs fraction 1"
:precision binary64
(fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))