rgwfuncs 0.0.33__tar.gz → 0.0.35__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rgwfuncs
3
- Version: 0.0.33
3
+ Version: 0.0.35
4
4
  Summary: A functional programming paradigm for mathematical modelling and data science
5
5
  Home-page: https://github.com/ryangerardwilson/rgwfunc
6
6
  Author: Ryan Gerard Wilson
@@ -135,7 +135,7 @@ To display all docstrings, use:
135
135
 
136
136
  --------------------------------------------------------------------------------
137
137
 
138
- ## Documentation Access Functions
138
+ ## Documentation Access
139
139
 
140
140
  ### 1. docs
141
141
  Print a list of available function names in alphabetical order. If a filter is provided, print the docstrings of functions containing the term.
@@ -150,6 +150,60 @@ Print a list of available function names in alphabetical order. If a filter is p
150
150
 
151
151
  --------------------------------------------------------------------------------
152
152
 
153
+ ## Interactive Shell
154
+
155
+ This section includes functions that facilitate launching an interactive Python shell to inspect and modify local variables within the user's environment.
156
+
157
+ ### 1. `interactive_shell`
158
+
159
+ Launches an interactive prompt for inspecting and modifying local variables, making all methods in the rgwfuncs library available by default. This REPL (Read-Eval-Print Loop) environment supports command history and autocompletion, making it easier to interact with your Python code. This function is particularly useful for debugging purposes when you want real-time interaction with your program's execution environment.
160
+
161
+ • Parameters:
162
+ - `local_vars` (dict, optional): A dictionary of local variables to be accessible within the interactive shell. If not provided, defaults to an empty dictionary.
163
+
164
+ • Usage:
165
+ - You can call this function to enter an interactive shell where you can view and modify the variables in the given local scope.
166
+
167
+ • Example:
168
+
169
+ from rgwfuncs import interactive_shell
170
+ import pandas as pd
171
+ import numpy as np
172
+
173
+ # Example DataFrame
174
+ df = pd.DataFrame({
175
+ 'id': [1, 2, 3, 4, 5],
176
+ 'name': ['Alice', 'Bob', 'Charlie', 'David', 'Eva'],
177
+ 'age': [30, 25, 35, 28, 22],
178
+ 'city': ['New York', 'Los Angeles', 'Chicago', 'San Francisco', 'Boston']
179
+ })
180
+
181
+ # Launch the interactive shell with local variables
182
+ interactive_shell(locals())
183
+
184
+ Subsequently, in the interactive shell you can use any library in your python file, as well as all rgwfuncs methods (even if they are not imported). Notice, that while pandas and numpy are available in the shell as a result of importing them in the above script, the rgwfuncs method `first_n_rows` was not imported - yet is available for use.
185
+
186
+ Welcome to the rgwfuncs interactive shell.
187
+ >>> pirst_n_rows(df, 2)
188
+ Traceback (most recent call last):
189
+ File "<console>", line 1, in <module>
190
+ NameError: name 'pirst_n_rows' is not defined. Did you mean: 'first_n_rows'?
191
+ >>> first_n_rows(df, 2)
192
+ {'age': '30', 'city': 'New York', 'id': '1', 'name': 'Alice'}
193
+ {'age': '25', 'city': 'Los Angeles', 'id': '2', 'name': 'Bob'}
194
+ >>> print(df)
195
+ id name age city
196
+ 0 1 Alice 30 New York
197
+ 1 2 Bob 25 Los Angeles
198
+ 2 3 Charlie 35 Chicago
199
+ 3 4 David 28 San Francisco
200
+ 4 5 Eva 22 Boston
201
+ >>> arr = np.array([1, 2, 3, 4, 5])
202
+ >>> arr
203
+ array([1, 2, 3, 4, 5])
204
+
205
+ --------------------------------------------------------------------------------
206
+
153
207
  ## Algebra Based Functions
154
208
 
155
209
  This section provides comprehensive functions for handling algebraic expressions, performing tasks such as computation, simplification, solving equations, and prime factorization, all outputted in LaTeX format.
@@ -109,7 +109,7 @@ To display all docstrings, use:
109
109
 
110
110
  --------------------------------------------------------------------------------
111
111
 
112
- ## Documentation Access Functions
112
+ ## Documentation Access
113
113
 
114
114
  ### 1. docs
115
115
  Print a list of available function names in alphabetical order. If a filter is provided, print the docstrings of functions containing the term.
