Average Error: 16.8 → 4.9
Time: 12.7s
Precision: binary64
Cost: 2633
\[\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} \]
\[\begin{array}{l} t_1 := \left(x + y\right) + \frac{y \cdot \left(t - z\right)}{a - t}\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{-235} \lor \neg \left(t_1 \leq 0\right):\\ \;\;\;\;x + \left(y - \frac{y}{\frac{a - t}{z - t}}\right)\\ \mathbf{else}:\\ \;\;\;\;x - \frac{y}{\frac{t}{a - z}}\\ \end{array} \]
(FPCore (x y z t a) :precision binary64 (- (+ x y) (/ (* (- z t) y) (- a t))))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (+ (+ x y) (/ (* y (- t z)) (- a t)))))
   (if (or (<= t_1 -2e-235) (not (<= t_1 0.0)))
     (+ x (- y (/ y (/ (- a t) (- z t)))))
     (- x (/ y (/ t (- a z)))))))
double code(double x, double y, double z, double t, double a) {
	return (x + y) - (((z - t) * y) / (a - t));
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = (x + y) + ((y * (t - z)) / (a - t));
	double tmp;
	if ((t_1 <= -2e-235) || !(t_1 <= 0.0)) {
		tmp = x + (y - (y / ((a - t) / (z - t))));
	} else {
		tmp = x - (y / (t / (a - z)));
	}
	return tmp;
}
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    code = (x + y) - (((z - t) * y) / (a - t))
end function
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8) :: t_1
    real(8) :: tmp
    t_1 = (x + y) + ((y * (t - z)) / (a - t))
    if ((t_1 <= (-2d-235)) .or. (.not. (t_1 <= 0.0d0))) then
        tmp = x + (y - (y / ((a - t) / (z - t))))
    else
        tmp = x - (y / (t / (a - z)))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
	return (x + y) - (((z - t) * y) / (a - t));
}
public static double code(double x, double y, double z, double t, double a) {
	double t_1 = (x + y) + ((y * (t - z)) / (a - t));
	double tmp;
	if ((t_1 <= -2e-235) || !(t_1 <= 0.0)) {
		tmp = x + (y - (y / ((a - t) / (z - t))));
	} else {
		tmp = x - (y / (t / (a - z)));
	}
	return tmp;
}
def code(x, y, z, t, a):
	return (x + y) - (((z - t) * y) / (a - t))
def code(x, y, z, t, a):
	t_1 = (x + y) + ((y * (t - z)) / (a - t))
	tmp = 0
	if (t_1 <= -2e-235) or not (t_1 <= 0.0):
		tmp = x + (y - (y / ((a - t) / (z - t))))
	else:
		tmp = x - (y / (t / (a - z)))
	return tmp
function code(x, y, z, t, a)
	return Float64(Float64(x + y) - Float64(Float64(Float64(z - t) * y) / Float64(a - t)))
end
function code(x, y, z, t, a)
	t_1 = Float64(Float64(x + y) + Float64(Float64(y * Float64(t - z)) / Float64(a - t)))
	tmp = 0.0
	if ((t_1 <= -2e-235) || !(t_1 <= 0.0))
		tmp = Float64(x + Float64(y - Float64(y / Float64(Float64(a - t) / Float64(z - t)))));
	else
		tmp = Float64(x - Float64(y / Float64(t / Float64(a - z))));
	end
	return tmp
end
function tmp = code(x, y, z, t, a)
	tmp = (x + y) - (((z - t) * y) / (a - t));
