Skip to content

Fix cipher,equation,symbolics #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pypynum/Symbolics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 表达式展开
Expand Down
6 changes: 3 additions & 3 deletions pypynum/cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
12 changes: 6 additions & 6 deletions pypynum/equations.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
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
for item in range(len(left))])
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)))