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

Percentage Accurate: 100.0% → 100.0%
Time: 39.0s
Alternatives: 4
Speedup: 1.0×

Specification

?
\[\frac{\frac{230753}{100000} + x \cdot \frac{27061}{100000}}{1 + x \cdot \left(\frac{99229}{100000} + x \cdot \frac{4481}{100000}\right)} - x \]
(FPCore (x)
  :precision binary64
  (-
 (/
  (+ 230753/100000 (* x 27061/100000))
  (+ 1 (* x (+ 99229/100000 (* x 4481/100000)))))
 x))
double code(double x) {
	return ((2.30753 + (x * 0.27061)) / (1.0 + (x * (0.99229 + (x * 0.04481))))) - 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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = ((2.30753d0 + (x * 0.27061d0)) / (1.0d0 + (x * (0.99229d0 + (x * 0.04481d0))))) - x
end function
public static double code(double x) {
	return ((2.30753 + (x * 0.27061)) / (1.0 + (x * (0.99229 + (x * 0.04481))))) - x;
}
def code(x):
	return ((2.30753 + (x * 0.27061)) / (1.0 + (x * (0.99229 + (x * 0.04481))))) - x
function code(x)
	return Float64(Float64(Float64(2.30753 + Float64(x * 0.27061)) / Float64(1.0 + Float64(x * Float64(0.99229 + Float64(x * 0.04481))))) - x)
end
function tmp = code(x)
	tmp = ((2.30753 + (x * 0.27061)) / (1.0 + (x * (0.99229 + (x * 0.04481))))) - x;
end
code[x_] := N[(N[(N[(230753/100000 + N[(x * 27061/100000), $MachinePrecision]), $MachinePrecision] / N[(1 + N[(x * N[(99229/100000 + N[(x * 4481/100000), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\frac{\frac{230753}{100000} + x \cdot \frac{27061}{100000}}{1 + x \cdot \left(\frac{99229}{100000} + x \cdot \frac{4481}{100000}\right)} - x

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

\[\frac{\frac{230753}{100000} + x \cdot \frac{27061}{100000}}{1 + x \cdot \left(\frac{99229}{100000} + x \cdot \frac{4481}{100000}\right)} - x \]
(FPCore (x)
  :precision binary64
  (-
 (/
  (+ 230753/100000 (* x 27061/100000))
  (+ 1 (* x (+ 99229/100000 (* x 4481/100000)))))
 x))
double code(double x) {
	return ((2.30753 + (x * 0.27061)) / (1.0 + (x * (0.99229 + (x * 0.04481))))) - 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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = ((2.30753d0 + (x * 0.27061d0)) / (1.0d0 + (x * (0.99229d0 + (x * 0.04481d0))))) - x
end function
public static double code(double x) {
	return ((2.30753 + (x * 0.27061)) / (1.0 + (x * (0.99229 + (x * 0.04481))))) - x;
}
def code(x):
	return ((2.30753 + (x * 0.27061)) / (1.0 + (x * (0.99229 + (x * 0.04481))))) - x
function code(x)
	return Float64(Float64(Float64(2.30753 + Float64(x * 0.27061)) / Float64(1.0 + Float64(x * Float64(0.99229 + Float64(x * 0.04481))))) - x)
end
function tmp = code(x)
	tmp = ((2.30753 + (x * 0.27061)) / (1.0 + (x * (0.99229 + (x * 0.04481))))) - x;
end
code[x_] := N[(N[(N[(230753/100000 + N[(x * 27061/100000), $MachinePrecision]), $MachinePrecision] / N[(1 + N[(x * N[(99229/100000 + N[(x * 4481/100000), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\frac{\frac{230753}{100000} + x \cdot \frac{27061}{100000}}{1 + x \cdot \left(\frac{99229}{100000} + x \cdot \frac{4481}{100000}\right)} - x

Alternative 1: 97.6% accurate, 2.6× speedup?

\[\begin{array}{l} \mathbf{if}\;x \leq -190000000:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq 220000000:\\ \;\;\;\;\frac{230753}{100000}\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
(FPCore (x)
  :precision binary64
  (if (<= x -190000000) (- x) (if (<= x 220000000) 230753/100000 (- x))))
double code(double x) {
	double tmp;
	if (x <= -190000000.0) {
		tmp = -x;
	} else if (x <= 220000000.0) {
		tmp = 2.30753;
	} else {
		tmp = -x;
	}
	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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-190000000.0d0)) then
        tmp = -x
    else if (x <= 220000000.0d0) then
        tmp = 2.30753d0
    else
        tmp = -x
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= -190000000.0) {
		tmp = -x;
	} else if (x <= 220000000.0) {
		tmp = 2.30753;
	} else {
		tmp = -x;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -190000000.0:
		tmp = -x
	elif x <= 220000000.0:
		tmp = 2.30753
	else:
		tmp = -x
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -190000000.0)
		tmp = Float64(-x);
	elseif (x <= 220000000.0)
		tmp = 2.30753;
	else
		tmp = Float64(-x);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -190000000.0)
		tmp = -x;
	elseif (x <= 220000000.0)
		tmp = 2.30753;
	else
		tmp = -x;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, -190000000], (-x), If[LessEqual[x, 220000000], 230753/100000, (-x)]]
\begin{array}{l}
\mathbf{if}\;x \leq -190000000:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \leq 220000000:\\
\;\;\;\;\frac{230753}{100000}\\

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.9e8 or 2.2e8 < x

    1. Initial program 100.0%

      \[\frac{\frac{230753}{100000} + x \cdot \frac{27061}{100000}}{1 + x \cdot \left(\frac{99229}{100000} + x \cdot \frac{4481}{100000}\right)} - x \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{-1 \cdot x} \]
    3. Step-by-step derivation
      1. lower-*.f6451.5%

        \[\leadsto -1 \cdot \color{blue}{x} \]
    4. Applied rewrites51.5%

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

        \[\leadsto -1 \cdot \color{blue}{x} \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(x\right) \]
      3. lower-neg.f6451.5%

        \[\leadsto -x \]
    6. Applied rewrites51.5%

      \[\leadsto -x \]

    if -1.9e8 < x < 2.2e8

    1. Initial program 100.0%

      \[\frac{\frac{230753}{100000} + x \cdot \frac{27061}{100000}}{1 + x \cdot \left(\frac{99229}{100000} + x \cdot \frac{4481}{100000}\right)} - x \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{230753}{100000} + x \cdot \left(\frac{1900161040244073}{1000000000000000} \cdot x - \frac{30191289437}{10000000000}\right)} \]
    3. Step-by-step derivation
      1. lower-+.f64N/A

        \[\leadsto \frac{230753}{100000} + \color{blue}{x \cdot \left(\frac{1900161040244073}{1000000000000000} \cdot x - \frac{30191289437}{10000000000}\right)} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{230753}{100000} + x \cdot \color{blue}{\left(\frac{1900161040244073}{1000000000000000} \cdot x - \frac{30191289437}{10000000000}\right)} \]
      3. lower--.f64N/A

        \[\leadsto \frac{230753}{100000} + x \cdot \left(\frac{1900161040244073}{1000000000000000} \cdot x - \color{blue}{\frac{30191289437}{10000000000}}\right) \]
      4. lower-*.f6451.2%

        \[\leadsto \frac{230753}{100000} + x \cdot \left(\frac{1900161040244073}{1000000000000000} \cdot x - \frac{30191289437}{10000000000}\right) \]
    4. Applied rewrites51.2%

      \[\leadsto \color{blue}{\frac{230753}{100000} + x \cdot \left(\frac{1900161040244073}{1000000000000000} \cdot x - \frac{30191289437}{10000000000}\right)} \]
    5. Taylor expanded in x around 0

      \[\leadsto \frac{230753}{100000} + x \cdot \frac{-30191289437}{10000000000} \]
    6. Step-by-step derivation
      1. Applied rewrites58.0%

        \[\leadsto \frac{230753}{100000} + x \cdot \frac{-30191289437}{10000000000} \]
      2. Step-by-step derivation
        1. lift-+.f64N/A

          \[\leadsto \frac{230753}{100000} + \color{blue}{x \cdot \frac{-30191289437}{10000000000}} \]
        2. +-commutativeN/A

          \[\leadsto x \cdot \frac{-30191289437}{10000000000} + \color{blue}{\frac{230753}{100000}} \]
        3. add-flipN/A

          \[\leadsto x \cdot \frac{-30191289437}{10000000000} - \color{blue}{\left(\mathsf{neg}\left(\frac{230753}{100000}\right)\right)} \]
        4. metadata-evalN/A

          \[\leadsto x \cdot \frac{-30191289437}{10000000000} - \frac{-230753}{100000} \]
        5. sub-to-multN/A

          \[\leadsto \left(1 - \frac{\frac{-230753}{100000}}{x \cdot \frac{-30191289437}{10000000000}}\right) \cdot \color{blue}{\left(x \cdot \frac{-30191289437}{10000000000}\right)} \]
        6. remove-double-negN/A

          \[\leadsto \left(1 - \frac{\frac{-230753}{100000}}{x \cdot \frac{-30191289437}{10000000000}}\right) \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot \frac{-30191289437}{10000000000}\right)\right)\right)\right) \]
        7. lift-*.f64N/A

          \[\leadsto \left(1 - \frac{\frac{-230753}{100000}}{x \cdot \frac{-30191289437}{10000000000}}\right) \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot \frac{-30191289437}{10000000000}\right)\right)\right)\right) \]
        8. distribute-lft-neg-outN/A

          \[\leadsto \left(1 - \frac{\frac{-230753}{100000}}{x \cdot \frac{-30191289437}{10000000000}}\right) \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right) \cdot \frac{-30191289437}{10000000000}\right)\right) \]
        9. lower-unsound-*.f64N/A

          \[\leadsto \left(1 - \frac{\frac{-230753}{100000}}{x \cdot \frac{-30191289437}{10000000000}}\right) \cdot \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right) \cdot \frac{-30191289437}{10000000000}\right)\right)} \]
      3. Applied rewrites58.0%

        \[\leadsto \left(1 - \frac{\frac{-230753}{100000}}{\frac{-30191289437}{10000000000} \cdot x}\right) \cdot \color{blue}{\left(\frac{-30191289437}{10000000000} \cdot x\right)} \]
      4. Taylor expanded in x around 0

        \[\leadsto \frac{230753}{100000} \]
      5. Step-by-step derivation
        1. Applied rewrites50.1%

          \[\leadsto \frac{230753}{100000} \]
      6. Recombined 2 regimes into one program.
      7. Add Preprocessing

      Alternative 2: 97.4% accurate, 9.8× speedup?

      \[\frac{230753}{100000} - x \]
      (FPCore (x)
        :precision binary64
        (- 230753/100000 x))
      double code(double x) {
      	return 2.30753 - 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)
      use fmin_fmax_functions
          real(8), intent (in) :: x
          code = 2.30753d0 - x
      end function
      
      public static double code(double x) {
      	return 2.30753 - x;
      }
      
      def code(x):
      	return 2.30753 - x
      
      function code(x)
      	return Float64(2.30753 - x)
      end
      
      function tmp = code(x)
      	tmp = 2.30753 - x;
      end
      
      code[x_] := N[(230753/100000 - x), $MachinePrecision]
      
      \frac{230753}{100000} - x
      
      Derivation
      1. Initial program 100.0%

        \[\frac{\frac{230753}{100000} + x \cdot \frac{27061}{100000}}{1 + x \cdot \left(\frac{99229}{100000} + x \cdot \frac{4481}{100000}\right)} - x \]
      2. Step-by-step derivation
        1. lift-/.f64N/A

          \[\leadsto \color{blue}{\frac{\frac{230753}{100000} + x \cdot \frac{27061}{100000}}{1 + x \cdot \left(\frac{99229}{100000} + x \cdot \frac{4481}{100000}\right)}} - x \]
        2. frac-2negN/A

          \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(\frac{230753}{100000} + x \cdot \frac{27061}{100000}\right)\right)}{\mathsf{neg}\left(\left(1 + x \cdot \left(\frac{99229}{100000} + x \cdot \frac{4481}{100000}\right)\right)\right)}} - x \]
        3. mult-flipN/A

          \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(\frac{230753}{100000} + x \cdot \frac{27061}{100000}\right)\right)\right) \cdot \frac{1}{\mathsf{neg}\left(\left(1 + x \cdot \left(\frac{99229}{100000} + x \cdot \frac{4481}{100000}\right)\right)\right)}} - x \]
        4. *-commutativeN/A

          \[\leadsto \color{blue}{\frac{1}{\mathsf{neg}\left(\left(1 + x \cdot \left(\frac{99229}{100000} + x \cdot \frac{4481}{100000}\right)\right)\right)} \cdot \left(\mathsf{neg}\left(\left(\frac{230753}{100000} + x \cdot \frac{27061}{100000}\right)\right)\right)} - x \]
        5. lower-*.f64N/A

          \[\leadsto \color{blue}{\frac{1}{\mathsf{neg}\left(\left(1 + x \cdot \left(\frac{99229}{100000} + x \cdot \frac{4481}{100000}\right)\right)\right)} \cdot \left(\mathsf{neg}\left(\left(\frac{230753}{100000} + x \cdot \frac{27061}{100000}\right)\right)\right)} - x \]
      3. Applied rewrites100.0%

        \[\leadsto \color{blue}{\frac{-1}{\left(\frac{4481}{100000} \cdot x - \frac{-99229}{100000}\right) \cdot x - -1} \cdot \left(\frac{-230753}{100000} - \frac{27061}{100000} \cdot x\right)} - x \]
      4. Taylor expanded in x around 0

        \[\leadsto \color{blue}{\frac{230753}{100000}} - x \]
      5. Step-by-step derivation
        1. Applied rewrites97.6%

          \[\leadsto \color{blue}{\frac{230753}{100000}} - x \]
        2. Add Preprocessing

        Alternative 3: 50.1% accurate, 39.0× speedup?

        \[\frac{230753}{100000} \]
        (FPCore (x)
          :precision binary64
          230753/100000)
        double code(double x) {
        	return 2.30753;
        }
        
        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)
        use fmin_fmax_functions
            real(8), intent (in) :: x
            code = 2.30753d0
        end function
        
        public static double code(double x) {
        	return 2.30753;
        }
        
        def code(x):
        	return 2.30753
        
        function code(x)
        	return 2.30753
        end
        
        function tmp = code(x)
        	tmp = 2.30753;
        end
        
        code[x_] := 230753/100000
        
        \frac{230753}{100000}
        
        Derivation
        1. Initial program 100.0%

          \[\frac{\frac{230753}{100000} + x \cdot \frac{27061}{100000}}{1 + x \cdot \left(\frac{99229}{100000} + x \cdot \frac{4481}{100000}\right)} - x \]
        2. Taylor expanded in x around 0

          \[\leadsto \color{blue}{\frac{230753}{100000} + x \cdot \left(\frac{1900161040244073}{1000000000000000} \cdot x - \frac{30191289437}{10000000000}\right)} \]
        3. Step-by-step derivation
          1. lower-+.f64N/A

            \[\leadsto \frac{230753}{100000} + \color{blue}{x \cdot \left(\frac{1900161040244073}{1000000000000000} \cdot x - \frac{30191289437}{10000000000}\right)} \]
          2. lower-*.f64N/A

            \[\leadsto \frac{230753}{100000} + x \cdot \color{blue}{\left(\frac{1900161040244073}{1000000000000000} \cdot x - \frac{30191289437}{10000000000}\right)} \]
          3. lower--.f64N/A

            \[\leadsto \frac{230753}{100000} + x \cdot \left(\frac{1900161040244073}{1000000000000000} \cdot x - \color{blue}{\frac{30191289437}{10000000000}}\right) \]
          4. lower-*.f6451.2%

            \[\leadsto \frac{230753}{100000} + x \cdot \left(\frac{1900161040244073}{1000000000000000} \cdot x - \frac{30191289437}{10000000000}\right) \]
        4. Applied rewrites51.2%

          \[\leadsto \color{blue}{\frac{230753}{100000} + x \cdot \left(\frac{1900161040244073}{1000000000000000} \cdot x - \frac{30191289437}{10000000000}\right)} \]
        5. Taylor expanded in x around 0

          \[\leadsto \frac{230753}{100000} + x \cdot \frac{-30191289437}{10000000000} \]
        6. Step-by-step derivation
          1. Applied rewrites58.0%

            \[\leadsto \frac{230753}{100000} + x \cdot \frac{-30191289437}{10000000000} \]
          2. Step-by-step derivation
            1. lift-+.f64N/A

              \[\leadsto \frac{230753}{100000} + \color{blue}{x \cdot \frac{-30191289437}{10000000000}} \]
            2. +-commutativeN/A

              \[\leadsto x \cdot \frac{-30191289437}{10000000000} + \color{blue}{\frac{230753}{100000}} \]
            3. add-flipN/A

              \[\leadsto x \cdot \frac{-30191289437}{10000000000} - \color{blue}{\left(\mathsf{neg}\left(\frac{230753}{100000}\right)\right)} \]
            4. metadata-evalN/A

              \[\leadsto x \cdot \frac{-30191289437}{10000000000} - \frac{-230753}{100000} \]
            5. sub-to-multN/A

              \[\leadsto \left(1 - \frac{\frac{-230753}{100000}}{x \cdot \frac{-30191289437}{10000000000}}\right) \cdot \color{blue}{\left(x \cdot \frac{-30191289437}{10000000000}\right)} \]
            6. remove-double-negN/A

              \[\leadsto \left(1 - \frac{\frac{-230753}{100000}}{x \cdot \frac{-30191289437}{10000000000}}\right) \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot \frac{-30191289437}{10000000000}\right)\right)\right)\right) \]
            7. lift-*.f64N/A

              \[\leadsto \left(1 - \frac{\frac{-230753}{100000}}{x \cdot \frac{-30191289437}{10000000000}}\right) \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot \frac{-30191289437}{10000000000}\right)\right)\right)\right) \]
            8. distribute-lft-neg-outN/A

              \[\leadsto \left(1 - \frac{\frac{-230753}{100000}}{x \cdot \frac{-30191289437}{10000000000}}\right) \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right) \cdot \frac{-30191289437}{10000000000}\right)\right) \]
            9. lower-unsound-*.f64N/A

              \[\leadsto \left(1 - \frac{\frac{-230753}{100000}}{x \cdot \frac{-30191289437}{10000000000}}\right) \cdot \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right) \cdot \frac{-30191289437}{10000000000}\right)\right)} \]
          3. Applied rewrites58.0%

            \[\leadsto \left(1 - \frac{\frac{-230753}{100000}}{\frac{-30191289437}{10000000000} \cdot x}\right) \cdot \color{blue}{\left(\frac{-30191289437}{10000000000} \cdot x\right)} \]
          4. Taylor expanded in x around 0

            \[\leadsto \frac{230753}{100000} \]
          5. Step-by-step derivation
            1. Applied rewrites50.1%

              \[\leadsto \frac{230753}{100000} \]
            2. Add Preprocessing

            Reproduce

            ?
            herbie shell --seed 2025271 -o generate:evaluate
            (FPCore (x)
              :name "Numeric.SpecFunctions:invIncompleteGamma from math-functions-0.1.5.2, C"
              :precision binary64
              (- (/ (+ 230753/100000 (* x 27061/100000)) (+ 1 (* x (+ 99229/100000 (* x 4481/100000))))) x))