diff --git a/pypynum/Symbolics.py b/pypynum/Symbolics.py index 8071404..ff6a03a 100644 --- a/pypynum/Symbolics.py +++ b/pypynum/Symbolics.py @@ -56,7 +56,7 @@ def parse_expr(expr: str) -> list: result.append(number) if depth != 0: raise ValueError("The parentheses in the expression are not paired") - return result if len(result) != 1 else result[0] + return result # TODO 表达式展开 diff --git a/pypynum/cipher.py b/pypynum/cipher.py index 6ee06d5..77226b2 100644 --- a/pypynum/cipher.py +++ b/pypynum/cipher.py @@ -129,13 +129,13 @@ def substitution(text: str, sub_map: dict, decrypt: bool = False) -> str: return result -def morse(text: str, decrypt: bool = False) -> str: +def morse(string: str, decrypt: bool = False) -> str: code_dict = MORSE_CODE_REVERSE if decrypt else MORSE_CODE result = [] if decrypt: - text = text.split() + text = string.split() else: - text = text.upper() + text = string.upper() for item in text: if item in code_dict: result.append(code_dict[item]) diff --git a/pypynum/equations.py b/pypynum/equations.py index 6cf68e9..7477a8b 100644 --- a/pypynum/equations.py +++ b/pypynum/equations.py @@ -1,6 +1,7 @@ -def lin_eq(left: list, right: list) -> list: - from .Array import array - from .Matrix import mat +from .Array import array +from .Matrix import eigen, mat +def lin_eq(left: list, right: list) : + d = mat(left).det() if d != 0: return array([mat([left[_][:item] + [right[_]] + left[_][item + 1:] for _ in range(len(left))]).det() / d @@ -8,9 +9,8 @@ def lin_eq(left: list, right: list) -> list: return array([float("inf")] * len(right)) -def poly_eq(coefficients: list) -> list: - from .Array import array - from .Matrix import eigen, mat +def poly_eq(coefficients: list) : + p = [_ / coefficients[0] for _ in coefficients[1:]] return array(sorted(eigen(mat([[-p[i] if j == 0 else 1 if i + 1 == j else 0 for j in range(len(p))] for i in range(len(p))]))[0].diag().t()[0], key=lambda c: (c.real, c.imag)))