?

Average Error: 4.4 → 2.3
Time: 11.8s
Precision: binary64
Cost: 1992

?

\[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \]
\[\begin{array}{l} t_1 := \frac{y}{z} - \frac{t}{1 - z}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+164}:\\ \;\;\;\;t_1 \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z} - t \cdot x\\ \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 (- (/ y z) (/ t (- 1.0 z)))))
   (if (<= t_1 (- INFINITY))
     (/ y (/ z x))
     (if (<= t_1 2e+164) (* t_1 x) (- (* y (/ x z)) (* t x))))))
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 = (y / z) - (t / (1.0 - z));
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = y / (z / x);
	} else if (t_1 <= 2e+164) {
		tmp = t_1 * x;
	} else {
		tmp = (y * (x / z)) - (t * x);
	}
	return tmp;
}
public static double code(double x, double y, double z, double t) {
	return x * ((y / z) - (t / (1.0 - z)));
}
public static double code(double x, double y, double z, double t) {
	double t_1 = (y / z) - (t / (1.0 - z));
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = y / (z / x);
	} else if (t_1 <= 2e+164) {
		tmp = t_1 * x;
	} else {
		tmp = (y * (x / z)) - (t * x);
	}
	return tmp;
}
def code(x, y, z, t):
	return x * ((y / z) - (t / (1.0 - z)))
def code(x, y, z, t):
	t_1 = (y / z) - (t / (1.0 - z))
	tmp = 0
	if t_1 <= -math.inf:
		tmp = y / (z / x)
	elif t_1 <= 2e+164:
		tmp = t_1 * x
	else:
		tmp = (y * (x / z)) - (t * x)
	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(Float64(y / z) - Float64(t / Float64(1.0 - z)))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(y / Float64(z / x));
	elseif (t_1 <= 2e+164)
		tmp = Float64(t_1 * x);
	else
		tmp = Float64(Float64(y * Float64(x / z)) - Float64(t * x));
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = x * ((y / z) - (t / (1.0 - z)));
end
function tmp_2 = code(x, y, z, t)
	t_1 = (y / z) - (t / (1.0 - z));
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = y / (z / x);
	elseif (t_1 <= 2e+164)
		tmp = t_1 * x;
	else
		tmp = (y * (x / z)) - (t * x);
	end
	tmp_2 = 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[(N[(y / z), $MachinePrecision] - N[(t / N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+164], N[(t$95$1 * x), $MachinePrecision], N[(N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision] - N[(t * x), $MachinePrecision]), $MachinePrecision]]]]
x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\begin{array}{l}
t_1 := \frac{y}{z} - \frac{t}{1 - z}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+164}:\\
\;\;\;\;t_1 \cdot x\\

\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z} - t \cdot x\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original4.4
Target4.1
Herbie2.3
\[\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 3 regimes
  2. if (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < -inf.0

    1. Initial program 64.0

      \[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \]
    2. Taylor expanded in y around inf 0.3

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} \]
    3. Simplified64.0

      \[\leadsto \color{blue}{\frac{y}{z} \cdot x} \]
      Proof

      [Start]0.3

      \[ \frac{y \cdot x}{z} \]

      associate-*l/ [<=]64.0

      \[ \color{blue}{\frac{y}{z} \cdot x} \]
    4. Applied egg-rr0.2

      \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} \]

    if -inf.0 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < 2e164

    1. Initial program 1.4

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

    if 2e164 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z)))

    1. Initial program 14.1

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

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

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

      [Start]9.0

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

      +-commutative [=>]9.0

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

      associate-*r* [=>]9.0

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

      mul-1-neg [=>]9.0

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

      associate-*l/ [<=]21.6

      \[ \left(-t\right) \cdot x + \color{blue}{\frac{y}{z} \cdot x} \]
    4. Taylor expanded in t around 0 9.0

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

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

      [Start]9.0

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

      *-commutative [=>]9.0

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

      associate-*r/ [<=]21.6

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

      mul-1-neg [=>]21.6

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

      sub-neg [<=]21.6

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

      *-commutative [=>]21.6

      \[ x \cdot \frac{y}{z} - \color{blue}{x \cdot t} \]
    6. Taylor expanded in x around 0 9.0

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} - x \cdot t \]
    7. Simplified8.6

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

      [Start]9.0

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

      *-commutative [<=]9.0

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

      associate-*l/ [<=]8.6

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

      *-commutative [=>]8.6

      \[ \color{blue}{y \cdot \frac{x}{z}} - x \cdot t \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.3

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

Alternatives

Alternative 1
Error19.5
Cost980
\[\begin{array}{l} t_1 := x \cdot \frac{t}{z}\\ \mathbf{if}\;z \leq -6 \cdot 10^{+159}:\\ \;\;\;\;\frac{y}{z} \cdot x\\ \mathbf{elif}\;z \leq -1.9 \cdot 10^{+88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5 \cdot 10^{+34}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t\right)\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{+168}:\\ \;\;\;\;\frac{x}{\frac{z}{t}}\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{+251}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error5.2
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1400000000:\\ \;\;\;\;\frac{x}{\frac{z}{y + t}}\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{-5}:\\ \;\;\;\;\frac{y}{z} \cdot x - t \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y + t}{z}\\ \end{array} \]
Alternative 3
Error4.0
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1400000000:\\ \;\;\;\;\frac{x}{\frac{z}{y + t}}\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;y \cdot \frac{x}{z} - t \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y + t}{z}\\ \end{array} \]
Alternative 4
Error5.1
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1400000000 \lor \neg \left(z \leq 1.7 \cdot 10^{-5}\right):\\ \;\;\;\;x \cdot \frac{y + t}{z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t\right)\\ \end{array} \]
Alternative 5
Error5.2
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -1400000000:\\ \;\;\;\;\frac{x}{\frac{z}{y + t}}\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{-5}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y + t}{z}\\ \end{array} \]
Alternative 6
Error26.4
Cost585
\[\begin{array}{l} \mathbf{if}\;t \leq -3.9 \cdot 10^{+151} \lor \neg \left(t \leq 1.26 \cdot 10^{+141}\right):\\ \;\;\;\;t \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]
Alternative 7
Error24.2
Cost584
\[\begin{array}{l} \mathbf{if}\;t \leq -1.45 \cdot 10^{+126}:\\ \;\;\;\;x \cdot \frac{t}{z}\\ \mathbf{elif}\;t \leq 3.2 \cdot 10^{+141}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(-x\right)\\ \end{array} \]
Alternative 8
Error23.6
Cost584
\[\begin{array}{l} \mathbf{if}\;t \leq -1.65 \cdot 10^{+126}:\\ \;\;\;\;x \cdot \frac{t}{z}\\ \mathbf{elif}\;t \leq 2.3 \cdot 10^{+127}:\\ \;\;\;\;\frac{y}{z} \cdot x\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(-x\right)\\ \end{array} \]
Alternative 9
Error23.4
Cost584
\[\begin{array}{l} \mathbf{if}\;t \leq -8.6 \cdot 10^{+123}:\\ \;\;\;\;x \cdot \frac{t}{z}\\ \mathbf{elif}\;t \leq 8 \cdot 10^{+127}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(-x\right)\\ \end{array} \]
Alternative 10
Error50.6
Cost256
\[t \cdot \left(-x\right) \]

Error

Reproduce?

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