Average Error: 2.0 → 0.2
Time: 16.7s
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.2
Herbie0.2
\[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.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)): 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): 27 points increase in error, 5 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(1 - z\right)}, x\right) \]

Alternatives

Alternative 1
Error17.7
Cost1236
\[\begin{array}{l} t_1 := x - \frac{a}{\frac{t}{y}}\\ \mathbf{if}\;z \leq -5.387095152012939 \cdot 10^{+53}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq -8.24076043262349 \cdot 10^{-86}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.146883686007662 \cdot 10^{-280}:\\ \;\;\;\;x - a \cdot y\\ \mathbf{elif}\;z \leq 4.489230064309801 \cdot 10^{-17}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.809265099421616 \cdot 10^{+127}:\\ \;\;\;\;x - \frac{a}{\frac{1 - z}{y}}\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 2
Error6.7
Cost1232
\[\begin{array}{l} t_1 := x + \frac{z - y}{\frac{t}{a}}\\ \mathbf{if}\;t \leq -3.2141959111083213 \cdot 10^{+124}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -9.643993416743493 \cdot 10^{+70}:\\ \;\;\;\;\frac{a}{\left(t - z\right) + 1} \cdot \left(z - y\right)\\ \mathbf{elif}\;t \leq -2.116399063425096 \cdot 10^{+26}:\\ \;\;\;\;x + \frac{a \cdot \left(z - y\right)}{t}\\ \mathbf{elif}\;t \leq 4.3531347233443016 \cdot 10^{+100}:\\ \;\;\;\;x + a \cdot \frac{z - y}{1 - z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error15.3
Cost1104
\[\begin{array}{l} t_1 := x - \frac{a}{\frac{z + -1}{z}}\\ t_2 := x - \frac{a}{\frac{t}{y}}\\ \mathbf{if}\;t \leq -2.116399063425096 \cdot 10^{+26}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -9.306455801026913 \cdot 10^{-227}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 7.423921031747934 \cdot 10^{-264}:\\ \;\;\;\;x - a \cdot y\\ \mathbf{elif}\;t \leq 4.3531347233443016 \cdot 10^{+100}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error17.2
Cost980
\[\begin{array}{l} t_1 := x - a \cdot y\\ t_2 := x - \frac{a}{\frac{t}{y}}\\ \mathbf{if}\;z \leq -5.387095152012939 \cdot 10^{+53}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq -8.24076043262349 \cdot 10^{-86}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.146883686007662 \cdot 10^{-280}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.2296368800678494 \cdot 10^{-173}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.901461162239927 \cdot 10^{-33}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 5
Error6.1
Cost968
\[\begin{array}{l} t_1 := x + \frac{z - y}{\frac{t}{a}}\\ \mathbf{if}\;t \leq -3.0940565643227074 \cdot 10^{+121}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 4.3531347233443016 \cdot 10^{+100}:\\ \;\;\;\;x - \frac{a}{\frac{1 - z}{y - z}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error6.0
Cost968
\[\begin{array}{l} t_1 := x + \frac{z - y}{\frac{t}{a}}\\ \mathbf{if}\;t \leq -3.0940565643227074 \cdot 10^{+121}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 4.3531347233443016 \cdot 10^{+100}:\\ \;\;\;\;x + a \cdot \frac{z - y}{1 - z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error8.7
Cost904
\[\begin{array}{l} t_1 := x + \frac{z - y}{\frac{-z}{a}}\\ \mathbf{if}\;z \leq -5.387095152012939 \cdot 10^{+53}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 0.0003366142962280227:\\ \;\;\;\;x - y \cdot \frac{a}{t + 1}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error9.5
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -5.387095152012939 \cdot 10^{+53}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 0.0003366142962280227:\\ \;\;\;\;x - \frac{a}{\frac{t + 1}{y}}\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 9
Error9.7
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -5.387095152012939 \cdot 10^{+53}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 0.0003366142962280227:\\ \;\;\;\;x - y \cdot \frac{a}{t + 1}\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 10
Error0.2
Cost832
\[x - \frac{a}{\frac{\left(t - z\right) + 1}{y - z}} \]
Alternative 11
Error0.2
Cost832
\[x + a \cdot \frac{z - y}{\left(t - z\right) + 1} \]
Alternative 12
Error17.1
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -7.075657097985072 \cdot 10^{+46}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 2.901461162239927 \cdot 10^{-33}:\\ \;\;\;\;x - a \cdot y\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 13
Error19.2
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -5.387095152012939 \cdot 10^{+53}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 2.901461162239927 \cdot 10^{-33}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 14
Error27.2
Cost392
\[\begin{array}{l} \mathbf{if}\;x \leq -7.769698313128528 \cdot 10^{-272}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8.007739046823117 \cdot 10^{-88}:\\ \;\;\;\;-a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 15
Error28.0
Cost64
\[x \]

Error

Reproduce

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