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

Error

Target

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

Derivation

  1. Initial program 2.0

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

    \[\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, 1 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): 1 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)): 1 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): 29 points increase in error, 12 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.3

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

Alternatives

Alternative 1
Error6.3
Cost968
\[\begin{array}{l} \mathbf{if}\;t \leq -3.5 \cdot 10^{+76}:\\ \;\;\;\;x + \frac{z - y}{\frac{t}{a}}\\ \mathbf{elif}\;t \leq 2.8 \cdot 10^{+67}:\\ \;\;\;\;x + \frac{a}{1 - z} \cdot \left(z - y\right)\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot \frac{z - y}{t}\\ \end{array} \]
Alternative 2
Error5.5
Cost968
\[\begin{array}{l} \mathbf{if}\;t \leq -2 \cdot 10^{+66}:\\ \;\;\;\;x + \frac{z - y}{\frac{t}{a}}\\ \mathbf{elif}\;t \leq 7.2 \cdot 10^{+105}:\\ \;\;\;\;x - \frac{a}{\frac{1 - z}{y - z}}\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot \frac{z - y}{t}\\ \end{array} \]
Alternative 3
Error9.5
Cost904
\[\begin{array}{l} \mathbf{if}\;z \leq -3.8 \cdot 10^{+50}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 10^{+28}:\\ \;\;\;\;x - y \cdot \frac{a}{t + 1}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{y - z}{\frac{-z}{a}}\\ \end{array} \]
Alternative 4
Error16.7
Cost848
\[\begin{array}{l} t_1 := x - a \cdot y\\ \mathbf{if}\;z \leq -0.0012:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq -1.95 \cdot 10^{-306}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.4 \cdot 10^{-284}:\\ \;\;\;\;x - \frac{a \cdot y}{t}\\ \mathbf{elif}\;z \leq 0.0065:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 5
Error9.8
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -3.8 \cdot 10^{+50}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{+28}:\\ \;\;\;\;x - y \cdot \frac{a}{t + 1}\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 6
Error0.3
Cost832
\[x + a \cdot \frac{z - y}{\left(t - z\right) + 1} \]
Alternative 7
Error18.9
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{-10}:\\ \;\;\;\;x + a \cdot z\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 8
Error16.7
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -0.00135:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 0.0045:\\ \;\;\;\;x - a \cdot y\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 9
Error19.5
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -2.55 \cdot 10^{+51}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 6.8 \cdot 10^{+28}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 10
Error27.7
Cost64
\[x \]

Error

Reproduce

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