Average Error: 10.8 → 1.4
Time: 12.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.3
Herbie1.4
\[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.4

    \[\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, 1 points decrease in error
    (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 y (-.f64 z t)) (-.f64 z a))) x): 45 points increase in error, 9 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.4

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

Alternatives

Alternative 1
Error2.6
Cost1992
\[\begin{array}{l} t_1 := y \cdot \frac{z - t}{z - a}\\ t_2 := \frac{y \cdot \left(z - t\right)}{z - a}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{+205}:\\ \;\;\;\;x + t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error11.0
Cost972
\[\begin{array}{l} t_1 := x - \frac{y}{\frac{a}{z - t}}\\ \mathbf{if}\;a \leq -8.787807453946963 \cdot 10^{+32}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 8.003323500230787 \cdot 10^{-96}:\\ \;\;\;\;\left(y + x\right) - y \cdot \frac{t}{z}\\ \mathbf{elif}\;a \leq 2.5367155722615748 \cdot 10^{+137}:\\ \;\;\;\;x + z \cdot \frac{y}{z - a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error11.6
Cost840
\[\begin{array}{l} t_1 := \left(y + x\right) - y \cdot \frac{t}{z}\\ \mathbf{if}\;z \leq -9.796644944149417 \cdot 10^{+20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 0.0004997994754050088:\\ \;\;\;\;x + y \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error11.1
Cost840
\[\begin{array}{l} t_1 := x - \frac{y}{\frac{a}{z - t}}\\ \mathbf{if}\;a \leq -8.787807453946963 \cdot 10^{+32}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 11955071050002.19:\\ \;\;\;\;\left(y + x\right) - y \cdot \frac{t}{z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error1.4
Cost832
\[x + y \cdot \left(\left(z - t\right) \cdot \frac{1}{z - a}\right) \]
Alternative 6
Error18.2
Cost712
\[\begin{array}{l} t_1 := x - z \cdot \frac{y}{a}\\ \mathbf{if}\;a \leq -3.778146315230698 \cdot 10^{+119}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 5.450794290782853 \cdot 10^{+127}:\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error13.9
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -2.552989375547654 \cdot 10^{+23}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 2.4872058519325763 \cdot 10^{+39}:\\ \;\;\;\;x + t \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 8
Error14.7
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -2.552989375547654 \cdot 10^{+23}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 0.0004997994754050088:\\ \;\;\;\;x + \frac{y \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 9
Error14.1
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -2.552989375547654 \cdot 10^{+23}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 2.4872058519325763 \cdot 10^{+39}:\\ \;\;\;\;x + y \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 10
Error19.5
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -3.475726187018565 \cdot 10^{-108}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 3.717830092976928 \cdot 10^{-102}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 11
Error26.5
Cost328
\[\begin{array}{l} \mathbf{if}\;y \leq -1.55 \cdot 10^{+196}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 9 \cdot 10^{+194}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 12
Error28.7
Cost64
\[x \]

Error

Reproduce

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