2018-12-07 07:10:15 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim:fenc=utf-8
|
|
|
|
#
|
|
|
|
# Copyright © 2017 lafrite <lafrite@Poivre>
|
|
|
|
#
|
|
|
|
# Distributed under terms of the MIT license.
|
|
|
|
|
|
|
|
"""
|
2018-12-07 09:27:50 +00:00
|
|
|
Tokens representing polynomials functions
|
2018-12-07 07:10:15 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
from .token import Token
|
|
|
|
|
|
|
|
__all__ = ["Polynomial", "Quadratic", "Linear"]
|
|
|
|
|
|
|
|
class Polynomial(Token):
|
|
|
|
|
|
|
|
""" Token representing a polynomial """
|
|
|
|
|
2018-12-07 09:27:50 +00:00
|
|
|
def __init__(self, mo, name="", ancestor=None):
|
2018-12-07 07:10:15 +00:00
|
|
|
if not isinstance(mo, MOpolynomial):
|
|
|
|
raise TypeError
|
|
|
|
if not isinstance(mo.value, int):
|
|
|
|
raise TypeError
|
|
|
|
|
2018-12-07 09:27:50 +00:00
|
|
|
Token.__init__(self, mo, name, ancestor)
|
2018-12-07 07:10:15 +00:00
|
|
|
self._mathtype = 'polynome'
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def random(cls):
|
|
|
|
raise NotImplemented
|
|
|
|
|
|
|
|
def __setitem__(self, key, item):
|
|
|
|
""" Use Polynomial like if they were a dictionnary to set coefficients """
|
|
|
|
pass
|
|
|
|
|
|
|
|
def __getitem__(self, key):
|
|
|
|
""" Use Polynomial like if they were a dictionnary to get coefficients """
|
|
|
|
pass
|
|
|
|
|
|
|
|
def __call__(self, value):
|
|
|
|
""" Call a Polynomial to evaluate itself on value """
|
|
|
|
pass
|
|
|
|
|
2018-12-07 09:27:50 +00:00
|
|
|
class Linear(Token):
|
|
|
|
|
|
|
|
""" Token representing a linear """
|
|
|
|
|
|
|
|
def __init__(self, mo, name="", ancestor=None):
|
|
|
|
if not isinstance(mo, MOpolynomial):
|
|
|
|
raise TypeError
|
|
|
|
if not isinstance(mo.value, int):
|
|
|
|
raise TypeError
|
|
|
|
|
|
|
|
Token.__init__(self, mo, name, ancestor)
|
|
|
|
self._mathtype = 'affine'
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def random(cls):
|
|
|
|
raise NotImplemented
|
|
|
|
|
|
|
|
class Quadratic(Token):
|
|
|
|
|
|
|
|
""" Token representing a quadratic """
|
|
|
|
|
|
|
|
def __init__(self, mo, name="", ancestor=None):
|
|
|
|
if not isinstance(mo, MOpolynomial):
|
|
|
|
raise TypeError
|
|
|
|
if not isinstance(mo.value, int):
|
|
|
|
raise TypeError
|
|
|
|
|
|
|
|
Token.__init__(self, mo, name, ancestor)
|
|
|
|
self._mathtype = 'polynome du 2nd degré'
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def random(cls):
|
|
|
|
raise NotImplemented
|
|
|
|
|
2018-12-07 07:10:15 +00:00
|
|
|
|
|
|
|
# -----------------------------
|
|
|
|
# Reglages pour 'vim'
|
|
|
|
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
|
|
|
# cursor: 16 del
|