Octave 3.8, jcobi/4, as called

Percentage Accurate: 27.9% → 99.6%
Time: 1.7s
Alternatives: 3
Speedup: 36.9×

Specification

?
\[i > 0\]
\[\begin{array}{l} t_0 := \left(2 \cdot i\right) \cdot \left(2 \cdot i\right)\\ \frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{t\_0}}{t\_0 - 1} \end{array} \]
(FPCore (i)
 :precision binary64
 (let* ((t_0 (* (* 2.0 i) (* 2.0 i))))
   (/ (/ (* (* i i) (* i i)) t_0) (- t_0 1.0))))
double code(double i) {
	double t_0 = (2.0 * i) * (2.0 * i);
	return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0);
}
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(i)
use fmin_fmax_functions
    real(8), intent (in) :: i
    real(8) :: t_0
    t_0 = (2.0d0 * i) * (2.0d0 * i)
    code = (((i * i) * (i * i)) / t_0) / (t_0 - 1.0d0)
end function
public static double code(double i) {
	double t_0 = (2.0 * i) * (2.0 * i);
	return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0);
}
def code(i):
	t_0 = (2.0 * i) * (2.0 * i)
	return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0)
function code(i)
	t_0 = Float64(Float64(2.0 * i) * Float64(2.0 * i))
	return Float64(Float64(Float64(Float64(i * i) * Float64(i * i)) / t_0) / Float64(t_0 - 1.0))
end
function tmp = code(i)
	t_0 = (2.0 * i) * (2.0 * i);
	tmp = (((i * i) * (i * i)) / t_0) / (t_0 - 1.0);
