Average Error: 10.9 → 1.5
Time: 9.9s
Precision: binary64
Cost: 6976
\[x + \frac{y \cdot \left(z - t\right)}{z - a} \]
\[\mathsf{fma}\left(y, \frac{z - t}{z - a}, x\right) \]
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) (- z a))))
(FPCore (x y z t a) :precision binary64 (fma y (/ (- z t) (- z a)) x))
double code(double x, double y, double z, double t, double a) {
	return x + ((y * (z - t)) / (z - a));
}
double code(double x, double y, double z, double t, double a) {
	return fma(y, ((z - t) / (z - a)), x);
}
function code(x, y, z, t, a)
	return Float64(x + Float64(Float64(y * Float64(z - t)) / Float64(z - a)))
end
function code(x, y, z, t, a)
	return fma(y, Float64(Float64(z - t) / Float64(z - a)), x)
end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := N[(y * N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
x + \frac{y \cdot \left(z - t\right)}{z - a}
\mathsf{fma}\left(y, \frac{z - t}{z - a}, x\right)

Error

Target

Original10.9
Target1.3
Herbie1.5
\[x + \frac{y}{\frac{z - a}{z - t}} \]

Derivation

  1. Initial program 10.9

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{z - t}{z - a}, x\right)} \]
    Proof
    (fma.f64 y (/.f64 (-.f64 z t) (-.f64 z a)) x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (/.f64 (-.f64 z t) (-.f64 z a))) x)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 y (-.f64 z t)) (-.f64 z a))) x): 52 points increase in error, 11 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 x (/.f64 (*.f64 y (-.f64 z t)) (-.f64 z a)))): 0 points increase in error, 0 points decrease in error
  3. Final simplification1.5

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

Alternatives

Alternative 1
Error11.7
Cost1104
\[\begin{array}{l} t_1 := x + \frac{y}{\frac{z}{z - t}}\\ \mathbf{if}\;z \leq -7.363152803005468 \cdot 10^{+54}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -5.861992670048382 \cdot 10^{-87}:\\ \;\;\;\;x + z \cdot \frac{y}{z - a}\\ \mathbf{elif}\;z \leq -1.4537157758165616 \cdot 10^{-92}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.9889007285943366 \cdot 10^{-28}:\\ \;\;\;\;x + \frac{y \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(1 - \frac{t}{z}\right)\\ \end{array} \]
Alternative 2
Error2.8
Cost968
\[\begin{array}{l} \mathbf{if}\;z \leq -8.51037057805889 \cdot 10^{+224}:\\ \;\;\;\;x + \frac{y}{\frac{z}{z - t}}\\ \mathbf{elif}\;z \leq 3.6278388581804327 \cdot 10^{+163}:\\ \;\;\;\;x + \left(z - t\right) \cdot \frac{y}{z - a}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(1 - \frac{t}{z}\right)\\ \end{array} \]
Alternative 3
Error12.0
Cost840
\[\begin{array}{l} t_1 := x + \frac{y}{\frac{z}{z - t}}\\ \mathbf{if}\;z \leq -1.4537157758165616 \cdot 10^{-92}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.9889007285943366 \cdot 10^{-28}:\\ \;\;\;\;x + \frac{y \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error12.0
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1.4537157758165616 \cdot 10^{-92}:\\ \;\;\;\;x + \frac{y}{\frac{z}{z - t}}\\ \mathbf{elif}\;z \leq 1.9889007285943366 \cdot 10^{-28}:\\ \;\;\;\;x + \frac{y \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(1 - \frac{t}{z}\right)\\ \end{array} \]
Alternative 5
Error9.5
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -39.86208699718609:\\ \;\;\;\;x + \frac{y}{\frac{z}{z - t}}\\ \mathbf{elif}\;z \leq 1.9889007285943366 \cdot 10^{-28}:\\ \;\;\;\;x - \frac{y \cdot t}{z - a}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(1 - \frac{t}{z}\right)\\ \end{array} \]
Alternative 6
Error19.2
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -39.86208699718609:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 4.955094425600251 \cdot 10^{-32}:\\ \;\;\;\;x - y \cdot \frac{z}{a}\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 7
Error14.1
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -1.0497235172700611 \cdot 10^{-35}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 1.2110648219911614 \cdot 10^{-27}:\\ \;\;\;\;x + \frac{y}{\frac{a}{t}}\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 8
Error14.8
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -1.0497235172700611 \cdot 10^{-35}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 1.2110648219911614 \cdot 10^{-27}:\\ \;\;\;\;x + \frac{y \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 9
Error1.3
Cost704
\[x + \frac{y}{\frac{z - a}{z - t}} \]
Alternative 10
Error20.1
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -4.5 \cdot 10^{-203}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 2.2153459185548576 \cdot 10^{-92}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 11
Error27.0
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1622934199125395 \cdot 10^{-178}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 9.749632623831724 \cdot 10^{-118}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error51.4
Cost64
\[y \]

Error

Reproduce

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

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

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