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

Percentage Accurate: 99.9% → 99.9%
Time: 6.9s
Alternatives: 9
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left(1 - x\right) + y \cdot \sqrt{x} \end{array} \]
(FPCore (x y) :precision binary64 (+ (- 1.0 x) (* y (sqrt x))))
double code(double x, double y) {
	return (1.0 - x) + (y * sqrt(x));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (1.0d0 - x) + (y * sqrt(x))
end function
public static double code(double x, double y) {
	return (1.0 - x) + (y * Math.sqrt(x));
}
def code(x, y):
	return (1.0 - x) + (y * math.sqrt(x))
function code(x, y)
	return Float64(Float64(1.0 - x) + Float64(y * sqrt(x)))
end
function tmp = code(x, y)
	tmp = (1.0 - x) + (y * sqrt(x));
end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(1 - x\right) + y \cdot \sqrt{x}
\end{array}

Sampling outcomes in binary64 precision:

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.

Accuracy vs Speed?

Herbie found 9 alternatives:

AlternativeAccuracySpeedup
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.

Initial Program: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(1 - x\right) + y \cdot \sqrt{x} \end{array} \]
(FPCore (x y) :precision binary64 (+ (- 1.0 x) (* y (sqrt x))))
double code(double x, double y) {
	return (1.0 - x) + (y * sqrt(x));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (1.0d0 - x) + (y * sqrt(x))
end function
public static double code(double x, double y) {
	return (1.0 - x) + (y * Math.sqrt(x));
}
def code(x, y):
	return (1.0 - x) + (y * math.sqrt(x))
function code(x, y)
	return Float64(Float64(1.0 - x) + Float64(y * sqrt(x)))
end
function tmp = code(x, y)
	tmp = (1.0 - x) + (y * sqrt(x));
end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(1 - x\right) + y \cdot \sqrt{x}
\end{array}

Alternative 1: 99.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(y, \sqrt{x}, 1 - x\right) \end{array} \]
(FPCore (x y) :precision binary64 (fma y (sqrt x) (- 1.0 x)))
double code(double x, double y) {
	return fma(y, sqrt(x), (1.0 - x));
}
function code(x, y)
	return fma(y, sqrt(x), Float64(1.0 - x))
end
code[x_, y_] := N[(y * N[Sqrt[x], $MachinePrecision] + N[(1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(y, \sqrt{x}, 1 - x\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(1 - x\right) + y \cdot \sqrt{x} \]
  2. Step-by-step derivation
    1. +-commutative99.9%

      \[\leadsto \color{blue}{y \cdot \sqrt{x} + \left(1 - x\right)} \]
    2. fma-define99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \sqrt{x}, 1 - x\right)} \]
  3. Simplified99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, \sqrt{x}, 1 - x\right)} \]
  4. Add Preprocessing
  5. Final simplification99.9%

    \[\leadsto \mathsf{fma}\left(y, \sqrt{x}, 1 - x\right) \]
  6. Add Preprocessing

