Average Error: 10.8 → 0.7
Time: 13.2s
Precision: binary64
Cost: 7620
\[x + \frac{y \cdot \left(z - t\right)}{a - t} \]
\[\begin{array}{l} t_1 := \frac{y \cdot \left(z - t\right)}{a - t}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(t - z, \frac{y}{t - a}, x\right)\\ \mathbf{elif}\;t_1 \leq 10^{-26}:\\ \;\;\;\;t_1 + x\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z - t}{\frac{a - t}{y}}\\ \end{array} \]
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) (- a t))))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (/ (* y (- z t)) (- a t))))
   (if (<= t_1 (- INFINITY))
     (fma (- t z) (/ y (- t a)) x)
     (if (<= t_1 1e-26) (+ t_1 x) (+ x (/ (- z t) (/ (- a t) y)))))))
double code(double x, double y, double z, double t, double a) {
	return x + ((y * (z - t)) / (a - t));
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = (y * (z - t)) / (a - t);
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = fma((t - z), (y / (t - a)), x);
	} else if (t_1 <= 1e-26) {
		tmp = t_1 + x;
	} else {
		tmp = x + ((z - t) / ((a - t) / y));
	}
	return tmp;
}
function code(x, y, z, t, a)
	return Float64(x + Float64(Float64(y * Float64(z - t)) / Float64(a - t)))
end
function code(x, y, z, t, a)
	t_1 = Float64(Float64(y * Float64(z - t)) / Float64(a - t))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = fma(Float64(t - z), Float64(y / Float64(t - a)), x);
	elseif (t_1 <= 1e-26)
		tmp = Float64(t_1 + x);
	else
		tmp = Float64(x + Float64(Float64(z - t) / Float64(Float64(a - t) / y)));
	end
	return tmp
end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(t - z), $MachinePrecision] * N[(y / N[(t - a), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$1, 1e-26], N[(t$95$1 + x), $MachinePrecision], N[(x + N[(N[(z - t), $MachinePrecision] / N[(N[(a - t), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
x + \frac{y \cdot \left(z - t\right)}{a - t}
\begin{array}{l}
t_1 := \frac{y \cdot \left(z - t\right)}{a - t}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(t - z, \frac{y}{t - a}, x\right)\\

\mathbf{elif}\;t_1 \leq 10^{-26}:\\
\;\;\;\;t_1 + x\\

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


\end{array}

Error

Target

Original10.8
Target1.2
Herbie0.7
\[x + \frac{y}{\frac{a - t}{z - t}} \]

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 y (-.f64 z t)) (-.f64 a t)) < -inf.0

    1. Initial program 64.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(t - z, \frac{y}{t - a}, x\right)} \]
      Proof
      (fma.f64 (-.f64 t z) (/.f64 y (-.f64 t a)) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 (-.f64 t z) (Rewrite<= *-lft-identity_binary64 (*.f64 1 (/.f64 y (-.f64 t a)))) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 (-.f64 t z) (*.f64 (Rewrite<= metadata-eval (/.f64 -1 -1)) (/.f64 y (-.f64 t a))) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 (-.f64 t z) (Rewrite<= times-frac_binary64 (/.f64 (*.f64 -1 y) (*.f64 -1 (-.f64 t a)))) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 (-.f64 t z) (/.f64 (*.f64 -1 y) (Rewrite<= neg-mul-1_binary64 (neg.f64 (-.f64 t a)))) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 (-.f64 t z) (/.f64 (*.f64 -1 y) (Rewrite<= sub0-neg_binary64 (-.f64 0 (-.f64 t a)))) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 (-.f64 t z) (/.f64 (*.f64 -1 y) (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 0 t) a))) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 (-.f64 t z) (/.f64 (*.f64 -1 y) (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 t)) a)) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 (-.f64 t z) (/.f64 (*.f64 -1 y) (Rewrite<= +-commutative_binary64 (+.f64 a (neg.f64 t)))) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 (-.f64 t z) (/.f64 (*.f64 -1 y) (Rewrite<= sub-neg_binary64 (-.f64 a t))) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 (-.f64 t z) (Rewrite<= associate-*r/_binary64 (*.f64 -1 (/.f64 y (-.f64 a t)))) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (-.f64 t z) (*.f64 -1 (/.f64 y (-.f64 a t)))) x)): 2 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (-.f64 t z) -1) (/.f64 y (-.f64 a t)))) x): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 -1 (-.f64 t z))) (/.f64 y (-.f64 a t))) x): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (-.f64 t z))) (/.f64 y (-.f64 a t))) x): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (Rewrite<= sub0-neg_binary64 (-.f64 0 (-.f64 t z))) (/.f64 y (-.f64 a t))) x): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 0 t) z)) (/.f64 y (-.f64 a t))) x): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 t)) z) (/.f64 y (-.f64 a t))) x): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (Rewrite<= +-commutative_binary64 (+.f64 z (neg.f64 t))) (/.f64 y (-.f64 a t))) x): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (Rewrite<= sub-neg_binary64 (-.f64 z t)) (/.f64 y (-.f64 a t))) x): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) x): 50 points increase in error, 15 points decrease in error
      (+.f64 (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 y (-.f64 z t))) (-.f64 a t)) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 x (/.f64 (*.f64 y (-.f64 z t)) (-.f64 a t)))): 0 points increase in error, 0 points decrease in error

    if -inf.0 < (/.f64 (*.f64 y (-.f64 z t)) (-.f64 a t)) < 1e-26

    1. Initial program 0.3

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

    if 1e-26 < (/.f64 (*.f64 y (-.f64 z t)) (-.f64 a t))

    1. Initial program 21.5

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

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

      \[\leadsto x + \color{blue}{\frac{z - t}{\frac{a - t}{y}}} \]
      Proof
      (/.f64 (-.f64 z t) (/.f64 (-.f64 a t) y)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> div-sub_binary64 (-.f64 (/.f64 z (/.f64 (-.f64 a t) y)) (/.f64 t (/.f64 (-.f64 a t) y)))): 1 points increase in error, 3 points decrease in error
      (-.f64 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 z y) (-.f64 a t))) (/.f64 t (/.f64 (-.f64 a t) y))): 42 points increase in error, 27 points decrease in error
      (-.f64 (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 y z)) (-.f64 a t)) (/.f64 t (/.f64 (-.f64 a t) y))): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 (*.f64 y z) (-.f64 a t)) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 t y) (-.f64 a t)))): 49 points increase in error, 25 points decrease in error
      (-.f64 (/.f64 (*.f64 y z) (-.f64 a t)) (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 y t)) (-.f64 a t))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= unsub-neg_binary64 (+.f64 (/.f64 (*.f64 y z) (-.f64 a t)) (neg.f64 (/.f64 (*.f64 y t) (-.f64 a t))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 (*.f64 y z) (-.f64 a t)) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 (*.f64 y t) (-.f64 a t))))): 0 points increase in error, 0 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification0.7

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

