# Concrete Math with Python III

### Python带你游览具体世界的数学基础

"我们知道这些知识到底有什么用处？"

• 数列与金融基础
• 排列组合与概率基础
• 方程组/矩阵
• 线性规划
• 质数与加密
• 随机数与概率分布

### 注意：具备扎实的高中数学、理工科本科数学基础的朋友可以简单阅览或者跳过这一部分。

``````

In [1]:

import itertools as itt
import numpy as np
import numpy.random as nprnd
import scipy.stats as spstat
import scipy.special as ssp
import pandas as pd
import bokeh
import bokeh.plotting as bplt
import bokeh.palettes as bpal

``````
``````

In [2]:

# 工具配置
TOOLS = "pan,wheel_zoom,box_zoom,box_select"
# 作图配置
plot_config = dict(plot_width=800, plot_height=500, tools=TOOLS)
bplt.output_notebook()

``````
``````

/* BEGIN /Users/wangweiyang/anaconda/anaconda/lib/python2.7/site-packages/bokeh/server/static/css/bokeh.min.css */
* jQuery UI CSS Framework 1.11.2
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
*
* http://api.jqueryui.com/category/theming/
* jQuery UI Accordion 1.11.2
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
*
* http://api.jqueryui.com/accordion/#theming
* jQuery UI Autocomplete 1.11.2
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
*
* http://api.jqueryui.com/autocomplete/#theming
*/.bk-ui-autocomplete{position:absolute;top:0;left:0;cursor:default}/*!
* jQuery UI Button 1.11.2
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
*
* http://api.jqueryui.com/button/#theming
* jQuery UI Datepicker 1.11.2
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
*
* http://api.jqueryui.com/datepicker/#theming
* jQuery UI Dialog 1.11.2
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
*
* http://api.jqueryui.com/dialog/#theming
*/.bk-ui-dialog{overflow:hidden;position:absolute;top:0;left:0;padding:.2em;outline:0}.bk-ui-dialog .bk-ui-dialog-titlebar{padding:.4em 1em;position:relative}.bk-ui-dialog .bk-ui-dialog-title{float:left;margin:.1em 0;white-space:nowrap;width:90%;overflow:hidden;text-overflow:ellipsis}.bk-ui-dialog .bk-ui-dialog-titlebar-close{position:absolute;right:.3em;top:50%;width:20px;margin:-10px 0 0 0;padding:1px;height:20px}.bk-ui-dialog .bk-ui-dialog-content{position:relative;border:0;padding:.5em 1em;background:0 0;overflow:auto}.bk-ui-dialog .bk-ui-dialog-buttonpane{text-align:left;border-width:1px 0 0 0;background-image:none;margin-top:.5em;padding:.3em 1em .5em .4em}.bk-ui-dialog .bk-ui-dialog-buttonpane .bk-ui-dialog-buttonset{float:right}.bk-ui-dialog .bk-ui-dialog-buttonpane button{margin:.5em .4em .5em 0;cursor:pointer}.bk-ui-dialog .bk-ui-resizable-se{width:12px;height:12px;right:-5px;bottom:-5px;background-position:16px 16px}.bk-ui-draggable .bk-ui-dialog-titlebar{cursor:move}/*!
* jQuery UI Draggable 1.11.2
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
*//*!
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
*
* jQuery UI Progressbar 1.11.2
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
*
* http://api.jqueryui.com/progressbar/#theming
* jQuery UI Resizable 1.11.2
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
*/.bk-ui-resizable{position:relative}.bk-ui-resizable-handle{position:absolute;font-size:.1px;display:block}.bk-ui-resizable-autohide .bk-ui-resizable-handle,.bk-ui-resizable-disabled .bk-ui-resizable-handle{display:none}.bk-ui-resizable-n{cursor:n-resize;height:7px;width:100%;top:-5px;left:0}.bk-ui-resizable-s{cursor:s-resize;height:7px;width:100%;bottom:-5px;left:0}.bk-ui-resizable-e{cursor:e-resize;width:7px;right:-5px;top:0;height:100%}.bk-ui-resizable-w{cursor:w-resize;width:7px;left:-5px;top:0;height:100%}.bk-ui-resizable-se{cursor:se-resize;width:12px;height:12px;right:1px;bottom:1px}.bk-ui-resizable-sw{cursor:sw-resize;width:9px;height:9px;left:-5px;bottom:-5px}.bk-ui-slider-vertical .bk-ui-slider-range-min,.bk-ui-spinner-down{bottom:0}.bk-ui-resizable-nw{cursor:nw-resize;width:9px;height:9px;left:-5px;top:-5px}.bk-ui-resizable-ne{cursor:ne-resize;width:9px;height:9px;right:-5px;top:-5px}/*!
* jQuery UI Selectable 1.11.2
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
*/.bk-ui-selectable{-ms-touch-action:none;touch-action:none}.bk-ui-selectable-helper{position:absolute;z-index:100;border:1px dotted #000}/*!
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
*
* jQuery UI Sortable 1.11.2
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
*//*!
* jQuery UI Slider 1.11.2
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
*
* http://api.jqueryui.com/slider/#theming
*/.bk-ui-slider{position:relative;text-align:left}.bk-ui-slider .bk-ui-slider-handle{position:absolute;z-index:2;width:1.2em;height:1.2em;cursor:default}.bk-ui-slider .bk-ui-slider-range{position:absolute;z-index:1;font-size:.7em;display:block;border:0;background-position:0 0}.bk-ui-slider.bk-ui-state-disabled .bk-ui-slider-handle,.bk-ui-slider.bk-ui-state-disabled .bk-ui-slider-range{filter:inherit}.bk-ui-slider-horizontal{height:.8em}.bk-ui-slider-horizontal .bk-ui-slider-handle{top:-.3em;margin-left:-.6em}.bk-ui-slider-horizontal .bk-ui-slider-range{top:0;height:100%}.bk-ui-slider-horizontal .bk-ui-slider-range-min{left:0}.bk-ui-slider-horizontal .bk-ui-slider-range-max{right:0}.bk-ui-slider-vertical{width:.8em;height:100px}.bk-ui-slider-vertical .bk-ui-slider-handle{left:-.3em;margin-left:0;margin-bottom:-.6em}.bk-ui-slider-vertical .bk-ui-slider-range{left:0;width:100%}.bk-ui-slider-vertical .bk-ui-slider-range-max{top:0}/*!
* jQuery UI Spinner 1.11.2
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
*
* http://api.jqueryui.com/spinner/#theming
* jQuery UI Tabs 1.11.2
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
*
* http://api.jqueryui.com/tabs/#theming
* jQuery UI Tooltip 1.11.2
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
*
* http://api.jqueryui.com/tooltip/#theming
* jQuery UI CSS Framework 1.11.2
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
*
* http://api.jqueryui.com/category/theming/
*
* To view and modify this theme, visit http://jqueryui.com/themeroller/
/*# sourceMappingURL=bokeh.min.css.map */
/* END /Users/wangweiyang/anaconda/anaconda/lib/python2.7/site-packages/bokeh/server/static/css/bokeh.min.css */

/* BEGIN /Users/wangweiyang/anaconda/anaconda/lib/python2.7/site-packages/bokeh/server/static/js/bokeh.min.js */