end
function tmp_2 = code(x, y, z, t, a)
	t_1 = (x + y) + ((y * (t - z)) / (a - t));
	tmp = 0.0;
	if ((t_1 <= -2e-235) || ~((t_1 <= 0.0)))
		tmp = x + (y - (y / ((a - t) / (z - t))));
	else
		tmp = x - (y / (t / (a - z)));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_] := N[(N[(x + y), $MachinePrecision] - N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(x + y), $MachinePrecision] + N[(N[(y * N[(t - z), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -2e-235], N[Not[LessEqual[t$95$1, 0.0]], $MachinePrecision]], N[(x + N[(y - N[(y / N[(N[(a - t), $MachinePrecision] / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(y / N[(t / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\begin{array}{l}
t_1 := \left(x + y\right) + \frac{y \cdot \left(t - z\right)}{a - t}\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{-235} \lor \neg \left(t_1 \leq 0\right):\\
\;\;\;\;x + \left(y - \frac{y}{\frac{a - t}{z - t}}\right)\\

\mathbf{else}:\\
\;\;\;\;x - \frac{y}{\frac{t}{a - z}}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original16.8
Target8.7
Herbie4.9
\[\begin{array}{l} \mathbf{if}\;\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} < -1.3664970889390727 \cdot 10^{-7}:\\ \;\;\;\;\left(y + x\right) - \left(\left(z - t\right) \cdot \frac{1}{a - t}\right) \cdot y\\ \mathbf{elif}\;\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} < 1.4754293444577233 \cdot 10^{-239}:\\ \;\;\;\;\frac{y \cdot \left(a - z\right) - x \cdot t}{a - t}\\ \mathbf{else}:\\ \;\;\;\;\left(y + x\right) - \left(\left(z - t\right) \cdot \frac{1}{a - t}\right) \cdot y\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < -1.9999999999999999e-235 or 0.0 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t)))

    1. Initial program 13.0

      \[\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} \]
    2. Simplified5.2

      \[\leadsto \color{blue}{x + \left(y - \frac{y}{\frac{a - t}{z - t}}\right)} \]
      Proof
      (+.f64 x (-.f64 y (/.f64 y (/.f64 (-.f64 a t) (-.f64 z t))))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (-.f64 (Rewrite<= +-rgt-identity_binary64 (+.f64 y 0)) (/.f64 y (/.f64 (-.f64 a t) (-.f64 z t))))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (-.f64 (+.f64 y 0) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y (-.f64 z t)) (-.f64 a t))))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (-.f64 (+.f64 y 0) (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 z t) y)) (-.f64 a t)))): 4 points increase in error, 0 points decrease in error
      (Rewrite=> associate-+r-_binary64 (-.f64 (+.f64 x (+.f64 y 0)) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t)))): 0 points increase in error, 4 points decrease in error
      (-.f64 (+.f64 x (Rewrite=> +-rgt-identity_binary64 y)) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))): 0 points increase in error, 0 points decrease in error

    if -1.9999999999999999e-235 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < 0.0

    1. Initial program 58.0

      \[\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} \]
    2. Simplified33.7

      \[\leadsto \color{blue}{x + \left(y - \frac{y}{\frac{a - t}{z - t}}\right)} \]
      Proof
      (+.f64 x (-.f64 y (/.f64 y (/.f64 (-.f64 a t) (-.f64 z t))))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (-.f64 (Rewrite<= +-rgt-identity_binary64 (+.f64 y 0)) (/.f64 y (/.f64 (-.f64 a t) (-.f64 z t))))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (-.f64 (+.f64 y 0) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y (-.f64 z t)) (-.f64 a t))))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (-.f64 (+.f64 y 0) (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 z t) y)) (-.f64 a t)))): 4 points increase in error, 0 points decrease in error
      (Rewrite=> associate-+r-_binary64 (-.f64 (+.f64 x (+.f64 y 0)) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t)))): 0 points increase in error, 4 points decrease in error
      (-.f64 (+.f64 x (Rewrite=> +-rgt-identity_binary64 y)) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in t around inf 1.7

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

      \[\leadsto x + \color{blue}{\frac{\left(-y\right) \cdot \left(a - z\right)}{t}} \]
      Proof
      (+.f64 x (/.f64 (*.f64 (neg.f64 y) (-.f64 a z)) t)): 0 points increase in error, 0 points decrease in error
      (+.f64 x (/.f64 (*.f64 (Rewrite=> neg-mul-1_binary64 (*.f64 -1 y)) (-.f64 a z)) t)): 6 points increase in error, 0 points decrease in error
      (+.f64 x (/.f64 (Rewrite<= associate-*r*_binary64 (*.f64 -1 (*.f64 y (-.f64 a z)))) t)): 0 points increase in error, 6 points decrease in error
      (+.f64 x (/.f64 (*.f64 -1 (Rewrite<= distribute-lft-out--_binary64 (-.f64 (*.f64 y a) (*.f64 y z)))) t)): 0 points increase in error, 6 points decrease in error
      (+.f64 x (/.f64 (Rewrite<= distribute-lft-out--_binary64 (-.f64 (*.f64 -1 (*.f64 y a)) (*.f64 -1 (*.f64 y z)))) t)): 6 points increase in error, 0 points decrease in error
      (+.f64 x (/.f64 (-.f64 (*.f64 -1 (Rewrite=> *-commutative_binary64 (*.f64 a y))) (*.f64 -1 (*.f64 y z))) t)): 0 points increase in error, 0 points decrease in error
    5. Taylor expanded in x around 0 1.7

      \[\leadsto \color{blue}{-1 \cdot \frac{y \cdot \left(a - z\right)}{t} + x} \]
    6. Simplified2.0

      \[\leadsto \color{blue}{x - \frac{y}{\frac{t}{a - z}}} \]
      Proof
      (-.f64 x (/.f64 y (/.f64 t (-.f64 a z)))): 0 points increase in error, 0 points decrease in error
      (-.f64 x (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y (-.f64 a z)) t))): 8 points increase in error, 0 points decrease in error
      (-.f64 x (Rewrite<= associate-*r/_binary64 (*.f64 y (/.f64 (-.f64 a z) t)))): 0 points increase in error, 3 points decrease in error
      (-.f64 x (Rewrite<= *-lft-identity_binary64 (*.f64 1 (*.f64 y (/.f64 (-.f64 a z) t))))): 0 points increase in error, 8 points decrease in error
      (Rewrite=> cancel-sign-sub-inv_binary64 (+.f64 x (*.f64 (neg.f64 1) (*.f64 y (/.f64 (-.f64 a z) t))))): 8 points increase in error, 0 points decrease in error
      (+.f64 x (*.f64 (Rewrite=> metadata-eval -1) (*.f64 y (/.f64 (-.f64 a z) t)))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (*.f64 -1 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 y (-.f64 a z)) t)))): 0 points increase in error, 8 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 (/.f64 (*.f64 y (-.f64 a z)) t)) x)): 0 points increase in error, 0 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification4.9

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