Alternatives

Alternative 1
Error0.8
Cost1992
\[\begin{array}{l} t_1 := x + \frac{z - t}{\frac{a - t}{y}}\\ t_2 := \frac{y \cdot \left(z - t\right)}{a - t}\\ \mathbf{if}\;t_2 \leq -1 \cdot 10^{+289}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{-26}:\\ \;\;\;\;t_2 + x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error13.2
Cost840
\[\begin{array}{l} \mathbf{if}\;t \leq -1.2648237186566223 \cdot 10^{-54}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;t \leq 394460682655753.06:\\ \;\;\;\;x + \frac{z - t}{\frac{a}{y}}\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 3
Error9.6
Cost840
\[\begin{array}{l} t_1 := x - y \cdot \frac{t}{a - t}\\ \mathbf{if}\;t \leq -1.1726018152567782 \cdot 10^{-104}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 3.84816900523611 \cdot 10^{-102}:\\ \;\;\;\;x + \frac{z - t}{\frac{a}{y}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error9.6
Cost840
\[\begin{array}{l} t_1 := x - y \cdot \frac{t}{a - t}\\ \mathbf{if}\;t \leq -1.1726018152567782 \cdot 10^{-104}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 3.84816900523611 \cdot 10^{-102}:\\ \;\;\;\;x + \left(z - t\right) \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error18.9
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -1.2648237186566223 \cdot 10^{-54}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;t \leq 394460682655753.06:\\ \;\;\;\;x - \frac{y \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 6
Error14.4
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -1.2648237186566223 \cdot 10^{-54}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;t \leq 5.582685282189044 \cdot 10^{-90}:\\ \;\;\;\;x + z \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 7
Error3.0
Cost704
\[x + \frac{z - t}{\frac{a - t}{y}} \]
Alternative 8
Error19.4
Cost456
\[\begin{array}{l} \mathbf{if}\;t \leq -5.131901334223244 \cdot 10^{-97}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;t \leq 5.582685282189044 \cdot 10^{-90}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 9
Error28.9
Cost64
\[x \]

Error

Reproduce

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

  :herbie-target
  (+ x (/ y (/ (- a t) (- z t))))

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