?

Average Accuracy: 97.7% → 99.0%
Time: 11.1s
Precision: binary64
Cost: 7241

?

\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{+48} \lor \neg \left(x \leq 3.2 \cdot 10^{-5}\right):\\ \;\;\;\;\left|\frac{x}{y} \cdot \left(z + -1\right)\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array} \]
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -5e+48) (not (<= x 3.2e-5)))
   (fabs (* (/ x y) (+ z -1.0)))
   (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 <= -5e+48) || !(x <= 3.2e-5)) {
		tmp = fabs(((x / y) * (z + -1.0)));
	} 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 <= (-5d+48)) .or. (.not. (x <= 3.2d-5))) then
        tmp = abs(((x / y) * (z + (-1.0d0))))
    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 <= -5e+48) || !(x <= 3.2e-5)) {
		tmp = Math.abs(((x / y) * (z + -1.0)));
	} 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 <= -5e+48) or not (x <= 3.2e-5):
		tmp = math.fabs(((x / y) * (z + -1.0)))
	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 <= -5e+48) || !(x <= 3.2e-5))
		tmp = abs(Float64(Float64(x / y) * Float64(z + -1.0)));
	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 <= -5e+48) || ~((x <= 3.2e-5)))
		tmp = abs(((x / y) * (z + -1.0)));
	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, -5e+48], N[Not[LessEqual[x, 3.2e-5]], $MachinePrecision]], N[Abs[N[(N[(x / y), $MachinePrecision] * N[(z + -1.0), $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 -5 \cdot 10^{+48} \lor \neg \left(x \leq 3.2 \cdot 10^{-5}\right):\\
\;\;\;\;\left|\frac{x}{y} \cdot \left(z + -1\right)\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 2 regimes
  2. if x < -4.99999999999999973e48 or 3.19999999999999986e-5 < x

    1. Initial program 99.8%

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

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

      [Start]99.8

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

      fabs-sub [=>]99.8

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

      associate-*l/ [=>]85.9

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

      *-commutative [=>]85.9

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

      associate-*l/ [<=]99.8

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

      *-commutative [=>]99.8

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

      fma-neg [=>]99.8

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

      distribute-neg-frac [=>]99.8

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

      +-commutative [=>]99.8

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

      distribute-neg-in [=>]99.8

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

      unsub-neg [=>]99.8

      \[ \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{\color{blue}{\left(-4\right) - x}}{y}\right)\right| \]

      metadata-eval [=>]99.8

      \[ \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{\color{blue}{-4} - x}{y}\right)\right| \]
    3. Taylor expanded in x around inf 97.6%

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

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

      [Start]97.6

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

      *-commutative [=>]97.6

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

      sub-neg [=>]97.6

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

      +-commutative [=>]97.6

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

      distribute-rgt-out [<=]97.6

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

      distribute-neg-frac [=>]97.6

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

      metadata-eval [=>]97.6

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

      associate-*l/ [=>]97.9

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

      associate-*r/ [<=]97.9

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

      *-commutative [=>]97.9

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

      *-commutative [<=]97.9

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

      associate-*r/ [=>]84.0

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

      associate-/l* [=>]97.9

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

      associate-/r/ [=>]97.9

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

      distribute-lft-out [=>]97.9

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

    if -4.99999999999999973e48 < x < 3.19999999999999986e-5

    1. Initial program 96.5%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Applied egg-rr99.6%

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

      [Start]96.5

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

      associate-*l/ [=>]99.6

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

      sub-div [=>]99.6

      \[ \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.0%

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

Alternatives

Alternative 1
Accuracy69.9%
Cost7248
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|x \cdot \frac{z}{y}\right|\\ \mathbf{if}\;x \leq -6.2 \cdot 10^{+126}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -2.65 \cdot 10^{-8}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-11}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 1.32 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Accuracy69.9%
Cost7248
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|\frac{x}{y} \cdot z\right|\\ \mathbf{if}\;x \leq -1.86 \cdot 10^{+124}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -2.4 \cdot 10^{-9}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{-10}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 2 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Accuracy69.9%
Cost7248
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -2.6 \cdot 10^{+124}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.35 \cdot 10^{-9}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;x \leq 5.7 \cdot 10^{-8}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 6.9 \cdot 10^{+28}:\\ \;\;\;\;\left|\frac{x}{y} \cdot z\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Accuracy86.5%
Cost7113
\[\begin{array}{l} \mathbf{if}\;x \leq -1.6 \cdot 10^{-9} \lor \neg \left(x \leq 7 \cdot 10^{-7}\right):\\ \;\;\;\;\left|\frac{x}{y} \cdot \left(z + -1\right)\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \end{array} \]
Alternative 5
Accuracy97.7%
Cost7104
\[\left|\frac{x}{y} \cdot z - \frac{x + 4}{y}\right| \]
Alternative 6
Accuracy81.6%
Cost6984
\[\begin{array}{l} \mathbf{if}\;z \leq -5 \cdot 10^{+98}:\\ \;\;\;\;\left|\frac{x}{y} \cdot z\right|\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{+122}:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \end{array} \]
Alternative 7
Accuracy70.8%
Cost6857
\[\begin{array}{l} \mathbf{if}\;x \leq -10.5 \lor \neg \left(x \leq 4\right):\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \end{array} \]
Alternative 8
Accuracy49.5%
Cost6592
\[\left|\frac{4}{y}\right| \]

Error

Reproduce?

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