| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 8649 |
(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 (- t_0 (* (/ x y) z))))
(if (<= t_1 -2e+78)
(fabs (- t_0 (/ z (/ y x))))
(if (<= t_1 5e+81) (fabs (/ (- (+ x 4.0) (* x z)) y)) (fabs t_1)))))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 = t_0 - ((x / y) * z);
double tmp;
if (t_1 <= -2e+78) {
tmp = fabs((t_0 - (z / (y / x))));
} else if (t_1 <= 5e+81) {
tmp = fabs((((x + 4.0) - (x * z)) / y));
} else {
tmp = fabs(t_1);
}
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) :: tmp
t_0 = (x + 4.0d0) / y
t_1 = t_0 - ((x / y) * z)
if (t_1 <= (-2d+78)) then
tmp = abs((t_0 - (z / (y / x))))
else if (t_1 <= 5d+81) then
tmp = abs((((x + 4.0d0) - (x * z)) / y))
else
tmp = abs(t_1)
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 = t_0 - ((x / y) * z);
double tmp;
if (t_1 <= -2e+78) {
tmp = Math.abs((t_0 - (z / (y / x))));
} else if (t_1 <= 5e+81) {
tmp = Math.abs((((x + 4.0) - (x * z)) / y));
} else {
tmp = Math.abs(t_1);
}
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 = t_0 - ((x / y) * z) tmp = 0 if t_1 <= -2e+78: tmp = math.fabs((t_0 - (z / (y / x)))) elif t_1 <= 5e+81: tmp = math.fabs((((x + 4.0) - (x * z)) / y)) else: tmp = math.fabs(t_1) 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(t_0 - Float64(Float64(x / y) * z)) tmp = 0.0 if (t_1 <= -2e+78) tmp = abs(Float64(t_0 - Float64(z / Float64(y / x)))); elseif (t_1 <= 5e+81) tmp = abs(Float64(Float64(Float64(x + 4.0) - Float64(x * z)) / y)); else tmp = abs(t_1); 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 = t_0 - ((x / y) * z); tmp = 0.0; if (t_1 <= -2e+78) tmp = abs((t_0 - (z / (y / x)))); elseif (t_1 <= 5e+81) tmp = abs((((x + 4.0) - (x * z)) / y)); else tmp = abs(t_1); 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[(t$95$0 - N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+78], N[Abs[N[(t$95$0 - N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[t$95$1, 5e+81], N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] - N[(x * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[t$95$1], $MachinePrecision]]]]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
t_0 := \frac{x + 4}{y}\\
t_1 := t_0 - \frac{x}{y} \cdot z\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+78}:\\
\;\;\;\;\left|t_0 - \frac{z}{\frac{y}{x}}\right|\\
\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+81}:\\
\;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|t_1\right|\\
\end{array}
Results
if (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < -2.00000000000000002e78Initial program 0.1
Simplified0.1
[Start]0.1 | \[ \left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\] |
|---|---|
*-lft-identity [<=]0.1 | \[ \color{blue}{1 \cdot \left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|}
\] |
metadata-eval [<=]0.1 | \[ \color{blue}{\left|-1\right|} \cdot \left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\] |
fabs-sub [=>]0.1 | \[ \left|-1\right| \cdot \color{blue}{\left|\frac{x}{y} \cdot z - \frac{x + 4}{y}\right|}
\] |
fabs-mul [<=]0.1 | \[ \color{blue}{\left|-1 \cdot \left(\frac{x}{y} \cdot z - \frac{x + 4}{y}\right)\right|}
\] |
neg-mul-1 [<=]0.1 | \[ \left|\color{blue}{-\left(\frac{x}{y} \cdot z - \frac{x + 4}{y}\right)}\right|
\] |
sub0-neg [<=]0.1 | \[ \left|\color{blue}{0 - \left(\frac{x}{y} \cdot z - \frac{x + 4}{y}\right)}\right|
\] |
associate-+l- [<=]0.1 | \[ \left|\color{blue}{\left(0 - \frac{x}{y} \cdot z\right) + \frac{x + 4}{y}}\right|
\] |
neg-sub0 [<=]0.1 | \[ \left|\color{blue}{\left(-\frac{x}{y} \cdot z\right)} + \frac{x + 4}{y}\right|
\] |
+-commutative [<=]0.1 | \[ \left|\color{blue}{\frac{x + 4}{y} + \left(-\frac{x}{y} \cdot z\right)}\right|
\] |
sub-neg [<=]0.1 | \[ \left|\color{blue}{\frac{x + 4}{y} - \frac{x}{y} \cdot z}\right|
\] |
associate-*l/ [=>]6.8 | \[ \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right|
\] |
*-commutative [=>]6.8 | \[ \left|\frac{x + 4}{y} - \frac{\color{blue}{z \cdot x}}{y}\right|
\] |
associate-/l* [=>]0.1 | \[ \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right|
\] |
if -2.00000000000000002e78 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < 4.9999999999999998e81Initial program 2.9
Taylor expanded in x around 0 0.3
Simplified0.7
[Start]0.3 | \[ \left|4 \cdot \frac{1}{y} + \left(\frac{1}{y} - \frac{z}{y}\right) \cdot x\right|
\] |
|---|---|
*-commutative [=>]0.3 | \[ \left|4 \cdot \frac{1}{y} + \color{blue}{x \cdot \left(\frac{1}{y} - \frac{z}{y}\right)}\right|
\] |
sub-neg [=>]0.3 | \[ \left|4 \cdot \frac{1}{y} + x \cdot \color{blue}{\left(\frac{1}{y} + \left(-\frac{z}{y}\right)\right)}\right|
\] |
mul-1-neg [<=]0.3 | \[ \left|4 \cdot \frac{1}{y} + x \cdot \left(\frac{1}{y} + \color{blue}{-1 \cdot \frac{z}{y}}\right)\right|
\] |
distribute-rgt-in [=>]0.3 | \[ \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 [<=]0.3 | \[ \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* [<=]0.3 | \[ \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/ [=>]0.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 [=>]0.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 [=>]0.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/ [<=]2.9 | \[ \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 [<=]2.9 | \[ \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+ [=>]2.9 | \[ \left|\color{blue}{\left(4 \cdot \frac{1}{y} + x \cdot \frac{1}{y}\right) + \frac{x}{y} \cdot \left(-z\right)}\right|
\] |
+-commutative [<=]2.9 | \[ \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 [<=]2.9 | \[ \left|\color{blue}{\frac{1}{y} \cdot \left(x + 4\right)} + \frac{x}{y} \cdot \left(-z\right)\right|
\] |
associate-*l/ [=>]2.9 | \[ \left|\color{blue}{\frac{1 \cdot \left(x + 4\right)}{y}} + \frac{x}{y} \cdot \left(-z\right)\right|
\] |
*-lft-identity [=>]2.9 | \[ \left|\frac{\color{blue}{x + 4}}{y} + \frac{x}{y} \cdot \left(-z\right)\right|
\] |
distribute-rgt-neg-out [=>]2.9 | \[ \left|\frac{x + 4}{y} + \color{blue}{\left(-\frac{x}{y} \cdot z\right)}\right|
\] |
if 4.9999999999999998e81 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) Initial program 0.1
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 8649 |
| Alternative 2 | |
|---|---|
| Error | 19.8 |
| Cost | 7381 |
| Alternative 3 | |
|---|---|
| Error | 19.8 |
| Cost | 7381 |
| Alternative 4 | |
|---|---|
| Error | 19.9 |
| Cost | 7381 |
| Alternative 5 | |
|---|---|
| Error | 0.4 |
| Cost | 7241 |
| Alternative 6 | |
|---|---|
| Error | 9.3 |
| Cost | 7113 |
| Alternative 7 | |
|---|---|
| Error | 9.3 |
| Cost | 7113 |
| Alternative 8 | |
|---|---|
| Error | 11.3 |
| Cost | 6984 |
| Alternative 9 | |
|---|---|
| Error | 19.0 |
| Cost | 6857 |
| Alternative 10 | |
|---|---|
| Error | 32.9 |
| Cost | 6592 |
herbie shell --seed 2023073
(FPCore (x y z)
:name "fabs fraction 1"
:precision binary64
(fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))