Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, D

Percentage Accurate: 99.8% → 99.8%
Time: 17.5s
Alternatives: 8
Speedup: 1.4×

Specification

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

\\
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.8% accurate, 1.0× speedup?

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

\\
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\end{array}

Alternative 1: 99.8% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \left(\left(x \cdot x\right) \cdot 9 + 3\right) + x \cdot -12 \end{array} \]
(FPCore (x) :precision binary64 (+ (+ (* (* x x) 9.0) 3.0) (* x -12.0)))
double code(double x) {
	return (((x * x) * 9.0) + 3.0) + (x * -12.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (((x * x) * 9.0d0) + 3.0d0) + (x * (-12.0d0))
end function
public static double code(double x) {
	return (((x * x) * 9.0) + 3.0) + (x * -12.0);
}
def code(x):
	return (((x * x) * 9.0) + 3.0) + (x * -12.0)
function code(x)
	return Float64(Float64(Float64(Float64(x * x) * 9.0) + 3.0) + Float64(x * -12.0))
end
function tmp = code(x)
	tmp = (((x * x) * 9.0) + 3.0) + (x * -12.0);
end
code[x_] := N[(N[(N[(N[(x * x), $MachinePrecision] * 9.0), $MachinePrecision] + 3.0), $MachinePrecision] + N[(x * -12.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(x \cdot x\right) \cdot 9 + 3\right) + x \cdot -12
\end{array}
Derivation
  1. Initial program 99.8%

    \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
  2. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \cdot \color{blue}{3} \]
    2. distribute-rgt1-inN/A

      \[\leadsto 3 + \color{blue}{\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) \cdot 3} \]
    3. +-lowering-+.f64N/A

      \[\leadsto \mathsf{+.f64}\left(3, \color{blue}{\left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) \cdot 3\right)}\right) \]
    4. *-commutativeN/A

      \[\leadsto \mathsf{+.f64}\left(3, \left(\left(x \cdot \left(x \cdot 3\right) - x \cdot 4\right) \cdot 3\right)\right) \]
    5. distribute-lft-out--N/A

      \[\leadsto \mathsf{+.f64}\left(3, \left(\left(x \cdot \left(x \cdot 3 - 4\right)\right) \cdot 3\right)\right) \]
    6. associate-*l*N/A

      \[\leadsto \mathsf{+.f64}\left(3, \left(x \cdot \color{blue}{\left(\left(x \cdot 3 - 4\right) \cdot 3\right)}\right)\right) \]
    7. *-lowering-*.f64N/A

      \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \color{blue}{\left(\left(x \cdot 3 - 4\right) \cdot 3\right)}\right)\right) \]
    8. *-commutativeN/A

      \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \left(3 \cdot \color{blue}{\left(x \cdot 3 - 4\right)}\right)\right)\right) \]
    9. sub-negN/A

      \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \left(3 \cdot \left(x \cdot 3 + \color{blue}{\left(\mathsf{neg}\left(4\right)\right)}\right)\right)\right)\right) \]
    10. distribute-lft-inN/A

      \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \left(3 \cdot \left(x \cdot 3\right) + \color{blue}{3 \cdot \left(\mathsf{neg}\left(4\right)\right)}\right)\right)\right) \]
    11. +-lowering-+.f64N/A

      \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\left(3 \cdot \left(x \cdot 3\right)\right), \color{blue}{\left(3 \cdot \left(\mathsf{neg}\left(4\right)\right)\right)}\right)\right)\right) \]
    12. *-commutativeN/A

      \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\left(\left(x \cdot 3\right) \cdot 3\right), \left(\color{blue}{3} \cdot \left(\mathsf{neg}\left(4\right)\right)\right)\right)\right)\right) \]
    13. associate-*l*N/A

      \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\left(x \cdot \left(3 \cdot 3\right)\right), \left(\color{blue}{3} \cdot \left(\mathsf{neg}\left(4\right)\right)\right)\right)\right)\right) \]
    14. *-lowering-*.f64N/A

      \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(3 \cdot 3\right)\right), \left(\color{blue}{3} \cdot \left(\mathsf{neg}\left(4\right)\right)\right)\right)\right)\right) \]
    15. metadata-evalN/A

      \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 9\right), \left(3 \cdot \left(\mathsf{neg}\left(4\right)\right)\right)\right)\right)\right) \]
    16. metadata-evalN/A

      \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 9\right), \left(3 \cdot -4\right)\right)\right)\right) \]
    17. metadata-eval99.9%

      \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 9\right), -12\right)\right)\right) \]
  3. Simplified99.9%

    \[\leadsto \color{blue}{3 + x \cdot \left(x \cdot 9 + -12\right)} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto x \cdot \left(x \cdot 9 + -12\right) + \color{blue}{3} \]
    2. distribute-lft-inN/A

      \[\leadsto \left(x \cdot \left(x \cdot 9\right) + x \cdot -12\right) + 3 \]
    3. associate-+l+N/A

      \[\leadsto x \cdot \left(x \cdot 9\right) + \color{blue}{\left(x \cdot -12 + 3\right)} \]
    4. associate-*r*N/A

      \[\leadsto \left(x \cdot x\right) \cdot 9 + \left(\color{blue}{x \cdot -12} + 3\right) \]
    5. *-commutativeN/A

      \[\leadsto \left(x \cdot x\right) \cdot 9 + \left(-12 \cdot x + 3\right) \]
    6. fma-defineN/A

      \[\leadsto \mathsf{fma}\left(x \cdot x, \color{blue}{9}, -12 \cdot x + 3\right) \]
    7. fma-lowering-fma.f64N/A

      \[\leadsto \mathsf{fma.f64}\left(\left(x \cdot x\right), \color{blue}{9}, \left(-12 \cdot x + 3\right)\right) \]
    8. *-lowering-*.f64N/A

      \[\leadsto \mathsf{fma.f64}\left(\mathsf{*.f64}\left(x, x\right), 9, \left(-12 \cdot x + 3\right)\right) \]
    9. +-lowering-+.f64N/A

      \[\leadsto \mathsf{fma.f64}\left(\mathsf{*.f64}\left(x, x\right), 9, \mathsf{+.f64}\left(\left(-12 \cdot x\right), 3\right)\right) \]
    10. *-commutativeN/A

      \[\leadsto \mathsf{fma.f64}\left(\mathsf{*.f64}\left(x, x\right), 9, \mathsf{+.f64}\left(\left(x \cdot -12\right), 3\right)\right) \]
    11. *-lowering-*.f6499.9%

      \[\leadsto \mathsf{fma.f64}\left(\mathsf{*.f64}\left(x, x\right), 9, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, -12\right), 3\right)\right) \]
  6. Applied egg-rr99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot x, 9, x \cdot -12 + 3\right)} \]
  7. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \left(x \cdot x\right) \cdot 9 + \left(3 + \color{blue}{x \cdot -12}\right) \]
    2. associate-+r+N/A

      \[\leadsto \left(\left(x \cdot x\right) \cdot 9 + 3\right) + \color{blue}{x \cdot -12} \]
    3. +-lowering-+.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\left(\left(x \cdot x\right) \cdot 9 + 3\right), \color{blue}{\left(x \cdot -12\right)}\right) \]
    4. +-lowering-+.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{+.f64}\left(\left(\left(x \cdot x\right) \cdot 9\right), 3\right), \left(\color{blue}{x} \cdot -12\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\left(x \cdot x\right), 9\right), 3\right), \left(x \cdot -12\right)\right) \]
    6. *-lowering-*.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), 9\right), 3\right), \left(x \cdot -12\right)\right) \]
    7. *-lowering-*.f6499.9%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), 9\right), 3\right), \mathsf{*.f64}\left(x, \color{blue}{-12}\right)\right) \]
  8. Applied egg-rr99.9%

    \[\leadsto \color{blue}{\left(\left(x \cdot x\right) \cdot 9 + 3\right) + x \cdot -12} \]
  9. Add Preprocessing

