| Alternative 1 | |
|---|---|
| Accuracy | 82.5% |
| Cost | 40652 |

(FPCore (x l t) :precision binary64 (/ (* (sqrt 2.0) t) (sqrt (- (* (/ (+ x 1.0) (- x 1.0)) (+ (* l l) (* 2.0 (* t t)))) (* l l)))))
(FPCore (x l t)
:precision binary64
(let* ((t_1 (fma (* t 2.0) t (* l l)))
(t_2
(*
t
(/
(sqrt 2.0)
(sqrt
(+
(/ (* l l) x)
(+ (* 2.0 (+ (* t t) (/ (* t t) x))) (/ t_1 x))))))))
(if (<= t -1.05e+14)
(/ (sqrt 2.0) (* (- (sqrt 2.0)) (sqrt (/ (+ x 1.0) (+ x -1.0)))))
(if (<= t 7.8e-215)
t_2
(if (<= t 3.1e-164)
(*
t
(/
(sqrt 2.0)
(fma
0.5
(/ (+ (* l l) (fma 2.0 (* t t) t_1)) (* (sqrt 2.0) (* t x)))
(* t (sqrt 2.0)))))
(if (<= t 1.8e+85) t_2 (/ (sqrt 2.0) (sqrt 2.0))))))))double code(double x, double l, double t) {
return (sqrt(2.0) * t) / sqrt(((((x + 1.0) / (x - 1.0)) * ((l * l) + (2.0 * (t * t)))) - (l * l)));
}
double code(double x, double l, double t) {
double t_1 = fma((t * 2.0), t, (l * l));
double t_2 = t * (sqrt(2.0) / sqrt((((l * l) / x) + ((2.0 * ((t * t) + ((t * t) / x))) + (t_1 / x)))));
double tmp;
if (t <= -1.05e+14) {
tmp = sqrt(2.0) / (-sqrt(2.0) * sqrt(((x + 1.0) / (x + -1.0))));
} else if (t <= 7.8e-215) {
tmp = t_2;
} else if (t <= 3.1e-164) {
tmp = t * (sqrt(2.0) / fma(0.5, (((l * l) + fma(2.0, (t * t), t_1)) / (sqrt(2.0) * (t * x))), (t * sqrt(2.0))));
} else if (t <= 1.8e+85) {
tmp = t_2;
} else {
tmp = sqrt(2.0) / sqrt(2.0);
}
return tmp;
}
function code(x, l, t) return Float64(Float64(sqrt(2.0) * t) / sqrt(Float64(Float64(Float64(Float64(x + 1.0) / Float64(x - 1.0)) * Float64(Float64(l * l) + Float64(2.0 * Float64(t * t)))) - Float64(l * l)))) end
function code(x, l, t) t_1 = fma(Float64(t * 2.0), t, Float64(l * l)) t_2 = Float64(t * Float64(sqrt(2.0) / sqrt(Float64(Float64(Float64(l * l) / x) + Float64(Float64(2.0 * Float64(Float64(t * t) + Float64(Float64(t * t) / x))) + Float64(t_1 / x)))))) tmp = 0.0 if (t <= -1.05e+14) tmp = Float64(sqrt(2.0) / Float64(Float64(-sqrt(2.0)) * sqrt(Float64(Float64(x + 1.0) / Float64(x + -1.0))))); elseif (t <= 7.8e-215) tmp = t_2; elseif (t <= 3.1e-164) tmp = Float64(t * Float64(sqrt(2.0) / fma(0.5, Float64(Float64(Float64(l * l) + fma(2.0, Float64(t * t), t_1)) / Float64(sqrt(2.0) * Float64(t * x))), Float64(t * sqrt(2.0))))); elseif (t <= 1.8e+85) tmp = t_2; else tmp = Float64(sqrt(2.0) / sqrt(2.0)); end return tmp end
code[x_, l_, t_] := N[(N[(N[Sqrt[2.0], $MachinePrecision] * t), $MachinePrecision] / N[Sqrt[N[(N[(N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision] * N[(N[(l * l), $MachinePrecision] + N[(2.0 * N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(l * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_, l_, t_] := Block[{t$95$1 = N[(N[(t * 2.0), $MachinePrecision] * t + N[(l * l), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t * N[(N[Sqrt[2.0], $MachinePrecision] / N[Sqrt[N[(N[(N[(l * l), $MachinePrecision] / x), $MachinePrecision] + N[(N[(2.0 * N[(N[(t * t), $MachinePrecision] + N[(N[(t * t), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t$95$1 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t, -1.05e+14], N[(N[Sqrt[2.0], $MachinePrecision] / N[((-N[Sqrt[2.0], $MachinePrecision]) * N[Sqrt[N[(N[(x + 1.0), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 7.8e-215], t$95$2, If[LessEqual[t, 3.1e-164], N[(t * N[(N[Sqrt[2.0], $MachinePrecision] / N[(0.5 * N[(N[(N[(l * l), $MachinePrecision] + N[(2.0 * N[(t * t), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[2.0], $MachinePrecision] * N[(t * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 1.8e+85], t$95$2, N[(N[Sqrt[2.0], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]]]]]]]
\frac{\sqrt{2} \cdot t}{\sqrt{\frac{x + 1}{x - 1} \cdot \left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right) - \ell \cdot \ell}}
\begin{array}{l}
t_1 := \mathsf{fma}\left(t \cdot 2, t, \ell \cdot \ell\right)\\
t_2 := t \cdot \frac{\sqrt{2}}{\sqrt{\frac{\ell \cdot \ell}{x} + \left(2 \cdot \left(t \cdot t + \frac{t \cdot t}{x}\right) + \frac{t_1}{x}\right)}}\\
\mathbf{if}\;t \leq -1.05 \cdot 10^{+14}:\\
\;\;\;\;\frac{\sqrt{2}}{\left(-\sqrt{2}\right) \cdot \sqrt{\frac{x + 1}{x + -1}}}\\
\mathbf{elif}\;t \leq 7.8 \cdot 10^{-215}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t \leq 3.1 \cdot 10^{-164}:\\
\;\;\;\;t \cdot \frac{\sqrt{2}}{\mathsf{fma}\left(0.5, \frac{\ell \cdot \ell + \mathsf{fma}\left(2, t \cdot t, t_1\right)}{\sqrt{2} \cdot \left(t \cdot x\right)}, t \cdot \sqrt{2}\right)}\\
\mathbf{elif}\;t \leq 1.8 \cdot 10^{+85}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{2}}{\sqrt{2}}\\
\end{array}
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
if t < -1.05e14Initial program 41.9%
Simplified41.9%
[Start]41.9% | \[ \frac{\sqrt{2} \cdot t}{\sqrt{\frac{x + 1}{x - 1} \cdot \left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right) - \ell \cdot \ell}}
\] |
|---|---|
associate-/l* [=>]41.9% | \[ \color{blue}{\frac{\sqrt{2}}{\frac{\sqrt{\frac{x + 1}{x - 1} \cdot \left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right) - \ell \cdot \ell}}{t}}}
\] |
fma-neg [=>]41.9% | \[ \frac{\sqrt{2}}{\frac{\sqrt{\color{blue}{\mathsf{fma}\left(\frac{x + 1}{x - 1}, \ell \cdot \ell + 2 \cdot \left(t \cdot t\right), -\ell \cdot \ell\right)}}}{t}}
\] |
remove-double-neg [<=]41.9% | \[ \frac{\sqrt{2}}{\frac{\sqrt{\mathsf{fma}\left(\frac{x + 1}{x - 1}, \color{blue}{-\left(-\left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right)\right)}, -\ell \cdot \ell\right)}}{t}}
\] |
fma-neg [<=]41.9% | \[ \frac{\sqrt{2}}{\frac{\sqrt{\color{blue}{\frac{x + 1}{x - 1} \cdot \left(-\left(-\left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right)\right)\right) - \ell \cdot \ell}}}{t}}
\] |
sub-neg [=>]41.9% | \[ \frac{\sqrt{2}}{\frac{\sqrt{\frac{x + 1}{\color{blue}{x + \left(-1\right)}} \cdot \left(-\left(-\left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right)\right)\right) - \ell \cdot \ell}}{t}}
\] |
metadata-eval [=>]41.9% | \[ \frac{\sqrt{2}}{\frac{\sqrt{\frac{x + 1}{x + \color{blue}{-1}} \cdot \left(-\left(-\left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right)\right)\right) - \ell \cdot \ell}}{t}}
\] |
remove-double-neg [=>]41.9% | \[ \frac{\sqrt{2}}{\frac{\sqrt{\frac{x + 1}{x + -1} \cdot \color{blue}{\left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right)} - \ell \cdot \ell}}{t}}
\] |
fma-def [=>]41.9% | \[ \frac{\sqrt{2}}{\frac{\sqrt{\frac{x + 1}{x + -1} \cdot \color{blue}{\mathsf{fma}\left(\ell, \ell, 2 \cdot \left(t \cdot t\right)\right)} - \ell \cdot \ell}}{t}}
\] |
Taylor expanded in t around -inf 95.0%
Simplified95.0%
[Start]95.0% | \[ \frac{\sqrt{2}}{-1 \cdot \left(\sqrt{2} \cdot \sqrt{\frac{1 + x}{x - 1}}\right)}
\] |
|---|---|
associate-*r* [=>]95.0% | \[ \frac{\sqrt{2}}{\color{blue}{\left(-1 \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1 + x}{x - 1}}}}
\] |
neg-mul-1 [<=]95.0% | \[ \frac{\sqrt{2}}{\color{blue}{\left(-\sqrt{2}\right)} \cdot \sqrt{\frac{1 + x}{x - 1}}}
\] |
+-commutative [<=]95.0% | \[ \frac{\sqrt{2}}{\left(-\sqrt{2}\right) \cdot \sqrt{\frac{\color{blue}{x + 1}}{x - 1}}}
\] |
sub-neg [=>]95.0% | \[ \frac{\sqrt{2}}{\left(-\sqrt{2}\right) \cdot \sqrt{\frac{x + 1}{\color{blue}{x + \left(-1\right)}}}}
\] |
metadata-eval [=>]95.0% | \[ \frac{\sqrt{2}}{\left(-\sqrt{2}\right) \cdot \sqrt{\frac{x + 1}{x + \color{blue}{-1}}}}
\] |
+-commutative [=>]95.0% | \[ \frac{\sqrt{2}}{\left(-\sqrt{2}\right) \cdot \sqrt{\frac{x + 1}{\color{blue}{-1 + x}}}}
\] |
if -1.05e14 < t < 7.7999999999999999e-215 or 3.1000000000000001e-164 < t < 1.7999999999999999e85Initial program 37.5%
Simplified37.5%
[Start]37.5% | \[ \frac{\sqrt{2} \cdot t}{\sqrt{\frac{x + 1}{x - 1} \cdot \left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right) - \ell \cdot \ell}}
\] |
|---|---|
associate-*l/ [<=]37.5% | \[ \color{blue}{\frac{\sqrt{2}}{\sqrt{\frac{x + 1}{x - 1} \cdot \left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right) - \ell \cdot \ell}} \cdot t}
\] |
Taylor expanded in x around inf 79.6%
Simplified79.6%
[Start]79.6% | \[ \frac{\sqrt{2}}{\sqrt{\left(\frac{{\ell}^{2}}{x} + \left(2 \cdot \frac{{t}^{2}}{x} + 2 \cdot {t}^{2}\right)\right) - -1 \cdot \frac{{\ell}^{2} + 2 \cdot {t}^{2}}{x}}} \cdot t
\] |
|---|---|
associate--l+ [=>]79.6% | \[ \frac{\sqrt{2}}{\sqrt{\color{blue}{\frac{{\ell}^{2}}{x} + \left(\left(2 \cdot \frac{{t}^{2}}{x} + 2 \cdot {t}^{2}\right) - -1 \cdot \frac{{\ell}^{2} + 2 \cdot {t}^{2}}{x}\right)}}} \cdot t
\] |
unpow2 [=>]79.6% | \[ \frac{\sqrt{2}}{\sqrt{\frac{\color{blue}{\ell \cdot \ell}}{x} + \left(\left(2 \cdot \frac{{t}^{2}}{x} + 2 \cdot {t}^{2}\right) - -1 \cdot \frac{{\ell}^{2} + 2 \cdot {t}^{2}}{x}\right)}} \cdot t
\] |
distribute-lft-out [=>]79.6% | \[ \frac{\sqrt{2}}{\sqrt{\frac{\ell \cdot \ell}{x} + \left(\color{blue}{2 \cdot \left(\frac{{t}^{2}}{x} + {t}^{2}\right)} - -1 \cdot \frac{{\ell}^{2} + 2 \cdot {t}^{2}}{x}\right)}} \cdot t
\] |
unpow2 [=>]79.6% | \[ \frac{\sqrt{2}}{\sqrt{\frac{\ell \cdot \ell}{x} + \left(2 \cdot \left(\frac{\color{blue}{t \cdot t}}{x} + {t}^{2}\right) - -1 \cdot \frac{{\ell}^{2} + 2 \cdot {t}^{2}}{x}\right)}} \cdot t
\] |
unpow2 [=>]79.6% | \[ \frac{\sqrt{2}}{\sqrt{\frac{\ell \cdot \ell}{x} + \left(2 \cdot \left(\frac{t \cdot t}{x} + \color{blue}{t \cdot t}\right) - -1 \cdot \frac{{\ell}^{2} + 2 \cdot {t}^{2}}{x}\right)}} \cdot t
\] |
associate-*r/ [=>]79.6% | \[ \frac{\sqrt{2}}{\sqrt{\frac{\ell \cdot \ell}{x} + \left(2 \cdot \left(\frac{t \cdot t}{x} + t \cdot t\right) - \color{blue}{\frac{-1 \cdot \left({\ell}^{2} + 2 \cdot {t}^{2}\right)}{x}}\right)}} \cdot t
\] |
mul-1-neg [=>]79.6% | \[ \frac{\sqrt{2}}{\sqrt{\frac{\ell \cdot \ell}{x} + \left(2 \cdot \left(\frac{t \cdot t}{x} + t \cdot t\right) - \frac{\color{blue}{-\left({\ell}^{2} + 2 \cdot {t}^{2}\right)}}{x}\right)}} \cdot t
\] |
+-commutative [=>]79.6% | \[ \frac{\sqrt{2}}{\sqrt{\frac{\ell \cdot \ell}{x} + \left(2 \cdot \left(\frac{t \cdot t}{x} + t \cdot t\right) - \frac{-\color{blue}{\left(2 \cdot {t}^{2} + {\ell}^{2}\right)}}{x}\right)}} \cdot t
\] |
unpow2 [=>]79.6% | \[ \frac{\sqrt{2}}{\sqrt{\frac{\ell \cdot \ell}{x} + \left(2 \cdot \left(\frac{t \cdot t}{x} + t \cdot t\right) - \frac{-\left(2 \cdot \color{blue}{\left(t \cdot t\right)} + {\ell}^{2}\right)}{x}\right)}} \cdot t
\] |
associate-*l* [<=]79.6% | \[ \frac{\sqrt{2}}{\sqrt{\frac{\ell \cdot \ell}{x} + \left(2 \cdot \left(\frac{t \cdot t}{x} + t \cdot t\right) - \frac{-\left(\color{blue}{\left(2 \cdot t\right) \cdot t} + {\ell}^{2}\right)}{x}\right)}} \cdot t
\] |
unpow2 [=>]79.6% | \[ \frac{\sqrt{2}}{\sqrt{\frac{\ell \cdot \ell}{x} + \left(2 \cdot \left(\frac{t \cdot t}{x} + t \cdot t\right) - \frac{-\left(\left(2 \cdot t\right) \cdot t + \color{blue}{\ell \cdot \ell}\right)}{x}\right)}} \cdot t
\] |
fma-udef [<=]79.6% | \[ \frac{\sqrt{2}}{\sqrt{\frac{\ell \cdot \ell}{x} + \left(2 \cdot \left(\frac{t \cdot t}{x} + t \cdot t\right) - \frac{-\color{blue}{\mathsf{fma}\left(2 \cdot t, t, \ell \cdot \ell\right)}}{x}\right)}} \cdot t
\] |
if 7.7999999999999999e-215 < t < 3.1000000000000001e-164Initial program 2.8%
Simplified2.8%
[Start]2.8% | \[ \frac{\sqrt{2} \cdot t}{\sqrt{\frac{x + 1}{x - 1} \cdot \left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right) - \ell \cdot \ell}}
\] |
|---|---|
associate-*l/ [<=]2.8% | \[ \color{blue}{\frac{\sqrt{2}}{\sqrt{\frac{x + 1}{x - 1} \cdot \left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right) - \ell \cdot \ell}} \cdot t}
\] |
Taylor expanded in x around inf 66.0%
Simplified66.0%
[Start]66.0% | \[ \frac{\sqrt{2}}{0.5 \cdot \frac{\left({\ell}^{2} + 2 \cdot {t}^{2}\right) - -1 \cdot \left({\ell}^{2} + 2 \cdot {t}^{2}\right)}{\sqrt{2} \cdot \left(t \cdot x\right)} + \sqrt{2} \cdot t} \cdot t
\] |
|---|---|
fma-def [=>]66.0% | \[ \frac{\sqrt{2}}{\color{blue}{\mathsf{fma}\left(0.5, \frac{\left({\ell}^{2} + 2 \cdot {t}^{2}\right) - -1 \cdot \left({\ell}^{2} + 2 \cdot {t}^{2}\right)}{\sqrt{2} \cdot \left(t \cdot x\right)}, \sqrt{2} \cdot t\right)}} \cdot t
\] |
if 1.7999999999999999e85 < t Initial program 26.4%
Simplified26.4%
[Start]26.4% | \[ \frac{\sqrt{2} \cdot t}{\sqrt{\frac{x + 1}{x - 1} \cdot \left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right) - \ell \cdot \ell}}
\] |
|---|---|
associate-/l* [=>]26.4% | \[ \color{blue}{\frac{\sqrt{2}}{\frac{\sqrt{\frac{x + 1}{x - 1} \cdot \left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right) - \ell \cdot \ell}}{t}}}
\] |
fma-neg [=>]26.4% | \[ \frac{\sqrt{2}}{\frac{\sqrt{\color{blue}{\mathsf{fma}\left(\frac{x + 1}{x - 1}, \ell \cdot \ell + 2 \cdot \left(t \cdot t\right), -\ell \cdot \ell\right)}}}{t}}
\] |
remove-double-neg [<=]26.4% | \[ \frac{\sqrt{2}}{\frac{\sqrt{\mathsf{fma}\left(\frac{x + 1}{x - 1}, \color{blue}{-\left(-\left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right)\right)}, -\ell \cdot \ell\right)}}{t}}
\] |
fma-neg [<=]26.4% | \[ \frac{\sqrt{2}}{\frac{\sqrt{\color{blue}{\frac{x + 1}{x - 1} \cdot \left(-\left(-\left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right)\right)\right) - \ell \cdot \ell}}}{t}}
\] |
sub-neg [=>]26.4% | \[ \frac{\sqrt{2}}{\frac{\sqrt{\frac{x + 1}{\color{blue}{x + \left(-1\right)}} \cdot \left(-\left(-\left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right)\right)\right) - \ell \cdot \ell}}{t}}
\] |
metadata-eval [=>]26.4% | \[ \frac{\sqrt{2}}{\frac{\sqrt{\frac{x + 1}{x + \color{blue}{-1}} \cdot \left(-\left(-\left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right)\right)\right) - \ell \cdot \ell}}{t}}
\] |
remove-double-neg [=>]26.4% | \[ \frac{\sqrt{2}}{\frac{\sqrt{\frac{x + 1}{x + -1} \cdot \color{blue}{\left(\ell \cdot \ell + 2 \cdot \left(t \cdot t\right)\right)} - \ell \cdot \ell}}{t}}
\] |
fma-def [=>]26.4% | \[ \frac{\sqrt{2}}{\frac{\sqrt{\frac{x + 1}{x + -1} \cdot \color{blue}{\mathsf{fma}\left(\ell, \ell, 2 \cdot \left(t \cdot t\right)\right)} - \ell \cdot \ell}}{t}}
\] |
Taylor expanded in x around inf 96.7%
Final simplification87.1%
| Alternative 1 | |
|---|---|
| Accuracy | 82.5% |
| Cost | 40652 |
| Alternative 2 | |
|---|---|
| Accuracy | 82.0% |
| Cost | 21713 |
| Alternative 3 | |
|---|---|
| Accuracy | 75.7% |
| Cost | 20100 |
| Alternative 4 | |
|---|---|
| Accuracy | 56.6% |
| Cost | 13508 |
| Alternative 5 | |
|---|---|
| Accuracy | 37.6% |
| Cost | 12992 |
herbie shell --seed 2023272
(FPCore (x l t)
:name "Toniolo and Linder, Equation (7)"
:precision binary64
(/ (* (sqrt 2.0) t) (sqrt (- (* (/ (+ x 1.0) (- x 1.0)) (+ (* l l) (* 2.0 (* t t)))) (* l l)))))