{ "cells": [ { "cell_type": "markdown", "metadata": { "toc": "true" }, "source": [ "# Table of Contents\n", "
" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Julia Version 1.1.0\n", "Commit 80516ca202 (2019-01-21 21:24 UTC)\n", "Platform Info:\n", " OS: macOS (x86_64-apple-darwin14.5.0)\n", " CPU: Intel(R) Core(TM) i7-6920HQ CPU @ 2.90GHz\n", " WORD_SIZE: 64\n", " LIBM: libopenlibm\n", " LLVM: libLLVM-6.0.1 (ORCJIT, skylake)\n", "Environment:\n", " JULIA_EDITOR = code\n" ] } ], "source": [ "versioninfo()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Computer arithmetics" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Units of computer storage\n", "\n", "* `bit` = `binary` + `digit` (coined by statistician [John Tukey](https://en.wikipedia.org/wiki/Bit#History)). \n", "* `byte` = 8 bits. \n", "* KB = kilobyte = $10^3$ bytes. \n", "* MB = megabytes = $10^6$ bytes. \n", "* GB = gigabytes = $10^9$ bytes. Typical RAM size. \n", "* TB = terabytes = $10^{12}$ bytes. Typical hard drive size. Size of NYSE each trading session. \n", "* PB = petabytes = $10^{15}$ bytes. \n", "* EB = exabytes = $10^{18}$ bytes. Size of all healthcare data in 2011 is ~150 EB. \n", "* ZB = zetabytes = $10^{21}$ bytes. \n", "\n", "Julia function `Base.summarysize` shows the amount of memory (in bytes) used by an object." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "80040" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = rand(100, 100)\n", "Base.summarysize(x)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`varinfo()` function prints all variables in workspace and their sizes." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\begin{tabular}\n", "{l | r | l}\n", "name & size & summary \\\\\n", "\\hline\n", "Base & & Module \\\\\n", "Core & & Module \\\\\n", "Main & & Module \\\\\n", "x & 78.164 KiB & 100×100 Array\\{Float64,2\\} \\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "| name | size | summary |\n", "|:---- | ----------:|:------------------------ |\n", "| Base | | Module |\n", "| Core | | Module |\n", "| Main | | Module |\n", "| x | 78.164 KiB | 100×100 Array{Float64,2} |\n" ], "text/plain": [ "name size summary \n", "–––– –––––––––– ––––––––––––––––––––––––\n", "Base Module \n", "Core Module \n", "Main Module \n", "x 78.164 KiB 100×100 Array{Float64,2}" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "varinfo() # similar to Matlab whos()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Storage of Characters\n", "\n", "* Plain text files are stored in the form of characters: `.jl`, `.r`, `.c`, `.cpp`, `.ipynb`, `.html`, `.tex`, ... \n", "* ASCII (American Code for Information Interchange): 7 bits, only $2^7=128$ characters. " ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "128×2 Array{Any,2}:\n", " 0 '\\0' \n", " 1 '\\x01'\n", " 2 '\\x02'\n", " 3 '\\x03'\n", " 4 '\\x04'\n", " 5 '\\x05'\n", " 6 '\\x06'\n", " 7 '\\a' \n", " 8 '\\b' \n", " 9 '\\t' \n", " 10 '\\n' \n", " 11 '\\v' \n", " 12 '\\f' \n", " ⋮ \n", " 116 't' \n", " 117 'u' \n", " 118 'v' \n", " 119 'w' \n", " 120 'x' \n", " 121 'y' \n", " 122 'z' \n", " 123 '{' \n", " 124 '|' \n", " 125 '}' \n", " 126 '~' \n", " 127 '\\x7f'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# integers 0, 1, ..., 127 and corresponding ascii character\n", "[0:127 Char.(0:127)]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Extended ASCII: 8 bits, $2^8=256$ characters. " ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "128×2 Array{Any,2}:\n", " 128 '\\u80'\n", " 129 '\\u81'\n", " 130 '\\u82'\n", " 131 '\\u83'\n", " 132 '\\u84'\n", " 133 '\\u85'\n", " 134 '\\u86'\n", " 135 '\\u87'\n", " 136 '\\u88'\n", " 137 '\\u89'\n", " 138 '\\u8a'\n", " 139 '\\u8b'\n", " 140 '\\u8c'\n", " ⋮ \n", " 244 'ô' \n", " 245 'õ' \n", " 246 'ö' \n", " 247 '÷' \n", " 248 'ø' \n", " 249 'ù' \n", " 250 'ú' \n", " 251 'û' \n", " 252 'ü' \n", " 253 'ý' \n", " 254 'þ' \n", " 255 'ÿ' " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# integers 128, 129, ..., 255 and corresponding extended ascii character\n", "# show(STDOUT, \"text/plain\", [128:255 Char.(128:255)])\n", "[128:255 Char.(128:255)]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Unicode: UTF-8, UTF-16 and UTF-32 support many more characters including foreign characters; last 7 digits conform to ASCII. \n", "\n", "* [UTF-8](https://en.wikipedia.org/wiki/UTF-8) is the current dominant character encoding on internet. \n", "\n", "\n", "\n", "* Julia supports the full range of UTF-8 characters. You can type many Unicode math symbols by typing the backslashed LaTeX symbol name followed by tab. " ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# \\beta-