精确可构造数表示
constructible的Python项目详细描述
可构造模块提供了 constructible numbers在python中。
支持Python2和Python3。
可构造数是包含有理数的最小字段,其中 任何非负的可构造数也是可构造的。非负可构造数是 用罗盘和直尺从单位长度构造的长度。
用法
通常,sqrt函数足以处理可构造的数字:
>>> from constructible import sqrt >>> x = sqrt(2) + sqrt(3) >>> print(x) ((0 + 1 * sqrt(2)) + (1 + 0 * sqrt(2)) * sqrt((3 + 0 * sqrt(2)))) >>> y = x*x >>> print(y) ((5 + 0 * sqrt(2)) + (0 + 2 * sqrt(2)) * sqrt((3 + 0 * sqrt(2)))) >>> z = y*y >>> t = 10*y - z >>> t == 1 True
安装
要从pypi安装,只需键入
pip install constructible
这个库是一个纯python文件,所以手工安装也很容易。
测试
有些测试使用unittest。由于Travis-CI,每次推到github都会触发一个测试:
在pypi上释放
需要以下步骤:
在setup.py中更新版本
在git中标记版本:
git tag 0.1 -m "Adds a tag so that we can put this on PyPI." git push --tags origin
测试版本:
python setup.py register -r pypitest python setup.py sdist upload -r pypitest
有效的版本:
python setup.py register -r pypi python setup.py sdist upload -r pypi
更改日志
- 2016-05-23 v0.1初始版本
- 2016-09-30V0.2定影1和添加测试< /LI>
- 2016~10-03 V0.3固定问题2
- 2016-10-23 v0.4增加了hash和float,速度优化
A确认
感谢Anders Kaseorg谁 implementation of constructible numbers in Haskell 提供灵感,尤其是 algorithm for taking square roots 在二次扩展域中。