sqrtexp (problem 3.4.4)

Percentage Accurate: 35.6% → 100.0%
Time: 7.4s
Alternatives: 6
Speedup: 3.1×

Specification

?
\[\begin{array}{l} \\ \sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}} \end{array} \]
(FPCore (x)
 :precision binary64
 (sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))
double code(double x) {
	return sqrt(((exp((2.0 * x)) - 1.0) / (exp(x) - 1.0)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sqrt(((exp((2.0d0 * x)) - 1.0d0) / (exp(x) - 1.0d0)))
end function
public static double code(double x) {
	return Math.sqrt(((Math.exp((2.0 * x)) - 1.0) / (Math.exp(x) - 1.0)));
}
def code(x):
	return math.sqrt(((math.exp((2.0 * x)) - 1.0) / (math.exp(x) - 1.0)))
function code(x)
	return sqrt(Float64(Float64(exp(Float64(2.0 * x)) - 1.0) / Float64(exp(x) - 1.0)))
end
function tmp = code(x)
	tmp = sqrt(((exp((2.0 * x)) - 1.0) / (exp(x) - 1.0)));
end
code[x_] := N[Sqrt[N[(N[(N[Exp[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}
\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 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: 35.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}} \end{array} \]
(FPCore (x)
 :precision binary64
 (sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))
double code(double x) {
	return sqrt(((exp((2.0 * x)) - 1.0) / (exp(x) - 1.0)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sqrt(((exp((2.0d0 * x)) - 1.0d0) / (exp(x) - 1.0d0)))
end function
public static double code(double x) {
	return Math.sqrt(((Math.exp((2.0 * x)) - 1.0) / (Math.exp(x) - 1.0)));
}
def code(x):
	return math.sqrt(((math.exp((2.0 * x)) - 1.0) / (math.exp(x) - 1.0)))
function code(x)
	return sqrt(Float64(Float64(exp(Float64(2.0 * x)) - 1.0) / Float64(exp(x) - 1.0)))
end
function tmp = code(x)
	tmp = sqrt(((exp((2.0 * x)) - 1.0) / (exp(x) - 1.0)));
end
code[x_] := N[Sqrt[N[(N[(N[Exp[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}
\end{array}

Alternative 1: 100.0% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \sqrt{1 + e^{x}} \end{array} \]
(FPCore (x) :precision binary64 (sqrt (+ 1.0 (exp x))))
double code(double x) {
	return sqrt((1.0 + exp(x)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sqrt((1.0d0 + exp(x)))
end function
public static double code(double x) {
	return Math.sqrt((1.0 + Math.exp(x)));
}
def code(x):
	return math.sqrt((1.0 + math.exp(x)))
function code(x)
	return sqrt(Float64(1.0 + exp(x)))
end
function tmp = code(x)
	tmp = sqrt((1.0 + exp(x)));
end
code[x_] := N[Sqrt[N[(1.0 + N[Exp[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{1 + e^{x}}
\end{array}
Derivation
  1. Initial program 36.1%

    \[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}} \]
  2. Step-by-step derivation
    1. *-commutative36.1%

      \[\leadsto \sqrt{\frac{e^{\color{blue}{x \cdot 2}} - 1}{e^{x} - 1}} \]
    2. exp-lft-sqr36.9%

      \[\leadsto \sqrt{\frac{\color{blue}{e^{x} \cdot e^{x}} - 1}{e^{x} - 1}} \]
    3. difference-of-sqr-137.9%

      \[\leadsto \sqrt{\frac{\color{blue}{\left(e^{x} + 1\right) \cdot \left(e^{x} - 1\right)}}{e^{x} - 1}} \]
    4. associate-/l*38.3%

      \[\leadsto \sqrt{\color{blue}{\frac{e^{x} + 1}{\frac{e^{x} - 1}{e^{x} - 1}}}} \]
    5. *-inverses100.0%

      \[\leadsto \sqrt{\frac{e^{x} + 1}{\color{blue}{1}}} \]
    6. /-rgt-identity100.0%

      \[\leadsto \sqrt{\color{blue}{e^{x} + 1}} \]
    7. +-commutative100.0%

      \[\leadsto \sqrt{\color{blue}{1 + e^{x}}} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\sqrt{1 + e^{x}}} \]
  4. Add Preprocessing
  5. Final simplification100.0%

    \[\leadsto \sqrt{1 + e^{x}} \]
  6. Add Preprocessing

Alternative 2: 72.8% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4.4:\\ \;\;\;\;\sqrt{2}\\ \mathbf{elif}\;x \leq 1.66:\\ \;\;\;\;{\left(0.5 + x \cdot -0.25\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2} \cdot \left(1 + x \cdot \left(x \cdot 0.09375\right)\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -4.4)
   (sqrt 2.0)
   (if (<= x 1.66)
     (pow (+ 0.5 (* x -0.25)) -0.5)
     (* (sqrt 2.0) (+ 1.0 (* x (* x 0.09375)))))))
double code(double x) {
	double tmp;
	if (x <= -4.4) {
		tmp = sqrt(2.0);
	} else if (x <= 1.66) {
		tmp = pow((0.5 + (x * -0.25)), -0.5);
	} else {
		tmp = sqrt(2.0) * (1.0 + (x * (x * 0.09375)));
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-4.4d0)) then
        tmp = sqrt(2.0d0)
    else if (x <= 1.66d0) then
        tmp = (0.5d0 + (x * (-0.25d0))) ** (-0.5d0)
    else
        tmp = sqrt(2.0d0) * (1.0d0 + (x * (x * 0.09375d0)))
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= -4.4) {
		tmp = Math.sqrt(2.0);
	} else if (x <= 1.66) {
		tmp = Math.pow((0.5 + (x * -0.25)), -0.5);
	} else {
		tmp = Math.sqrt(2.0) * (1.0 + (x * (x * 0.09375)));
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -4.4:
		tmp = math.sqrt(2.0)
	elif x <= 1.66:
		tmp = math.pow((0.5 + (x * -0.25)), -0.5)
	else:
		tmp = math.sqrt(2.0) * (1.0 + (x * (x * 0.09375)))
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -4.4)
		tmp = sqrt(2.0);
	elseif (x <= 1.66)
		tmp = Float64(0.5 + Float64(x * -0.25)) ^ -0.5;
	else
		tmp = Float64(sqrt(2.0) * Float64(1.0 + Float64(x * Float64(x * 0.09375))));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -4.4)
		tmp = sqrt(2.0);
	elseif (x <= 1.66)
		tmp = (0.5 + (x * -0.25)) ^ -0.5;
	else
		tmp = sqrt(2.0) * (1.0 + (x * (x * 0.09375)));
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, -4.4], N[Sqrt[2.0], $MachinePrecision], If[LessEqual[x, 1.66], N[Power[N[(0.5 + N[(x * -0.25), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision], N[(N[Sqrt[2.0], $MachinePrecision] * N[(1.0 + N[(x * N[(x * 0.09375), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.4:\\
\;\;\;\;\sqrt{2}\\

\mathbf{elif}\;x \leq 1.66:\\
\;\;\;\;{\left(0.5 + x \cdot -0.25\right)}^{-0.5}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{2} \cdot \left(1 + x \cdot \left(x \cdot 0.09375\right)\right)\\


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

    1. Initial program 100.0%

      \[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}} \]
    2. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \sqrt{\frac{e^{\color{blue}{x \cdot 2}} - 1}{e^{x} - 1}} \]
      2. exp-lft-sqr100.0%

        \[\leadsto \sqrt{\frac{\color{blue}{e^{x} \cdot e^{x}} - 1}{e^{x} - 1}} \]
      3. difference-of-sqr-1100.0%

        \[\leadsto \sqrt{\frac{\color{blue}{\left(e^{x} + 1\right) \cdot \left(e^{x} - 1\right)}}{e^{x} - 1}} \]
      4. associate-/l*100.0%

        \[\leadsto \sqrt{\color{blue}{\frac{e^{x} + 1}{\frac{e^{x} - 1}{e^{x} - 1}}}} \]
      5. *-inverses100.0%

        \[\leadsto \sqrt{\frac{e^{x} + 1}{\color{blue}{1}}} \]
      6. /-rgt-identity100.0%

        \[\leadsto \sqrt{\color{blue}{e^{x} + 1}} \]
      7. +-commutative100.0%

        \[\leadsto \sqrt{\color{blue}{1 + e^{x}}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\sqrt{1 + e^{x}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 20.7%

      \[\leadsto \sqrt{\color{blue}{2}} \]

    if -4.4000000000000004 < x < 1.65999999999999992

    1. Initial program 5.4%

      \[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}} \]
    2. Step-by-step derivation
      1. *-commutative5.4%

        \[\leadsto \sqrt{\frac{e^{\color{blue}{x \cdot 2}} - 1}{e^{x} - 1}} \]
      2. exp-lft-sqr6.6%

        \[\leadsto \sqrt{\frac{\color{blue}{e^{x} \cdot e^{x}} - 1}{e^{x} - 1}} \]
      3. difference-of-sqr-18.1%

        \[\leadsto \sqrt{\frac{\color{blue}{\left(e^{x} + 1\right) \cdot \left(e^{x} - 1\right)}}{e^{x} - 1}} \]
      4. associate-/l*8.1%

        \[\leadsto \sqrt{\color{blue}{\frac{e^{x} + 1}{\frac{e^{x} - 1}{e^{x} - 1}}}} \]
      5. *-inverses100.0%

        \[\leadsto \sqrt{\frac{e^{x} + 1}{\color{blue}{1}}} \]
      6. /-rgt-identity100.0%

        \[\leadsto \sqrt{\color{blue}{e^{x} + 1}} \]
      7. +-commutative100.0%

        \[\leadsto \sqrt{\color{blue}{1 + e^{x}}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\sqrt{1 + e^{x}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. pow1/2100.0%

        \[\leadsto \color{blue}{{\left(1 + e^{x}\right)}^{0.5}} \]
      2. +-commutative100.0%

        \[\leadsto {\color{blue}{\left(e^{x} + 1\right)}}^{0.5} \]
      3. flip-+6.6%

        \[\leadsto {\color{blue}{\left(\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} - 1}\right)}}^{0.5} \]
      4. metadata-eval6.6%

        \[\leadsto {\left(\frac{e^{x} \cdot e^{x} - \color{blue}{1}}{e^{x} - 1}\right)}^{0.5} \]
      5. exp-lft-sqr5.4%

        \[\leadsto {\left(\frac{\color{blue}{e^{x \cdot 2}} - 1}{e^{x} - 1}\right)}^{0.5} \]
      6. *-commutative5.4%

        \[\leadsto {\left(\frac{e^{\color{blue}{2 \cdot x}} - 1}{e^{x} - 1}\right)}^{0.5} \]
      7. expm1-udef7.8%

        \[\leadsto {\left(\frac{\color{blue}{\mathsf{expm1}\left(2 \cdot x\right)}}{e^{x} - 1}\right)}^{0.5} \]
      8. expm1-udef99.9%

        \[\leadsto {\left(\frac{\mathsf{expm1}\left(2 \cdot x\right)}{\color{blue}{\mathsf{expm1}\left(x\right)}}\right)}^{0.5} \]
      9. div-inv99.6%

        \[\leadsto {\color{blue}{\left(\mathsf{expm1}\left(2 \cdot x\right) \cdot \frac{1}{\mathsf{expm1}\left(x\right)}\right)}}^{0.5} \]
      10. div-inv99.9%

        \[\leadsto {\color{blue}{\left(\frac{\mathsf{expm1}\left(2 \cdot x\right)}{\mathsf{expm1}\left(x\right)}\right)}}^{0.5} \]
      11. clear-num99.9%

        \[\leadsto {\color{blue}{\left(\frac{1}{\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}}\right)}}^{0.5} \]
      12. inv-pow99.9%

        \[\leadsto {\color{blue}{\left({\left(\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}\right)}^{-1}\right)}}^{0.5} \]
      13. metadata-eval99.9%

        \[\leadsto {\left({\left(\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}\right)}^{\color{blue}{\left(-1\right)}}\right)}^{0.5} \]
      14. pow-pow100.0%

        \[\leadsto \color{blue}{{\left(\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}\right)}^{\left(\left(-1\right) \cdot 0.5\right)}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{{\left(\frac{1}{1 + e^{x}}\right)}^{-0.5}} \]
    7. Taylor expanded in x around 0 99.5%

      \[\leadsto {\color{blue}{\left(0.5 + -0.25 \cdot x\right)}}^{-0.5} \]

    if 1.65999999999999992 < x

    1. Initial program 51.9%

      \[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}} \]
    2. Step-by-step derivation
      1. *-commutative51.9%

        \[\leadsto \sqrt{\frac{e^{\color{blue}{x \cdot 2}} - 1}{e^{x} - 1}} \]
      2. exp-lft-sqr51.9%

        \[\leadsto \sqrt{\frac{\color{blue}{e^{x} \cdot e^{x}} - 1}{e^{x} - 1}} \]
      3. difference-of-sqr-151.9%

        \[\leadsto \sqrt{\frac{\color{blue}{\left(e^{x} + 1\right) \cdot \left(e^{x} - 1\right)}}{e^{x} - 1}} \]
      4. associate-/l*100.0%

        \[\leadsto \sqrt{\color{blue}{\frac{e^{x} + 1}{\frac{e^{x} - 1}{e^{x} - 1}}}} \]
      5. *-inverses100.0%

        \[\leadsto \sqrt{\frac{e^{x} + 1}{\color{blue}{1}}} \]
      6. /-rgt-identity100.0%

        \[\leadsto \sqrt{\color{blue}{e^{x} + 1}} \]
      7. +-commutative100.0%

        \[\leadsto \sqrt{\color{blue}{1 + e^{x}}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\sqrt{1 + e^{x}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. pow1/2100.0%

        \[\leadsto \color{blue}{{\left(1 + e^{x}\right)}^{0.5}} \]
      2. +-commutative100.0%

        \[\leadsto {\color{blue}{\left(e^{x} + 1\right)}}^{0.5} \]
      3. flip-+51.9%

        \[\leadsto {\color{blue}{\left(\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} - 1}\right)}}^{0.5} \]
      4. metadata-eval51.9%

        \[\leadsto {\left(\frac{e^{x} \cdot e^{x} - \color{blue}{1}}{e^{x} - 1}\right)}^{0.5} \]
      5. exp-lft-sqr51.9%

        \[\leadsto {\left(\frac{\color{blue}{e^{x \cdot 2}} - 1}{e^{x} - 1}\right)}^{0.5} \]
      6. *-commutative51.9%

        \[\leadsto {\left(\frac{e^{\color{blue}{2 \cdot x}} - 1}{e^{x} - 1}\right)}^{0.5} \]
      7. expm1-udef51.9%

        \[\leadsto {\left(\frac{\color{blue}{\mathsf{expm1}\left(2 \cdot x\right)}}{e^{x} - 1}\right)}^{0.5} \]
      8. expm1-udef51.9%

        \[\leadsto {\left(\frac{\mathsf{expm1}\left(2 \cdot x\right)}{\color{blue}{\mathsf{expm1}\left(x\right)}}\right)}^{0.5} \]
      9. div-inv51.9%

        \[\leadsto {\color{blue}{\left(\mathsf{expm1}\left(2 \cdot x\right) \cdot \frac{1}{\mathsf{expm1}\left(x\right)}\right)}}^{0.5} \]
      10. div-inv51.9%

        \[\leadsto {\color{blue}{\left(\frac{\mathsf{expm1}\left(2 \cdot x\right)}{\mathsf{expm1}\left(x\right)}\right)}}^{0.5} \]
      11. clear-num51.9%

        \[\leadsto {\color{blue}{\left(\frac{1}{\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}}\right)}}^{0.5} \]
      12. inv-pow51.9%

        \[\leadsto {\color{blue}{\left({\left(\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}\right)}^{-1}\right)}}^{0.5} \]
      13. metadata-eval51.9%

        \[\leadsto {\left({\left(\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}\right)}^{\color{blue}{\left(-1\right)}}\right)}^{0.5} \]
      14. pow-pow51.9%

        \[\leadsto \color{blue}{{\left(\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}\right)}^{\left(\left(-1\right) \cdot 0.5\right)}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{{\left(\frac{1}{1 + e^{x}}\right)}^{-0.5}} \]
    7. Taylor expanded in x around 0 0.0%

      \[\leadsto {\color{blue}{\left(0.5 + -0.25 \cdot x\right)}}^{-0.5} \]
    8. Taylor expanded in x around 0 11.9%

      \[\leadsto \color{blue}{\sqrt{2} + \left(0.09375 \cdot \left({x}^{2} \cdot \sqrt{2}\right) + 0.25 \cdot \left(x \cdot \sqrt{2}\right)\right)} \]
    9. Step-by-step derivation
      1. *-rgt-identity11.9%

        \[\leadsto \color{blue}{\sqrt{2} \cdot 1} + \left(0.09375 \cdot \left({x}^{2} \cdot \sqrt{2}\right) + 0.25 \cdot \left(x \cdot \sqrt{2}\right)\right) \]
      2. associate-*r*11.9%

        \[\leadsto \sqrt{2} \cdot 1 + \left(\color{blue}{\left(0.09375 \cdot {x}^{2}\right) \cdot \sqrt{2}} + 0.25 \cdot \left(x \cdot \sqrt{2}\right)\right) \]
      3. associate-*r*11.9%

        \[\leadsto \sqrt{2} \cdot 1 + \left(\left(0.09375 \cdot {x}^{2}\right) \cdot \sqrt{2} + \color{blue}{\left(0.25 \cdot x\right) \cdot \sqrt{2}}\right) \]
      4. *-commutative11.9%

        \[\leadsto \sqrt{2} \cdot 1 + \left(\left(0.09375 \cdot {x}^{2}\right) \cdot \sqrt{2} + \color{blue}{\left(x \cdot 0.25\right)} \cdot \sqrt{2}\right) \]
      5. distribute-rgt-out11.9%

        \[\leadsto \sqrt{2} \cdot 1 + \color{blue}{\sqrt{2} \cdot \left(0.09375 \cdot {x}^{2} + x \cdot 0.25\right)} \]
      6. distribute-lft-out11.9%

        \[\leadsto \color{blue}{\sqrt{2} \cdot \left(1 + \left(0.09375 \cdot {x}^{2} + x \cdot 0.25\right)\right)} \]
      7. +-commutative11.9%

        \[\leadsto \sqrt{2} \cdot \left(1 + \color{blue}{\left(x \cdot 0.25 + 0.09375 \cdot {x}^{2}\right)}\right) \]
      8. *-commutative11.9%

        \[\leadsto \sqrt{2} \cdot \left(1 + \left(\color{blue}{0.25 \cdot x} + 0.09375 \cdot {x}^{2}\right)\right) \]
      9. unpow211.9%

        \[\leadsto \sqrt{2} \cdot \left(1 + \left(0.25 \cdot x + 0.09375 \cdot \color{blue}{\left(x \cdot x\right)}\right)\right) \]
      10. associate-*r*11.9%

        \[\leadsto \sqrt{2} \cdot \left(1 + \left(0.25 \cdot x + \color{blue}{\left(0.09375 \cdot x\right) \cdot x}\right)\right) \]
      11. distribute-rgt-out11.9%

        \[\leadsto \sqrt{2} \cdot \left(1 + \color{blue}{x \cdot \left(0.25 + 0.09375 \cdot x\right)}\right) \]
      12. *-commutative11.9%

        \[\leadsto \sqrt{2} \cdot \left(1 + x \cdot \left(0.25 + \color{blue}{x \cdot 0.09375}\right)\right) \]
    10. Simplified11.9%

      \[\leadsto \color{blue}{\sqrt{2} \cdot \left(1 + x \cdot \left(0.25 + x \cdot 0.09375\right)\right)} \]
    11. Taylor expanded in x around inf 11.7%

      \[\leadsto \sqrt{2} \cdot \left(1 + x \cdot \color{blue}{\left(0.09375 \cdot x\right)}\right) \]
    12. Step-by-step derivation
      1. *-commutative11.7%

        \[\leadsto \sqrt{2} \cdot \left(1 + x \cdot \color{blue}{\left(x \cdot 0.09375\right)}\right) \]
    13. Simplified11.7%

      \[\leadsto \sqrt{2} \cdot \left(1 + x \cdot \color{blue}{\left(x \cdot 0.09375\right)}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification73.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.4:\\ \;\;\;\;\sqrt{2}\\ \mathbf{elif}\;x \leq 1.66:\\ \;\;\;\;{\left(0.5 + x \cdot -0.25\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2} \cdot \left(1 + x \cdot \left(x \cdot 0.09375\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 72.8% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4.4:\\ \;\;\;\;\sqrt{2}\\ \mathbf{elif}\;x \leq 1.46:\\ \;\;\;\;{\left(0.5 + x \cdot -0.25\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2} \cdot \left(1 + x \cdot 0.25\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -4.4)
   (sqrt 2.0)
   (if (<= x 1.46)
     (pow (+ 0.5 (* x -0.25)) -0.5)
     (* (sqrt 2.0) (+ 1.0 (* x 0.25))))))
double code(double x) {
	double tmp;
	if (x <= -4.4) {
		tmp = sqrt(2.0);
	} else if (x <= 1.46) {
		tmp = pow((0.5 + (x * -0.25)), -0.5);
	} else {
		tmp = sqrt(2.0) * (1.0 + (x * 0.25));
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-4.4d0)) then
        tmp = sqrt(2.0d0)
    else if (x <= 1.46d0) then
        tmp = (0.5d0 + (x * (-0.25d0))) ** (-0.5d0)
    else
        tmp = sqrt(2.0d0) * (1.0d0 + (x * 0.25d0))
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= -4.4) {
		tmp = Math.sqrt(2.0);
	} else if (x <= 1.46) {
		tmp = Math.pow((0.5 + (x * -0.25)), -0.5);
	} else {
		tmp = Math.sqrt(2.0) * (1.0 + (x * 0.25));
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -4.4:
		tmp = math.sqrt(2.0)
	elif x <= 1.46:
		tmp = math.pow((0.5 + (x * -0.25)), -0.5)
	else:
		tmp = math.sqrt(2.0) * (1.0 + (x * 0.25))
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -4.4)
		tmp = sqrt(2.0);
	elseif (x <= 1.46)
		tmp = Float64(0.5 + Float64(x * -0.25)) ^ -0.5;
	else
		tmp = Float64(sqrt(2.0) * Float64(1.0 + Float64(x * 0.25)));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -4.4)
		tmp = sqrt(2.0);
	elseif (x <= 1.46)
		tmp = (0.5 + (x * -0.25)) ^ -0.5;
	else
		tmp = sqrt(2.0) * (1.0 + (x * 0.25));
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, -4.4], N[Sqrt[2.0], $MachinePrecision], If[LessEqual[x, 1.46], N[Power[N[(0.5 + N[(x * -0.25), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision], N[(N[Sqrt[2.0], $MachinePrecision] * N[(1.0 + N[(x * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.4:\\
\;\;\;\;\sqrt{2}\\

\mathbf{elif}\;x \leq 1.46:\\
\;\;\;\;{\left(0.5 + x \cdot -0.25\right)}^{-0.5}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{2} \cdot \left(1 + x \cdot 0.25\right)\\


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

    1. Initial program 100.0%

      \[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}} \]
    2. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \sqrt{\frac{e^{\color{blue}{x \cdot 2}} - 1}{e^{x} - 1}} \]
      2. exp-lft-sqr100.0%

        \[\leadsto \sqrt{\frac{\color{blue}{e^{x} \cdot e^{x}} - 1}{e^{x} - 1}} \]
      3. difference-of-sqr-1100.0%

        \[\leadsto \sqrt{\frac{\color{blue}{\left(e^{x} + 1\right) \cdot \left(e^{x} - 1\right)}}{e^{x} - 1}} \]
      4. associate-/l*100.0%

        \[\leadsto \sqrt{\color{blue}{\frac{e^{x} + 1}{\frac{e^{x} - 1}{e^{x} - 1}}}} \]
      5. *-inverses100.0%

        \[\leadsto \sqrt{\frac{e^{x} + 1}{\color{blue}{1}}} \]
      6. /-rgt-identity100.0%

        \[\leadsto \sqrt{\color{blue}{e^{x} + 1}} \]
      7. +-commutative100.0%

        \[\leadsto \sqrt{\color{blue}{1 + e^{x}}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\sqrt{1 + e^{x}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 20.7%

      \[\leadsto \sqrt{\color{blue}{2}} \]

    if -4.4000000000000004 < x < 1.46

    1. Initial program 5.4%

      \[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}} \]
    2. Step-by-step derivation
      1. *-commutative5.4%

        \[\leadsto \sqrt{\frac{e^{\color{blue}{x \cdot 2}} - 1}{e^{x} - 1}} \]
      2. exp-lft-sqr6.6%

        \[\leadsto \sqrt{\frac{\color{blue}{e^{x} \cdot e^{x}} - 1}{e^{x} - 1}} \]
      3. difference-of-sqr-18.1%

        \[\leadsto \sqrt{\frac{\color{blue}{\left(e^{x} + 1\right) \cdot \left(e^{x} - 1\right)}}{e^{x} - 1}} \]
      4. associate-/l*8.1%

        \[\leadsto \sqrt{\color{blue}{\frac{e^{x} + 1}{\frac{e^{x} - 1}{e^{x} - 1}}}} \]
      5. *-inverses100.0%

        \[\leadsto \sqrt{\frac{e^{x} + 1}{\color{blue}{1}}} \]
      6. /-rgt-identity100.0%

        \[\leadsto \sqrt{\color{blue}{e^{x} + 1}} \]
      7. +-commutative100.0%

        \[\leadsto \sqrt{\color{blue}{1 + e^{x}}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\sqrt{1 + e^{x}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. pow1/2100.0%

        \[\leadsto \color{blue}{{\left(1 + e^{x}\right)}^{0.5}} \]
      2. +-commutative100.0%

        \[\leadsto {\color{blue}{\left(e^{x} + 1\right)}}^{0.5} \]
      3. flip-+6.6%

        \[\leadsto {\color{blue}{\left(\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} - 1}\right)}}^{0.5} \]
      4. metadata-eval6.6%

        \[\leadsto {\left(\frac{e^{x} \cdot e^{x} - \color{blue}{1}}{e^{x} - 1}\right)}^{0.5} \]
      5. exp-lft-sqr5.4%

        \[\leadsto {\left(\frac{\color{blue}{e^{x \cdot 2}} - 1}{e^{x} - 1}\right)}^{0.5} \]
      6. *-commutative5.4%

        \[\leadsto {\left(\frac{e^{\color{blue}{2 \cdot x}} - 1}{e^{x} - 1}\right)}^{0.5} \]
      7. expm1-udef7.8%

        \[\leadsto {\left(\frac{\color{blue}{\mathsf{expm1}\left(2 \cdot x\right)}}{e^{x} - 1}\right)}^{0.5} \]
      8. expm1-udef99.9%

        \[\leadsto {\left(\frac{\mathsf{expm1}\left(2 \cdot x\right)}{\color{blue}{\mathsf{expm1}\left(x\right)}}\right)}^{0.5} \]
      9. div-inv99.6%

        \[\leadsto {\color{blue}{\left(\mathsf{expm1}\left(2 \cdot x\right) \cdot \frac{1}{\mathsf{expm1}\left(x\right)}\right)}}^{0.5} \]
      10. div-inv99.9%

        \[\leadsto {\color{blue}{\left(\frac{\mathsf{expm1}\left(2 \cdot x\right)}{\mathsf{expm1}\left(x\right)}\right)}}^{0.5} \]
      11. clear-num99.9%

        \[\leadsto {\color{blue}{\left(\frac{1}{\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}}\right)}}^{0.5} \]
      12. inv-pow99.9%

        \[\leadsto {\color{blue}{\left({\left(\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}\right)}^{-1}\right)}}^{0.5} \]
      13. metadata-eval99.9%

        \[\leadsto {\left({\left(\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}\right)}^{\color{blue}{\left(-1\right)}}\right)}^{0.5} \]
      14. pow-pow100.0%

        \[\leadsto \color{blue}{{\left(\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}\right)}^{\left(\left(-1\right) \cdot 0.5\right)}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{{\left(\frac{1}{1 + e^{x}}\right)}^{-0.5}} \]
    7. Taylor expanded in x around 0 99.5%

      \[\leadsto {\color{blue}{\left(0.5 + -0.25 \cdot x\right)}}^{-0.5} \]

    if 1.46 < x

    1. Initial program 51.9%

      \[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}} \]
    2. Step-by-step derivation
      1. *-commutative51.9%

        \[\leadsto \sqrt{\frac{e^{\color{blue}{x \cdot 2}} - 1}{e^{x} - 1}} \]
      2. exp-lft-sqr51.9%

        \[\leadsto \sqrt{\frac{\color{blue}{e^{x} \cdot e^{x}} - 1}{e^{x} - 1}} \]
      3. difference-of-sqr-151.9%

        \[\leadsto \sqrt{\frac{\color{blue}{\left(e^{x} + 1\right) \cdot \left(e^{x} - 1\right)}}{e^{x} - 1}} \]
      4. associate-/l*100.0%

        \[\leadsto \sqrt{\color{blue}{\frac{e^{x} + 1}{\frac{e^{x} - 1}{e^{x} - 1}}}} \]
      5. *-inverses100.0%

        \[\leadsto \sqrt{\frac{e^{x} + 1}{\color{blue}{1}}} \]
      6. /-rgt-identity100.0%

        \[\leadsto \sqrt{\color{blue}{e^{x} + 1}} \]
      7. +-commutative100.0%

        \[\leadsto \sqrt{\color{blue}{1 + e^{x}}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\sqrt{1 + e^{x}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. pow1/2100.0%

        \[\leadsto \color{blue}{{\left(1 + e^{x}\right)}^{0.5}} \]
      2. +-commutative100.0%

        \[\leadsto {\color{blue}{\left(e^{x} + 1\right)}}^{0.5} \]
      3. flip-+51.9%

        \[\leadsto {\color{blue}{\left(\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} - 1}\right)}}^{0.5} \]
      4. metadata-eval51.9%

        \[\leadsto {\left(\frac{e^{x} \cdot e^{x} - \color{blue}{1}}{e^{x} - 1}\right)}^{0.5} \]
      5. exp-lft-sqr51.9%

        \[\leadsto {\left(\frac{\color{blue}{e^{x \cdot 2}} - 1}{e^{x} - 1}\right)}^{0.5} \]
      6. *-commutative51.9%

        \[\leadsto {\left(\frac{e^{\color{blue}{2 \cdot x}} - 1}{e^{x} - 1}\right)}^{0.5} \]
      7. expm1-udef51.9%

        \[\leadsto {\left(\frac{\color{blue}{\mathsf{expm1}\left(2 \cdot x\right)}}{e^{x} - 1}\right)}^{0.5} \]
      8. expm1-udef51.9%

        \[\leadsto {\left(\frac{\mathsf{expm1}\left(2 \cdot x\right)}{\color{blue}{\mathsf{expm1}\left(x\right)}}\right)}^{0.5} \]
      9. div-inv51.9%

        \[\leadsto {\color{blue}{\left(\mathsf{expm1}\left(2 \cdot x\right) \cdot \frac{1}{\mathsf{expm1}\left(x\right)}\right)}}^{0.5} \]
      10. div-inv51.9%

        \[\leadsto {\color{blue}{\left(\frac{\mathsf{expm1}\left(2 \cdot x\right)}{\mathsf{expm1}\left(x\right)}\right)}}^{0.5} \]
      11. clear-num51.9%

        \[\leadsto {\color{blue}{\left(\frac{1}{\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}}\right)}}^{0.5} \]
      12. inv-pow51.9%

        \[\leadsto {\color{blue}{\left({\left(\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}\right)}^{-1}\right)}}^{0.5} \]
      13. metadata-eval51.9%

        \[\leadsto {\left({\left(\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}\right)}^{\color{blue}{\left(-1\right)}}\right)}^{0.5} \]
      14. pow-pow51.9%

        \[\leadsto \color{blue}{{\left(\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}\right)}^{\left(\left(-1\right) \cdot 0.5\right)}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{{\left(\frac{1}{1 + e^{x}}\right)}^{-0.5}} \]
    7. Taylor expanded in x around 0 11.2%

      \[\leadsto \color{blue}{\sqrt{2} + 0.25 \cdot \left(x \cdot \sqrt{2}\right)} \]
    8. Step-by-step derivation
      1. associate-*r*11.2%

        \[\leadsto \sqrt{2} + \color{blue}{\left(0.25 \cdot x\right) \cdot \sqrt{2}} \]
      2. distribute-rgt1-in11.2%

        \[\leadsto \color{blue}{\left(0.25 \cdot x + 1\right) \cdot \sqrt{2}} \]
      3. *-commutative11.2%

        \[\leadsto \left(\color{blue}{x \cdot 0.25} + 1\right) \cdot \sqrt{2} \]
    9. Simplified11.2%

      \[\leadsto \color{blue}{\left(x \cdot 0.25 + 1\right) \cdot \sqrt{2}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification73.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.4:\\ \;\;\;\;\sqrt{2}\\ \mathbf{elif}\;x \leq 1.46:\\ \;\;\;\;{\left(0.5 + x \cdot -0.25\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2} \cdot \left(1 + x \cdot 0.25\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 72.8% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4.4:\\ \;\;\;\;\sqrt{2}\\ \mathbf{elif}\;x \leq 1.55:\\ \;\;\;\;{\left(0.5 + x \cdot -0.25\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x + 2}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -4.4)
   (sqrt 2.0)
   (if (<= x 1.55) (pow (+ 0.5 (* x -0.25)) -0.5) (sqrt (+ x 2.0)))))
double code(double x) {
	double tmp;
	if (x <= -4.4) {
		tmp = sqrt(2.0);
	} else if (x <= 1.55) {
		tmp = pow((0.5 + (x * -0.25)), -0.5);
	} else {
		tmp = sqrt((x + 2.0));
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-4.4d0)) then
        tmp = sqrt(2.0d0)
    else if (x <= 1.55d0) then
        tmp = (0.5d0 + (x * (-0.25d0))) ** (-0.5d0)
    else
        tmp = sqrt((x + 2.0d0))
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= -4.4) {
		tmp = Math.sqrt(2.0);
	} else if (x <= 1.55) {
		tmp = Math.pow((0.5 + (x * -0.25)), -0.5);
	} else {
		tmp = Math.sqrt((x + 2.0));
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -4.4:
		tmp = math.sqrt(2.0)
	elif x <= 1.55:
		tmp = math.pow((0.5 + (x * -0.25)), -0.5)
	else:
		tmp = math.sqrt((x + 2.0))
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -4.4)
		tmp = sqrt(2.0);
	elseif (x <= 1.55)
		tmp = Float64(0.5 + Float64(x * -0.25)) ^ -0.5;
	else
		tmp = sqrt(Float64(x + 2.0));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -4.4)
		tmp = sqrt(2.0);
	elseif (x <= 1.55)
		tmp = (0.5 + (x * -0.25)) ^ -0.5;
	else
		tmp = sqrt((x + 2.0));
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, -4.4], N[Sqrt[2.0], $MachinePrecision], If[LessEqual[x, 1.55], N[Power[N[(0.5 + N[(x * -0.25), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision], N[Sqrt[N[(x + 2.0), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.4:\\
\;\;\;\;\sqrt{2}\\

\mathbf{elif}\;x \leq 1.55:\\
\;\;\;\;{\left(0.5 + x \cdot -0.25\right)}^{-0.5}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{x + 2}\\


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

    1. Initial program 100.0%

      \[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}} \]
    2. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \sqrt{\frac{e^{\color{blue}{x \cdot 2}} - 1}{e^{x} - 1}} \]
      2. exp-lft-sqr100.0%

        \[\leadsto \sqrt{\frac{\color{blue}{e^{x} \cdot e^{x}} - 1}{e^{x} - 1}} \]
      3. difference-of-sqr-1100.0%

        \[\leadsto \sqrt{\frac{\color{blue}{\left(e^{x} + 1\right) \cdot \left(e^{x} - 1\right)}}{e^{x} - 1}} \]
      4. associate-/l*100.0%

        \[\leadsto \sqrt{\color{blue}{\frac{e^{x} + 1}{\frac{e^{x} - 1}{e^{x} - 1}}}} \]
      5. *-inverses100.0%

        \[\leadsto \sqrt{\frac{e^{x} + 1}{\color{blue}{1}}} \]
      6. /-rgt-identity100.0%

        \[\leadsto \sqrt{\color{blue}{e^{x} + 1}} \]
      7. +-commutative100.0%

        \[\leadsto \sqrt{\color{blue}{1 + e^{x}}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\sqrt{1 + e^{x}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 20.7%

      \[\leadsto \sqrt{\color{blue}{2}} \]

    if -4.4000000000000004 < x < 1.55000000000000004

    1. Initial program 5.4%

      \[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}} \]
    2. Step-by-step derivation
      1. *-commutative5.4%

        \[\leadsto \sqrt{\frac{e^{\color{blue}{x \cdot 2}} - 1}{e^{x} - 1}} \]
      2. exp-lft-sqr6.6%

        \[\leadsto \sqrt{\frac{\color{blue}{e^{x} \cdot e^{x}} - 1}{e^{x} - 1}} \]
      3. difference-of-sqr-18.1%

        \[\leadsto \sqrt{\frac{\color{blue}{\left(e^{x} + 1\right) \cdot \left(e^{x} - 1\right)}}{e^{x} - 1}} \]
      4. associate-/l*8.1%

        \[\leadsto \sqrt{\color{blue}{\frac{e^{x} + 1}{\frac{e^{x} - 1}{e^{x} - 1}}}} \]
      5. *-inverses100.0%

        \[\leadsto \sqrt{\frac{e^{x} + 1}{\color{blue}{1}}} \]
      6. /-rgt-identity100.0%

        \[\leadsto \sqrt{\color{blue}{e^{x} + 1}} \]
      7. +-commutative100.0%

        \[\leadsto \sqrt{\color{blue}{1 + e^{x}}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\sqrt{1 + e^{x}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. pow1/2100.0%

        \[\leadsto \color{blue}{{\left(1 + e^{x}\right)}^{0.5}} \]
      2. +-commutative100.0%

        \[\leadsto {\color{blue}{\left(e^{x} + 1\right)}}^{0.5} \]
      3. flip-+6.6%

        \[\leadsto {\color{blue}{\left(\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} - 1}\right)}}^{0.5} \]
      4. metadata-eval6.6%

        \[\leadsto {\left(\frac{e^{x} \cdot e^{x} - \color{blue}{1}}{e^{x} - 1}\right)}^{0.5} \]
      5. exp-lft-sqr5.4%

        \[\leadsto {\left(\frac{\color{blue}{e^{x \cdot 2}} - 1}{e^{x} - 1}\right)}^{0.5} \]
      6. *-commutative5.4%

        \[\leadsto {\left(\frac{e^{\color{blue}{2 \cdot x}} - 1}{e^{x} - 1}\right)}^{0.5} \]
      7. expm1-udef7.8%

        \[\leadsto {\left(\frac{\color{blue}{\mathsf{expm1}\left(2 \cdot x\right)}}{e^{x} - 1}\right)}^{0.5} \]
      8. expm1-udef99.9%

        \[\leadsto {\left(\frac{\mathsf{expm1}\left(2 \cdot x\right)}{\color{blue}{\mathsf{expm1}\left(x\right)}}\right)}^{0.5} \]
      9. div-inv99.6%

        \[\leadsto {\color{blue}{\left(\mathsf{expm1}\left(2 \cdot x\right) \cdot \frac{1}{\mathsf{expm1}\left(x\right)}\right)}}^{0.5} \]
      10. div-inv99.9%

        \[\leadsto {\color{blue}{\left(\frac{\mathsf{expm1}\left(2 \cdot x\right)}{\mathsf{expm1}\left(x\right)}\right)}}^{0.5} \]
      11. clear-num99.9%

        \[\leadsto {\color{blue}{\left(\frac{1}{\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}}\right)}}^{0.5} \]
      12. inv-pow99.9%

        \[\leadsto {\color{blue}{\left({\left(\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}\right)}^{-1}\right)}}^{0.5} \]
      13. metadata-eval99.9%

        \[\leadsto {\left({\left(\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}\right)}^{\color{blue}{\left(-1\right)}}\right)}^{0.5} \]
      14. pow-pow100.0%

        \[\leadsto \color{blue}{{\left(\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}\right)}^{\left(\left(-1\right) \cdot 0.5\right)}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{{\left(\frac{1}{1 + e^{x}}\right)}^{-0.5}} \]
    7. Taylor expanded in x around 0 99.5%

      \[\leadsto {\color{blue}{\left(0.5 + -0.25 \cdot x\right)}}^{-0.5} \]

    if 1.55000000000000004 < x

    1. Initial program 51.9%

      \[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}} \]
    2. Step-by-step derivation
      1. *-commutative51.9%

        \[\leadsto \sqrt{\frac{e^{\color{blue}{x \cdot 2}} - 1}{e^{x} - 1}} \]
      2. exp-lft-sqr51.9%

        \[\leadsto \sqrt{\frac{\color{blue}{e^{x} \cdot e^{x}} - 1}{e^{x} - 1}} \]
      3. difference-of-sqr-151.9%

        \[\leadsto \sqrt{\frac{\color{blue}{\left(e^{x} + 1\right) \cdot \left(e^{x} - 1\right)}}{e^{x} - 1}} \]
      4. associate-/l*100.0%

        \[\leadsto \sqrt{\color{blue}{\frac{e^{x} + 1}{\frac{e^{x} - 1}{e^{x} - 1}}}} \]
      5. *-inverses100.0%

        \[\leadsto \sqrt{\frac{e^{x} + 1}{\color{blue}{1}}} \]
      6. /-rgt-identity100.0%

        \[\leadsto \sqrt{\color{blue}{e^{x} + 1}} \]
      7. +-commutative100.0%

        \[\leadsto \sqrt{\color{blue}{1 + e^{x}}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\sqrt{1 + e^{x}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 11.0%

      \[\leadsto \sqrt{\color{blue}{2 + x}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification73.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.4:\\ \;\;\;\;\sqrt{2}\\ \mathbf{elif}\;x \leq 1.55:\\ \;\;\;\;{\left(0.5 + x \cdot -0.25\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x + 2}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 72.8% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.7:\\ \;\;\;\;\sqrt{2}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2} \cdot \left(1 + x \cdot \left(0.25 + x \cdot 0.09375\right)\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -2.7)
   (sqrt 2.0)
   (* (sqrt 2.0) (+ 1.0 (* x (+ 0.25 (* x 0.09375)))))))
double code(double x) {
	double tmp;
	if (x <= -2.7) {
		tmp = sqrt(2.0);
	} else {
		tmp = sqrt(2.0) * (1.0 + (x * (0.25 + (x * 0.09375))));
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-2.7d0)) then
        tmp = sqrt(2.0d0)
    else
        tmp = sqrt(2.0d0) * (1.0d0 + (x * (0.25d0 + (x * 0.09375d0))))
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= -2.7) {
		tmp = Math.sqrt(2.0);
	} else {
		tmp = Math.sqrt(2.0) * (1.0 + (x * (0.25 + (x * 0.09375))));
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -2.7:
		tmp = math.sqrt(2.0)
	else:
		tmp = math.sqrt(2.0) * (1.0 + (x * (0.25 + (x * 0.09375))))
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -2.7)
		tmp = sqrt(2.0);
	else
		tmp = Float64(sqrt(2.0) * Float64(1.0 + Float64(x * Float64(0.25 + Float64(x * 0.09375)))));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -2.7)
		tmp = sqrt(2.0);
	else
		tmp = sqrt(2.0) * (1.0 + (x * (0.25 + (x * 0.09375))));
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, -2.7], N[Sqrt[2.0], $MachinePrecision], N[(N[Sqrt[2.0], $MachinePrecision] * N[(1.0 + N[(x * N[(0.25 + N[(x * 0.09375), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7:\\
\;\;\;\;\sqrt{2}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{2} \cdot \left(1 + x \cdot \left(0.25 + x \cdot 0.09375\right)\right)\\


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

    1. Initial program 100.0%

      \[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}} \]
    2. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \sqrt{\frac{e^{\color{blue}{x \cdot 2}} - 1}{e^{x} - 1}} \]
      2. exp-lft-sqr100.0%

        \[\leadsto \sqrt{\frac{\color{blue}{e^{x} \cdot e^{x}} - 1}{e^{x} - 1}} \]
      3. difference-of-sqr-1100.0%

        \[\leadsto \sqrt{\frac{\color{blue}{\left(e^{x} + 1\right) \cdot \left(e^{x} - 1\right)}}{e^{x} - 1}} \]
      4. associate-/l*100.0%

        \[\leadsto \sqrt{\color{blue}{\frac{e^{x} + 1}{\frac{e^{x} - 1}{e^{x} - 1}}}} \]
      5. *-inverses100.0%

        \[\leadsto \sqrt{\frac{e^{x} + 1}{\color{blue}{1}}} \]
      6. /-rgt-identity100.0%

        \[\leadsto \sqrt{\color{blue}{e^{x} + 1}} \]
      7. +-commutative100.0%

        \[\leadsto \sqrt{\color{blue}{1 + e^{x}}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\sqrt{1 + e^{x}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 20.7%

      \[\leadsto \sqrt{\color{blue}{2}} \]

    if -2.7000000000000002 < x

    1. Initial program 6.0%

      \[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}} \]
    2. Step-by-step derivation
      1. *-commutative6.0%

        \[\leadsto \sqrt{\frac{e^{\color{blue}{x \cdot 2}} - 1}{e^{x} - 1}} \]
      2. exp-lft-sqr7.2%

        \[\leadsto \sqrt{\frac{\color{blue}{e^{x} \cdot e^{x}} - 1}{e^{x} - 1}} \]
      3. difference-of-sqr-18.6%

        \[\leadsto \sqrt{\frac{\color{blue}{\left(e^{x} + 1\right) \cdot \left(e^{x} - 1\right)}}{e^{x} - 1}} \]
      4. associate-/l*9.2%

        \[\leadsto \sqrt{\color{blue}{\frac{e^{x} + 1}{\frac{e^{x} - 1}{e^{x} - 1}}}} \]
      5. *-inverses100.0%

        \[\leadsto \sqrt{\frac{e^{x} + 1}{\color{blue}{1}}} \]
      6. /-rgt-identity100.0%

        \[\leadsto \sqrt{\color{blue}{e^{x} + 1}} \]
      7. +-commutative100.0%

        \[\leadsto \sqrt{\color{blue}{1 + e^{x}}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\sqrt{1 + e^{x}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. pow1/2100.0%

        \[\leadsto \color{blue}{{\left(1 + e^{x}\right)}^{0.5}} \]
      2. +-commutative100.0%

        \[\leadsto {\color{blue}{\left(e^{x} + 1\right)}}^{0.5} \]
      3. flip-+7.2%

        \[\leadsto {\color{blue}{\left(\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} - 1}\right)}}^{0.5} \]
      4. metadata-eval7.2%

        \[\leadsto {\left(\frac{e^{x} \cdot e^{x} - \color{blue}{1}}{e^{x} - 1}\right)}^{0.5} \]
      5. exp-lft-sqr6.0%

        \[\leadsto {\left(\frac{\color{blue}{e^{x \cdot 2}} - 1}{e^{x} - 1}\right)}^{0.5} \]
      6. *-commutative6.0%

        \[\leadsto {\left(\frac{e^{\color{blue}{2 \cdot x}} - 1}{e^{x} - 1}\right)}^{0.5} \]
      7. expm1-udef8.3%

        \[\leadsto {\left(\frac{\color{blue}{\mathsf{expm1}\left(2 \cdot x\right)}}{e^{x} - 1}\right)}^{0.5} \]
      8. expm1-udef99.4%

        \[\leadsto {\left(\frac{\mathsf{expm1}\left(2 \cdot x\right)}{\color{blue}{\mathsf{expm1}\left(x\right)}}\right)}^{0.5} \]
      9. div-inv99.1%

        \[\leadsto {\color{blue}{\left(\mathsf{expm1}\left(2 \cdot x\right) \cdot \frac{1}{\mathsf{expm1}\left(x\right)}\right)}}^{0.5} \]
      10. div-inv99.4%

        \[\leadsto {\color{blue}{\left(\frac{\mathsf{expm1}\left(2 \cdot x\right)}{\mathsf{expm1}\left(x\right)}\right)}}^{0.5} \]
      11. clear-num99.4%

        \[\leadsto {\color{blue}{\left(\frac{1}{\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}}\right)}}^{0.5} \]
      12. inv-pow99.4%

        \[\leadsto {\color{blue}{\left({\left(\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}\right)}^{-1}\right)}}^{0.5} \]
      13. metadata-eval99.4%

        \[\leadsto {\left({\left(\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}\right)}^{\color{blue}{\left(-1\right)}}\right)}^{0.5} \]
      14. pow-pow99.4%

        \[\leadsto \color{blue}{{\left(\frac{\mathsf{expm1}\left(x\right)}{\mathsf{expm1}\left(2 \cdot x\right)}\right)}^{\left(\left(-1\right) \cdot 0.5\right)}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{{\left(\frac{1}{1 + e^{x}}\right)}^{-0.5}} \]
    7. Taylor expanded in x around 0 98.4%

      \[\leadsto {\color{blue}{\left(0.5 + -0.25 \cdot x\right)}}^{-0.5} \]
    8. Taylor expanded in x around 0 98.5%

      \[\leadsto \color{blue}{\sqrt{2} + \left(0.09375 \cdot \left({x}^{2} \cdot \sqrt{2}\right) + 0.25 \cdot \left(x \cdot \sqrt{2}\right)\right)} \]
    9. Step-by-step derivation
      1. *-rgt-identity98.5%

        \[\leadsto \color{blue}{\sqrt{2} \cdot 1} + \left(0.09375 \cdot \left({x}^{2} \cdot \sqrt{2}\right) + 0.25 \cdot \left(x \cdot \sqrt{2}\right)\right) \]
      2. associate-*r*98.5%

        \[\leadsto \sqrt{2} \cdot 1 + \left(\color{blue}{\left(0.09375 \cdot {x}^{2}\right) \cdot \sqrt{2}} + 0.25 \cdot \left(x \cdot \sqrt{2}\right)\right) \]
      3. associate-*r*98.5%

        \[\leadsto \sqrt{2} \cdot 1 + \left(\left(0.09375 \cdot {x}^{2}\right) \cdot \sqrt{2} + \color{blue}{\left(0.25 \cdot x\right) \cdot \sqrt{2}}\right) \]
      4. *-commutative98.5%

        \[\leadsto \sqrt{2} \cdot 1 + \left(\left(0.09375 \cdot {x}^{2}\right) \cdot \sqrt{2} + \color{blue}{\left(x \cdot 0.25\right)} \cdot \sqrt{2}\right) \]
      5. distribute-rgt-out98.5%

        \[\leadsto \sqrt{2} \cdot 1 + \color{blue}{\sqrt{2} \cdot \left(0.09375 \cdot {x}^{2} + x \cdot 0.25\right)} \]
      6. distribute-lft-out98.5%

        \[\leadsto \color{blue}{\sqrt{2} \cdot \left(1 + \left(0.09375 \cdot {x}^{2} + x \cdot 0.25\right)\right)} \]
      7. +-commutative98.5%

        \[\leadsto \sqrt{2} \cdot \left(1 + \color{blue}{\left(x \cdot 0.25 + 0.09375 \cdot {x}^{2}\right)}\right) \]
      8. *-commutative98.5%

        \[\leadsto \sqrt{2} \cdot \left(1 + \left(\color{blue}{0.25 \cdot x} + 0.09375 \cdot {x}^{2}\right)\right) \]
      9. unpow298.5%

        \[\leadsto \sqrt{2} \cdot \left(1 + \left(0.25 \cdot x + 0.09375 \cdot \color{blue}{\left(x \cdot x\right)}\right)\right) \]
      10. associate-*r*98.5%

        \[\leadsto \sqrt{2} \cdot \left(1 + \left(0.25 \cdot x + \color{blue}{\left(0.09375 \cdot x\right) \cdot x}\right)\right) \]
      11. distribute-rgt-out98.5%

        \[\leadsto \sqrt{2} \cdot \left(1 + \color{blue}{x \cdot \left(0.25 + 0.09375 \cdot x\right)}\right) \]
      12. *-commutative98.5%

        \[\leadsto \sqrt{2} \cdot \left(1 + x \cdot \left(0.25 + \color{blue}{x \cdot 0.09375}\right)\right) \]
    10. Simplified98.5%

      \[\leadsto \color{blue}{\sqrt{2} \cdot \left(1 + x \cdot \left(0.25 + x \cdot 0.09375\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification73.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.7:\\ \;\;\;\;\sqrt{2}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2} \cdot \left(1 + x \cdot \left(0.25 + x \cdot 0.09375\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 71.9% accurate, 3.1× speedup?

\[\begin{array}{l} \\ \sqrt{2} \end{array} \]
(FPCore (x) :precision binary64 (sqrt 2.0))
double code(double x) {
	return sqrt(2.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sqrt(2.0d0)
end function
public static double code(double x) {
	return Math.sqrt(2.0);
}
def code(x):
	return math.sqrt(2.0)
function code(x)
	return sqrt(2.0)
end
function tmp = code(x)
	tmp = sqrt(2.0);
end
code[x_] := N[Sqrt[2.0], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{2}
\end{array}
Derivation
  1. Initial program 36.1%

    \[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}} \]
  2. Step-by-step derivation
    1. *-commutative36.1%

      \[\leadsto \sqrt{\frac{e^{\color{blue}{x \cdot 2}} - 1}{e^{x} - 1}} \]
    2. exp-lft-sqr36.9%

      \[\leadsto \sqrt{\frac{\color{blue}{e^{x} \cdot e^{x}} - 1}{e^{x} - 1}} \]
    3. difference-of-sqr-137.9%

      \[\leadsto \sqrt{\frac{\color{blue}{\left(e^{x} + 1\right) \cdot \left(e^{x} - 1\right)}}{e^{x} - 1}} \]
    4. associate-/l*38.3%

      \[\leadsto \sqrt{\color{blue}{\frac{e^{x} + 1}{\frac{e^{x} - 1}{e^{x} - 1}}}} \]
    5. *-inverses100.0%

      \[\leadsto \sqrt{\frac{e^{x} + 1}{\color{blue}{1}}} \]
    6. /-rgt-identity100.0%

      \[\leadsto \sqrt{\color{blue}{e^{x} + 1}} \]
    7. +-commutative100.0%

      \[\leadsto \sqrt{\color{blue}{1 + e^{x}}} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\sqrt{1 + e^{x}}} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 72.0%

    \[\leadsto \sqrt{\color{blue}{2}} \]
  6. Final simplification72.0%

    \[\leadsto \sqrt{2} \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2024018 
(FPCore (x)
  :name "sqrtexp (problem 3.4.4)"
  :precision binary64
  (sqrt (/ (- (exp (* 2.0 x)) 1.0) (- (exp x) 1.0))))