?

Average Accuracy: 87.8% → 99.3%
Time: 8.7s
Precision: binary64
Cost: 1865

?

\[\frac{x + y}{1 - \frac{y}{z}} \]
\[\begin{array}{l} t_0 := \frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{if}\;t_0 \leq -2 \cdot 10^{-246} \lor \neg \left(t_0 \leq 0\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (+ x y) (- 1.0 (/ y z))))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (+ x y) (- 1.0 (/ y z)))))
   (if (or (<= t_0 -2e-246) (not (<= t_0 0.0))) t_0 (* z (- -1.0 (/ x y))))))
double code(double x, double y, double z) {
	return (x + y) / (1.0 - (y / z));
}
double code(double x, double y, double z) {
	double t_0 = (x + y) / (1.0 - (y / z));
	double tmp;
	if ((t_0 <= -2e-246) || !(t_0 <= 0.0)) {
		tmp = t_0;
	} else {
		tmp = z * (-1.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 = (x + y) / (1.0d0 - (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 + y) / (1.0d0 - (y / z))
    if ((t_0 <= (-2d-246)) .or. (.not. (t_0 <= 0.0d0))) then
        tmp = t_0
    else
        tmp = z * ((-1.0d0) - (x / y))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	return (x + y) / (1.0 - (y / z));
}
public static double code(double x, double y, double z) {
	double t_0 = (x + y) / (1.0 - (y / z));
	double tmp;
	if ((t_0 <= -2e-246) || !(t_0 <= 0.0)) {
		tmp = t_0;
	} else {
		tmp = z * (-1.0 - (x / y));
	}
	return tmp;
}
def code(x, y, z):
	return (x + y) / (1.0 - (y / z))
def code(x, y, z):
	t_0 = (x + y) / (1.0 - (y / z))
	tmp = 0
	if (t_0 <= -2e-246) or not (t_0 <= 0.0):
		tmp = t_0
	else:
		tmp = z * (-1.0 - (x / y))
	return tmp
function code(x, y, z)
	return Float64(Float64(x + y) / Float64(1.0 - Float64(y / z)))
end
function code(x, y, z)
	t_0 = Float64(Float64(x + y) / Float64(1.0 - Float64(y / z)))
	tmp = 0.0
	if ((t_0 <= -2e-246) || !(t_0 <= 0.0))
		tmp = t_0;
	else
		tmp = Float64(z * Float64(-1.0 - Float64(x / y)));
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = (x + y) / (1.0 - (y / z));
end
function tmp_2 = code(x, y, z)
	t_0 = (x + y) / (1.0 - (y / z));
	tmp = 0.0;
	if ((t_0 <= -2e-246) || ~((t_0 <= 0.0)))
		tmp = t_0;
	else
		tmp = z * (-1.0 - (x / y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] / N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] / N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -2e-246], N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision]], t$95$0, N[(z * N[(-1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{x + y}{1 - \frac{y}{z}}
\begin{array}{l}
t_0 := \frac{x + y}{1 - \frac{y}{z}}\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{-246} \lor \neg \left(t_0 \leq 0\right):\\
\;\;\;\;t_0\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original87.8%
Target93.7%
Herbie99.3%
\[\begin{array}{l} \mathbf{if}\;y < -3.7429310762689856 \cdot 10^{+171}:\\ \;\;\;\;\frac{y + x}{-y} \cdot z\\ \mathbf{elif}\;y < 3.5534662456086734 \cdot 10^{+168}:\\ \;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y + x}{-y} \cdot z\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < -1.99999999999999991e-246 or -0.0 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z)))

    1. Initial program 99.9%

      \[\frac{x + y}{1 - \frac{y}{z}} \]

    if -1.99999999999999991e-246 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < -0.0

    1. Initial program 15.8%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Simplified15.8%

      \[\leadsto \color{blue}{\frac{y + x}{1 - \frac{y}{z}}} \]
      Proof

      [Start]15.8

      \[ \frac{x + y}{1 - \frac{y}{z}} \]

      +-commutative [=>]15.8

      \[ \frac{\color{blue}{y + x}}{1 - \frac{y}{z}} \]
    3. Taylor expanded in z around 0 92.4%

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

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

      [Start]92.4

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

      associate-/l* [=>]11.9

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

      associate-*r/ [=>]11.9

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

      neg-mul-1 [<=]11.9

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

      distribute-neg-in [=>]11.9

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

      sub-neg [<=]11.9

      \[ \frac{\color{blue}{\left(-y\right) - x}}{\frac{y}{z}} \]
    5. Taylor expanded in y around 0 95.6%

      \[\leadsto \color{blue}{-1 \cdot z + -1 \cdot \frac{z \cdot x}{y}} \]
    6. Simplified96.1%

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

      [Start]95.6

      \[ -1 \cdot z + -1 \cdot \frac{z \cdot x}{y} \]

      mul-1-neg [=>]95.6

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

      associate-*r/ [<=]96.1

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

      mul-1-neg [=>]96.1

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

      unsub-neg [=>]96.1

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

      mul-1-neg [<=]96.1

      \[ \color{blue}{-1 \cdot z} - z \cdot \frac{x}{y} \]

      *-commutative [=>]96.1

      \[ \color{blue}{z \cdot -1} - z \cdot \frac{x}{y} \]

      distribute-lft-out-- [=>]96.1

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

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

Alternatives

Alternative 1
Accuracy73.2%
Cost1373
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := z \cdot \left(-1 - \frac{x}{y}\right)\\ t_2 := \frac{y}{t_0}\\ \mathbf{if}\;y \leq -1.1 \cdot 10^{+46}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{-59}:\\ \;\;\;\;\frac{x}{t_0}\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{-20}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{+31}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{+56}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{+98} \lor \neg \left(y \leq 2.3 \cdot 10^{+145}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 2
Accuracy73.3%
Cost1373
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;y \leq -3.1 \cdot 10^{+42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{-60}:\\ \;\;\;\;\frac{x}{t_0}\\ \mathbf{elif}\;y \leq 2.85 \cdot 10^{-21}:\\ \;\;\;\;y \cdot \frac{1}{t_0}\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+31}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{+56}:\\ \;\;\;\;\frac{y}{t_0}\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{+98} \lor \neg \left(y \leq 2.3 \cdot 10^{+145}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 3
Accuracy72.7%
Cost978
\[\begin{array}{l} \mathbf{if}\;y \leq -3.4 \cdot 10^{-59} \lor \neg \left(y \leq 1.2 \cdot 10^{-14}\right) \land \left(y \leq 3.2 \cdot 10^{+98} \lor \neg \left(y \leq 2.3 \cdot 10^{+145}\right)\right):\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 4
Accuracy73.2%
Cost977
\[\begin{array}{l} t_0 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;y \leq -2.2 \cdot 10^{+41}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.45 \cdot 10^{-59}:\\ \;\;\;\;\frac{x}{1 - \frac{y}{z}}\\ \mathbf{elif}\;y \leq 2 \cdot 10^{+98} \lor \neg \left(y \leq 2.3 \cdot 10^{+145}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 5
Accuracy65.8%
Cost780
\[\begin{array}{l} \mathbf{if}\;y \leq -1.45 \cdot 10^{+79}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 24.5:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq 1.45 \cdot 10^{+96}:\\ \;\;\;\;\frac{x}{y} \cdot \left(-z\right)\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{+145}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 6
Accuracy67.3%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -4.3 \cdot 10^{+79}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{+145}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 7
Accuracy57.6%
Cost392
\[\begin{array}{l} \mathbf{if}\;y \leq -6.5 \cdot 10^{+50}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{-74}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 8
Accuracy38.2%
Cost328
\[\begin{array}{l} \mathbf{if}\;y \leq -0.032:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 7.4 \cdot 10^{-28}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 9
Accuracy34.6%
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023137 
(FPCore (x y z)
  :name "Graphics.Rendering.Chart.Backend.Diagrams:calcFontMetrics from Chart-diagrams-1.5.1, A"
  :precision binary64

  :herbie-target
  (if (< y -3.7429310762689856e+171) (* (/ (+ y x) (- y)) z) (if (< y 3.5534662456086734e+168) (/ (+ x y) (- 1.0 (/ y z))) (* (/ (+ y x) (- y)) z)))

  (/ (+ x y) (- 1.0 (/ y z))))