Giter Club home page Giter Club logo

constructible's Introduction

Representing Constructible Numbers in Python

Build Status: Build Status

The constructible module provides exact representation of constructible numbers in Python.

Python 2 and Python 3 are supported.

The constructible numbers are the smallest field containing the rational numbers, where the square root of any non-negative constructible number is constructible as well. The non-negative constructible numbers are the lengths which can be constructed from the unit length using only a compass and a straightedge.

Usage

Usually the sqrt function is enough to work with constructible numbers:

>>> 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

Installation

To install from PYPI just type

pip install constructible

The library is a single pure python file, so it is also easy to install by hand.

Testing

There are some tests using unittest. Thanks to Travis-CI each push to github triggers a test: Build Status

Releasing on PYPI

The following steps are needed:

  • make sure .pypirc is up to date:

    [distutils]
    index-servers =
      pypinew
      pypitest
    
    [pypinew]
    repository = https://upload.pypi.org/legacy/
    username=xxx
    password=xxx
    
    [pypitest]
    repository=https://test.pypi.org/legacy/
    username=xxx
    password=xxx
    
  • Update the version in setup.py

  • Tag the version in git:

    git tag 0.1 -m "Adds a tag so that we can put this on PyPI."
    git push --tags origin
    
  • Test release with:

    python setup.py sdist upload -r pypitest
    
  • Productive release with:

    python setup.py sdist upload -r pypinew
    

Changelog

  • 2016-05-23 V0.1 Initial Release
  • 2016-09-30 V0.2 Fixing Issue 1 and added Tests
  • 2016-10-03 V0.3 Fixing Issue 2
  • 2016-10-23 V0.4 Added __hash__ and __float__, speed optimizations
  • 2020-07-08 V0.5 New hash function and improvements by Arsenii A.

Aknowledgements

Thanks to Anders Kaseorg whose implementation of constructible numbers in Haskell provided inspiration and in particular the algorithm for taking square roots in quadratic extension fields.

constructible's People

Contributors

leovt avatar arseniiv avatar andersk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.