sample-dynamic-3f.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Dynamic Preview of Textarea with MathJax Content</title>
  5. <!-- Copyright (c) 2012-2018 The MathJax Consortium -->
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  8. <style>
  9. .changed { color: red }
  10. </style>
  11. <script type="text/x-mathjax-config">
  12. MathJax.Hub.Config({
  13. TeX: {
  14. equationNumbers: {autoNumber: "AMS"},
  15. extensions: ["begingroup.js"],
  16. noErrors: {disabled: true}
  17. },
  18. showProcessingMessages: false,
  19. tex2jax: { inlineMath: [['$','$'],['\\(','\\)']] }
  20. });
  21. //MathJax.Hub.signal.Interest(function (message) {console.log(message)});
  22. </script>
  23. <script type="text/javascript" src="../MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
  24. <script>
  25. var Preview = {
  26. typeset: null, // the typeset preview area (filled in by Init below)
  27. preview: null, // the untypeset preview (filled in by Init below)
  28. buffer: null, // the new preview to be typeset (filled in by Init below)
  29. par: [], // paragraph-specific data
  30. refs: [], // undefined references needing to be reprocessed
  31. updateNeeded: 0, // number of paragraphs needing update
  32. oldtext: '', // used to see if an update is needed
  33. pending: false, // true when a restart is in the MathJax queue
  34. classDelay: 400, // how long to leave changed paragraphs colored
  35. ctimeout: null, // timeout for changed style remover
  36. labelDelay: 1250, // how long to wait before reprocessing for label changes
  37. ltimeout: null, // timeout for changed labels
  38. keytimes: [], // tracks the times between keypresses
  39. keyrate: 100, // the average of the keytimes (default value)
  40. keyn: 0, // key index to replace next
  41. keysize: 10, // use this many keypresses
  42. //
  43. // Get the preview and buffer DIV's
  44. //
  45. Init: function () {
  46. this.typeset = document.getElementById("MathPreview");
  47. this.buffer = document.createElement("div");
  48. this.preview = document.createElement("div");
  49. for (var i = 0; i < this.keysize; i++) {this.keytimes[i] = this.keyrate}
  50. },
  51. //
  52. // This gets called when a key is pressed in the textarea.
  53. //
  54. Update: function (up) {
  55. if (up) {
  56. //
  57. // Determine the typing speed as a rolling average of the last few keystrokes
  58. //
  59. var time = new Date().getTime();
  60. if (this.lasttime) {
  61. var delta = time - this.lasttime;
  62. if (delta < 4*this.keyrate) {
  63. this.keyrate = (this.keysize*this.keyrate+delta-this.keytimes[this.keyn])/this.keysize;
  64. this.keytimes[this.keyn++] = delta;
  65. if (this.keyn === this.keysize) {this.keyn = 0}
  66. }
  67. }
  68. this.lasttime = time;
  69. }
  70. var text = document.getElementById("MathInput").value;
  71. text = text.replace(/^\s+/,'').replace(/\s+$/,'').replace(/\r\n?/g,"\n");
  72. if (text !== this.oldtext) {
  73. this.oldtext = text;
  74. if (!this.pending) {
  75. this.pending = true;
  76. if (this.ctimeout) {clearTimeout(this.ctimeout); this.ctimeout = null}
  77. if (this.ltimeout) {clearTimeout(this.ltimeout); this.ltimeout = null}
  78. MathJax.Hub.Queue(
  79. // allow a little time for additional typing
  80. ["Delay",MathJax.Callback,Math.min(200,Math.floor(this.keyrate/2)+1)],
  81. ["Restart",this]
  82. );
  83. }
  84. }
  85. },
  86. Restart: function () {
  87. this.pending = false;
  88. var text = this.oldtext.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
  89. var text = text.replace(/\n\n+/g,"<p>");
  90. this.buffer.innerHTML = text;
  91. var update = this.CompareBuffers();
  92. if (update.needed) {
  93. MathJax.Hub.Queue(
  94. ["CopyChanges",this,update],
  95. ["PreTypeset",this,update],
  96. ["Typeset",this,update],
  97. ["PostTypeset",this,update]
  98. );
  99. }
  100. },
  101. CompareBuffers: function () {
  102. var b1 = this.buffer.childNodes,
  103. b2 = this.preview.childNodes,
  104. i, m1 = b1.length, m2 = b2.length, m = Math.min(m1,m2);
  105. //
  106. // Make sure all top-level elements are containers
  107. //
  108. for (i = 0; i < m1; i++) {
  109. var node = b1[i];
  110. if (typeof(node.innerHTML) === "undefined") {
  111. this.buffer.replaceChild(document.createElement("span"),node);
  112. b1[i].appendChild(node);
  113. }
  114. }
  115. //
  116. // Find first non-matching element, if any,
  117. // and the last non-matching element
  118. //
  119. for (i = 0; i < m; i++) {if (b1[i].innerHTML !== b2[i].innerHTML) break}
  120. if (i === m && m1 === m2) {return {needed: false}}
  121. while (m1 > i && m2 > i) {if (b1[--m1].innerHTML !== b2[--m2].innerHTML) break}
  122. return {needed:true, start:i, end1:m1, end2:m2};
  123. },
  124. CopyChanges: function (update) {
  125. var i = update.start, m1 = update.end1, m2 = update.end2;
  126. var b1 = this.buffer.childNodes,
  127. b2 = this.typeset.childNodes;
  128. update.indices = []; update.nodes = []; update.replace = true;
  129. //
  130. // Remove differing elements from typeset copy
  131. // and add in the new (untypeset) elements.
  132. //
  133. this.recordOldData(this.par.splice(i,m2+1-i)); var tail = b2[m2+1];
  134. while (m2 >= i && b2[i]) {this.typeset.removeChild(b2[i]); m2--}
  135. while (i <= m1 && b1[i]) {
  136. this.par.splice(i,0,{number:0, labels:[], defs:[], refs:[], replaced:true, update:true});
  137. var node = b1[i].cloneNode(true); update.nodes.push(node);
  138. update.indices.push(i++); this.updateNeeded++;
  139. if (tail) {this.typeset.insertBefore(node,tail)} else {this.typeset.appendChild(node)}
  140. this.addChanged(node);
  141. }
  142. //
  143. // Swap buffers and set up the new buffer for the next change
  144. //
  145. this.preview = this.buffer; this.buffer = document.createElement("div");
  146. },
  147. PreTypeset: function (update) {
  148. var TEX = MathJax.InputJax.TeX;
  149. this.incremental = true;
  150. this.i = this.j = 0; this.eqNum = 0;
  151. this.update = update.indices;
  152. this.replace = update.replace;
  153. //
  154. // Pop any left over \begingroups and push a new one
  155. // Reset the equation numbers (but not labels)
  156. //
  157. while (TEX.rootStack.top > 1) {TEX.rootStack.stack.pop(); TEX.rootStack.top--}
  158. TEX.rootStack.Push(TEX.nsStack.nsFrame());
  159. },
  160. recordOldData: function (par) {
  161. var AMS = MathJax.Extension["TeX/AMSmath"];
  162. var labels = [], defs = [];
  163. this.oldnumber = 0;
  164. for (var i = 0, m = par.length; i < m; i++) {
  165. this.oldnumber += par[i].number;
  166. defs.push(par[i].defs.all);
  167. for (var j = 0, n = par[i].labels.length; j < n; j++) {
  168. delete AMS.labels[par[i].labels[j].split(/=/)[0]];
  169. labels.push(par[i].labels[j]);
  170. }
  171. }
  172. this.oldlabels = labels.join('');
  173. this.olddefs = defs.join('');
  174. },
  175. Typeset: function (update) {
  176. return MathJax.Hub.Typeset(update.nodes,{});
  177. },
  178. BeginMath: function () {
  179. //
  180. // Save the start time for this paragraph
  181. //
  182. this.time = new Date().getTime();
  183. },
  184. BeginInput: function () {
  185. //
  186. // Skip any paragraphs that aren't being updated, and
  187. // update the equation numbers and macro definitions
  188. // accordingly
  189. //
  190. var TEX = MathJax.InputJax.TeX, par;
  191. while (this.i < this.update[this.j]) {
  192. par = this.par[this.i++];
  193. this.eqNum += par.number;
  194. for (i = 0, m = par.defs.length; i < m; i++) {
  195. TEX.rootStack.Def.apply(TEX.rootStack,par.defs[i]);
  196. }
  197. }
  198. TEX.resetEquationNumbers(this.eqNum,true);
  199. //
  200. // Store new macro and label definitions here
  201. //
  202. par = this.par[this.i];
  203. if (par) {
  204. if (!par.replaced) {par.olddefs = par.defs.all; par.oldlabels = par.labels.join('')}
  205. par.defs = []; par.defs.all = [];
  206. par.labels = [];
  207. }
  208. },
  209. TeXFilter: function (data) {
  210. //
  211. // Get any new labels for this paragraph
  212. //
  213. var AMS = MathJax.Extension["TeX/AMSmath"];
  214. var labels = this.par[this.i].labels;
  215. for (var id in AMS.eqlabels) {if (AMS.eqlabels.hasOwnProperty(id)) {
  216. labels.push(id+"="+AMS.eqlabels[id])
  217. }}
  218. },
  219. TeXDef: function (def) {
  220. var defs = this.par[this.i].defs;
  221. defs.push(def);
  222. defs.all.push(def[0]+"{"+def[1]+"}");
  223. },
  224. EndInput: function () {
  225. //
  226. // Record the undefined references,
  227. // the new definitions, and the equation number
  228. // for this paragraph
  229. //
  230. var AMS = MathJax.Extension["TeX/AMSmath"];
  231. var par = this.par[this.i];
  232. if (par) {
  233. par.refs = AMS.refs; AMS.refs = [];
  234. par.defs.all = par.defs.all.join("");
  235. par.number = AMS.startNumber - this.eqNum;
  236. this.eqNum = AMS.startNumber;
  237. if (!par.replaced) {
  238. delete par.update;
  239. if (par.defs.all !== par.olddefs) {this.refreshRest = true}
  240. if (par.labels.join('') !== par.oldlabels) {
  241. // ### cancel typesetting and do all paragraphs
  242. this.refreshAll = true;
  243. }
  244. delete par.olddefs; delete par.oldlabels;
  245. }
  246. }
  247. },
  248. EndMath: function () {
  249. //
  250. // Record the tie it took for this paragraph
  251. // and go on to the next one.
  252. //
  253. var par = (this.par[this.i]||{});
  254. var time = new Date().getTime();
  255. par.time = time - this.time; this.time = time;
  256. delete par.update; this.updateNeeded--;
  257. this.j++; this.i++;
  258. },
  259. PostTypeset: function (update) {
  260. var incremental = this.incremental; this.incremental = false;
  261. // ### if cancelled return?
  262. //
  263. // Check if there are undefined references that might have been
  264. // defined in this update, and reprocess if so.
  265. //
  266. for (var i = 0, m = this.update.length; i < m; i++) {
  267. var par = this.par[this.update[i]];
  268. if (par.refs.length) {this.refs = this.refs.concat(par.refs); par.refs = []}
  269. }
  270. if (incremental && this.refs.length) {
  271. var queue = MathJax.Callback.Queue(
  272. ["Reprocess",MathJax.Hub,this.refs,{}],
  273. function () {/* if not cancelled */ this.refs = []}
  274. );
  275. return queue.Push(["PostTypeset",this,update]);
  276. }
  277. //
  278. // Set the timer for the color removal
  279. //
  280. this.ctimeout = setTimeout(this.Unmark,this.classDelay);
  281. //
  282. //
  283. var labels = [], defs = [], number = 0;
  284. if (this.replace) {
  285. for (i = 0, m = this.update.length; i < m; i++) {
  286. var par = this.par[this.update[i]];
  287. if (par.replaced) {
  288. labels = labels.concat(par.labels.join(''));
  289. defs = defs.concat(par.defs.all);
  290. number += par.number;
  291. delete par.replaced;
  292. }
  293. }
  294. this.loopCount = 0; // avoid any possibility of infinite loop
  295. // (shouldn't happen anyway, but I'm paranoid)
  296. }
  297. if (update.nodes.length !== this.preview.childNodes.length) {
  298. if (this.refreshAll || labels.join('') !== this.oldlabels) {
  299. this.MarkForUpdate(0); this.refreshAll = this.refreshRest = false;
  300. } else if (this.refreshRest || number !== this.oldnumber || defs.join('') !== this.olddefs) {
  301. this.MarkForUpdate(this.i); this.refreshRest = false;
  302. }
  303. if (this.updateNeeded && this.loopCount++ < 10) {
  304. var delay = Math.min(this.labelDelay,3*this.keyRate);
  305. if (this.getTime() < 2*this.keyrate) {this.Refresh()}
  306. else {this.ltimeout = setTimeout(this.Refresh,delay)}
  307. }
  308. }
  309. },
  310. MarkForUpdate: function (i) {
  311. for (var m = this.par.length; i < m; i++) {
  312. if (!this.par[i].update) {this.par[i].update = true; this.updateNeeded++}
  313. }
  314. },
  315. GetMarked: function () {
  316. var AMS = MathJax.Extension["TeX/AMSmath"];
  317. var nodes = [], indices = [], par = this.par;
  318. for (var i = 0, m = par.length; i < m; i++) {
  319. if (par[i].update) {
  320. var node = this.typeset.childNodes[i];
  321. nodes.push(node); indices.push(i);
  322. this.addChanged(node);
  323. for (var j = 0, n = par[i].labels.length; j < n; j++) {
  324. delete AMS.labels[par[i].labels[j].split(/=/)[0]];
  325. }
  326. }
  327. }
  328. return {nodes:nodes, indices:indices};
  329. },
  330. Unmark: function () {
  331. Preview.ctimeout = null; var nodes = Preview.typeset.childNodes;
  332. for (var i = 0, m = nodes.length; i < m; i++) {Preview.removeChanged(nodes[i])}
  333. },
  334. Refresh: function () {
  335. var update = Preview.GetMarked();
  336. this.oldlabels = this.olddefs = ""; this.oldnumber = 0;
  337. if (update.nodes.length) {
  338. MathJax.Hub.Queue(
  339. ["PreTypeset",Preview,update],
  340. ["Reprocess",MathJax.Hub,update.nodes,{}],
  341. ["PostTypeset",Preview,update]
  342. );
  343. }
  344. },
  345. getTime: function () {
  346. var time = 0, i = 0, m = this.par.length;
  347. while (i < m) {if (this.par[i].update) {time += this.par[i].time}; i++}
  348. return time;
  349. },
  350. //
  351. // Remove the "changed" class from an element (leaving all other classes)
  352. //
  353. removeChanged: function (node) {
  354. if (node.className) {
  355. node.className = node.className.toString()
  356. .replace(/(^|\s+)changed(\s|$)/,"$2")
  357. .replace(/^\s+/,"");
  358. }
  359. },
  360. addChanged: function (node) {
  361. if (node.className && node.className != "")
  362. {node.className += " changed"} else {node.className = "changed"}
  363. }
  364. };
  365. //
  366. // Hook into the math signals
  367. //
  368. MathJax.Hub.Register.MessageHook("Begin Math",function () {
  369. if (Preview.incremental) {Preview.BeginMath()}
  370. });
  371. MathJax.Hub.Register.MessageHook("End Math",function () {
  372. if (Preview.incremental) {Preview.EndMath()}
  373. });
  374. MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
  375. MathJax.InputJax.TeX.postfilterHooks.Add(function (data) {
  376. if (Preview.incremental) {Preview.TeXFilter(data)}
  377. });
  378. });
  379. MathJax.Hub.Register.MessageHook("Begin Math Input",function () {
  380. if (Preview.incremental) {Preview.BeginInput()}
  381. });
  382. MathJax.Hub.Register.MessageHook("End Math Input",function () {
  383. if (Preview.incremental) {Preview.EndInput()}
  384. },5); // priority = 5 to make sure it is before AMS.eqlabels are removed.
  385. //
  386. // Hook into the definition routines to record
  387. // new definitions that occur.
  388. //
  389. MathJax.Hub.Register.StartupHook("TeX begingroup Ready",function () {
  390. var STACK = MathJax.InputJax.TeX.eqnStack;
  391. var DEF = STACK.Def;
  392. STACK.Def = function () {
  393. if (Preview.incremental) {Preview.TeXDef([].slice.call(arguments,0))}
  394. DEF.apply(this,arguments);
  395. }
  396. //
  397. // Temporary hack to fix typo in begingroup.js
  398. //
  399. MathJax.InputJax.TeX.rootStack.stack[0].environments =
  400. MathJax.InputJax.TeX.Definitions.environment;
  401. });
  402. </script>
  403. </head>
  404. <body>
  405. Type text with embedded TeX in the box below:<br/>
  406. <textarea id="MathInput" cols="60" rows="10" onkeyup="Preview.Update(true)" onkeydown="Preview.Update()" style="margin-top:5px">
  407. There must be some missing constraints. If $\alpha_n$ is allowed to be negative, we get the following counterexample. $\smash{\rlap{\phantom{\Bigg(}}}$
  408. Define
  409. $$
  410. u_{n+1}=(1-\alpha_n)u_n+\beta_n\tag{1}
  411. $$
  412. and
  413. $$
  414. A_n=\prod_{k=1}^{n-1}(1-\alpha_k)\tag{2}
  415. $$
  416. By induction, it can be verified that
  417. $$
  418. u_n=A_n\left(u_1+\sum_{k=1}^{n-1}\frac{\beta_k}{A_{k+1}}\right)\tag{3}
  419. $$
  420. For $j\ge1$, define
  421. $$
  422. n_j=\left\{\begin{array}{}
  423. 2^{j(j-1)/2}&\text{when }j\text{ is odd}\\
  424. 2^{j(j-1)/2+1}&\text{when }j\text{ is even}
  425. \end{array}\right.\tag{4}
  426. $$
  427. and for $n\ge1$,
  428. $$
  429. \alpha_n=\left\{\begin{array}{}
  430. \frac{1}{n+1}&\text{for }n_j\le n< n_{j+1}\text{ when }j\text{ is odd}\\
  431. -\frac1n&\text{for }n_j\le n< n_{j+1}\text{ when }j\text{ is even}
  432. \end{array}\right.\tag{5}
  433. $$
  434. Obviously, $\displaystyle\lim_{n\to\infty}\alpha_n=0$.
  435. Using telescoping products, it is not difficult to show that
  436. $$
  437. \frac{A_{n_{j+1}}}{A_{n_j}}=\left\{\begin{array}{}
  438. \frac{n_j}{n_{j+1}}=2^{-j-1}&\text{when }j\text{ is odd}\\
  439. \frac{n_{j+1}}{n_j}=2^{j-1}&\text{when }j\text{ is even}
  440. \end{array}\right.\tag{6}
  441. $$
  442. Equation $(6)$ yields
  443. $$
  444. A_{n_j}=\left\{\begin{array}{}
  445. 2^{-(j-1)/2}&\text{when }j\text{ is odd}\\
  446. 2^{-(3j-2)/2}&\text{when }j\text{ is even}
  447. \end{array}\right.\tag{7}
  448. $$
  449. Furthermore, using the standard formula for the partial harmonic series, when $j$ is odd,
  450. $$
  451. \begin{align}
  452. \sum_{n=n_j}^{n_{j+1}-1}\alpha_n
  453. &=\log\left(\frac{n_{j+1}}{n_j}\right)+O\left(\frac{1}{n_j}\right)\\
  454. &=(j+1)\log(2)+O\left(2^{-j(j-1)/2}\right)\tag{8}
  455. \end{align}
  456. $$
  457. and when $j$ is even,
  458. $$
  459. \begin{align}
  460. \sum_{n=n_j}^{n_{j+1}-1}\alpha_n
  461. &=-\log\left(\frac{n_{j+1}}{n_j}\right)+O\left(\frac{1}{n_j}\right)\\
  462. &=-(j-1)\log(2)+O\left(2^{-j(j-1)/2}\right)\tag{9}
  463. \end{align}
  464. $$
  465. Combining $(8)$ and $(9)$ yields
  466. $$
  467. \sum_{n=1}^{n_j-1}\alpha_n=\left\{\begin{array}{}
  468. \frac{j-1}{2}\log(2)+O(1)&\text{when }j\text{ is odd}\\
  469. \frac{3j-2}{2}\log(2)+O(1)&\text{when }j\text{ is even}
  470. \end{array}\right.\tag{10}
  471. $$
  472. Equation $(10)$ says that $\displaystyle\sum_{n=1}^\infty\alpha_n=\infty$.
  473. Define
  474. $$
  475. \beta_n=\left\{\begin{array}{}
  476. 2^{-j}&\text{when }n=n_j-1\text{ for }j\text{ even}\\
  477. 0&\text{otherwise}
  478. \end{array}\right.\tag{11}
  479. $$
  480. Summing the geometric series yields $\displaystyle\sum_{n=1}^\infty\beta_n=\frac13$.
  481. Using $(3)$, we get
  482. $$
  483. \begin{align}
  484. u_{n_{j+1}}
  485. &=A_{n_{j+1}}\left(u_1+\sum_{k=1}^{n_{j+1}-1}\frac{\beta_k}{A_{k+1}}\right)\\
  486. &\ge\frac{A_{n_{j+1}}}{A_{n_j}}\beta_{n_j-1}\\
  487. &=2^{j-1}\cdot2^{-j}\\
  488. &=\frac12\tag{12}
  489. \end{align}
  490. $$
  491. when $j$ is even. $(12)$ says that $\displaystyle\lim_{n\to\infty}u_n\not=0$.
  492. </textarea>
  493. <br/><br/>
  494. <div id="MoreMath"></div>
  495. Preview is shown here:
  496. <div id="MathPreview" style="border:1px solid; padding: 3px; width:50%; margin-top:5px"></div>
  497. <div style="display:none">Force loading: $x$</div>
  498. <script>
  499. Preview.Init();
  500. MathJax.Hub.Queue(["Update",Preview]);
  501. </script>
  502. </body>
  503. </html>
  504. <!--
  505. | There must be some missing constraints. If $\alpha_n$ is allowed to be negative, we get the following counterexample. $\smash{\rlap{\phantom{\Bigg(}}}$
  506. |
  507. | Define
  508. | $$
  509. | u_{n+1}=(1-\alpha_n)u_n+\beta_n\tag{1}
  510. | $$
  511. | and
  512. | $$
  513. | A_n=\prod_{k=1}^{n-1}(1-\alpha_k)\tag{2}
  514. | $$
  515. | By induction, it can be verified that
  516. | $$
  517. | u_n=A_n\left(u_1+\sum_{k=1}^{n-1}\frac{\beta_k}{A_{k+1}}\right)\tag{3}
  518. | $$
  519. | For $j\ge1$, define
  520. | $$
  521. | n_j=\left\{\begin{array}{}
  522. | 2^{j(j-1)/2}&\text{when }j\text{ is odd}\\
  523. | 2^{j(j-1)/2+1}&\text{when }j\text{ is even}
  524. | \end{array}\right.\tag{4}
  525. | $$
  526. | and for $n\ge1$,
  527. | $$
  528. | \alpha_n=\left\{\begin{array}{}
  529. | \frac{1}{n+1}&\text{for }n_j\le n< n_{j+1}\text{ when }j\text{ is odd}\\
  530. | -\frac1n&\text{for }n_j\le n< n_{j+1}\text{ when }j\text{ is even}
  531. | \end{array}\right.\tag{5}
  532. | $$
  533. | Obviously, $\displaystyle\lim_{n\to\infty}\alpha_n=0$.
  534. |
  535. | Using telescoping products, it is not difficult to show that
  536. | $$
  537. | \frac{A_{n_{j+1}}}{A_{n_j}}=\left\{\begin{array}{}
  538. | \frac{n_j}{n_{j+1}}=2^{-j-1}&\text{when }j\text{ is odd}\\
  539. | \frac{n_{j+1}}{n_j}=2^{j-1}&\text{when }j\text{ is even}
  540. | \end{array}\right.\tag{6}
  541. | $$
  542. | Equation $(6)$ yields
  543. | $$
  544. | A_{n_j}=\left\{\begin{array}{}
  545. | 2^{-(j-1)/2}&\text{when }j\text{ is odd}\\
  546. | 2^{-(3j-2)/2}&\text{when }j\text{ is even}
  547. | \end{array}\right.\tag{7}
  548. | $$
  549. | Furthermore, using the standard formula for the partial harmonic series, when $j$ is odd,
  550. | $$
  551. | \begin{align}
  552. | \sum_{n=n_j}^{n_{j+1}-1}\alpha_n
  553. | &=\log\left(\frac{n_{j+1}}{n_j}\right)+O\left(\frac{1}{n_j}\right)\\
  554. | &=(j+1)\log(2)+O\left(2^{-j(j-1)/2}\right)\tag{8}
  555. | \end{align}
  556. | $$
  557. | and when $j$ is even,
  558. | $$
  559. | \begin{align}
  560. | \sum_{n=n_j}^{n_{j+1}-1}\alpha_n
  561. | &=-\log\left(\frac{n_{j+1}}{n_j}\right)+O\left(\frac{1}{n_j}\right)\\
  562. | &=-(j-1)\log(2)+O\left(2^{-j(j-1)/2}\right)\tag{9}
  563. | \end{align}
  564. | $$
  565. | Combining $(8)$ and $(9)$ yields
  566. | $$
  567. | \sum_{n=1}^{n_j-1}\alpha_n=\left\{\begin{array}{}
  568. | \frac{j-1}{2}\log(2)+O(1)&\text{when }j\text{ is odd}\\
  569. | \frac{3j-2}{2}\log(2)+O(1)&\text{when }j\text{ is even}
  570. | \end{array}\right.\tag{10}
  571. | $$
  572. | Equation $(10)$ says that $\displaystyle\sum_{n=1}^\infty\alpha_n=\infty$.
  573. |
  574. | Define
  575. | $$
  576. | \beta_n=\left\{\begin{array}{}
  577. | 2^{-j}&\text{when }n=n_j-1\text{ for }j\text{ even}\\
  578. | 0&\text{otherwise}
  579. | \end{array}\right.\tag{11}
  580. | $$
  581. | Summing the geometric series yields $\displaystyle\sum_{n=1}^\infty\beta_n=\frac13$.
  582. |
  583. | Using $(3)$, we get
  584. | $$
  585. | \begin{align}
  586. | u_{n_{j+1}}
  587. | &=A_{n_{j+1}}\left(u_1+\sum_{k=1}^{n_{j+1}-1}\frac{\beta_k}{A_{k+1}}\right)\\
  588. | &\ge\frac{A_{n_{j+1}}}{A_{n_j}}\beta_{n_j-1}\\
  589. | &=2^{j-1}\cdot2^{-j}\\
  590. | &=\frac12\tag{12}
  591. | \end{align}
  592. | $$
  593. | when $j$ is even. $(12)$ says that $\displaystyle\lim_{n\to\infty}u_n\not=0$.
  594. -->