?

Average Error: 97.4% → 99.7%
Time: 17.1s
Precision: binary64
Cost: 8648.00

?

\[\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} \]
(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}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 3 regimes
  2. if (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < -0.0200000000000000004

    1. Initial program 99.8

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Simplified99.8

      \[\leadsto \color{blue}{\left|\frac{x + 4}{y} - \frac{z}{\frac{y}{x}}\right|} \]
      Proof

      [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-137

    1. Initial program 91.9

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Taylor expanded in x around 0 99.8

      \[\leadsto \left|\color{blue}{4 \cdot \frac{1}{y} + \left(\frac{1}{y} - \frac{z}{y}\right) \cdot x}\right| \]
    3. Simplified99.9

      \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - z \cdot x}{y}}\right| \]
      Proof

      [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))

    1. Initial program 99.5

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x + 4}{y} - z \cdot \frac{x}{y} \leq -0.02:\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;\frac{x + 4}{y} - z \cdot \frac{x}{y} \leq 5 \cdot 10^{-137}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|z \cdot \frac{x}{y} + \frac{-4 - x}{y}\right|\\ \end{array} \]

Alternatives

Alternative 1
Error66.9%
Cost7777.00
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|z \cdot \frac{x}{y}\right|\\ \mathbf{if}\;x \leq -1.22 \cdot 10^{+216}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -8.5 \cdot 10^{+70}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -260000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -3.3 \cdot 10^{-26}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-34}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{+55} \lor \neg \left(x \leq 1.85 \cdot 10^{+122}\right) \land x \leq 9.6 \cdot 10^{+173}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error67.1%
Cost7777.00
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|z \cdot \frac{x}{y}\right|\\ \mathbf{if}\;x \leq -9.5 \cdot 10^{+215}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -4.1 \cdot 10^{+72}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -500000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -2.9 \cdot 10^{-26}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq 5.2 \cdot 10^{-34}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 2.65 \cdot 10^{+47} \lor \neg \left(x \leq 1.6 \cdot 10^{+122}\right) \land x \leq 3.7 \cdot 10^{+174}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error67.1%
Cost7777.00
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -1.08 \cdot 10^{+216}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.56 \cdot 10^{+69}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;x \leq -150000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -7.8 \cdot 10^{-26}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{-34}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 2.9 \cdot 10^{+50} \lor \neg \left(x \leq 1.7 \cdot 10^{+122}\right) \land x \leq 1.15 \cdot 10^{+174}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error99.2%
Cost7496.00
\[\begin{array}{l} t_0 := \frac{x + 4}{y}\\ \mathbf{if}\;x \leq -1.26 \cdot 10^{+67}:\\ \;\;\;\;\left|t_0 - \frac{z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;x \leq 2 \cdot 10^{-118}:\\ \;\;\;\;\left|t_0 - \frac{\frac{x}{\frac{1}{z}}}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|z \cdot \frac{x}{y} + \frac{-4 - x}{y}\right|\\ \end{array} \]
Alternative 5
Error85.3%
Cost7376.00
\[\begin{array}{l} t_0 := \left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{if}\;x \leq -2.2 \cdot 10^{-27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 6 \cdot 10^{-34}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 6 \cdot 10^{-23}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;x \leq 370000:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error85.4%
Cost7376.00
\[\begin{array}{l} t_0 := \left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{if}\;x \leq -7.8 \cdot 10^{-26}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5.2 \cdot 10^{-34}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-23}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;x \leq 430:\\ \;\;\;\;\left|\frac{x}{y} + \frac{4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error99.4%
Cost7368.00
\[\begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{+33}:\\ \;\;\;\;\left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{elif}\;x \leq 2 \cdot 10^{-118}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|z \cdot \frac{x}{y} + \frac{-4 - x}{y}\right|\\ \end{array} \]
Alternative 8
Error99.8%
Cost7241.00
\[\begin{array}{l} \mathbf{if}\;x \leq -4.3 \cdot 10^{+33} \lor \neg \left(x \leq 2.5 \cdot 10^{+14}\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} \]
Alternative 9
Error97.8%
Cost7113.00
\[\begin{array}{l} \mathbf{if}\;x \leq -9 \cdot 10^{-19} \lor \neg \left(x \leq 4.5\right):\\ \;\;\;\;\left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4 - x \cdot z}{y}\right|\\ \end{array} \]
Alternative 10
Error81.6%
Cost6985.00
\[\begin{array}{l} \mathbf{if}\;z \leq -2.5 \cdot 10^{+146} \lor \neg \left(z \leq 80000000000\right):\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \end{array} \]
Alternative 11
Error81.7%
Cost6984.00
\[\begin{array}{l} \mathbf{if}\;z \leq -1.5 \cdot 10^{+146}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;z \leq 70000000000:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \end{array} \]
Alternative 12
Error70.1%
Cost6857.00
\[\begin{array}{l} \mathbf{if}\;x \leq -10.5 \lor \neg \left(x \leq 4\right):\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \end{array} \]
Alternative 13
Error48.9%
Cost6592.00
\[\frac{4}{\left|y\right|} \]

Error

Reproduce?

herbie shell --seed 2023093 
(FPCore (x y z)
  :name "fabs fraction 1"
  :precision binary64
  (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))