Alternatives

Alternative 1
Error15.6
Cost1368
\[\begin{array}{l} t_1 := x - \frac{y}{\frac{t}{a - z}}\\ \mathbf{if}\;t \leq -7.6 \cdot 10^{+114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.6 \cdot 10^{-160}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;t \leq -3 \cdot 10^{-173}:\\ \;\;\;\;\frac{y \cdot z}{t - a}\\ \mathbf{elif}\;t \leq 3.2 \cdot 10^{-147}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;t \leq 62000:\\ \;\;\;\;x + \frac{y}{\frac{t - a}{z}}\\ \mathbf{elif}\;t \leq 7 \cdot 10^{+105}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error12.6
Cost1104
\[\begin{array}{l} t_1 := x - \frac{y}{\frac{t}{a - z}}\\ \mathbf{if}\;t \leq -3.7 \cdot 10^{+114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 7 \cdot 10^{-145}:\\ \;\;\;\;\left(x + y\right) - \frac{y}{\frac{a}{z}}\\ \mathbf{elif}\;t \leq 45000:\\ \;\;\;\;x + \frac{y}{\frac{t - a}{z}}\\ \mathbf{elif}\;t \leq 9.5 \cdot 10^{+105}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error12.7
Cost1104
\[\begin{array}{l} t_1 := \frac{t}{a - z}\\ \mathbf{if}\;t \leq -1.45 \cdot 10^{+120}:\\ \;\;\;\;x + y \cdot \frac{-1}{t_1}\\ \mathbf{elif}\;t \leq 7 \cdot 10^{-145}:\\ \;\;\;\;\left(x + y\right) - \frac{y}{\frac{a}{z}}\\ \mathbf{elif}\;t \leq 64000000:\\ \;\;\;\;x + \frac{y}{\frac{t - a}{z}}\\ \mathbf{elif}\;t \leq 1.52 \cdot 10^{+106}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;x - \frac{y}{t_1}\\ \end{array} \]
Alternative 4
Error10.8
Cost841
\[\begin{array}{l} \mathbf{if}\;a \leq -9.5 \cdot 10^{+98} \lor \neg \left(a \leq 1.02 \cdot 10^{+77}\right):\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{\frac{t - a}{z}}\\ \end{array} \]
Alternative 5
Error15.5
Cost713
\[\begin{array}{l} \mathbf{if}\;a \leq -2.1 \cdot 10^{-94} \lor \neg \left(a \leq 8.2 \cdot 10^{+30}\right):\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y \cdot z}{t}\\ \end{array} \]
Alternative 6
Error20.5
Cost456
\[\begin{array}{l} \mathbf{if}\;t \leq -4.5 \cdot 10^{+118}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 4 \cdot 10^{+184}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error27.8
Cost328
\[\begin{array}{l} \mathbf{if}\;y \leq -2.05 \cdot 10^{+50}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{+168}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 8
Error29.4
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022343 
(FPCore (x y z t a)
  :name "Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisTick from plot-0.2.3.4, B"
  :precision binary64

  :herbie-target
  (if (< (- (+ x y) (/ (* (- z t) y) (- a t))) -1.3664970889390727e-7) (- (+ y x) (* (* (- z t) (/ 1.0 (- a t))) y)) (if (< (- (+ x y) (/ (* (- z t) y) (- a t))) 1.4754293444577233e-239) (/ (- (* y (- a z)) (* x t)) (- a t)) (- (+ y x) (* (* (- z t) (/ 1.0 (- a t))) y))))

  (- (+ x y) (/ (* (- z t) y) (- a t))))