@@ -124,6 +124,60 @@ Print a list of available function names in alphabetical order. If a filter is p
124
124
 
125
125
  --------------------------------------------------------------------------------
126
126
 
127
+ ## Interactive Shell
128
+
129
+ This section includes functions that facilitate launching an interactive Python shell to inspect and modify local variables within the user's environment.
130
+
131
+ ### 1. `interactive_shell`
132
+
133
+ Launches an interactive prompt for inspecting and modifying local variables, making all methods in the rgwfuncs library available by default. This REPL (Read-Eval-Print Loop) environment supports command history and autocompletion, making it easier to interact with your Python code. This function is particularly useful for debugging purposes when you want real-time interaction with your program's execution environment.
134
+
135
+ • Parameters:
136
+ - `local_vars` (dict, optional): A dictionary of local variables to be accessible within the interactive shell. If not provided, defaults to an empty dictionary.
137
+
138
+ • Usage:
139
+ - You can call this function to enter an interactive shell where you can view and modify the variables in the given local scope.
140
+
141
+ • Example:
142
+
143
+ from rgwfuncs import interactive_shell
144
+ import pandas as pd
145
+ import numpy as np
146
+
147
+ # Example DataFrame
148
+ df = pd.DataFrame({
149
+ 'id': [1, 2, 3, 4, 5],
150
+ 'name': ['Alice', 'Bob', 'Charlie', 'David', 'Eva'],
151
+ 'age': [30, 25, 35, 28, 22],
152
+ 'city': ['New York', 'Los Angeles', 'Chicago', 'San Francisco', 'Boston']
153
+ })
154
+
155
+ # Launch the interactive shell with local variables
156
+ interactive_shell(locals())
157
+
158
+ Subsequently, in the interactive shell you can use any library in your python file, as well as all rgwfuncs methods (even if they are not imported). Notice, that while pandas and numpy are available in the shell as a result of importing them in the above script, the rgwfuncs method `first_n_rows` was not imported - yet is available for use.
159
+
160
+ Welcome to the rgwfuncs interactive shell.
161
+ >>> pirst_n_rows(df, 2)
162
+ Traceback (most recent call last):
163
+ File "<console>", line 1, in <module>
164
+ NameError: name 'pirst_n_rows' is not defined. Did you mean: 'first_n_rows'?
165
+ >>> first_n_rows(df, 2)
166
+ {'age': '30', 'city': 'New York', 'id': '1', 'name': 'Alice'}
167
+ {'age': '25', 'city': 'Los Angeles', 'id': '2', 'name': 'Bob'}
168
+ >>> print(df)
169
+ id name age city
170
+ 0 1 Alice 30 New York
171
+ 1 2 Bob 25 Los Angeles
172
+ 2 3 Charlie 35 Chicago
173
+ 3 4 David 28 San Francisco
174
+ 4 5 Eva 22 Boston
175
+ >>> arr = np.array([1, 2, 3, 4, 5])
176
+ >>> arr
177
+ array([1, 2, 3, 4, 5])
178
+
179
+ --------------------------------------------------------------------------------
180
+
127
181
  ## Algebra Based Functions
128
182
 
129
183
  This section provides comprehensive functions for handling algebraic expressions, performing tasks such as computation, simplification, solving equations, and prime factorization, all outputted in LaTeX format.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "rgwfuncs"
7
- version = "0.0.33"
7
+ version = "0.0.35"
8
8
  authors = [
9
9
  { name = "Ryan Gerard Wilson", email = "ryangerardwilson@gmail.com" },
10
10
  ]
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = rgwfuncs
3
- version = 0.0.33
3
+ version = 0.0.35
4
4
  author = Ryan Gerard Wilson
5
5
  author_email = ryangerardwilson@gmail.com
6
6
  description = A functional programming paradigm for mathematical modelling and data science
@@ -4,4 +4,5 @@
4
4
  from .algebra_lib import compute_constant_expression, compute_constant_expression_involving_matrices, compute_constant_expression_involving_ordered_series, compute_prime_factors, python_polynomial_expression_to_latex, simplify_polynomial_expression, solve_homogeneous_polynomial_expression