end
code[i_] := Block[{t$95$0 = N[(N[(2.0 * i), $MachinePrecision] * N[(2.0 * i), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[(i * i), $MachinePrecision] * N[(i * i), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] / N[(t$95$0 - 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left(2 \cdot i\right) \cdot \left(2 \cdot i\right)\\
\frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{t\_0}}{t\_0 - 1}
\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.

Accuracy vs Speed?

Herbie found 3 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: 27.9% accurate, 1.0× speedup?

\[\begin{array}{l} t_0 := \left(2 \cdot i\right) \cdot \left(2 \cdot i\right)\\ \frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{t\_0}}{t\_0 - 1} \end{array} \]
(FPCore (i)
 :precision binary64
 (let* ((t_0 (* (* 2.0 i) (* 2.0 i))))
   (/ (/ (* (* i i) (* i i)) t_0) (- t_0 1.0))))
double code(double i) {
	double t_0 = (2.0 * i) * (2.0 * i);
	return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0);
}
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(i)
use fmin_fmax_functions
    real(8), intent (in) :: i
    real(8) :: t_0
    t_0 = (2.0d0 * i) * (2.0d0 * i)
    code = (((i * i) * (i * i)) / t_0) / (t_0 - 1.0d0)
end function
public static double code(double i) {
	double t_0 = (2.0 * i) * (2.0 * i);
	return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0);
}
def code(i):
	t_0 = (2.0 * i) * (2.0 * i)
	return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0)
function code(i)
	t_0 = Float64(Float64(2.0 * i) * Float64(2.0 * i))
	return Float64(Float64(Float64(Float64(i * i) * Float64(i * i)) / t_0) / Float64(t_0 - 1.0))
end
function tmp = code(i)
	t_0 = (2.0 * i) * (2.0 * i);
	tmp = (((i * i) * (i * i)) / t_0) / (t_0 - 1.0);
end
code[i_] := Block[{t$95$0 = N[(N[(2.0 * i), $MachinePrecision] * N[(2.0 * i), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[(i * i), $MachinePrecision] * N[(i * i), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] / N[(t$95$0 - 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left(2 \cdot i\right) \cdot \left(2 \cdot i\right)\\
\frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{t\_0}}{t\_0 - 1}
\end{array}

Alternative 1: 99.6% accurate, 1.7× speedup?

\[\begin{array}{l} \mathbf{if}\;i \leq 20:\\ \;\;\;\;\frac{\left(i \cdot i\right) \cdot 0.25}{\mathsf{fma}\left(4, i \cdot i, -1\right)}\\ \mathbf{else}:\\ \;\;\;\;0.0625\\ \end{array} \]
(FPCore (i)
 :precision binary64
 (if (<= i 20.0) (/ (* (* i i) 0.25) (fma 4.0 (* i i) -1.0)) 0.0625))
double code(double i) {
	double tmp;
	if (i <= 20.0) {
		tmp = ((i * i) * 0.25) / fma(4.0, (i * i), -1.0);
	} else {
		tmp = 0.0625;
	}
	return tmp;
}
function code(i)
	tmp = 0.0
	if (i <= 20.0)
		tmp = Float64(Float64(Float64(i * i) * 0.25) / fma(4.0, Float64(i * i), -1.0));
	else
		tmp = 0.0625;
	end
	return tmp
end
code[i_] := If[LessEqual[i, 20.0], N[(N[(N[(i * i), $MachinePrecision] * 0.25), $MachinePrecision] / N[(4.0 * N[(i * i), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], 0.0625]
\begin{array}{l}
\mathbf{if}\;i \leq 20:\\
\;\;\;\;\frac{\left(i \cdot i\right) \cdot 0.25}{\mathsf{fma}\left(4, i \cdot i, -1\right)}\\

\mathbf{else}:\\
\;\;\;\;0.0625\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if i < 20

    1. Initial program 27.9%

      \[\frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right)}}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1} \]
    2. Step-by-step derivation
      1. Applied rewrites74.5%

        \[\leadsto \color{blue}{\frac{\left(i \cdot i\right) \cdot 0.25}{\mathsf{fma}\left(4, i \cdot i, -1\right)}} \]

      if 20 < i

      1. Initial program 27.9%

        \[\frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right)}}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1} \]
      2. Taylor expanded in i around inf

        \[\leadsto \color{blue}{\frac{1}{16}} \]
      3. Step-by-step derivation
        1. Applied rewrites51.8%

          \[\leadsto \color{blue}{0.0625} \]
      4. Recombined 2 regimes into one program.
      5. Add Preprocessing

      Alternative 2: 98.3% accurate, 2.6× speedup?

      \[\begin{array}{l} \mathbf{if}\;i \leq 8.5 \cdot 10^{-7}:\\ \;\;\;\;\frac{\left(i \cdot i\right) \cdot 0.25}{-1}\\ \mathbf{else}:\\ \;\;\;\;0.0625\\ \end{array} \]
      (FPCore (i)
       :precision binary64
       (if (<= i 8.5e-7) (/ (* (* i i) 0.25) -1.0) 0.0625))
      double code(double i) {
      	double tmp;
      	if (i <= 8.5e-7) {
      		tmp = ((i * i) * 0.25) / -1.0;
      	} else {
      		tmp = 0.0625;
      	}
      	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(i)
      use fmin_fmax_functions
          real(8), intent (in) :: i
          real(8) :: tmp
          if (i <= 8.5d-7) then
              tmp = ((i * i) * 0.25d0) / (-1.0d0)
          else
              tmp = 0.0625d0
          end if
          code = tmp
      end function
      
      public static double code(double i) {
      	double tmp;
      	if (i <= 8.5e-7) {
      		tmp = ((i * i) * 0.25) / -1.0;
      	} else {
      		tmp = 0.0625;
      	}
      	return tmp;
      }
      
      def code(i):
      	tmp = 0
      	if i <= 8.5e-7:
      		tmp = ((i * i) * 0.25) / -1.0
      	else:
      		tmp = 0.0625
      	return tmp
      
      function code(i)
      	tmp = 0.0
      	if (i <= 8.5e-7)
      		tmp = Float64(Float64(Float64(i * i) * 0.25) / -1.0);
      	else
      		tmp = 0.0625;
      	end
      	return tmp
      end
      
      function tmp_2 = code(i)
      	tmp = 0.0;
      	if (i <= 8.5e-7)
      		tmp = ((i * i) * 0.25) / -1.0;
      	else
      		tmp = 0.0625;
      	end
      	tmp_2 = tmp;
      end
      
      code[i_] := If[LessEqual[i, 8.5e-7], N[(N[(N[(i * i), $MachinePrecision] * 0.25), $MachinePrecision] / -1.0), $MachinePrecision], 0.0625]
      
      \begin{array}{l}
      \mathbf{if}\;i \leq 8.5 \cdot 10^{-7}:\\
      \;\;\;\;\frac{\left(i \cdot i\right) \cdot 0.25}{-1}\\
      
      \mathbf{else}:\\
      \;\;\;\;0.0625\\
      
      
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if i < 8.5000000000000001e-7

        1. Initial program 27.9%

          \[\frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right)}}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1} \]
        2. Step-by-step derivation
          1. Applied rewrites74.5%

            \[\leadsto \color{blue}{\frac{\left(i \cdot i\right) \cdot 0.25}{\mathsf{fma}\left(4, i \cdot i, -1\right)}} \]
          2. Taylor expanded in i around 0

            \[\leadsto \frac{\left(i \cdot i\right) \cdot 0.25}{\color{blue}{-1}} \]
          3. Step-by-step derivation
            1. Applied rewrites48.8%

              \[\leadsto \frac{\left(i \cdot i\right) \cdot 0.25}{\color{blue}{-1}} \]

            if 8.5000000000000001e-7 < i

            1. Initial program 27.9%

              \[\frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right)}}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1} \]
            2. Taylor expanded in i around inf

              \[\leadsto \color{blue}{\frac{1}{16}} \]
            3. Step-by-step derivation
              1. Applied rewrites51.8%

                \[\leadsto \color{blue}{0.0625} \]
            4. Recombined 2 regimes into one program.
            5. Add Preprocessing

            Alternative 3: 51.8% accurate, 36.9× speedup?

            \[0.0625 \]
            (FPCore (i) :precision binary64 0.0625)
            double code(double i) {
            	return 0.0625;
            }
            
            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(i)
            use fmin_fmax_functions
                real(8), intent (in) :: i
                code = 0.0625d0
            end function
            
            public static double code(double i) {
            	return 0.0625;
            }
            
            def code(i):
            	return 0.0625
            
            function code(i)
            	return 0.0625
            end
            
            function tmp = code(i)
            	tmp = 0.0625;
            end
            
            code[i_] := 0.0625
            
            0.0625
            
            Derivation
            1. Initial program 27.9%

              \[\frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right)}}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1} \]
            2. Taylor expanded in i around inf

              \[\leadsto \color{blue}{\frac{1}{16}} \]
            3. Step-by-step derivation
              1. Applied rewrites51.8%

                \[\leadsto \color{blue}{0.0625} \]
              2. Add Preprocessing

              Reproduce

              ?
              herbie shell --seed 2025193 
              (FPCore (i)
                :name "Octave 3.8, jcobi/4, as called"
                :precision binary64
                :pre (> i 0.0)
                (/ (/ (* (* i i) (* i i)) (* (* 2.0 i) (* 2.0 i))) (- (* (* 2.0 i) (* 2.0 i)) 1.0)))