?

Average Error: 52.7 → 0.0
Time: 10.2s
Precision: binary64
Cost: 13572

?

\[\log \left(x + \sqrt{x \cdot x + 1}\right) \]
\[\begin{array}{l} \mathbf{if}\;x \leq -0.4:\\ \;\;\;\;-\log \left(\mathsf{hypot}\left(1, x\right) - x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(x \cdot \left(1 + \frac{x}{1 + \mathsf{hypot}\left(1, x\right)}\right)\right)\\ \end{array} \]
(FPCore (x) :precision binary64 (log (+ x (sqrt (+ (* x x) 1.0)))))
(FPCore (x)
 :precision binary64
 (if (<= x -0.4)
   (- (log (- (hypot 1.0 x) x)))
   (log1p (* x (+ 1.0 (/ x (+ 1.0 (hypot 1.0 x))))))))
double code(double x) {
	return log((x + sqrt(((x * x) + 1.0))));
}
double code(double x) {
	double tmp;
	if (x <= -0.4) {
		tmp = -log((hypot(1.0, x) - x));
	} else {
		tmp = log1p((x * (1.0 + (x / (1.0 + 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 <= -0.4) {
		tmp = -Math.log((Math.hypot(1.0, x) - x));
	} else {
		tmp = Math.log1p((x * (1.0 + (x / (1.0 + 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 <= -0.4:
		tmp = -math.log((math.hypot(1.0, x) - x))
	else:
		tmp = math.log1p((x * (1.0 + (x / (1.0 + 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 <= -0.4)
		tmp = Float64(-log(Float64(hypot(1.0, x) - x)));
	else
		tmp = log1p(Float64(x * Float64(1.0 + Float64(x / Float64(1.0 + hypot(1.0, x))))));
	end
	return 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, -0.4], (-N[Log[N[(N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]), N[Log[1 + N[(x * N[(1.0 + N[(x / N[(1.0 + N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\log \left(x + \sqrt{x \cdot x + 1}\right)
\begin{array}{l}
\mathbf{if}\;x \leq -0.4:\\
\;\;\;\;-\log \left(\mathsf{hypot}\left(1, x\right) - x\right)\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original52.7
Target45.1
Herbie0.0
\[\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 2 regimes
  2. if x < -0.40000000000000002

    1. Initial program 62.8

      \[\log \left(x + \sqrt{x \cdot x + 1}\right) \]
    2. Simplified62.8

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

      [Start]62.8

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

      +-commutative [=>]62.8

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

      hypot-1-def [=>]62.8

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

      \[\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)} \]
    4. Simplified0.0

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

      [Start]62.8

      \[ \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 [<=]62.1

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

      +-commutative [=>]62.1

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

      associate--r+ [=>]32.2

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

      +-inverses [=>]0.0

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

      metadata-eval [=>]0.0

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

      metadata-eval [<=]0.0

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

      associate-/r* [<=]0.0

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

      neg-mul-1 [<=]0.0

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

      neg-sub0 [=>]0.0

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

      associate--r- [=>]0.0

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

      neg-sub0 [<=]0.0

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

      +-commutative [<=]0.0

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

      sub-neg [<=]0.0

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

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

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

      [Start]0.0

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

      +-lft-identity [=>]0.0

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

    if -0.40000000000000002 < x

    1. Initial program 49.4

      \[\log \left(x + \sqrt{x \cdot x + 1}\right) \]
    2. Simplified38.7

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

      [Start]49.4

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

      +-commutative [=>]49.4

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

      hypot-1-def [=>]38.7

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

      \[\leadsto \log \color{blue}{\left(\left(1 + \left(x + \mathsf{hypot}\left(1, x\right)\right)\right) - 1\right)} \]
    4. Applied egg-rr0.5

      \[\leadsto \color{blue}{\mathsf{log1p}\left(x + \left(\mathsf{hypot}\left(1, x\right) + -1\right)\right)} \]
    5. Applied egg-rr10.7

      \[\leadsto \mathsf{log1p}\left(x + \color{blue}{\left(x \cdot x + 0\right) \cdot \frac{1}{1 + \mathsf{hypot}\left(1, x\right)}}\right) \]
    6. Simplified0.0

      \[\leadsto \mathsf{log1p}\left(x + \color{blue}{\frac{x}{\frac{1 + \mathsf{hypot}\left(1, x\right)}{x}}}\right) \]
      Proof

      [Start]10.7

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

      associate-*r/ [=>]10.7

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

      +-rgt-identity [=>]10.7

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

      *-rgt-identity [=>]10.7

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

      associate-/l* [=>]0.0

      \[ \mathsf{log1p}\left(x + \color{blue}{\frac{x}{\frac{1 + \mathsf{hypot}\left(1, x\right)}{x}}}\right) \]
    7. Applied egg-rr0.0

      \[\leadsto \mathsf{log1p}\left(\color{blue}{\left(1 + \frac{x}{1 + \mathsf{hypot}\left(1, x\right)}\right) \cdot x}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.4:\\ \;\;\;\;-\log \left(\mathsf{hypot}\left(1, x\right) - x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(x \cdot \left(1 + \frac{x}{1 + \mathsf{hypot}\left(1, x\right)}\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.4
Cost13508
\[\begin{array}{l} \mathbf{if}\;x \leq -8.5 \cdot 10^{-9}:\\ \;\;\;\;-\log \left(x + \left(\mathsf{hypot}\left(1, x\right) - \left(x + x\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(x + \left(\mathsf{hypot}\left(1, x\right) + -1\right)\right)\\ \end{array} \]
Alternative 2
Error0.1
Cost13320
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;-\log \left(x \cdot -2 + \frac{-0.5}{x}\right)\\ \mathbf{elif}\;x \leq 0.0042:\\ \;\;\;\;\mathsf{log1p}\left(x + \frac{x}{x \cdot 0.5 + \frac{1}{x} \cdot 2}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \mathsf{hypot}\left(1, x\right)\right)\\ \end{array} \]
Alternative 3
Error0.4
Cost13316
\[\begin{array}{l} \mathbf{if}\;x \leq -0.00075:\\ \;\;\;\;-\log \left(\mathsf{hypot}\left(1, x\right) - x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(x + \left(\mathsf{hypot}\left(1, x\right) + -1\right)\right)\\ \end{array} \]
Alternative 4
Error0.6
Cost13252
\[\begin{array}{l} \mathbf{if}\;x \leq -1.4 \cdot 10^{-8}:\\ \;\;\;\;-\log \left(\mathsf{hypot}\left(1, x\right) - x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(x + \frac{x}{\left(1 + \frac{1}{x}\right) + \frac{0.5}{x \cdot x}}\right)\\ \end{array} \]
Alternative 5
Error0.3
Cost7496
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;-\log \left(x \cdot -2 + \frac{-0.5}{x}\right)\\ \mathbf{elif}\;x \leq 1.3:\\ \;\;\;\;\mathsf{log1p}\left(x + \frac{x}{x \cdot 0.5 + \frac{1}{x} \cdot 2}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \left(x + \frac{0.5}{x}\right)\right)\\ \end{array} \]
Alternative 6
Error0.8
Cost7492
\[\begin{array}{l} \mathbf{if}\;x \leq -0.36:\\ \;\;\;\;-\log \left(x \cdot -2 + \frac{-0.5}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(x + \frac{x}{\left(1 + \frac{1}{x}\right) + \frac{0.5}{x \cdot x}}\right)\\ \end{array} \]
Alternative 7
Error0.4
Cost7112
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;-\log \left(\frac{x}{-0.5}\right)\\ \mathbf{elif}\;x \leq 0.95:\\ \;\;\;\;x + -0.16666666666666666 \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \left(x + \frac{0.5}{x}\right)\right)\\ \end{array} \]
Alternative 8
Error0.3
Cost7112
\[\begin{array}{l} \mathbf{if}\;x \leq -0.95:\\ \;\;\;\;-\log \left(x \cdot -2 + \frac{-0.5}{x}\right)\\ \mathbf{elif}\;x \leq 0.95:\\ \;\;\;\;x + -0.16666666666666666 \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \left(x + \frac{0.5}{x}\right)\right)\\ \end{array} \]
Alternative 9
Error0.4
Cost7048
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;-\log \left(\frac{x}{-0.5}\right)\\ \mathbf{elif}\;x \leq 1.25:\\ \;\;\;\;x + -0.16666666666666666 \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + x\right)\\ \end{array} \]
Alternative 10
Error0.6
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 11
Error0.6
Cost6856
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;-\log \left(\frac{x}{-0.5}\right)\\ \mathbf{elif}\;x \leq 1.25:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + x\right)\\ \end{array} \]
Alternative 12
Error15.4
Cost6724
\[\begin{array}{l} \mathbf{if}\;x \leq 1.25:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + x\right)\\ \end{array} \]
Alternative 13
Error26.5
Cost6596
\[\begin{array}{l} \mathbf{if}\;x \leq 1.6:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(x\right)\\ \end{array} \]
Alternative 14
Error30.7
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023027 
(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)))))