?

Average Accuracy: 97.4% → 99.5%
Time: 11.2s
Precision: binary64
Cost: 7368

?

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

\mathbf{elif}\;x \leq 3 \cdot 10^{-103}:\\
\;\;\;\;\left|t_0 - \frac{x \cdot z}{y}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|t_0 - z \cdot \frac{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 x < -1.9999999999999999e31

    1. Initial program 99.8%

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

      \[\leadsto \color{blue}{\left|\frac{x - \mathsf{fma}\left(x, z, -4\right)}{y}\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/ [=>]84.4

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

      div-sub [<=]84.4

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

      /-rgt-identity [<=]84.4

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

      metadata-eval [<=]84.4

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

      associate-/l* [<=]84.4

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

      *-commutative [=>]84.4

      \[ \left|\frac{\color{blue}{\left(--1\right) \cdot \left(\left(x + 4\right) - x \cdot z\right)}}{y}\right| \]
    3. Taylor expanded in x around inf 84.3%

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

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

      [Start]84.3

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

      associate-/l* [=>]99.6

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

    if -1.9999999999999999e31 < x < 3e-103

    1. Initial program 95.9%

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

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

    if 3e-103 < x

    1. Initial program 99.0%

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

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

Alternatives

Alternative 1
Accuracy68.0%
Cost7512
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|z \cdot \frac{x}{y}\right|\\ \mathbf{if}\;x \leq -5.8 \cdot 10^{+182}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.95 \cdot 10^{+31}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -220000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -0.0095:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{-22}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 5.1 \cdot 10^{+64}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Accuracy67.9%
Cost7512
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{if}\;x \leq -5.8 \cdot 10^{+181}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.35 \cdot 10^{+32}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3200000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -0.012:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.05 \cdot 10^{-22}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{+64}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Accuracy99.5%
Cost7368
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+29}:\\ \;\;\;\;\left|\frac{1 - z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{-103}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x + 4}{y} - z \cdot \frac{x}{y}\right|\\ \end{array} \]
Alternative 4
Accuracy85.8%
Cost7240
\[\begin{array}{l} \mathbf{if}\;x \leq -0.85:\\ \;\;\;\;\left|\frac{1 - z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{-23}:\\ \;\;\;\;\left|\frac{x}{y} + \frac{4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y} - \frac{z}{\frac{y}{x}}\right|\\ \end{array} \]
Alternative 5
Accuracy99.8%
Cost7240
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+32}:\\ \;\;\;\;\left|\frac{1 - z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;x \leq 4 \cdot 10^{+18}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y} - \frac{z}{\frac{y}{x}}\right|\\ \end{array} \]
Alternative 6
Accuracy80.5%
Cost7113
\[\begin{array}{l} \mathbf{if}\;x \leq -0.52 \lor \neg \left(x \leq 1.8 \cdot 10^{-22}\right):\\ \;\;\;\;\left|\frac{x \cdot \left(1 - z\right)}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y} + \frac{4}{y}\right|\\ \end{array} \]
Alternative 7
Accuracy85.8%
Cost7113
\[\begin{array}{l} \mathbf{if}\;x \leq -0.75 \lor \neg \left(x \leq 2.5 \cdot 10^{-22}\right):\\ \;\;\;\;\left|\frac{1 - z}{\frac{y}{x}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y} + \frac{4}{y}\right|\\ \end{array} \]
Alternative 8
Accuracy82.5%
Cost6984
\[\begin{array}{l} \mathbf{if}\;z \leq -6 \cdot 10^{+103}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;z \leq 5.1 \cdot 10^{+74}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \end{array} \]
Alternative 9
Accuracy70.0%
Cost6857
\[\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 10
Accuracy48.7%
Cost6592
\[\frac{4}{\left|y\right|} \]

Error

Reproduce?

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