Package: znop
ZnopLibrary 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 UsageDescribe how to install the calculator and its commands.Note: This program willalways create aznop_db.jsonfile if it doesn't existin 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 sourceMake sure to have python > v3.6 installed.$ git clone https://github.com/paaksing/Znop.git$ cd Znop$ python setup.py install$ znop.Install using pipMake sure to have python > v3.6 installed andpipinstalled.$ pip install znop.$ znop.Install as executableFind the latest executable in this repository'sReleases.Download it to local machineExecute it.CommandsAll payload passed to the commands should strictly match this regex:[a-zA-Z0-9\+\-\*\(\)\^]CommandDescriptionset n=<setnumber>Set the set number of Zreduce<expression>Reduce a Zn expression or equationsolve<equation>Solve an one-dimensional Zn equationhelpUsage of this programquitQuit this programExample(n=10)reduce(3x*9)+78-4x
3x+8(n=10)setn=6OK(n=6)solvex^2+3x+2=0x∈{1,2,4,5}(n=6)quitLibrary UsageDescribe usage and API of this library.Requirements and installationPython 3.6 (due to requirements of f-strings)Install usingpip install znopAPI DocumentationThis library consists of 3 modules:coreandexceptions. All objects in this library can be "copied" or "reinstantiated" by doingeval(repr(obj))where obj is anznopobject.str()will return the string representation of the object andrepr()will return the string representation of the object in python syntax.Import the object from the respective modules e.g.:from znop.core import ZnEquationznop.core.ZnTermRepresents 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, thenResolveErrorwill be raised.znop.exceptions.ZSetErrorOperation between ZnInt of different Z set.znop.exceptions.ZVarErrorOperation between ZnInt of different variables outside products.znop.exceptions.ParseErrorIndicates a parsing error, reason will be stated whenParseErroris thrown.znop.exceptions.ResolveErrorCould not resolve equation.