mathparse 0.2.7__tar.gz → 0.2.9__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.
- {mathparse-0.2.7 → mathparse-0.2.9}/PKG-INFO +2 -2
- {mathparse-0.2.7 → mathparse-0.2.9}/mathparse/__init__.py +1 -1
- {mathparse-0.2.7 → mathparse-0.2.9}/mathparse/mathparse.py +18 -8
- {mathparse-0.2.7 → mathparse-0.2.9}/mathparse/mathwords.py +2 -2
- {mathparse-0.2.7 → mathparse-0.2.9}/mathparse.egg-info/PKG-INFO +2 -2
- {mathparse-0.2.7 → mathparse-0.2.9}/pyproject.toml +1 -1
- {mathparse-0.2.7 → mathparse-0.2.9}/tests/test_complex_statements.py +2 -2
- {mathparse-0.2.7 → mathparse-0.2.9}/tests/test_unary_operations.py +35 -0
- {mathparse-0.2.7 → mathparse-0.2.9}/LICENSE +0 -0
- {mathparse-0.2.7 → mathparse-0.2.9}/README.md +0 -0
- {mathparse-0.2.7 → mathparse-0.2.9}/mathparse.egg-info/SOURCES.txt +0 -0
- {mathparse-0.2.7 → mathparse-0.2.9}/mathparse.egg-info/dependency_links.txt +0 -0
- {mathparse-0.2.7 → mathparse-0.2.9}/mathparse.egg-info/requires.txt +0 -0
- {mathparse-0.2.7 → mathparse-0.2.9}/mathparse.egg-info/top_level.txt +0 -0
- {mathparse-0.2.7 → mathparse-0.2.9}/setup.cfg +0 -0
- {mathparse-0.2.7 → mathparse-0.2.9}/tests/test_binary_operations.py +0 -0
- {mathparse-0.2.7 → mathparse-0.2.9}/tests/test_language_support.py +0 -0
- {mathparse-0.2.7 → mathparse-0.2.9}/tests/test_prefix_unary_operations.py +0 -0
- {mathparse-0.2.7 → mathparse-0.2.9}/tests/test_replace_word_tokens.py +0 -0
- {mathparse-0.2.7 → mathparse-0.2.9}/tests/test_simplified_chinese.py +0 -0
- {mathparse-0.2.7 → mathparse-0.2.9}/tests/test_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mathparse
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.9
|
|
4
4
|
Summary: mathparse is a library for solving mathematical equations contained in strings
|
|
5
5
|
Author: Gunther Cox
|
|
6
6
|
License-Expression: MIT
|
|
@@ -16,7 +16,7 @@ Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
|
16
16
|
Classifier: Topic :: Text Processing :: General
|
|
17
17
|
Classifier: Topic :: Text Processing :: Linguistic
|
|
18
18
|
Classifier: Programming Language :: Python
|
|
19
|
-
Requires-Python: <3.15,>=3.
|
|
19
|
+
Requires-Python: <3.15,>=3.10
|
|
20
20
|
Description-Content-Type: text/markdown
|
|
21
21
|
License-File: LICENSE
|
|
22
22
|
Provides-Extra: test
|
|
@@ -466,17 +466,21 @@ def to_postfix(tokens: list) -> list:
|
|
|
466
466
|
"""
|
|
467
467
|
precedence = {
|
|
468
468
|
'.': 5,
|
|
469
|
-
'
|
|
470
|
-
'
|
|
471
|
-
'
|
|
472
|
-
'
|
|
473
|
-
'
|
|
469
|
+
'^': 4,
|
|
470
|
+
'/': 3,
|
|
471
|
+
'*': 3,
|
|
472
|
+
'+': 2,
|
|
473
|
+
'-': 2,
|
|
474
474
|
'(': 1
|
|
475
475
|
}
|
|
476
476
|
|
|
477
477
|
# Unary functions have a higher precedence than binary operators
|
|
478
478
|
unary_precedence = max(precedence.values()) + 1
|
|
479
479
|
|
|
480
|
+
# Right-associative operators use strict inequality when popping,
|
|
481
|
+
# so that e.g. 2^3^2 evaluates as 2^(3^2) = 512, not (2^3)^2 = 64
|
|
482
|
+
right_associative = {'^'}
|
|
483
|
+
|
|
480
484
|
postfix = []
|
|
481
485
|
opstack = []
|
|
482
486
|
|
|
@@ -497,12 +501,18 @@ def to_postfix(tokens: list) -> list:
|
|
|
497
501
|
postfix.append(top_token)
|
|
498
502
|
top_token = opstack.pop()
|
|
499
503
|
elif is_binary(token):
|
|
500
|
-
#
|
|
501
|
-
#
|
|
504
|
+
# Pop operators with higher precedence, or equal precedence when
|
|
505
|
+
# the current token is left-associative (right-associative
|
|
506
|
+
# operators like ^ only yield to strictly higher precedence so
|
|
507
|
+
# that 2^3^2 = 2^(3^2) = 512 rather than (2^3)^2 = 64).
|
|
508
|
+
is_left_assoc = token not in right_associative
|
|
502
509
|
while (opstack != []) and (
|
|
503
510
|
(
|
|
504
511
|
opstack[-1] in precedence and token in precedence and (
|
|
505
|
-
precedence[opstack[-1]]
|
|
512
|
+
precedence[opstack[-1]] > precedence[token] or (
|
|
513
|
+
is_left_assoc and
|
|
514
|
+
precedence[opstack[-1]] == precedence[token]
|
|
515
|
+
)
|
|
506
516
|
)
|
|
507
517
|
) or
|
|
508
518
|
(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mathparse
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.9
|
|
4
4
|
Summary: mathparse is a library for solving mathematical equations contained in strings
|
|
5
5
|
Author: Gunther Cox
|
|
6
6
|
License-Expression: MIT
|
|
@@ -16,7 +16,7 @@ Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
|
16
16
|
Classifier: Topic :: Text Processing :: General
|
|
17
17
|
Classifier: Topic :: Text Processing :: Linguistic
|
|
18
18
|
Classifier: Programming Language :: Python
|
|
19
|
-
Requires-Python: <3.15,>=3.
|
|
19
|
+
Requires-Python: <3.15,>=3.10
|
|
20
20
|
Description-Content-Type: text/markdown
|
|
21
21
|
License-File: LICENSE
|
|
22
22
|
Provides-Extra: test
|
|
@@ -12,7 +12,7 @@ version = {attr = "mathparse.__version__"}
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "mathparse"
|
|
15
|
-
requires-python = ">=3.
|
|
15
|
+
requires-python = ">=3.10,<3.15"
|
|
16
16
|
urls = { Documentation = "https://mathparse.chatterbot.us", Repository = "https://github.com/gunthercox/mathparse", Changelog = "https://github.com/gunthercox/mathparse/releases" }
|
|
17
17
|
authors = [
|
|
18
18
|
{name = "Gunther Cox"},
|
|
@@ -70,11 +70,11 @@ class ComplexStatementsTestCase(TestCase):
|
|
|
70
70
|
Test using the unicode π symbol as a constant.
|
|
71
71
|
"""
|
|
72
72
|
result = mathparse.parse('2 * π')
|
|
73
|
-
self.assertAlmostEqual(result, 2 * 3.
|
|
73
|
+
self.assertAlmostEqual(result, 2 * 3.141593, places=5)
|
|
74
74
|
|
|
75
75
|
def test_unicode_pi_in_expression(self):
|
|
76
76
|
"""
|
|
77
77
|
Test using the unicode π symbol in a complex expression.
|
|
78
78
|
"""
|
|
79
79
|
result = mathparse.parse('π + 1')
|
|
80
|
-
self.assertAlmostEqual(result, 3.
|
|
80
|
+
self.assertAlmostEqual(result, 3.141593 + 1, places=5)
|
|
@@ -10,6 +10,33 @@ class UnaryOperatorTestCase(TestCase):
|
|
|
10
10
|
|
|
11
11
|
self.assertEqual(result, 256)
|
|
12
12
|
|
|
13
|
+
def test_exponent_precedence_over_addition_and_multiplication(self):
|
|
14
|
+
"""
|
|
15
|
+
Exponentiation must bind tighter than + and *.
|
|
16
|
+
2 ^ 3 + 4 * 5 = (2^3) + (4*5) = 8 + 20 = 28
|
|
17
|
+
"""
|
|
18
|
+
result = mathparse.parse('2 ^ 3 + 4 * 5')
|
|
19
|
+
|
|
20
|
+
self.assertEqual(result, 28)
|
|
21
|
+
|
|
22
|
+
def test_exponent_precedence_mixed_expression(self):
|
|
23
|
+
"""
|
|
24
|
+
Exponentiation must bind tighter than * and +.
|
|
25
|
+
2 + 3 * 4 ^ 5 = 2 + 3 * (4^5) = 2 + 3*1024 = 3074
|
|
26
|
+
"""
|
|
27
|
+
result = mathparse.parse('2 + 3 * 4 ^ 5')
|
|
28
|
+
|
|
29
|
+
self.assertEqual(result, 3074)
|
|
30
|
+
|
|
31
|
+
def test_exponent_right_associative(self):
|
|
32
|
+
"""
|
|
33
|
+
Exponentiation is right-associative: 2^3^2 = 2^(3^2) = 512,
|
|
34
|
+
not (2^3)^2 = 64.
|
|
35
|
+
"""
|
|
36
|
+
result = mathparse.parse('2 ^ 3 ^ 2')
|
|
37
|
+
|
|
38
|
+
self.assertEqual(result, 512)
|
|
39
|
+
|
|
13
40
|
def test_without_unary_operator_fre(self):
|
|
14
41
|
result = mathparse.parse('50 * (85 / 100)', language='FRE')
|
|
15
42
|
self.assertEqual(result, 42.5)
|
|
@@ -37,6 +64,14 @@ class UnaryWordOperatorTestCase(TestCase):
|
|
|
37
64
|
|
|
38
65
|
self.assertEqual(result, 2)
|
|
39
66
|
|
|
67
|
+
def test_square_root_with_decimal(self):
|
|
68
|
+
mathparse.parse('sqrt(4) . 5')
|
|
69
|
+
|
|
70
|
+
# TODO: Should this raise a parsing error instead of
|
|
71
|
+
# returning a number (2.5)?
|
|
72
|
+
|
|
73
|
+
raise self.skipTest('Skip until decision is made on expected behavior')
|
|
74
|
+
|
|
40
75
|
def test_negative_number(self):
|
|
41
76
|
result = mathparse.parse('-4 + 2')
|
|
42
77
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|