Average Error: 4.7 → 3.7
Time: 11.9s
Precision: binary64
Cost: 8713
\[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \]
\[\begin{array}{l} t_1 := \frac{t}{1 - z}\\ t_2 := \frac{y}{z} - t_1\\ \mathbf{if}\;t_2 \leq -1 \cdot 10^{-210} \lor \neg \left(t_2 \leq 0\right):\\ \;\;\;\;\frac{x}{\frac{z}{y}} - t_1 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, 1 - z, -z \cdot t\right)}{z} \cdot \frac{x}{1 - z}\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (* x (- (/ y z) (/ t (- 1.0 z)))))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (/ t (- 1.0 z))) (t_2 (- (/ y z) t_1)))
   (if (or (<= t_2 -1e-210) (not (<= t_2 0.0)))
     (- (/ x (/ z y)) (* t_1 x))
     (* (/ (fma y (- 1.0 z) (- (* z t))) z) (/ x (- 1.0 z))))))
double code(double x, double y, double z, double t) {
	return x * ((y / z) - (t / (1.0 - z)));
}
double code(double x, double y, double z, double t) {
	double t_1 = t / (1.0 - z);
	double t_2 = (y / z) - t_1;
	double tmp;
	if ((t_2 <= -1e-210) || !(t_2 <= 0.0)) {
		tmp = (x / (z / y)) - (t_1 * x);
	} else {
		tmp = (fma(y, (1.0 - z), -(z * t)) / z) * (x / (1.0 - z));
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(x * Float64(Float64(y / z) - Float64(t / Float64(1.0 - z))))
end
function code(x, y, z, t)
	t_1 = Float64(t / Float64(1.0 - z))
	t_2 = Float64(Float64(y / z) - t_1)
	tmp = 0.0
	if ((t_2 <= -1e-210) || !(t_2 <= 0.0))
		tmp = Float64(Float64(x / Float64(z / y)) - Float64(t_1 * x));
	else
		tmp = Float64(Float64(fma(y, Float64(1.0 - z), Float64(-Float64(z * t))) / z) * Float64(x / Float64(1.0 - z)));
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(x * N[(N[(y / z), $MachinePrecision] - N[(t / N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(t / N[(1.0 - z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(y / z), $MachinePrecision] - t$95$1), $MachinePrecision]}, If[Or[LessEqual[t$95$2, -1e-210], N[Not[LessEqual[t$95$2, 0.0]], $MachinePrecision]], N[(N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision] - N[(t$95$1 * x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y * N[(1.0 - z), $MachinePrecision] + (-N[(z * t), $MachinePrecision])), $MachinePrecision] / z), $MachinePrecision] * N[(x / N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\begin{array}{l}
t_1 := \frac{t}{1 - z}\\
t_2 := \frac{y}{z} - t_1\\
\mathbf{if}\;t_2 \leq -1 \cdot 10^{-210} \lor \neg \left(t_2 \leq 0\right):\\
\;\;\;\;\frac{x}{\frac{z}{y}} - t_1 \cdot x\\

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


\end{array}

Error

Target

Original4.7
Target4.2
Herbie3.7
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) < -7.623226303312042 \cdot 10^{-196}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t \cdot \frac{1}{1 - z}\right)\\ \mathbf{elif}\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) < 1.4133944927702302 \cdot 10^{-211}:\\ \;\;\;\;\frac{y \cdot x}{z} + \left(-\frac{t \cdot x}{1 - z}\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t \cdot \frac{1}{1 - z}\right)\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < -1e-210 or 0.0 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z)))

    1. Initial program 4.0

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

      \[\leadsto \color{blue}{\frac{-t}{1 - z} \cdot x + \frac{y}{z} \cdot x} \]
    3. Applied egg-rr3.7

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

    if -1e-210 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < 0.0

    1. Initial program 14.0

      \[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \]
    2. Applied egg-rr24.9

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

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

      [Start]24.9

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

      associate-/l* [=>]14.9

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

      associate-/r/ [=>]3.3

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

      /-rgt-identity [<=]3.3

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

      /-rgt-identity [=>]3.3

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

      fma-neg [=>]3.3

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

      distribute-rgt-neg-out [<=]3.3

      \[ \frac{\mathsf{fma}\left(y, 1 - z, \color{blue}{z \cdot \left(-t\right)}\right)}{z} \cdot \frac{x}{1 - z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification3.7

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

Alternatives

Alternative 1
Error3.7
Cost2121
\[\begin{array}{l} t_1 := \frac{t}{1 - z}\\ t_2 := \frac{y}{z} - t_1\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{-174} \lor \neg \left(t_2 \leq 5 \cdot 10^{-200}\right):\\ \;\;\;\;\frac{x}{\frac{z}{y}} - t_1 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(y + t\right)}{z}\\ \end{array} \]
Alternative 2
Error3.9
Cost1993
\[\begin{array}{l} t_1 := \frac{y}{z} - \frac{t}{1 - z}\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{-166} \lor \neg \left(t_1 \leq 0\right):\\ \;\;\;\;t_1 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(y + t\right)}{z}\\ \end{array} \]
Alternative 3
Error3.9
Cost1992
\[\begin{array}{l} t_1 := \frac{t}{1 - z}\\ t_2 := \frac{y}{z} - t_1\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{-174}:\\ \;\;\;\;\frac{y}{z} \cdot x - t_1 \cdot x\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;\frac{x \cdot \left(y + t\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;t_2 \cdot x\\ \end{array} \]
Alternative 4
Error26.9
Cost1113
\[\begin{array}{l} t_1 := y \cdot \frac{x}{z}\\ \mathbf{if}\;y \leq -1.3 \cdot 10^{-138}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.4 \cdot 10^{-237}:\\ \;\;\;\;t \cdot \frac{x}{z}\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{-280}:\\ \;\;\;\;t \cdot \left(-x\right)\\ \mathbf{elif}\;y \leq 2.46 \cdot 10^{-57} \lor \neg \left(y \leq 6.5 \cdot 10^{-40}\right) \land y \leq 7.2 \cdot 10^{-8}:\\ \;\;\;\;x \cdot \frac{t}{z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error20.4
Cost980
\[\begin{array}{l} \mathbf{if}\;z \leq -9 \cdot 10^{+28}:\\ \;\;\;\;\frac{y}{z} \cdot x\\ \mathbf{elif}\;z \leq -52000:\\ \;\;\;\;x \cdot \frac{t}{z}\\ \mathbf{elif}\;z \leq 7 \cdot 10^{+55}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t\right)\\ \mathbf{elif}\;z \leq 3.8 \cdot 10^{+240}:\\ \;\;\;\;\frac{x}{\frac{z}{t}}\\ \mathbf{elif}\;z \leq 1.02 \cdot 10^{+278}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{t \cdot x}{z}\\ \end{array} \]
Alternative 6
Error26.9
Cost848
\[\begin{array}{l} t_1 := y \cdot \frac{x}{z}\\ t_2 := t \cdot \frac{x}{z}\\ \mathbf{if}\;y \leq -1.35 \cdot 10^{-138}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.2 \cdot 10^{-237}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 5.9 \cdot 10^{-300}:\\ \;\;\;\;t \cdot \left(-x\right)\\ \mathbf{elif}\;y \leq 4 \cdot 10^{-56}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error24.5
Cost848
\[\begin{array}{l} t_1 := x \cdot \frac{t}{z}\\ \mathbf{if}\;t \leq -1.95 \cdot 10^{+146}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.55 \cdot 10^{+70}:\\ \;\;\;\;t \cdot \left(-x\right)\\ \mathbf{elif}\;t \leq -4 \cdot 10^{-10}:\\ \;\;\;\;t \cdot \frac{x}{z}\\ \mathbf{elif}\;t \leq 7.2 \cdot 10^{+40}:\\ \;\;\;\;\frac{y}{z} \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error24.4
Cost848
\[\begin{array}{l} \mathbf{if}\;t \leq -1.95 \cdot 10^{+146}:\\ \;\;\;\;\frac{x}{\frac{z}{t}}\\ \mathbf{elif}\;t \leq -2.5 \cdot 10^{+70}:\\ \;\;\;\;t \cdot \left(-x\right)\\ \mathbf{elif}\;t \leq -4 \cdot 10^{-10}:\\ \;\;\;\;t \cdot \frac{x}{z}\\ \mathbf{elif}\;t \leq 2.5 \cdot 10^{+41}:\\ \;\;\;\;\frac{y}{z} \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{t}{z}\\ \end{array} \]
Alternative 9
Error24.4
Cost848
\[\begin{array}{l} \mathbf{if}\;t \leq -1.95 \cdot 10^{+146}:\\ \;\;\;\;\frac{x}{\frac{z}{t}}\\ \mathbf{elif}\;t \leq -3 \cdot 10^{+69}:\\ \;\;\;\;t \cdot \left(-x\right)\\ \mathbf{elif}\;t \leq -2 \cdot 10^{-10}:\\ \;\;\;\;t \cdot \frac{x}{z}\\ \mathbf{elif}\;t \leq 1.7 \cdot 10^{+40}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{t}{z}\\ \end{array} \]
Alternative 10
Error5.2
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;x \cdot \frac{y + t}{z}\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{x}{\frac{z}{y}} - t \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{y + t}}\\ \end{array} \]
Alternative 11
Error18.8
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -3.5 \cdot 10^{-10} \lor \neg \left(t \leq 1.15 \cdot 10^{+39}\right):\\ \;\;\;\;t \cdot \frac{x}{z + -1}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \end{array} \]
Alternative 12
Error5.4
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;x \cdot \frac{y + t}{z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t\right)\\ \end{array} \]
Alternative 13
Error5.5
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;x \cdot \frac{y + t}{z}\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{y + t}}\\ \end{array} \]
Alternative 14
Error35.4
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;t \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(-x\right)\\ \end{array} \]
Alternative 15
Error50.5
Cost256
\[t \cdot \left(-x\right) \]

Error

Reproduce

herbie shell --seed 2023016 
(FPCore (x y z t)
  :name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, C"
  :precision binary64

  :herbie-target
  (if (< (* x (- (/ y z) (/ t (- 1.0 z)))) -7.623226303312042e-196) (* x (- (/ y z) (* t (/ 1.0 (- 1.0 z))))) (if (< (* x (- (/ y z) (/ t (- 1.0 z)))) 1.4133944927702302e-211) (+ (/ (* y x) z) (- (/ (* t x) (- 1.0 z)))) (* x (- (/ y z) (* t (/ 1.0 (- 1.0 z)))))))

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