Compare commits

..

No commits in common. "b1f9f71fae168a9eac5f5e2502e1352524e04436" and "19b230254acb82a23c6e7b764c9a774ddbff2e4a" have entirely different histories.

6 changed files with 11 additions and 29 deletions

View File

@ -2,8 +2,8 @@ import numpy as np
import matplotlib.pyplot as plt
class GraphStatic:
@classmethod
def plot(cls, xs: np.ndarray, ys: np.ndarray, params: dict[str, str]) -> plt.Figure:
@staticmethod
def plot(xs: np.ndarray, ys: np.ndarray, params: dict[str, str]) -> plt.Figure:
"""
строим график через
"""
@ -13,7 +13,7 @@ class GraphStatic:
Все методы при этом статичные
"""
cls.__some_func(1, 2)
GraphStatic.__some_func(1, 2)
"""
И возвращаем Figure

View File

@ -37,21 +37,16 @@ Functions:
| `cosh` | $\cosh(x)$ |
| `cot` | $\cot(x)$ |
| `exp` | $\exp(x)$ |
| `inf` | $\inf(X)$ |
| `lg` | $\lg(x)$ |
| `ln` | $\ln(x)$ |
| `log10` | $\log_{10}(x)$ |
| `log2` | $\log_2(x)$ |
| `max` | $\sup(X)$ |
| `min` | $\inf(X)$ |
| `prod` | $\displaystyle \prod_{i=0}^n x_i$ |
| `sgn` | $sgn(x)$ |
| `sign` | $sgn(x)$ |
| `sin` | $\sin(x)$ |
| `sinh` | $\sinh(x)$ |
| `sqrt` | $\sqrt{x}$ |
| `sum` | $\displaystyle\sum_{i=0}^n x_i$ |
| `sup` | $\sup(X)$ |
| `tan` | $\tan(x)$ |
| `tanh` | $\tanh(x)$ |
@ -63,6 +58,6 @@ Floating points: `.`, `,`
Functions have only one argument, provided in braces. Operators must have two operands except minus (if it is the first character of equation or braced expression).
`avg`, `sum`, `max`, `sup`, `min`, `inf` and `prod` applied on `numpy.ndarray` produce `float`.
`avg`, `sum` and `prod` applied on `numpy.ndarray` produce `float`.
**! There is no error handling yet !**

View File

@ -1,6 +0,0 @@
import numpy as np
CONSTANTS = {
"e": np.e,
"pi": np.pi,
}

View File

@ -26,23 +26,18 @@ functions: dict[str, FunctionType] = {
"cosh": np.cosh,
"cot": cot,
"exp": np.exp,
"inf": np.inf,
"lg": np.log10,
"ln": np.log,
"log10": np.log10,
"log2": np.log2,
"max": np.max,
"min": np.min,
"prod": np.prod,
"sgn": np.sign,
"sign": np.sign,
"sin": np.sin,
"sinh": np.sinh,
"sqrt": np.sqrt,
"sum": np.sum,
"sup": np.max,
"tah": np.tanh,
"tan": np.tan,
"tah": np.tanh,
}
operators: dict[str, OperatorType] = {

View File

@ -1,3 +1,5 @@
from collections.abc import Mapping
from .expression import BinaryExpression, Expression, UnaryExpression, ValueExpression
from .operation import (
BraceOperation,
@ -8,7 +10,6 @@ from .operation import (
)
from .tokenizer import Token, Tokenizer
from .types import ValueType
from .constants import CONSTANTS
class Parser:
@ -63,8 +64,7 @@ class Parser:
self.__debug_expr = repr(self.val_stack)
def evaluate(self, variables: dict[str, ValueType]):
variables |= CONSTANTS
def evaluate(self, variables: Mapping[str, ValueType]):
return self._evaluator(variables)
def do_one(self):

View File

@ -15,17 +15,15 @@ class Tokenizer:
prev = None
for ch in self.expression:
if (breaker_type := Tokenizer.is_breaker(ch)) is not None:
if (breaker_type := self.is_breaker(ch)) is not None:
if len(accumulator) > 0:
# ch is `(` after function name
if breaker_type == Token.LBrace and Tokenizer.is_function(
accumulator
):
if breaker_type == Token.LBrace and self.is_function(accumulator):
yield accumulator, Token.Function
prev = Token.Function
accumulator = ""
else:
value, token_type = Tokenizer.detect_number(accumulator)
value, token_type = self.detect_number(accumulator)
yield value, token_type
prev = token_type
accumulator = ""