Average Error: 6.7 → 1.8
Time: 11.0s
Precision: binary64
Cost: 6848
\[x + \frac{y \cdot \left(z - x\right)}{t} \]
\[\mathsf{fma}\left(\frac{y}{t}, z - x, x\right) \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
(FPCore (x y z t) :precision binary64 (fma (/ y t) (- z x) x))
double code(double x, double y, double z, double t) {
	return x + ((y * (z - x)) / t);
}
double code(double x, double y, double z, double t) {
	return fma((y / t), (z - x), x);
}
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y * Float64(z - x)) / t))
end
function code(x, y, z, t)
	return fma(Float64(y / t), Float64(z - x), x)
end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision] + x), $MachinePrecision]
x + \frac{y \cdot \left(z - x\right)}{t}
\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)

Error

Target

Original6.7
Target1.8
Herbie1.8
\[x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right) \]

Derivation

  1. Initial program 6.7

    \[x + \frac{y \cdot \left(z - x\right)}{t} \]
  2. Simplified1.8

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)} \]
    Proof

    [Start]6.7

    \[ x + \frac{y \cdot \left(z - x\right)}{t} \]

    +-commutative [=>]6.7

    \[ \color{blue}{\frac{y \cdot \left(z - x\right)}{t} + x} \]

    associate-*l/ [<=]1.8

    \[ \color{blue}{\frac{y}{t} \cdot \left(z - x\right)} + x \]

    fma-def [=>]1.8

    \[ \color{blue}{\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)} \]
  3. Final simplification1.8

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

Alternatives

Alternative 1
Error25.7
Cost1176
\[\begin{array}{l} t_1 := \frac{y}{t} \cdot z\\ \mathbf{if}\;x \leq -1.45 \cdot 10^{-145}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{-110}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-89}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.15 \cdot 10^{-25}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.2 \cdot 10^{+100}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.04 \cdot 10^{+117}:\\ \;\;\;\;\frac{y}{t} \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error17.2
Cost978
\[\begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{-141} \lor \neg \left(x \leq 7 \cdot 10^{-134}\right) \land \left(x \leq 5 \cdot 10^{-74} \lor \neg \left(x \leq 9 \cdot 10^{-26}\right)\right):\\ \;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{t} \cdot z\\ \end{array} \]
Alternative 3
Error15.4
Cost978
\[\begin{array}{l} \mathbf{if}\;x \leq -4.2 \cdot 10^{-137} \lor \neg \left(x \leq 7 \cdot 10^{-110}\right) \land \left(x \leq 2.2 \cdot 10^{-88} \lor \neg \left(x \leq 1.4 \cdot 10^{-25}\right)\right):\\ \;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{t} \cdot \left(z - x\right)\\ \end{array} \]
Alternative 4
Error25.5
Cost849
\[\begin{array}{l} \mathbf{if}\;x \leq -1.02 \cdot 10^{-138}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.95 \cdot 10^{-109} \lor \neg \left(x \leq 4.5 \cdot 10^{-88}\right) \land x \leq 9 \cdot 10^{-26}:\\ \;\;\;\;\frac{y}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error9.0
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -6.8 \cdot 10^{+37} \lor \neg \left(x \leq 5.8 \cdot 10^{-11}\right):\\ \;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{t} \cdot z\\ \end{array} \]
Alternative 6
Error9.0
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -1.75 \cdot 10^{+37}:\\ \;\;\;\;x - \frac{y}{t} \cdot x\\ \mathbf{elif}\;x \leq 6.6 \cdot 10^{-11}:\\ \;\;\;\;x + \frac{y}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\ \end{array} \]
Alternative 7
Error1.8
Cost704
\[x + \frac{1}{\frac{\frac{t}{y}}{z - x}} \]
Alternative 8
Error1.8
Cost576
\[x + \frac{y}{t} \cdot \left(z - x\right) \]
Alternative 9
Error31.2
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2023016 
(FPCore (x y z t)
  :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, D"
  :precision binary64

  :herbie-target
  (- x (+ (* x (/ y t)) (* (- z) (/ y t))))

  (+ x (/ (* y (- z x)) t)))