rgwfuncs 0.0.28__tar.gz → 0.0.29__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.
- {rgwfuncs-0.0.28/src/rgwfuncs.egg-info → rgwfuncs-0.0.29}/PKG-INFO +54 -66
- {rgwfuncs-0.0.28 → rgwfuncs-0.0.29}/README.md +53 -65
- {rgwfuncs-0.0.28 → rgwfuncs-0.0.29}/pyproject.toml +1 -1
- {rgwfuncs-0.0.28 → rgwfuncs-0.0.29}/setup.cfg +1 -1
- {rgwfuncs-0.0.28 → rgwfuncs-0.0.29}/src/rgwfuncs/__init__.py +1 -1
- {rgwfuncs-0.0.28 → rgwfuncs-0.0.29}/src/rgwfuncs/algebra_lib.py +27 -22
- {rgwfuncs-0.0.28 → rgwfuncs-0.0.29/src/rgwfuncs.egg-info}/PKG-INFO +54 -66
- {rgwfuncs-0.0.28 → rgwfuncs-0.0.29}/tests/test_algebra_lib.py +18 -23
- {rgwfuncs-0.0.28 → rgwfuncs-0.0.29}/LICENSE +0 -0
- {rgwfuncs-0.0.28 → rgwfuncs-0.0.29}/src/rgwfuncs/df_lib.py +0 -0
- {rgwfuncs-0.0.28 → rgwfuncs-0.0.29}/src/rgwfuncs/docs_lib.py +0 -0
- {rgwfuncs-0.0.28 → rgwfuncs-0.0.29}/src/rgwfuncs/str_lib.py +0 -0
- {rgwfuncs-0.0.28 → rgwfuncs-0.0.29}/src/rgwfuncs.egg-info/SOURCES.txt +0 -0
- {rgwfuncs-0.0.28 → rgwfuncs-0.0.29}/src/rgwfuncs.egg-info/dependency_links.txt +0 -0
- {rgwfuncs-0.0.28 → rgwfuncs-0.0.29}/src/rgwfuncs.egg-info/entry_points.txt +0 -0
- {rgwfuncs-0.0.28 → rgwfuncs-0.0.29}/src/rgwfuncs.egg-info/requires.txt +0 -0
- {rgwfuncs-0.0.28 → rgwfuncs-0.0.29}/src/rgwfuncs.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: rgwfuncs
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.29
|
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
|
@@ -154,105 +154,97 @@ Print a list of available function names in alphabetical order. If a filter is p
|
|
154
154
|
|
155
155
|
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.
|
156
156
|
|
157
|
-
### 1. `
|
157
|
+
### 1. `compute_constant_expression`
|
158
158
|
|
159
|
-
Evaluates
|
159
|
+
Computes the numerical result of a given expression, which can evaluate to a constant, represented as a float. Evaluates an constant expression provided as a string and returns the computed result. Supports various arithmetic operations, including addition, subtraction, multiplication, division, and modulo, as well as mathematical functions from the math module.
|
160
160
|
|
161
|
-
|
162
|
-
- `expression` (str):
|
161
|
+
• Parameters:
|
162
|
+
- `expression` (str): The constant expression to compute. This should be a string consisting of arithmetic operations and Python's math module functions.
|
163
163
|
|
164
|
-
|
164
|
+
• Returns:
|
165
165
|
- `float`: The computed numerical result.
|
166
166
|
|
167
|
-
|
167
|
+
• Example:
|
168
168
|
|
169
|
-
from rgwfuncs import
|
170
|
-
result1 =
|
169
|
+
from rgwfuncs import compute_constant_expression
|
170
|
+
result1 = compute_constant_expression("2 + 2")
|
171
171
|
print(result1) # Output: 4.0
|
172
172
|
|
173
|
-
result2 =
|
173
|
+
result2 = compute_constant_expression("10 % 3")
|
174
174
|
print(result2) # Output: 1.0
|
175
175
|
|
176
|
-
result3 =
|
176
|
+
result3 = compute_constant_expression("math.gcd(36, 60) * math.sin(math.radians(45)) * 10000")
|
177
177
|
print(result3) # Output: 84852.8137423857
|
178
178
|
|
179
|
-
These examples illustrate the ability to handle basic arithmetic, the modulo operator, and functions utilizing the Python math module.
|
180
|
-
|
181
179
|
--------------------------------------------------------------------------------
|
182
180
|
|
183
|
-
### 2. `
|
181
|
+
### 2. `simplify_polynomial_expression`
|
184
182
|
|
185
|
-
Simplifies
|
183
|
+
Simplifies an algebraic expression in polynomial form and returns it in LaTeX format. Takes an algebraic expression, in polynomial form, written in Python syntax and simplifies it. The result is returned as a LaTeX formatted string, suitable for academic or professional documentation.
|
186
184
|
|
187
|
-
|
188
|
-
- `expression` (str):
|
185
|
+
• Parameters:
|
186
|
+
- `expression` (str): The algebraic expression, in polynomial form, to simplify. For instance, the expression 'np.diff(8*x**30) where as 'np.diff([2,5,9,11)' is not a polynomial.
|
189
187
|
- `subs` (Optional[Dict[str, float]]): An optional dictionary of substitutions where keys are variable names and values are the numbers to substitute them with.
|
190
188
|
|
191
|
-
|
189
|
+
• Returns:
|
192
190
|
- `str`: The simplified expression formatted as a LaTeX string.
|
193
191
|
|
194
|
-
|
192
|
+
• Example Usage:
|
195
193
|
|
196
|
-
from rgwfuncs import
|
194
|
+
from rgwfuncs import simplify_polynomial_expression
|
197
195
|
|
198
196
|
# Example 1: Simplifying a polynomial expression without substitutions
|
199
|
-
simplified_expr1 =
|
197
|
+
simplified_expr1 = simplify_polynomial_expression("2*x + 3*x")
|
200
198
|
print(simplified_expr1) # Output: "5 x"
|
201
199
|
|
202
200
|
# Example 2: Simplifying a complex expression involving derivatives
|
203
|
-
simplified_expr2 =
|
204
|
-
"(np.diff(3*x**8)) / (np.diff(8*x**30) * 11*y**3)"
|
205
|
-
)
|
201
|
+
simplified_expr2 = simplify_polynomial_expression("(np.diff(3*x**8)) / (np.diff(8*x**30) * 11*y**3)")
|
206
202
|
print(simplified_expr2) # Output: r"\frac{1}{110 x^{22} y^{3}}"
|
207
203
|
|
208
204
|
# Example 3: Simplifying with substitutions
|
209
|
-
simplified_expr3 =
|
205
|
+
simplified_expr3 = simplify_polynomial_expression("x**2 + y**2", subs={"x": 3, "y": 4})
|
210
206
|
print(simplified_expr3) # Output: "25"
|
211
207
|
|
212
208
|
# Example 4: Simplifying with partial substitution
|
213
|
-
simplified_expr4 =
|
214
|
-
print(simplified_expr4) # Output: "a
|
215
|
-
|
216
|
-
These examples demonstrate the simplification of polynomial expressions, handling complex ratios involving derivatives, and applying variable substitutions before simplifying. The function handles expressions both with and without substitutions, providing flexibility in its usage.
|
209
|
+
simplified_expr4 = simplify_polynomial_expression("a*b + b", subs={"b": 2})
|
210
|
+
print(simplified_expr4) # Output: "2 a + 2"
|
217
211
|
|
218
212
|
--------------------------------------------------------------------------------
|
219
213
|
|
220
|
-
### 3. `
|
214
|
+
### 3. `solve_homogeneous_polynomial_expression`
|
221
215
|
|
222
|
-
Solves equations for specified variables, with optional substitutions, returning LaTeX-formatted solutions.
|
216
|
+
Solves a homogeneous polynomial expression for a specified variable and returns solutions in LaTeX format. Assumes that the expression is homoegeneous (i.e. equal to zero), and solves for a designated variable. May optionally include substitutions for other variables in the equation. The solutions are provided as a LaTeX formatted string. The method solves equations for specified variables, with optional substitutions, returning LaTeX-formatted solutions.
|
223
217
|
|
224
|
-
|
225
|
-
- `expression` (str): A string of the
|
218
|
+
• Parameters:
|
219
|
+
- `expression` (str): A string of the homogeneous polynomial expression to solve.
|
226
220
|
- `variable` (str): The variable to solve for.
|
227
221
|
- `subs` (Optional[Dict[str, float]]): Substitutions for variables.
|
228
222
|
|
229
|
-
|
223
|
+
• Returns:
|
230
224
|
- `str`: Solutions formatted in LaTeX.
|
231
225
|
|
232
|
-
|
226
|
+
• Example:
|
233
227
|
|
234
|
-
from rgwfuncs import
|
235
|
-
solutions1 =
|
228
|
+
from rgwfuncs import solve_homogeneous_polynomial_expression
|
229
|
+
solutions1 = solve_homogeneous_polynomial_expression("a*x**2 + b*x + c", "x", {"a": 3, "b": 7, "c": 5})
|
236
230
|
print(solutions1) # Output: "\left[-7/6 - sqrt(11)*I/6, -7/6 + sqrt(11)*I/6\right]"
|
237
231
|
|
238
|
-
solutions2 =
|
232
|
+
solutions2 = solve_homogeneous_polynomial_expression("x**2 - 4", "x")
|
239
233
|
print(solutions2) # Output: "\left[-2, 2\right]"
|
240
234
|
|
241
|
-
Here, we solve both a quadratic equation with complex solutions and a simpler polynomial equation.
|
242
|
-
|
243
235
|
--------------------------------------------------------------------------------
|
244
236
|
|
245
237
|
### 4. `get_prime_factors_latex`
|
246
238
|
|
247
239
|
Computes prime factors of a number and presents them in LaTeX format.
|
248
240
|
|
249
|
-
|
241
|
+
• Parameters:
|
250
242
|
- `n` (int): The integer to factorize.
|
251
243
|
|
252
|
-
|
244
|
+
• Returns:
|
253
245
|
- `str`: Prime factorization in LaTeX.
|
254
246
|
|
255
|
-
|
247
|
+
• Example:
|
256
248
|
|
257
249
|
from rgwfuncs import get_prime_factors_latex
|
258
250
|
factors1 = get_prime_factors_latex(100)
|
@@ -266,64 +258,60 @@ Computes prime factors of a number and presents them in LaTeX format.
|
|
266
258
|
|
267
259
|
--------------------------------------------------------------------------------
|
268
260
|
|
269
|
-
### 5. `
|
261
|
+
### 5. `compute_matrix_expression`
|
270
262
|
|
271
|
-
Computes the results of 1D or 2D matrix operations and formats them as LaTeX strings.
|
263
|
+
Computes the results of expressions containing 1D or 2D matrix operations and formats them as LaTeX strings.
|
272
264
|
|
273
|
-
|
265
|
+
• Parameters:
|
274
266
|
- `expression` (str): A string representing a sequence of matrix operations involving either 1D or 2D lists. Supported operations include addition (`+`), subtraction (`-`), multiplication (`*`), and division (`/`).
|
275
267
|
|
276
|
-
|
268
|
+
• Returns:
|
277
269
|
- `str`: The LaTeX-formatted string representation of the computed matrix, or an error message if the operations cannot be performed due to dimensional mismatches.
|
278
270
|
|
279
|
-
|
271
|
+
• Example:
|
280
272
|
|
281
|
-
from rgwfuncs import
|
273
|
+
from rgwfuncs import compute_matrix_expression
|
282
274
|
|
283
275
|
# Example with addition of 2D matrices
|
284
|
-
result =
|
276
|
+
result = compute_matrix_expression("[[2, 6, 9], [1, 3, 5]] + [[1, 2, 3], [4, 5, 6]]")
|
285
277
|
print(result) # Output: \begin{bmatrix}3 & 8 & 12\\5 & 8 & 11\end{bmatrix}
|
286
278
|
|
287
279
|
# Example of mixed operations with 1D matrices treated as 2D
|
288
|
-
result =
|
280
|
+
result = compute_matrix_expression("[3, 6, 9] + [1, 2, 3] - [2, 2, 2]")
|
289
281
|
print(result) # Output: \begin{bmatrix}2 & 6 & 10\end{bmatrix}
|
290
282
|
|
291
283
|
# Example with dimension mismatch
|
292
|
-
result =
|
284
|
+
result = compute_matrix_expression("[[4, 3, 51]] + [[1, 1]]")
|
293
285
|
print(result) # Output: Operations between matrices must involve matrices of the same dimension
|
294
286
|
|
295
|
-
This function performs elementwise operations on both 1D and 2D matrices represented as Python lists and formats the result as a LaTeX string. It handles operations sequentially from left to right and gracefully handles dimension mismatches by returning a meaningful message. It utilizes Python's `ast.literal_eval` for safe and robust parsing.
|
296
|
-
|
297
287
|
--------------------------------------------------------------------------------
|
298
288
|
|
299
|
-
### 6. `
|
289
|
+
### 6. `compute_ordered_series_expression`
|
300
290
|
|
301
|
-
Computes the result of operations on ordered series expressed as 1D lists
|
291
|
+
Computes the result of expressions containing operations on ordered series expressed as 1D lists. The syntax of the expression supports the discrete difference operator via the `ddd()` method.
|
302
292
|
|
303
|
-
|
304
|
-
- `expression` (str): A series operation expression. Supports operations such as "+", "-", "*", "/", and `ddd` for discrete differences.
|
293
|
+
• Parameters:
|
294
|
+
- `expression` (str): A series operation expression. Supports operations such as "+", "-", "*", "/", and `ddd()` for discrete differences.
|
305
295
|
|
306
|
-
|
296
|
+
• Returns:
|
307
297
|
- `str`: The string representation of the resultant series after performing operations, or an error message if series lengths do not match.
|
308
298
|
|
309
|
-
|
299
|
+
• Example:
|
310
300
|
|
311
|
-
from rgwfuncs import
|
301
|
+
from rgwfuncs import compute_ordered_series_expression
|
312
302
|
|
313
303
|
# Example with addition and discrete differences
|
314
|
-
result =
|
304
|
+
result = compute_ordered_series_expression("ddd([2, 6, 9, 60]) + ddd([78, 79, 80])")
|
315
305
|
print(result) # Output: [4, 3, 51] + [1, 1]
|
316
306
|
|
317
307
|
# Example with elementwise subtraction
|
318
|
-
result =
|
308
|
+
result = compute_ordered_series_expression("[10, 15, 21] - [5, 5, 5]")
|
319
309
|
print(result) # Output: [5, 10, 16]
|
320
310
|
|
321
311
|
# Example with length mismatch
|
322
|
-
result =
|
312
|
+
result = compute_ordered_series_expression("[4, 3, 51] + [1, 1]")
|
323
313
|
print(result) # Output: Operations between ordered series must involve series of equal length
|
324
314
|
|
325
|
-
This function first applies the discrete difference operator to any series where applicable, then evaluates arithmetic operations between series. It returns a string representation of the result or an error message if the series lengths do not match. The function is robust, directly parsing and evaluating given series expressions with safety checks in place.
|
326
|
-
|
327
315
|
--------------------------------------------------------------------------------
|
328
316
|
|
329
317
|
## String Based Functions
|
@@ -128,105 +128,97 @@ Print a list of available function names in alphabetical order. If a filter is p
|
|
128
128
|
|
129
129
|
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.
|
130
130
|
|
131
|
-
### 1. `
|
131
|
+
### 1. `compute_constant_expression`
|
132
132
|
|
133
|
-
Evaluates
|
133
|
+
Computes the numerical result of a given expression, which can evaluate to a constant, represented as a float. Evaluates an constant expression provided as a string and returns the computed result. Supports various arithmetic operations, including addition, subtraction, multiplication, division, and modulo, as well as mathematical functions from the math module.
|
134
134
|
|
135
|
-
|
136
|
-
- `expression` (str):
|
135
|
+
• Parameters:
|
136
|
+
- `expression` (str): The constant expression to compute. This should be a string consisting of arithmetic operations and Python's math module functions.
|
137
137
|
|
138
|
-
|
138
|
+
• Returns:
|
139
139
|
- `float`: The computed numerical result.
|
140
140
|
|
141
|
-
|
141
|
+
• Example:
|
142
142
|
|
143
|
-
from rgwfuncs import
|
144
|
-
result1 =
|
143
|
+
from rgwfuncs import compute_constant_expression
|
144
|
+
result1 = compute_constant_expression("2 + 2")
|
145
145
|
print(result1) # Output: 4.0
|
146
146
|
|
147
|
-
result2 =
|
147
|
+
result2 = compute_constant_expression("10 % 3")
|
148
148
|
print(result2) # Output: 1.0
|
149
149
|
|
150
|
-
result3 =
|
150
|
+
result3 = compute_constant_expression("math.gcd(36, 60) * math.sin(math.radians(45)) * 10000")
|
151
151
|
print(result3) # Output: 84852.8137423857
|
152
152
|
|
153
|
-
These examples illustrate the ability to handle basic arithmetic, the modulo operator, and functions utilizing the Python math module.
|
154
|
-
|
155
153
|
--------------------------------------------------------------------------------
|
156
154
|
|
157
|
-
### 2. `
|
155
|
+
### 2. `simplify_polynomial_expression`
|
158
156
|
|
159
|
-
Simplifies
|
157
|
+
Simplifies an algebraic expression in polynomial form and returns it in LaTeX format. Takes an algebraic expression, in polynomial form, written in Python syntax and simplifies it. The result is returned as a LaTeX formatted string, suitable for academic or professional documentation.
|
160
158
|
|
161
|
-
|
162
|
-
- `expression` (str):
|
159
|
+
• Parameters:
|
160
|
+
- `expression` (str): The algebraic expression, in polynomial form, to simplify. For instance, the expression 'np.diff(8*x**30) where as 'np.diff([2,5,9,11)' is not a polynomial.
|
163
161
|
- `subs` (Optional[Dict[str, float]]): An optional dictionary of substitutions where keys are variable names and values are the numbers to substitute them with.
|
164
162
|
|
165
|
-
|
163
|
+
• Returns:
|
166
164
|
- `str`: The simplified expression formatted as a LaTeX string.
|
167
165
|
|
168
|
-
|
166
|
+
• Example Usage:
|
169
167
|
|
170
|
-
from rgwfuncs import
|
168
|
+
from rgwfuncs import simplify_polynomial_expression
|
171
169
|
|
172
170
|
# Example 1: Simplifying a polynomial expression without substitutions
|
173
|
-
simplified_expr1 =
|
171
|
+
simplified_expr1 = simplify_polynomial_expression("2*x + 3*x")
|
174
172
|
print(simplified_expr1) # Output: "5 x"
|
175
173
|
|
176
174
|
# Example 2: Simplifying a complex expression involving derivatives
|
177
|
-
simplified_expr2 =
|
178
|
-
"(np.diff(3*x**8)) / (np.diff(8*x**30) * 11*y**3)"
|
179
|
-
)
|
175
|
+
simplified_expr2 = simplify_polynomial_expression("(np.diff(3*x**8)) / (np.diff(8*x**30) * 11*y**3)")
|
180
176
|
print(simplified_expr2) # Output: r"\frac{1}{110 x^{22} y^{3}}"
|
181
177
|
|
182
178
|
# Example 3: Simplifying with substitutions
|
183
|
-
simplified_expr3 =
|
179
|
+
simplified_expr3 = simplify_polynomial_expression("x**2 + y**2", subs={"x": 3, "y": 4})
|
184
180
|
print(simplified_expr3) # Output: "25"
|
185
181
|
|
186
182
|
# Example 4: Simplifying with partial substitution
|
187
|
-
simplified_expr4 =
|
188
|
-
print(simplified_expr4) # Output: "a
|
189
|
-
|
190
|
-
These examples demonstrate the simplification of polynomial expressions, handling complex ratios involving derivatives, and applying variable substitutions before simplifying. The function handles expressions both with and without substitutions, providing flexibility in its usage.
|
183
|
+
simplified_expr4 = simplify_polynomial_expression("a*b + b", subs={"b": 2})
|
184
|
+
print(simplified_expr4) # Output: "2 a + 2"
|
191
185
|
|
192
186
|
--------------------------------------------------------------------------------
|
193
187
|
|
194
|
-
### 3. `
|
188
|
+
### 3. `solve_homogeneous_polynomial_expression`
|
195
189
|
|
196
|
-
Solves equations for specified variables, with optional substitutions, returning LaTeX-formatted solutions.
|
190
|
+
Solves a homogeneous polynomial expression for a specified variable and returns solutions in LaTeX format. Assumes that the expression is homoegeneous (i.e. equal to zero), and solves for a designated variable. May optionally include substitutions for other variables in the equation. The solutions are provided as a LaTeX formatted string. The method solves equations for specified variables, with optional substitutions, returning LaTeX-formatted solutions.
|
197
191
|
|
198
|
-
|
199
|
-
- `expression` (str): A string of the
|
192
|
+
• Parameters:
|
193
|
+
- `expression` (str): A string of the homogeneous polynomial expression to solve.
|
200
194
|
- `variable` (str): The variable to solve for.
|
201
195
|
- `subs` (Optional[Dict[str, float]]): Substitutions for variables.
|
202
196
|
|
203
|
-
|
197
|
+
• Returns:
|
204
198
|
- `str`: Solutions formatted in LaTeX.
|
205
199
|
|
206
|
-
|
200
|
+
• Example:
|
207
201
|
|
208
|
-
from rgwfuncs import
|
209
|
-
solutions1 =
|
202
|
+
from rgwfuncs import solve_homogeneous_polynomial_expression
|
203
|
+
solutions1 = solve_homogeneous_polynomial_expression("a*x**2 + b*x + c", "x", {"a": 3, "b": 7, "c": 5})
|
210
204
|
print(solutions1) # Output: "\left[-7/6 - sqrt(11)*I/6, -7/6 + sqrt(11)*I/6\right]"
|
211
205
|
|
212
|
-
solutions2 =
|
206
|
+
solutions2 = solve_homogeneous_polynomial_expression("x**2 - 4", "x")
|
213
207
|
print(solutions2) # Output: "\left[-2, 2\right]"
|
214
208
|
|
215
|
-
Here, we solve both a quadratic equation with complex solutions and a simpler polynomial equation.
|
216
|
-
|
217
209
|
--------------------------------------------------------------------------------
|
218
210
|
|
219
211
|
### 4. `get_prime_factors_latex`
|
220
212
|
|
221
213
|
Computes prime factors of a number and presents them in LaTeX format.
|
222
214
|
|
223
|
-
|
215
|
+
• Parameters:
|
224
216
|
- `n` (int): The integer to factorize.
|
225
217
|
|
226
|
-
|
218
|
+
• Returns:
|
227
219
|
- `str`: Prime factorization in LaTeX.
|
228
220
|
|
229
|
-
|
221
|
+
• Example:
|
230
222
|
|
231
223
|
from rgwfuncs import get_prime_factors_latex
|
232
224
|
factors1 = get_prime_factors_latex(100)
|
@@ -240,64 +232,60 @@ Computes prime factors of a number and presents them in LaTeX format.
|
|
240
232
|
|
241
233
|
--------------------------------------------------------------------------------
|
242
234
|
|
243
|
-
### 5. `
|
235
|
+
### 5. `compute_matrix_expression`
|
244
236
|
|
245
|
-
Computes the results of 1D or 2D matrix operations and formats them as LaTeX strings.
|
237
|
+
Computes the results of expressions containing 1D or 2D matrix operations and formats them as LaTeX strings.
|
246
238
|
|
247
|
-
|
239
|
+
• Parameters:
|
248
240
|
- `expression` (str): A string representing a sequence of matrix operations involving either 1D or 2D lists. Supported operations include addition (`+`), subtraction (`-`), multiplication (`*`), and division (`/`).
|
249
241
|
|
250
|
-
|
242
|
+
• Returns:
|
251
243
|
- `str`: The LaTeX-formatted string representation of the computed matrix, or an error message if the operations cannot be performed due to dimensional mismatches.
|
252
244
|
|
253
|
-
|
245
|
+
• Example:
|
254
246
|
|
255
|
-
from rgwfuncs import
|
247
|
+
from rgwfuncs import compute_matrix_expression
|
256
248
|
|
257
249
|
# Example with addition of 2D matrices
|
258
|
-
result =
|
250
|
+
result = compute_matrix_expression("[[2, 6, 9], [1, 3, 5]] + [[1, 2, 3], [4, 5, 6]]")
|
259
251
|
print(result) # Output: \begin{bmatrix}3 & 8 & 12\\5 & 8 & 11\end{bmatrix}
|
260
252
|
|
261
253
|
# Example of mixed operations with 1D matrices treated as 2D
|
262
|
-
result =
|
254
|
+
result = compute_matrix_expression("[3, 6, 9] + [1, 2, 3] - [2, 2, 2]")
|
263
255
|
print(result) # Output: \begin{bmatrix}2 & 6 & 10\end{bmatrix}
|
264
256
|
|
265
257
|
# Example with dimension mismatch
|
266
|
-
result =
|
258
|
+
result = compute_matrix_expression("[[4, 3, 51]] + [[1, 1]]")
|
267
259
|
print(result) # Output: Operations between matrices must involve matrices of the same dimension
|
268
260
|
|
269
|
-
This function performs elementwise operations on both 1D and 2D matrices represented as Python lists and formats the result as a LaTeX string. It handles operations sequentially from left to right and gracefully handles dimension mismatches by returning a meaningful message. It utilizes Python's `ast.literal_eval` for safe and robust parsing.
|
270
|
-
|
271
261
|
--------------------------------------------------------------------------------
|
272
262
|
|
273
|
-
### 6. `
|
263
|
+
### 6. `compute_ordered_series_expression`
|
274
264
|
|
275
|
-
Computes the result of operations on ordered series expressed as 1D lists
|
265
|
+
Computes the result of expressions containing operations on ordered series expressed as 1D lists. The syntax of the expression supports the discrete difference operator via the `ddd()` method.
|
276
266
|
|
277
|
-
|
278
|
-
- `expression` (str): A series operation expression. Supports operations such as "+", "-", "*", "/", and `ddd` for discrete differences.
|
267
|
+
• Parameters:
|
268
|
+
- `expression` (str): A series operation expression. Supports operations such as "+", "-", "*", "/", and `ddd()` for discrete differences.
|
279
269
|
|
280
|
-
|
270
|
+
• Returns:
|
281
271
|
- `str`: The string representation of the resultant series after performing operations, or an error message if series lengths do not match.
|
282
272
|
|
283
|
-
|
273
|
+
• Example:
|
284
274
|
|
285
|
-
from rgwfuncs import
|
275
|
+
from rgwfuncs import compute_ordered_series_expression
|
286
276
|
|
287
277
|
# Example with addition and discrete differences
|
288
|
-
result =
|
278
|
+
result = compute_ordered_series_expression("ddd([2, 6, 9, 60]) + ddd([78, 79, 80])")
|
289
279
|
print(result) # Output: [4, 3, 51] + [1, 1]
|
290
280
|
|
291
281
|
# Example with elementwise subtraction
|
292
|
-
result =
|
282
|
+
result = compute_ordered_series_expression("[10, 15, 21] - [5, 5, 5]")
|
293
283
|
print(result) # Output: [5, 10, 16]
|
294
284
|
|
295
285
|
# Example with length mismatch
|
296
|
-
result =
|
286
|
+
result = compute_ordered_series_expression("[4, 3, 51] + [1, 1]")
|
297
287
|
print(result) # Output: Operations between ordered series must involve series of equal length
|
298
288
|
|
299
|
-
This function first applies the discrete difference operator to any series where applicable, then evaluates arithmetic operations between series. It returns a string representation of the result or an error message if the series lengths do not match. The function is robust, directly parsing and evaluating given series expressions with safety checks in place.
|
300
|
-
|
301
289
|
--------------------------------------------------------------------------------
|
302
290
|
|
303
291
|
## String Based Functions
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# This file is automatically generated
|
2
2
|
# Dynamically importing functions from modules
|
3
3
|
|
4
|
-
from .algebra_lib import
|
4
|
+
from .algebra_lib import compute_constant_expression, compute_matrix_expression, compute_ordered_series_expression, get_prime_factors_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
7
|
from .str_lib import send_telegram_message
|
@@ -7,17 +7,18 @@ from sympy.parsing.sympy_parser import parse_expr
|
|
7
7
|
from typing import Tuple, List, Dict, Optional
|
8
8
|
|
9
9
|
|
10
|
-
def
|
10
|
+
def compute_constant_expression(expression: str) -> float:
|
11
11
|
"""
|
12
|
-
Computes the numerical result of a given
|
12
|
+
Computes the numerical result of a given expression, which can evaluate to a constant,
|
13
|
+
represented as a float.
|
13
14
|
|
14
|
-
Evaluates an
|
15
|
+
Evaluates an constant expression provided as a string and returns the computed result.
|
15
16
|
Supports various arithmetic operations, including addition, subtraction, multiplication,
|
16
17
|
division, and modulo, as well as mathematical functions from the math module.
|
17
18
|
|
18
19
|
Parameters:
|
19
|
-
expression (str): The
|
20
|
-
of arithmetic operations and
|
20
|
+
expression (str): The constant expression to compute. This should be a string consisting
|
21
|
+
of arithmetic operations and Python's math module functions.
|
21
22
|
|
22
23
|
Returns:
|
23
24
|
float: The evaluated numerical result of the expression.
|
@@ -36,18 +37,21 @@ def compute_algebraic_expression(expression: str) -> float:
|
|
36
37
|
raise ValueError(f"Error computing expression: {e}")
|
37
38
|
|
38
39
|
|
39
|
-
def
|
40
|
+
def simplify_polynomial_expression(
|
40
41
|
expression: str,
|
41
42
|
subs: Optional[Dict[str, float]] = None
|
42
43
|
) -> str:
|
43
44
|
"""
|
44
|
-
Simplifies an algebraic expression and returns it in LaTeX format.
|
45
|
+
Simplifies an algebraic expression in polynomial form and returns it in LaTeX format.
|
45
46
|
|
46
|
-
Takes an algebraic expression written in Python syntax and simplifies it.
|
47
|
-
returned as a LaTeX formatted string, suitable for academic or professional
|
47
|
+
Takes an algebraic expression, in polynomial form, written in Python syntax and simplifies it.
|
48
|
+
The result is returned as a LaTeX formatted string, suitable for academic or professional
|
49
|
+
documentation.
|
48
50
|
|
49
51
|
Parameters:
|
50
|
-
expression (str): The algebraic expression to simplify.
|
52
|
+
expression (str): The algebraic expression, in polynomial form, to simplify. For instance,
|
53
|
+
the expression `np.diff(8*x**30)` is a polynomial, whereas np.diff([2,5,9,11)
|
54
|
+
is not a polynomial.
|
51
55
|
subs (Optional[Dict[str, float]]): An optional dictionary of substitutions for variables
|
52
56
|
in the expression.
|
53
57
|
|
@@ -58,7 +62,6 @@ def simplify_algebraic_expression(
|
|
58
62
|
ValueError: If the expression cannot be simplified due to errors in expression or parameters.
|
59
63
|
"""
|
60
64
|
|
61
|
-
|
62
65
|
def recursive_parse_function_call(
|
63
66
|
func_call: str, prefix: str, sym_vars: Dict[str, Expr]) -> Tuple[str, List[Expr]]:
|
64
67
|
# print(f"Parsing function call: {func_call}")
|
@@ -209,19 +212,21 @@ def simplify_algebraic_expression(
|
|
209
212
|
raise ValueError(f"Error simplifying expression: {e}")
|
210
213
|
|
211
214
|
|
212
|
-
def
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
215
|
+
def solve_homogeneous_polynomial_expression(
|
216
|
+
expression: str,
|
217
|
+
variable: str,
|
218
|
+
subs: Optional[Dict[str, float]] = None
|
219
|
+
) -> str:
|
217
220
|
"""
|
218
|
-
Solves
|
221
|
+
Solves a homogeneous polynomial expression for a specified variable and returns solutions
|
222
|
+
in LaTeX format.
|
219
223
|
|
220
|
-
|
221
|
-
|
224
|
+
Assumes that the expression is homoegeneous (i.e. equal to zero), and solves for a
|
225
|
+
designated variable. May optionally include substitutions for other variables in the
|
226
|
+
equation. The solutions are provided as a LaTeX formatted string.
|
222
227
|
|
223
228
|
Parameters:
|
224
|
-
expression (str): The
|
229
|
+
expression (str): The homogeneous polynomial expression to solve.
|
225
230
|
variable (str): The variable to solve the equation for.
|
226
231
|
subs (Optional[Dict[str, float]]): An optional dictionary of substitutions for variables
|
227
232
|
in the equation.
|
@@ -260,7 +265,7 @@ def solve_algebraic_expression(
|
|
260
265
|
raise ValueError(f"Error solving the expression: {e}")
|
261
266
|
|
262
267
|
|
263
|
-
def
|
268
|
+
def compute_matrix_expression(expression: str) -> str:
|
264
269
|
"""
|
265
270
|
Computes the result of a matrix-like operation on 1D or 2D list inputs and returns it as a LaTeX string.
|
266
271
|
|
@@ -350,7 +355,7 @@ def compute_matrix_operation(expression: str) -> str:
|
|
350
355
|
return f"Error computing matrix operation: {e}"
|
351
356
|
|
352
357
|
|
353
|
-
def
|
358
|
+
def compute_ordered_series_expression(expression: str) -> str:
|
354
359
|
"""
|
355
360
|
Computes the result of operations on ordered series expressed as 1D lists, including discrete difference (ddd),
|
356
361
|
and returns it as a string.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: rgwfuncs
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.29
|
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
|
@@ -154,105 +154,97 @@ Print a list of available function names in alphabetical order. If a filter is p
|
|
154
154
|
|
155
155
|
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.
|
156
156
|
|
157
|
-
### 1. `
|
157
|
+
### 1. `compute_constant_expression`
|
158
158
|
|
159
|
-
Evaluates
|
159
|
+
Computes the numerical result of a given expression, which can evaluate to a constant, represented as a float. Evaluates an constant expression provided as a string and returns the computed result. Supports various arithmetic operations, including addition, subtraction, multiplication, division, and modulo, as well as mathematical functions from the math module.
|
160
160
|
|
161
|
-
|
162
|
-
- `expression` (str):
|
161
|
+
• Parameters:
|
162
|
+
- `expression` (str): The constant expression to compute. This should be a string consisting of arithmetic operations and Python's math module functions.
|
163
163
|
|
164
|
-
|
164
|
+
• Returns:
|
165
165
|
- `float`: The computed numerical result.
|
166
166
|
|
167
|
-
|
167
|
+
• Example:
|
168
168
|
|
169
|
-
from rgwfuncs import
|
170
|
-
result1 =
|
169
|
+
from rgwfuncs import compute_constant_expression
|
170
|
+
result1 = compute_constant_expression("2 + 2")
|
171
171
|
print(result1) # Output: 4.0
|
172
172
|
|
173
|
-
result2 =
|
173
|
+
result2 = compute_constant_expression("10 % 3")
|
174
174
|
print(result2) # Output: 1.0
|
175
175
|
|
176
|
-
result3 =
|
176
|
+
result3 = compute_constant_expression("math.gcd(36, 60) * math.sin(math.radians(45)) * 10000")
|
177
177
|
print(result3) # Output: 84852.8137423857
|
178
178
|
|
179
|
-
These examples illustrate the ability to handle basic arithmetic, the modulo operator, and functions utilizing the Python math module.
|
180
|
-
|
181
179
|
--------------------------------------------------------------------------------
|
182
180
|
|
183
|
-
### 2. `
|
181
|
+
### 2. `simplify_polynomial_expression`
|
184
182
|
|
185
|
-
Simplifies
|
183
|
+
Simplifies an algebraic expression in polynomial form and returns it in LaTeX format. Takes an algebraic expression, in polynomial form, written in Python syntax and simplifies it. The result is returned as a LaTeX formatted string, suitable for academic or professional documentation.
|
186
184
|
|
187
|
-
|
188
|
-
- `expression` (str):
|
185
|
+
• Parameters:
|
186
|
+
- `expression` (str): The algebraic expression, in polynomial form, to simplify. For instance, the expression 'np.diff(8*x**30) where as 'np.diff([2,5,9,11)' is not a polynomial.
|
189
187
|
- `subs` (Optional[Dict[str, float]]): An optional dictionary of substitutions where keys are variable names and values are the numbers to substitute them with.
|
190
188
|
|
191
|
-
|
189
|
+
• Returns:
|
192
190
|
- `str`: The simplified expression formatted as a LaTeX string.
|
193
191
|
|
194
|
-
|
192
|
+
• Example Usage:
|
195
193
|
|
196
|
-
from rgwfuncs import
|
194
|
+
from rgwfuncs import simplify_polynomial_expression
|
197
195
|
|
198
196
|
# Example 1: Simplifying a polynomial expression without substitutions
|
199
|
-
simplified_expr1 =
|
197
|
+
simplified_expr1 = simplify_polynomial_expression("2*x + 3*x")
|
200
198
|
print(simplified_expr1) # Output: "5 x"
|
201
199
|
|
202
200
|
# Example 2: Simplifying a complex expression involving derivatives
|
203
|
-
simplified_expr2 =
|
204
|
-
"(np.diff(3*x**8)) / (np.diff(8*x**30) * 11*y**3)"
|
205
|
-
)
|
201
|
+
simplified_expr2 = simplify_polynomial_expression("(np.diff(3*x**8)) / (np.diff(8*x**30) * 11*y**3)")
|
206
202
|
print(simplified_expr2) # Output: r"\frac{1}{110 x^{22} y^{3}}"
|
207
203
|
|
208
204
|
# Example 3: Simplifying with substitutions
|
209
|
-
simplified_expr3 =
|
205
|
+
simplified_expr3 = simplify_polynomial_expression("x**2 + y**2", subs={"x": 3, "y": 4})
|
210
206
|
print(simplified_expr3) # Output: "25"
|
211
207
|
|
212
208
|
# Example 4: Simplifying with partial substitution
|
213
|
-
simplified_expr4 =
|
214
|
-
print(simplified_expr4) # Output: "a
|
215
|
-
|
216
|
-
These examples demonstrate the simplification of polynomial expressions, handling complex ratios involving derivatives, and applying variable substitutions before simplifying. The function handles expressions both with and without substitutions, providing flexibility in its usage.
|
209
|
+
simplified_expr4 = simplify_polynomial_expression("a*b + b", subs={"b": 2})
|
210
|
+
print(simplified_expr4) # Output: "2 a + 2"
|
217
211
|
|
218
212
|
--------------------------------------------------------------------------------
|
219
213
|
|
220
|
-
### 3. `
|
214
|
+
### 3. `solve_homogeneous_polynomial_expression`
|
221
215
|
|
222
|
-
Solves equations for specified variables, with optional substitutions, returning LaTeX-formatted solutions.
|
216
|
+
Solves a homogeneous polynomial expression for a specified variable and returns solutions in LaTeX format. Assumes that the expression is homoegeneous (i.e. equal to zero), and solves for a designated variable. May optionally include substitutions for other variables in the equation. The solutions are provided as a LaTeX formatted string. The method solves equations for specified variables, with optional substitutions, returning LaTeX-formatted solutions.
|
223
217
|
|
224
|
-
|
225
|
-
- `expression` (str): A string of the
|
218
|
+
• Parameters:
|
219
|
+
- `expression` (str): A string of the homogeneous polynomial expression to solve.
|
226
220
|
- `variable` (str): The variable to solve for.
|
227
221
|
- `subs` (Optional[Dict[str, float]]): Substitutions for variables.
|
228
222
|
|
229
|
-
|
223
|
+
• Returns:
|
230
224
|
- `str`: Solutions formatted in LaTeX.
|
231
225
|
|
232
|
-
|
226
|
+
• Example:
|
233
227
|
|
234
|
-
from rgwfuncs import
|
235
|
-
solutions1 =
|
228
|
+
from rgwfuncs import solve_homogeneous_polynomial_expression
|
229
|
+
solutions1 = solve_homogeneous_polynomial_expression("a*x**2 + b*x + c", "x", {"a": 3, "b": 7, "c": 5})
|
236
230
|
print(solutions1) # Output: "\left[-7/6 - sqrt(11)*I/6, -7/6 + sqrt(11)*I/6\right]"
|
237
231
|
|
238
|
-
solutions2 =
|
232
|
+
solutions2 = solve_homogeneous_polynomial_expression("x**2 - 4", "x")
|
239
233
|
print(solutions2) # Output: "\left[-2, 2\right]"
|
240
234
|
|
241
|
-
Here, we solve both a quadratic equation with complex solutions and a simpler polynomial equation.
|
242
|
-
|
243
235
|
--------------------------------------------------------------------------------
|
244
236
|
|
245
237
|
### 4. `get_prime_factors_latex`
|
246
238
|
|
247
239
|
Computes prime factors of a number and presents them in LaTeX format.
|
248
240
|
|
249
|
-
|
241
|
+
• Parameters:
|
250
242
|
- `n` (int): The integer to factorize.
|
251
243
|
|
252
|
-
|
244
|
+
• Returns:
|
253
245
|
- `str`: Prime factorization in LaTeX.
|
254
246
|
|
255
|
-
|
247
|
+
• Example:
|
256
248
|
|
257
249
|
from rgwfuncs import get_prime_factors_latex
|
258
250
|
factors1 = get_prime_factors_latex(100)
|
@@ -266,64 +258,60 @@ Computes prime factors of a number and presents them in LaTeX format.
|
|
266
258
|
|
267
259
|
--------------------------------------------------------------------------------
|
268
260
|
|
269
|
-
### 5. `
|
261
|
+
### 5. `compute_matrix_expression`
|
270
262
|
|
271
|
-
Computes the results of 1D or 2D matrix operations and formats them as LaTeX strings.
|
263
|
+
Computes the results of expressions containing 1D or 2D matrix operations and formats them as LaTeX strings.
|
272
264
|
|
273
|
-
|
265
|
+
• Parameters:
|
274
266
|
- `expression` (str): A string representing a sequence of matrix operations involving either 1D or 2D lists. Supported operations include addition (`+`), subtraction (`-`), multiplication (`*`), and division (`/`).
|
275
267
|
|
276
|
-
|
268
|
+
• Returns:
|
277
269
|
- `str`: The LaTeX-formatted string representation of the computed matrix, or an error message if the operations cannot be performed due to dimensional mismatches.
|
278
270
|
|
279
|
-
|
271
|
+
• Example:
|
280
272
|
|
281
|
-
from rgwfuncs import
|
273
|
+
from rgwfuncs import compute_matrix_expression
|
282
274
|
|
283
275
|
# Example with addition of 2D matrices
|
284
|
-
result =
|
276
|
+
result = compute_matrix_expression("[[2, 6, 9], [1, 3, 5]] + [[1, 2, 3], [4, 5, 6]]")
|
285
277
|
print(result) # Output: \begin{bmatrix}3 & 8 & 12\\5 & 8 & 11\end{bmatrix}
|
286
278
|
|
287
279
|
# Example of mixed operations with 1D matrices treated as 2D
|
288
|
-
result =
|
280
|
+
result = compute_matrix_expression("[3, 6, 9] + [1, 2, 3] - [2, 2, 2]")
|
289
281
|
print(result) # Output: \begin{bmatrix}2 & 6 & 10\end{bmatrix}
|
290
282
|
|
291
283
|
# Example with dimension mismatch
|
292
|
-
result =
|
284
|
+
result = compute_matrix_expression("[[4, 3, 51]] + [[1, 1]]")
|
293
285
|
print(result) # Output: Operations between matrices must involve matrices of the same dimension
|
294
286
|
|
295
|
-
This function performs elementwise operations on both 1D and 2D matrices represented as Python lists and formats the result as a LaTeX string. It handles operations sequentially from left to right and gracefully handles dimension mismatches by returning a meaningful message. It utilizes Python's `ast.literal_eval` for safe and robust parsing.
|
296
|
-
|
297
287
|
--------------------------------------------------------------------------------
|
298
288
|
|
299
|
-
### 6. `
|
289
|
+
### 6. `compute_ordered_series_expression`
|
300
290
|
|
301
|
-
Computes the result of operations on ordered series expressed as 1D lists
|
291
|
+
Computes the result of expressions containing operations on ordered series expressed as 1D lists. The syntax of the expression supports the discrete difference operator via the `ddd()` method.
|
302
292
|
|
303
|
-
|
304
|
-
- `expression` (str): A series operation expression. Supports operations such as "+", "-", "*", "/", and `ddd` for discrete differences.
|
293
|
+
• Parameters:
|
294
|
+
- `expression` (str): A series operation expression. Supports operations such as "+", "-", "*", "/", and `ddd()` for discrete differences.
|
305
295
|
|
306
|
-
|
296
|
+
• Returns:
|
307
297
|
- `str`: The string representation of the resultant series after performing operations, or an error message if series lengths do not match.
|
308
298
|
|
309
|
-
|
299
|
+
• Example:
|
310
300
|
|
311
|
-
from rgwfuncs import
|
301
|
+
from rgwfuncs import compute_ordered_series_expression
|
312
302
|
|
313
303
|
# Example with addition and discrete differences
|
314
|
-
result =
|
304
|
+
result = compute_ordered_series_expression("ddd([2, 6, 9, 60]) + ddd([78, 79, 80])")
|
315
305
|
print(result) # Output: [4, 3, 51] + [1, 1]
|
316
306
|
|
317
307
|
# Example with elementwise subtraction
|
318
|
-
result =
|
308
|
+
result = compute_ordered_series_expression("[10, 15, 21] - [5, 5, 5]")
|
319
309
|
print(result) # Output: [5, 10, 16]
|
320
310
|
|
321
311
|
# Example with length mismatch
|
322
|
-
result =
|
312
|
+
result = compute_ordered_series_expression("[4, 3, 51] + [1, 1]")
|
323
313
|
print(result) # Output: Operations between ordered series must involve series of equal length
|
324
314
|
|
325
|
-
This function first applies the discrete difference operator to any series where applicable, then evaluates arithmetic operations between series. It returns a string representation of the result or an error message if the series lengths do not match. The function is robust, directly parsing and evaluating given series expressions with safety checks in place.
|
326
|
-
|
327
315
|
--------------------------------------------------------------------------------
|
328
316
|
|
329
317
|
## String Based Functions
|
@@ -7,15 +7,15 @@ import math
|
|
7
7
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
8
8
|
|
9
9
|
from src.rgwfuncs.algebra_lib import (
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
compute_constant_expression,
|
11
|
+
simplify_polynomial_expression,
|
12
|
+
solve_homogeneous_polynomial_expression,
|
13
|
+
compute_matrix_expression,
|
14
|
+
compute_ordered_series_expression,
|
15
15
|
get_prime_factors_latex)
|
16
16
|
|
17
17
|
|
18
|
-
def
|
18
|
+
def test_compute_constant_expression():
|
19
19
|
test_cases = [
|
20
20
|
("2 + 2", 4.0),
|
21
21
|
("5 - 3", 2.0),
|
@@ -27,10 +27,11 @@ def test_compute_algebraic_expression():
|
|
27
27
|
]
|
28
28
|
|
29
29
|
for input_data, expected_output in test_cases:
|
30
|
-
result =
|
30
|
+
result = compute_constant_expression(input_data)
|
31
31
|
assert math.isclose(result, expected_output, rel_tol=1e-9), f"Failed for {input_data}, got {result}"
|
32
32
|
|
33
|
-
|
33
|
+
|
34
|
+
def test_simplify_polynomial_expression():
|
34
35
|
test_cases = [
|
35
36
|
# Without substitutions
|
36
37
|
(("(np.diff(3*x**8)) / (np.diff(8*x**30) * 11*y**3)", None), r"\frac{1}{110 x^{22} y^{3}}"),
|
@@ -42,27 +43,21 @@ def test_simplify_algebraic_expression():
|
|
42
43
|
]
|
43
44
|
|
44
45
|
for (expression, subs), expected_output in test_cases:
|
45
|
-
output =
|
46
|
-
assert output == expected_output, (
|
47
|
-
f"Test failed for expression: {expression} with substitutions: {subs}. "
|
48
|
-
f"Expected {expected_output}, got {output}"
|
49
|
-
)
|
46
|
+
output = simplify_polynomial_expression(expression, subs)
|
47
|
+
assert output == expected_output, (f"Test failed for expression: {expression} with substitutions: {subs}. Expected {expected_output}, got {output}")
|
50
48
|
|
51
49
|
|
52
|
-
def
|
50
|
+
def test_solve_homogeneous_polynomial_expression():
|
53
51
|
test_cases = [
|
54
52
|
# Test case with substitutions
|
55
|
-
(
|
56
|
-
("a*x**2 + b*x + c", "x", {"a": 3, "b": 7, "c": 5}),
|
57
|
-
r"\left[-7/6 - sqrt(11)*I/6, -7/6 + sqrt(11)*I/6\right]"
|
58
|
-
),
|
53
|
+
(("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]"),
|
59
54
|
]
|
60
55
|
|
61
56
|
for (expression, variable, subs), expected_output in test_cases:
|
62
|
-
assert
|
57
|
+
assert solve_homogeneous_polynomial_expression(expression, variable, subs) == expected_output
|
63
58
|
|
64
59
|
|
65
|
-
def
|
60
|
+
def test_compute_matrix_expression():
|
66
61
|
test_cases = [
|
67
62
|
("[[2, 6, 9],[1, 3, 5]] + [[1, 2, 3],[4, 5, 6]]", r"\begin{bmatrix}3 & 8 & 12\\5 & 8 & 11\end{bmatrix}"),
|
68
63
|
("[[10, 10, 10],[2, 4, 6]] - [[5, 3, 2],[1, 2, 1]]", r"\begin{bmatrix}5 & 7 & 8\\1 & 2 & 5\end{bmatrix}"),
|
@@ -80,13 +75,13 @@ def test_compute_matrix_operation():
|
|
80
75
|
]
|
81
76
|
|
82
77
|
for input_data, expected_output in test_cases:
|
83
|
-
result =
|
78
|
+
result = compute_matrix_expression(input_data)
|
84
79
|
assert result == expected_output, f"Failed for {input_data}, got {result}"
|
85
80
|
|
86
81
|
# Example test function
|
87
82
|
|
88
83
|
|
89
|
-
def
|
84
|
+
def test_compute_ordered_series_expression():
|
90
85
|
test_cases = [
|
91
86
|
("[2, 6, 9] + [1, 2, 3]", "[3, 8, 12]"),
|
92
87
|
("[10, 15, 21] - [5, 5, 5]", "[5, 10, 16]"),
|
@@ -104,7 +99,7 @@ def test_compute_ordered_series_operations():
|
|
104
99
|
]
|
105
100
|
|
106
101
|
for input_data, expected_output in test_cases:
|
107
|
-
result =
|
102
|
+
result = compute_ordered_series_expression(input_data)
|
108
103
|
assert result == expected_output, f"Failed for {input_data}, got {result}"
|
109
104
|
|
110
105
|
|
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
|