Skip to main content

This package contains implementation of the library "MPComplex". MPComplex is a data type supporting complex numbers which allow comparison and sorting operations.

Project description

MPComplex

MPComplex is a data type which support complex numbers which allow comparison and sorting operations. This library extends 'mpc' in 'mpmath' library (https://pypi.org/project/mpmath/) by allowing comparisons and sorting.

MPComplex Operations

The operations supported by MPComplex are addition, subtraction, multiplication, division, power, comparisons, and sorting.

Addition

Input: MPComplex(4, 2) + MPComplex(5, 3) Output: MPComplex(9, 5)

Subtraction

Input: MPComplex(7, 9) - MPComplex(3, 3) Output: MPComplex(4, 6)

Multiplication

Input: MPComplex(5, 4) * MPComplex(4, 6) Output: MPComplex(-4, 46)

Division

Input: MPComplex(5, 4) / MPComplex(4, 6) Output: MPComplex(0.846153846153846, -0.269230769230769)

Power

Input: MPComplex(4, 2) ** 5 Output: MPComplex(-1216, 1312)

Comparisons in General

MPComplex objects are compared to each other in the following order:

  1. real part value
  2. imaginary part value

For example, to check whether MPComplex object a is greater than MPComplex object b or not, the program does the following steps:

  1. Checks if the real part of a is greater than the real part of b or not. If yes, 'True' is returned.
  2. If the real part of a is equal to the real part of b, go to step 3. Else, go to step 4.
  3. Return true if the imaginary part of a is greater than the imaginary part of b. Else, return 'False'.
  4. Return 'False' immediately.

The similar process applies to the operations 'less than', 'less than or equal to', and 'greater than or equal to' as well.

For checking equality of two complex numbers, equality applies if the real and imaginary parts of both numbers are equal.

Greater Than

Input: MPComplex(5, 4) > MPComplex(4, 6) Output: True

Greater Than or Equal To

Input: MPComplex(5, 4) >= MPComplex(4, 6) Output: True

Less Than

Input: MPComplex(5, 4) < MPComplex(4, 6) Output: False

Less Than or Equal To

Input: MPComplex(5, 4) <= MPComplex(4, 6) Output: False

Equal To

Input: MPComplex(4, 2) == MPComplex(4, 1) Output: False

Not Equal To

Input: MPComplex(4, 2) != MPComplex(4, 1) Output: True

Sorting

If a list of MPComplex objects is called with sort() method, the list will be sorted in ascending order.

Input: [MPComplex(4, 2), MPComplex(4, 1), MPComplex(5, 3), MPComplex(2, 7)].sort() Output: [MPComplex(2, 7), MPComplex(4, 1), MPComplex(4, 2), MPComplex(5, 3)]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

MPComplex-1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

MPComplex-1-py2-none-any.whl (5.7 kB view details)

Uploaded Python 2

File details

Details for the file MPComplex-1.tar.gz.

File metadata

  • Download URL: MPComplex-1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.4

File hashes

Hashes for MPComplex-1.tar.gz
Algorithm Hash digest
SHA256 8f92086cf787498f7fa4b5e84f130d7891952b7e8614257ed3211ce6b38a67dc
MD5 00764b82049684ec0d926246a4efd63f
BLAKE2b-256 9be63d5ff49dc1f2ed72d970453d4586f3415e753e6967afae8ce12efe3e5596

See more details on using hashes here.

Provenance

File details

Details for the file MPComplex-1-py2-none-any.whl.

File metadata

  • Download URL: MPComplex-1-py2-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.4

File hashes

Hashes for MPComplex-1-py2-none-any.whl
Algorithm Hash digest
SHA256 4af7fe8c14c955215d4121d0f147ead8be5325ec583d213ae8503beea38da863
MD5 983b72a8898487e221c02c5e0f4c6bcc
BLAKE2b-256 787f0c61c9ab7e743f2c79ed14d8211e4a3c212296f130f3626f6c74c2dd9794

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page