Octave 3.8, jcobi/4, as called

Percentage Accurate: 32.1% → 99.9%
Time: 4.8s
Alternatives: 6
Speedup: 71.0×

Specification

?
\[i > 0\]
\[\begin{array}{l} \\ \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} \end{array} \]
(FPCore (i)
 :precision binary32
 (let* ((t_0 (* (* 2.0 i) (* 2.0 i))))
   (/ (/ (* (* i i) (* i i)) t_0) (- t_0 1.0))))
float code(float i) {
	float t_0 = (2.0f * i) * (2.0f * i);
	return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0f);
}
real(4) function code(i)
    real(4), intent (in) :: i
    real(4) :: t_0
    t_0 = (2.0e0 * i) * (2.0e0 * i)
    code = (((i * i) * (i * i)) / t_0) / (t_0 - 1.0e0)
end function
function code(i)
	t_0 = Float32(Float32(Float32(2.0) * i) * Float32(Float32(2.0) * i))
	return Float32(Float32(Float32(Float32(i * i) * Float32(i * i)) / t_0) / Float32(t_0 - Float32(1.0)))
end
function tmp = code(i)
	t_0 = (single(2.0) * i) * (single(2.0) * i);
	tmp = (((i * i) * (i * i)) / t_0) / (t_0 - single(1.0));
end
\begin{array}{l}

\\
\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}
\end{array}

Sampling outcomes in binary32 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 6 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: 32.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \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} \end{array} \]
(FPCore (i)
 :precision binary32
 (let* ((t_0 (* (* 2.0 i) (* 2.0 i))))
   (/ (/ (* (* i i) (* i i)) t_0) (- t_0 1.0))))
float code(float i) {
	float t_0 = (2.0f * i) * (2.0f * i);
	return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0f);
}
real(4) function code(i)
    real(4), intent (in) :: i
    real(4) :: t_0
    t_0 = (2.0e0 * i) * (2.0e0 * i)
    code = (((i * i) * (i * i)) / t_0) / (t_0 - 1.0e0)
end function
function code(i)
	t_0 = Float32(Float32(Float32(2.0) * i) * Float32(Float32(2.0) * i))
	return Float32(Float32(Float32(Float32(i * i) * Float32(i * i)) / t_0) / Float32(t_0 - Float32(1.0)))
end
function tmp = code(i)
	t_0 = (single(2.0) * i) * (single(2.0) * i);
	tmp = (((i * i) * (i * i)) / t_0) / (t_0 - single(1.0));
end
\begin{array}{l}

\\
\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}
\end{array}

Alternative 1: 99.9% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;i \leq 2000:\\ \;\;\;\;\left(i \cdot i\right) \cdot \frac{0.25}{4 \cdot \left(i \cdot i\right) - 1}\\ \mathbf{else}:\\ \;\;\;\;0.0625\\ \end{array} \end{array} \]
(FPCore (i)
 :precision binary32
 (if (<= i 2000.0) (* (* i i) (/ 0.25 (- (* 4.0 (* i i)) 1.0))) 0.0625))
float code(float i) {
	float tmp;
	if (i <= 2000.0f) {
		tmp = (i * i) * (0.25f / ((4.0f * (i * i)) - 1.0f));
	} else {
		tmp = 0.0625f;
	}
	return tmp;
}
real(4) function code(i)
    real(4), intent (in) :: i
    real(4) :: tmp
    if (i <= 2000.0e0) then
        tmp = (i * i) * (0.25e0 / ((4.0e0 * (i * i)) - 1.0e0))
    else
        tmp = 0.0625e0
    end if
    code = tmp
end function
function code(i)
	tmp = Float32(0.0)
	if (i <= Float32(2000.0))
		tmp = Float32(Float32(i * i) * Float32(Float32(0.25) / Float32(Float32(Float32(4.0) * Float32(i * i)) - Float32(1.0))));
	else
		tmp = Float32(0.0625);
	end
	return tmp
