Skip to main content

Library that solves discrete math operations of the group Zn, provides both as calculator program or third party library.

Project description

Znop

Library that solves discrete math operations of the group Zn, provides both as calculator program or third party library.

The group Zn consists of the elements {0, 1, 2, . . . , n−1} with addition mod n as the operation. You can also multiply elements of Zn, but you do not obtain a group: The element 0 does not have a multiplicative inverse, for instance. However, if you confine your attention to the units in Zn — the elements which have multiplicative inverses — you do get a group under multiplication mod n. It is denoted Un, and is called the group of units in Zn.

Program Usage

Describe how to install the calculator and its commands.

Note: This program will always create a znop_db.json file if it doesn't exist in the directory you execute the program, this file is aimed to save your last ~30 commands and the Zn group (default n=10) set on your program.

Install from source

  1. Make sure to have python > v3.6 installed.
  2. $ git clone https://github.com/paaksing/Znop.git
  3. $ cd Znop
  4. $ python setup.py install
  5. $ znop.

Install using pip

  1. Make sure to have python > v3.6 installed and pip installed.
  2. $ pip install znop.
  3. $ znop.

Install as executable

  1. Find the latest executable in this repository's Releases.
  2. Download it to local machine
  3. Execute it.

Commands

All payload passed to the commands should strictly match this regex: [a-zA-Z0-9\+\-\*\(\)\^]

Command Description
set n=<setnumber> Set the set number of Z
reduce <expression> Reduce a Zn expression or equation
solve <equation> Solve an one-dimensional Zn equation
help Usage of this program
quit Quit this program

Example

(n=10) reduce (3x*9)+78-4x
3x+8

(n=10) set n=6
OK

(n=6) solve x^2+3x+2=0
x  {1, 2, 4, 5}

(n=6) quit

Library Usage

Describe usage and API of this library.

Requirements and installation

  • Python 3.6 (due to requirements of f-strings)
  • Install using pip install znop

API Documentation

This library consists of 3 modules: core and exceptions. All objects in this library can be "copied" or "reinstantiated" by doing eval(repr(obj)) where obj is an znop object. str() will return the string representation of the object and repr() will return the string representation of the object in python syntax.

Import the object from the respective modules e.g.: from znop.core import ZnEquation

znop.core.ZnTerm

Represents a term in the group of ZnTerm

  • __init__(n: int, raw: str): Create an instance of ZnTerm, arguments: n (set number), raw (raw string of term, e.g. '2x').

  • __add__, __sub__, __mul__, __neg__, __eq__: This object supports [+, -, *] operations between ZnTerms, with the exception of multiplications that it can multiply a ZnExpression by doing distributive, it will always return a new ZnTerm. Supports - (negate) operation and returns a new ZnTerm. It also supports equality comparison == between ZnTerms.

  • eval(values: Dict[str, int]): Evaluate the variables in the term, receives a mapping of variable name to value e.g. {'x': 6}, and return a new ZnTerm.

znop.core.ZnExpression

  • __init__(n: int, raw: str): Create an instance of ZnExpression, arguments: n (set number), raw (raw string of expression, e.g. '2x+x-3'). This expression is automatically reduced to its simplest form.

  • __mul__, __eq__: This objects supports * between ZnExpressions and ZnTerms by doing distributive, It also supports equality comparison == between ZnExpressions.

  • reduce(): Reduce the expression to the simplest form, this function is automatically called on instantiation.

  • eval(values: Dict[str, int]): Evaluate the variables in the expression, receives a mapping of variable name to value e.g. {'x': 6}, and return a new ZnExpression.

znop.core.ZnEquation

  • __init__(n: int, raw: str): Create an instance of ZnEquation, arguments: n (set number), raw (raw string of equation, e.g. '2x^2+3=0'). This equation is automatically reduced to its simplest form.

  • reduce(): Reduce the equation to the simplest form, this function is automatically called on instantiation.

  • solve(): Solve the equation by returning a list of solutions (ints). If the equation cannot be solved, then ResolveError will be raised.

znop.exceptions.ZSetError

Operation between ZnInt of different Z set.

znop.exceptions.ZVarError

Operation between ZnInt of different variables outside products.

znop.exceptions.ParseError

Indicates a parsing error, reason will be stated when ParseError is thrown.

znop.exceptions.ResolveError

Could not resolve equation.

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

znop-0.2.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

znop-0.2.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file znop-0.2.0.tar.gz.

File metadata

  • Download URL: znop-0.2.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.12

File hashes

Hashes for znop-0.2.0.tar.gz
Algorithm Hash digest
SHA256 21b94f23ad4e27c8bffeabad3ca1f0a31e5e851a708b538725f75ae683dcd3bf
MD5 1c958168af7deaf0d6c405c4f7730714
BLAKE2b-256 f42fce98252471d1032ffdffb6171e82f836fc5ca3b0ae9d5e49f5596c768b28

See more details on using hashes here.

File details

Details for the file znop-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: znop-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.12

File hashes

Hashes for znop-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23dbe0b146b3fb9b2478bc651c96984c648599da5fd1c47b82d38a09e29ff18f
MD5 0a1178f7392ae175a4eac2a68c4b50fc
BLAKE2b-256 a31706369369212beac4036d23d5ad16e89908a405c26c6e3c71be925a789e25

See more details on using hashes here.

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