Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, C

?

Percentage Accurate: 94.4% → 98.1%
Time: 12.4s
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:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;t_1 \leq 10^{+300}:\\ \;\;\;\;t_1 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{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 (- (/ y z) (/ t (- 1.0 z)))))
   (if (<= t_1 (- INFINITY))
     (* y (/ x z))
     (if (<= t_1 1e+300) (* t_1 x) (/ (* y x) 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 = (y / z) - (t / (1.0 - z));
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = y * (x / z);
	} else if (t_1 <= 1e+300) {
		tmp = t_1 * x;
	} else {
		tmp = (y * x) / z;
	}
	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 * (x / z);
	} else if (t_1 <= 1e+300) {
		tmp = t_1 * x;
	} else {
		tmp = (y * x) / z;
	}
	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 * (x / z)
	elif t_1 <= 1e+300:
		tmp = t_1 * x
	else:
		tmp = (y * x) / 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(Float64(y / z) - Float64(t / Float64(1.0 - z)))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(y * Float64(x / z));
	elseif (t_1 <= 1e+300)
		tmp = Float64(t_1 * x);
	else
		tmp = Float64(Float64(y * x) / z);
	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 * (x / z);
	elseif (t_1 <= 1e+300)
		tmp = t_1 * x;
	else
		tmp = (y * x) / z;
	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[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e+300], N[(t$95$1 * x), $MachinePrecision], N[(N[(y * x), $MachinePrecision] / z), $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:\\
\;\;\;\;y \cdot \frac{x}{z}\\

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

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


\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 10 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original94.4%
Target95.0%
Herbie98.1%
\[\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 53.0%

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

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

      [Start]53.0%

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

      frac-2neg [=>]53.0%

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

      div-inv [=>]53.0%

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

      fma-neg [=>]53.0%

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

      distribute-neg-frac [=>]53.0%

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

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

      [Start]53.0%

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

      fma-udef [=>]53.0%

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

      +-commutative [=>]53.0%

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

      distribute-lft-neg-out [=>]53.0%

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

      unsub-neg [=>]53.0%

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

      neg-mul-1 [=>]53.0%

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

      *-commutative [=>]53.0%

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

      associate-*r/ [<=]53.0%

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

      metadata-eval [<=]53.0%

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

      associate-/r* [<=]53.0%

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

      neg-mul-1 [<=]53.0%

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

      associate-*r/ [=>]53.0%

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

      *-rgt-identity [=>]53.0%

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

      neg-sub0 [=>]53.0%

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

      associate--r- [=>]53.0%

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

      metadata-eval [=>]53.0%

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

      neg-mul-1 [=>]53.0%

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

      associate-/r* [=>]53.0%

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

      metadata-eval [=>]53.0%

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

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} \]
    5. Simplified99.8%

      \[\leadsto \color{blue}{y \cdot \frac{x}{z}} \]
      Step-by-step derivation

      [Start]99.8%

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

      associate-*r/ [<=]99.8%

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

    if -inf.0 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < 1.0000000000000001e300

    1. Initial program 98.6%

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

    if 1.0000000000000001e300 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z)))

    1. Initial program 81.2%

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

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification98.8%

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

Alternatives

Alternative 1
Accuracy98.1%
Cost1992
\[\begin{array}{l} t_1 := \frac{y}{z} - \frac{t}{1 - z}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;t_1 \leq 10^{+300}:\\ \;\;\;\;t_1 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \end{array} \]
Alternative 2
Accuracy40.3%
Cost850
\[\begin{array}{l} \mathbf{if}\;z \leq -40000000000 \lor \neg \left(z \leq -8.2 \cdot 10^{-99} \lor \neg \left(z \leq 5.2 \cdot 10^{-201}\right) \land z \leq 1\right):\\ \;\;\;\;t \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(-x\right)\\ \end{array} \]
Alternative 3
Accuracy74.8%
Cost848
\[\begin{array}{l} t_1 := \frac{y}{z} \cdot x\\ t_2 := \frac{x}{\frac{z}{t}}\\ \mathbf{if}\;z \leq -1.45 \cdot 10^{+94}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -7600000000000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{+18}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t\right)\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{+172}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Accuracy71.2%
Cost844
\[\begin{array}{l} \mathbf{if}\;t \leq -9.5 \cdot 10^{+55}:\\ \;\;\;\;x \cdot \frac{t}{z + -1}\\ \mathbf{elif}\;t \leq -9.5 \cdot 10^{-287}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{elif}\;t \leq 2.4 \cdot 10^{+34}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t\right)\\ \end{array} \]
Alternative 5
Accuracy64.7%
Cost716
\[\begin{array}{l} \mathbf{if}\;t \leq -7.8 \cdot 10^{+118}:\\ \;\;\;\;\frac{x}{\frac{z}{t}}\\ \mathbf{elif}\;t \leq -1.5 \cdot 10^{-288}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{elif}\;t \leq 5.8 \cdot 10^{+54}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]
Alternative 6
Accuracy89.0%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -40000000000 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;\frac{x}{z} \cdot \left(y + t\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t\right)\\ \end{array} \]
Alternative 7
Accuracy93.3%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -40000000000 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;\frac{x}{\frac{z}{y + t}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t\right)\\ \end{array} \]
Alternative 8
Accuracy62.6%
Cost452
\[\begin{array}{l} \mathbf{if}\;t \leq -7.6 \cdot 10^{+118}:\\ \;\;\;\;t \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]
Alternative 9
Accuracy63.8%
Cost452
\[\begin{array}{l} \mathbf{if}\;t \leq -3 \cdot 10^{+119}:\\ \;\;\;\;\frac{x}{\frac{z}{t}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]
Alternative 10
Accuracy22.8%
Cost256
\[t \cdot \left(-x\right) \]

Reproduce?

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