From db9917444bf165f93e200f02b4b2785eda7253af Mon Sep 17 00:00:00 2001 From: thzsen Date: Sun, 30 Jun 2024 10:07:27 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E4=BA=86parse=5Fexpr?= =?UTF-8?q?=E7=9A=84=E8=BF=94=E5=9B=9E=E5=80=BC=E4=B8=BA=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pypynum/Symbolics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 表达式展开 From 026a6792d649e6995641e8cd53ffa9d98668561f Mon Sep 17 00:00:00 2001 From: thzsen Date: Sun, 30 Jun 2024 10:52:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E8=BF=99?= =?UTF-8?q?=E4=B8=A4=E4=B8=AA=E6=96=87=E4=BB=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pypynum/cipher.py | 6 +++--- pypynum/equations.py | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) 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)))