Alternative 2: 94.8% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{+71} \lor \neg \left(y \leq 5.5 \cdot 10^{+37}\right):\\ \;\;\;\;1 + y \cdot \sqrt{x}\\ \mathbf{else}:\\ \;\;\;\;1 - x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= y -5e+71) (not (<= y 5.5e+37))) (+ 1.0 (* y (sqrt x))) (- 1.0 x)))
double code(double x, double y) {
	double tmp;
	if ((y <= -5e+71) || !(y <= 5.5e+37)) {
		tmp = 1.0 + (y * sqrt(x));
	} else {
		tmp = 1.0 - x;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((y <= (-5d+71)) .or. (.not. (y <= 5.5d+37))) then
        tmp = 1.0d0 + (y * sqrt(x))
    else
        tmp = 1.0d0 - x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((y <= -5e+71) || !(y <= 5.5e+37)) {
		tmp = 1.0 + (y * Math.sqrt(x));
	} else {
		tmp = 1.0 - x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (y <= -5e+71) or not (y <= 5.5e+37):
		tmp = 1.0 + (y * math.sqrt(x))
	else:
		tmp = 1.0 - x
	return tmp
function code(x, y)
	tmp = 0.0
	if ((y <= -5e+71) || !(y <= 5.5e+37))
		tmp = Float64(1.0 + Float64(y * sqrt(x)));
	else
		tmp = Float64(1.0 - x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((y <= -5e+71) || ~((y <= 5.5e+37)))
		tmp = 1.0 + (y * sqrt(x));
	else
		tmp = 1.0 - x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[y, -5e+71], N[Not[LessEqual[y, 5.5e+37]], $MachinePrecision]], N[(1.0 + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+71} \lor \neg \left(y \leq 5.5 \cdot 10^{+37}\right):\\
\;\;\;\;1 + y \cdot \sqrt{x}\\

\mathbf{else}:\\
\;\;\;\;1 - x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -4.99999999999999972e71 or 5.50000000000000016e37 < y

    1. Initial program 99.7%

      \[\left(1 - x\right) + y \cdot \sqrt{x} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 96.6%

      \[\leadsto \color{blue}{1 + \sqrt{x} \cdot y} \]

    if -4.99999999999999972e71 < y < 5.50000000000000016e37

    1. Initial program 100.0%

      \[\left(1 - x\right) + y \cdot \sqrt{x} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 97.0%

      \[\leadsto \color{blue}{1 - x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{+71} \lor \neg \left(y \leq 5.5 \cdot 10^{+37}\right):\\ \;\;\;\;1 + y \cdot \sqrt{x}\\ \mathbf{else}:\\ \;\;\;\;1 - x\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 92.2% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -7.5 \cdot 10^{+73} \lor \neg \left(y \leq 8.6 \cdot 10^{+48}\right):\\ \;\;\;\;y \cdot \sqrt{x}\\ \mathbf{else}:\\ \;\;\;\;1 - x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= y -7.5e+73) (not (<= y 8.6e+48))) (* y (sqrt x)) (- 1.0 x)))
double code(double x, double y) {
	double tmp;
	if ((y <= -7.5e+73) || !(y <= 8.6e+48)) {
		tmp = y * sqrt(x);
	} else {
		tmp = 1.0 - x;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((y <= (-7.5d+73)) .or. (.not. (y <= 8.6d+48))) then
        tmp = y * sqrt(x)
    else
        tmp = 1.0d0 - x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((y <= -7.5e+73) || !(y <= 8.6e+48)) {
		tmp = y * Math.sqrt(x);
	} else {
		tmp = 1.0 - x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (y <= -7.5e+73) or not (y <= 8.6e+48):
		tmp = y * math.sqrt(x)
	else:
		tmp = 1.0 - x
	return tmp
function code(x, y)
	tmp = 0.0
	if ((y <= -7.5e+73) || !(y <= 8.6e+48))
		tmp = Float64(y * sqrt(x));
	else
		tmp = Float64(1.0 - x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((y <= -7.5e+73) || ~((y <= 8.6e+48)))
		tmp = y * sqrt(x);
	else
		tmp = 1.0 - x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[y, -7.5e+73], N[Not[LessEqual[y, 8.6e+48]], $MachinePrecision]], N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{+73} \lor \neg \left(y \leq 8.6 \cdot 10^{+48}\right):\\
\;\;\;\;y \cdot \sqrt{x}\\

\mathbf{else}:\\
\;\;\;\;1 - x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -7.5e73 or 8.59999999999999957e48 < y

    1. Initial program 99.7%

      \[\left(1 - x\right) + y \cdot \sqrt{x} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. +-commutative99.7%

        \[\leadsto \color{blue}{y \cdot \sqrt{x} + \left(1 - x\right)} \]
      2. *-commutative99.7%

        \[\leadsto \color{blue}{\sqrt{x} \cdot y} + \left(1 - x\right) \]
      3. add-sqr-sqrt99.3%

        \[\leadsto \color{blue}{\left(\sqrt{\sqrt{x}} \cdot \sqrt{\sqrt{x}}\right)} \cdot y + \left(1 - x\right) \]
      4. associate-*l*99.3%

        \[\leadsto \color{blue}{\sqrt{\sqrt{x}} \cdot \left(\sqrt{\sqrt{x}} \cdot y\right)} + \left(1 - x\right) \]
      5. fma-define99.3%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\sqrt{x}}, \sqrt{\sqrt{x}} \cdot y, 1 - x\right)} \]
      6. pow1/299.3%

        \[\leadsto \mathsf{fma}\left(\sqrt{\color{blue}{{x}^{0.5}}}, \sqrt{\sqrt{x}} \cdot y, 1 - x\right) \]
      7. sqrt-pow199.4%

        \[\leadsto \mathsf{fma}\left(\color{blue}{{x}^{\left(\frac{0.5}{2}\right)}}, \sqrt{\sqrt{x}} \cdot y, 1 - x\right) \]
      8. metadata-eval99.4%

        \[\leadsto \mathsf{fma}\left({x}^{\color{blue}{0.25}}, \sqrt{\sqrt{x}} \cdot y, 1 - x\right) \]
      9. pow1/299.4%

        \[\leadsto \mathsf{fma}\left({x}^{0.25}, \sqrt{\color{blue}{{x}^{0.5}}} \cdot y, 1 - x\right) \]
      10. sqrt-pow199.3%

        \[\leadsto \mathsf{fma}\left({x}^{0.25}, \color{blue}{{x}^{\left(\frac{0.5}{2}\right)}} \cdot y, 1 - x\right) \]
      11. metadata-eval99.3%

        \[\leadsto \mathsf{fma}\left({x}^{0.25}, {x}^{\color{blue}{0.25}} \cdot y, 1 - x\right) \]
    4. Applied egg-rr99.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{0.25}, {x}^{0.25} \cdot y, 1 - x\right)} \]
    5. Taylor expanded in y around inf 88.8%

      \[\leadsto \color{blue}{\sqrt{x} \cdot y} \]

    if -7.5e73 < y < 8.59999999999999957e48

    1. Initial program 100.0%

      \[\left(1 - x\right) + y \cdot \sqrt{x} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 97.0%

      \[\leadsto \color{blue}{1 - x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification93.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -7.5 \cdot 10^{+73} \lor \neg \left(y \leq 8.6 \cdot 10^{+48}\right):\\ \;\;\;\;y \cdot \sqrt{x}\\ \mathbf{else}:\\ \;\;\;\;1 - x\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 98.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.6:\\ \;\;\;\;1 + y \cdot \sqrt{x}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\frac{y}{\sqrt{x}} + -1\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x 0.6) (+ 1.0 (* y (sqrt x))) (* x (+ (/ y (sqrt x)) -1.0))))
double code(double x, double y) {
	double tmp;
	if (x <= 0.6) {
		tmp = 1.0 + (y * sqrt(x));
	} else {
		tmp = x * ((y / sqrt(x)) + -1.0);
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= 0.6d0) then
        tmp = 1.0d0 + (y * sqrt(x))
    else
        tmp = x * ((y / sqrt(x)) + (-1.0d0))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= 0.6) {
		tmp = 1.0 + (y * Math.sqrt(x));
	} else {
		tmp = x * ((y / Math.sqrt(x)) + -1.0);
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= 0.6:
		tmp = 1.0 + (y * math.sqrt(x))
	else:
		tmp = x * ((y / math.sqrt(x)) + -1.0)
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= 0.6)
		tmp = Float64(1.0 + Float64(y * sqrt(x)));
	else
		tmp = Float64(x * Float64(Float64(y / sqrt(x)) + -1.0));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= 0.6)
		tmp = 1.0 + (y * sqrt(x));
	else
		tmp = x * ((y / sqrt(x)) + -1.0);
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, 0.6], N[(1.0 + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(y / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.6:\\
\;\;\;\;1 + y \cdot \sqrt{x}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 0.599999999999999978

    1. Initial program 99.9%

      \[\left(1 - x\right) + y \cdot \sqrt{x} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 99.3%

      \[\leadsto \color{blue}{1 + \sqrt{x} \cdot y} \]

    if 0.599999999999999978 < x

    1. Initial program 99.8%

      \[\left(1 - x\right) + y \cdot \sqrt{x} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 98.4%

      \[\leadsto \color{blue}{x \cdot \left(\sqrt{\frac{1}{x}} \cdot y - 1\right)} \]
    4. Step-by-step derivation
      1. *-commutative98.4%

        \[\leadsto x \cdot \left(\color{blue}{y \cdot \sqrt{\frac{1}{x}}} - 1\right) \]
      2. sqrt-div98.3%

        \[\leadsto x \cdot \left(y \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{x}}} - 1\right) \]
      3. metadata-eval98.3%

        \[\leadsto x \cdot \left(y \cdot \frac{\color{blue}{1}}{\sqrt{x}} - 1\right) \]
      4. un-div-inv98.4%

        \[\leadsto x \cdot \left(\color{blue}{\frac{y}{\sqrt{x}}} - 1\right) \]
    5. Applied egg-rr98.4%

      \[\leadsto x \cdot \left(\color{blue}{\frac{y}{\sqrt{x}}} - 1\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.6:\\ \;\;\;\;1 + y \cdot \sqrt{x}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\frac{y}{\sqrt{x}} + -1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 98.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \sqrt{x}\\ \mathbf{if}\;x \leq 1.25 \cdot 10^{-9}:\\ \;\;\;\;1 + t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_0 - x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* y (sqrt x)))) (if (<= x 1.25e-9) (+ 1.0 t_0) (- t_0 x))))
