Average Error: 10.8 → 1.3
Time: 14.6s
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.8
Target1.2
Herbie1.3
\[x + \frac{y}{\frac{z - a}{z - t}} \]

Derivation

  1. Initial program 10.8

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

    \[\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): 67 points increase in error, 15 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.3

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

Alternatives

Alternative 1
Error20.0
Cost1764
\[\begin{array}{l} t_1 := x + \frac{y \cdot t}{a}\\ t_2 := \frac{z - t}{\frac{z - a}{y}}\\ t_3 := x + \frac{y \cdot \left(z - t\right)}{z}\\ \mathbf{if}\;y \leq -1.45 \cdot 10^{+195}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -3.6 \cdot 10^{+142}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;y \leq -1.468242191699485 \cdot 10^{+70}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -5.592445433889699 \cdot 10^{+19}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.5647091667019486 \cdot 10^{-47}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -1.675171770914274 \cdot 10^{-239}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.2739625612022378 \cdot 10^{-75}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 5.1256827197208156 \cdot 10^{+23}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 8.410694832655683 \cdot 10^{+71}:\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error13.8
Cost1496
\[\begin{array}{l} t_1 := x + y \cdot \frac{t}{a}\\ t_2 := y \cdot \frac{z - t}{z - a}\\ t_3 := x + \frac{y}{1 + \frac{t - a}{z}}\\ \mathbf{if}\;x \leq -2.1523843917245985 \cdot 10^{-57}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -2.445666973299253 \cdot 10^{-178}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -3.638177101933542 \cdot 10^{-199}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -7.487818449306402 \cdot 10^{-215}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.701155811685798 \cdot 10^{-133}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.3352479287394619 \cdot 10^{+42}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Error18.8
Cost1372
\[\begin{array}{l} t_1 := x + y \cdot \frac{t}{a}\\ t_2 := \frac{z - t}{\frac{z - a}{y}}\\ \mathbf{if}\;x \leq -1.0355913081853344 \cdot 10^{-47}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;x \leq -3.06611222461086 \cdot 10^{-134}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -3.4041549661255185 \cdot 10^{-214}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.4769794755084367 \cdot 10^{-277}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 9.572352462842168 \cdot 10^{-238}:\\ \;\;\;\;\frac{y \cdot \left(z - t\right)}{z - a}\\ \mathbf{elif}\;x \leq 6.701155811685798 \cdot 10^{-133}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.3352479287394619 \cdot 10^{+42}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 4
Error14.3
Cost844
\[\begin{array}{l} \mathbf{if}\;z \leq -7.157382938518188 \cdot 10^{+78}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq -3.614963905746512 \cdot 10^{-19}:\\ \;\;\;\;x + \frac{y \cdot \left(z - t\right)}{z}\\ \mathbf{elif}\;z \leq 2.1652849903371764 \cdot 10^{+61}:\\ \;\;\;\;x + y \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 5
Error16.2
Cost844
\[\begin{array}{l} \mathbf{if}\;x \leq -1.0355913081853344 \cdot 10^{-47}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;x \leq 6.701155811685798 \cdot 10^{-133}:\\ \;\;\;\;y \cdot \frac{z - t}{z - a}\\ \mathbf{elif}\;x \leq 1.3352479287394619 \cdot 10^{+42}:\\ \;\;\;\;x + y \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 6
Error12.2
Cost840
\[\begin{array}{l} t_1 := x + \left(y - y \cdot \frac{t}{z}\right)\\ \mathbf{if}\;z \leq -3.614963905746512 \cdot 10^{-19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.1652849903371764 \cdot 10^{+61}:\\ \;\;\;\;x + y \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error23.0
Cost716
\[\begin{array}{l} \mathbf{if}\;t \leq -6.5 \cdot 10^{+245}:\\ \;\;\;\;y \cdot \frac{t}{a}\\ \mathbf{elif}\;t \leq 3.9 \cdot 10^{+202}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;t \leq 5 \cdot 10^{+241}:\\ \;\;\;\;\frac{y}{\frac{a}{t}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error14.4
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -3.614963905746512 \cdot 10^{-19}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 2.1652849903371764 \cdot 10^{+61}:\\ \;\;\;\;x + t \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 9
Error14.6
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -3.614963905746512 \cdot 10^{-19}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 2.1652849903371764 \cdot 10^{+61}:\\ \;\;\;\;x + y \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 10
Error1.2
Cost704
\[x + \frac{y}{\frac{z - a}{z - t}} \]
Alternative 11
Error20.2
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -9.805643663235994 \cdot 10^{-47}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 2.1652849903371764 \cdot 10^{+61}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 12
Error27.3
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -1.3517693888480801 \cdot 10^{-235}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.701155811685798 \cdot 10^{-133}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error29.0
Cost64
\[x \]

Error

Reproduce

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