Compare commits
No commits in common. "b1f9f71fae168a9eac5f5e2502e1352524e04436" and "19b230254acb82a23c6e7b764c9a774ddbff2e4a" have entirely different histories.
b1f9f71fae
...
19b230254a
@ -2,8 +2,8 @@ import numpy as np
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
class GraphStatic:
|
class GraphStatic:
|
||||||
@classmethod
|
@staticmethod
|
||||||
def plot(cls, xs: np.ndarray, ys: np.ndarray, params: dict[str, str]) -> plt.Figure:
|
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
|
И возвращаем Figure
|
||||||
|
@ -37,21 +37,16 @@ Functions:
|
|||||||
| `cosh` | $\cosh(x)$ |
|
| `cosh` | $\cosh(x)$ |
|
||||||
| `cot` | $\cot(x)$ |
|
| `cot` | $\cot(x)$ |
|
||||||
| `exp` | $\exp(x)$ |
|
| `exp` | $\exp(x)$ |
|
||||||
| `inf` | $\inf(X)$ |
|
|
||||||
| `lg` | $\lg(x)$ |
|
| `lg` | $\lg(x)$ |
|
||||||
| `ln` | $\ln(x)$ |
|
| `ln` | $\ln(x)$ |
|
||||||
| `log10` | $\log_{10}(x)$ |
|
| `log10` | $\log_{10}(x)$ |
|
||||||
| `log2` | $\log_2(x)$ |
|
| `log2` | $\log_2(x)$ |
|
||||||
| `max` | $\sup(X)$ |
|
|
||||||
| `min` | $\inf(X)$ |
|
|
||||||
| `prod` | $\displaystyle \prod_{i=0}^n x_i$ |
|
| `prod` | $\displaystyle \prod_{i=0}^n x_i$ |
|
||||||
| `sgn` | $sgn(x)$ |
|
| `sgn` | $sgn(x)$ |
|
||||||
| `sign` | $sgn(x)$ |
|
|
||||||
| `sin` | $\sin(x)$ |
|
| `sin` | $\sin(x)$ |
|
||||||
| `sinh` | $\sinh(x)$ |
|
| `sinh` | $\sinh(x)$ |
|
||||||
| `sqrt` | $\sqrt{x}$ |
|
| `sqrt` | $\sqrt{x}$ |
|
||||||
| `sum` | $\displaystyle\sum_{i=0}^n x_i$ |
|
| `sum` | $\displaystyle\sum_{i=0}^n x_i$ |
|
||||||
| `sup` | $\sup(X)$ |
|
|
||||||
| `tan` | $\tan(x)$ |
|
| `tan` | $\tan(x)$ |
|
||||||
| `tanh` | $\tanh(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).
|
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 !**
|
**! There is no error handling yet !**
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
import numpy as np
|
|
||||||
|
|
||||||
CONSTANTS = {
|
|
||||||
"e": np.e,
|
|
||||||
"pi": np.pi,
|
|
||||||
}
|
|
@ -26,23 +26,18 @@ functions: dict[str, FunctionType] = {
|
|||||||
"cosh": np.cosh,
|
"cosh": np.cosh,
|
||||||
"cot": cot,
|
"cot": cot,
|
||||||
"exp": np.exp,
|
"exp": np.exp,
|
||||||
"inf": np.inf,
|
|
||||||
"lg": np.log10,
|
"lg": np.log10,
|
||||||
"ln": np.log,
|
"ln": np.log,
|
||||||
"log10": np.log10,
|
"log10": np.log10,
|
||||||
"log2": np.log2,
|
"log2": np.log2,
|
||||||
"max": np.max,
|
|
||||||
"min": np.min,
|
|
||||||
"prod": np.prod,
|
"prod": np.prod,
|
||||||
"sgn": np.sign,
|
"sgn": np.sign,
|
||||||
"sign": np.sign,
|
|
||||||
"sin": np.sin,
|
"sin": np.sin,
|
||||||
"sinh": np.sinh,
|
"sinh": np.sinh,
|
||||||
"sqrt": np.sqrt,
|
"sqrt": np.sqrt,
|
||||||
"sum": np.sum,
|
"sum": np.sum,
|
||||||
"sup": np.max,
|
|
||||||
"tah": np.tanh,
|
|
||||||
"tan": np.tan,
|
"tan": np.tan,
|
||||||
|
"tah": np.tanh,
|
||||||
}
|
}
|
||||||
|
|
||||||
operators: dict[str, OperatorType] = {
|
operators: dict[str, OperatorType] = {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from collections.abc import Mapping
|
||||||
|
|
||||||
from .expression import BinaryExpression, Expression, UnaryExpression, ValueExpression
|
from .expression import BinaryExpression, Expression, UnaryExpression, ValueExpression
|
||||||
from .operation import (
|
from .operation import (
|
||||||
BraceOperation,
|
BraceOperation,
|
||||||
@ -8,7 +10,6 @@ from .operation import (
|
|||||||
)
|
)
|
||||||
from .tokenizer import Token, Tokenizer
|
from .tokenizer import Token, Tokenizer
|
||||||
from .types import ValueType
|
from .types import ValueType
|
||||||
from .constants import CONSTANTS
|
|
||||||
|
|
||||||
|
|
||||||
class Parser:
|
class Parser:
|
||||||
@ -63,8 +64,7 @@ class Parser:
|
|||||||
|
|
||||||
self.__debug_expr = repr(self.val_stack)
|
self.__debug_expr = repr(self.val_stack)
|
||||||
|
|
||||||
def evaluate(self, variables: dict[str, ValueType]):
|
def evaluate(self, variables: Mapping[str, ValueType]):
|
||||||
variables |= CONSTANTS
|
|
||||||
return self._evaluator(variables)
|
return self._evaluator(variables)
|
||||||
|
|
||||||
def do_one(self):
|
def do_one(self):
|
||||||
|
@ -15,17 +15,15 @@ class Tokenizer:
|
|||||||
prev = None
|
prev = None
|
||||||
|
|
||||||
for ch in self.expression:
|
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:
|
if len(accumulator) > 0:
|
||||||
# ch is `(` after function name
|
# ch is `(` after function name
|
||||||
if breaker_type == Token.LBrace and Tokenizer.is_function(
|
if breaker_type == Token.LBrace and self.is_function(accumulator):
|
||||||
accumulator
|
|
||||||
):
|
|
||||||
yield accumulator, Token.Function
|
yield accumulator, Token.Function
|
||||||
prev = Token.Function
|
prev = Token.Function
|
||||||
accumulator = ""
|
accumulator = ""
|
||||||
else:
|
else:
|
||||||
value, token_type = Tokenizer.detect_number(accumulator)
|
value, token_type = self.detect_number(accumulator)
|
||||||
yield value, token_type
|
yield value, token_type
|
||||||
prev = token_type
|
prev = token_type
|
||||||
accumulator = ""
|
accumulator = ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user