Alternative 2: 98.7% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(-12 + x \cdot 9\right)\\ \mathbf{if}\;x \leq -0.58:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 0.56:\\ \;\;\;\;3 \cdot \left(x \cdot -4 + 1\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (* x (+ -12.0 (* x 9.0)))))
   (if (<= x -0.58) t_0 (if (<= x 0.56) (* 3.0 (+ (* x -4.0) 1.0)) t_0))))
double code(double x) {
	double t_0 = x * (-12.0 + (x * 9.0));
	double tmp;
	if (x <= -0.58) {
		tmp = t_0;
	} else if (x <= 0.56) {
		tmp = 3.0 * ((x * -4.0) + 1.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = x * ((-12.0d0) + (x * 9.0d0))
    if (x <= (-0.58d0)) then
        tmp = t_0
    else if (x <= 0.56d0) then
        tmp = 3.0d0 * ((x * (-4.0d0)) + 1.0d0)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = x * (-12.0 + (x * 9.0));
	double tmp;
	if (x <= -0.58) {
		tmp = t_0;
	} else if (x <= 0.56) {
		tmp = 3.0 * ((x * -4.0) + 1.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x):
	t_0 = x * (-12.0 + (x * 9.0))
	tmp = 0
	if x <= -0.58:
		tmp = t_0
	elif x <= 0.56:
		tmp = 3.0 * ((x * -4.0) + 1.0)
	else:
		tmp = t_0
	return tmp
function code(x)
	t_0 = Float64(x * Float64(-12.0 + Float64(x * 9.0)))
	tmp = 0.0
	if (x <= -0.58)
		tmp = t_0;
	elseif (x <= 0.56)
		tmp = Float64(3.0 * Float64(Float64(x * -4.0) + 1.0));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = x * (-12.0 + (x * 9.0));
	tmp = 0.0;
	if (x <= -0.58)
		tmp = t_0;
	elseif (x <= 0.56)
		tmp = 3.0 * ((x * -4.0) + 1.0);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(x * N[(-12.0 + N[(x * 9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.58], t$95$0, If[LessEqual[x, 0.56], N[(3.0 * N[(N[(x * -4.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \left(-12 + x \cdot 9\right)\\
\mathbf{if}\;x \leq -0.58:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq 0.56:\\
\;\;\;\;3 \cdot \left(x \cdot -4 + 1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -0.57999999999999996 or 0.56000000000000005 < x

    1. Initial program 99.6%

      \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{{x}^{2} \cdot \left(9 - 12 \cdot \frac{1}{x}\right)} \]
    4. Step-by-step derivation
      1. unpow2N/A

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

        \[\leadsto x \cdot \color{blue}{\left(x \cdot \left(9 - 12 \cdot \frac{1}{x}\right)\right)} \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(x \cdot \left(9 - 12 \cdot \frac{1}{x}\right)\right)}\right) \]
      4. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(x \cdot \left(9 + \color{blue}{\left(\mathsf{neg}\left(12 \cdot \frac{1}{x}\right)\right)}\right)\right)\right) \]
      5. distribute-rgt-inN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(9 \cdot x + \color{blue}{\left(\mathsf{neg}\left(12 \cdot \frac{1}{x}\right)\right) \cdot x}\right)\right) \]
      6. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(\left(\mathsf{neg}\left(12 \cdot \frac{1}{x}\right)\right) \cdot x + \color{blue}{9 \cdot x}\right)\right) \]
      7. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(\left(\left(\mathsf{neg}\left(12\right)\right) \cdot \frac{1}{x}\right) \cdot x + 9 \cdot x\right)\right) \]
      8. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(\left(-12 \cdot \frac{1}{x}\right) \cdot x + 9 \cdot x\right)\right) \]
      9. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(-12 \cdot \left(\frac{1}{x} \cdot x\right) + \color{blue}{9} \cdot x\right)\right) \]
      10. fma-defineN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(\mathsf{fma}\left(-12, \color{blue}{\frac{1}{x} \cdot x}, 9 \cdot x\right)\right)\right) \]
      11. lft-mult-inverseN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(\mathsf{fma}\left(-12, 1, 9 \cdot x\right)\right)\right) \]
      12. fma-undefineN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(-12 \cdot 1 + \color{blue}{9 \cdot x}\right)\right) \]
      13. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(-12 + \color{blue}{9} \cdot x\right)\right) \]
      14. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(-12, \color{blue}{\left(9 \cdot x\right)}\right)\right) \]
      15. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(-12, \left(x \cdot \color{blue}{9}\right)\right)\right) \]
      16. *-lowering-*.f6498.7%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(-12, \mathsf{*.f64}\left(x, \color{blue}{9}\right)\right)\right) \]
    5. Simplified98.7%

      \[\leadsto \color{blue}{x \cdot \left(-12 + x \cdot 9\right)} \]

    if -0.57999999999999996 < x < 0.56000000000000005

    1. Initial program 100.0%

      \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \mathsf{*.f64}\left(3, \mathsf{+.f64}\left(\color{blue}{\left(-4 \cdot x\right)}, 1\right)\right) \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(3, \mathsf{+.f64}\left(\left(x \cdot -4\right), 1\right)\right) \]
      2. *-lowering-*.f6499.6%

        \[\leadsto \mathsf{*.f64}\left(3, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, -4\right), 1\right)\right) \]
    5. Simplified99.6%

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

