| Alternative 1 | |
|---|---|
| Error | 66.9% |
| Cost | 7777.00 |
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (+ x 4.0) y)) (t_1 (* z (/ x y))) (t_2 (- t_0 t_1)))
(if (<= t_2 -0.02)
(fabs (- t_0 (/ z (/ y x))))
(if (<= t_2 5e-137)
(fabs (/ (- (+ x 4.0) (* x z)) y))
(fabs (+ t_1 (/ (- -4.0 x) 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 t_0 = (x + 4.0) / y;
double t_1 = z * (x / y);
double t_2 = t_0 - t_1;
double tmp;
if (t_2 <= -0.02) {
tmp = fabs((t_0 - (z / (y / x))));
} else if (t_2 <= 5e-137) {
tmp = fabs((((x + 4.0) - (x * z)) / y));
} else {
tmp = fabs((t_1 + ((-4.0 - x) / 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) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = (x + 4.0d0) / y
t_1 = z * (x / y)
t_2 = t_0 - t_1
if (t_2 <= (-0.02d0)) then
tmp = abs((t_0 - (z / (y / x))))
else if (t_2 <= 5d-137) then
tmp = abs((((x + 4.0d0) - (x * z)) / y))
else
tmp = abs((t_1 + (((-4.0d0) - x) / 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 t_0 = (x + 4.0) / y;
double t_1 = z * (x / y);
double t_2 = t_0 - t_1;
double tmp;
if (t_2 <= -0.02) {
tmp = Math.abs((t_0 - (z / (y / x))));
} else if (t_2 <= 5e-137) {
tmp = Math.abs((((x + 4.0) - (x * z)) / y));
} else {
tmp = Math.abs((t_1 + ((-4.0 - x) / y)));
}
return tmp;
}
def code(x, y, z): return math.fabs((((x + 4.0) / y) - ((x / y) * z)))
def code(x, y, z): t_0 = (x + 4.0) / y t_1 = z * (x / y) t_2 = t_0 - t_1 tmp = 0 if t_2 <= -0.02: tmp = math.fabs((t_0 - (z / (y / x)))) elif t_2 <= 5e-137: tmp = math.fabs((((x + 4.0) - (x * z)) / y)) else: tmp = math.fabs((t_1 + ((-4.0 - x) / 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) t_0 = Float64(Float64(x + 4.0) / y) t_1 = Float64(z * Float64(x / y)) t_2 = Float64(t_0 - t_1) tmp = 0.0 if (t_2 <= -0.02) tmp = abs(Float64(t_0 - Float64(z / Float64(y / x)))); elseif (t_2 <= 5e-137) tmp = abs(Float64(Float64(Float64(x + 4.0) - Float64(x * z)) / y)); else tmp = abs(Float64(t_1 + Float64(Float64(-4.0 - x) / 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) t_0 = (x + 4.0) / y; t_1 = z * (x / y); t_2 = t_0 - t_1; tmp = 0.0; if (t_2 <= -0.02) tmp = abs((t_0 - (z / (y / x)))); elseif (t_2 <= 5e-137) tmp = abs((((x + 4.0) - (x * z)) / y)); else tmp = abs((t_1 + ((-4.0 - x) / 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_] := Block[{t$95$0 = N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 - t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, -0.02], N[Abs[N[(t$95$0 - N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[t$95$2, 5e-137], N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] - N[(x * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(t$95$1 + N[(N[(-4.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
t_0 := \frac{x + 4}{y}\\
t_1 := z \cdot \frac{x}{y}\\
t_2 := t_0 - t_1\\
\mathbf{if}\;t_2 \leq -0.02:\\
\;\;\;\;\left|t_0 - \frac{z}{\frac{y}{x}}\right|\\
\mathbf{elif}\;t_2 \leq 5 \cdot 10^{-137}:\\
\;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|t_1 + \frac{-4 - x}{y}\right|\\
\end{array}
Results
if (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < -0.0200000000000000004Initial 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/ [=>]92.0 | \[ \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right|
\] |
*-commutative [=>]92.0 | \[ \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|
\] |
if -0.0200000000000000004 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < 5.00000000000000001e-137Initial program 91.9
Taylor expanded in x around 0 99.8
Simplified99.9
[Start]99.8 | \[ \left|4 \cdot \frac{1}{y} + \left(\frac{1}{y} - \frac{z}{y}\right) \cdot x\right|
\] |
|---|---|
*-commutative [=>]99.8 | \[ \left|4 \cdot \frac{1}{y} + \color{blue}{x \cdot \left(\frac{1}{y} - \frac{z}{y}\right)}\right|
\] |
sub-neg [=>]99.8 | \[ \left|4 \cdot \frac{1}{y} + x \cdot \color{blue}{\left(\frac{1}{y} + \left(-\frac{z}{y}\right)\right)}\right|
\] |
mul-1-neg [<=]99.8 | \[ \left|4 \cdot \frac{1}{y} + x \cdot \left(\frac{1}{y} + \color{blue}{-1 \cdot \frac{z}{y}}\right)\right|
\] |
distribute-rgt-in [=>]99.8 | \[ \left|4 \cdot \frac{1}{y} + \color{blue}{\left(\frac{1}{y} \cdot x + \left(-1 \cdot \frac{z}{y}\right) \cdot x\right)}\right|
\] |
*-commutative [<=]99.8 | \[ \left|4 \cdot \frac{1}{y} + \left(\color{blue}{x \cdot \frac{1}{y}} + \left(-1 \cdot \frac{z}{y}\right) \cdot x\right)\right|
\] |
associate-*r* [<=]99.8 | \[ \left|4 \cdot \frac{1}{y} + \left(x \cdot \frac{1}{y} + \color{blue}{-1 \cdot \left(\frac{z}{y} \cdot x\right)}\right)\right|
\] |
associate-*l/ [=>]99.8 | \[ \left|4 \cdot \frac{1}{y} + \left(x \cdot \frac{1}{y} + -1 \cdot \color{blue}{\frac{z \cdot x}{y}}\right)\right|
\] |
mul-1-neg [=>]99.8 | \[ \left|4 \cdot \frac{1}{y} + \left(x \cdot \frac{1}{y} + \color{blue}{\left(-\frac{z \cdot x}{y}\right)}\right)\right|
\] |
*-commutative [=>]99.8 | \[ \left|4 \cdot \frac{1}{y} + \left(x \cdot \frac{1}{y} + \left(-\frac{\color{blue}{x \cdot z}}{y}\right)\right)\right|
\] |
associate-*l/ [<=]91.8 | \[ \left|4 \cdot \frac{1}{y} + \left(x \cdot \frac{1}{y} + \left(-\color{blue}{\frac{x}{y} \cdot z}\right)\right)\right|
\] |
distribute-rgt-neg-out [<=]91.8 | \[ \left|4 \cdot \frac{1}{y} + \left(x \cdot \frac{1}{y} + \color{blue}{\frac{x}{y} \cdot \left(-z\right)}\right)\right|
\] |
associate-+r+ [=>]91.8 | \[ \left|\color{blue}{\left(4 \cdot \frac{1}{y} + x \cdot \frac{1}{y}\right) + \frac{x}{y} \cdot \left(-z\right)}\right|
\] |
+-commutative [<=]91.8 | \[ \left|\color{blue}{\left(x \cdot \frac{1}{y} + 4 \cdot \frac{1}{y}\right)} + \frac{x}{y} \cdot \left(-z\right)\right|
\] |
distribute-rgt-in [<=]91.8 | \[ \left|\color{blue}{\frac{1}{y} \cdot \left(x + 4\right)} + \frac{x}{y} \cdot \left(-z\right)\right|
\] |
associate-*l/ [=>]91.9 | \[ \left|\color{blue}{\frac{1 \cdot \left(x + 4\right)}{y}} + \frac{x}{y} \cdot \left(-z\right)\right|
\] |
*-lft-identity [=>]91.9 | \[ \left|\frac{\color{blue}{x + 4}}{y} + \frac{x}{y} \cdot \left(-z\right)\right|
\] |
distribute-rgt-neg-out [=>]91.9 | \[ \left|\frac{x + 4}{y} + \color{blue}{\left(-\frac{x}{y} \cdot z\right)}\right|
\] |
if 5.00000000000000001e-137 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) Initial program 99.5
Final simplification99.7
| Alternative 1 | |
|---|---|
| Error | 66.9% |
| Cost | 7777.00 |
| Alternative 2 | |
|---|---|
| Error | 67.1% |
| Cost | 7777.00 |
| Alternative 3 | |
|---|---|
| Error | 67.1% |
| Cost | 7777.00 |
| Alternative 4 | |
|---|---|
| Error | 99.2% |
| Cost | 7496.00 |
| Alternative 5 | |
|---|---|
| Error | 85.3% |
| Cost | 7376.00 |
| Alternative 6 | |
|---|---|
| Error | 85.4% |
| Cost | 7376.00 |
| Alternative 7 | |
|---|---|
| Error | 99.4% |
| Cost | 7368.00 |
| Alternative 8 | |
|---|---|
| Error | 99.8% |
| Cost | 7241.00 |
| Alternative 9 | |
|---|---|
| Error | 97.8% |
| Cost | 7113.00 |
| Alternative 10 | |
|---|---|
| Error | 81.6% |
| Cost | 6985.00 |
| Alternative 11 | |
|---|---|
| Error | 81.7% |
| Cost | 6984.00 |
| Alternative 12 | |
|---|---|
| Error | 70.1% |
| Cost | 6857.00 |
| Alternative 13 | |
|---|---|
| Error | 48.9% |
| Cost | 6592.00 |
herbie shell --seed 2023093
(FPCore (x y z)
:name "fabs fraction 1"
:precision binary64
(fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))