?

Average Error: 16.0 → 3.4
Time: 22.0s
Precision: binary64
Cost: 2888

?

\[\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} \]
\[\begin{array}{l} t_1 := y \cdot \left(\left(1 + \frac{t}{a - t}\right) - \frac{z}{a - t}\right) + x\\ t_2 := \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{-249}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;y \cdot \left(\frac{z}{t} - \frac{a}{t}\right) + x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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 (+ (* y (- (+ 1.0 (/ t (- a t))) (/ z (- a t)))) x))
        (t_2 (- (+ x y) (/ (* (- z t) y) (- a t)))))
   (if (<= t_2 -2e-249)
     t_1
     (if (<= t_2 0.0) (+ (* y (- (/ z t) (/ a t))) x) t_1))))
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 = (y * ((1.0 + (t / (a - t))) - (z / (a - t)))) + x;
	double t_2 = (x + y) - (((z - t) * y) / (a - t));
	double tmp;
	if (t_2 <= -2e-249) {
		tmp = t_1;
	} else if (t_2 <= 0.0) {
		tmp = (y * ((z / t) - (a / t))) + x;
	} else {
		tmp = t_1;
	}
	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) :: t_2
    real(8) :: tmp
    t_1 = (y * ((1.0d0 + (t / (a - t))) - (z / (a - t)))) + x
    t_2 = (x + y) - (((z - t) * y) / (a - t))
    if (t_2 <= (-2d-249)) then
        tmp = t_1
    else if (t_2 <= 0.0d0) then
        tmp = (y * ((z / t) - (a / t))) + x
    else
        tmp = t_1
    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 = (y * ((1.0 + (t / (a - t))) - (z / (a - t)))) + x;
	double t_2 = (x + y) - (((z - t) * y) / (a - t));
	double tmp;
	if (t_2 <= -2e-249) {
		tmp = t_1;
	} else if (t_2 <= 0.0) {
		tmp = (y * ((z / t) - (a / t))) + x;
	} else {
		tmp = t_1;
	}
	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 = (y * ((1.0 + (t / (a - t))) - (z / (a - t)))) + x
	t_2 = (x + y) - (((z - t) * y) / (a - t))
	tmp = 0
	if t_2 <= -2e-249:
		tmp = t_1
	elif t_2 <= 0.0:
		tmp = (y * ((z / t) - (a / t))) + x
	else:
		tmp = t_1
	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(y * Float64(Float64(1.0 + Float64(t / Float64(a - t))) - Float64(z / Float64(a - t)))) + x)
	t_2 = Float64(Float64(x + y) - Float64(Float64(Float64(z - t) * y) / Float64(a - t)))
	tmp = 0.0
	if (t_2 <= -2e-249)
		tmp = t_1;
	elseif (t_2 <= 0.0)
		tmp = Float64(Float64(y * Float64(Float64(z / t) - Float64(a / t))) + x);
	else
		tmp = t_1;
	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 = (y * ((1.0 + (t / (a - t))) - (z / (a - t)))) + x;
	t_2 = (x + y) - (((z - t) * y) / (a - t));
	tmp = 0.0;
	if (t_2 <= -2e-249)
		tmp = t_1;
	elseif (t_2 <= 0.0)
		tmp = (y * ((z / t) - (a / t))) + x;
	else
		tmp = t_1;
	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[(y * N[(N[(1.0 + N[(t / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(z / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x + y), $MachinePrecision] - N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -2e-249], t$95$1, If[LessEqual[t$95$2, 0.0], N[(N[(y * N[(N[(z / t), $MachinePrecision] - N[(a / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]]
\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\begin{array}{l}
t_1 := y \cdot \left(\left(1 + \frac{t}{a - t}\right) - \frac{z}{a - t}\right) + x\\
t_2 := \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}\\
\mathbf{if}\;t_2 \leq -2 \cdot 10^{-249}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;y \cdot \left(\frac{z}{t} - \frac{a}{t}\right) + x\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original16.0
Target8.3
Herbie3.4
\[\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))) < -2.00000000000000011e-249 or 0.0 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t)))

    1. Initial program 12.4

      \[\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} \]
    2. Taylor expanded in y around 0 3.5

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

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

    1. Initial program 58.5

      \[\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} \]
    2. Taylor expanded in y around 0 19.8

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

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

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

      [Start]2.4

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

      rational.json-simplify-2 [=>]2.4

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

      rational.json-simplify-9 [=>]2.4

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

      \[\leadsto \color{blue}{y \cdot \left(\frac{z}{t} - \frac{a}{t}\right) + x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification3.4

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

Alternatives

Alternative 1
Error5.4
Cost4432
\[\begin{array}{l} t_1 := x - y \cdot \frac{z}{a - t}\\ t_2 := \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq -5 \cdot 10^{-173}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;y \cdot \left(\frac{z}{t} - \frac{a}{t}\right) + x\\ \mathbf{elif}\;t_2 \leq 4 \cdot 10^{+300}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error5.1
Cost2696
\[\begin{array}{l} t_1 := x + y \cdot \left(1 + \left(-\frac{z - t}{a - t}\right)\right)\\ t_2 := \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{-249}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;y \cdot \left(\frac{z}{t} - \frac{a}{t}\right) + x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error13.6
Cost1104
\[\begin{array}{l} t_1 := y \cdot \left(1 - \frac{z}{a}\right) + x\\ t_2 := x - y \cdot \left(-\frac{z}{t}\right)\\ \mathbf{if}\;t \leq -1.5 \cdot 10^{+81}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -5 \cdot 10^{-58}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -8.5 \cdot 10^{-78}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 2.15 \cdot 10^{-16}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error10.1
Cost1104
\[\begin{array}{l} t_1 := x - y \cdot \frac{z}{a - t}\\ t_2 := y \cdot \left(1 - \frac{z}{a}\right) + x\\ \mathbf{if}\;a \leq -1.15 \cdot 10^{+114}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -2 \cdot 10^{-98}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -7.8 \cdot 10^{-203}:\\ \;\;\;\;y \cdot \left(\frac{z}{t} - \frac{a}{t}\right) + x\\ \mathbf{elif}\;a \leq 6.2 \cdot 10^{+117}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error14.3
Cost908
\[\begin{array}{l} \mathbf{if}\;a \leq -3.55 \cdot 10^{+93}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;a \leq -2.15 \cdot 10^{+16}:\\ \;\;\;\;x - y \cdot \frac{z}{a}\\ \mathbf{elif}\;a \leq 2.2 \cdot 10^{-18}:\\ \;\;\;\;x - y \cdot \left(-\frac{z}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 6
Error14.9
Cost844
\[\begin{array}{l} \mathbf{if}\;a \leq -5.5 \cdot 10^{+93}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;a \leq -3.55 \cdot 10^{+16}:\\ \;\;\;\;x - y \cdot \frac{z}{a}\\ \mathbf{elif}\;a \leq 3.4 \cdot 10^{-19}:\\ \;\;\;\;\frac{y \cdot z}{t} + x\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 7
Error9.8
Cost840
\[\begin{array}{l} t_1 := y \cdot \left(1 - \frac{z}{a}\right) + x\\ \mathbf{if}\;a \leq -1.15 \cdot 10^{+114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 6.2 \cdot 10^{+117}:\\ \;\;\;\;x - y \cdot \frac{z}{a - t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error30.1
Cost724
\[\begin{array}{l} \mathbf{if}\;a \leq -2.5 \cdot 10^{+168}:\\ \;\;\;\;x\\ \mathbf{elif}\;a \leq -7.2 \cdot 10^{+113}:\\ \;\;\;\;y\\ \mathbf{elif}\;a \leq 8.2 \cdot 10^{+143}:\\ \;\;\;\;x\\ \mathbf{elif}\;a \leq 3.7 \cdot 10^{+179}:\\ \;\;\;\;y\\ \mathbf{elif}\;a \leq 1.75 \cdot 10^{+239}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 9
Error14.9
Cost712
\[\begin{array}{l} \mathbf{if}\;a \leq -3 \cdot 10^{+55}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;a \leq 1.35 \cdot 10^{-17}:\\ \;\;\;\;\frac{y \cdot z}{t} + x\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 10
Error19.7
Cost456
\[\begin{array}{l} \mathbf{if}\;a \leq -3.4 \cdot 10^{+55}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;a \leq 9.5 \cdot 10^{-43}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 11
Error28.7
Cost64
\[x \]

Error

Reproduce?

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