项目作者: andrew-lei

项目描述 :
Interval arithmetic for Python using algebraic data types
高级语言: Python
项目地址: git://github.com/andrew-lei/intervals.git
创建时间: 2018-04-26T07:03:59Z
项目社区:https://github.com/andrew-lei/intervals

开源协议:MIT License

下载


Interval arithmetic in Python using Algebraic Data Types

More or less based on a Haskell package.

Contains an infix class released under PSF License.

Requires uxadt

  1. sudo pip3 install uxadt

Supports arithmetic (add,sub,mul,div) and comparison.

Comparison using forall by default.

Use e.g., ltSome or leSome if x < y for some values of x and y

Equality is weird for intervals.

Addition:

  1. >>> Interval(-1,3) + Interval(4,5)
  2. Interval(3,8)
  3. >>> Interval(1,3) + Empty()
  4. Empty()
  5. >>> Empty() + Interval(1,3)
  6. Empty()

Multiplication:

  1. >>> Interval(-1,3) * Interval(4,5)
  2. Interval(-5,15)
  3. >>> Interval(-3,3) * Interval(-5,2)
  4. Interval(-15,15)
  5. >>> Interval(1,3) * Empty()
  6. Empty()
  7. >>> Empty() * Interval(1,3)
  8. Empty()

Unary minus operator

  1. >>> -Interval(-1,3)
  2. Interval(-3,1)
  3. >>> -Empty()
  4. Empty()

Binary minus operator

  1. >>> Interval(3,6) - Interval(-4,2)
  2. Interval(1,10)
  3. >>> Empty() - Interval(1,2)
  4. Empty()

Division

  1. >>> Interval(1,3) / Interval(3,5)
  2. Interval(0.2,1.0))
  3. >>> Interval(1,3) / Interval(-1,1)
  4. Interval(-inf,inf)
  5. >>> Interval(1,3) / Interval(0,3)
  6. Interval(0.3333333333333333, inf)

Inclusion

  1. >>> 1 in Interval(0,2)
  2. True
  3. >>> -1 in Interval(0,2)
  4. False
  5. >>> 1 in Empty()
  6. False