Average Error: 6.6 → 1.6
Time: 5.6s
Precision: binary64
\[x + \frac{y \cdot \left(z - x\right)}{t} \]
\[\begin{array}{l} \mathbf{if}\;t \leq -1 \cdot 10^{-68}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z}{t} - \frac{x}{t}, x\right)\\ \mathbf{elif}\;t \leq 10^{-97}:\\ \;\;\;\;x + \frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z - x, \frac{y}{t}, x\right)\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
(FPCore (x y z t)
 :precision binary64
 (if (<= t -1e-68)
   (fma y (- (/ z t) (/ x t)) x)
   (if (<= t 1e-97) (+ x (/ (* y (- z x)) t)) (fma (- z x) (/ y t) 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) {
	double tmp;
	if (t <= -1e-68) {
		tmp = fma(y, ((z / t) - (x / t)), x);
	} else if (t <= 1e-97) {
		tmp = x + ((y * (z - x)) / t);
	} else {
		tmp = fma((z - x), (y / t), x);
	}
	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 (t <= -1e-68)
		tmp = fma(y, Float64(Float64(z / t) - Float64(x / t)), x);
	elseif (t <= 1e-97)
		tmp = Float64(x + Float64(Float64(y * Float64(z - x)) / t));
	else
		tmp = fma(Float64(z - x), Float64(y / t), x);
	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[t, -1e-68], N[(y * N[(N[(z / t), $MachinePrecision] - N[(x / t), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t, 1e-97], N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(N[(z - x), $MachinePrecision] * N[(y / t), $MachinePrecision] + x), $MachinePrecision]]]
x + \frac{y \cdot \left(z - x\right)}{t}
\begin{array}{l}
\mathbf{if}\;t \leq -1 \cdot 10^{-68}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z}{t} - \frac{x}{t}, x\right)\\

\mathbf{elif}\;t \leq 10^{-97}:\\
\;\;\;\;x + \frac{y \cdot \left(z - x\right)}{t}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z - x, \frac{y}{t}, x\right)\\


\end{array}

Error

Target

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

Derivation

  1. Split input into 3 regimes
  2. if t < -1.00000000000000007e-68

    1. Initial program 8.0

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Taylor expanded in z around 0 8.0

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

      \[\leadsto x + \color{blue}{\frac{y}{\frac{t}{z - x}}} \]
    4. Applied egg-rr8.0

      \[\leadsto x + \color{blue}{{\left(\frac{t}{y \cdot \left(z - x\right)}\right)}^{-1}} \]
    5. Taylor expanded in y around 0 1.6

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

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

    if -1.00000000000000007e-68 < t < 1.00000000000000004e-97

    1. Initial program 2.3

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

    if 1.00000000000000004e-97 < t

    1. Initial program 8.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(z - x, \frac{y}{t}, x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.6

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

Reproduce

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