Hyperbolic arcsine

?

Percentage Accurate: 18.0% → 99.8%
Time: 11.1s
Precision: binary64
Cost: 20488

?

\[\log \left(x + \sqrt{x \cdot x + 1}\right) \]
\[\begin{array}{l} \mathbf{if}\;x \leq -1.05:\\ \;\;\;\;-\log \left(x \cdot -2 - \frac{0.5}{x}\right)\\ \mathbf{elif}\;x \leq 0.023:\\ \;\;\;\;-0.16666666666666666 \cdot {x}^{3} + \left(0.075 \cdot {x}^{5} + \left(x + -0.044642857142857144 \cdot {x}^{7}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \mathsf{hypot}\left(1, x\right)\right)\\ \end{array} \]
(FPCore (x) :precision binary64 (log (+ x (sqrt (+ (* x x) 1.0)))))
(FPCore (x)
 :precision binary64
 (if (<= x -1.05)
   (- (log (- (* x -2.0) (/ 0.5 x))))
   (if (<= x 0.023)
     (+
      (* -0.16666666666666666 (pow x 3.0))
      (+ (* 0.075 (pow x 5.0)) (+ x (* -0.044642857142857144 (pow x 7.0)))))
     (log (+ x (hypot 1.0 x))))))
double code(double x) {
	return log((x + sqrt(((x * x) + 1.0))));
}
double code(double x) {
	double tmp;
	if (x <= -1.05) {
		tmp = -log(((x * -2.0) - (0.5 / x)));
	} else if (x <= 0.023) {
		tmp = (-0.16666666666666666 * pow(x, 3.0)) + ((0.075 * pow(x, 5.0)) + (x + (-0.044642857142857144 * pow(x, 7.0))));
	} else {
		tmp = log((x + hypot(1.0, x)));
	}
	return tmp;
}
public static double code(double x) {
	return Math.log((x + Math.sqrt(((x * x) + 1.0))));
}
public static double code(double x) {
	double tmp;
	if (x <= -1.05) {
		tmp = -Math.log(((x * -2.0) - (0.5 / x)));
	} else if (x <= 0.023) {
		tmp = (-0.16666666666666666 * Math.pow(x, 3.0)) + ((0.075 * Math.pow(x, 5.0)) + (x + (-0.044642857142857144 * Math.pow(x, 7.0))));
	} else {
		tmp = Math.log((x + Math.hypot(1.0, x)));
	}
	return tmp;
}
def code(x):
	return math.log((x + math.sqrt(((x * x) + 1.0))))
def code(x):
	tmp = 0
	if x <= -1.05:
		tmp = -math.log(((x * -2.0) - (0.5 / x)))
	elif x <= 0.023:
		tmp = (-0.16666666666666666 * math.pow(x, 3.0)) + ((0.075 * math.pow(x, 5.0)) + (x + (-0.044642857142857144 * math.pow(x, 7.0))))
	else:
		tmp = math.log((x + math.hypot(1.0, x)))
	return tmp
function code(x)
	return log(Float64(x + sqrt(Float64(Float64(x * x) + 1.0))))
end
function code(x)
	tmp = 0.0
	if (x <= -1.05)
		tmp = Float64(-log(Float64(Float64(x * -2.0) - Float64(0.5 / x))));
	elseif (x <= 0.023)
		tmp = Float64(Float64(-0.16666666666666666 * (x ^ 3.0)) + Float64(Float64(0.075 * (x ^ 5.0)) + Float64(x + Float64(-0.044642857142857144 * (x ^ 7.0)))));
	else
		tmp = log(Float64(x + hypot(1.0, x)));
	end
	return tmp
end
function tmp = code(x)
	tmp = log((x + sqrt(((x * x) + 1.0))));
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -1.05)
		tmp = -log(((x * -2.0) - (0.5 / x)));
	elseif (x <= 0.023)
		tmp = (-0.16666666666666666 * (x ^ 3.0)) + ((0.075 * (x ^ 5.0)) + (x + (-0.044642857142857144 * (x ^ 7.0))));
	else
		tmp = log((x + hypot(1.0, x)));
	end
	tmp_2 = tmp;