Alternative 3: 98.2% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.55:\\ \;\;\;\;x \cdot \left(x \cdot 9\right)\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;3 \cdot \left(x \cdot -4 + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot x\right) \cdot 9\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -1.55)
   (* x (* x 9.0))
   (if (<= x 1.0) (* 3.0 (+ (* x -4.0) 1.0)) (* (* x x) 9.0))))
double code(double x) {
	double tmp;
	if (x <= -1.55) {
		tmp = x * (x * 9.0);
	} else if (x <= 1.0) {
		tmp = 3.0 * ((x * -4.0) + 1.0);
	} else {
		tmp = (x * x) * 9.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-1.55d0)) then
        tmp = x * (x * 9.0d0)
    else if (x <= 1.0d0) then
        tmp = 3.0d0 * ((x * (-4.0d0)) + 1.0d0)
    else
        tmp = (x * x) * 9.0d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= -1.55) {
		tmp = x * (x * 9.0);
	} else if (x <= 1.0) {
		tmp = 3.0 * ((x * -4.0) + 1.0);
	} else {
		tmp = (x * x) * 9.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -1.55:
		tmp = x * (x * 9.0)
	elif x <= 1.0:
		tmp = 3.0 * ((x * -4.0) + 1.0)
	else:
		tmp = (x * x) * 9.0
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -1.55)
		tmp = Float64(x * Float64(x * 9.0));
	elseif (x <= 1.0)
		tmp = Float64(3.0 * Float64(Float64(x * -4.0) + 1.0));
	else
		tmp = Float64(Float64(x * x) * 9.0);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -1.55)
		tmp = x * (x * 9.0);
	elseif (x <= 1.0)
		tmp = 3.0 * ((x * -4.0) + 1.0);
	else
		tmp = (x * x) * 9.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, -1.55], N[(x * N[(x * 9.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], N[(3.0 * N[(N[(x * -4.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] * 9.0), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55:\\
\;\;\;\;x \cdot \left(x \cdot 9\right)\\

\mathbf{elif}\;x \leq 1:\\
\;\;\;\;3 \cdot \left(x \cdot -4 + 1\right)\\

\mathbf{else}:\\
\;\;\;\;\left(x \cdot x\right) \cdot 9\\


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

    1. Initial program 99.6%

      \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{9 \cdot {x}^{2}} \]
    4. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto 9 \cdot \left(x \cdot \color{blue}{x}\right) \]
      2. associate-*r*N/A

        \[\leadsto \left(9 \cdot x\right) \cdot \color{blue}{x} \]
      3. *-commutativeN/A

        \[\leadsto x \cdot \color{blue}{\left(9 \cdot x\right)} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(9 \cdot x\right)}\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(x \cdot \color{blue}{9}\right)\right) \]
      6. *-lowering-*.f6497.0%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{9}\right)\right) \]
    5. Simplified97.0%

      \[\leadsto \color{blue}{x \cdot \left(x \cdot 9\right)} \]

    if -1.55000000000000004 < x < 1

    1. Initial program 100.0%

      \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \mathsf{*.f64}\left(3, \mathsf{+.f64}\left(\color{blue}{\left(-4 \cdot x\right)}, 1\right)\right) \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(3, \mathsf{+.f64}\left(\left(x \cdot -4\right), 1\right)\right) \]
      2. *-lowering-*.f6499.6%

        \[\leadsto \mathsf{*.f64}\left(3, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, -4\right), 1\right)\right) \]
    5. Simplified99.6%

      \[\leadsto 3 \cdot \left(\color{blue}{x \cdot -4} + 1\right) \]

    if 1 < x

    1. Initial program 99.6%

      \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \mathsf{*.f64}\left(3, \color{blue}{\left(3 \cdot {x}^{2}\right)}\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(3, \mathsf{*.f64}\left(3, \color{blue}{\left({x}^{2}\right)}\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(3, \mathsf{*.f64}\left(3, \left(x \cdot \color{blue}{x}\right)\right)\right) \]
      3. *-lowering-*.f6498.1%

        \[\leadsto \mathsf{*.f64}\left(3, \mathsf{*.f64}\left(3, \mathsf{*.f64}\left(x, \color{blue}{x}\right)\right)\right) \]
    5. Simplified98.1%

      \[\leadsto 3 \cdot \color{blue}{\left(3 \cdot \left(x \cdot x\right)\right)} \]
    6. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \left(3 \cdot 3\right) \cdot \color{blue}{\left(x \cdot x\right)} \]
      2. metadata-evalN/A

        \[\leadsto 9 \cdot \left(\color{blue}{x} \cdot x\right) \]
      3. *-commutativeN/A

        \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{9} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(x \cdot x\right), \color{blue}{9}\right) \]
      5. *-lowering-*.f6498.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), 9\right) \]
    7. Applied egg-rr98.3%

      \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 9} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 98.2% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.55:\\ \;\;\;\;x \cdot \left(x \cdot 9\right)\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;3 + x \cdot -12\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot x\right) \cdot 9\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -1.55)
   (* x (* x 9.0))
   (if (<= x 1.0) (+ 3.0 (* x -12.0)) (* (* x x) 9.0))))
