?

Average Error: 1.7 → 1.5
Time: 9.6s
Precision: binary64
Cost: 9544

?

\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} t_0 := \frac{x}{y} \cdot z\\ t_1 := \frac{x + 4}{y} - t_0\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+16}:\\ \;\;\;\;\left|\left(4 \cdot \frac{1}{y} + \frac{x}{y}\right) - t_0\right|\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+110}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - z \cdot x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|-\left(\left(\frac{1}{y} \cdot -4 - \frac{x}{y}\right) - \left(-\frac{x}{y}\right) \cdot \left(\frac{x}{y} \cdot \frac{z}{\frac{x}{y}}\right)\right)\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 y) z)) (t_1 (- (/ (+ x 4.0) y) t_0)))
   (if (<= t_1 -5e+16)
     (fabs (- (+ (* 4.0 (/ 1.0 y)) (/ x y)) t_0))
     (if (<= t_1 2e+110)
       (fabs (/ (- (+ x 4.0) (* z x)) y))
       (fabs
        (-
         (-
          (- (* (/ 1.0 y) -4.0) (/ x y))
          (* (- (/ x y)) (* (/ x y) (/ z (/ 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 / y) * z;
	double t_1 = ((x + 4.0) / y) - t_0;
	double tmp;
	if (t_1 <= -5e+16) {
		tmp = fabs((((4.0 * (1.0 / y)) + (x / y)) - t_0));
	} else if (t_1 <= 2e+110) {
		tmp = fabs((((x + 4.0) - (z * x)) / y));
	} else {
		tmp = fabs(-((((1.0 / y) * -4.0) - (x / y)) - (-(x / y) * ((x / y) * (z / (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) :: tmp
    t_0 = (x / y) * z
    t_1 = ((x + 4.0d0) / y) - t_0
    if (t_1 <= (-5d+16)) then
        tmp = abs((((4.0d0 * (1.0d0 / y)) + (x / y)) - t_0))
    else if (t_1 <= 2d+110) then
        tmp = abs((((x + 4.0d0) - (z * x)) / y))
    else
        tmp = abs(-((((1.0d0 / y) * (-4.0d0)) - (x / y)) - (-(x / y) * ((x / y) * (z / (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 / y) * z;
	double t_1 = ((x + 4.0) / y) - t_0;
	double tmp;
	if (t_1 <= -5e+16) {
		tmp = Math.abs((((4.0 * (1.0 / y)) + (x / y)) - t_0));
	} else if (t_1 <= 2e+110) {
		tmp = Math.abs((((x + 4.0) - (z * x)) / y));
	} else {
		tmp = Math.abs(-((((1.0 / y) * -4.0) - (x / y)) - (-(x / y) * ((x / y) * (z / (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 / y) * z
	t_1 = ((x + 4.0) / y) - t_0
	tmp = 0
	if t_1 <= -5e+16:
		tmp = math.fabs((((4.0 * (1.0 / y)) + (x / y)) - t_0))
	elif t_1 <= 2e+110:
		tmp = math.fabs((((x + 4.0) - (z * x)) / y))
	else:
		tmp = math.fabs(-((((1.0 / y) * -4.0) - (x / y)) - (-(x / y) * ((x / y) * (z / (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 / y) * z)
	t_1 = Float64(Float64(Float64(x + 4.0) / y) - t_0)
	tmp = 0.0
	if (t_1 <= -5e+16)
		tmp = abs(Float64(Float64(Float64(4.0 * Float64(1.0 / y)) + Float64(x / y)) - t_0));
	elseif (t_1 <= 2e+110)
		tmp = abs(Float64(Float64(Float64(x + 4.0) - Float64(z * x)) / y));
	else
		tmp = abs(Float64(-Float64(Float64(Float64(Float64(1.0 / y) * -4.0) - Float64(x / y)) - Float64(Float64(-Float64(x / y)) * Float64(Float64(x / y) * Float64(z / Float64(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 / y) * z;
	t_1 = ((x + 4.0) / y) - t_0;
	tmp = 0.0;
	if (t_1 <= -5e+16)
		tmp = abs((((4.0 * (1.0 / y)) + (x / y)) - t_0));
	elseif (t_1 <= 2e+110)
		tmp = abs((((x + 4.0) - (z * x)) / y));
	else
		tmp = abs(-((((1.0 / y) * -4.0) - (x / y)) - (-(x / y) * ((x / y) * (z / (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 / y), $MachinePrecision] * z), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+16], N[Abs[N[(N[(N[(4.0 * N[(1.0 / y), $MachinePrecision]), $MachinePrecision] + N[(x / y), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision], If[LessEqual[t$95$1, 2e+110], N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] - N[(z * x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[(-N[(N[(N[(N[(1.0 / y), $MachinePrecision] * -4.0), $MachinePrecision] - N[(x / y), $MachinePrecision]), $MachinePrecision] - N[((-N[(x / y), $MachinePrecision]) * N[(N[(x / y), $MachinePrecision] * N[(z / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision])], $MachinePrecision]]]]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
t_0 := \frac{x}{y} \cdot z\\
t_1 := \frac{x + 4}{y} - t_0\\
\mathbf{if}\;t_1 \leq -5 \cdot 10^{+16}:\\
\;\;\;\;\left|\left(4 \cdot \frac{1}{y} + \frac{x}{y}\right) - t_0\right|\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+110}:\\
\;\;\;\;\left|\frac{\left(x + 4\right) - z \cdot x}{y}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|-\left(\left(\frac{1}{y} \cdot -4 - \frac{x}{y}\right) - \left(-\frac{x}{y}\right) \cdot \left(\frac{x}{y} \cdot \frac{z}{\frac{x}{y}}\right)\right)\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)) < -5e16

    1. Initial program 0.1

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

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

    if -5e16 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < 2e110

    1. Initial program 3.2

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

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

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

      [Start]0.8

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

      rational_best_oopsla_all_46_json_45_simplify-35 [<=]0.8

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

    if 2e110 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z))

    1. Initial program 0.1

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

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

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

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

      [Start]5.1

      \[ \left|-1 \cdot \left(\left(\frac{1}{y} \cdot -4 - \frac{x}{y}\right) - \left(\frac{x}{y} \cdot \frac{z}{\frac{x}{y}}\right) \cdot \left(-\frac{x}{y}\right)\right)\right| \]

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]5.1

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

      rational_best_oopsla_all_46_json_45_simplify-92 [=>]5.1

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]5.1

      \[ \left|-\left(\left(\frac{1}{y} \cdot -4 - \frac{x}{y}\right) - \color{blue}{\left(-\frac{x}{y}\right) \cdot \left(\frac{x}{y} \cdot \frac{z}{\frac{x}{y}}\right)}\right)\right| \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.5

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

Alternatives

Alternative 1
Error0.5
Cost8648
\[\begin{array}{l} t_0 := \frac{x + 4}{y} - \frac{x}{y} \cdot z\\ t_1 := \left|t_0\right|\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{+16}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+110}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - z \cdot x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error0.5
Cost8648
\[\begin{array}{l} t_0 := \frac{x}{y} \cdot z\\ t_1 := \frac{x + 4}{y} - t_0\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+16}:\\ \;\;\;\;\left|\left(4 \cdot \frac{1}{y} + \frac{x}{y}\right) - t_0\right|\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+110}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - z \cdot x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|t_1\right|\\ \end{array} \]
Alternative 3
Error9.5
Cost7376
\[\begin{array}{l} t_0 := \left|\frac{4}{y}\right|\\ t_1 := \left|\frac{1 - z}{y} \cdot x\right|\\ \mathbf{if}\;x \leq -1.15 \cdot 10^{-15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{-123}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-108}:\\ \;\;\;\;\left|-\frac{z \cdot x}{y}\right|\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{-23}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error13.0
Cost7312
\[\begin{array}{l} t_0 := \left|\frac{4 + x}{y}\right|\\ t_1 := \left|-\frac{z \cdot x}{y}\right|\\ \mathbf{if}\;z \leq -3.8 \cdot 10^{+111}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.65 \cdot 10^{+46}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2600000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.4 \cdot 10^{+96}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error11.8
Cost7312
\[\begin{array}{l} t_0 := \left|\frac{4 + x}{y}\right|\\ t_1 := \left|\left(-\frac{z}{y}\right) \cdot x\right|\\ \mathbf{if}\;z \leq -4.5 \cdot 10^{+114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.02 \cdot 10^{+54}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.9 \cdot 10^{+14}:\\ \;\;\;\;\left|-\frac{z \cdot x}{y}\right|\\ \mathbf{elif}\;z \leq 4.6 \cdot 10^{+96}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error1.0
Cost7240
\[\begin{array}{l} \mathbf{if}\;x \leq -10.5:\\ \;\;\;\;\left|\frac{1 - z}{y} \cdot x\right|\\ \mathbf{elif}\;x \leq 4.2:\\ \;\;\;\;\left|\frac{4 - z \cdot x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\left(\frac{1}{y} - \frac{z}{y}\right) \cdot x\right|\\ \end{array} \]
Alternative 7
Error1.0
Cost7112
\[\begin{array}{l} t_0 := \left|\frac{1 - z}{y} \cdot x\right|\\ \mathbf{if}\;x \leq -9.5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.2:\\ \;\;\;\;\left|\frac{4 - z \cdot x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error2.1
Cost7108
\[\begin{array}{l} \mathbf{if}\;x \leq -7.8 \cdot 10^{+95}:\\ \;\;\;\;\left|\frac{1 - z}{y} \cdot x\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - z \cdot x}{y}\right|\\ \end{array} \]
Alternative 9
Error19.3
Cost6856
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -10.5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error18.4
Cost6720
\[\left|\frac{4 + x}{y}\right| \]
Alternative 11
Error33.2
Cost6592
\[\left|\frac{4}{y}\right| \]

Error

Reproduce?

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