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.
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.
- Make sure to have python > v3.6
- Find the latest source code in this repository's Releases.
- Decompress the source code.
$ cd Znop
$ python setup.py install
$ znop
.
- Make sure to have python > v3.6 installed and git installed.
$ git clone https://github.com/paaksing/Znop.git
$ cd Znop
$ python setup.py install
$ znop
.
- Make sure to have python > v3.6 installed and
pip
installed. $ pip install znop
.$ znop
.
Note: There is only windows binaries, and windows antivirus might classify it as malicious app.
- Find the latest executable in this repository's Releases.
- Download it to local machine
- Execute it.
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 |
(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
Describe usage and API of this library.
- Python 3.6 (due to requirements of f-strings)
- Install using
pip install znop
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
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.
-
__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.
-
__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, thenResolveError
will be raised.
Operation between ZnInt of different Z set.
Operation between ZnInt of different variables outside products.
Indicates a parsing error, reason will be stated when ParseError
is thrown.
Could not resolve equation.