?

Average Error: 11.54% → 0.35%
Time: 11.4s
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 -5 \cdot 10^{-279} \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 -5e-279) (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 <= -5e-279) || !(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 <= (-5d-279)) .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 <= -5e-279) || !(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 <= -5e-279) 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 <= -5e-279) || !(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 <= -5e-279) || ~((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, -5e-279], 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 -5 \cdot 10^{-279} \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

Original11.54%
Target6.14%
Herbie0.35%
\[\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.99999999999999969e-279 or 0.0 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z)))

    1. Initial program 0.14

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

    if -4.99999999999999969e-279 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < 0.0

    1. Initial program 90.42

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Simplified90.42

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

      [Start]90.42

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

      +-commutative [=>]90.42

      \[ \frac{\color{blue}{y + x}}{1 - \frac{y}{z}} \]
    3. Applied egg-rr90.44

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

      \[\leadsto \color{blue}{\left(-1 \cdot \frac{z}{y}\right)} \cdot \left(y + x\right) \]
    5. Simplified87.48

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

      [Start]87.48

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

      associate-*r/ [=>]87.48

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

      mul-1-neg [=>]87.48

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

      \[\leadsto \color{blue}{-1 \cdot \frac{\left(y + x\right) \cdot z}{y}} \]
    7. Simplified1.78

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

      [Start]3.24

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

      *-commutative [=>]3.24

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

      associate-*l/ [<=]87.48

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

      distribute-lft-in [=>]87.48

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

      associate-/r/ [<=]74.06

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

      associate-/l* [<=]74.05

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

      *-commutative [=>]74.05

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

      associate-*l/ [<=]74.06

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

      *-commutative [<=]74.06

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

      associate-*r/ [=>]3.26

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

      associate-*l/ [<=]1.77

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

      *-inverses [=>]1.77

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

      *-lft-identity [=>]1.77

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

      distribute-lft-out [<=]1.77

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

      mul-1-neg [=>]1.77

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

      unsub-neg [=>]1.77

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

      distribute-rgt-out-- [=>]1.78

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \leq -5 \cdot 10^{-279} \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
Error30.15%
Cost1242
\[\begin{array}{l} \mathbf{if}\;z \leq -1.7 \cdot 10^{+67}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -1.22 \cdot 10^{+29} \lor \neg \left(z \leq -1.05 \cdot 10^{-22}\right) \land \left(z \leq 2.3 \cdot 10^{-121} \lor \neg \left(z \leq 1.35 \cdot 10^{-30}\right) \land z \leq 1.7 \cdot 10^{+75}\right):\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 2
Error29.92%
Cost1241
\[\begin{array}{l} t_0 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;z \leq -3.1 \cdot 10^{+67}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -4.6 \cdot 10^{+48}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{-20}:\\ \;\;\;\;\frac{x}{1 - \frac{y}{z}}\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{-121} \lor \neg \left(z \leq 3.8 \cdot 10^{-31}\right) \land z \leq 2.75 \cdot 10^{+75}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 3
Error29.68%
Cost1240
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{x}{t_0}\\ t_2 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;z \leq -9.5 \cdot 10^{+66}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -4.6 \cdot 10^{+46}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.6 \cdot 10^{-19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-121}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{-49}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 8 \cdot 10^{+85}:\\ \;\;\;\;\frac{y}{t_0}\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 4
Error29.43%
Cost1240
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{x}{t_0}\\ \mathbf{if}\;z \leq -2.2 \cdot 10^{+67}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -1.6 \cdot 10^{+46}:\\ \;\;\;\;\left(x + y\right) \cdot \frac{-z}{y}\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-21}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{-121}:\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{elif}\;z \leq 2.8 \cdot 10^{-42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.82 \cdot 10^{+84}:\\ \;\;\;\;\frac{y}{t_0}\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 5
Error29.41%
Cost1240
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{x}{t_0}\\ \mathbf{if}\;z \leq -3.1 \cdot 10^{+67}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -1.95 \cdot 10^{+46}:\\ \;\;\;\;\left(x + y\right) \cdot \frac{-z}{y}\\ \mathbf{elif}\;z \leq -6.5 \cdot 10^{-19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-121}:\\ \;\;\;\;\frac{z}{\frac{-y}{x + y}}\\ \mathbf{elif}\;z \leq 1.05 \cdot 10^{-48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{+84}:\\ \;\;\;\;\frac{y}{t_0}\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 6
Error33.21%
Cost780
\[\begin{array}{l} \mathbf{if}\;y \leq -9.8 \cdot 10^{+128}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{+75}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+141}:\\ \;\;\;\;z \cdot \frac{-x}{y}\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 7
Error33.24%
Cost780
\[\begin{array}{l} \mathbf{if}\;y \leq -4.6 \cdot 10^{+129}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 1.02 \cdot 10^{+75}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+141}:\\ \;\;\;\;\frac{-z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 8
Error43.63%
Cost656
\[\begin{array}{l} \mathbf{if}\;y \leq -1.15 \cdot 10^{-7}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 2.4 \cdot 10^{-149}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{-32}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 1.75 \cdot 10^{+74}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 9
Error32.83%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -5.1 \cdot 10^{+129}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 3 \cdot 10^{+149}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 10
Error59.09%
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -2.7 \cdot 10^{-73}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{-106}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error65.05%
Cost64
\[x \]

Error

Reproduce?

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