Average Error: 6.5 → 0.9
Time: 9.6s
Precision: binary64
Cost: 8136
\[x + \frac{y \cdot \left(z - x\right)}{t} \]
\[\begin{array}{l} t_1 := x + \frac{y \cdot \left(z - x\right)}{t}\\ t_2 := \mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+306}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{+296}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (+ x (/ (* y (- z x)) t))) (t_2 (fma y (/ (- z x) t) x)))
   (if (<= t_1 -1e+306) t_2 (if (<= t_1 1e+296) t_1 t_2))))
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 t_1 = x + ((y * (z - x)) / t);
	double t_2 = fma(y, ((z - x) / t), x);
	double tmp;
	if (t_1 <= -1e+306) {
		tmp = t_2;
	} else if (t_1 <= 1e+296) {
		tmp = t_1;
	} else {
		tmp = t_2;
	}
	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)
	t_1 = Float64(x + Float64(Float64(y * Float64(z - x)) / t))
	t_2 = fma(y, Float64(Float64(z - x) / t), x)
	tmp = 0.0
	if (t_1 <= -1e+306)
		tmp = t_2;
	elseif (t_1 <= 1e+296)
		tmp = t_1;
	else
		tmp = t_2;
	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_] := Block[{t$95$1 = N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+306], t$95$2, If[LessEqual[t$95$1, 1e+296], t$95$1, t$95$2]]]]
x + \frac{y \cdot \left(z - x\right)}{t}
\begin{array}{l}
t_1 := x + \frac{y \cdot \left(z - x\right)}{t}\\
t_2 := \mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{+306}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 10^{+296}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}

Error

Target

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

Derivation

  1. Split input into 2 regimes
  2. if (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < -1.00000000000000002e306 or 9.99999999999999981e295 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t))

    1. Initial program 54.5

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

      \[\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)): 1 points increase in error, 1 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 y (-.f64 z x)) t)) x): 42 points increase in error, 44 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 -1.00000000000000002e306 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < 9.99999999999999981e295

    1. Initial program 0.7

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{t}, y \cdot \left(z - x\right), x\right)} \]
    3. Taylor expanded in t around 0 0.7

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

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

Alternatives

Alternative 1
Error0.9
Cost1864
\[\begin{array}{l} t_1 := x + \frac{y \cdot \left(z - x\right)}{t}\\ t_2 := x + \frac{y}{\frac{t}{z - x}}\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+306}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{+296}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error26.4
Cost912
\[\begin{array}{l} \mathbf{if}\;x \leq -2.3177019130344637 \cdot 10^{-84}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.2716025014859312 \cdot 10^{-149}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{+159}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{+173}:\\ \;\;\;\;\frac{x \cdot y}{-t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error26.4
Cost912
\[\begin{array}{l} \mathbf{if}\;x \leq -2.3177019130344637 \cdot 10^{-84}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.2716025014859312 \cdot 10^{-149}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{+159}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{+173}:\\ \;\;\;\;y \cdot \frac{-x}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error26.8
Cost912
\[\begin{array}{l} \mathbf{if}\;x \leq -2.3177019130344637 \cdot 10^{-84}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.2716025014859312 \cdot 10^{-149}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{+159}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{+195}:\\ \;\;\;\;x \cdot \frac{-y}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error4.6
Cost840
\[\begin{array}{l} t_1 := x - x \cdot \frac{y}{t}\\ \mathbf{if}\;x \leq -1 \cdot 10^{+171}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.277489689684912 \cdot 10^{+85}:\\ \;\;\;\;x + \frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error11.5
Cost712
\[\begin{array}{l} t_1 := \frac{z - x}{\frac{t}{y}}\\ \mathbf{if}\;y \leq -5.7 \cdot 10^{+75}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5 \cdot 10^{+185}:\\ \;\;\;\;x + \frac{y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error10.3
Cost712
\[\begin{array}{l} t_1 := x - x \cdot \frac{y}{t}\\ \mathbf{if}\;x \leq -12489800739977724:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.8034420689554325 \cdot 10^{-54}:\\ \;\;\;\;x + \frac{y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error15.2
Cost648
\[\begin{array}{l} \mathbf{if}\;x \leq 2.9 \cdot 10^{+150}:\\ \;\;\;\;x + \frac{y \cdot z}{t}\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{+195}:\\ \;\;\;\;x \cdot \frac{-y}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error26.0
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2.3177019130344637 \cdot 10^{-84}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.2716025014859312 \cdot 10^{-149}:\\ \;\;\;\;\frac{z}{\frac{t}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error26.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2.3177019130344637 \cdot 10^{-84}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.2716025014859312 \cdot 10^{-149}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error31.7
Cost64
\[x \]

Error

Reproduce

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