{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Error symmetry wave divisor function.\n", "\n", "The divisor function can be written as a summation of waves (see link below previous questions Stacks Exchange). The error in the wave divisor function is mainly determined by it's neighbor divisors. The error is proportional to:\n", "\n", "$$ \\varepsilon (x) \\propto \\sum_{\\mathbb{X}\\vert (x-1)}^{} \\cos(k \\mathbb{X}) + \\sum_{\\mathbb{X}\\vert (x+1)}^{} \\cos(k \\mathbb{X})$$\n", "\n", "Here $\\mathbb{X} \\vert (x-1)$ means: $\\mathbb{X}$ divides $(x-1)$. Basically the divisors are added from the neighbors of $x$:\n", "\n", "$$\\varepsilon (9) = \\cos(k1)+\\cos(k2)+\\cos(k4)+\\cos(k8)+\\cos(k1)+\\cos(k2)+\\cos(k5)+\\cos(k10)$$\n", "\n", "The total error then is a (cosine)summation of errors like Brownian motion. Where k is a constant and determines the pulse width of each divisor wave, see link below for more information.\n", "\n", "$$ k=-\\frac{2 \\log(L)}{\\pi \\Delta x^{2}}$$\n", "\n", "We can simulate the error for a number $x$ by keeping $L=0.5$ and vary $\\Delta x$ between: 0.15 and 0.2 in 10000 steps. For every $k$ the error can be calculated. See simulation below.\n", "\n", "It is observed that for $x=odd$ the error $\\varepsilon (x)$ tends to nonsymmetrical/skewed distribution. For $x=even$ the error $\\varepsilon (x)$ tends to a symmetrical distribution.\n", "\n", "Normally 1 is excluded as an divisor, but the symmetrical and skewed distribution are always present (with and without 1 as divisor).\n", "\n", "# Question:\n", "\n", "Why does the error for odd and even numbers $x$ tend to behave symmetric and asymmetric/skewed? \n", "\n", "# More information.\n", "\n", "More information: [Wave Divisor Function][1], [Question Stacks Exchange][2]\n", "\n", "[1]: https://mybinder.org/v2/gh/oooVincentooo/Shared/master?filepath=Wave%20Divisor%20Function%20rev%202.4.ipynb\n", "[2]: https://math.stackexchange.com/q/3427431" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import ipywidgets as widgets\n", "import matplotlib.pyplot as plt1\n", "import matplotlib.pyplot as plt2\n", "\n", "import numpy as np\n", "\n", "from IPython.display import display\n", "import ipywidgets as widgets\n", "\n", "from operator import add\n", "from operator import sub\n", "from operator import mul\n", "from operator import truediv\n", "\n", "from IPython.display import display" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "%matplotlib widget" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "ca0629b0925145ea9e34d688baa0a693", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "25964090705a4a70917c4162816ac04a", "version_major": 2, "version_minor": 0 }, "text/plain": [ "interactive(children=(Dropdown(description='$x$:', index=50, options=(500, 501, 502, 503, 504, 505, 506, 507, …" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig, ax1= plt1.subplots(1,2, figsize=(9, 4))\n", "\n", "from ipywidgets import IntProgress\n", "\n", "def update_plot(sx2):\n", " \n", " ax1[0].clear()\n", " ax1[1].clear()\n", " \n", " wave2=list(range(1,sx2+2))\n", " #print(wave)\n", " \n", " #dx range\n", " dxr2=np.linspace(0.1,0.2,10000)\n", " \n", " errt2=[0]*10000\n", " error2=[0]*10000\n", " #print(errt)\n", "\n", " #k range\n", " k=-2*np.log(0.5)/(np.pi*dxr2**2)\n", " #k=np.linspace(10,40,10000)\n", "\n", " f = IntProgress(min=0, max=sx2+2, description=\"\")\n", " display(f)\n", " \n", " #Total neighbor divisors counter\n", " nd=0\n", " \n", " for x2 in wave2:\n", " \n", " # #N range\n", " # N1=(np.log(0.5))/(np.log(np.cos(np.pi*dxr/x)))\n", " # #print(N1)\n", " # N1=2*np.round(0.5*N1,0) \n", " # #print(N1)\n", " f.value += 1\n", " \n", "\n", " if ((sx2-1)%x2)==0:\n", " error2=np.cos(k*x2)\n", " nd=nd+1\n", " #error=np.cos(np.pi*N1/x)\n", " #print(str((sx-1)) +': ' + str(x))\n", "\n", " else:\n", " error2=[0]*10000\n", "\n", " errt2=list(map(add, errt2, error2))\n", " \n", " if ((sx2+1)%x2)==0:\n", " error2=np.cos(k*x2)\n", " nd=nd+1\n", " #error=np.cos(np.pi*N1/x)\n", " #print(str((sx+1)) +': ' + str(x))\n", " \n", " else:\n", " error2=[0]*10000\n", " \n", " errt2=list(map(add, errt2, error2))\n", " \n", " print(\"Mean: \" + str(np.mean(errt2)))\n", " print(\"Var: \" + str(np.var(errt2)))\n", " print(\"Number of neighbor divisors of (x=\" + str(sx2) + \"): \" + str(nd))\n", " \n", " \n", " \n", " #Plot Error\n", " units3 = '$\\Delta x$ =0.1-0.20, \\n $n=10000$, \\n $L$ =0.5, \\n $x$ = {}'\n", " ax1[0].plot(k, errt2, color='#1f77b4', label=units3.format(sx2))\n", " ax1[0].legend(loc=2)\n", " ax1[0].set_title('Error')\n", " ax1[0].set_xlabel('$k$')\n", " ax1[0].set_ylabel('$\\epsilon(x)$')\n", " ax1[0].grid(b=True, which='major', color='#666666', linestyle='-')\n", " \n", " #Plot histogram error\n", " ax1[1].hist(errt2, density=True, bins=30, rwidth=1, edgecolor='white', linewidth=0.5, zorder=5)\n", " ax1[1].set_xlabel('$Bin$')\n", " ax1[1].set_ylabel('$Density$')\n", " ax1[1].set_title('Distribution')\n", " ax1[1].grid(b=True, which='major', color='#666666', linestyle='-', zorder=0)\n", "\n", " plt1.tight_layout()\n", " plt1.show()\n", " \n", " f.close()\n", "\n", "sx2 = widgets.Dropdown(options=list(range(500,1001)), description='$x$:',value=550) \n", "\n", "widgets.interactive(update_plot, sx2=sx2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Partial Answer Skew Error Distribution.\n", "\n", "This is the divisor counting of neighbors left and right of x. So sum of divisors at (x-1) and (x+1). \n", "\n", "**Assumption 1:**\n", "\n", "Divisors of odd numbers will always be odd:\n", "[Do odd numbers have only odd divisors?][1]\n", "\n", "**Case 1 (odd divisors only):**\n", "\n", "Function analysis show that the following function is symmetrical (positive and negative spikes occur).\n", "$$ \\varepsilon(k) = \\sum_{\\mathbb{X}=2}^{30} \\cos(k (2\\mathbb{X}-1))$$\n", "\n", "\n", "**Case 2 (even divisors only):**\n", "\n", "Function analysis show that the following function only has positive spikes.\n", "$$ \\varepsilon(k) = \\sum_{\\mathbb{X}=2}^{30} \\cos(k 2 \\mathbb{X})$$\n", "\n", "So for even divisors the distribution will look skewed asymmetrical. Even divisors have a mix of odd and even divisors.\n", "\n", "Thus the error in the wave divisor function $\\sigma_{0}(x)$: for even numbers $x$ is symmetric and the error for odd numbers $x$ is skewed.\n", "\n", "Though no proof is supplied for both formula above. Maybe the derivative (and determine max and min) supply the proof. \n", "\n", "[1]: https://math.stackexchange.com/q/1436656/650339\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "71d391fa51954f99bba5a8bc1ead8a12", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig, ax2= plt2.subplots(1,2, figsize=(9, 4))\n", "\n", "from ipywidgets import IntProgress\n", "\n", "wave2=list(range(2,30))\n", "#print(wave)\n", "\n", "#k range\n", "k=np.linspace(10,40,10000)\n", "\n", "yevent=[0]*10000\n", "yoddt=[0]*10000\n", "\n", "for x2 in wave2:\n", "\n", " #Even cos(kX)\n", " yeven=np.cos(k*(2*x2))\n", " yevent=list(map(add, yevent, yeven))\n", "\n", " #Odd cos(kX)\n", " yodd=np.cos(k*(2*x2-1))\n", " yoddt=list(map(add, yoddt, yodd))\n", "\n", "#Plot Error\n", "units4 = 'Even: 30 wave added'\n", "ax2[0].plot(k, yevent, color='#1f77b4', label=units4)\n", "ax2[0].legend(loc=2)\n", "ax2[0].set_title('Error Simulation Even Divisors')\n", "ax2[0].set_xlabel('$k$')\n", "ax2[0].set_ylabel('$\\epsilon(k)$')\n", "ax2[0].grid(b=True, which='major', color='#666666', linestyle='-')\n", "ax2[0].set(ylim=(-40, 40))\n", "\n", "#Plot Error\n", "units5 = 'Odd: 30 wave added'\n", "ax2[1].plot(k, yoddt, color='#1f77b4', label=units5)\n", "ax2[1].legend(loc=2)\n", "ax2[1].set_title('Error Simulation Odd Divisors')\n", "ax2[1].set_xlabel('$k$')\n", "ax2[1].set_ylabel('$\\epsilon(k)$')\n", "ax2[1].grid(b=True, which='major', color='#666666', linestyle='-') \n", "ax2[1].set(ylim=(-40, 40))\n", "\n", "plt2.tight_layout()\n", "plt2.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.3" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": { "17e822457f3e4126aa1549697809ae2b": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "25964090705a4a70917c4162816ac04a": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "VBoxModel", "state": { "_dom_classes": [ "widget-interact" ], "children": [ "IPY_MODEL_51e13f1824d84e798f180daae59a08ef", "IPY_MODEL_ed82ae5a969e45988c507a4cabdd62c2" ], "layout": "IPY_MODEL_bcb889d70ef24827b3b6b416ec0b89ec" } }, "28275a52cff24a63931deef9d01333b6": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "ProgressStyleModel", "state": { "description_width": "" } }, "51e13f1824d84e798f180daae59a08ef": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DropdownModel", "state": { "_options_labels": [ "500", "501", "502", "503", "504", "505", "506", "507", "508", "509", "510", "511", "512", "513", "514", "515", "516", "517", "518", "519", "520", "521", "522", "523", "524", "525", "526", "527", "528", "529", "530", "531", "532", "533", "534", "535", "536", "537", "538", "539", "540", "541", "542", "543", "544", "545", "546", "547", "548", "549", "550", "551", "552", "553", "554", "555", "556", "557", "558", "559", "560", "561", "562", "563", "564", "565", "566", "567", "568", "569", "570", "571", "572", "573", "574", "575", "576", "577", "578", "579", "580", "581", "582", "583", "584", "585", "586", "587", "588", "589", "590", "591", "592", "593", "594", "595", "596", "597", "598", "599", "600", "601", "602", "603", "604", "605", "606", "607", "608", "609", "610", "611", "612", "613", "614", "615", "616", "617", "618", "619", "620", "621", "622", "623", "624", "625", "626", "627", "628", "629", "630", "631", "632", "633", "634", "635", "636", "637", "638", "639", "640", "641", "642", "643", "644", "645", "646", "647", "648", "649", "650", "651", "652", "653", "654", "655", "656", "657", "658", "659", "660", "661", "662", "663", "664", "665", "666", "667", "668", "669", "670", "671", "672", "673", "674", "675", "676", "677", "678", "679", "680", "681", "682", "683", "684", "685", "686", "687", "688", "689", "690", "691", "692", "693", "694", "695", "696", "697", "698", "699", "700", "701", "702", "703", "704", "705", "706", "707", "708", "709", "710", "711", "712", "713", "714", "715", "716", "717", "718", "719", "720", "721", "722", "723", "724", "725", "726", "727", "728", "729", "730", "731", "732", "733", "734", "735", "736", "737", "738", "739", "740", "741", "742", "743", "744", "745", "746", "747", "748", "749", "750", "751", "752", "753", "754", "755", "756", "757", "758", "759", "760", "761", "762", "763", "764", "765", "766", "767", "768", "769", "770", "771", "772", "773", "774", "775", "776", "777", "778", "779", "780", "781", "782", "783", "784", "785", "786", "787", "788", "789", "790", "791", "792", "793", "794", "795", "796", "797", "798", "799", "800", "801", "802", "803", "804", "805", "806", "807", "808", "809", "810", "811", "812", "813", "814", "815", "816", "817", "818", "819", "820", "821", "822", "823", "824", "825", "826", "827", "828", "829", "830", "831", "832", "833", "834", "835", "836", "837", "838", "839", "840", "841", "842", "843", "844", "845", "846", "847", "848", "849", "850", "851", "852", "853", "854", "855", "856", "857", "858", "859", "860", "861", "862", "863", "864", "865", "866", "867", "868", "869", "870", "871", "872", "873", "874", "875", "876", "877", "878", "879", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889", "890", "891", "892", "893", "894", "895", "896", "897", "898", "899", "900", "901", "902", "903", "904", "905", "906", "907", "908", "909", "910", "911", "912", "913", "914", "915", "916", "917", "918", "919", "920", "921", "922", "923", "924", "925", "926", "927", "928", "929", "930", "931", "932", "933", "934", "935", "936", "937", "938", "939", "940", "941", "942", "943", "944", "945", "946", "947", "948", "949", "950", "951", "952", "953", "954", "955", "956", "957", "958", "959", "960", "961", "962", "963", "964", "965", "966", "967", "968", "969", "970", "971", "972", "973", "974", "975", "976", "977", "978", "979", "980", "981", "982", "983", "984", "985", "986", "987", "988", "989", "990", "991", "992", "993", "994", "995", "996", "997", "998", "999", "1000" ], "description": "$x$:", "index": 50, "layout": "IPY_MODEL_ddc6f64cf60f4328a9f5ab4f5991b8b8", "style": "IPY_MODEL_57cd6ae99bfb4e70a9ce17509d890eae" } }, "57cd6ae99bfb4e70a9ce17509d890eae": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "71d391fa51954f99bba5a8bc1ead8a12": { "model_module": "jupyter-matplotlib", "model_module_version": "^0.7.3", "model_name": "MPLCanvasModel", "state": { "_cursor": "default", "_figure_label": "Figure 2", "_height": 400, "_width": 900, "layout": "IPY_MODEL_ba7f803fc21940318b4e74dfed16cc78", "toolbar": "IPY_MODEL_c843c61cf0ef4fd48215e8c42722cbc4", "toolbar_position": "left" } }, "864768879d1e43d8b18bb5ead2118d76": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "8f5f32f11ef94adebe61c693e0522baf": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "a5db4a1c949c49fb83d23d9d233c5b00": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "ba7f803fc21940318b4e74dfed16cc78": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "bcb889d70ef24827b3b6b416ec0b89ec": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "c06344c34c9d44b4958a42ba18ad8aba": { "model_module": "jupyter-matplotlib", "model_module_version": "^0.7.3", "model_name": "ToolbarModel", "state": { "layout": "IPY_MODEL_17e822457f3e4126aa1549697809ae2b", "toolitems": [ [ "Home", "Reset original view", "home", "home" ], [ "Back", "Back to previous view", "arrow-left", "back" ], [ "Forward", "Forward to next view", "arrow-right", "forward" ], [ "Pan", "Pan axes with left mouse, zoom with right", "arrows", "pan" ], [ "Zoom", "Zoom to rectangle", "square-o", "zoom" ], [ "Download", "Download plot", "floppy-o", "save_figure" ] ] } }, "c843c61cf0ef4fd48215e8c42722cbc4": { "model_module": "jupyter-matplotlib", "model_module_version": "^0.7.3", "model_name": "ToolbarModel", "state": { "layout": "IPY_MODEL_a5db4a1c949c49fb83d23d9d233c5b00", "toolitems": [ [ "Home", "Reset original view", "home", "home" ], [ "Back", "Back to previous view", "arrow-left", "back" ], [ "Forward", "Forward to next view", "arrow-right", "forward" ], [ "Pan", "Pan axes with left mouse, zoom with right", "arrows", "pan" ], [ "Zoom", "Zoom to rectangle", "square-o", "zoom" ], [ "Download", "Download plot", "floppy-o", "save_figure" ] ] } }, "ca0629b0925145ea9e34d688baa0a693": { "model_module": "jupyter-matplotlib", "model_module_version": "^0.7.3", "model_name": "MPLCanvasModel", "state": { "_cursor": "default", "_figure_label": "Figure 1", "_height": 400, "_image_mode": "diff", "_message": "x=21.5452 y=10.0129 ", "_width": 900, "layout": "IPY_MODEL_864768879d1e43d8b18bb5ead2118d76", "toolbar": "IPY_MODEL_c06344c34c9d44b4958a42ba18ad8aba", "toolbar_position": "left" } }, "cb726737abce4b2ea1c065ed14a283e0": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "ddc6f64cf60f4328a9f5ab4f5991b8b8": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "ed82ae5a969e45988c507a4cabdd62c2": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "layout": "IPY_MODEL_cb726737abce4b2ea1c065ed14a283e0", "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": "IntProgress(value=0, max=552)" }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": "Mean: 0.15848461577451534\nVar: 5.984970799733128\nNumber of neighbor divisors of (x=550): 10\n" } ] } } }, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }