?

Average Error: 6.6 → 1.0
Time: 10.6s
Precision: binary64
Cost: 7492

?

\[x + \frac{y \cdot \left(z - x\right)}{t} \]
\[\begin{array}{l} t_1 := x + \frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\ \mathbf{elif}\;t_1 \leq 10^{+269}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + \left(z - x\right) \cdot \frac{y}{t}\\ \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))))
   (if (<= t_1 (- INFINITY))
     (fma y (/ (- z x) t) x)
     (if (<= t_1 1e+269) t_1 (+ x (* (- z x) (/ y 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 t_1 = x + ((y * (z - x)) / t);
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = fma(y, ((z - x) / t), x);
	} else if (t_1 <= 1e+269) {
		tmp = t_1;
	} else {
		tmp = x + ((z - x) * (y / 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)
	t_1 = Float64(x + Float64(Float64(y * Float64(z - x)) / t))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = fma(y, Float64(Float64(z - x) / t), x);
	elseif (t_1 <= 1e+269)
		tmp = t_1;
	else
		tmp = Float64(x + Float64(Float64(z - x) * Float64(y / 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_] := Block[{t$95$1 = N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$1, 1e+269], t$95$1, N[(x + N[(N[(z - x), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
x + \frac{y \cdot \left(z - x\right)}{t}
\begin{array}{l}
t_1 := x + \frac{y \cdot \left(z - x\right)}{t}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\

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

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


\end{array}

Error?

Target

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

Derivation?

  1. Split input into 3 regimes
  2. if (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < -inf.0

    1. Initial program 64.0

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

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

      [Start]64.0

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

      +-commutative [=>]64.0

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

      associate-*r/ [<=]0.2

      \[ \color{blue}{y \cdot \frac{z - x}{t}} + x \]

      fma-def [=>]0.2

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

    if -inf.0 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < 1e269

    1. Initial program 0.8

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

    if 1e269 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t))

    1. Initial program 34.5

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

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

      [Start]34.5

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

      associate-*l/ [<=]2.7

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

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

Alternatives

Alternative 1
Error1.0
Cost1865
\[\begin{array}{l} t_1 := x + \frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 10^{+269}\right):\\ \;\;\;\;x + \left(z - x\right) \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error26.0
Cost1505
\[\begin{array}{l} t_1 := y \cdot \frac{z - x}{t}\\ \mathbf{if}\;t \leq -1.4 \cdot 10^{+118}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -8 \cdot 10^{+109}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.7 \cdot 10^{+27}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -1.4 \cdot 10^{-262}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.35 \cdot 10^{-184}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;t \leq 3.9 \cdot 10^{+38} \lor \neg \left(t \leq 2.9 \cdot 10^{+180}\right) \land t \leq 2.7 \cdot 10^{+196}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error30.8
Cost1376
\[\begin{array}{l} t_1 := z \cdot \frac{y}{t}\\ \mathbf{if}\;z \leq -6.6 \cdot 10^{+190}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.1 \cdot 10^{+153}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2.25 \cdot 10^{+114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7.8 \cdot 10^{+14}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 7.5 \cdot 10^{+61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.25 \cdot 10^{+77}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6 \cdot 10^{+124}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.1 \cdot 10^{+222}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 4
Error31.2
Cost1376
\[\begin{array}{l} t_1 := z \cdot \frac{y}{t}\\ \mathbf{if}\;z \leq -4.5 \cdot 10^{+188}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -8.4 \cdot 10^{+160}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -6 \cdot 10^{+115}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{-71}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.45 \cdot 10^{+61}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \mathbf{elif}\;z \leq 3.3 \cdot 10^{+77}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{+124}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.05 \cdot 10^{+222}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 5
Error15.4
Cost1241
\[\begin{array}{l} t_1 := y \cdot \frac{z - x}{t}\\ t_2 := x + \frac{y}{\frac{t}{z}}\\ \mathbf{if}\;t \leq -7.8 \cdot 10^{-91}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -3.5 \cdot 10^{-283}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -3.1 \cdot 10^{-291}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 7.8 \cdot 10^{-188}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;t \leq 2.85 \cdot 10^{-154} \lor \neg \left(t \leq 1.95 \cdot 10^{+28}\right):\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error27.3
Cost912
\[\begin{array}{l} \mathbf{if}\;x \leq -1.5 \cdot 10^{-85}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{-130}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{+199}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6 \cdot 10^{+221}:\\ \;\;\;\;x \cdot \frac{-y}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error2.1
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -3 \cdot 10^{-78} \lor \neg \left(x \leq -6.8 \cdot 10^{-283}\right):\\ \;\;\;\;x + \left(z - x\right) \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{\frac{t}{z - x}}\\ \end{array} \]
Alternative 8
Error11.0
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -2.4 \cdot 10^{-48} \lor \neg \left(z \leq 3.8 \cdot 10^{-213}\right):\\ \;\;\;\;x + \frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x - x \cdot \frac{y}{t}\\ \end{array} \]
Alternative 9
Error26.4
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2.3 \cdot 10^{-94}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.15 \cdot 10^{-117}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error2.1
Cost576
\[x + \left(z - x\right) \cdot \frac{y}{t} \]
Alternative 11
Error32.6
Cost64
\[x \]

Error

Reproduce?

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