end
function tmp_2 = code(i)
	tmp = single(0.0);
	if (i <= single(2000.0))
		tmp = (i * i) * (single(0.25) / ((single(4.0) * (i * i)) - single(1.0)));
	else
		tmp = single(0.0625);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;i \leq 2000:\\
\;\;\;\;\left(i \cdot i\right) \cdot \frac{0.25}{4 \cdot \left(i \cdot i\right) - 1}\\

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


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

    1. Initial program 46.2%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. lift-/.f32N/A

        \[\leadsto \color{blue}{\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. lift-/.f32N/A

        \[\leadsto \frac{\color{blue}{\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} \]
      3. associate-/l/N/A

        \[\leadsto \color{blue}{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{\left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right)\right) \cdot \left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1\right)}} \]
      4. lift-*.f32N/A

        \[\leadsto \frac{\color{blue}{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}}{\left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right)\right) \cdot \left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1\right)} \]
      5. associate-/l*N/A

        \[\leadsto \color{blue}{\left(i \cdot i\right) \cdot \frac{i \cdot i}{\left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right)\right) \cdot \left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1\right)}} \]
      6. lower-*.f32N/A

        \[\leadsto \color{blue}{\left(i \cdot i\right) \cdot \frac{i \cdot i}{\left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right)\right) \cdot \left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1\right)}} \]
      7. lower-/.f32N/A

        \[\leadsto \left(i \cdot i\right) \cdot \color{blue}{\frac{i \cdot i}{\left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right)\right) \cdot \left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1\right)}} \]
      8. lift-*.f32N/A

        \[\leadsto \left(i \cdot i\right) \cdot \frac{i \cdot i}{\color{blue}{\left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right)\right)} \cdot \left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1\right)} \]
      9. lift-*.f32N/A

        \[\leadsto \left(i \cdot i\right) \cdot \frac{i \cdot i}{\left(\left(2 \cdot i\right) \cdot \color{blue}{\left(2 \cdot i\right)}\right) \cdot \left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1\right)} \]
      10. associate-*r*N/A

        \[\leadsto \left(i \cdot i\right) \cdot \frac{i \cdot i}{\color{blue}{\left(\left(\left(2 \cdot i\right) \cdot 2\right) \cdot i\right)} \cdot \left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1\right)} \]
      11. associate-*l*N/A

        \[\leadsto \left(i \cdot i\right) \cdot \frac{i \cdot i}{\color{blue}{\left(\left(2 \cdot i\right) \cdot 2\right) \cdot \left(i \cdot \left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1\right)\right)}} \]
      12. lower-*.f32N/A

        \[\leadsto \left(i \cdot i\right) \cdot \frac{i \cdot i}{\color{blue}{\left(\left(2 \cdot i\right) \cdot 2\right) \cdot \left(i \cdot \left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1\right)\right)}} \]
    4. Applied rewrites60.9%

      \[\leadsto \color{blue}{\left(i \cdot i\right) \cdot \frac{i \cdot i}{\left(i \cdot 4\right) \cdot \left(i \cdot \left(4 \cdot \left(i \cdot i\right) - 1\right)\right)}} \]
    5. Applied rewrites99.4%

      \[\leadsto \color{blue}{\frac{i \cdot i}{1 - -2 \cdot i} \cdot \frac{0.25}{i \cdot 2 - 1}} \]
    6. Step-by-step derivation
      1. lift-*.f32N/A

        \[\leadsto \color{blue}{\frac{i \cdot i}{1 - -2 \cdot i} \cdot \frac{\frac{1}{4}}{i \cdot 2 - 1}} \]
      2. lift-/.f32N/A

        \[\leadsto \frac{i \cdot i}{1 - -2 \cdot i} \cdot \color{blue}{\frac{\frac{1}{4}}{i \cdot 2 - 1}} \]
      3. lift-/.f32N/A

        \[\leadsto \color{blue}{\frac{i \cdot i}{1 - -2 \cdot i}} \cdot \frac{\frac{1}{4}}{i \cdot 2 - 1} \]
      4. frac-timesN/A

        \[\leadsto \color{blue}{\frac{\left(i \cdot i\right) \cdot \frac{1}{4}}{\left(1 - -2 \cdot i\right) \cdot \left(i \cdot 2 - 1\right)}} \]
      5. associate-/l*N/A

        \[\leadsto \color{blue}{\left(i \cdot i\right) \cdot \frac{\frac{1}{4}}{\left(1 - -2 \cdot i\right) \cdot \left(i \cdot 2 - 1\right)}} \]
      6. lift--.f32N/A

        \[\leadsto \left(i \cdot i\right) \cdot \frac{\frac{1}{4}}{\left(1 - -2 \cdot i\right) \cdot \color{blue}{\left(i \cdot 2 - 1\right)}} \]
      7. flip3--N/A

        \[\leadsto \left(i \cdot i\right) \cdot \frac{\frac{1}{4}}{\left(1 - -2 \cdot i\right) \cdot \color{blue}{\frac{{\left(i \cdot 2\right)}^{3} - {1}^{3}}{\left(i \cdot 2\right) \cdot \left(i \cdot 2\right) + \left(1 \cdot 1 + \left(i \cdot 2\right) \cdot 1\right)}}} \]
      8. associate-*r/N/A

        \[\leadsto \left(i \cdot i\right) \cdot \frac{\frac{1}{4}}{\color{blue}{\frac{\left(1 - -2 \cdot i\right) \cdot \left({\left(i \cdot 2\right)}^{3} - {1}^{3}\right)}{\left(i \cdot 2\right) \cdot \left(i \cdot 2\right) + \left(1 \cdot 1 + \left(i \cdot 2\right) \cdot 1\right)}}} \]
      9. lift--.f32N/A

        \[\leadsto \left(i \cdot i\right) \cdot \frac{\frac{1}{4}}{\frac{\color{blue}{\left(1 - -2 \cdot i\right)} \cdot \left({\left(i \cdot 2\right)}^{3} - {1}^{3}\right)}{\left(i \cdot 2\right) \cdot \left(i \cdot 2\right) + \left(1 \cdot 1 + \left(i \cdot 2\right) \cdot 1\right)}} \]
      10. lift-*.f32N/A

        \[\leadsto \left(i \cdot i\right) \cdot \frac{\frac{1}{4}}{\frac{\left(1 - \color{blue}{-2 \cdot i}\right) \cdot \left({\left(i \cdot 2\right)}^{3} - {1}^{3}\right)}{\left(i \cdot 2\right) \cdot \left(i \cdot 2\right) + \left(1 \cdot 1 + \left(i \cdot 2\right) \cdot 1\right)}} \]
      11. fp-cancel-sub-sign-invN/A

        \[\leadsto \left(i \cdot i\right) \cdot \frac{\frac{1}{4}}{\frac{\color{blue}{\left(1 + \left(\mathsf{neg}\left(-2\right)\right) \cdot i\right)} \cdot \left({\left(i \cdot 2\right)}^{3} - {1}^{3}\right)}{\left(i \cdot 2\right) \cdot \left(i \cdot 2\right) + \left(1 \cdot 1 + \left(i \cdot 2\right) \cdot 1\right)}} \]
      12. metadata-evalN/A

        \[\leadsto \left(i \cdot i\right) \cdot \frac{\frac{1}{4}}{\frac{\left(1 + \color{blue}{2} \cdot i\right) \cdot \left({\left(i \cdot 2\right)}^{3} - {1}^{3}\right)}{\left(i \cdot 2\right) \cdot \left(i \cdot 2\right) + \left(1 \cdot 1 + \left(i \cdot 2\right) \cdot 1\right)}} \]
      13. +-commutativeN/A

        \[\leadsto \left(i \cdot i\right) \cdot \frac{\frac{1}{4}}{\frac{\color{blue}{\left(2 \cdot i + 1\right)} \cdot \left({\left(i \cdot 2\right)}^{3} - {1}^{3}\right)}{\left(i \cdot 2\right) \cdot \left(i \cdot 2\right) + \left(1 \cdot 1 + \left(i \cdot 2\right) \cdot 1\right)}} \]
    7. Applied rewrites99.8%

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

    if 2e3 < i

    1. Initial program 15.2%

      \[\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. Add Preprocessing
    3. Taylor expanded in i around inf

      \[\leadsto \color{blue}{\frac{1}{16}} \]
    4. Step-by-step derivation
      1. Applied rewrites100.0%

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

    Alternative 2: 98.1% accurate, 2.4× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;i \leq 0.5:\\ \;\;\;\;\left(i \cdot -0.25 - i \cdot \left(i \cdot i\right)\right) \cdot i\\ \mathbf{else}:\\ \;\;\;\;\frac{0.015625}{i \cdot i} + 0.0625\\ \end{array} \end{array} \]
    (FPCore (i)
     :precision binary32
     (if (<= i 0.5)
       (* (- (* i -0.25) (* i (* i i))) i)
       (+ (/ 0.015625 (* i i)) 0.0625)))
    float code(float i) {
    	float tmp;
    	if (i <= 0.5f) {
    		tmp = ((i * -0.25f) - (i * (i * i))) * i;
    	} else {
    		tmp = (0.015625f / (i * i)) + 0.0625f;
    	}
    	return tmp;
    }
    
    real(4) function code(i)
        real(4), intent (in) :: i
        real(4) :: tmp
        if (i <= 0.5e0) then
            tmp = ((i * (-0.25e0)) - (i * (i * i))) * i
        else
            tmp = (0.015625e0 / (i * i)) + 0.0625e0
        end if
        code = tmp
    end function
    
    function code(i)
    	tmp = Float32(0.0)
    	if (i <= Float32(0.5))
    		tmp = Float32(Float32(Float32(i * Float32(-0.25)) - Float32(i * Float32(i * i))) * i);
    	else
    		tmp = Float32(Float32(Float32(0.015625) / Float32(i * i)) + Float32(0.0625));
    	end
    	return tmp
    end
    
    function tmp_2 = code(i)
    	tmp = single(0.0);
    	if (i <= single(0.5))
    		tmp = ((i * single(-0.25)) - (i * (i * i))) * i;
    	else
    		tmp = (single(0.015625) / (i * i)) + single(0.0625);
    	end
    	tmp_2 = tmp;
    end
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;i \leq 0.5:\\
    \;\;\;\;\left(i \cdot -0.25 - i \cdot \left(i \cdot i\right)\right) \cdot i\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{0.015625}{i \cdot i} + 0.0625\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if i < 0.5

      1. Initial program 38.7%

        \[\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. Add Preprocessing
      3. Taylor expanded in i around 0

        \[\leadsto \color{blue}{{i}^{2} \cdot \left({i}^{2} \cdot \left(-4 \cdot {i}^{2} - 1\right) - \frac{1}{4}\right)} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{\left({i}^{2} \cdot \left(-4 \cdot {i}^{2} - 1\right) - \frac{1}{4}\right) \cdot {i}^{2}} \]
        2. lower-*.f32N/A

          \[\leadsto \color{blue}{\left({i}^{2} \cdot \left(-4 \cdot {i}^{2} - 1\right) - \frac{1}{4}\right) \cdot {i}^{2}} \]
      5. Applied rewrites98.1%

        \[\leadsto \color{blue}{\left(\left(\left(-4 \cdot i\right) \cdot i - 1\right) \cdot \left(i \cdot i\right) - 0.25\right) \cdot \left(i \cdot i\right)} \]
      6. Applied rewrites98.1%

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

        \[\leadsto \left(i \cdot \left(-1 \cdot {i}^{2} - \frac{1}{4}\right)\right) \cdot i \]
      8. Step-by-step derivation
        1. Applied rewrites97.6%

          \[\leadsto \left(\left(-0.25 - i \cdot i\right) \cdot i\right) \cdot i \]
        2. Step-by-step derivation
          1. Applied rewrites97.6%

            \[\leadsto \left(i \cdot -0.25 + i \cdot \left(\left(-i\right) \cdot i\right)\right) \cdot i \]

          if 0.5 < i

          1. Initial program 24.6%

            \[\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. Add Preprocessing
          3. Taylor expanded in i around inf

            \[\leadsto \color{blue}{\frac{1}{16} + \frac{1}{64} \cdot \frac{1}{{i}^{2}}} \]
          4. Step-by-step derivation
            1. +-commutativeN/A

              \[\leadsto \color{blue}{\frac{1}{64} \cdot \frac{1}{{i}^{2}} + \frac{1}{16}} \]
            2. lower-+.f32N/A

              \[\leadsto \color{blue}{\frac{1}{64} \cdot \frac{1}{{i}^{2}} + \frac{1}{16}} \]
            3. associate-*r/N/A

              \[\leadsto \color{blue}{\frac{\frac{1}{64} \cdot 1}{{i}^{2}}} + \frac{1}{16} \]
            4. metadata-evalN/A

              \[\leadsto \frac{\color{blue}{\frac{1}{64}}}{{i}^{2}} + \frac{1}{16} \]
            5. lower-/.f32N/A

              \[\leadsto \color{blue}{\frac{\frac{1}{64}}{{i}^{2}}} + \frac{1}{16} \]
            6. unpow2N/A

              \[\leadsto \frac{\frac{1}{64}}{\color{blue}{i \cdot i}} + \frac{1}{16} \]
            7. lower-*.f3297.3

              \[\leadsto \frac{0.015625}{\color{blue}{i \cdot i}} + 0.0625 \]
          5. Applied rewrites97.3%

            \[\leadsto \color{blue}{\frac{0.015625}{i \cdot i} + 0.0625} \]
        3. Recombined 2 regimes into one program.
        4. Final simplification97.4%

          \[\leadsto \begin{array}{l} \mathbf{if}\;i \leq 0.5:\\ \;\;\;\;\left(i \cdot -0.25 - i \cdot \left(i \cdot i\right)\right) \cdot i\\ \mathbf{else}:\\ \;\;\;\;\frac{0.015625}{i \cdot i} + 0.0625\\ \end{array} \]
        5. Add Preprocessing

        Alternative 3: 98.1% accurate, 2.7× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;i \leq 0.5:\\ \;\;\;\;\left(\left(-0.25 - i \cdot i\right) \cdot i\right) \cdot i\\ \mathbf{else}:\\ \;\;\;\;\frac{0.015625}{i \cdot i} + 0.0625\\ \end{array} \end{array} \]
        (FPCore (i)
         :precision binary32
         (if (<= i 0.5) (* (* (- -0.25 (* i i)) i) i) (+ (/ 0.015625 (* i i)) 0.0625)))
        float code(float i) {
        	float tmp;
        	if (i <= 0.5f) {
        		tmp = ((-0.25f - (i * i)) * i) * i;
        	} else {
        		tmp = (0.015625f / (i * i)) + 0.0625f;
        	}
        	return tmp;
        }
        
        real(4) function code(i)
            real(4), intent (in) :: i
            real(4) :: tmp
            if (i <= 0.5e0) then
                tmp = (((-0.25e0) - (i * i)) * i) * i
            else
                tmp = (0.015625e0 / (i * i)) + 0.0625e0
            end if
            code = tmp
        end function
        
        function code(i)
        	tmp = Float32(0.0)
        	if (i <= Float32(0.5))
        		tmp = Float32(Float32(Float32(Float32(-0.25) - Float32(i * i)) * i) * i);
        	else
        		tmp = Float32(Float32(Float32(0.015625) / Float32(i * i)) + Float32(0.0625));
        	end
        	return tmp
        end
        
        function tmp_2 = code(i)
        	tmp = single(0.0);
        	if (i <= single(0.5))
        		tmp = ((single(-0.25) - (i * i)) * i) * i;
        	else
        		tmp = (single(0.015625) / (i * i)) + single(0.0625);
        	end
        	tmp_2 = tmp;
        end
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;i \leq 0.5:\\
        \;\;\;\;\left(\left(-0.25 - i \cdot i\right) \cdot i\right) \cdot i\\
        
        \mathbf{else}:\\
        \;\;\;\;\frac{0.015625}{i \cdot i} + 0.0625\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if i < 0.5

          1. Initial program 38.7%

            \[\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. Add Preprocessing
          3. Taylor expanded in i around 0

            \[\leadsto \color{blue}{{i}^{2} \cdot \left({i}^{2} \cdot \left(-4 \cdot {i}^{2} - 1\right) - \frac{1}{4}\right)} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{\left({i}^{2} \cdot \left(-4 \cdot {i}^{2} - 1\right) - \frac{1}{4}\right) \cdot {i}^{2}} \]
            2. lower-*.f32N/A

              \[\leadsto \color{blue}{\left({i}^{2} \cdot \left(-4 \cdot {i}^{2} - 1\right) - \frac{1}{4}\right) \cdot {i}^{2}} \]
          5. Applied rewrites98.1%

            \[\leadsto \color{blue}{\left(\left(\left(-4 \cdot i\right) \cdot i - 1\right) \cdot \left(i \cdot i\right) - 0.25\right) \cdot \left(i \cdot i\right)} \]
          6. Applied rewrites98.1%

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

            \[\leadsto \left(i \cdot \left(-1 \cdot {i}^{2} - \frac{1}{4}\right)\right) \cdot i \]
          8. Step-by-step derivation
            1. Applied rewrites97.6%

              \[\leadsto \left(\left(-0.25 - i \cdot i\right) \cdot i\right) \cdot i \]

            if 0.5 < i

            1. Initial program 24.6%

              \[\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. Add Preprocessing
            3. Taylor expanded in i around inf

              \[\leadsto \color{blue}{\frac{1}{16} + \frac{1}{64} \cdot \frac{1}{{i}^{2}}} \]
            4. Step-by-step derivation
              1. +-commutativeN/A

                \[\leadsto \color{blue}{\frac{1}{64} \cdot \frac{1}{{i}^{2}} + \frac{1}{16}} \]
              2. lower-+.f32N/A

                \[\leadsto \color{blue}{\frac{1}{64} \cdot \frac{1}{{i}^{2}} + \frac{1}{16}} \]
              3. associate-*r/N/A

                \[\leadsto \color{blue}{\frac{\frac{1}{64} \cdot 1}{{i}^{2}}} + \frac{1}{16} \]
              4. metadata-evalN/A

                \[\leadsto \frac{\color{blue}{\frac{1}{64}}}{{i}^{2}} + \frac{1}{16} \]
              5. lower-/.f32N/A

                \[\leadsto \color{blue}{\frac{\frac{1}{64}}{{i}^{2}}} + \frac{1}{16} \]
              6. unpow2N/A

                \[\leadsto \frac{\frac{1}{64}}{\color{blue}{i \cdot i}} + \frac{1}{16} \]
              7. lower-*.f3297.3

                \[\leadsto \frac{0.015625}{\color{blue}{i \cdot i}} + 0.0625 \]
            5. Applied rewrites97.3%

              \[\leadsto \color{blue}{\frac{0.015625}{i \cdot i} + 0.0625} \]
          9. Recombined 2 regimes into one program.
          10. Add Preprocessing

          Alternative 4: 97.2% accurate, 2.8× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;i \leq 0.5:\\ \;\;\;\;\left(\left(-0.25 - i \cdot i\right) \cdot i\right) \cdot i\\ \mathbf{else}:\\ \;\;\;\;0.0625\\ \end{array} \end{array} \]
          (FPCore (i)
           :precision binary32
           (if (<= i 0.5) (* (* (- -0.25 (* i i)) i) i) 0.0625))
          float code(float i) {
          	float tmp;
          	if (i <= 0.5f) {
          		tmp = ((-0.25f - (i * i)) * i) * i;
          	} else {
          		tmp = 0.0625f;
          	}
          	return tmp;
          }
          
          real(4) function code(i)
              real(4), intent (in) :: i
              real(4) :: tmp
              if (i <= 0.5e0) then
                  tmp = (((-0.25e0) - (i * i)) * i) * i
              else
                  tmp = 0.0625e0
              end if
              code = tmp
          end function
          
          function code(i)
          	tmp = Float32(0.0)
          	if (i <= Float32(0.5))
          		tmp = Float32(Float32(Float32(Float32(-0.25) - Float32(i * i)) * i) * i);
          	else
          		tmp = Float32(0.0625);
          	end
          	return tmp
          end
          
          function tmp_2 = code(i)
          	tmp = single(0.0);
          	if (i <= single(0.5))
          		tmp = ((single(-0.25) - (i * i)) * i) * i;
          	else
          		tmp = single(0.0625);
          	end
          	tmp_2 = tmp;
          end
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;i \leq 0.5:\\
          \;\;\;\;\left(\left(-0.25 - i \cdot i\right) \cdot i\right) \cdot i\\
          
          \mathbf{else}:\\
          \;\;\;\;0.0625\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if i < 0.5

            1. Initial program 38.7%

              \[\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. Add Preprocessing
            3. Taylor expanded in i around 0

              \[\leadsto \color{blue}{{i}^{2} \cdot \left({i}^{2} \cdot \left(-4 \cdot {i}^{2} - 1\right) - \frac{1}{4}\right)} \]
            4. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \color{blue}{\left({i}^{2} \cdot \left(-4 \cdot {i}^{2} - 1\right) - \frac{1}{4}\right) \cdot {i}^{2}} \]
              2. lower-*.f32N/A

                \[\leadsto \color{blue}{\left({i}^{2} \cdot \left(-4 \cdot {i}^{2} - 1\right) - \frac{1}{4}\right) \cdot {i}^{2}} \]
            5. Applied rewrites98.1%

              \[\leadsto \color{blue}{\left(\left(\left(-4 \cdot i\right) \cdot i - 1\right) \cdot \left(i \cdot i\right) - 0.25\right) \cdot \left(i \cdot i\right)} \]
            6. Applied rewrites98.1%

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

              \[\leadsto \left(i \cdot \left(-1 \cdot {i}^{2} - \frac{1}{4}\right)\right) \cdot i \]
            8. Step-by-step derivation
              1. Applied rewrites97.6%

                \[\leadsto \left(\left(-0.25 - i \cdot i\right) \cdot i\right) \cdot i \]

              if 0.5 < i

              1. Initial program 24.6%

                \[\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. Add Preprocessing
              3. Taylor expanded in i around inf

                \[\leadsto \color{blue}{\frac{1}{16}} \]
              4. Step-by-step derivation
                1. Applied rewrites95.1%

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

              Alternative 5: 96.4% accurate, 4.2× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;i \leq 0.5:\\ \;\;\;\;\left(-0.25 \cdot i\right) \cdot i\\ \mathbf{else}:\\ \;\;\;\;0.0625\\ \end{array} \end{array} \]
              (FPCore (i) :precision binary32 (if (<= i 0.5) (* (* -0.25 i) i) 0.0625))
              float code(float i) {
              	float tmp;
              	if (i <= 0.5f) {
              		tmp = (-0.25f * i) * i;
              	} else {
              		tmp = 0.0625f;
              	}
              	return tmp;
              }
              
              real(4) function code(i)
                  real(4), intent (in) :: i
                  real(4) :: tmp
                  if (i <= 0.5e0) then
                      tmp = ((-0.25e0) * i) * i
                  else
                      tmp = 0.0625e0
                  end if
                  code = tmp
              end function
              
              function code(i)
              	tmp = Float32(0.0)
              	if (i <= Float32(0.5))
              		tmp = Float32(Float32(Float32(-0.25) * i) * i);
              	else
              		tmp = Float32(0.0625);
              	end
              	return tmp
              end
              
              function tmp_2 = code(i)
              	tmp = single(0.0);
              	if (i <= single(0.5))
              		tmp = (single(-0.25) * i) * i;
              	else
              		tmp = single(0.0625);
              	end
              	tmp_2 = tmp;
              end
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              \mathbf{if}\;i \leq 0.5:\\
              \;\;\;\;\left(-0.25 \cdot i\right) \cdot i\\
              
              \mathbf{else}:\\
              \;\;\;\;0.0625\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if i < 0.5

                1. Initial program 38.7%

                  \[\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. Add Preprocessing
                3. Taylor expanded in i around 0

                  \[\leadsto \color{blue}{\frac{-1}{4} \cdot {i}^{2}} \]
                4. Step-by-step derivation
                  1. metadata-evalN/A

                    \[\leadsto \color{blue}{\left(\frac{1}{4} \cdot -1\right)} \cdot {i}^{2} \]
                  2. associate-*r*N/A

                    \[\leadsto \color{blue}{\frac{1}{4} \cdot \left(-1 \cdot {i}^{2}\right)} \]
                  3. mul-1-negN/A

                    \[\leadsto \frac{1}{4} \cdot \color{blue}{\left(\mathsf{neg}\left({i}^{2}\right)\right)} \]
                  4. unpow2N/A

                    \[\leadsto \frac{1}{4} \cdot \left(\mathsf{neg}\left(\color{blue}{i \cdot i}\right)\right) \]
                  5. distribute-lft-neg-inN/A

                    \[\leadsto \frac{1}{4} \cdot \color{blue}{\left(\left(\mathsf{neg}\left(i\right)\right) \cdot i\right)} \]
                  6. associate-*r*N/A

                    \[\leadsto \color{blue}{\left(\frac{1}{4} \cdot \left(\mathsf{neg}\left(i\right)\right)\right) \cdot i} \]
                  7. lower-*.f32N/A

                    \[\leadsto \color{blue}{\left(\frac{1}{4} \cdot \left(\mathsf{neg}\left(i\right)\right)\right) \cdot i} \]
                  8. mul-1-negN/A

                    \[\leadsto \left(\frac{1}{4} \cdot \color{blue}{\left(-1 \cdot i\right)}\right) \cdot i \]
                  9. associate-*r*N/A

                    \[\leadsto \color{blue}{\left(\left(\frac{1}{4} \cdot -1\right) \cdot i\right)} \cdot i \]
                  10. metadata-evalN/A

                    \[\leadsto \left(\color{blue}{\frac{-1}{4}} \cdot i\right) \cdot i \]
                  11. lower-*.f3296.2

                    \[\leadsto \color{blue}{\left(-0.25 \cdot i\right)} \cdot i \]
                5. Applied rewrites96.2%

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

                if 0.5 < i

                1. Initial program 24.6%

                  \[\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. Add Preprocessing
                3. Taylor expanded in i around inf

                  \[\leadsto \color{blue}{\frac{1}{16}} \]
                4. Step-by-step derivation
                  1. Applied rewrites95.1%

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

                Alternative 6: 51.7% accurate, 71.0× speedup?

                \[\begin{array}{l} \\ 0.0625 \end{array} \]
                (FPCore (i) :precision binary32 0.0625)
                float code(float i) {
                	return 0.0625f;
                }
                
                real(4) function code(i)
                    real(4), intent (in) :: i
                    code = 0.0625e0
                end function
                
                function code(i)
                	return Float32(0.0625)
                end
                
                function tmp = code(i)
                	tmp = single(0.0625);
                end
                
                \begin{array}{l}
                
                \\
                0.0625
                \end{array}
                
                Derivation
                1. Initial program 30.8%

                  \[\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. Add Preprocessing
                3. Taylor expanded in i around inf

                  \[\leadsto \color{blue}{\frac{1}{16}} \]
                4. Step-by-step derivation
                  1. Applied rewrites55.5%

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

                  Reproduce

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