double code(double x, double y) {
	double t_0 = y * sqrt(x);
	double tmp;
	if (x <= 1.25e-9) {
		tmp = 1.0 + t_0;
	} else {
		tmp = t_0 - x;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: tmp
    t_0 = y * sqrt(x)
    if (x <= 1.25d-9) then
        tmp = 1.0d0 + t_0
    else
        tmp = t_0 - x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = y * Math.sqrt(x);
	double tmp;
	if (x <= 1.25e-9) {
		tmp = 1.0 + t_0;
	} else {
		tmp = t_0 - x;
	}
	return tmp;
}
def code(x, y):
	t_0 = y * math.sqrt(x)
	tmp = 0
	if x <= 1.25e-9:
		tmp = 1.0 + t_0
	else:
		tmp = t_0 - x
	return tmp
function code(x, y)
	t_0 = Float64(y * sqrt(x))
	tmp = 0.0
	if (x <= 1.25e-9)
		tmp = Float64(1.0 + t_0);
	else
		tmp = Float64(t_0 - x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = y * sqrt(x);
	tmp = 0.0;
	if (x <= 1.25e-9)
		tmp = 1.0 + t_0;
	else
		tmp = t_0 - x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 1.25e-9], N[(1.0 + t$95$0), $MachinePrecision], N[(t$95$0 - x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := y \cdot \sqrt{x}\\
\mathbf{if}\;x \leq 1.25 \cdot 10^{-9}:\\
\;\;\;\;1 + t\_0\\

\mathbf{else}:\\
\;\;\;\;t\_0 - x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.25e-9

    1. Initial program 99.9%

      \[\left(1 - x\right) + y \cdot \sqrt{x} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 99.3%

      \[\leadsto \color{blue}{1 + \sqrt{x} \cdot y} \]

    if 1.25e-9 < x

    1. Initial program 99.8%

      \[\left(1 - x\right) + y \cdot \sqrt{x} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 98.4%

      \[\leadsto \color{blue}{x \cdot \left(\sqrt{\frac{1}{x}} \cdot y - 1\right)} \]
    4. Taylor expanded in x around 0 98.5%

      \[\leadsto \color{blue}{-1 \cdot x + \sqrt{x} \cdot y} \]
    5. Step-by-step derivation
      1. neg-mul-198.5%

        \[\leadsto \color{blue}{\left(-x\right)} + \sqrt{x} \cdot y \]
      2. +-commutative98.5%

        \[\leadsto \color{blue}{\sqrt{x} \cdot y + \left(-x\right)} \]
      3. *-commutative98.5%

        \[\leadsto \color{blue}{y \cdot \sqrt{x}} + \left(-x\right) \]
      4. sub-neg98.5%

        \[\leadsto \color{blue}{y \cdot \sqrt{x} - x} \]
    6. Simplified98.5%

      \[\leadsto \color{blue}{y \cdot \sqrt{x} - x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.25 \cdot 10^{-9}:\\ \;\;\;\;1 + y \cdot \sqrt{x}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \sqrt{x} - x\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(1 - x\right) + y \cdot \sqrt{x} \end{array} \]
(FPCore (x y) :precision binary64 (+ (- 1.0 x) (* y (sqrt x))))
double code(double x, double y) {
	return (1.0 - x) + (y * sqrt(x));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (1.0d0 - x) + (y * sqrt(x))
end function
public static double code(double x, double y) {
	return (1.0 - x) + (y * Math.sqrt(x));
}
def code(x, y):
	return (1.0 - x) + (y * math.sqrt(x))
function code(x, y)
	return Float64(Float64(1.0 - x) + Float64(y * sqrt(x)))
end
function tmp = code(x, y)
	tmp = (1.0 - x) + (y * sqrt(x));
end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(1 - x\right) + y \cdot \sqrt{x}
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(1 - x\right) + y \cdot \sqrt{x} \]
  2. Add Preprocessing
  3. Final simplification99.9%

    \[\leadsto \left(1 - x\right) + y \cdot \sqrt{x} \]
  4. Add Preprocessing

Alternative 7: 61.8% accurate, 15.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.6:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \end{array} \]
(FPCore (x y) :precision binary64 (if (<= x 0.6) 1.0 (- x)))
double code(double x, double y) {
	double tmp;
	if (x <= 0.6) {
		tmp = 1.0;
	} else {
		tmp = -x;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= 0.6d0) then
        tmp = 1.0d0
    else
        tmp = -x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= 0.6) {
		tmp = 1.0;
	} else {
		tmp = -x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= 0.6:
		tmp = 1.0
	else:
		tmp = -x
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= 0.6)
		tmp = 1.0;
	else
		tmp = Float64(-x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= 0.6)
		tmp = 1.0;
	else
		tmp = -x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, 0.6], 1.0, (-x)]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.6:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;-x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 0.599999999999999978

    1. Initial program 99.9%

      \[\left(1 - x\right) + y \cdot \sqrt{x} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 99.3%

      \[\leadsto \color{blue}{1 + \sqrt{x} \cdot y} \]
    4. Taylor expanded in y around 0 63.2%

      \[\leadsto \color{blue}{1} \]

    if 0.599999999999999978 < x

    1. Initial program 99.8%

      \[\left(1 - x\right) + y \cdot \sqrt{x} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 98.4%

      \[\leadsto \color{blue}{x \cdot \left(\sqrt{\frac{1}{x}} \cdot y - 1\right)} \]
    4. Taylor expanded in y around 0 58.0%

      \[\leadsto \color{blue}{-1 \cdot x} \]
    5. Step-by-step derivation
      1. neg-mul-158.0%

        \[\leadsto \color{blue}{-x} \]
    6. Simplified58.0%

      \[\leadsto \color{blue}{-x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification60.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.6:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 62.7% accurate, 35.7× speedup?

\[\begin{array}{l} \\ 1 - x \end{array} \]
(FPCore (x y) :precision binary64 (- 1.0 x))
double code(double x, double y) {
	return 1.0 - x;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = 1.0d0 - x
end function
public static double code(double x, double y) {
	return 1.0 - x;
}
def code(x, y):
	return 1.0 - x
function code(x, y)
	return Float64(1.0 - x)
end
function tmp = code(x, y)
	tmp = 1.0 - x;
end
code[x_, y_] := N[(1.0 - x), $MachinePrecision]
\begin{array}{l}

\\
1 - x
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(1 - x\right) + y \cdot \sqrt{x} \]
  2. Add Preprocessing
  3. Taylor expanded in y around 0 61.6%

    \[\leadsto \color{blue}{1 - x} \]
  4. Final simplification61.6%

    \[\leadsto 1 - x \]
  5. Add Preprocessing

Alternative 9: 31.9% accurate, 107.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
	return 1.0;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = 1.0d0
end function
public static double code(double x, double y) {
	return 1.0;
}
def code(x, y):
	return 1.0
function code(x, y)
	return 1.0
end
function tmp = code(x, y)
	tmp = 1.0;
end
code[x_, y_] := 1.0
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(1 - x\right) + y \cdot \sqrt{x} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 70.7%

    \[\leadsto \color{blue}{1 + \sqrt{x} \cdot y} \]
  4. Taylor expanded in y around 0 32.9%

    \[\leadsto \color{blue}{1} \]
  5. Final simplification32.9%

    \[\leadsto 1 \]
  6. Add Preprocessing

Reproduce

?
herbie shell --seed 2024073 
(FPCore (x y)
  :name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
  :precision binary64
  (+ (- 1.0 x) (* y (sqrt x))))