# ?

Average Error: 55.6 → 4.7
Time: 19.8s
Precision: binary64
Cost: 39432

# ?

$\left(1 \leq a \land a \leq 1000\right) \land \left(-1 \leq b \land b \leq 1\right)$
$\log \left(\sinh a \cdot b + \sqrt{1 + {\left(\sinh a \cdot b\right)}^{2}}\right)$
$\begin{array}{l} t_0 := \sinh a \cdot b\\ \mathbf{if}\;t_0 \leq -4000:\\ \;\;\;\;\log \left(\frac{\frac{-0.5}{b}}{\sinh a}\right)\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{-6}:\\ \;\;\;\;b \cdot \left(0.5 \cdot \left(e^{a} - e^{-a}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(t_0 + \mathsf{hypot}\left(1, t_0\right)\right)\\ \end{array}$
(FPCore (a b)
:precision binary64
(log (+ (* (sinh a) b) (sqrt (+ 1.0 (pow (* (sinh a) b) 2.0))))))
(FPCore (a b)
:precision binary64
(let* ((t_0 (* (sinh a) b)))
(if (<= t_0 -4000.0)
(log (/ (/ -0.5 b) (sinh a)))
(if (<= t_0 2e-6)
(* b (* 0.5 (- (exp a) (exp (- a)))))
(log (+ t_0 (hypot 1.0 t_0)))))))
double code(double a, double b) {
return log(((sinh(a) * b) + sqrt((1.0 + pow((sinh(a) * b), 2.0)))));
}

double code(double a, double b) {
double t_0 = sinh(a) * b;
double tmp;
if (t_0 <= -4000.0) {
tmp = log(((-0.5 / b) / sinh(a)));
} else if (t_0 <= 2e-6) {
tmp = b * (0.5 * (exp(a) - exp(-a)));
} else {
tmp = log((t_0 + hypot(1.0, t_0)));
}
return tmp;
}

public static double code(double a, double b) {
return Math.log(((Math.sinh(a) * b) + Math.sqrt((1.0 + Math.pow((Math.sinh(a) * b), 2.0)))));
}

public static double code(double a, double b) {
double t_0 = Math.sinh(a) * b;
double tmp;
if (t_0 <= -4000.0) {
tmp = Math.log(((-0.5 / b) / Math.sinh(a)));
} else if (t_0 <= 2e-6) {
tmp = b * (0.5 * (Math.exp(a) - Math.exp(-a)));
} else {
tmp = Math.log((t_0 + Math.hypot(1.0, t_0)));
}
return tmp;
}

def code(a, b):
return math.log(((math.sinh(a) * b) + math.sqrt((1.0 + math.pow((math.sinh(a) * b), 2.0)))))

def code(a, b):
t_0 = math.sinh(a) * b
tmp = 0
if t_0 <= -4000.0:
tmp = math.log(((-0.5 / b) / math.sinh(a)))
elif t_0 <= 2e-6:
tmp = b * (0.5 * (math.exp(a) - math.exp(-a)))
else:
tmp = math.log((t_0 + math.hypot(1.0, t_0)))
return tmp

function code(a, b)
return log(Float64(Float64(sinh(a) * b) + sqrt(Float64(1.0 + (Float64(sinh(a) * b) ^ 2.0)))))
end

function code(a, b)
t_0 = Float64(sinh(a) * b)
tmp = 0.0
if (t_0 <= -4000.0)
tmp = log(Float64(Float64(-0.5 / b) / sinh(a)));
elseif (t_0 <= 2e-6)
tmp = Float64(b * Float64(0.5 * Float64(exp(a) - exp(Float64(-a)))));
else
tmp = log(Float64(t_0 + hypot(1.0, t_0)));
end
return tmp
end

function tmp = code(a, b)
tmp = log(((sinh(a) * b) + sqrt((1.0 + ((sinh(a) * b) ^ 2.0)))));
end

function tmp_2 = code(a, b)
t_0 = sinh(a) * b;
tmp = 0.0;
if (t_0 <= -4000.0)
tmp = log(((-0.5 / b) / sinh(a)));
elseif (t_0 <= 2e-6)
tmp = b * (0.5 * (exp(a) - exp(-a)));
else
tmp = log((t_0 + hypot(1.0, t_0)));
end
tmp_2 = tmp;
end

code[a_, b_] := N[Log[N[(N[(N[Sinh[a], $MachinePrecision] * b),$MachinePrecision] + N[Sqrt[N[(1.0 + N[Power[N[(N[Sinh[a], $MachinePrecision] * b),$MachinePrecision], 2.0], $MachinePrecision]),$MachinePrecision]], $MachinePrecision]),$MachinePrecision]], $MachinePrecision]  code[a_, b_] := Block[{t$95$0 = N[(N[Sinh[a],$MachinePrecision] * b), $MachinePrecision]}, If[LessEqual[t$95$0, -4000.0], N[Log[N[(N[(-0.5 / b),$MachinePrecision] / N[Sinh[a], $MachinePrecision]),$MachinePrecision]], $MachinePrecision], If[LessEqual[t$95$0, 2e-6], N[(b * N[(0.5 * N[(N[Exp[a],$MachinePrecision] - N[Exp[(-a)], $MachinePrecision]),$MachinePrecision]), $MachinePrecision]),$MachinePrecision], N[Log[N[(t$95$0 + N[Sqrt[1.0 ^ 2 + t$95$0 ^ 2], $MachinePrecision]),$MachinePrecision]], \$MachinePrecision]]]]

\log \left(\sinh a \cdot b + \sqrt{1 + {\left(\sinh a \cdot b\right)}^{2}}\right)

\begin{array}{l}
t_0 := \sinh a \cdot b\\
\mathbf{if}\;t_0 \leq -4000:\\
\;\;\;\;\log \left(\frac{\frac{-0.5}{b}}{\sinh a}\right)\\

\mathbf{elif}\;t_0 \leq 2 \cdot 10^{-6}:\\
\;\;\;\;b \cdot \left(0.5 \cdot \left(e^{a} - e^{-a}\right)\right)\\

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

\end{array}


# Try it out?

Results

 In Out
Enter valid numbers for all inputs

# Derivation?

1. Split input into 3 regimes
2. ## if (*.f64 (sinh.f64 a) b) < -4e3

1. Initial program 62.8

$\log \left(\sinh a \cdot b + \sqrt{1 + {\left(\sinh a \cdot b\right)}^{2}}\right)$
2. Taylor expanded in b around -inf 20.7

$\leadsto \log \color{blue}{\left(-1 \cdot \left(b \cdot \left(0.5 \cdot \left(e^{a} - \frac{1}{e^{a}}\right) + -0.5 \cdot \left(e^{a} - \frac{1}{e^{a}}\right)\right)\right) - \frac{1}{\left(e^{a} - \frac{1}{e^{a}}\right) \cdot b}\right)}$
3. Simplified20.7

$\leadsto \log \color{blue}{\left(b \cdot 0 - \frac{\frac{1}{b}}{e^{a} - e^{-a}}\right)}$
Proof
[Start]20.7 $\log \left(-1 \cdot \left(b \cdot \left(0.5 \cdot \left(e^{a} - \frac{1}{e^{a}}\right) + -0.5 \cdot \left(e^{a} - \frac{1}{e^{a}}\right)\right)\right) - \frac{1}{\left(e^{a} - \frac{1}{e^{a}}\right) \cdot b}\right)$ $\log \left(\color{blue}{\left(-b \cdot \left(0.5 \cdot \left(e^{a} - \frac{1}{e^{a}}\right) + -0.5 \cdot \left(e^{a} - \frac{1}{e^{a}}\right)\right)\right)} - \frac{1}{\left(e^{a} - \frac{1}{e^{a}}\right) \cdot b}\right)$ $\log \left(\color{blue}{b \cdot \left(-\left(0.5 \cdot \left(e^{a} - \frac{1}{e^{a}}\right) + -0.5 \cdot \left(e^{a} - \frac{1}{e^{a}}\right)\right)\right)} - \frac{1}{\left(e^{a} - \frac{1}{e^{a}}\right) \cdot b}\right)$ $\log \left(b \cdot \left(-\color{blue}{\left(e^{a} - \frac{1}{e^{a}}\right) \cdot \left(0.5 + -0.5\right)}\right) - \frac{1}{\left(e^{a} - \frac{1}{e^{a}}\right) \cdot b}\right)$ $\log \left(b \cdot \left(-\left(e^{a} - \frac{1}{e^{a}}\right) \cdot \color{blue}{0}\right) - \frac{1}{\left(e^{a} - \frac{1}{e^{a}}\right) \cdot b}\right)$ $\log \left(b \cdot \left(-\color{blue}{0}\right) - \frac{1}{\left(e^{a} - \frac{1}{e^{a}}\right) \cdot b}\right)$ $\log \left(b \cdot \color{blue}{0} - \frac{1}{\left(e^{a} - \frac{1}{e^{a}}\right) \cdot b}\right)$ $\log \left(b \cdot 0 - \frac{1}{\color{blue}{b \cdot \left(e^{a} - \frac{1}{e^{a}}\right)}}\right)$ $\log \left(b \cdot 0 - \color{blue}{\frac{\frac{1}{b}}{e^{a} - \frac{1}{e^{a}}}}\right)$ $\log \left(b \cdot 0 - \frac{\frac{1}{b}}{e^{a} - \color{blue}{e^{-a}}}\right)$
4. Taylor expanded in b around 0 64.0

$\leadsto \color{blue}{\log \left(-\frac{1}{e^{a} - e^{-a}}\right) + -1 \cdot \log b}$
5. Simplified20.7

$\leadsto \color{blue}{\log \left(\frac{\frac{-0.5}{b}}{\sinh a}\right)}$
Proof
[Start]64.0 $\log \left(-\frac{1}{e^{a} - e^{-a}}\right) + -1 \cdot \log b$ $\log \color{blue}{\left(-1 \cdot \frac{1}{e^{a} - e^{-a}}\right)} + -1 \cdot \log b$ $\color{blue}{\left(\log -1 + \log \left(\frac{1}{e^{a} - e^{-a}}\right)\right)} + -1 \cdot \log b$ $\left(\log -1 + \log \left(\frac{1}{e^{a} - e^{-a}}\right)\right) + \color{blue}{\left(-\log b\right)}$ $\left(\log -1 + \log \left(\frac{1}{e^{a} - e^{-a}}\right)\right) + \color{blue}{\log \left(\frac{1}{b}\right)}$ $\color{blue}{\log -1 + \left(\log \left(\frac{1}{e^{a} - e^{-a}}\right) + \log \left(\frac{1}{b}\right)\right)}$ $\log -1 + \left(\log \left(\frac{\color{blue}{0.5 \cdot 2}}{e^{a} - e^{-a}}\right) + \log \left(\frac{1}{b}\right)\right)$ $\log -1 + \left(\log \color{blue}{\left(\frac{0.5}{e^{a} - e^{-a}} \cdot 2\right)} + \log \left(\frac{1}{b}\right)\right)$ $\log -1 + \left(\log \color{blue}{\left(\frac{0.5}{\frac{e^{a} - e^{-a}}{2}}\right)} + \log \left(\frac{1}{b}\right)\right)$ $\log -1 + \left(\log \left(\frac{\color{blue}{\frac{1}{2}}}{\frac{e^{a} - e^{-a}}{2}}\right) + \log \left(\frac{1}{b}\right)\right)$ $\log -1 + \left(\log \left(\frac{\frac{1}{2}}{\color{blue}{\sinh a}}\right) + \log \left(\frac{1}{b}\right)\right)$ $\log -1 + \left(\log \color{blue}{\left(\frac{1}{2 \cdot \sinh a}\right)} + \log \left(\frac{1}{b}\right)\right)$ $\log -1 + \left(\log \left(\frac{1}{2 \cdot \sinh a}\right) + \color{blue}{\left(-\log b\right)}\right)$ $\log -1 + \color{blue}{\left(\log \left(\frac{1}{2 \cdot \sinh a}\right) - \log b\right)}$ $\log -1 + \color{blue}{\log \left(\frac{\frac{1}{2 \cdot \sinh a}}{b}\right)}$ $\log -1 + \log \color{blue}{\left(\frac{1}{\left(2 \cdot \sinh a\right) \cdot b}\right)}$

## if -4e3 < (*.f64 (sinh.f64 a) b) < 1.99999999999999991e-6

1. Initial program 59.0

$\log \left(\sinh a \cdot b + \sqrt{1 + {\left(\sinh a \cdot b\right)}^{2}}\right)$
2. Taylor expanded in b around 0 0.9

$\leadsto \color{blue}{0.5 \cdot \left(\left(e^{a} - \frac{1}{e^{a}}\right) \cdot b\right)}$
3. Simplified0.9

$\leadsto \color{blue}{b \cdot \left(0.5 \cdot \left(e^{a} - e^{-a}\right)\right)}$
Proof
[Start]0.9 $0.5 \cdot \left(\left(e^{a} - \frac{1}{e^{a}}\right) \cdot b\right)$ $\color{blue}{\left(0.5 \cdot \left(e^{a} - \frac{1}{e^{a}}\right)\right) \cdot b}$ $\color{blue}{b \cdot \left(0.5 \cdot \left(e^{a} - \frac{1}{e^{a}}\right)\right)}$ $b \cdot \left(0.5 \cdot \left(e^{a} - \color{blue}{e^{-a}}\right)\right)$

## if 1.99999999999999991e-6 < (*.f64 (sinh.f64 a) b)

1. Initial program 23.5

$\log \left(\sinh a \cdot b + \sqrt{1 + {\left(\sinh a \cdot b\right)}^{2}}\right)$
2. Simplified18.2

$\leadsto \color{blue}{\log \left(\mathsf{fma}\left(\sinh a, b, \mathsf{hypot}\left(1, \sinh a \cdot b\right)\right)\right)}$
Proof
[Start]23.5 $\log \left(\sinh a \cdot b + \sqrt{1 + {\left(\sinh a \cdot b\right)}^{2}}\right)$ $\log \color{blue}{\left(\mathsf{fma}\left(\sinh a, b, \sqrt{1 + {\left(\sinh a \cdot b\right)}^{2}}\right)\right)}$ $\log \left(\mathsf{fma}\left(\sinh a, b, \sqrt{1 + \color{blue}{\left(\sinh a \cdot b\right) \cdot \left(\sinh a \cdot b\right)}}\right)\right)$ $\log \left(\mathsf{fma}\left(\sinh a, b, \color{blue}{\mathsf{hypot}\left(1, \sinh a \cdot b\right)}\right)\right)$
3. Applied egg-rr18.1

$\leadsto \log \color{blue}{\left(\mathsf{hypot}\left(1, \sinh a \cdot b\right) + \sinh a \cdot b\right)}$
3. Recombined 3 regimes into one program.
4. Final simplification4.7

$\leadsto \begin{array}{l} \mathbf{if}\;\sinh a \cdot b \leq -4000:\\ \;\;\;\;\log \left(\frac{\frac{-0.5}{b}}{\sinh a}\right)\\ \mathbf{elif}\;\sinh a \cdot b \leq 2 \cdot 10^{-6}:\\ \;\;\;\;b \cdot \left(0.5 \cdot \left(e^{a} - e^{-a}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\sinh a \cdot b + \mathsf{hypot}\left(1, \sinh a \cdot b\right)\right)\\ \end{array}$

# Alternatives

Alternative 1
Error5.1
Cost32904
$\begin{array}{l} t_0 := e^{a} - e^{-a}\\ t_1 := \sinh a \cdot b\\ \mathbf{if}\;t_1 \leq -4000:\\ \;\;\;\;\log \left(\frac{\frac{-0.5}{b}}{\sinh a}\right)\\ \mathbf{elif}\;t_1 \leq 0.05:\\ \;\;\;\;b \cdot \left(0.5 \cdot t_0\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(b \cdot t_0\right)\\ \end{array}$
Alternative 2
Error8.9
Cost19972
$\begin{array}{l} \mathbf{if}\;\sinh a \cdot b \leq -4000:\\ \;\;\;\;\log \left(\frac{\frac{-0.5}{b}}{\sinh a}\right)\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(0.5 \cdot \left(e^{a} - e^{-a}\right)\right)\\ \end{array}$
Alternative 3
Error8.9
Cost19780
$\begin{array}{l} t_0 := \sinh a \cdot b\\ \mathbf{if}\;t_0 \leq -4000:\\ \;\;\;\;\log \left(\frac{\frac{-0.5}{b}}{\sinh a}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array}$
Alternative 4
Error12.9
Cost6592
$\sinh a \cdot b$
Alternative 5
Error56.8
Cost192
$a \cdot b$

# Reproduce?

herbie shell --seed 1
(FPCore (a b)
:name "log(sinh(a) * b + sqrt(1 + (sinh(a) * b) ^ 2))"
:precision binary64
:pre (and (and (<= 1.0 a) (<= a 1000.0)) (and (<= -1.0 b) (<= b 1.0)))
(log (+ (* (sinh a) b) (sqrt (+ 1.0 (pow (* (sinh a) b) 2.0))))))