Average Error: 6.9 → 2.2
Time: 14.4s
Precision: binary64
Cost: 7112
\[x + \frac{y \cdot \left(z - x\right)}{t} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -1.0067102364668002 \cdot 10^{-71}:\\ \;\;\;\;x + \left(z - x\right) \cdot \frac{1}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq 3.434203337940554 \cdot 10^{-165}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(z - x\right) \cdot \left(y \cdot \frac{1}{t}\right)\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
(FPCore (x y z t)
 :precision binary64
 (if (<= x -1.0067102364668002e-71)
   (+ x (* (- z x) (/ 1.0 (/ t y))))
   (if (<= x 3.434203337940554e-165)
     (fma y (/ (- z x) t) x)
     (+ x (* (- z x) (* y (/ 1.0 t)))))))
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) {
	double tmp;
	if (x <= -1.0067102364668002e-71) {
		tmp = x + ((z - x) * (1.0 / (t / y)));
	} else if (x <= 3.434203337940554e-165) {
		tmp = fma(y, ((z - x) / t), x);
	} else {
		tmp = x + ((z - x) * (y * (1.0 / t)));
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y * Float64(z - x)) / t))
end
function code(x, y, z, t)
	tmp = 0.0
	if (x <= -1.0067102364668002e-71)
		tmp = Float64(x + Float64(Float64(z - x) * Float64(1.0 / Float64(t / y))));
	elseif (x <= 3.434203337940554e-165)
		tmp = fma(y, Float64(Float64(z - x) / t), x);
	else
		tmp = Float64(x + Float64(Float64(z - x) * Float64(y * Float64(1.0 / t))));
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[x, -1.0067102364668002e-71], N[(x + N[(N[(z - x), $MachinePrecision] * N[(1.0 / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.434203337940554e-165], N[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision] + x), $MachinePrecision], N[(x + N[(N[(z - x), $MachinePrecision] * N[(y * N[(1.0 / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
x + \frac{y \cdot \left(z - x\right)}{t}
\begin{array}{l}
\mathbf{if}\;x \leq -1.0067102364668002 \cdot 10^{-71}:\\
\;\;\;\;x + \left(z - x\right) \cdot \frac{1}{\frac{t}{y}}\\

\mathbf{elif}\;x \leq 3.434203337940554 \cdot 10^{-165}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\

\mathbf{else}:\\
\;\;\;\;x + \left(z - x\right) \cdot \left(y \cdot \frac{1}{t}\right)\\


\end{array}

Error

Target

Original6.9
Target2.0
Herbie2.2
\[x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right) \]

Derivation

  1. Split input into 3 regimes
  2. if x < -1.00671023646680022e-71

    1. Initial program 8.7

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Applied egg-rr0.4

      \[\leadsto x + \color{blue}{\left(z - x\right) \cdot \left(y \cdot \frac{1}{t}\right)} \]
    3. Applied egg-rr0.4

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

    if -1.00671023646680022e-71 < x < 3.4342033379405538e-165

    1. Initial program 5.2

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)} \]
      Proof
      (fma.f64 y (/.f64 (-.f64 z x) t) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (/.f64 (-.f64 z x) t)) x)): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 y (-.f64 z x)) t)) x): 47 points increase in error, 47 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t))): 0 points increase in error, 0 points decrease in error

    if 3.4342033379405538e-165 < x

    1. Initial program 7.1

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Applied egg-rr1.0

      \[\leadsto x + \color{blue}{\left(z - x\right) \cdot \left(y \cdot \frac{1}{t}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.0067102364668002 \cdot 10^{-71}:\\ \;\;\;\;x + \left(z - x\right) \cdot \frac{1}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq 3.434203337940554 \cdot 10^{-165}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(z - x\right) \cdot \left(y \cdot \frac{1}{t}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error1.0
Cost1992
\[\begin{array}{l} t_1 := x + \frac{\left(z - x\right) \cdot y}{t}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;x + \frac{y}{\frac{t}{z - x}}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+297}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + \frac{\frac{z - x}{t}}{\frac{1}{y}}\\ \end{array} \]
Alternative 2
Error0.9
Cost1864
\[\begin{array}{l} t_1 := x + \frac{y}{\frac{t}{z - x}}\\ t_2 := x + \frac{\left(z - x\right) \cdot y}{t}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{+297}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error12.0
Cost976
\[\begin{array}{l} t_1 := x + \frac{z \cdot y}{t}\\ t_2 := x - \frac{x}{\frac{t}{y}}\\ \mathbf{if}\;x \leq -7.716644162669336 \cdot 10^{-69}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 5.797414288985791 \cdot 10^{-230}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.9328350781773735 \cdot 10^{-129}:\\ \;\;\;\;\frac{z - x}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq 1.2599258063749972 \cdot 10^{-13}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error12.2
Cost976
\[\begin{array}{l} t_1 := x + \frac{z \cdot y}{t}\\ t_2 := x - \frac{x}{\frac{t}{y}}\\ \mathbf{if}\;x \leq -7.716644162669336 \cdot 10^{-69}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 7.725885732891094 \cdot 10^{-240}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.871973886937964 \cdot 10^{-118}:\\ \;\;\;\;\left(z - x\right) \cdot \frac{y}{t}\\ \mathbf{elif}\;x \leq 1.2599258063749972 \cdot 10^{-13}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error2.1
Cost968
\[\begin{array}{l} t_1 := x + \left(z - x\right) \cdot \frac{1}{\frac{t}{y}}\\ \mathbf{if}\;x \leq -1.0067102364668002 \cdot 10^{-71}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.434203337940554 \cdot 10^{-165}:\\ \;\;\;\;x + \frac{y}{\frac{t}{z - x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error2.1
Cost968
\[\begin{array}{l} \mathbf{if}\;x \leq -1.0067102364668002 \cdot 10^{-71}:\\ \;\;\;\;x + \left(z - x\right) \cdot \frac{1}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq 3.434203337940554 \cdot 10^{-165}:\\ \;\;\;\;x + \frac{y}{\frac{t}{z - x}}\\ \mathbf{else}:\\ \;\;\;\;x + \left(z - x\right) \cdot \left(y \cdot \frac{1}{t}\right)\\ \end{array} \]
Alternative 7
Error20.1
Cost844
\[\begin{array}{l} t_1 := x - \frac{y}{\frac{t}{x}}\\ \mathbf{if}\;x \leq -5.519338175716365 \cdot 10^{-139}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.871973886937964 \cdot 10^{-118}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{+183}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error18.4
Cost844
\[\begin{array}{l} t_1 := x - \frac{y}{\frac{t}{x}}\\ \mathbf{if}\;x \leq -3.796611319528088 \cdot 10^{-112}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.871973886937964 \cdot 10^{-118}:\\ \;\;\;\;\frac{\left(z - x\right) \cdot y}{t}\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{+183}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error3.9
Cost840
\[\begin{array}{l} t_1 := x + \frac{y}{\frac{t}{z - x}}\\ \mathbf{if}\;y \leq -9.331191613420102 \cdot 10^{-92}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.55 \cdot 10^{-63}:\\ \;\;\;\;x + \frac{z \cdot y}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error11.6
Cost712
\[\begin{array}{l} t_1 := x + \frac{z \cdot y}{t}\\ \mathbf{if}\;z \leq -3.255113194900892 \cdot 10^{-221}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.0790745183485307 \cdot 10^{-141}:\\ \;\;\;\;x - \frac{y}{\frac{t}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error10.7
Cost712
\[\begin{array}{l} t_1 := x - \frac{x}{\frac{t}{y}}\\ \mathbf{if}\;x \leq -7.716644162669336 \cdot 10^{-69}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.2599258063749972 \cdot 10^{-13}:\\ \;\;\;\;x + \frac{z \cdot y}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error25.9
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -5.02890998355651 \cdot 10^{-45}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.871973886937964 \cdot 10^{-118}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error32.0
Cost64
\[x \]

Error

Reproduce

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