masts 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- masts-0.1.0/LICENSE +21 -0
- masts-0.1.0/PKG-INFO +111 -0
- masts-0.1.0/README.md +87 -0
- masts-0.1.0/pyproject.toml +42 -0
- masts-0.1.0/setup.cfg +4 -0
- masts-0.1.0/src/masts.egg-info/PKG-INFO +111 -0
- masts-0.1.0/src/masts.egg-info/SOURCES.txt +23 -0
- masts-0.1.0/src/masts.egg-info/dependency_links.txt +1 -0
- masts-0.1.0/src/masts.egg-info/entry_points.txt +2 -0
- masts-0.1.0/src/masts.egg-info/top_level.txt +1 -0
- masts-0.1.0/src/math_step_to_step/__init__.py +10 -0
- masts-0.1.0/src/math_step_to_step/__main__.py +3 -0
- masts-0.1.0/src/math_step_to_step/cli.py +41 -0
- masts-0.1.0/src/math_step_to_step/context.py +23 -0
- masts-0.1.0/src/math_step_to_step/engine.py +318 -0
- masts-0.1.0/src/math_step_to_step/errors.py +72 -0
- masts-0.1.0/src/math_step_to_step/fmt.py +167 -0
- masts-0.1.0/src/math_step_to_step/nodes.py +131 -0
- masts-0.1.0/src/math_step_to_step/parser.py +210 -0
- masts-0.1.0/src/math_step_to_step/poly.py +91 -0
- masts-0.1.0/src/math_step_to_step/py.typed +0 -0
- masts-0.1.0/src/math_step_to_step/solver.py +234 -0
- masts-0.1.0/src/math_step_to_step/symbols.py +119 -0
- masts-0.1.0/tests/test_fuzz.py +58 -0
- masts-0.1.0/tests/test_steps.py +133 -0
masts-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 VVT
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
masts-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: masts
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Step-by-step solutions for math expressions and equations (1 + 2 x 3 -> ['1 + 6', '7']), plus text-to-symbol helpers (6^6 -> 6⁶).
|
|
5
|
+
Author: PipoAndDodo
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: math,steps,solver,equation,calculator,superscript,education
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Education
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Education
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# math-step-to-step
|
|
26
|
+
|
|
27
|
+
Giải biểu thức / phương trình **từng bước** và trả về danh sách các bước.
|
|
28
|
+
Không phụ thuộc thư viện ngoài, dùng phân số chính xác (`fractions.Fraction`) nên không bị sai số.
|
|
29
|
+
|
|
30
|
+
*Step-by-step solver for math expressions and equations. Pure Python, zero dependencies, exact arithmetic.*
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install math-step-to-step
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Dùng nhanh
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from math_step_to_step import steps, solve, evaluate, prettify
|
|
40
|
+
|
|
41
|
+
steps("1 + 2 x 3") # ['1 + 6', '7']
|
|
42
|
+
steps("(1 + 2) x 3 + 4 x 5") # ['3 × 3 + 4 × 5', '9 + 20', '29']
|
|
43
|
+
steps("2 + 3 x (4 - 1)^2") # ['2 + 3 × 3²', '2 + 3 × 9', '2 + 27', '29']
|
|
44
|
+
steps("1/2 + 1/3") # ['1/2 + 1/3', '5/6']
|
|
45
|
+
|
|
46
|
+
# tìm x
|
|
47
|
+
steps("2x + 3 = 7") # ['2x = 7 - 3', '2x = 4', 'x = 4 ÷ 2', 'x = 2']
|
|
48
|
+
steps("2(x + 3) = 10") # ['2x + 6 = 10', '2x = 10 - 6', '2x = 4', 'x = 4 ÷ 2', 'x = 2']
|
|
49
|
+
steps("x^2 - 3x + 2 = 0") # a, b, c -> Δ -> x₁, x₂ (từng bước)
|
|
50
|
+
|
|
51
|
+
# kết quả có cấu trúc
|
|
52
|
+
sol = solve("x^2 - 3x + 2 = 0")
|
|
53
|
+
sol.kind, sol.values # ('roots', (2, 1))
|
|
54
|
+
|
|
55
|
+
evaluate("2 + 3 x 4") # 14 (nhanh, không tạo chuỗi bước)
|
|
56
|
+
|
|
57
|
+
# đổi chuỗi thành ký hiệu
|
|
58
|
+
prettify("6^6") # '6⁶'
|
|
59
|
+
prettify("x^2 + y^(n+1) <= sqrt(2)*pi") # 'x² + yⁿ⁺¹ ≤ √2×π'
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Cú pháp nhập
|
|
63
|
+
|
|
64
|
+
| Viết | Ý nghĩa |
|
|
65
|
+
|---|---|
|
|
66
|
+
| `+ - * x × · / ÷ :` | cộng, trừ, nhân, chia |
|
|
67
|
+
| `x` giữa hai toán hạng, vd `2 x 3` | **phép nhân**; còn `2x`, `x + 1`, `x²` thì `x` là **biến** |
|
|
68
|
+
| `^`, `**`, `²` `³` | lũy thừa (số mũ nguyên) |
|
|
69
|
+
| `sqrt(…)`, `√9` | căn bậc hai |
|
|
70
|
+
| `( )`, `[ ]`, `{ }` | ngoặc |
|
|
71
|
+
| `2x`, `3(x+1)`, `(a)(b)` | nhân ngầm |
|
|
72
|
+
| `1,5` hoặc `1.5` | số thập phân |
|
|
73
|
+
| `=` | phương trình (1 biến, bậc 1 hoặc 2) |
|
|
74
|
+
|
|
75
|
+
## Tùy chọn của `steps()` / `solve()`
|
|
76
|
+
|
|
77
|
+
| Tham số | Mặc định | Ý nghĩa |
|
|
78
|
+
|---|---|---|
|
|
79
|
+
| `include_original` | `False` | thêm biểu thức gốc làm bước đầu |
|
|
80
|
+
| `detailed` | `False` | mỗi bước chỉ làm 1 phép (`1+2+3` → `3 + 3` → `6`) thay vì gộp |
|
|
81
|
+
| `pretty` | `True` | dùng `× ÷ ² √`; `False` ra ASCII (`* / ^ sqrt()`), có thể đưa lại vào thư viện |
|
|
82
|
+
| `style` | `"auto"` | `"fraction"`, `"decimal"` hoặc `"auto"` (thập phân nếu đầu vào có số thập phân) |
|
|
83
|
+
| `lang` | `"vi"` | ngôn ngữ thông báo: `"vi"` / `"en"` |
|
|
84
|
+
|
|
85
|
+
Cách chọn bước: ngoặc trước → lũy thừa/căn → nhân chia → cộng trừ; các phép độc lập được làm **cùng một bước**
|
|
86
|
+
và chuỗi cộng/nhân liên tiếp được gộp để lời giải ngắn nhất. Với phương trình: rút gọn → chuyển vế → chia hệ số;
|
|
87
|
+
bậc 2 dùng Δ.
|
|
88
|
+
|
|
89
|
+
## Ký hiệu
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from math_step_to_step import superscript, subscript, prettify
|
|
93
|
+
superscript("123") # '¹²³'
|
|
94
|
+
subscript("12") # '₁₂'
|
|
95
|
+
prettify("H_2O, 6^6, x^(n+1), 1/2, a<=b, a!=b, +-3, alpha")
|
|
96
|
+
# 'H₂O, 6⁶, xⁿ⁺¹, ½, a≤b, a≠b, ±3, α'
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Giới hạn (cố ý, để ít lỗi)
|
|
100
|
+
Một biến; phương trình bậc ≤ 2; số mũ nguyên; không có số phức; không rút gọn căn phức tạp
|
|
101
|
+
(căn không chính phương được rút gọn dạng `2 × √3` và cho giá trị gần đúng). Đầu vào sai/không hỗ trợ
|
|
102
|
+
luôn ném `MathStepError` (kế thừa `ValueError`) với thông báo rõ ràng.
|
|
103
|
+
|
|
104
|
+
## Dòng lệnh
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
math-step-to-step "(1 + 2) x 3 + 4 x 5"
|
|
108
|
+
python -m math_step_to_step "2x + 3 = 7" --en
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
MIT License.
|
masts-0.1.0/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# math-step-to-step
|
|
2
|
+
|
|
3
|
+
Giải biểu thức / phương trình **từng bước** và trả về danh sách các bước.
|
|
4
|
+
Không phụ thuộc thư viện ngoài, dùng phân số chính xác (`fractions.Fraction`) nên không bị sai số.
|
|
5
|
+
|
|
6
|
+
*Step-by-step solver for math expressions and equations. Pure Python, zero dependencies, exact arithmetic.*
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install math-step-to-step
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Dùng nhanh
|
|
13
|
+
|
|
14
|
+
```python
|
|
15
|
+
from math_step_to_step import steps, solve, evaluate, prettify
|
|
16
|
+
|
|
17
|
+
steps("1 + 2 x 3") # ['1 + 6', '7']
|
|
18
|
+
steps("(1 + 2) x 3 + 4 x 5") # ['3 × 3 + 4 × 5', '9 + 20', '29']
|
|
19
|
+
steps("2 + 3 x (4 - 1)^2") # ['2 + 3 × 3²', '2 + 3 × 9', '2 + 27', '29']
|
|
20
|
+
steps("1/2 + 1/3") # ['1/2 + 1/3', '5/6']
|
|
21
|
+
|
|
22
|
+
# tìm x
|
|
23
|
+
steps("2x + 3 = 7") # ['2x = 7 - 3', '2x = 4', 'x = 4 ÷ 2', 'x = 2']
|
|
24
|
+
steps("2(x + 3) = 10") # ['2x + 6 = 10', '2x = 10 - 6', '2x = 4', 'x = 4 ÷ 2', 'x = 2']
|
|
25
|
+
steps("x^2 - 3x + 2 = 0") # a, b, c -> Δ -> x₁, x₂ (từng bước)
|
|
26
|
+
|
|
27
|
+
# kết quả có cấu trúc
|
|
28
|
+
sol = solve("x^2 - 3x + 2 = 0")
|
|
29
|
+
sol.kind, sol.values # ('roots', (2, 1))
|
|
30
|
+
|
|
31
|
+
evaluate("2 + 3 x 4") # 14 (nhanh, không tạo chuỗi bước)
|
|
32
|
+
|
|
33
|
+
# đổi chuỗi thành ký hiệu
|
|
34
|
+
prettify("6^6") # '6⁶'
|
|
35
|
+
prettify("x^2 + y^(n+1) <= sqrt(2)*pi") # 'x² + yⁿ⁺¹ ≤ √2×π'
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Cú pháp nhập
|
|
39
|
+
|
|
40
|
+
| Viết | Ý nghĩa |
|
|
41
|
+
|---|---|
|
|
42
|
+
| `+ - * x × · / ÷ :` | cộng, trừ, nhân, chia |
|
|
43
|
+
| `x` giữa hai toán hạng, vd `2 x 3` | **phép nhân**; còn `2x`, `x + 1`, `x²` thì `x` là **biến** |
|
|
44
|
+
| `^`, `**`, `²` `³` | lũy thừa (số mũ nguyên) |
|
|
45
|
+
| `sqrt(…)`, `√9` | căn bậc hai |
|
|
46
|
+
| `( )`, `[ ]`, `{ }` | ngoặc |
|
|
47
|
+
| `2x`, `3(x+1)`, `(a)(b)` | nhân ngầm |
|
|
48
|
+
| `1,5` hoặc `1.5` | số thập phân |
|
|
49
|
+
| `=` | phương trình (1 biến, bậc 1 hoặc 2) |
|
|
50
|
+
|
|
51
|
+
## Tùy chọn của `steps()` / `solve()`
|
|
52
|
+
|
|
53
|
+
| Tham số | Mặc định | Ý nghĩa |
|
|
54
|
+
|---|---|---|
|
|
55
|
+
| `include_original` | `False` | thêm biểu thức gốc làm bước đầu |
|
|
56
|
+
| `detailed` | `False` | mỗi bước chỉ làm 1 phép (`1+2+3` → `3 + 3` → `6`) thay vì gộp |
|
|
57
|
+
| `pretty` | `True` | dùng `× ÷ ² √`; `False` ra ASCII (`* / ^ sqrt()`), có thể đưa lại vào thư viện |
|
|
58
|
+
| `style` | `"auto"` | `"fraction"`, `"decimal"` hoặc `"auto"` (thập phân nếu đầu vào có số thập phân) |
|
|
59
|
+
| `lang` | `"vi"` | ngôn ngữ thông báo: `"vi"` / `"en"` |
|
|
60
|
+
|
|
61
|
+
Cách chọn bước: ngoặc trước → lũy thừa/căn → nhân chia → cộng trừ; các phép độc lập được làm **cùng một bước**
|
|
62
|
+
và chuỗi cộng/nhân liên tiếp được gộp để lời giải ngắn nhất. Với phương trình: rút gọn → chuyển vế → chia hệ số;
|
|
63
|
+
bậc 2 dùng Δ.
|
|
64
|
+
|
|
65
|
+
## Ký hiệu
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from math_step_to_step import superscript, subscript, prettify
|
|
69
|
+
superscript("123") # '¹²³'
|
|
70
|
+
subscript("12") # '₁₂'
|
|
71
|
+
prettify("H_2O, 6^6, x^(n+1), 1/2, a<=b, a!=b, +-3, alpha")
|
|
72
|
+
# 'H₂O, 6⁶, xⁿ⁺¹, ½, a≤b, a≠b, ±3, α'
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Giới hạn (cố ý, để ít lỗi)
|
|
76
|
+
Một biến; phương trình bậc ≤ 2; số mũ nguyên; không có số phức; không rút gọn căn phức tạp
|
|
77
|
+
(căn không chính phương được rút gọn dạng `2 × √3` và cho giá trị gần đúng). Đầu vào sai/không hỗ trợ
|
|
78
|
+
luôn ném `MathStepError` (kế thừa `ValueError`) với thông báo rõ ràng.
|
|
79
|
+
|
|
80
|
+
## Dòng lệnh
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
math-step-to-step "(1 + 2) x 3 + 4 x 5"
|
|
84
|
+
python -m math_step_to_step "2x + 3 = 7" --en
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
MIT License.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "masts"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Step-by-step solutions for math expressions and equations (1 + 2 x 3 -> ['1 + 6', '7']), plus text-to-symbol helpers (6^6 -> 6⁶)."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "PipoAndDodo" }]
|
|
14
|
+
keywords = ["math", "steps", "solver", "equation", "calculator", "superscript", "education"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Education",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.9",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Topic :: Education",
|
|
26
|
+
"Topic :: Scientific/Engineering :: Mathematics",
|
|
27
|
+
"Typing :: Typed",
|
|
28
|
+
]
|
|
29
|
+
dependencies = []
|
|
30
|
+
|
|
31
|
+
[project.scripts]
|
|
32
|
+
math-step-to-step = "math_step_to_step.cli:main"
|
|
33
|
+
|
|
34
|
+
[tool.setuptools.packages.find]
|
|
35
|
+
where = ["src"]
|
|
36
|
+
|
|
37
|
+
[tool.setuptools.package-data]
|
|
38
|
+
math_step_to_step = ["py.typed"]
|
|
39
|
+
|
|
40
|
+
[tool.pytest.ini_options]
|
|
41
|
+
testpaths = ["tests"]
|
|
42
|
+
pythonpath = ["src"]
|
masts-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: masts
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Step-by-step solutions for math expressions and equations (1 + 2 x 3 -> ['1 + 6', '7']), plus text-to-symbol helpers (6^6 -> 6⁶).
|
|
5
|
+
Author: PipoAndDodo
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: math,steps,solver,equation,calculator,superscript,education
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Education
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Education
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# math-step-to-step
|
|
26
|
+
|
|
27
|
+
Giải biểu thức / phương trình **từng bước** và trả về danh sách các bước.
|
|
28
|
+
Không phụ thuộc thư viện ngoài, dùng phân số chính xác (`fractions.Fraction`) nên không bị sai số.
|
|
29
|
+
|
|
30
|
+
*Step-by-step solver for math expressions and equations. Pure Python, zero dependencies, exact arithmetic.*
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install math-step-to-step
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Dùng nhanh
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from math_step_to_step import steps, solve, evaluate, prettify
|
|
40
|
+
|
|
41
|
+
steps("1 + 2 x 3") # ['1 + 6', '7']
|
|
42
|
+
steps("(1 + 2) x 3 + 4 x 5") # ['3 × 3 + 4 × 5', '9 + 20', '29']
|
|
43
|
+
steps("2 + 3 x (4 - 1)^2") # ['2 + 3 × 3²', '2 + 3 × 9', '2 + 27', '29']
|
|
44
|
+
steps("1/2 + 1/3") # ['1/2 + 1/3', '5/6']
|
|
45
|
+
|
|
46
|
+
# tìm x
|
|
47
|
+
steps("2x + 3 = 7") # ['2x = 7 - 3', '2x = 4', 'x = 4 ÷ 2', 'x = 2']
|
|
48
|
+
steps("2(x + 3) = 10") # ['2x + 6 = 10', '2x = 10 - 6', '2x = 4', 'x = 4 ÷ 2', 'x = 2']
|
|
49
|
+
steps("x^2 - 3x + 2 = 0") # a, b, c -> Δ -> x₁, x₂ (từng bước)
|
|
50
|
+
|
|
51
|
+
# kết quả có cấu trúc
|
|
52
|
+
sol = solve("x^2 - 3x + 2 = 0")
|
|
53
|
+
sol.kind, sol.values # ('roots', (2, 1))
|
|
54
|
+
|
|
55
|
+
evaluate("2 + 3 x 4") # 14 (nhanh, không tạo chuỗi bước)
|
|
56
|
+
|
|
57
|
+
# đổi chuỗi thành ký hiệu
|
|
58
|
+
prettify("6^6") # '6⁶'
|
|
59
|
+
prettify("x^2 + y^(n+1) <= sqrt(2)*pi") # 'x² + yⁿ⁺¹ ≤ √2×π'
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Cú pháp nhập
|
|
63
|
+
|
|
64
|
+
| Viết | Ý nghĩa |
|
|
65
|
+
|---|---|
|
|
66
|
+
| `+ - * x × · / ÷ :` | cộng, trừ, nhân, chia |
|
|
67
|
+
| `x` giữa hai toán hạng, vd `2 x 3` | **phép nhân**; còn `2x`, `x + 1`, `x²` thì `x` là **biến** |
|
|
68
|
+
| `^`, `**`, `²` `³` | lũy thừa (số mũ nguyên) |
|
|
69
|
+
| `sqrt(…)`, `√9` | căn bậc hai |
|
|
70
|
+
| `( )`, `[ ]`, `{ }` | ngoặc |
|
|
71
|
+
| `2x`, `3(x+1)`, `(a)(b)` | nhân ngầm |
|
|
72
|
+
| `1,5` hoặc `1.5` | số thập phân |
|
|
73
|
+
| `=` | phương trình (1 biến, bậc 1 hoặc 2) |
|
|
74
|
+
|
|
75
|
+
## Tùy chọn của `steps()` / `solve()`
|
|
76
|
+
|
|
77
|
+
| Tham số | Mặc định | Ý nghĩa |
|
|
78
|
+
|---|---|---|
|
|
79
|
+
| `include_original` | `False` | thêm biểu thức gốc làm bước đầu |
|
|
80
|
+
| `detailed` | `False` | mỗi bước chỉ làm 1 phép (`1+2+3` → `3 + 3` → `6`) thay vì gộp |
|
|
81
|
+
| `pretty` | `True` | dùng `× ÷ ² √`; `False` ra ASCII (`* / ^ sqrt()`), có thể đưa lại vào thư viện |
|
|
82
|
+
| `style` | `"auto"` | `"fraction"`, `"decimal"` hoặc `"auto"` (thập phân nếu đầu vào có số thập phân) |
|
|
83
|
+
| `lang` | `"vi"` | ngôn ngữ thông báo: `"vi"` / `"en"` |
|
|
84
|
+
|
|
85
|
+
Cách chọn bước: ngoặc trước → lũy thừa/căn → nhân chia → cộng trừ; các phép độc lập được làm **cùng một bước**
|
|
86
|
+
và chuỗi cộng/nhân liên tiếp được gộp để lời giải ngắn nhất. Với phương trình: rút gọn → chuyển vế → chia hệ số;
|
|
87
|
+
bậc 2 dùng Δ.
|
|
88
|
+
|
|
89
|
+
## Ký hiệu
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from math_step_to_step import superscript, subscript, prettify
|
|
93
|
+
superscript("123") # '¹²³'
|
|
94
|
+
subscript("12") # '₁₂'
|
|
95
|
+
prettify("H_2O, 6^6, x^(n+1), 1/2, a<=b, a!=b, +-3, alpha")
|
|
96
|
+
# 'H₂O, 6⁶, xⁿ⁺¹, ½, a≤b, a≠b, ±3, α'
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Giới hạn (cố ý, để ít lỗi)
|
|
100
|
+
Một biến; phương trình bậc ≤ 2; số mũ nguyên; không có số phức; không rút gọn căn phức tạp
|
|
101
|
+
(căn không chính phương được rút gọn dạng `2 × √3` và cho giá trị gần đúng). Đầu vào sai/không hỗ trợ
|
|
102
|
+
luôn ném `MathStepError` (kế thừa `ValueError`) với thông báo rõ ràng.
|
|
103
|
+
|
|
104
|
+
## Dòng lệnh
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
math-step-to-step "(1 + 2) x 3 + 4 x 5"
|
|
108
|
+
python -m math_step_to_step "2x + 3 = 7" --en
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
MIT License.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/masts.egg-info/PKG-INFO
|
|
5
|
+
src/masts.egg-info/SOURCES.txt
|
|
6
|
+
src/masts.egg-info/dependency_links.txt
|
|
7
|
+
src/masts.egg-info/entry_points.txt
|
|
8
|
+
src/masts.egg-info/top_level.txt
|
|
9
|
+
src/math_step_to_step/__init__.py
|
|
10
|
+
src/math_step_to_step/__main__.py
|
|
11
|
+
src/math_step_to_step/cli.py
|
|
12
|
+
src/math_step_to_step/context.py
|
|
13
|
+
src/math_step_to_step/engine.py
|
|
14
|
+
src/math_step_to_step/errors.py
|
|
15
|
+
src/math_step_to_step/fmt.py
|
|
16
|
+
src/math_step_to_step/nodes.py
|
|
17
|
+
src/math_step_to_step/parser.py
|
|
18
|
+
src/math_step_to_step/poly.py
|
|
19
|
+
src/math_step_to_step/py.typed
|
|
20
|
+
src/math_step_to_step/solver.py
|
|
21
|
+
src/math_step_to_step/symbols.py
|
|
22
|
+
tests/test_fuzz.py
|
|
23
|
+
tests/test_steps.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
math_step_to_step
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""math-step-to-step: step-by-step solutions for math expressions and equations."""
|
|
2
|
+
from .errors import MathStepError
|
|
3
|
+
from .solver import Solution, evaluate, solve, steps
|
|
4
|
+
from .symbols import prettify, subscript, superscript
|
|
5
|
+
|
|
6
|
+
__version__ = "0.1.0"
|
|
7
|
+
__all__ = [
|
|
8
|
+
"steps", "solve", "evaluate", "Solution", "MathStepError",
|
|
9
|
+
"superscript", "subscript", "prettify", "__version__",
|
|
10
|
+
]
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Command line: math-step-to-step "1 + 2 x 3"."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
from . import __version__
|
|
8
|
+
from .errors import MathStepError
|
|
9
|
+
from .solver import solve
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main(argv=None):
|
|
13
|
+
ap = argparse.ArgumentParser(prog="math-step-to-step", description=__doc__)
|
|
14
|
+
ap.add_argument("expression", nargs="*", help="expression; omit to read lines from stdin")
|
|
15
|
+
ap.add_argument("-d", "--detailed", action="store_true", help="one operation per step")
|
|
16
|
+
ap.add_argument("--ascii", action="store_true", help="plain ASCII output")
|
|
17
|
+
ap.add_argument("--en", action="store_true", help="English messages")
|
|
18
|
+
ap.add_argument("--style", choices=["auto", "fraction", "decimal"], default="auto")
|
|
19
|
+
ap.add_argument("-V", "--version", action="version", version=__version__)
|
|
20
|
+
a = ap.parse_args(argv)
|
|
21
|
+
|
|
22
|
+
lines = [" ".join(a.expression)] if a.expression else (l.strip() for l in sys.stdin)
|
|
23
|
+
code = 0
|
|
24
|
+
for line in lines:
|
|
25
|
+
if not line:
|
|
26
|
+
continue
|
|
27
|
+
try:
|
|
28
|
+
sol = solve(line, include_original=True, detailed=a.detailed,
|
|
29
|
+
pretty=not a.ascii, style=a.style, lang="en" if a.en else "vi")
|
|
30
|
+
except MathStepError as e:
|
|
31
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
32
|
+
code = 1
|
|
33
|
+
continue
|
|
34
|
+
print(sol.steps[0])
|
|
35
|
+
for s in sol.steps[1:]:
|
|
36
|
+
print(" →", s)
|
|
37
|
+
return code
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Options shared by the parser, engine and formatter."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from .errors import LANGS
|
|
5
|
+
|
|
6
|
+
MAX_LEN = 10_000 # max characters of input
|
|
7
|
+
MAX_BITS = 14_000 # max size of any intermediate number (~4200 digits)
|
|
8
|
+
MAX_DEG = 60 # max polynomial degree
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Ctx:
|
|
12
|
+
__slots__ = ("pretty", "detailed", "lang", "style", "decimal")
|
|
13
|
+
|
|
14
|
+
def __init__(self, pretty=True, detailed=False, lang="vi", style="auto"):
|
|
15
|
+
if lang not in LANGS:
|
|
16
|
+
raise ValueError(f"lang must be one of {LANGS}")
|
|
17
|
+
if style not in ("auto", "fraction", "decimal"):
|
|
18
|
+
raise ValueError("style must be 'auto', 'fraction' or 'decimal'")
|
|
19
|
+
self.pretty = bool(pretty)
|
|
20
|
+
self.detailed = bool(detailed)
|
|
21
|
+
self.lang = lang
|
|
22
|
+
self.style = style
|
|
23
|
+
self.decimal = style == "decimal"
|