Average Error: 1.9 → 0.2
Time: 21.3s
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

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

Derivation

  1. Initial program 1.9

    \[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): 1 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, 1 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): 37 points increase in error, 8 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
Error0.9
Cost2504
\[\begin{array}{l} t_1 := \frac{\left(t - z\right) + 1}{a}\\ t_2 := \frac{y - z}{t_1}\\ \mathbf{if}\;t_2 \leq -4 \cdot 10^{-177}:\\ \;\;\;\;x + \frac{z - y}{t_1}\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;x + a \cdot \frac{z}{t + \left(1 - z\right)}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z - y}{\frac{t}{a} + \frac{1 - z}{a}}\\ \end{array} \]
Alternative 2
Error0.9
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 -4 \cdot 10^{-177}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_3 \leq 0:\\ \;\;\;\;x + a \cdot \frac{z}{t + \left(1 - z\right)}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error22.3
Cost1504
\[\begin{array}{l} t_1 := x - a \cdot y\\ t_2 := x + a \cdot \frac{z}{t}\\ \mathbf{if}\;t \leq -1.0381248867926146 \cdot 10^{+112}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -2.7682759135070297 \cdot 10^{-92}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;t \leq -1.3581903523889474 \cdot 10^{-132}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 3.6708258590930913 \cdot 10^{-146}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;t \leq 8.907639838274639 \cdot 10^{+45}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.4614870524406917 \cdot 10^{+76}:\\ \;\;\;\;a \cdot \frac{y}{z}\\ \mathbf{elif}\;t \leq 1.4184847404666691 \cdot 10^{+99}:\\ \;\;\;\;\frac{a}{t} \cdot \left(z - y\right)\\ \mathbf{elif}\;t \leq 1.1854091014429938 \cdot 10^{+136}:\\ \;\;\;\;x - a\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error18.2
Cost1240
\[\begin{array}{l} t_1 := x - \frac{a \cdot y}{1 - z}\\ t_2 := x - \frac{a}{\frac{t}{y}}\\ \mathbf{if}\;t \leq -0.02393573656865198:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 3.4648981495154512 \cdot 10^{-273}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 3.234035802886892 \cdot 10^{-185}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;t \leq 3.064574722796336 \cdot 10^{+65}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.4184847404666691 \cdot 10^{+99}:\\ \;\;\;\;\frac{a}{t} \cdot \left(z - y\right)\\ \mathbf{elif}\;t \leq 1.2335454033721844 \cdot 10^{+139}:\\ \;\;\;\;x - a\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error17.3
Cost1240
\[\begin{array}{l} t_1 := x - \frac{a \cdot y}{1 - z}\\ t_2 := x - \frac{a}{\frac{t}{y}}\\ \mathbf{if}\;t \leq -0.02393573656865198:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 3.4648981495154512 \cdot 10^{-273}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 3.234035802886892 \cdot 10^{-185}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;t \leq 5.242489187998337:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.4184847404666691 \cdot 10^{+99}:\\ \;\;\;\;x + \frac{a \cdot \left(z - y\right)}{t}\\ \mathbf{elif}\;t \leq 1.2335454033721844 \cdot 10^{+139}:\\ \;\;\;\;x - a\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error7.4
Cost1232
\[\begin{array}{l} t_1 := x + a \cdot \frac{z}{t + \left(1 - z\right)}\\ \mathbf{if}\;t \leq -3.195088258632385 \cdot 10^{+19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 5.242489187998337:\\ \;\;\;\;x + \frac{z - y}{\frac{1 - z}{a}}\\ \mathbf{elif}\;t \leq 5.074451545475317 \cdot 10^{+90}:\\ \;\;\;\;x + \frac{z - y}{\frac{t}{a}}\\ \mathbf{elif}\;t \leq 1.2335454033721844 \cdot 10^{+139}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + \frac{a}{t} \cdot \left(z - y\right)\\ \end{array} \]
Alternative 7
Error17.4
Cost1108
\[\begin{array}{l} t_1 := x + \frac{z - y}{\frac{t}{a}}\\ \mathbf{if}\;z \leq -4.9723687118816335 \cdot 10^{+26}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq -7.5711060556671914 \cdot 10^{-180}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1733.0684165239147:\\ \;\;\;\;x - \frac{a \cdot y}{1 - z}\\ \mathbf{elif}\;z \leq 4.010320760069792 \cdot 10^{+80}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 9.178133260661372 \cdot 10^{+148}:\\ \;\;\;\;x + y \cdot \frac{a}{z}\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 8
Error9.2
Cost1036
\[\begin{array}{l} t_1 := x + \frac{z - y}{\frac{-z}{a}}\\ \mathbf{if}\;z \leq -1.3484092594546644 \cdot 10^{+269}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq -2.02315651438881 \cdot 10^{+84}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.34655856041675 \cdot 10^{+58}:\\ \;\;\;\;x - y \cdot \frac{a}{t + 1}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error11.0
Cost1036
\[\begin{array}{l} \mathbf{if}\;z \leq -1.6710401451148576 \cdot 10^{+200}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq -6.26481793049109 \cdot 10^{+118}:\\ \;\;\;\;\frac{a}{t + \left(1 - z\right)} \cdot \left(z - y\right)\\ \mathbf{elif}\;z \leq 6.34655856041675 \cdot 10^{+58}:\\ \;\;\;\;x - y \cdot \frac{a}{t + 1}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z - y}{\frac{-z}{a}}\\ \end{array} \]
Alternative 10
Error7.1
Cost968
\[\begin{array}{l} t_1 := x + a \cdot \frac{z}{t + \left(1 - z\right)}\\ \mathbf{if}\;z \leq -6.165954600457157 \cdot 10^{-25}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.34655856041675 \cdot 10^{+58}:\\ \;\;\;\;x - y \cdot \frac{a}{t + 1}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error10.3
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -6.26481793049109 \cdot 10^{+118}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 6.34655856041675 \cdot 10^{+58}:\\ \;\;\;\;x - \frac{y}{\frac{t + 1}{a}}\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 12
Error10.2
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -6.26481793049109 \cdot 10^{+118}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 6.34655856041675 \cdot 10^{+58}:\\ \;\;\;\;x - y \cdot \frac{a}{t + 1}\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 13
Error18.0
Cost716
\[\begin{array}{l} \mathbf{if}\;z \leq -6.26481793049109 \cdot 10^{+118}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq -7.5711060556671914 \cdot 10^{-180}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.2768674292009731 \cdot 10^{-21}:\\ \;\;\;\;x - a \cdot y\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 14
Error17.6
Cost716
\[\begin{array}{l} \mathbf{if}\;z \leq -6.26481793049109 \cdot 10^{+118}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq -7.5711060556671914 \cdot 10^{-180}:\\ \;\;\;\;x - \frac{a}{\frac{t}{y}}\\ \mathbf{elif}\;z \leq 1.2768674292009731 \cdot 10^{-21}:\\ \;\;\;\;x - a \cdot y\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 15
Error20.2
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -6.26481793049109 \cdot 10^{+118}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 2.334811113439605 \cdot 10^{-73}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 16
Error27.6
Cost260
\[\begin{array}{l} \mathbf{if}\;a \leq -5.1 \cdot 10^{+141}:\\ \;\;\;\;-a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 17
Error28.0
Cost64
\[x \]

Error

Reproduce

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