end
code[x_] := N[Log[N[(x + N[Sqrt[N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_] := If[LessEqual[x, -1.05], (-N[Log[N[(N[(x * -2.0), $MachinePrecision] - N[(0.5 / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), If[LessEqual[x, 0.023], N[(N[(-0.16666666666666666 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.075 * N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] + N[(x + N[(-0.044642857142857144 * N[Power[x, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[N[(x + N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\log \left(x + \sqrt{x \cdot x + 1}\right)
\begin{array}{l}
\mathbf{if}\;x \leq -1.05:\\
\;\;\;\;-\log \left(x \cdot -2 - \frac{0.5}{x}\right)\\

\mathbf{elif}\;x \leq 0.023:\\
\;\;\;\;-0.16666666666666666 \cdot {x}^{3} + \left(0.075 \cdot {x}^{5} + \left(x + -0.044642857142857144 \cdot {x}^{7}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\log \left(x + \mathsf{hypot}\left(1, x\right)\right)\\


\end{array}

Local Percentage Accuracy?

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.

Herbie found 11 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each of Herbie's proposed alternatives. Up and to the right is better. Each dot represents an alternative program; the red square represents the initial program.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original18.0%
Target30.4%
Herbie99.8%
\[\begin{array}{l} \mathbf{if}\;x < 0:\\ \;\;\;\;\log \left(\frac{-1}{x - \sqrt{x \cdot x + 1}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \sqrt{x \cdot x + 1}\right)\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if x < -1.05000000000000004

    1. Initial program 2.6%

      \[\log \left(x + \sqrt{x \cdot x + 1}\right) \]
    2. Simplified4.0%

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)} \]
      Step-by-step derivation

      [Start]2.6

      \[ \log \left(x + \sqrt{x \cdot x + 1}\right) \]

      +-commutative [=>]2.6

      \[ \log \left(x + \sqrt{\color{blue}{1 + x \cdot x}}\right) \]

      hypot-1-def [=>]4.0

      \[ \log \left(x + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right) \]
    3. Applied egg-rr2.2%

      \[\leadsto \log \color{blue}{\left(\frac{x \cdot x}{x - \mathsf{hypot}\left(1, x\right)} - \frac{1 + x \cdot x}{x - \mathsf{hypot}\left(1, x\right)}\right)} \]
      Step-by-step derivation

      [Start]4.0

      \[ \log \left(x + \mathsf{hypot}\left(1, x\right)\right) \]

      flip-+ [=>]2.9

      \[ \log \color{blue}{\left(\frac{x \cdot x - \mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)}{x - \mathsf{hypot}\left(1, x\right)}\right)} \]

      div-sub [=>]2.2

      \[ \log \color{blue}{\left(\frac{x \cdot x}{x - \mathsf{hypot}\left(1, x\right)} - \frac{\mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)}{x - \mathsf{hypot}\left(1, x\right)}\right)} \]

      hypot-udef [=>]2.2

      \[ \log \left(\frac{x \cdot x}{x - \mathsf{hypot}\left(1, x\right)} - \frac{\color{blue}{\sqrt{1 \cdot 1 + x \cdot x}} \cdot \mathsf{hypot}\left(1, x\right)}{x - \mathsf{hypot}\left(1, x\right)}\right) \]

      hypot-udef [=>]2.2

      \[ \log \left(\frac{x \cdot x}{x - \mathsf{hypot}\left(1, x\right)} - \frac{\sqrt{1 \cdot 1 + x \cdot x} \cdot \color{blue}{\sqrt{1 \cdot 1 + x \cdot x}}}{x - \mathsf{hypot}\left(1, x\right)}\right) \]

      add-sqr-sqrt [<=]2.2

      \[ \log \left(\frac{x \cdot x}{x - \mathsf{hypot}\left(1, x\right)} - \frac{\color{blue}{1 \cdot 1 + x \cdot x}}{x - \mathsf{hypot}\left(1, x\right)}\right) \]

      metadata-eval [=>]2.2

      \[ \log \left(\frac{x \cdot x}{x - \mathsf{hypot}\left(1, x\right)} - \frac{\color{blue}{1} + x \cdot x}{x - \mathsf{hypot}\left(1, x\right)}\right) \]
    4. Simplified100.0%

      \[\leadsto \log \color{blue}{\left(\frac{-1}{x - \mathsf{hypot}\left(1, x\right)}\right)} \]
      Step-by-step derivation

      [Start]2.2

      \[ \log \left(\frac{x \cdot x}{x - \mathsf{hypot}\left(1, x\right)} - \frac{1 + x \cdot x}{x - \mathsf{hypot}\left(1, x\right)}\right) \]

      div-sub [<=]2.9

      \[ \log \color{blue}{\left(\frac{x \cdot x - \left(1 + x \cdot x\right)}{x - \mathsf{hypot}\left(1, x\right)}\right)} \]

      +-commutative [=>]2.9

      \[ \log \left(\frac{x \cdot x - \color{blue}{\left(x \cdot x + 1\right)}}{x - \mathsf{hypot}\left(1, x\right)}\right) \]

      associate--r+ [=>]44.4

      \[ \log \left(\frac{\color{blue}{\left(x \cdot x - x \cdot x\right) - 1}}{x - \mathsf{hypot}\left(1, x\right)}\right) \]

      +-inverses [=>]100.0

      \[ \log \left(\frac{\color{blue}{0} - 1}{x - \mathsf{hypot}\left(1, x\right)}\right) \]

      metadata-eval [=>]100.0

      \[ \log \left(\frac{\color{blue}{-1}}{x - \mathsf{hypot}\left(1, x\right)}\right) \]
    5. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\log \left(\frac{-1}{x - \mathsf{hypot}\left(1, x\right)}\right) + 0} \]
      Step-by-step derivation

      [Start]100.0

      \[ \log \left(\frac{-1}{x - \mathsf{hypot}\left(1, x\right)}\right) \]

      *-un-lft-identity [=>]100.0

      \[ \log \color{blue}{\left(1 \cdot \frac{-1}{x - \mathsf{hypot}\left(1, x\right)}\right)} \]

      *-commutative [=>]100.0

      \[ \log \color{blue}{\left(\frac{-1}{x - \mathsf{hypot}\left(1, x\right)} \cdot 1\right)} \]

      log-prod [=>]100.0

      \[ \color{blue}{\log \left(\frac{-1}{x - \mathsf{hypot}\left(1, x\right)}\right) + \log 1} \]

      metadata-eval [=>]100.0

      \[ \log \left(\frac{-1}{x - \mathsf{hypot}\left(1, x\right)}\right) + \color{blue}{0} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{-\log \left(\mathsf{hypot}\left(1, x\right) - x\right)} \]
      Step-by-step derivation

      [Start]100.0

      \[ \log \left(\frac{-1}{x - \mathsf{hypot}\left(1, x\right)}\right) + 0 \]

      +-rgt-identity [=>]100.0

      \[ \color{blue}{\log \left(\frac{-1}{x - \mathsf{hypot}\left(1, x\right)}\right)} \]

      metadata-eval [<=]100.0

      \[ \log \left(\frac{\color{blue}{\frac{1}{-1}}}{x - \mathsf{hypot}\left(1, x\right)}\right) \]

      associate-/r* [<=]100.0

      \[ \log \color{blue}{\left(\frac{1}{-1 \cdot \left(x - \mathsf{hypot}\left(1, x\right)\right)}\right)} \]

      neg-mul-1 [<=]100.0

      \[ \log \left(\frac{1}{\color{blue}{-\left(x - \mathsf{hypot}\left(1, x\right)\right)}}\right) \]

      log-rec [=>]100.0

      \[ \color{blue}{-\log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right)} \]

      neg-sub0 [=>]100.0

      \[ -\log \color{blue}{\left(0 - \left(x - \mathsf{hypot}\left(1, x\right)\right)\right)} \]

      sub-neg [=>]100.0

      \[ -\log \left(0 - \color{blue}{\left(x + \left(-\mathsf{hypot}\left(1, x\right)\right)\right)}\right) \]

      +-commutative [<=]100.0

      \[ -\log \left(0 - \color{blue}{\left(\left(-\mathsf{hypot}\left(1, x\right)\right) + x\right)}\right) \]

      associate--r+ [=>]100.0

      \[ -\log \color{blue}{\left(\left(0 - \left(-\mathsf{hypot}\left(1, x\right)\right)\right) - x\right)} \]

      neg-sub0 [<=]100.0

      \[ -\log \left(\color{blue}{\left(-\left(-\mathsf{hypot}\left(1, x\right)\right)\right)} - x\right) \]

      remove-double-neg [=>]100.0

      \[ -\log \left(\color{blue}{\mathsf{hypot}\left(1, x\right)} - x\right) \]
    7. Taylor expanded in x around -inf 100.0%

      \[\leadsto -\log \color{blue}{\left(-2 \cdot x - 0.5 \cdot \frac{1}{x}\right)} \]
    8. Simplified100.0%

      \[\leadsto -\log \color{blue}{\left(x \cdot -2 - \frac{0.5}{x}\right)} \]
      Step-by-step derivation

      [Start]100.0

      \[ -\log \left(-2 \cdot x - 0.5 \cdot \frac{1}{x}\right) \]

      *-commutative [=>]100.0

      \[ -\log \left(\color{blue}{x \cdot -2} - 0.5 \cdot \frac{1}{x}\right) \]

      associate-*r/ [=>]100.0

      \[ -\log \left(x \cdot -2 - \color{blue}{\frac{0.5 \cdot 1}{x}}\right) \]

      metadata-eval [=>]100.0

      \[ -\log \left(x \cdot -2 - \frac{\color{blue}{0.5}}{x}\right) \]

    if -1.05000000000000004 < x < 0.023

    1. Initial program 8.5%

      \[\log \left(x + \sqrt{x \cdot x + 1}\right) \]
    2. Simplified8.5%

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)} \]
      Step-by-step derivation

      [Start]8.5

      \[ \log \left(x + \sqrt{x \cdot x + 1}\right) \]

      +-commutative [=>]8.5

      \[ \log \left(x + \sqrt{\color{blue}{1 + x \cdot x}}\right) \]

      hypot-1-def [=>]8.5

      \[ \log \left(x + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right) \]
    3. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot {x}^{3} + \left(0.075 \cdot {x}^{5} + \left(-0.044642857142857144 \cdot {x}^{7} + x\right)\right)} \]

    if 0.023 < x

    1. Initial program 52.4%

      \[\log \left(x + \sqrt{x \cdot x + 1}\right) \]
    2. Simplified100.0%

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)} \]
      Step-by-step derivation

      [Start]52.4

      \[ \log \left(x + \sqrt{x \cdot x + 1}\right) \]

      +-commutative [=>]52.4

      \[ \log \left(x + \sqrt{\color{blue}{1 + x \cdot x}}\right) \]

      hypot-1-def [=>]100.0

      \[ \log \left(x + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification100.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.05:\\ \;\;\;\;-\log \left(x \cdot -2 - \frac{0.5}{x}\right)\\ \mathbf{elif}\;x \leq 0.023:\\ \;\;\;\;-0.16666666666666666 \cdot {x}^{3} + \left(0.075 \cdot {x}^{5} + \left(x + -0.044642857142857144 \cdot {x}^{7}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \mathsf{hypot}\left(1, x\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Accuracy99.7%
Cost13768
\[\begin{array}{l} \mathbf{if}\;x \leq -1.05:\\ \;\;\;\;-\log \left(x \cdot -2 - \frac{0.5}{x}\right)\\ \mathbf{elif}\;x \leq 0.009:\\ \;\;\;\;-0.16666666666666666 \cdot {x}^{3} + \left(x + 0.075 \cdot {x}^{5}\right)\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{1}{x + \mathsf{hypot}\left(1, x\right)}\right)\\ \end{array} \]
Alternative 2
Accuracy99.8%
Cost13512
\[\begin{array}{l} \mathbf{if}\;x \leq -7 \cdot 10^{-6}:\\ \;\;\;\;-\log \left(\mathsf{hypot}\left(1, x\right) - x\right)\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-6}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{1}{x + \mathsf{hypot}\left(1, x\right)}\right)\\ \end{array} \]
Alternative 3
Accuracy99.7%
Cost13320
\[\begin{array}{l} \mathbf{if}\;x \leq -0.95:\\ \;\;\;\;-\log \left(x \cdot -2 - \frac{0.5}{x}\right)\\ \mathbf{elif}\;x \leq 0.0008:\\ \;\;\;\;x + -0.16666666666666666 \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \mathsf{hypot}\left(1, x\right)\right)\\ \end{array} \]
Alternative 4
Accuracy99.8%
Cost13320
\[\begin{array}{l} \mathbf{if}\;x \leq -7 \cdot 10^{-6}:\\ \;\;\;\;-\log \left(\mathsf{hypot}\left(1, x\right) - x\right)\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-6}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \mathsf{hypot}\left(1, x\right)\right)\\ \end{array} \]
Alternative 5
Accuracy99.5%
Cost7240
\[\begin{array}{l} \mathbf{if}\;x \leq -0.95:\\ \;\;\;\;-\log \left(x \cdot -2 - \frac{0.5}{x}\right)\\ \mathbf{elif}\;x \leq 0.96:\\ \;\;\;\;x + -0.16666666666666666 \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;\log \left(x \cdot 2 + 0.5 \cdot \frac{1}{x}\right)\\ \end{array} \]
Alternative 6
Accuracy99.3%
Cost7048
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;\log \left(\frac{-0.5}{x}\right)\\ \mathbf{elif}\;x \leq 1.25:\\ \;\;\;\;x + -0.16666666666666666 \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + x\right)\\ \end{array} \]
Alternative 7
Accuracy99.4%
Cost7048
\[\begin{array}{l} \mathbf{if}\;x \leq -0.95:\\ \;\;\;\;-\log \left(x \cdot -2 - \frac{0.5}{x}\right)\\ \mathbf{elif}\;x \leq 1.25:\\ \;\;\;\;x + -0.16666666666666666 \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + x\right)\\ \end{array} \]
Alternative 8
Accuracy99.0%
Cost6856
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;\log \left(\frac{-0.5}{x}\right)\\ \mathbf{elif}\;x \leq 1.25:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + x\right)\\ \end{array} \]
Alternative 9
Accuracy75.5%
Cost6724
\[\begin{array}{l} \mathbf{if}\;x \leq 1.25:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + x\right)\\ \end{array} \]
Alternative 10
Accuracy52.8%
Cost64
\[x \]

Reproduce?

herbie shell --seed 2023160 
(FPCore (x)
  :name "Hyperbolic arcsine"
  :precision binary64

  :herbie-target
  (if (< x 0.0) (log (/ -1.0 (- x (sqrt (+ (* x x) 1.0))))) (log (+ x (sqrt (+ (* x x) 1.0)))))

  (log (+ x (sqrt (+ (* x x) 1.0)))))