Alternative 1 | |
---|---|
Error | 5.1 |
Cost | 32904 |
(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}
Results
if (*.f64 (sinh.f64 a) b) < -4e3
Initial program 62.8
Taylor expanded in b around -inf 20.7
Simplified20.7
[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)
\] |
---|---|
mul-1-neg [=>]20.7 | \[ \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)
\] |
distribute-rgt-neg-in [=>]20.7 | \[ \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)
\] |
distribute-rgt-out [=>]20.7 | \[ \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)
\] |
metadata-eval [=>]20.7 | \[ \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)
\] |
mul0-rgt [=>]20.7 | \[ \log \left(b \cdot \left(-\color{blue}{0}\right) - \frac{1}{\left(e^{a} - \frac{1}{e^{a}}\right) \cdot b}\right)
\] |
metadata-eval [=>]20.7 | \[ \log \left(b \cdot \color{blue}{0} - \frac{1}{\left(e^{a} - \frac{1}{e^{a}}\right) \cdot b}\right)
\] |
*-commutative [=>]20.7 | \[ \log \left(b \cdot 0 - \frac{1}{\color{blue}{b \cdot \left(e^{a} - \frac{1}{e^{a}}\right)}}\right)
\] |
associate-/r* [=>]20.7 | \[ \log \left(b \cdot 0 - \color{blue}{\frac{\frac{1}{b}}{e^{a} - \frac{1}{e^{a}}}}\right)
\] |
rec-exp [=>]20.7 | \[ \log \left(b \cdot 0 - \frac{\frac{1}{b}}{e^{a} - \color{blue}{e^{-a}}}\right)
\] |
Taylor expanded in b around 0 64.0
Simplified20.7
[Start]64.0 | \[ \log \left(-\frac{1}{e^{a} - e^{-a}}\right) + -1 \cdot \log b
\] |
---|---|
neg-mul-1 [=>]64.0 | \[ \log \color{blue}{\left(-1 \cdot \frac{1}{e^{a} - e^{-a}}\right)} + -1 \cdot \log b
\] |
log-prod [=>]64.0 | \[ \color{blue}{\left(\log -1 + \log \left(\frac{1}{e^{a} - e^{-a}}\right)\right)} + -1 \cdot \log b
\] |
mul-1-neg [=>]64.0 | \[ \left(\log -1 + \log \left(\frac{1}{e^{a} - e^{-a}}\right)\right) + \color{blue}{\left(-\log b\right)}
\] |
log-rec [<=]64.0 | \[ \left(\log -1 + \log \left(\frac{1}{e^{a} - e^{-a}}\right)\right) + \color{blue}{\log \left(\frac{1}{b}\right)}
\] |
associate-+l+ [=>]64.0 | \[ \color{blue}{\log -1 + \left(\log \left(\frac{1}{e^{a} - e^{-a}}\right) + \log \left(\frac{1}{b}\right)\right)}
\] |
metadata-eval [<=]64.0 | \[ \log -1 + \left(\log \left(\frac{\color{blue}{0.5 \cdot 2}}{e^{a} - e^{-a}}\right) + \log \left(\frac{1}{b}\right)\right)
\] |
associate-*l/ [<=]64.0 | \[ \log -1 + \left(\log \color{blue}{\left(\frac{0.5}{e^{a} - e^{-a}} \cdot 2\right)} + \log \left(\frac{1}{b}\right)\right)
\] |
associate-/r/ [<=]64.0 | \[ \log -1 + \left(\log \color{blue}{\left(\frac{0.5}{\frac{e^{a} - e^{-a}}{2}}\right)} + \log \left(\frac{1}{b}\right)\right)
\] |
metadata-eval [<=]64.0 | \[ \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)
\] |
sinh-def [<=]64.0 | \[ \log -1 + \left(\log \left(\frac{\frac{1}{2}}{\color{blue}{\sinh a}}\right) + \log \left(\frac{1}{b}\right)\right)
\] |
associate-/r* [<=]64.0 | \[ \log -1 + \left(\log \color{blue}{\left(\frac{1}{2 \cdot \sinh a}\right)} + \log \left(\frac{1}{b}\right)\right)
\] |
log-rec [=>]64.0 | \[ \log -1 + \left(\log \left(\frac{1}{2 \cdot \sinh a}\right) + \color{blue}{\left(-\log b\right)}\right)
\] |
sub-neg [<=]64.0 | \[ \log -1 + \color{blue}{\left(\log \left(\frac{1}{2 \cdot \sinh a}\right) - \log b\right)}
\] |
log-div [<=]64.0 | \[ \log -1 + \color{blue}{\log \left(\frac{\frac{1}{2 \cdot \sinh a}}{b}\right)}
\] |
associate-/r* [<=]64.0 | \[ \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
Initial program 59.0
Taylor expanded in b around 0 0.9
Simplified0.9
[Start]0.9 | \[ 0.5 \cdot \left(\left(e^{a} - \frac{1}{e^{a}}\right) \cdot b\right)
\] |
---|---|
associate-*r* [=>]0.9 | \[ \color{blue}{\left(0.5 \cdot \left(e^{a} - \frac{1}{e^{a}}\right)\right) \cdot b}
\] |
*-commutative [<=]0.9 | \[ \color{blue}{b \cdot \left(0.5 \cdot \left(e^{a} - \frac{1}{e^{a}}\right)\right)}
\] |
rec-exp [=>]0.9 | \[ b \cdot \left(0.5 \cdot \left(e^{a} - \color{blue}{e^{-a}}\right)\right)
\] |
if 1.99999999999999991e-6 < (*.f64 (sinh.f64 a) b)
Initial program 23.5
Simplified18.2
[Start]23.5 | \[ \log \left(\sinh a \cdot b + \sqrt{1 + {\left(\sinh a \cdot b\right)}^{2}}\right)
\] |
---|---|
fma-def [=>]23.5 | \[ \log \color{blue}{\left(\mathsf{fma}\left(\sinh a, b, \sqrt{1 + {\left(\sinh a \cdot b\right)}^{2}}\right)\right)}
\] |
unpow2 [=>]23.5 | \[ \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)
\] |
hypot-1-def [=>]18.2 | \[ \log \left(\mathsf{fma}\left(\sinh a, b, \color{blue}{\mathsf{hypot}\left(1, \sinh a \cdot b\right)}\right)\right)
\] |
Applied egg-rr18.1
Final simplification4.7
Alternative 1 | |
---|---|
Error | 5.1 |
Cost | 32904 |
Alternative 2 | |
---|---|
Error | 8.9 |
Cost | 19972 |
Alternative 3 | |
---|---|
Error | 8.9 |
Cost | 19780 |
Alternative 4 | |
---|---|
Error | 12.9 |
Cost | 6592 |
Alternative 5 | |
---|---|
Error | 56.8 |
Cost | 192 |
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))))))