?

Average Accuracy: 88.4% → 99.9%
Time: 10.1s
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 -4 \cdot 10^{-293} \lor \neg \left(t_0 \leq 0\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left(-z\right) - \frac{z}{\frac{y}{x}}\\ \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 -4e-293) (not (<= t_0 0.0))) t_0 (- (- z) (/ z (/ y x))))))
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 <= -4e-293) || !(t_0 <= 0.0)) {
		tmp = t_0;
	} else {
		tmp = -z - (z / (y / x));
	}
	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 <= (-4d-293)) .or. (.not. (t_0 <= 0.0d0))) then
        tmp = t_0
    else
        tmp = -z - (z / (y / x))
    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 <= -4e-293) || !(t_0 <= 0.0)) {
		tmp = t_0;
	} else {
		tmp = -z - (z / (y / x));
	}
	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 <= -4e-293) or not (t_0 <= 0.0):
		tmp = t_0
	else:
		tmp = -z - (z / (y / x))
	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 <= -4e-293) || !(t_0 <= 0.0))
		tmp = t_0;
	else
		tmp = Float64(Float64(-z) - Float64(z / Float64(y / x)));
	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 <= -4e-293) || ~((t_0 <= 0.0)))
		tmp = t_0;
	else
		tmp = -z - (z / (y / x));
	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, -4e-293], N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision]], t$95$0, N[((-z) - N[(z / N[(y / x), $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 -4 \cdot 10^{-293} \lor \neg \left(t_0 \leq 0\right):\\
\;\;\;\;t_0\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original88.4%
Target94.0%
Herbie99.9%
\[\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))) < -4.0000000000000002e-293 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 -4.0000000000000002e-293 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < 0.0

    1. Initial program 8.0%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in z around 0 98.3%

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

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

      [Start]98.3

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

      mul-1-neg [=>]98.3

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

      associate-/l* [=>]7.9

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

      +-commutative [<=]7.9

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

      associate-/r/ [=>]99.8

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

      distribute-rgt-neg-in [=>]99.8

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

      +-commutative [=>]99.8

      \[ \frac{\color{blue}{y + x}}{y} \cdot \left(-z\right) \]
    4. Taylor expanded in y around 0 99.7%

      \[\leadsto \color{blue}{-1 \cdot z + -1 \cdot \frac{z \cdot x}{y}} \]
    5. Simplified99.8%

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

      [Start]99.7

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

      +-commutative [=>]99.7

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

      mul-1-neg [=>]99.7

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

      unsub-neg [=>]99.7

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

      mul-1-neg [=>]99.7

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

      associate-/l* [=>]99.8

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

      distribute-neg-frac [=>]99.8

      \[ \color{blue}{\frac{-z}{\frac{y}{x}}} - z \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.9%

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

Alternatives

Alternative 1
Accuracy69.9%
Cost1304
\[\begin{array}{l} t_0 := \frac{x}{1 - \frac{y}{z}}\\ t_1 := \frac{z \cdot \left(\left(-y\right) - x\right)}{y}\\ \mathbf{if}\;y \leq -5.6 \cdot 10^{+163}:\\ \;\;\;\;z \cdot \left(-1 - \frac{z}{y}\right)\\ \mathbf{elif}\;y \leq -8.5 \cdot 10^{+37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.22 \cdot 10^{-138}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq -2.7 \cdot 10^{-233}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.02 \cdot 10^{-198}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq 3.9 \cdot 10^{+25}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Accuracy69.6%
Cost1240
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{x}{t_0}\\ \mathbf{if}\;y \leq -1.42 \cdot 10^{+40}:\\ \;\;\;\;z \cdot \left(-1 - \frac{z}{y}\right)\\ \mathbf{elif}\;y \leq -2.6 \cdot 10^{-137}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq -2 \cdot 10^{-227}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 6.8 \cdot 10^{-205}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq 8.4 \cdot 10^{-42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.45 \cdot 10^{+156}:\\ \;\;\;\;\frac{y}{t_0}\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 3
Accuracy74.6%
Cost1172
\[\begin{array}{l} t_0 := \frac{x}{1 - \frac{y}{z}}\\ t_1 := z \cdot \frac{\left(-y\right) - x}{y}\\ \mathbf{if}\;y \leq -4.9 \cdot 10^{+36}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.4 \cdot 10^{-138}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq -1.02 \cdot 10^{-232}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 7 \cdot 10^{-202}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{+31}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Accuracy74.6%
Cost1172
\[\begin{array}{l} t_0 := \frac{x}{1 - \frac{y}{z}}\\ \mathbf{if}\;y \leq -2.1 \cdot 10^{+35}:\\ \;\;\;\;z \cdot \frac{\left(-y\right) - x}{y}\\ \mathbf{elif}\;y \leq -4.5 \cdot 10^{-138}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq -8.6 \cdot 10^{-230}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.05 \cdot 10^{-207}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq 1.88 \cdot 10^{+28}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left(-z\right) - \frac{z}{\frac{y}{x}}\\ \end{array} \]
Alternative 5
Accuracy68.5%
Cost1108
\[\begin{array}{l} t_0 := \frac{x}{1 - \frac{y}{z}}\\ \mathbf{if}\;y \leq -2.6 \cdot 10^{+40}:\\ \;\;\;\;z \cdot \left(-1 - \frac{z}{y}\right)\\ \mathbf{elif}\;y \leq -2.6 \cdot 10^{-138}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{-226}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 6.5 \cdot 10^{-204}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq 2.1 \cdot 10^{+76}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 6
Accuracy68.1%
Cost580
\[\begin{array}{l} \mathbf{if}\;y \leq -1.2 \cdot 10^{+37}:\\ \;\;\;\;z \cdot \left(-1 - \frac{z}{y}\right)\\ \mathbf{elif}\;y \leq 5.2 \cdot 10^{+31}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 7
Accuracy68.2%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -8 \cdot 10^{+35}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 3.1 \cdot 10^{+35}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 8
Accuracy57.9%
Cost392
\[\begin{array}{l} \mathbf{if}\;y \leq -5.9 \cdot 10^{+35}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 2.4 \cdot 10^{-39}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 9
Accuracy40.5%
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1 \cdot 10^{-106}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-231}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Accuracy34.6%
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023151 
(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))))