How to use the simplification.Polynomial function in simplification

To help you get started, we’ve selected a few simplification examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github KenMercusLai / checkio / tests / test_simplification.py View on Github external
def test_Polynomial(self):
        assert str(Polynomial([1]) + Polynomial([1])) == '2'
        assert str(Polynomial([3]) + Polynomial([0, 4]) +
                   Polynomial([-24]) + Polynomial([0, -2])) == '2*x-21'
        assert str(Polynomial([-1, 1]) * Polynomial([-1, 1])) == 'x**2-2*x+1'
        assert str(-Polynomial([-1, 1])) == '-x+1'
        assert str(-Polynomial([1])) == '-1'
        assert str(Polynomial([-2, 2]) * Polynomial([2, 2])) == '4*x**2-4'
        assert str(Polynomial([-2, 1]) * Polynomial([2, 1])
                   * Polynomial([2, 1])) == 'x**3+2*x**2-4*x-8'
        assert str(Polynomial([2]) * Polynomial([3, 2]) -
                   Polynomial([0, 1]) + Polynomial([0, 0, 0, 0, 1])) == 'x**4+3*x+6'
        assert str(Polynomial([0, 1])) == 'x'
        assert str(Polynomial([0, 1])-Polynomial([0, 1])) == '0'
github KenMercusLai / checkio / simplification.py View on Github external
def __add__(self, other):
        if len(self.plist) > len(other.plist):
            new = [i for i in self.plist]
            for i in range(len(other.plist)):
                new[i] += other.plist[i]
        else:
            new = [i for i in other.plist]
            for i in range(len(self.plist)):
                new[i] += self.plist[i]
        return Polynomial(new)
github KenMercusLai / checkio / simplification.py View on Github external
def __mul__(self, other):
        result = []
        for i in range(len(other.plist)):
            result.append(
                Polynomial([0] * i + [j * other.plist[i] for j in self.plist]))
        return functools.reduce(operator.add, result)
github KenMercusLai / checkio / simplification.py View on Github external
for i in range(len(symbols) - 1):
            try:
                int(symbols[i])
                int(symbols[i + 1])
                symbols = symbols[
                    :i] + [symbols[i] + symbols[i + 1]] + symbols[i + 2:]
                changed = True
                break
            except ValueError:
                pass

    # convert numbers and x
    for i in range(len(symbols)):
        try:
            int(symbols[i])
            symbols[i] = Polynomial([int(symbols[i])])
        except ValueError:
            if symbols[i] == 'x':
                symbols[i] = Polynomial([0, 1])
    return symbols
github KenMercusLai / checkio / simplification.py View on Github external
def __neg__(self):
        return Polynomial([-1]) * self

simplification

Fast linestring simplification using RDP or Visvalingam-Whyatt and a Rust binary

MIT
Latest version published 1 month ago

Package Health Score

76 / 100
Full package analysis