5
5
  from .df_lib import append_columns, append_percentile_classification_column, append_ranged_classification_column, append_ranged_date_classification_column, append_rows, append_xgb_labels, append_xgb_logistic_regression_predictions, append_xgb_regression_predictions, bag_union_join, bottom_n_unique_values, cascade_sort, delete_rows, drop_duplicates, drop_duplicates_retain_first, drop_duplicates_retain_last, filter_dataframe, filter_indian_mobiles, first_n_rows, from_raw_data, insert_dataframe_in_sqlite_database, last_n_rows, left_join, limit_dataframe, load_data_from_path, load_data_from_query, load_data_from_sqlite_path, mask_against_dataframe, mask_against_dataframe_converse, numeric_clean, order_columns, print_correlation, print_dataframe, print_memory_usage, print_n_frequency_cascading, print_n_frequency_linear, rename_columns, retain_columns, right_join, send_data_to_email, send_data_to_slack, send_dataframe_via_telegram, sync_dataframe_to_sqlite_database, top_n_unique_values, union_join, update_rows
6
6
  from .docs_lib import docs
7
+ from .interactive_shell_lib import interactive_shell
7
8
  from .str_lib import send_telegram_message
@@ -76,7 +76,7 @@ def compute_constant_expression_involving_matrices(expression: str) -> str:
76
76
  Computes the result of a constant expression involving matrices and returns it as a LaTeX string.
77
77
 
78
78
  Parameters:
79
- expression (str): The constant expression involving matrices. Example format includes operations such as "+",
79
+ expression (str): The constant expression involving matrices. Example format includes operations such as "+",
80
80
  "-", "*", "/".
81
81
 
82
82
  Returns:
@@ -161,9 +161,9 @@ def compute_constant_expression_involving_matrices(expression: str) -> str:
161
161
 
162
162
  def compute_constant_expression_involving_ordered_series(expression: str) -> str:
