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

Error

Target

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

Derivation

  1. Initial program 2.1

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(a, \frac{z - y}{\left(t - z\right) + 1}, x\right)} \]
    Proof
    (fma.f64 a (/.f64 (-.f64 z y) (+.f64 (-.f64 t z) 1)) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 a (Rewrite=> div-sub_binary64 (-.f64 (/.f64 z (+.f64 (-.f64 t z) 1)) (/.f64 y (+.f64 (-.f64 t z) 1)))) x): 0 points increase in error, 14 points decrease in error
    (fma.f64 a (Rewrite=> sub-neg_binary64 (+.f64 (/.f64 z (+.f64 (-.f64 t z) 1)) (neg.f64 (/.f64 y (+.f64 (-.f64 t z) 1))))) x): 3 points increase in error, 0 points decrease in error
    (fma.f64 a (Rewrite<= +-commutative_binary64 (+.f64 (neg.f64 (/.f64 y (+.f64 (-.f64 t z) 1))) (/.f64 z (+.f64 (-.f64 t z) 1)))) x): 0 points increase in error, 3 points decrease in error
    (fma.f64 a (+.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 (/.f64 y (+.f64 (-.f64 t z) 1)))) (/.f64 z (+.f64 (-.f64 t z) 1))) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 a (Rewrite<= associate--r-_binary64 (-.f64 0 (-.f64 (/.f64 y (+.f64 (-.f64 t z) 1)) (/.f64 z (+.f64 (-.f64 t z) 1))))) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 a (-.f64 0 (Rewrite<= div-sub_binary64 (/.f64 (-.f64 y z) (+.f64 (-.f64 t z) 1)))) x): 3 points increase in error, 0 points decrease in error
    (fma.f64 a (Rewrite<= neg-sub0_binary64 (neg.f64 (/.f64 (-.f64 y z) (+.f64 (-.f64 t z) 1)))) x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a (neg.f64 (/.f64 (-.f64 y z) (+.f64 (-.f64 t z) 1)))) x)): 3 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (neg.f64 (/.f64 (-.f64 y z) (+.f64 (-.f64 t z) 1))) a)) x): 0 points increase in error, 3 points decrease in error
    (+.f64 (Rewrite<= distribute-lft-neg-in_binary64 (neg.f64 (*.f64 (/.f64 (-.f64 y z) (+.f64 (-.f64 t z) 1)) a))) x): 0 points increase in error, 0 points decrease in error
    (+.f64 (neg.f64 (Rewrite<= associate-/r/_binary64 (/.f64 (-.f64 y z) (/.f64 (+.f64 (-.f64 t z) 1) a)))) x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 x (neg.f64 (/.f64 (-.f64 y z) (/.f64 (+.f64 (-.f64 t z) 1) a))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= sub-neg_binary64 (-.f64 x (/.f64 (-.f64 y z) (/.f64 (+.f64 (-.f64 t z) 1) a)))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.2

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

Alternatives

Alternative 1
Error18.3
Cost1240
\[\begin{array}{l} t_1 := x - a \cdot y\\ t_2 := x - y \cdot \frac{a}{t}\\ \mathbf{if}\;z \leq -2.5 \cdot 10^{-68}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq -4.25 \cdot 10^{-172}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.25 \cdot 10^{-236}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{-186}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 3.1 \cdot 10^{-43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{+100}:\\ \;\;\;\;x + a \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 2
Error6.4
Cost969
\[\begin{array}{l} \mathbf{if}\;z \leq -2.95 \cdot 10^{-31} \lor \neg \left(z \leq 3.3 \cdot 10^{-43}\right):\\ \;\;\;\;x + a \cdot \frac{z}{\left(t - z\right) + 1}\\ \mathbf{else}:\\ \;\;\;\;x - a \cdot \frac{y}{t + 1}\\ \end{array} \]
Alternative 3
Error8.3
Cost968
\[\begin{array}{l} \mathbf{if}\;z \leq -2.2 \cdot 10^{+29}:\\ \;\;\;\;x + \frac{z - y}{\frac{-z}{a}}\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{-43}:\\ \;\;\;\;x - a \cdot \frac{y}{t + 1}\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \frac{a}{\left(t - z\right) + 1}\\ \end{array} \]
Alternative 4
Error6.5
Cost968
\[\begin{array}{l} \mathbf{if}\;t \leq -29000000000000:\\ \;\;\;\;x + \frac{z - y}{\frac{t}{a}}\\ \mathbf{elif}\;t \leq 1.85 \cdot 10^{+39}:\\ \;\;\;\;x + \frac{a}{1 - z} \cdot \left(z - y\right)\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot \frac{z - y}{t}\\ \end{array} \]
Alternative 5
Error6.3
Cost968
\[\begin{array}{l} \mathbf{if}\;t \leq -1.35 \cdot 10^{+15}:\\ \;\;\;\;x + \frac{z - y}{\frac{t}{a}}\\ \mathbf{elif}\;t \leq 1.75 \cdot 10^{+163}:\\ \;\;\;\;x - \frac{a}{\frac{1 - z}{y - z}}\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot \frac{z - y}{t}\\ \end{array} \]
Alternative 6
Error9.1
Cost905
\[\begin{array}{l} \mathbf{if}\;z \leq -3.6 \cdot 10^{+27} \lor \neg \left(z \leq 2.4 \cdot 10^{+69}\right):\\ \;\;\;\;x + \frac{z - y}{\frac{-z}{a}}\\ \mathbf{else}:\\ \;\;\;\;x - a \cdot \frac{y}{t + 1}\\ \end{array} \]
Alternative 7
Error17.2
Cost844
\[\begin{array}{l} \mathbf{if}\;z \leq -1.4 \cdot 10^{-30}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 3.6 \cdot 10^{-43}:\\ \;\;\;\;x - a \cdot y\\ \mathbf{elif}\;z \leq 2.35 \cdot 10^{+75}:\\ \;\;\;\;x + z \cdot \frac{a}{t}\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 8
Error17.5
Cost844
\[\begin{array}{l} \mathbf{if}\;z \leq -1.4 \cdot 10^{-30}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{-44}:\\ \;\;\;\;x - a \cdot y\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{+100}:\\ \;\;\;\;x + a \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 9
Error10.9
Cost844
\[\begin{array}{l} \mathbf{if}\;z \leq -7.5 \cdot 10^{+28}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 3.6 \cdot 10^{-43}:\\ \;\;\;\;x - a \cdot \frac{y}{t + 1}\\ \mathbf{elif}\;z \leq 2.05 \cdot 10^{+101}:\\ \;\;\;\;x + a \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 10
Error0.2
Cost832
\[x + a \cdot \frac{z - y}{\left(t - z\right) + 1} \]
Alternative 11
Error17.0
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -6.5 \cdot 10^{-31}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 2.4 \cdot 10^{+69}:\\ \;\;\;\;x - a \cdot y\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 12
Error19.7
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -1.4 \cdot 10^{-30}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{+78}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 13
Error27.0
Cost392
\[\begin{array}{l} \mathbf{if}\;a \leq -9 \cdot 10^{+240}:\\ \;\;\;\;-a\\ \mathbf{elif}\;a \leq 8.6 \cdot 10^{+103}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-a\\ \end{array} \]
Alternative 14
Error27.8
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022343 
(FPCore (x y z t a)
  :name "Graphics.Rendering.Chart.SparkLine:renderSparkLine from Chart-1.5.3"
  :precision binary64

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

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