Average Error: 1.9 → 0.2
Time: 13.9s
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.2
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): 2 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, 2 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): 28 points increase in error, 10 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
Error15.5
Cost1104
\[\begin{array}{l} \mathbf{if}\;t \leq -9.11545711165471 \cdot 10^{+138}:\\ \;\;\;\;x - \frac{a}{\frac{t}{y}}\\ \mathbf{elif}\;t \leq 3.2994064454616784 \cdot 10^{-138}:\\ \;\;\;\;x - \frac{a}{1 - \frac{1}{z}}\\ \mathbf{elif}\;t \leq 1.892173196674624 \cdot 10^{-53}:\\ \;\;\;\;x - a \cdot y\\ \mathbf{elif}\;t \leq 8.254347326089875 \cdot 10^{+107}:\\ \;\;\;\;x - a\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z - y}{\frac{t}{a}}\\ \end{array} \]
Alternative 2
Error16.3
Cost976
\[\begin{array}{l} t_1 := x - \frac{a}{\frac{t}{y}}\\ \mathbf{if}\;t \leq -9.11545711165471 \cdot 10^{+138}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 3.2994064454616784 \cdot 10^{-138}:\\ \;\;\;\;x - \frac{a}{1 - \frac{1}{z}}\\ \mathbf{elif}\;t \leq 1.892173196674624 \cdot 10^{-53}:\\ \;\;\;\;x - a \cdot y\\ \mathbf{elif}\;t \leq 4.884916956036249 \cdot 10^{+104}:\\ \;\;\;\;x - a\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error6.7
Cost972
\[\begin{array}{l} \mathbf{if}\;t \leq -9.11545711165471 \cdot 10^{+138}:\\ \;\;\;\;x - \frac{a}{\frac{t}{y}}\\ \mathbf{elif}\;t \leq 122.57594854983186:\\ \;\;\;\;x + a \cdot \frac{z - y}{1 - z}\\ \mathbf{elif}\;t \leq 8.689479256336787 \cdot 10^{+196}:\\ \;\;\;\;x - \frac{a}{1 - \frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z - y}{\frac{t}{a}}\\ \end{array} \]
Alternative 4
Error7.5
Cost904
\[\begin{array}{l} t_1 := x - \frac{a}{\frac{-z}{y - z}}\\ \mathbf{if}\;z \leq -0.006195692644150916:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 141236470609.5425:\\ \;\;\;\;x - \frac{a}{\frac{t + 1}{y}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error7.5
Cost904
\[\begin{array}{l} t_1 := x + a \cdot \frac{z - y}{-z}\\ \mathbf{if}\;z \leq -0.006195692644150916:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 141236470609.5425:\\ \;\;\;\;x - \frac{a}{\frac{t + 1}{y}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error7.1
Cost904
\[\begin{array}{l} \mathbf{if}\;z \leq -0.006195692644150916:\\ \;\;\;\;x - \frac{a}{1 + \frac{-1 - t}{z}}\\ \mathbf{elif}\;z \leq 141236470609.5425:\\ \;\;\;\;x - \frac{a}{\frac{t + 1}{y}}\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot \frac{z - y}{-z}\\ \end{array} \]
Alternative 7
Error9.8
Cost840
\[\begin{array}{l} t_1 := x - \frac{a}{1 - \frac{1}{z}}\\ \mathbf{if}\;z \leq -0.006195692644150916:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.599496647557363 \cdot 10^{-7}:\\ \;\;\;\;x - \frac{a}{\frac{t + 1}{y}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error7.8
Cost840
\[\begin{array}{l} t_1 := x - \frac{a}{1 - \frac{t}{z}}\\ \mathbf{if}\;z \leq -3.0475727880824724 \cdot 10^{+65}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.5793985222201038 \cdot 10^{-38}:\\ \;\;\;\;x - \frac{a}{\frac{t + 1}{y}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error0.3
Cost832
\[x - \frac{a}{\frac{\left(t - z\right) + 1}{y - z}} \]
Alternative 10
Error0.2
Cost832
\[x + a \cdot \frac{z - y}{\left(t - z\right) + 1} \]
Alternative 11
Error16.9
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -0.006195692644150916:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 4.599496647557363 \cdot 10^{-7}:\\ \;\;\;\;x - a \cdot y\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 12
Error19.9
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -3.0475727880824724 \cdot 10^{+65}:\\ \;\;\;\;x - a\\ \mathbf{elif}\;z \leq 4.599496647557363 \cdot 10^{-7}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x - a\\ \end{array} \]
Alternative 13
Error27.7
Cost260
\[\begin{array}{l} \mathbf{if}\;a \leq 1.02 \cdot 10^{+153}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-a\\ \end{array} \]
Alternative 14
Error28.0
Cost64
\[x \]

Error

Reproduce

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