Numeric.SpecFunctions:invIncompleteGamma from math-functions-0.1.5.2, B

Percentage Accurate: 71.8% → 99.8%
Time: 1.2min
Alternatives: 7
Speedup: 3.7×

Specification

?
\[1 - \log \left(1 - \frac{x - y}{1 - y}\right) \]
(FPCore (x y)
  :precision binary64
  (- 1 (log (- 1 (/ (- x y) (- 1 y))))))
double code(double x, double y) {
	return 1.0 - log((1.0 - ((x - y) / (1.0 - y))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = 1.0d0 - log((1.0d0 - ((x - y) / (1.0d0 - y))))
end function
public static double code(double x, double y) {
	return 1.0 - Math.log((1.0 - ((x - y) / (1.0 - y))));
}
def code(x, y):
	return 1.0 - math.log((1.0 - ((x - y) / (1.0 - y))))
function code(x, y)
	return Float64(1.0 - log(Float64(1.0 - Float64(Float64(x - y) / Float64(1.0 - y)))))
end
function tmp = code(x, y)
	tmp = 1.0 - log((1.0 - ((x - y) / (1.0 - y))));
end
code[x_, y_] := N[(1 - N[Log[N[(1 - N[(N[(x - y), $MachinePrecision] / N[(1 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)

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 7 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: 71.8% accurate, 1.0× speedup?

\[1 - \log \left(1 - \frac{x - y}{1 - y}\right) \]
(FPCore (x y)
  :precision binary64
  (- 1 (log (- 1 (/ (- x y) (- 1 y))))))
double code(double x, double y) {
	return 1.0 - log((1.0 - ((x - y) / (1.0 - y))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = 1.0d0 - log((1.0d0 - ((x - y) / (1.0d0 - y))))
end function
public static double code(double x, double y) {
	return 1.0 - Math.log((1.0 - ((x - y) / (1.0 - y))));
}
def code(x, y):
	return 1.0 - math.log((1.0 - ((x - y) / (1.0 - y))))
function code(x, y)
	return Float64(1.0 - log(Float64(1.0 - Float64(Float64(x - y) / Float64(1.0 - y)))))
end
function tmp = code(x, y)
	tmp = 1.0 - log((1.0 - ((x - y) / (1.0 - y))));
end
code[x_, y_] := N[(1 - N[Log[N[(1 - N[(N[(x - y), $MachinePrecision] / N[(1 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)

Alternative 1: 99.8% accurate, 0.5× speedup?

\[\begin{array}{l} \mathbf{if}\;1 - \log \left(1 - \frac{x - y}{1 - y}\right) \leq 15:\\ \;\;\;\;1 - \log \left(\frac{\left(y - x\right) - \left(y - 1\right)}{1 - y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \log \left(\frac{x - 1}{y}\right)\\ \end{array} \]
(FPCore (x y)
  :precision binary64
  (if (<= (- 1 (log (- 1 (/ (- x y) (- 1 y))))) 15)
  (- 1 (log (/ (- (- y x) (- y 1)) (- 1 y))))
  (- 1 (log (/ (- x 1) y)))))
double code(double x, double y) {
	double tmp;
	if ((1.0 - log((1.0 - ((x - y) / (1.0 - y))))) <= 15.0) {
		tmp = 1.0 - log((((y - x) - (y - 1.0)) / (1.0 - y)));
	} else {
		tmp = 1.0 - log(((x - 1.0) / y));
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((1.0d0 - log((1.0d0 - ((x - y) / (1.0d0 - y))))) <= 15.0d0) then
        tmp = 1.0d0 - log((((y - x) - (y - 1.0d0)) / (1.0d0 - y)))
    else
        tmp = 1.0d0 - log(((x - 1.0d0) / y))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((1.0 - Math.log((1.0 - ((x - y) / (1.0 - y))))) <= 15.0) {
		tmp = 1.0 - Math.log((((y - x) - (y - 1.0)) / (1.0 - y)));
	} else {
		tmp = 1.0 - Math.log(((x - 1.0) / y));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (1.0 - math.log((1.0 - ((x - y) / (1.0 - y))))) <= 15.0:
		tmp = 1.0 - math.log((((y - x) - (y - 1.0)) / (1.0 - y)))
	else:
		tmp = 1.0 - math.log(((x - 1.0) / y))
	return tmp
function code(x, y)
	tmp = 0.0
	if (Float64(1.0 - log(Float64(1.0 - Float64(Float64(x - y) / Float64(1.0 - y))))) <= 15.0)
		tmp = Float64(1.0 - log(Float64(Float64(Float64(y - x) - Float64(y - 1.0)) / Float64(1.0 - y))));
	else
		tmp = Float64(1.0 - log(Float64(Float64(x - 1.0) / y)));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((1.0 - log((1.0 - ((x - y) / (1.0 - y))))) <= 15.0)
		tmp = 1.0 - log((((y - x) - (y - 1.0)) / (1.0 - y)));
	else
		tmp = 1.0 - log(((x - 1.0) / y));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[N[(1 - N[Log[N[(1 - N[(N[(x - y), $MachinePrecision] / N[(1 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 15], N[(1 - N[Log[N[(N[(N[(y - x), $MachinePrecision] - N[(y - 1), $MachinePrecision]), $MachinePrecision] / N[(1 - y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1 - N[Log[N[(N[(x - 1), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;1 - \log \left(1 - \frac{x - y}{1 - y}\right) \leq 15:\\
\;\;\;\;1 - \log \left(\frac{\left(y - x\right) - \left(y - 1\right)}{1 - y}\right)\\

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 #s(literal 1 binary64) (log.f64 (-.f64 #s(literal 1 binary64) (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y))))) < 15

    1. Initial program 71.8%

      \[1 - \log \left(1 - \frac{x - y}{1 - y}\right) \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto 1 - \log \color{blue}{\left(1 - \frac{x - y}{1 - y}\right)} \]
      2. lift-/.f64N/A

        \[\leadsto 1 - \log \left(1 - \color{blue}{\frac{x - y}{1 - y}}\right) \]
      3. sub-to-fractionN/A

        \[\leadsto 1 - \log \color{blue}{\left(\frac{1 \cdot \left(1 - y\right) - \left(x - y\right)}{1 - y}\right)} \]
      4. frac-2negN/A

        \[\leadsto 1 - \log \color{blue}{\left(\frac{\mathsf{neg}\left(\left(1 \cdot \left(1 - y\right) - \left(x - y\right)\right)\right)}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right)} \]
      5. distribute-neg-fracN/A

        \[\leadsto 1 - \log \color{blue}{\left(\mathsf{neg}\left(\frac{1 \cdot \left(1 - y\right) - \left(x - y\right)}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right)\right)} \]
      6. distribute-frac-neg2N/A

        \[\leadsto 1 - \log \color{blue}{\left(\frac{1 \cdot \left(1 - y\right) - \left(x - y\right)}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(1 - y\right)\right)\right)\right)}\right)} \]
      7. sub-negate-revN/A

        \[\leadsto 1 - \log \left(\frac{\color{blue}{\mathsf{neg}\left(\left(\left(x - y\right) - 1 \cdot \left(1 - y\right)\right)\right)}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(1 - y\right)\right)\right)\right)}\right) \]
      8. frac-2neg-revN/A

        \[\leadsto 1 - \log \color{blue}{\left(\frac{\left(x - y\right) - 1 \cdot \left(1 - y\right)}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right)} \]
      9. *-lft-identityN/A

        \[\leadsto 1 - \log \left(\frac{\left(x - y\right) - \color{blue}{\left(1 - y\right)}}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right) \]
      10. sub-negate-revN/A

        \[\leadsto 1 - \log \left(\frac{\color{blue}{\mathsf{neg}\left(\left(\left(1 - y\right) - \left(x - y\right)\right)\right)}}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right) \]
      11. *-lft-identityN/A

        \[\leadsto 1 - \log \left(\frac{\mathsf{neg}\left(\left(\color{blue}{1 \cdot \left(1 - y\right)} - \left(x - y\right)\right)\right)}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right) \]
      12. *-lft-identityN/A

        \[\leadsto 1 - \log \left(\frac{\mathsf{neg}\left(\left(\color{blue}{\left(1 - y\right)} - \left(x - y\right)\right)\right)}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right) \]
      13. sub-flip-reverseN/A

        \[\leadsto 1 - \log \left(\frac{\mathsf{neg}\left(\color{blue}{\left(\left(1 - y\right) + \left(\mathsf{neg}\left(\left(x - y\right)\right)\right)\right)}\right)}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right) \]
      14. distribute-neg-inN/A

        \[\leadsto 1 - \log \left(\frac{\color{blue}{\left(\mathsf{neg}\left(\left(1 - y\right)\right)\right) + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(x - y\right)\right)\right)\right)\right)}}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right) \]
      15. remove-double-negN/A

        \[\leadsto 1 - \log \left(\frac{\left(\mathsf{neg}\left(\left(1 - y\right)\right)\right) + \color{blue}{\left(x - y\right)}}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right) \]
      16. *-lft-identityN/A

        \[\leadsto 1 - \log \left(\frac{\color{blue}{1 \cdot \left(\mathsf{neg}\left(\left(1 - y\right)\right)\right)} + \left(x - y\right)}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right) \]
      17. add-flip-revN/A

        \[\leadsto 1 - \log \left(\frac{\color{blue}{1 \cdot \left(\mathsf{neg}\left(\left(1 - y\right)\right)\right) - \left(\mathsf{neg}\left(\left(x - y\right)\right)\right)}}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right) \]
      18. sub-negate-revN/A

        \[\leadsto 1 - \log \left(\frac{\color{blue}{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(\left(x - y\right)\right)\right) - 1 \cdot \left(\mathsf{neg}\left(\left(1 - y\right)\right)\right)\right)\right)}}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right) \]
    3. Applied rewrites72.1%

      \[\leadsto 1 - \log \color{blue}{\left(\frac{\left(y - x\right) - \left(y - 1\right)}{1 - y}\right)} \]

    if 15 < (-.f64 #s(literal 1 binary64) (log.f64 (-.f64 #s(literal 1 binary64) (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)))))

    1. Initial program 71.8%

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

      \[\leadsto 1 - \log \color{blue}{\left(-1 \cdot \frac{1 - x}{y}\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto 1 - \log \left(-1 \cdot \color{blue}{\frac{1 - x}{y}}\right) \]
      2. lower-/.f64N/A

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

        \[\leadsto 1 - \log \left(-1 \cdot \frac{1 - x}{y}\right) \]
    4. Applied rewrites41.2%

      \[\leadsto 1 - \log \color{blue}{\left(-1 \cdot \frac{1 - x}{y}\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto 1 - \log \left(-1 \cdot \color{blue}{\frac{1 - x}{y}}\right) \]
      2. mul-1-negN/A

        \[\leadsto 1 - \log \left(\mathsf{neg}\left(\frac{1 - x}{y}\right)\right) \]
      3. lift-/.f64N/A

        \[\leadsto 1 - \log \left(\mathsf{neg}\left(\frac{1 - x}{y}\right)\right) \]
      4. distribute-neg-fracN/A

        \[\leadsto 1 - \log \left(\frac{\mathsf{neg}\left(\left(1 - x\right)\right)}{\color{blue}{y}}\right) \]
      5. lower-/.f64N/A

        \[\leadsto 1 - \log \left(\frac{\mathsf{neg}\left(\left(1 - x\right)\right)}{\color{blue}{y}}\right) \]
      6. lift--.f64N/A

        \[\leadsto 1 - \log \left(\frac{\mathsf{neg}\left(\left(1 - x\right)\right)}{y}\right) \]
      7. sub-negate-revN/A

        \[\leadsto 1 - \log \left(\frac{x - 1}{y}\right) \]
      8. lower--.f6441.2%

        \[\leadsto 1 - \log \left(\frac{x - 1}{y}\right) \]
    6. Applied rewrites41.2%

      \[\leadsto 1 - \log \left(\frac{x - 1}{\color{blue}{y}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 99.8% accurate, 0.5× speedup?

\[\begin{array}{l} \mathbf{if}\;1 - \log \left(1 - \frac{x - y}{1 - y}\right) \leq 15:\\ \;\;\;\;1 - \mathsf{30\_log1z0}\left(\left(\frac{y - x}{y - 1}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \log \left(\frac{x - 1}{y}\right)\\ \end{array} \]
(FPCore (x y)
  :precision binary64
  (if (<= (- 1 (log (- 1 (/ (- x y) (- 1 y))))) 15)
  (- 1 (30-log1z0 (/ (- y x) (- y 1))))
  (- 1 (log (/ (- x 1) y)))))
\begin{array}{l}
\mathbf{if}\;1 - \log \left(1 - \frac{x - y}{1 - y}\right) \leq 15:\\
\;\;\;\;1 - \mathsf{30\_log1z0}\left(\left(\frac{y - x}{y - 1}\right)\right)\\

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 #s(literal 1 binary64) (log.f64 (-.f64 #s(literal 1 binary64) (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y))))) < 15

    1. Initial program 71.8%

      \[1 - \log \left(1 - \frac{x - y}{1 - y}\right) \]
    2. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto 1 - \color{blue}{\log \left(1 - \frac{x - y}{1 - y}\right)} \]
      2. lift--.f64N/A

        \[\leadsto 1 - \log \color{blue}{\left(1 - \frac{x - y}{1 - y}\right)} \]
      3. lower-30-log1z070.9%

        \[\leadsto 1 - \color{blue}{\mathsf{30\_log1z0}\left(\left(\frac{x - y}{1 - y}\right)\right)} \]
      4. lift-/.f64N/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\color{blue}{\left(\frac{x - y}{1 - y}\right)}\right) \]
      5. frac-2negN/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\color{blue}{\left(\frac{\mathsf{neg}\left(\left(x - y\right)\right)}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right)}\right) \]
      6. lower-/.f64N/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\color{blue}{\left(\frac{\mathsf{neg}\left(\left(x - y\right)\right)}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right)}\right) \]
      7. lift--.f64N/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\left(\frac{\mathsf{neg}\left(\color{blue}{\left(x - y\right)}\right)}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right)\right) \]
      8. sub-negate-revN/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\left(\frac{\color{blue}{y - x}}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right)\right) \]
      9. lower--.f64N/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\left(\frac{\color{blue}{y - x}}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right)\right) \]
      10. lift--.f64N/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\left(\frac{y - x}{\mathsf{neg}\left(\color{blue}{\left(1 - y\right)}\right)}\right)\right) \]
      11. sub-negate-revN/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\left(\frac{y - x}{\color{blue}{y - 1}}\right)\right) \]
      12. lower--.f6470.9%

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\left(\frac{y - x}{\color{blue}{y - 1}}\right)\right) \]
    3. Applied rewrites70.9%

      \[\leadsto 1 - \color{blue}{\mathsf{30\_log1z0}\left(\left(\frac{y - x}{y - 1}\right)\right)} \]

    if 15 < (-.f64 #s(literal 1 binary64) (log.f64 (-.f64 #s(literal 1 binary64) (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)))))

    1. Initial program 71.8%

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

      \[\leadsto 1 - \log \color{blue}{\left(-1 \cdot \frac{1 - x}{y}\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto 1 - \log \left(-1 \cdot \color{blue}{\frac{1 - x}{y}}\right) \]
      2. lower-/.f64N/A

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

        \[\leadsto 1 - \log \left(-1 \cdot \frac{1 - x}{y}\right) \]
    4. Applied rewrites41.2%

      \[\leadsto 1 - \log \color{blue}{\left(-1 \cdot \frac{1 - x}{y}\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto 1 - \log \left(-1 \cdot \color{blue}{\frac{1 - x}{y}}\right) \]
      2. mul-1-negN/A

        \[\leadsto 1 - \log \left(\mathsf{neg}\left(\frac{1 - x}{y}\right)\right) \]
      3. lift-/.f64N/A

        \[\leadsto 1 - \log \left(\mathsf{neg}\left(\frac{1 - x}{y}\right)\right) \]
      4. distribute-neg-fracN/A

        \[\leadsto 1 - \log \left(\frac{\mathsf{neg}\left(\left(1 - x\right)\right)}{\color{blue}{y}}\right) \]
      5. lower-/.f64N/A

        \[\leadsto 1 - \log \left(\frac{\mathsf{neg}\left(\left(1 - x\right)\right)}{\color{blue}{y}}\right) \]
      6. lift--.f64N/A

        \[\leadsto 1 - \log \left(\frac{\mathsf{neg}\left(\left(1 - x\right)\right)}{y}\right) \]
      7. sub-negate-revN/A

        \[\leadsto 1 - \log \left(\frac{x - 1}{y}\right) \]
      8. lower--.f6441.2%

        \[\leadsto 1 - \log \left(\frac{x - 1}{y}\right) \]
    6. Applied rewrites41.2%

      \[\leadsto 1 - \log \left(\frac{x - 1}{\color{blue}{y}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 90.6% accurate, 0.5× speedup?

\[\begin{array}{l} \mathbf{if}\;1 - \log \left(1 - \frac{x - y}{1 - y}\right) \leq 30:\\ \;\;\;\;1 - \mathsf{30\_log1z0}\left(\left(\frac{y - x}{y - 1}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\ \end{array} \]
(FPCore (x y)
  :precision binary64
  (if (<= (- 1 (log (- 1 (/ (- x y) (- 1 y))))) 30)
  (- 1 (30-log1z0 (/ (- y x) (- y 1))))
  (- 1 (log (/ -1 y)))))
\begin{array}{l}
\mathbf{if}\;1 - \log \left(1 - \frac{x - y}{1 - y}\right) \leq 30:\\
\;\;\;\;1 - \mathsf{30\_log1z0}\left(\left(\frac{y - x}{y - 1}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 #s(literal 1 binary64) (log.f64 (-.f64 #s(literal 1 binary64) (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y))))) < 30

    1. Initial program 71.8%

      \[1 - \log \left(1 - \frac{x - y}{1 - y}\right) \]
    2. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto 1 - \color{blue}{\log \left(1 - \frac{x - y}{1 - y}\right)} \]
      2. lift--.f64N/A

        \[\leadsto 1 - \log \color{blue}{\left(1 - \frac{x - y}{1 - y}\right)} \]
      3. lower-30-log1z070.9%

        \[\leadsto 1 - \color{blue}{\mathsf{30\_log1z0}\left(\left(\frac{x - y}{1 - y}\right)\right)} \]
      4. lift-/.f64N/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\color{blue}{\left(\frac{x - y}{1 - y}\right)}\right) \]
      5. frac-2negN/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\color{blue}{\left(\frac{\mathsf{neg}\left(\left(x - y\right)\right)}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right)}\right) \]
      6. lower-/.f64N/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\color{blue}{\left(\frac{\mathsf{neg}\left(\left(x - y\right)\right)}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right)}\right) \]
      7. lift--.f64N/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\left(\frac{\mathsf{neg}\left(\color{blue}{\left(x - y\right)}\right)}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right)\right) \]
      8. sub-negate-revN/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\left(\frac{\color{blue}{y - x}}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right)\right) \]
      9. lower--.f64N/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\left(\frac{\color{blue}{y - x}}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right)\right) \]
      10. lift--.f64N/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\left(\frac{y - x}{\mathsf{neg}\left(\color{blue}{\left(1 - y\right)}\right)}\right)\right) \]
      11. sub-negate-revN/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\left(\frac{y - x}{\color{blue}{y - 1}}\right)\right) \]
      12. lower--.f6470.9%

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\left(\frac{y - x}{\color{blue}{y - 1}}\right)\right) \]
    3. Applied rewrites70.9%

      \[\leadsto 1 - \color{blue}{\mathsf{30\_log1z0}\left(\left(\frac{y - x}{y - 1}\right)\right)} \]

    if 30 < (-.f64 #s(literal 1 binary64) (log.f64 (-.f64 #s(literal 1 binary64) (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)))))

    1. Initial program 71.8%

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

      \[\leadsto 1 - \log \color{blue}{\left(-1 \cdot \frac{1 - x}{y}\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto 1 - \log \left(-1 \cdot \color{blue}{\frac{1 - x}{y}}\right) \]
      2. lower-/.f64N/A

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

        \[\leadsto 1 - \log \left(-1 \cdot \frac{1 - x}{y}\right) \]
    4. Applied rewrites41.2%

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

      \[\leadsto 1 - \log \left(\frac{-1}{\color{blue}{y}}\right) \]
    6. Step-by-step derivation
      1. lower-/.f6422.7%

        \[\leadsto 1 - \log \left(\frac{-1}{y}\right) \]
    7. Applied rewrites22.7%

      \[\leadsto 1 - \log \left(\frac{-1}{\color{blue}{y}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 74.9% accurate, 0.8× speedup?

\[\begin{array}{l} \mathbf{if}\;\log \left(1 - \frac{x - y}{1 - y}\right) \leq -\infty:\\ \;\;\;\;1 - \mathsf{30\_log1z0}\left(\left(\frac{x}{1 - y}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \mathsf{30\_log1z0}\left(\left(\frac{y - x}{y - 1}\right)\right)\\ \end{array} \]
(FPCore (x y)
  :precision binary64
  (if (<= (log (- 1 (/ (- x y) (- 1 y)))) (- INFINITY))
  (- 1 (30-log1z0 (/ x (- 1 y))))
  (- 1 (30-log1z0 (/ (- y x) (- y 1))))))
\begin{array}{l}
\mathbf{if}\;\log \left(1 - \frac{x - y}{1 - y}\right) \leq -\infty:\\
\;\;\;\;1 - \mathsf{30\_log1z0}\left(\left(\frac{x}{1 - y}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;1 - \mathsf{30\_log1z0}\left(\left(\frac{y - x}{y - 1}\right)\right)\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (log.f64 (-.f64 #s(literal 1 binary64) (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)))) < -inf.0

    1. Initial program 71.8%

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

      \[\leadsto 1 - \log \left(1 - \color{blue}{\frac{x}{1 - y}}\right) \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto 1 - \log \left(1 - \frac{x}{\color{blue}{1 - y}}\right) \]
      2. lower--.f6472.8%

        \[\leadsto 1 - \log \left(1 - \frac{x}{1 - \color{blue}{y}}\right) \]
    4. Applied rewrites72.8%

      \[\leadsto 1 - \log \left(1 - \color{blue}{\frac{x}{1 - y}}\right) \]
    5. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto 1 - \color{blue}{\log \left(1 - \frac{x}{1 - y}\right)} \]
      2. lift--.f64N/A

        \[\leadsto 1 - \log \color{blue}{\left(1 - \frac{x}{1 - y}\right)} \]
      3. lower-30-log1z072.8%

        \[\leadsto 1 - \color{blue}{\mathsf{30\_log1z0}\left(\left(\frac{x}{1 - y}\right)\right)} \]
    6. Applied rewrites72.8%

      \[\leadsto 1 - \color{blue}{\mathsf{30\_log1z0}\left(\left(\frac{x}{1 - y}\right)\right)} \]

    if -inf.0 < (log.f64 (-.f64 #s(literal 1 binary64) (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y))))

    1. Initial program 71.8%

      \[1 - \log \left(1 - \frac{x - y}{1 - y}\right) \]
    2. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto 1 - \color{blue}{\log \left(1 - \frac{x - y}{1 - y}\right)} \]
      2. lift--.f64N/A

        \[\leadsto 1 - \log \color{blue}{\left(1 - \frac{x - y}{1 - y}\right)} \]
      3. lower-30-log1z070.9%

        \[\leadsto 1 - \color{blue}{\mathsf{30\_log1z0}\left(\left(\frac{x - y}{1 - y}\right)\right)} \]
      4. lift-/.f64N/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\color{blue}{\left(\frac{x - y}{1 - y}\right)}\right) \]
      5. frac-2negN/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\color{blue}{\left(\frac{\mathsf{neg}\left(\left(x - y\right)\right)}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right)}\right) \]
      6. lower-/.f64N/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\color{blue}{\left(\frac{\mathsf{neg}\left(\left(x - y\right)\right)}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right)}\right) \]
      7. lift--.f64N/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\left(\frac{\mathsf{neg}\left(\color{blue}{\left(x - y\right)}\right)}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right)\right) \]
      8. sub-negate-revN/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\left(\frac{\color{blue}{y - x}}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right)\right) \]
      9. lower--.f64N/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\left(\frac{\color{blue}{y - x}}{\mathsf{neg}\left(\left(1 - y\right)\right)}\right)\right) \]
      10. lift--.f64N/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\left(\frac{y - x}{\mathsf{neg}\left(\color{blue}{\left(1 - y\right)}\right)}\right)\right) \]
      11. sub-negate-revN/A

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\left(\frac{y - x}{\color{blue}{y - 1}}\right)\right) \]
      12. lower--.f6470.9%

        \[\leadsto 1 - \mathsf{30\_log1z0}\left(\left(\frac{y - x}{\color{blue}{y - 1}}\right)\right) \]
    3. Applied rewrites70.9%

      \[\leadsto 1 - \color{blue}{\mathsf{30\_log1z0}\left(\left(\frac{y - x}{y - 1}\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 72.8% accurate, 3.7× speedup?

\[1 - \mathsf{30\_log1z0}\left(\left(\frac{x}{1 - y}\right)\right) \]
(FPCore (x y)
  :precision binary64
  (- 1 (30-log1z0 (/ x (- 1 y)))))
1 - \mathsf{30\_log1z0}\left(\left(\frac{x}{1 - y}\right)\right)
Derivation
  1. Initial program 71.8%

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

    \[\leadsto 1 - \log \left(1 - \color{blue}{\frac{x}{1 - y}}\right) \]
  3. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto 1 - \log \left(1 - \frac{x}{\color{blue}{1 - y}}\right) \]
    2. lower--.f6472.8%

      \[\leadsto 1 - \log \left(1 - \frac{x}{1 - \color{blue}{y}}\right) \]
  4. Applied rewrites72.8%

    \[\leadsto 1 - \log \left(1 - \color{blue}{\frac{x}{1 - y}}\right) \]
  5. Step-by-step derivation
    1. lift-log.f64N/A

      \[\leadsto 1 - \color{blue}{\log \left(1 - \frac{x}{1 - y}\right)} \]
    2. lift--.f64N/A

      \[\leadsto 1 - \log \color{blue}{\left(1 - \frac{x}{1 - y}\right)} \]
    3. lower-30-log1z072.8%

      \[\leadsto 1 - \color{blue}{\mathsf{30\_log1z0}\left(\left(\frac{x}{1 - y}\right)\right)} \]
  6. Applied rewrites72.8%

    \[\leadsto 1 - \color{blue}{\mathsf{30\_log1z0}\left(\left(\frac{x}{1 - y}\right)\right)} \]
  7. Add Preprocessing

Alternative 6: 62.3% accurate, 6.3× speedup?

\[1 - \mathsf{30\_log1z0}\left(x\right) \]
(FPCore (x y)
  :precision binary64
  (- 1 (30-log1z0 x)))
1 - \mathsf{30\_log1z0}\left(x\right)
Derivation
  1. Initial program 71.8%

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

    \[\leadsto 1 - \color{blue}{\log \left(1 - x\right)} \]
  3. Step-by-step derivation
    1. lower-30-log1z062.3%

      \[\leadsto 1 - \mathsf{30\_log1z0}\left(x\right) \]
  4. Applied rewrites62.3%

    \[\leadsto 1 - \color{blue}{\mathsf{30\_log1z0}\left(x\right)} \]
  5. Add Preprocessing

Alternative 7: 42.7% accurate, 20.7× speedup?

\[1 - \left(-x\right) \]
(FPCore (x y)
  :precision binary64
  (- 1 (- x)))
double code(double x, double y) {
	return 1.0 - -x;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y)
use fmin_fmax_functions
    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 - Float64(-x))
end
function tmp = code(x, y)
	tmp = 1.0 - -x;
end
code[x_, y_] := N[(1 - (-x)), $MachinePrecision]
1 - \left(-x\right)
Derivation
  1. Initial program 71.8%

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

    \[\leadsto 1 - \color{blue}{\log \left(1 - x\right)} \]
  3. Step-by-step derivation
    1. lower-30-log1z062.3%

      \[\leadsto 1 - \mathsf{30\_log1z0}\left(x\right) \]
  4. Applied rewrites62.3%

    \[\leadsto 1 - \color{blue}{\mathsf{30\_log1z0}\left(x\right)} \]
  5. Taylor expanded in x around 0

    \[\leadsto 1 - -1 \cdot \color{blue}{x} \]
  6. Step-by-step derivation
    1. lower-*.f6442.7%

      \[\leadsto 1 - -1 \cdot x \]
  7. Applied rewrites42.7%

    \[\leadsto 1 - -1 \cdot \color{blue}{x} \]
  8. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto 1 - -1 \cdot x \]
    2. mul-1-negN/A

      \[\leadsto 1 - \left(\mathsf{neg}\left(x\right)\right) \]
    3. lower-neg.f6442.7%

      \[\leadsto 1 - \left(-x\right) \]
  9. Applied rewrites42.7%

    \[\leadsto 1 - \left(-x\right) \]
  10. Add Preprocessing

Reproduce

?
herbie shell --seed 2025271 -o generate:evaluate
(FPCore (x y)
  :name "Numeric.SpecFunctions:invIncompleteGamma from math-functions-0.1.5.2, B"
  :precision binary64
  (- 1 (log (- 1 (/ (- x y) (- 1 y))))))