?

Average Error: 16.5 → 5.1
Time: 16.2s
Precision: binary64
Cost: 8905

?

\[\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^{-246} \lor \neg \left(t_1 \leq 0\right):\\ \;\;\;\;x + \mathsf{fma}\left(\frac{t - z}{a - t}, y, y\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-246) (not (<= t_1 0.0)))
     (+ x (fma (/ (- t z) (- a t)) y y))
     (- 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-246) || !(t_1 <= 0.0)) {
		tmp = x + fma(((t - z) / (a - t)), y, y);
	} 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-246) || !(t_1 <= 0.0))
		tmp = Float64(x + fma(Float64(Float64(t - z) / Float64(a - t)), y, y));
	else
		tmp = Float64(x - Float64(y / Float64(t / Float64(a - z))));
	end
	return 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-246], N[Not[LessEqual[t$95$1, 0.0]], $MachinePrecision]], N[(x + N[(N[(N[(t - z), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision] * y + y), $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^{-246} \lor \neg \left(t_1 \leq 0\right):\\
\;\;\;\;x + \mathsf{fma}\left(\frac{t - z}{a - t}, y, y\right)\\

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


\end{array}

Error?

Target

Original16.5
Target8.5
Herbie5.1
\[\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.99999999999999991e-246 or 0.0 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t)))

    1. Initial program 12.8

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

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

      [Start]12.8

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

      associate--l+ [=>]12.7

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

      sub-neg [=>]12.7

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

      +-commutative [=>]12.7

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

      neg-mul-1 [=>]12.7

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

      associate-*l/ [<=]5.4

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

      associate-*r* [=>]5.4

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

      fma-def [=>]5.4

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

      mul-1-neg [=>]5.4

      \[ x + \mathsf{fma}\left(\color{blue}{-\frac{z - t}{a - t}}, y, y\right) \]

      neg-sub0 [=>]5.4

      \[ x + \mathsf{fma}\left(\color{blue}{0 - \frac{z - t}{a - t}}, y, y\right) \]

      div-sub [=>]5.4

      \[ x + \mathsf{fma}\left(0 - \color{blue}{\left(\frac{z}{a - t} - \frac{t}{a - t}\right)}, y, y\right) \]

      associate--r- [=>]5.4

      \[ x + \mathsf{fma}\left(\color{blue}{\left(0 - \frac{z}{a - t}\right) + \frac{t}{a - t}}, y, y\right) \]

      neg-sub0 [<=]5.4

      \[ x + \mathsf{fma}\left(\color{blue}{\left(-\frac{z}{a - t}\right)} + \frac{t}{a - t}, y, y\right) \]

      +-commutative [=>]5.4

      \[ x + \mathsf{fma}\left(\color{blue}{\frac{t}{a - t} + \left(-\frac{z}{a - t}\right)}, y, y\right) \]

      sub-neg [<=]5.4

      \[ x + \mathsf{fma}\left(\color{blue}{\frac{t}{a - t} - \frac{z}{a - t}}, y, y\right) \]

      div-sub [<=]5.4

      \[ x + \mathsf{fma}\left(\color{blue}{\frac{t - z}{a - t}}, y, y\right) \]

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

    1. Initial program 59.0

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

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

      [Start]59.0

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

      associate-/l* [=>]59.4

      \[ \left(x + y\right) - \color{blue}{\frac{z - t}{\frac{a - t}{y}}} \]
    3. Applied egg-rr59.0

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{y \cdot a - y \cdot z}{t} + x} \]
    6. Simplified1.7

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

      [Start]1.7

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

      +-commutative [=>]1.7

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

      mul-1-neg [=>]1.7

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

      unsub-neg [=>]1.7

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

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

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

      associate-/l* [=>]1.7

      \[ x - \color{blue}{\frac{y}{\frac{t}{a - z}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification5.1

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

Alternatives

Alternative 1
Error5.0
Cost2633
\[\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^{-246} \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} \]
Alternative 2
Error8.8
Cost841
\[\begin{array}{l} \mathbf{if}\;a \leq -7.4 \cdot 10^{-10} \lor \neg \left(a \leq 1.85 \cdot 10^{+71}\right):\\ \;\;\;\;\left(x + y\right) - \frac{y}{\frac{a}{z}}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{\frac{t - a}{z}}\\ \end{array} \]
Alternative 3
Error13.1
Cost840
\[\begin{array}{l} \mathbf{if}\;a \leq -4.6 \cdot 10^{-11}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;a \leq 3.9 \cdot 10^{-38}:\\ \;\;\;\;x + \frac{y}{t} \cdot \left(z - a\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 4
Error10.7
Cost840
\[\begin{array}{l} \mathbf{if}\;a \leq -1.15 \cdot 10^{+60}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;a \leq 1.7 \cdot 10^{+143}:\\ \;\;\;\;x + \frac{y}{\frac{t - a}{z}}\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 5
Error14.8
Cost713
\[\begin{array}{l} \mathbf{if}\;a \leq -1.32 \cdot 10^{-14} \lor \neg \left(a \leq 1.75 \cdot 10^{-31}\right):\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y \cdot z}{t}\\ \end{array} \]
Alternative 6
Error19.8
Cost456
\[\begin{array}{l} \mathbf{if}\;a \leq -1.48 \cdot 10^{-36}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;a \leq 1.3 \cdot 10^{-94}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 7
Error28.8
Cost64
\[x \]

Error

Reproduce?

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