double code(double x) {
	double tmp;
	if (x <= -1.55) {
		tmp = x * (x * 9.0);
	} else if (x <= 1.0) {
		tmp = 3.0 + (x * -12.0);
	} else {
		tmp = (x * x) * 9.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-1.55d0)) then
        tmp = x * (x * 9.0d0)
    else if (x <= 1.0d0) then
        tmp = 3.0d0 + (x * (-12.0d0))
    else
        tmp = (x * x) * 9.0d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= -1.55) {
		tmp = x * (x * 9.0);
	} else if (x <= 1.0) {
		tmp = 3.0 + (x * -12.0);
	} else {
		tmp = (x * x) * 9.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -1.55:
		tmp = x * (x * 9.0)
	elif x <= 1.0:
		tmp = 3.0 + (x * -12.0)
	else:
		tmp = (x * x) * 9.0
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -1.55)
		tmp = Float64(x * Float64(x * 9.0));
	elseif (x <= 1.0)
		tmp = Float64(3.0 + Float64(x * -12.0));
	else
		tmp = Float64(Float64(x * x) * 9.0);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -1.55)
		tmp = x * (x * 9.0);
	elseif (x <= 1.0)
		tmp = 3.0 + (x * -12.0);
	else
		tmp = (x * x) * 9.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, -1.55], N[(x * N[(x * 9.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], N[(3.0 + N[(x * -12.0), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] * 9.0), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55:\\
\;\;\;\;x \cdot \left(x \cdot 9\right)\\

\mathbf{elif}\;x \leq 1:\\
\;\;\;\;3 + x \cdot -12\\

\mathbf{else}:\\
\;\;\;\;\left(x \cdot x\right) \cdot 9\\


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

    1. Initial program 99.6%

      \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{9 \cdot {x}^{2}} \]
    4. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto 9 \cdot \left(x \cdot \color{blue}{x}\right) \]
      2. associate-*r*N/A

        \[\leadsto \left(9 \cdot x\right) \cdot \color{blue}{x} \]
      3. *-commutativeN/A

        \[\leadsto x \cdot \color{blue}{\left(9 \cdot x\right)} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(9 \cdot x\right)}\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(x \cdot \color{blue}{9}\right)\right) \]
      6. *-lowering-*.f6497.0%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{9}\right)\right) \]
    5. Simplified97.0%

      \[\leadsto \color{blue}{x \cdot \left(x \cdot 9\right)} \]

    if -1.55000000000000004 < x < 1

    1. Initial program 100.0%

      \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
    2. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \cdot \color{blue}{3} \]
      2. distribute-rgt1-inN/A

        \[\leadsto 3 + \color{blue}{\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) \cdot 3} \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(3, \color{blue}{\left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) \cdot 3\right)}\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(3, \left(\left(x \cdot \left(x \cdot 3\right) - x \cdot 4\right) \cdot 3\right)\right) \]
      5. distribute-lft-out--N/A

        \[\leadsto \mathsf{+.f64}\left(3, \left(\left(x \cdot \left(x \cdot 3 - 4\right)\right) \cdot 3\right)\right) \]
      6. associate-*l*N/A

        \[\leadsto \mathsf{+.f64}\left(3, \left(x \cdot \color{blue}{\left(\left(x \cdot 3 - 4\right) \cdot 3\right)}\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \color{blue}{\left(\left(x \cdot 3 - 4\right) \cdot 3\right)}\right)\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \left(3 \cdot \color{blue}{\left(x \cdot 3 - 4\right)}\right)\right)\right) \]
      9. sub-negN/A

        \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \left(3 \cdot \left(x \cdot 3 + \color{blue}{\left(\mathsf{neg}\left(4\right)\right)}\right)\right)\right)\right) \]
      10. distribute-lft-inN/A

        \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \left(3 \cdot \left(x \cdot 3\right) + \color{blue}{3 \cdot \left(\mathsf{neg}\left(4\right)\right)}\right)\right)\right) \]
      11. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\left(3 \cdot \left(x \cdot 3\right)\right), \color{blue}{\left(3 \cdot \left(\mathsf{neg}\left(4\right)\right)\right)}\right)\right)\right) \]
      12. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\left(\left(x \cdot 3\right) \cdot 3\right), \left(\color{blue}{3} \cdot \left(\mathsf{neg}\left(4\right)\right)\right)\right)\right)\right) \]
      13. associate-*l*N/A

        \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\left(x \cdot \left(3 \cdot 3\right)\right), \left(\color{blue}{3} \cdot \left(\mathsf{neg}\left(4\right)\right)\right)\right)\right)\right) \]
      14. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(3 \cdot 3\right)\right), \left(\color{blue}{3} \cdot \left(\mathsf{neg}\left(4\right)\right)\right)\right)\right)\right) \]
      15. metadata-evalN/A

        \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 9\right), \left(3 \cdot \left(\mathsf{neg}\left(4\right)\right)\right)\right)\right)\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 9\right), \left(3 \cdot -4\right)\right)\right)\right) \]
      17. metadata-eval100.0%

        \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 9\right), -12\right)\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{3 + x \cdot \left(x \cdot 9 + -12\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0

      \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \color{blue}{-12}\right)\right) \]
    6. Step-by-step derivation
      1. Simplified99.6%

        \[\leadsto 3 + x \cdot \color{blue}{-12} \]

      if 1 < x

      1. Initial program 99.6%

        \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
      2. Add Preprocessing
      3. Taylor expanded in x around inf

        \[\leadsto \mathsf{*.f64}\left(3, \color{blue}{\left(3 \cdot {x}^{2}\right)}\right) \]
      4. Step-by-step derivation
        1. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(3, \mathsf{*.f64}\left(3, \color{blue}{\left({x}^{2}\right)}\right)\right) \]
        2. unpow2N/A

          \[\leadsto \mathsf{*.f64}\left(3, \mathsf{*.f64}\left(3, \left(x \cdot \color{blue}{x}\right)\right)\right) \]
        3. *-lowering-*.f6498.1%

          \[\leadsto \mathsf{*.f64}\left(3, \mathsf{*.f64}\left(3, \mathsf{*.f64}\left(x, \color{blue}{x}\right)\right)\right) \]
      5. Simplified98.1%

        \[\leadsto 3 \cdot \color{blue}{\left(3 \cdot \left(x \cdot x\right)\right)} \]
      6. Step-by-step derivation
        1. associate-*r*N/A

          \[\leadsto \left(3 \cdot 3\right) \cdot \color{blue}{\left(x \cdot x\right)} \]
        2. metadata-evalN/A

          \[\leadsto 9 \cdot \left(\color{blue}{x} \cdot x\right) \]
        3. *-commutativeN/A

          \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{9} \]
        4. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\left(x \cdot x\right), \color{blue}{9}\right) \]
        5. *-lowering-*.f6498.3%

          \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), 9\right) \]
      7. Applied egg-rr98.3%

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 9} \]
    7. Recombined 3 regimes into one program.
    8. Add Preprocessing

    Alternative 5: 97.5% accurate, 0.9× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.58:\\ \;\;\;\;x \cdot \left(x \cdot 9\right)\\ \mathbf{elif}\;x \leq 0.2:\\ \;\;\;\;3\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot x\right) \cdot 9\\ \end{array} \end{array} \]
    (FPCore (x)
     :precision binary64
     (if (<= x -0.58) (* x (* x 9.0)) (if (<= x 0.2) 3.0 (* (* x x) 9.0))))
    double code(double x) {
    	double tmp;
    	if (x <= -0.58) {
    		tmp = x * (x * 9.0);
    	} else if (x <= 0.2) {
    		tmp = 3.0;
    	} else {
    		tmp = (x * x) * 9.0;
    	}
    	return tmp;
    }
    
    real(8) function code(x)
        real(8), intent (in) :: x
        real(8) :: tmp
        if (x <= (-0.58d0)) then
            tmp = x * (x * 9.0d0)
        else if (x <= 0.2d0) then
            tmp = 3.0d0
        else
            tmp = (x * x) * 9.0d0
        end if
        code = tmp
    end function
    
    public static double code(double x) {
    	double tmp;
    	if (x <= -0.58) {
    		tmp = x * (x * 9.0);
    	} else if (x <= 0.2) {
    		tmp = 3.0;
    	} else {
    		tmp = (x * x) * 9.0;
    	}
    	return tmp;
    }
    
    def code(x):
    	tmp = 0
    	if x <= -0.58:
    		tmp = x * (x * 9.0)
    	elif x <= 0.2:
    		tmp = 3.0
    	else:
    		tmp = (x * x) * 9.0
    	return tmp
    
    function code(x)
    	tmp = 0.0
    	if (x <= -0.58)
    		tmp = Float64(x * Float64(x * 9.0));
    	elseif (x <= 0.2)
    		tmp = 3.0;
    	else
    		tmp = Float64(Float64(x * x) * 9.0);
    	end
    	return tmp
    end
    
    function tmp_2 = code(x)
    	tmp = 0.0;
    	if (x <= -0.58)
    		tmp = x * (x * 9.0);
    	elseif (x <= 0.2)
    		tmp = 3.0;
    	else
    		tmp = (x * x) * 9.0;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_] := If[LessEqual[x, -0.58], N[(x * N[(x * 9.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.2], 3.0, N[(N[(x * x), $MachinePrecision] * 9.0), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;x \leq -0.58:\\
    \;\;\;\;x \cdot \left(x \cdot 9\right)\\
    
    \mathbf{elif}\;x \leq 0.2:\\
    \;\;\;\;3\\
    
    \mathbf{else}:\\
    \;\;\;\;\left(x \cdot x\right) \cdot 9\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if x < -0.57999999999999996

      1. Initial program 99.6%

        \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
      2. Add Preprocessing
      3. Taylor expanded in x around inf

        \[\leadsto \color{blue}{9 \cdot {x}^{2}} \]
      4. Step-by-step derivation
        1. unpow2N/A

          \[\leadsto 9 \cdot \left(x \cdot \color{blue}{x}\right) \]
        2. associate-*r*N/A

          \[\leadsto \left(9 \cdot x\right) \cdot \color{blue}{x} \]
        3. *-commutativeN/A

          \[\leadsto x \cdot \color{blue}{\left(9 \cdot x\right)} \]
        4. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(9 \cdot x\right)}\right) \]
        5. *-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(x, \left(x \cdot \color{blue}{9}\right)\right) \]
        6. *-lowering-*.f6497.0%

          \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{9}\right)\right) \]
      5. Simplified97.0%

        \[\leadsto \color{blue}{x \cdot \left(x \cdot 9\right)} \]

      if -0.57999999999999996 < x < 0.20000000000000001

      1. Initial program 100.0%

        \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

        \[\leadsto \color{blue}{3} \]
      4. Step-by-step derivation
        1. Simplified98.5%

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

        if 0.20000000000000001 < x

        1. Initial program 99.6%

          \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
        2. Add Preprocessing
        3. Taylor expanded in x around inf

          \[\leadsto \mathsf{*.f64}\left(3, \color{blue}{\left(3 \cdot {x}^{2}\right)}\right) \]
        4. Step-by-step derivation
          1. *-lowering-*.f64N/A

            \[\leadsto \mathsf{*.f64}\left(3, \mathsf{*.f64}\left(3, \color{blue}{\left({x}^{2}\right)}\right)\right) \]
          2. unpow2N/A

            \[\leadsto \mathsf{*.f64}\left(3, \mathsf{*.f64}\left(3, \left(x \cdot \color{blue}{x}\right)\right)\right) \]
          3. *-lowering-*.f6498.1%

            \[\leadsto \mathsf{*.f64}\left(3, \mathsf{*.f64}\left(3, \mathsf{*.f64}\left(x, \color{blue}{x}\right)\right)\right) \]
        5. Simplified98.1%

          \[\leadsto 3 \cdot \color{blue}{\left(3 \cdot \left(x \cdot x\right)\right)} \]
        6. Step-by-step derivation
          1. associate-*r*N/A

            \[\leadsto \left(3 \cdot 3\right) \cdot \color{blue}{\left(x \cdot x\right)} \]
          2. metadata-evalN/A

            \[\leadsto 9 \cdot \left(\color{blue}{x} \cdot x\right) \]
          3. *-commutativeN/A

            \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{9} \]
          4. *-lowering-*.f64N/A

            \[\leadsto \mathsf{*.f64}\left(\left(x \cdot x\right), \color{blue}{9}\right) \]
          5. *-lowering-*.f6498.3%

            \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), 9\right) \]
        7. Applied egg-rr98.3%

          \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 9} \]
      5. Recombined 3 regimes into one program.
      6. Add Preprocessing

      Alternative 6: 97.5% accurate, 0.9× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(x \cdot 9\right)\\ \mathbf{if}\;x \leq -0.58:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 0.2:\\ \;\;\;\;3\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
      (FPCore (x)
       :precision binary64
       (let* ((t_0 (* x (* x 9.0)))) (if (<= x -0.58) t_0 (if (<= x 0.2) 3.0 t_0))))
      double code(double x) {
      	double t_0 = x * (x * 9.0);
      	double tmp;
      	if (x <= -0.58) {
      		tmp = t_0;
      	} else if (x <= 0.2) {
      		tmp = 3.0;
      	} else {
      		tmp = t_0;
      	}
      	return tmp;
      }
      
      real(8) function code(x)
          real(8), intent (in) :: x
          real(8) :: t_0
          real(8) :: tmp
          t_0 = x * (x * 9.0d0)
          if (x <= (-0.58d0)) then
              tmp = t_0
          else if (x <= 0.2d0) then
              tmp = 3.0d0
          else
              tmp = t_0
          end if
          code = tmp
      end function
      
      public static double code(double x) {
      	double t_0 = x * (x * 9.0);
      	double tmp;
      	if (x <= -0.58) {
      		tmp = t_0;
      	} else if (x <= 0.2) {
      		tmp = 3.0;
      	} else {
      		tmp = t_0;
      	}
      	return tmp;
      }
      
      def code(x):
      	t_0 = x * (x * 9.0)
      	tmp = 0
      	if x <= -0.58:
      		tmp = t_0
      	elif x <= 0.2:
      		tmp = 3.0
      	else:
      		tmp = t_0
      	return tmp
      
      function code(x)
      	t_0 = Float64(x * Float64(x * 9.0))
      	tmp = 0.0
      	if (x <= -0.58)
      		tmp = t_0;
      	elseif (x <= 0.2)
      		tmp = 3.0;
      	else
      		tmp = t_0;
      	end
      	return tmp
      end
      
      function tmp_2 = code(x)
      	t_0 = x * (x * 9.0);
      	tmp = 0.0;
      	if (x <= -0.58)
      		tmp = t_0;
      	elseif (x <= 0.2)
      		tmp = 3.0;
      	else
      		tmp = t_0;
      	end
      	tmp_2 = tmp;
      end
      
      code[x_] := Block[{t$95$0 = N[(x * N[(x * 9.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.58], t$95$0, If[LessEqual[x, 0.2], 3.0, t$95$0]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := x \cdot \left(x \cdot 9\right)\\
      \mathbf{if}\;x \leq -0.58:\\
      \;\;\;\;t\_0\\
      
      \mathbf{elif}\;x \leq 0.2:\\
      \;\;\;\;3\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_0\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if x < -0.57999999999999996 or 0.20000000000000001 < x

        1. Initial program 99.6%

          \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
        2. Add Preprocessing
        3. Taylor expanded in x around inf

          \[\leadsto \color{blue}{9 \cdot {x}^{2}} \]
        4. Step-by-step derivation
          1. unpow2N/A

            \[\leadsto 9 \cdot \left(x \cdot \color{blue}{x}\right) \]
          2. associate-*r*N/A

            \[\leadsto \left(9 \cdot x\right) \cdot \color{blue}{x} \]
          3. *-commutativeN/A

            \[\leadsto x \cdot \color{blue}{\left(9 \cdot x\right)} \]
          4. *-lowering-*.f64N/A

            \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(9 \cdot x\right)}\right) \]
          5. *-commutativeN/A

            \[\leadsto \mathsf{*.f64}\left(x, \left(x \cdot \color{blue}{9}\right)\right) \]
          6. *-lowering-*.f6497.7%

            \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{9}\right)\right) \]
        5. Simplified97.7%

          \[\leadsto \color{blue}{x \cdot \left(x \cdot 9\right)} \]

        if -0.57999999999999996 < x < 0.20000000000000001

        1. Initial program 100.0%

          \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
        2. Add Preprocessing
        3. Taylor expanded in x around 0

          \[\leadsto \color{blue}{3} \]
        4. Step-by-step derivation
          1. Simplified98.5%

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

        Alternative 7: 99.9% accurate, 1.4× speedup?

        \[\begin{array}{l} \\ 3 + x \cdot \left(-12 + x \cdot 9\right) \end{array} \]
        (FPCore (x) :precision binary64 (+ 3.0 (* x (+ -12.0 (* x 9.0)))))
        double code(double x) {
        	return 3.0 + (x * (-12.0 + (x * 9.0)));
        }
        
        real(8) function code(x)
            real(8), intent (in) :: x
            code = 3.0d0 + (x * ((-12.0d0) + (x * 9.0d0)))
        end function
        
        public static double code(double x) {
        	return 3.0 + (x * (-12.0 + (x * 9.0)));
        }
        
        def code(x):
        	return 3.0 + (x * (-12.0 + (x * 9.0)))
        
        function code(x)
        	return Float64(3.0 + Float64(x * Float64(-12.0 + Float64(x * 9.0))))
        end
        
        function tmp = code(x)
        	tmp = 3.0 + (x * (-12.0 + (x * 9.0)));
        end
        
        code[x_] := N[(3.0 + N[(x * N[(-12.0 + N[(x * 9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        3 + x \cdot \left(-12 + x \cdot 9\right)
        \end{array}
        
        Derivation
        1. Initial program 99.8%

          \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
        2. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \cdot \color{blue}{3} \]
          2. distribute-rgt1-inN/A

            \[\leadsto 3 + \color{blue}{\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) \cdot 3} \]
          3. +-lowering-+.f64N/A

            \[\leadsto \mathsf{+.f64}\left(3, \color{blue}{\left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) \cdot 3\right)}\right) \]
          4. *-commutativeN/A

            \[\leadsto \mathsf{+.f64}\left(3, \left(\left(x \cdot \left(x \cdot 3\right) - x \cdot 4\right) \cdot 3\right)\right) \]
          5. distribute-lft-out--N/A

            \[\leadsto \mathsf{+.f64}\left(3, \left(\left(x \cdot \left(x \cdot 3 - 4\right)\right) \cdot 3\right)\right) \]
          6. associate-*l*N/A

            \[\leadsto \mathsf{+.f64}\left(3, \left(x \cdot \color{blue}{\left(\left(x \cdot 3 - 4\right) \cdot 3\right)}\right)\right) \]
          7. *-lowering-*.f64N/A

            \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \color{blue}{\left(\left(x \cdot 3 - 4\right) \cdot 3\right)}\right)\right) \]
          8. *-commutativeN/A

            \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \left(3 \cdot \color{blue}{\left(x \cdot 3 - 4\right)}\right)\right)\right) \]
          9. sub-negN/A

            \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \left(3 \cdot \left(x \cdot 3 + \color{blue}{\left(\mathsf{neg}\left(4\right)\right)}\right)\right)\right)\right) \]
          10. distribute-lft-inN/A

            \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \left(3 \cdot \left(x \cdot 3\right) + \color{blue}{3 \cdot \left(\mathsf{neg}\left(4\right)\right)}\right)\right)\right) \]
          11. +-lowering-+.f64N/A

            \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\left(3 \cdot \left(x \cdot 3\right)\right), \color{blue}{\left(3 \cdot \left(\mathsf{neg}\left(4\right)\right)\right)}\right)\right)\right) \]
          12. *-commutativeN/A

            \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\left(\left(x \cdot 3\right) \cdot 3\right), \left(\color{blue}{3} \cdot \left(\mathsf{neg}\left(4\right)\right)\right)\right)\right)\right) \]
          13. associate-*l*N/A

            \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\left(x \cdot \left(3 \cdot 3\right)\right), \left(\color{blue}{3} \cdot \left(\mathsf{neg}\left(4\right)\right)\right)\right)\right)\right) \]
          14. *-lowering-*.f64N/A

            \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(3 \cdot 3\right)\right), \left(\color{blue}{3} \cdot \left(\mathsf{neg}\left(4\right)\right)\right)\right)\right)\right) \]
          15. metadata-evalN/A

            \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 9\right), \left(3 \cdot \left(\mathsf{neg}\left(4\right)\right)\right)\right)\right)\right) \]
          16. metadata-evalN/A

            \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 9\right), \left(3 \cdot -4\right)\right)\right)\right) \]
          17. metadata-eval99.9%

            \[\leadsto \mathsf{+.f64}\left(3, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 9\right), -12\right)\right)\right) \]
        3. Simplified99.9%

          \[\leadsto \color{blue}{3 + x \cdot \left(x \cdot 9 + -12\right)} \]
        4. Add Preprocessing
        5. Final simplification99.9%

          \[\leadsto 3 + x \cdot \left(-12 + x \cdot 9\right) \]
        6. Add Preprocessing

        Alternative 8: 51.3% accurate, 13.0× speedup?

        \[\begin{array}{l} \\ 3 \end{array} \]
        (FPCore (x) :precision binary64 3.0)
        double code(double x) {
        	return 3.0;
        }
        
        real(8) function code(x)
            real(8), intent (in) :: x
            code = 3.0d0
        end function
        
        public static double code(double x) {
        	return 3.0;
        }
        
        def code(x):
        	return 3.0
        
        function code(x)
        	return 3.0
        end
        
        function tmp = code(x)
        	tmp = 3.0;
        end
        
        code[x_] := 3.0
        
        \begin{array}{l}
        
        \\
        3
        \end{array}
        
        Derivation
        1. Initial program 99.8%

          \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
        2. Add Preprocessing
        3. Taylor expanded in x around 0

          \[\leadsto \color{blue}{3} \]
        4. Step-by-step derivation
          1. Simplified51.0%

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

          Developer Target 1: 99.8% accurate, 1.2× speedup?

          \[\begin{array}{l} \\ 3 + \left(\left(9 \cdot x\right) \cdot x - 12 \cdot x\right) \end{array} \]
          (FPCore (x) :precision binary64 (+ 3.0 (- (* (* 9.0 x) x) (* 12.0 x))))
          double code(double x) {
          	return 3.0 + (((9.0 * x) * x) - (12.0 * x));
          }
          
          real(8) function code(x)
              real(8), intent (in) :: x
              code = 3.0d0 + (((9.0d0 * x) * x) - (12.0d0 * x))
          end function
          
          public static double code(double x) {
          	return 3.0 + (((9.0 * x) * x) - (12.0 * x));
          }
          
          def code(x):
          	return 3.0 + (((9.0 * x) * x) - (12.0 * x))
          
          function code(x)
          	return Float64(3.0 + Float64(Float64(Float64(9.0 * x) * x) - Float64(12.0 * x)))
          end
          
          function tmp = code(x)
          	tmp = 3.0 + (((9.0 * x) * x) - (12.0 * x));
          end
          
          code[x_] := N[(3.0 + N[(N[(N[(9.0 * x), $MachinePrecision] * x), $MachinePrecision] - N[(12.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
          
          \begin{array}{l}
          
          \\
          3 + \left(\left(9 \cdot x\right) \cdot x - 12 \cdot x\right)
          \end{array}
          

          Reproduce

          ?
          herbie shell --seed 2024141 
          (FPCore (x)
            :name "Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, D"
            :precision binary64
          
            :alt
            (! :herbie-platform default (+ 3 (- (* (* 9 x) x) (* 12 x))))
          
            (* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))