Average Error: 2.2 → 0.2
Time: 16.6s
Precision: binary64
Cost: 7104
\[x - \frac{y - z}{\frac{\left(t - z\right) + 1}{a}} \]
\[\mathsf{fma}\left(a, \frac{z - y}{t - \left(z + -1\right)}, 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(t - Float64(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[(t - N[(z + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
x - \frac{y - z}{\frac{\left(t - z\right) + 1}{a}}
\mathsf{fma}\left(a, \frac{z - y}{t - \left(z + -1\right)}, x\right)

Error

Target

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

Derivation

  1. Initial program 2.2

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(a, \frac{z - y}{t - \left(z + -1\right)}, x\right)} \]
    Proof
    (fma.f64 a (/.f64 (-.f64 z y) (-.f64 t (+.f64 z -1))) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 a (/.f64 (-.f64 z y) (-.f64 t (+.f64 z (Rewrite<= metadata-eval (neg.f64 1))))) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 a (/.f64 (-.f64 z y) (-.f64 t (Rewrite<= sub-neg_binary64 (-.f64 z 1)))) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 a (/.f64 (-.f64 z y) (Rewrite<= associate-+l-_binary64 (+.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, 0 points decrease in error
    (fma.f64 a (Rewrite<= unsub-neg_binary64 (+.f64 (/.f64 z (+.f64 (-.f64 t z) 1)) (neg.f64 (/.f64 y (+.f64 (-.f64 t z) 1))))) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 a (+.f64 (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 (/.f64 z (+.f64 (-.f64 t z) 1))))) (neg.f64 (/.f64 y (+.f64 (-.f64 t z) 1)))) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 a (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 (neg.f64 (/.f64 z (+.f64 (-.f64 t z) 1))) (/.f64 y (+.f64 (-.f64 t z) 1))))) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 a (neg.f64 (Rewrite<= +-commutative_binary64 (+.f64 (/.f64 y (+.f64 (-.f64 t z) 1)) (neg.f64 (/.f64 z (+.f64 (-.f64 t z) 1)))))) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 a (neg.f64 (Rewrite<= sub-neg_binary64 (-.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 (neg.f64 (Rewrite<= div-sub_binary64 (/.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)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 a (/.f64 (-.f64 y z) (+.f64 (-.f64 t z) 1))))) x): 0 points increase in error, 0 points decrease in error
    (+.f64 (neg.f64 (Rewrite<= *-commutative_binary64 (*.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): 23 points increase in error, 7 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}{t - \left(z + -1\right)}, x\right) \]

Alternatives

Alternative 1
Error1.0
Cost2376
\[\begin{array}{l} t_1 := \frac{\left(t - z\right) + 1}{a}\\ t_2 := x + \frac{z - y}{t_1}\\ t_3 := \frac{y - z}{t_1}\\ \mathbf{if}\;t_3 \leq -1 \cdot 10^{-170}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_3 \leq 0:\\ \;\;\;\;x + \frac{a}{-1 + \frac{t + 1}{z}}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error21.1
Cost1508
\[\begin{array}{l} t_1 := x - y \cdot \frac{a}{t}\\ t_2 := x - a \cdot y\\ \mathbf{if}\;t \leq -2.454709914489556 \cdot 10^{+149}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.666162980227225 \cdot 10^{+139}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;t \leq -6.498419327007141 \cdot 10^{+38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -9.134096039975174 \cdot 10^{-83}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;t \leq -5.064906445868343 \cdot 10^{-153}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -1.2524615348513967 \cdot 10^{-225}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;t \leq 1.3921102133718983 \cdot 10^{-249}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 5.650080101428107 \cdot 10^{-186}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;t \leq 1.646983507192604 \cdot 10^{-57}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 3
Error16.1
Cost1500
\[\begin{array}{l} t_1 := x + \frac{a}{-1 + \frac{t}{z}}\\ t_2 := x - a \cdot y\\ \mathbf{if}\;t \leq -2.454709914489556 \cdot 10^{+149}:\\ \;\;\;\;x + \frac{a}{t} \cdot \left(z - y\right)\\ \mathbf{elif}\;t \leq -9.134096039975174 \cdot 10^{-83}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -5.064906445868343 \cdot 10^{-153}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -1.2524615348513967 \cdot 10^{-225}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;t \leq 1.3921102133718983 \cdot 10^{-249}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 5.650080101428107 \cdot 10^{-186}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.646983507192604 \cdot 10^{-57}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error13.9
Cost1104
\[\begin{array}{l} t_1 := x - a \cdot y\\ t_2 := x + \frac{a}{-1 + \frac{t}{z}}\\ \mathbf{if}\;z \leq -7.429423602024522 \cdot 10^{-20}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.4250226605247622 \cdot 10^{-174}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.029495770808362 \cdot 10^{-274}:\\ \;\;\;\;x - y \cdot \frac{a}{t}\\ \mathbf{elif}\;z \leq 6.110942629719727 \cdot 10^{-48}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error7.8
Cost968
\[\begin{array}{l} \mathbf{if}\;z \leq -5.438588241640533 \cdot 10^{+59}:\\ \;\;\;\;x + \frac{a}{-1 + \frac{t}{z}}\\ \mathbf{elif}\;z \leq 2517.6586304140988:\\ \;\;\;\;x - a \cdot \frac{y}{t - \left(z + -1\right)}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{y - z}{\frac{-z}{a}}\\ \end{array} \]
Alternative 6
Error8.7
Cost840
\[\begin{array}{l} t_1 := x + \frac{a}{-1 + \frac{t}{z}}\\ \mathbf{if}\;z \leq -0.001185820731416581:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.110942629719727 \cdot 10^{-48}:\\ \;\;\;\;x - \frac{a \cdot y}{t + 1}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error8.6
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -0.001185820731416581:\\ \;\;\;\;x + \frac{a}{-1 + \frac{t + 1}{z}}\\ \mathbf{elif}\;z \leq 6.110942629719727 \cdot 10^{-48}:\\ \;\;\;\;x - \frac{a \cdot y}{t + 1}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{a}{-1 + \frac{t}{z}}\\ \end{array} \]
Alternative 8
Error16.9
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -17609776806.63367:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 6.110942629719727 \cdot 10^{-48}:\\ \;\;\;\;x - a \cdot y\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 9
Error19.5
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -5.438588241640533 \cdot 10^{+59}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 3.773429619195409 \cdot 10^{-21}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 10
Error27.1
Cost392
\[\begin{array}{l} \mathbf{if}\;a \leq -5 \cdot 10^{+154}:\\ \;\;\;\;-a\\ \mathbf{elif}\;a \leq 2.600413390143343 \cdot 10^{+113}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-a\\ \end{array} \]
Alternative 11
Error27.8
Cost64
\[x \]

Error

Reproduce

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