163
163
  """
164
- Computes the result of a constant expression involving ordered series, and returns it as a Latex string.
164
+ Computes the result of a constant expression involving ordered series, and returns it as a Latex string.
165
165
  Supports operations lile "+", "-", "*", "/", as well as "dd()" (the discrete difference operator).
166
-
166
+
167
167
  The function first applies the discrete difference operator to any series where applicable, then evaluates
168
168
  arithmetic operations between series.
169
169
 
@@ -261,8 +261,6 @@ def compute_constant_expression_involving_ordered_series(expression: str) -> str
261
261
  return f"Error computing ordered series operation: {e}"
262
262
 
263
263
 
264
-
265
-
266
264
  def python_polynomial_expression_to_latex(
267
265
  expression: str,
268
266
  subs: Optional[Dict[str, float]] = None
@@ -549,5 +547,3 @@ def solve_homogeneous_polynomial_expression(
549
547
 
550
548
  except Exception as e:
551
549
  raise ValueError(f"Error solving the expression: {e}")
552
-
553
-
@@ -0,0 +1,32 @@
1
+ import code
2
+ import readline
3
+ import rlcompleter # noqa: F401
4
+ import sys # noqa: F401
5
+ from typing import Dict, Any
6
+ from .df_lib import * # noqa: F401, F403, E402
7
+ from .algebra_lib import * # noqa: F401, F403, E402
8
+ from .str_lib import * # noqa: F401, F403, E402
9
+ from .docs_lib import * # noqa: F401, F403, E402
10
+
11
+
12
+ def interactive_shell(local_vars: Dict[str, Any]) -> None:
13
+ """
14
+ Launches an interactive prompt for inspecting and modifying local variables, making all methods
15
+ in the rgwfuncs library available by default.
16
+
17
+ Parameters:
18
+ local_vars (dict): Dictionary of local variables to be available in the interactive shell.
19
+ """
20
+ if not isinstance(local_vars, dict):
21
+ raise TypeError("local_vars must be a dictionary")
22
+
23
+ readline.parse_and_bind("tab: complete")
24
+
25
+ # Make imported functions available in the REPL
26
+ local_vars.update(globals())
27
+
28
+ # Create interactive console with local context
29
+ console = code.InteractiveConsole(locals=local_vars)
30
+
31
+ # Start interactive session
32
+ console.interact(banner="Welcome to the rgwfuncs interactive shell.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rgwfuncs
3
- Version: 0.0.33
3
+ Version: 0.0.35
4
4
  Summary: A functional programming paradigm for mathematical modelling and data science
5
5
  Home-page: https://github.com/ryangerardwilson/rgwfunc
6
6
  Author: Ryan Gerard Wilson
@@ -135,7 +135,7 @@ To display all docstrings, use:
135
135
 
136
136
  --------------------------------------------------------------------------------
137
137
 
138
- ## Documentation Access Functions
138
+ ## Documentation Access
139
139
 
140
140
  ### 1. docs
141
141
  Print a list of available function names in alphabetical order. If a filter is provided, print the docstrings of functions containing the term.
@@ -150,6 +150,60 @@ Print a list of available function names in alphabetical order. If a filter is p
150
150
 
151
151
  --------------------------------------------------------------------------------
152
152
 
153
+ ## Interactive Shell
154
+
155
+ This section includes functions that facilitate launching an interactive Python shell to inspect and modify local variables within the user's environment.
156
+
157
+ ### 1. `interactive_shell`
158
+
159
+ Launches an interactive prompt for inspecting and modifying local variables, making all methods in the rgwfuncs library available by default. This REPL (Read-Eval-Print Loop) environment supports command history and autocompletion, making it easier to interact with your Python code. This function is particularly useful for debugging purposes when you want real-time interaction with your program's execution environment.
160
+
161
+ • Parameters:
162
+ - `local_vars` (dict, optional): A dictionary of local variables to be accessible within the interactive shell. If not provided, defaults to an empty dictionary.
163
+
164
+ • Usage:
165
+ - You can call this function to enter an interactive shell where you can view and modify the variables in the given local scope.
166
+
167
+ • Example:
168
+
169
+ from rgwfuncs import interactive_shell
170
+ import pandas as pd
171
+ import numpy as np
172
+
173
+ # Example DataFrame
174
+ df = pd.DataFrame({
175
+ 'id': [1, 2, 3, 4, 5],
176
+ 'name': ['Alice', 'Bob', 'Charlie', 'David', 'Eva'],
177
+ 'age': [30, 25, 35, 28, 22],
178
+ 'city': ['New York', 'Los Angeles', 'Chicago', 'San Francisco', 'Boston']
179
+ })
180
+
181
+ # Launch the interactive shell with local variables
182
+ interactive_shell(locals())
183
+
184
+ Subsequently, in the interactive shell you can use any library in your python file, as well as all rgwfuncs methods (even if they are not imported). Notice, that while pandas and numpy are available in the shell as a result of importing them in the above script, the rgwfuncs method `first_n_rows` was not imported - yet is available for use.
185
+
186
+ Welcome to the rgwfuncs interactive shell.
187
+ >>> pirst_n_rows(df, 2)
188
+ Traceback (most recent call last):
189
+ File "<console>", line 1, in <module>
190
+ NameError: name 'pirst_n_rows' is not defined. Did you mean: 'first_n_rows'?
191
+ >>> first_n_rows(df, 2)
192
+ {'age': '30', 'city': 'New York', 'id': '1', 'name': 'Alice'}
193
+ {'age': '25', 'city': 'Los Angeles', 'id': '2', 'name': 'Bob'}
194
+ >>> print(df)
195
+ id name age city
196
+ 0 1 Alice 30 New York
197
+ 1 2 Bob 25 Los Angeles
198
+ 2 3 Charlie 35 Chicago
199
+ 3 4 David 28 San Francisco
200
+ 4 5 Eva 22 Boston
201
+ >>> arr = np.array([1, 2, 3, 4, 5])
202
+ >>> arr
203
+ array([1, 2, 3, 4, 5])
204
+
205
+ --------------------------------------------------------------------------------
206
+
153
207
  ## Algebra Based Functions
154
208
 
155
209
  This section provides comprehensive functions for handling algebraic expressions, performing tasks such as computation, simplification, solving equations, and prime factorization, all outputted in LaTeX format.
@@ -6,11 +6,11 @@ src/rgwfuncs/__init__.py
6
6
  src/rgwfuncs/algebra_lib.py
7
7
  src/rgwfuncs/df_lib.py
8
8
  src/rgwfuncs/docs_lib.py
9
+ src/rgwfuncs/interactive_shell_lib.py
9
10
  src/rgwfuncs/str_lib.py
10
11
  src/rgwfuncs.egg-info/PKG-INFO
11
12
  src/rgwfuncs.egg-info/SOURCES.txt
12
13
  src/rgwfuncs.egg-info/dependency_links.txt
13
14
  src/rgwfuncs.egg-info/entry_points.txt
14
15
  src/rgwfuncs.egg-info/requires.txt
15
- src/rgwfuncs.egg-info/top_level.txt
16
- tests/test_algebra_lib.py
16
+ src/rgwfuncs.egg-info/top_level.txt
@@ -1,144 +0,0 @@
1
- import sys
2
- import os
3
- import math
4
-
5
- # flake8: noqa: E402
6
- # Allow the following import statement to be AFTER sys.path modifications
7
- sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
8
-
9
- from src.rgwfuncs.algebra_lib import (
10
- compute_prime_factors,
11
- compute_constant_expression,
12
- compute_constant_expression_involving_matrices,
13
- compute_constant_expression_involving_ordered_series,
14
- python_polynomial_expression_to_latex,
15
- simplify_polynomial_expression,
16
- solve_homogeneous_polynomial_expression)
17
-
18
-
19
- def test_compute_prime_factors():
20
- test_cases = [
21
- (100, "2^{2} \\cdot 5^{2}"),
22
- (60, "2^{2} \\cdot 3 \\cdot 5"),
23
- (45, "3^{2} \\cdot 5"),
24
- (1, ""), # Handle case with 1, which has no prime factors
25
- (17, "17") # Prime number itself
26
- ]
27
-
28
- for n, expected_output in test_cases:
29
- result = compute_prime_factors(n)
30
- assert result == expected_output, f"Failed for {n}, got {result}"
31
-
32
-
33
- def test_compute_constant_expression():
34
- test_cases = [
35
- ("2 + 2", 4.0),
36
- ("5 - 3", 2.0),
37
- ("3 * 3", 9.0),
38
- ("8 / 2", 4.0),
39
- ("10 % 3", 1.0),
40
- ("math.gcd(36, 60) * math.sin(math.radians(45)) * 10000", 84852.8137423857),
41
- # ("np.diff([2,6,9,60])", r"\left[\begin{matrix}4\\3\\51\end{matrix}\right]"),
42
- ]
43
-
44
- for input_data, expected_output in test_cases:
45
- result = compute_constant_expression(input_data)
46
- assert math.isclose(result, expected_output, rel_tol=1e-9), f"Failed for {input_data}, got {result}"
47
-
48
- def test_compute_constant_expression_involving_matrices():
49
- test_cases = [
50
- ("[[2, 6, 9],[1, 3, 5]] + [[1, 2, 3],[4, 5, 6]]", r"\begin{bmatrix}3 & 8 & 12\\5 & 8 & 11\end{bmatrix}"),
51
- ("[[10, 10, 10],[2, 4, 6]] - [[5, 3, 2],[1, 2, 1]]", r"\begin{bmatrix}5 & 7 & 8\\1 & 2 & 5\end{bmatrix}"),
52
- ("[[2, 4],[6, 8]] * [[1, 0.5],[2, 0.25]]", r"\begin{bmatrix}2 & 2.0\\12 & 2.0\end{bmatrix}"),
53
- ("[[8, 16],[32, 64]] / [[2, 2],[8, 16]]", r"\begin{bmatrix}4.0 & 8.0\\4.0 & 4.0\end{bmatrix}"),
54
- ("[[2, 6, 9], [1, 3, 5]] + [[1, 2, 3], [4, 5, 6]] - [[1, 1, 1], [1, 1, 1]]", r"\begin{bmatrix}2 & 7 & 11\\4 & 7 & 10\end{bmatrix}"),
55
- ("[2, 6, 9] + [1, 2, 3] - [1, 1, 1]", r"\begin{bmatrix}2 & 7 & 11\end{bmatrix}"),
56
- ("[[1, 2], [3, 4]] + [[2, 3], [4, 5]] + [[1, 1], [1, 1]]", r"\begin{bmatrix}4 & 6\\8 & 10\end{bmatrix}"),
57
- ("[3, 6, 9] - [1, 2, 3] + [5, 5, 5]", r"\begin{bmatrix}7 & 9 & 11\end{bmatrix}"),
58
- ("[3, 6, 9] - [1, 2, 3, 4]", r"Operations between matrices must involve matrices of the same dimension"),
59
-
60
- # Edge cases
61
- ("[]", r"\begin{bmatrix}\end{bmatrix}"), # Empty list
62
- ("[5]", r"\begin{bmatrix}5\end{bmatrix}"), # Single-element list
63
- ]
64
-
65
- for input_data, expected_output in test_cases:
66
- result = compute_constant_expression_involving_matrices(input_data)
67
- assert result == expected_output, f"Failed for {input_data}, got {result}"
68
-
69
- # Example test function
70
-
71
-
72
- def test_compute_constant_expression_involving_ordered_series():
73
- test_cases = [
74
- ("[2, 6, 9] + [1, 2, 3]", "[3, 8, 12]"),
75
- ("[10, 15, 21] - [5, 5, 5]", "[5, 10, 16]"),
76
- ("[2, 4, 6] * [1, 2, 3]", "[2, 8, 18]"),
77
- ("[8, 16, 32] / [2, 2, 8]", "[4.0, 8.0, 4.0]"),
78
- ("dd([2, 6, 9, 60]) + dd([78, 79, 80])", "Operations between ordered series must involve series of equal length"),
79
- ("dd([1, 3, 6, 10]) - dd([0, 1, 1, 2])", "[1, 3, 3]"),
80
-
81
- # Edge cases
82
- ("dd([1])", "[]"), # Single-element list, becomes empty
83
- ("dd([])", "[]"), # Empty list case
84
- ("[5]", "[5]"), # Single-element list, unchanged
85
- ("[]", "[]"), # Empty list
86
- ("[4, 3, 51] + [1, 1]", "Operations between ordered series must involve series of equal length"), # Test unequal lengths
87
- ]
88
-
89
- for input_data, expected_output in test_cases:
90
- result = compute_constant_expression_involving_ordered_series(input_data)
91
- assert result == expected_output, f"Failed for {input_data}, got {result}"
92
-
93
-
94
- def test_python_polynomial_expression_to_latex():
95
- test_cases = [
96
- # Without substitutions
97
- ("x**2 + y**2", None, r"x^{2} + y^{2}"),
98
- ("3*a + 4*b", None, r"3 a + 4 b"),
99
- ("3*x**3 / (7*y*m**(n+2) + 103)", None, r"\frac{3 x^{3}}{7 m^{n + 2} y + 103}"),
100
-
101
- # With substitutions
102
- ("x**2 + y**2", {"x": 3, "y": 4}, r"25"),
103
- ("x**2 + y**2", {"x": 3}, r"y^{2} + 9"),
104
- ("a*b + b", {"b": 2}, r"2 a + 2"),
105
- ("sin(x+z**2) + cos(y)", {"x": 55}, r"cos y + sin \left(z^{2} + 55\right)"),
106
- ("sin(x) + cos(y)", {"x": 0}, r"cos y")
107
- ]
108
-
109
- for expression, subs, expected_output in test_cases:
110
- output = python_polynomial_expression_to_latex(expression, subs)
111
- assert output == expected_output, (
112
- f"Test failed for expression: {expression} with substitutions: {subs}. "
113
- f"Expected {expected_output}, got {output}"
114
- )
115
-
116
-
117
-
118
- def test_simplify_polynomial_expression():
119
- test_cases = [
120
- # Without substitutions
121
- (("(np.diff(3*x**8)) / (np.diff(8*x**30) * 11*y**3)", None), r"\frac{1}{110 x^{22} y^{3}}"),
122
-
123
- # With substitutions
124
- (("x**2 + y**2", {"x": 3, "y": 4}), "25"),
125
- (("a*b + b", {"b": 2}), r"2 a + 2"), # Assumes no simplification of `a*b`
126
- (("(x**2 + y**2 + z**2)", {"x": 1, "y": 0, "z": 0}), "1")
127
- ]
128
-
129
- for (expression, subs), expected_output in test_cases:
130
- output = simplify_polynomial_expression(expression, subs)
131
- assert output == expected_output, (f"Test failed for expression: {expression} with substitutions: {subs}. Expected {expected_output}, got {output}")
132
-
133
-
134
- def test_solve_homogeneous_polynomial_expression():
135
- test_cases = [
136
- # Test case with substitutions
137
- (("a*x**2 + b*x + c", "x", {"a": 3, "b": 7, "c": 5}), r"\left[-7/6 - sqrt(11)*I/6, -7/6 + sqrt(11)*I/6\right]"),
138
- ]
139
-
140
- for (expression, variable, subs), expected_output in test_cases:
141
- assert solve_homogeneous_polynomial_expression(expression, variable, subs) == expected_output
142
-
143
-
144
-
File without changes