czechbol/mathcrypto

OOP

kamen-u-cesty opened this issue · 0 comments

Because this library is targeted at students wanting to understand the math behind the operations, I think the results of some operations should be objects with inner structure, not just a number.

Take the MathFunctions.crt() as an example (not mentioning the violation of naming conventions) -- the Chinese Remainder Theorem is meant to be computed by hand, and getting only the result as an integer doesn't help you understand the workings behind it.

I'm proposing OOP approach to this -- user would create the ChineseRemainderTheorem object in interactive session and would be able to inspect inner variables or get the result in multiple graphical formats. Something like this:

class ChineseRemainderTheorem:
    def __init__(self, input: List[List[int, int]]):
        ...
        self.result = ...

    @property
    def ascii(self):
        """Render the computation in ASCII"""
        ...

    @property
    def tex(self):
        """Render the computation in TeX"""
        ...
    
    def __str__(self):
        return f"{self.result}"

By enforcing certain rules (result variable, ascii and tex properties, the most basic result representation in str()) this would get much more powerful, because it would all work just like MultiplicativeGroup and not as mix of objects and functions.

This would also allow us to pick between multiple algorithms that are doing the same thing -- GCD can be solved by factorisation OR by using Euclidean Algorithm.