rgwfuncs 0.0.30__py3-none-any.whl → 0.0.32__py3-none-any.whl
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/__init__.py +1 -1
- rgwfuncs/algebra_lib.py +227 -226
- {rgwfuncs-0.0.30.dist-info → rgwfuncs-0.0.32.dist-info}/METADATA +109 -108
- rgwfuncs-0.0.32.dist-info/RECORD +11 -0
- rgwfuncs-0.0.30.dist-info/RECORD +0 -11
- {rgwfuncs-0.0.30.dist-info → rgwfuncs-0.0.32.dist-info}/LICENSE +0 -0
- {rgwfuncs-0.0.30.dist-info → rgwfuncs-0.0.32.dist-info}/WHEEL +0 -0
- {rgwfuncs-0.0.30.dist-info → rgwfuncs-0.0.32.dist-info}/entry_points.txt +0 -0
- {rgwfuncs-0.0.30.dist-info → rgwfuncs-0.0.32.dist-info}/top_level.txt +0 -0
rgwfuncs/__init__.py
CHANGED
@@ -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 compute_constant_expression,
|
4
|
+
from .algebra_lib import compute_constant_expression, compute_constant_expression_involving_matrices, compute_constant_expression_involving_ordered_series, compute_prime_factors_latex, 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
7
|
from .str_lib import send_telegram_message
|
rgwfuncs/algebra_lib.py
CHANGED
@@ -10,6 +10,37 @@ from sympy.parsing.sympy_parser import (standard_transformations, implicit_multi
|
|
10
10
|
from typing import Tuple, List, Dict, Optional
|
11
11
|
|
12
12
|
|
13
|
+
def compute_prime_factors_latex(n: int) -> str:
|
14
|
+
"""
|
15
|
+
Computes the prime factors of a number and returns the factorization as a LaTeX string.
|
16
|
+
|
17
|
+
Determines the prime factorization of the given integer. The result is formatted as a LaTeX
|
18
|
+
string, enabling easy integration into documents or presentations that require mathematical notation.
|
19
|
+
|
20
|
+
Parameters:
|
21
|
+
n (int): The number for which to compute prime factors.
|
22
|
+
|
23
|
+
Returns:
|
24
|
+
str: The LaTeX representation of the prime factorization.
|
25
|
+
"""
|
26
|
+
|
27
|
+
factors = []
|
28
|
+
while n % 2 == 0:
|
29
|
+
factors.append(2)
|
30
|
+
n //= 2
|
31
|
+
for i in range(3, int(math.sqrt(n)) + 1, 2):
|
32
|
+
while n % i == 0:
|
33
|
+
factors.append(i)
|
34
|
+
n //= i
|
35
|
+
if n > 2:
|
36
|
+
factors.append(n)
|
37
|
+
|
38
|
+
factor_counts = {factor: factors.count(factor) for factor in set(factors)}
|
39
|
+
latex_factors = [f"{factor}^{{{count}}}" if count > 1 else str(
|
40
|
+
factor) for factor, count in factor_counts.items()]
|
41
|
+
return " \\cdot ".join(latex_factors)
|
42
|
+
|
43
|
+
|
13
44
|
def compute_constant_expression(expression: str) -> float:
|
14
45
|
"""
|
15
46
|
Computes the numerical result of a given expression, which can evaluate to a constant,
|
@@ -40,6 +71,198 @@ def compute_constant_expression(expression: str) -> float:
|
|
40
71
|
raise ValueError(f"Error computing expression: {e}")
|
41
72
|
|
42
73
|
|
74
|
+
def compute_constant_expression_involving_matrices(expression: str) -> str:
|
75
|
+
"""
|
76
|
+
Computes the result of a constant expression involving matrices and returns it as a LaTeX string.
|
77
|
+
|
78
|
+
Parameters:
|
79
|
+
expression (str): The constant expression involving matrices. Example format includes operations such as "+",
|
80
|
+
"-", "*", "/".
|
81
|
+
|
82
|
+
Returns:
|
83
|
+
str: The LaTeX-formatted string representation of the result or a message indicating an error in dimensions.
|
84
|
+
"""
|
85
|
+
|
86
|
+
def elementwise_operation(matrix1: List[List[float]], matrix2: List[List[float]], operation: str) -> List[List[float]]:
|
87
|
+
if len(matrix1) != len(matrix2) or any(len(row1) != len(row2) for row1, row2 in zip(matrix1, matrix2)):
|
88
|
+
return "Operations between matrices must involve matrices of the same dimension"
|
89
|
+
|
90
|
+
if operation == '+':
|
91
|
+
return [[a + b for a, b in zip(row1, row2)] for row1, row2 in zip(matrix1, matrix2)]
|
92
|
+
elif operation == '-':
|
93
|
+
return [[a - b for a, b in zip(row1, row2)] for row1, row2 in zip(matrix1, matrix2)]
|
94
|
+
elif operation == '*':
|
95
|
+
return [[a * b for a, b in zip(row1, row2)] for row1, row2 in zip(matrix1, matrix2)]
|
96
|
+
elif operation == '/':
|
97
|
+
return [[a / b for a, b in zip(row1, row2) if b != 0] for row1, row2 in zip(matrix1, matrix2)]
|
98
|
+
else:
|
99
|
+
return f"Unsupported operation {operation}"
|
100
|
+
|
101
|
+
try:
|
102
|
+
# Use a stack-based method to properly parse matrices
|
103
|
+
elements = []
|
104
|
+
buffer = ''
|
105
|
+
bracket_level = 0
|
106
|
+
operators = set('+-*/')
|
107
|
+
|
108
|
+
for char in expression:
|
109
|
+
if char == '[':
|
110
|
+
if bracket_level == 0 and buffer.strip():
|
111
|
+
elements.append(buffer.strip())
|
112
|
+
buffer = ''
|
113
|
+
bracket_level += 1
|
114
|
+
elif char == ']':
|
115
|
+
bracket_level -= 1
|
116
|
+
if bracket_level == 0:
|
117
|
+
buffer += char
|
118
|
+
elements.append(buffer.strip())
|
119
|
+
buffer = ''
|
120
|
+
continue
|
121
|
+
if bracket_level == 0 and char in operators:
|
122
|
+
if buffer.strip():
|
123
|
+
elements.append(buffer.strip())
|
124
|
+
buffer = ''
|
125
|
+
elements.append(char)
|
126
|
+
else:
|
127
|
+
buffer += char
|
128
|
+
|
129
|
+
if buffer.strip():
|
130
|
+
elements.append(buffer.strip())
|
131
|
+
|
132
|
+
result = ast.literal_eval(elements[0])
|
133
|
+
|
134
|
+
if not any(isinstance(row, list) for row in result):
|
135
|
+
result = [result] # Convert 1D matrix to 2D
|
136
|
+
|
137
|
+
i = 1
|
138
|
+
while i < len(elements):
|
139
|
+
operation = elements[i]
|
140
|
+
matrix = ast.literal_eval(elements[i + 1])
|
141
|
+
|
142
|
+
if not any(isinstance(row, list) for row in matrix):
|
143
|
+
matrix = [matrix]
|
144
|
+
|
145
|
+
operation_result = elementwise_operation(result, matrix, operation)
|
146
|
+
|
147
|
+
# Check if the operation resulted in an error message
|
148
|
+
if isinstance(operation_result, str):
|
149
|
+
return operation_result
|
150
|
+
|
151
|
+
result = operation_result
|
152
|
+
i += 2
|
153
|
+
|
154
|
+
# Create a LaTeX-style matrix representation
|
155
|
+
matrix_entries = '\\\\'.join(' & '.join(str(x) for x in row) for row in result)
|
156
|
+
return r"\begin{bmatrix}" + f"{matrix_entries}" + r"\end{bmatrix}"
|
157
|
+
|
158
|
+
except Exception as e:
|
159
|
+
return f"Error computing matrix operation: {e}"
|
160
|
+
|
161
|
+
|
162
|
+
def compute_constant_expression_involving_ordered_series(expression: str) -> str:
|
163
|
+
"""
|
164
|
+
Computes the result of a constant expression involving ordered series, and returns it as a Latex string.
|
165
|
+
Supports operations lile "+", "-", "*", "/", as well as "dd()" (the discrete difference operator).
|
166
|
+
|
167
|
+
The function first applies the discrete difference operator to any series where applicable, then evaluates
|
168
|
+
arithmetic operations between series.
|
169
|
+
|
170
|
+
Parameters:
|
171
|
+
expression (str): The series operation expression to compute. Includes operations "+", "-", "*", "/", and "dd()".
|
172
|
+
|
173
|
+
Returns:
|
174
|
+
str: The string representation of the resultant series after performing operations, or an error message
|
175
|
+
if the series lengths do not match.
|
176
|
+
|
177
|
+
Raises:
|
178
|
+
ValueError: If the expression cannot be evaluated.
|
179
|
+
"""
|
180
|
+
|
181
|
+
def elementwise_operation(series1: List[float], series2: List[float], operation: str) -> List[float]:
|
182
|
+
if len(series1) != len(series2):
|
183
|
+
return "Operations between ordered series must involve series of equal length"
|
184
|
+
|
185
|
+
if operation == '+':
|
186
|
+
return [a + b for a, b in zip(series1, series2)]
|
187
|
+
elif operation == '-':
|
188
|
+
return [a - b for a, b in zip(series1, series2)]
|
189
|
+
elif operation == '*':
|
190
|
+
return [a * b for a, b in zip(series1, series2)]
|
191
|
+
elif operation == '/':
|
192
|
+
return [a / b for a, b in zip(series1, series2) if b != 0]
|
193
|
+
else:
|
194
|
+
return f"Unsupported operation {operation}"
|
195
|
+
|
196
|
+
def discrete_difference(series: list) -> list:
|
197
|
+
"""Computes the discrete difference of a series."""
|
198
|
+
return [series[i + 1] - series[i] for i in range(len(series) - 1)]
|
199
|
+
|
200
|
+
try:
|
201
|
+
# First, apply the discrete difference operator where applicable
|
202
|
+
pattern = r'dd\((\[[^\]]*\])\)'
|
203
|
+
matches = re.findall(pattern, expression)
|
204
|
+
|
205
|
+
for match in matches:
|
206
|
+
if match.strip() == '[]':
|
207
|
+
result_series = [] # Handle the empty list case
|
208
|
+
else:
|
209
|
+
series = ast.literal_eval(match)
|
210
|
+
result_series = discrete_difference(series)
|
211
|
+
expression = expression.replace(f'dd({match})', str(result_series))
|
212
|
+
|
213
|
+
# Now parse and evaluate the full expression with basic operations
|
214
|
+
elements = []
|
215
|
+
buffer = ''
|
216
|
+
bracket_level = 0
|
217
|
+
operators = set('+-*/')
|
218
|
+
|
219
|
+
for char in expression:
|
220
|
+
if char == '[':
|
221
|
+
if bracket_level == 0 and buffer.strip():
|
222
|
+
elements.append(buffer.strip())
|
223
|
+
buffer = ''
|
224
|
+
bracket_level += 1
|
225
|
+
elif char == ']':
|
226
|
+
bracket_level -= 1
|
227
|
+
if bracket_level == 0:
|
228
|
+
buffer += char
|
229
|
+
elements.append(buffer.strip())
|
230
|
+
buffer = ''
|
231
|
+
continue
|
232
|
+
if bracket_level == 0 and char in operators:
|
233
|
+
if buffer.strip():
|
234
|
+
elements.append(buffer.strip())
|
235
|
+
buffer = ''
|
236
|
+
elements.append(char)
|
237
|
+
else:
|
238
|
+
buffer += char
|
239
|
+
|
240
|
+
if buffer.strip():
|
241
|
+
elements.append(buffer.strip())
|
242
|
+
|
243
|
+
result = ast.literal_eval(elements[0])
|
244
|
+
|
245
|
+
i = 1
|
246
|
+
while i < len(elements):
|
247
|
+
operation = elements[i]
|
248
|
+
series = ast.literal_eval(elements[i + 1])
|
249
|
+
operation_result = elementwise_operation(result, series, operation)
|
250
|
+
|
251
|
+
# Check if the operation resulted in an error message
|
252
|
+
if isinstance(operation_result, str):
|
253
|
+
return operation_result
|
254
|
+
|
255
|
+
result = operation_result
|
256
|
+
i += 2
|
257
|
+
|
258
|
+
return str(result)
|
259
|
+
|
260
|
+
except Exception as e:
|
261
|
+
return f"Error computing ordered series operation: {e}"
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
43
266
|
def python_polynomial_expression_to_latex(
|
44
267
|
expression: str,
|
45
268
|
subs: Optional[Dict[str, float]] = None
|
@@ -100,7 +323,6 @@ def python_polynomial_expression_to_latex(
|
|
100
323
|
return latex_result
|
101
324
|
|
102
325
|
|
103
|
-
|
104
326
|
def simplify_polynomial_expression(
|
105
327
|
expression: str,
|
106
328
|
subs: Optional[Dict[str, float]] = None
|
@@ -109,7 +331,7 @@ def simplify_polynomial_expression(
|
|
109
331
|
Simplifies an algebraic expression in polynomial form and returns it in LaTeX format.
|
110
332
|
|
111
333
|
Takes an algebraic expression, in polynomial form, written in Python syntax and simplifies it.
|
112
|
-
The result is returned as a LaTeX formatted string, suitable for academic or professional
|
334
|
+
The result is returned as a LaTeX formatted string, suitable for academic or professional
|
113
335
|
documentation.
|
114
336
|
|
115
337
|
Parameters:
|
@@ -282,11 +504,11 @@ def solve_homogeneous_polynomial_expression(
|
|
282
504
|
subs: Optional[Dict[str, float]] = None
|
283
505
|
) -> str:
|
284
506
|
"""
|
285
|
-
Solves a homogeneous polynomial expression for a specified variable and returns solutions
|
507
|
+
Solves a homogeneous polynomial expression for a specified variable and returns solutions
|
286
508
|
in LaTeX format.
|
287
509
|
|
288
|
-
Assumes that the expression is homoegeneous (i.e. equal to zero), and solves for a
|
289
|
-
designated variable. May optionally include substitutions for other variables in the
|
510
|
+
Assumes that the expression is homoegeneous (i.e. equal to zero), and solves for a
|
511
|
+
designated variable. May optionally include substitutions for other variables in the
|
290
512
|
equation. The solutions are provided as a LaTeX formatted string.
|
291
513
|
|
292
514
|
Parameters:
|
@@ -329,224 +551,3 @@ def solve_homogeneous_polynomial_expression(
|
|
329
551
|
raise ValueError(f"Error solving the expression: {e}")
|
330
552
|
|
331
553
|
|
332
|
-
def compute_matrix_expression(expression: str) -> str:
|
333
|
-
"""
|
334
|
-
Computes the result of a matrix-like operation on 1D or 2D list inputs and returns it as a LaTeX string.
|
335
|
-
|
336
|
-
Evaluates an operation where lists are treated as matrices, performs operations on them sequentially, and
|
337
|
-
returns the result formatted as a LaTeX-style string.
|
338
|
-
|
339
|
-
Parameters:
|
340
|
-
expression (str): The matrix operation expression to compute. Example format includes operations such as "+", "-", "*", "/".
|
341
|
-
|
342
|
-
Returns:
|
343
|
-
str: The LaTeX-formatted string representation of the result or a message indicating an error in dimensions.
|
344
|
-
"""
|
345
|
-
|
346
|
-
def elementwise_operation(matrix1: List[List[float]], matrix2: List[List[float]], operation: str) -> List[List[float]]:
|
347
|
-
if len(matrix1) != len(matrix2) or any(len(row1) != len(row2) for row1, row2 in zip(matrix1, matrix2)):
|
348
|
-
return "Operations between matrices must involve matrices of the same dimension"
|
349
|
-
|
350
|
-
if operation == '+':
|
351
|
-
return [[a + b for a, b in zip(row1, row2)] for row1, row2 in zip(matrix1, matrix2)]
|
352
|
-
elif operation == '-':
|
353
|
-
return [[a - b for a, b in zip(row1, row2)] for row1, row2 in zip(matrix1, matrix2)]
|
354
|
-
elif operation == '*':
|
355
|
-
return [[a * b for a, b in zip(row1, row2)] for row1, row2 in zip(matrix1, matrix2)]
|
356
|
-
elif operation == '/':
|
357
|
-
return [[a / b for a, b in zip(row1, row2) if b != 0] for row1, row2 in zip(matrix1, matrix2)]
|
358
|
-
else:
|
359
|
-
return f"Unsupported operation {operation}"
|
360
|
-
|
361
|
-
try:
|
362
|
-
# Use a stack-based method to properly parse matrices
|
363
|
-
elements = []
|
364
|
-
buffer = ''
|
365
|
-
bracket_level = 0
|
366
|
-
operators = set('+-*/')
|
367
|
-
|
368
|
-
for char in expression:
|
369
|
-
if char == '[':
|
370
|
-
if bracket_level == 0 and buffer.strip():
|
371
|
-
elements.append(buffer.strip())
|
372
|
-
buffer = ''
|
373
|
-
bracket_level += 1
|
374
|
-
elif char == ']':
|
375
|
-
bracket_level -= 1
|
376
|
-
if bracket_level == 0:
|
377
|
-
buffer += char
|
378
|
-
elements.append(buffer.strip())
|
379
|
-
buffer = ''
|
380
|
-
continue
|
381
|
-
if bracket_level == 0 and char in operators:
|
382
|
-
if buffer.strip():
|
383
|
-
elements.append(buffer.strip())
|
384
|
-
buffer = ''
|
385
|
-
elements.append(char)
|
386
|
-
else:
|
387
|
-
buffer += char
|
388
|
-
|
389
|
-
if buffer.strip():
|
390
|
-
elements.append(buffer.strip())
|
391
|
-
|
392
|
-
result = ast.literal_eval(elements[0])
|
393
|
-
|
394
|
-
if not any(isinstance(row, list) for row in result):
|
395
|
-
result = [result] # Convert 1D matrix to 2D
|
396
|
-
|
397
|
-
i = 1
|
398
|
-
while i < len(elements):
|
399
|
-
operation = elements[i]
|
400
|
-
matrix = ast.literal_eval(elements[i + 1])
|
401
|
-
|
402
|
-
if not any(isinstance(row, list) for row in matrix):
|
403
|
-
matrix = [matrix]
|
404
|
-
|
405
|
-
operation_result = elementwise_operation(result, matrix, operation)
|
406
|
-
|
407
|
-
# Check if the operation resulted in an error message
|
408
|
-
if isinstance(operation_result, str):
|
409
|
-
return operation_result
|
410
|
-
|
411
|
-
result = operation_result
|
412
|
-
i += 2
|
413
|
-
|
414
|
-
# Create a LaTeX-style matrix representation
|
415
|
-
matrix_entries = '\\\\'.join(' & '.join(str(x) for x in row) for row in result)
|
416
|
-
return r"\begin{bmatrix}" + f"{matrix_entries}" + r"\end{bmatrix}"
|
417
|
-
|
418
|
-
except Exception as e:
|
419
|
-
return f"Error computing matrix operation: {e}"
|
420
|
-
|
421
|
-
|
422
|
-
def compute_ordered_series_expression(expression: str) -> str:
|
423
|
-
"""
|
424
|
-
Computes the result of operations on ordered series expressed as 1D lists, including discrete difference (ddd),
|
425
|
-
and returns it as a string.
|
426
|
-
|
427
|
-
The function first applies the discrete difference operator to any series where applicable, then evaluates
|
428
|
-
arithmetic operations between series.
|
429
|
-
|
430
|
-
Parameters:
|
431
|
-
expression (str): The series operation expression to compute. Includes operations "+", "-", "*", "/", and "ddd".
|
432
|
-
|
433
|
-
Returns:
|
434
|
-
str: The string representation of the resultant series after performing operations, or an error message
|
435
|
-
if the series lengths do not match.
|
436
|
-
|
437
|
-
Raises:
|
438
|
-
ValueError: If the expression cannot be evaluated.
|
439
|
-
"""
|
440
|
-
|
441
|
-
def elementwise_operation(series1: List[float], series2: List[float], operation: str) -> List[float]:
|
442
|
-
if len(series1) != len(series2):
|
443
|
-
return "Operations between ordered series must involve series of equal length"
|
444
|
-
|
445
|
-
if operation == '+':
|
446
|
-
return [a + b for a, b in zip(series1, series2)]
|
447
|
-
elif operation == '-':
|
448
|
-
return [a - b for a, b in zip(series1, series2)]
|
449
|
-
elif operation == '*':
|
450
|
-
return [a * b for a, b in zip(series1, series2)]
|
451
|
-
elif operation == '/':
|
452
|
-
return [a / b for a, b in zip(series1, series2) if b != 0]
|
453
|
-
else:
|
454
|
-
return f"Unsupported operation {operation}"
|
455
|
-
|
456
|
-
def discrete_difference(series: list) -> list:
|
457
|
-
"""Computes the discrete difference of a series."""
|
458
|
-
return [series[i + 1] - series[i] for i in range(len(series) - 1)]
|
459
|
-
|
460
|
-
try:
|
461
|
-
# First, apply the discrete difference operator where applicable
|
462
|
-
pattern = r'ddd\((\[[^\]]*\])\)'
|
463
|
-
matches = re.findall(pattern, expression)
|
464
|
-
|
465
|
-
for match in matches:
|
466
|
-
if match.strip() == '[]':
|
467
|
-
result_series = [] # Handle the empty list case
|
468
|
-
else:
|
469
|
-
series = ast.literal_eval(match)
|
470
|
-
result_series = discrete_difference(series)
|
471
|
-
expression = expression.replace(f'ddd({match})', str(result_series))
|
472
|
-
|
473
|
-
# Now parse and evaluate the full expression with basic operations
|
474
|
-
elements = []
|
475
|
-
buffer = ''
|
476
|
-
bracket_level = 0
|
477
|
-
operators = set('+-*/')
|
478
|
-
|
479
|
-
for char in expression:
|
480
|
-
if char == '[':
|
481
|
-
if bracket_level == 0 and buffer.strip():
|
482
|
-
elements.append(buffer.strip())
|
483
|
-
buffer = ''
|
484
|
-
bracket_level += 1
|
485
|
-
elif char == ']':
|
486
|
-
bracket_level -= 1
|
487
|
-
if bracket_level == 0:
|
488
|
-
buffer += char
|
489
|
-
elements.append(buffer.strip())
|
490
|
-
buffer = ''
|
491
|
-
continue
|
492
|
-
if bracket_level == 0 and char in operators:
|
493
|
-
if buffer.strip():
|
494
|
-
elements.append(buffer.strip())
|
495
|
-
buffer = ''
|
496
|
-
elements.append(char)
|
497
|
-
else:
|
498
|
-
buffer += char
|
499
|
-
|
500
|
-
if buffer.strip():
|
501
|
-
elements.append(buffer.strip())
|
502
|
-
|
503
|
-
result = ast.literal_eval(elements[0])
|
504
|
-
|
505
|
-
i = 1
|
506
|
-
while i < len(elements):
|
507
|
-
operation = elements[i]
|
508
|
-
series = ast.literal_eval(elements[i + 1])
|
509
|
-
operation_result = elementwise_operation(result, series, operation)
|
510
|
-
|
511
|
-
# Check if the operation resulted in an error message
|
512
|
-
if isinstance(operation_result, str):
|
513
|
-
return operation_result
|
514
|
-
|
515
|
-
result = operation_result
|
516
|
-
i += 2
|
517
|
-
|
518
|
-
return str(result)
|
519
|
-
|
520
|
-
except Exception as e:
|
521
|
-
return f"Error computing ordered series operation: {e}"
|
522
|
-
|
523
|
-
|
524
|
-
def get_prime_factors_latex(n: int) -> str:
|
525
|
-
"""
|
526
|
-
Computes the prime factors of a number and returns the factorization as a LaTeX string.
|
527
|
-
|
528
|
-
Determines the prime factorization of the given integer. The result is formatted as a LaTeX
|
529
|
-
string, enabling easy integration into documents or presentations that require mathematical notation.
|
530
|
-
|
531
|
-
Parameters:
|
532
|
-
n (int): The number for which to compute prime factors.
|
533
|
-
|
534
|
-
Returns:
|
535
|
-
str: The LaTeX representation of the prime factorization.
|
536
|
-
"""
|
537
|
-
|
538
|
-
factors = []
|
539
|
-
while n % 2 == 0:
|
540
|
-
factors.append(2)
|
541
|
-
n //= 2
|
542
|
-
for i in range(3, int(math.sqrt(n)) + 1, 2):
|
543
|
-
while n % i == 0:
|
544
|
-
factors.append(i)
|
545
|
-
n //= i
|
546
|
-
if n > 2:
|
547
|
-
factors.append(n)
|
548
|
-
|
549
|
-
factor_counts = {factor: factors.count(factor) for factor in set(factors)}
|
550
|
-
latex_factors = [f"{factor}^{{{count}}}" if count > 1 else str(
|
551
|
-
factor) for factor, count in factor_counts.items()]
|
552
|
-
return " \\cdot ".join(latex_factors)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: rgwfuncs
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.32
|
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,43 +154,27 @@ 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_prime_factors_latex`
|
158
158
|
|
159
|
-
|
159
|
+
Computes prime factors of a number and presents them in LaTeX format.
|
160
160
|
|
161
161
|
• Parameters:
|
162
|
-
- `
|
163
|
-
- `subs` (Optional[Dict[str, float]]): An optional dictionary of substitutions where the keys are variable names in the expression, and the values are the numbers with which to substitute those variables.
|
162
|
+
- `n` (int): The integer to factorize.
|
164
163
|
|
165
164
|
• Returns:
|
166
|
-
- `str`:
|
167
|
-
|
168
|
-
• Raises:
|
169
|
-
- `ValueError`: If the expression cannot be parsed due to syntax errors.
|
165
|
+
- `str`: Prime factorization in LaTeX.
|
170
166
|
|
171
167
|
• Example:
|
172
168
|
|
173
|
-
from rgwfuncs import
|
174
|
-
|
175
|
-
#
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
print(
|
182
|
-
|
183
|
-
# Another example with partial substitution
|
184
|
-
latex_result3 = python_polynomial_expression_to_latex("x**2 + y**2", {"x": 3})
|
185
|
-
print(latex_result3) # Output: "y^{2} + 9"
|
186
|
-
|
187
|
-
# Trigonometric functions included with symbolic variables
|
188
|
-
latex_result4 = python_polynomial_expression_to_latex("sin(x+z**2) + cos(y)", {"x": 55})
|
189
|
-
print(latex_result4) # Output: "cos y + sin \\left(z^{2} + 55\\right)"
|
190
|
-
|
191
|
-
# Simplified trigonometric functions example with substitution
|
192
|
-
latex_result5 = python_polynomial_expression_to_latex("sin(x) + cos(y)", {"x": 0})
|
193
|
-
print(latex_result5) # Output: "cos y"
|
169
|
+
from rgwfuncs import compute_prime_factors_latex
|
170
|
+
factors_1 = compute_prime_factors_latex(100)
|
171
|
+
print(factors_1) # Output: "2^{2} \cdot 5^{2}"
|
172
|
+
|
173
|
+
factors_2 = compute_prime_factors_latex(60)
|
174
|
+
print(factors_2) # Output: "2^{2} \cdot 3 \cdot 5"
|
175
|
+
|
176
|
+
factors_3 = compute_prime_factors_latex(17)
|
177
|
+
print(factors_3) # Output: "17"
|
194
178
|
|
195
179
|
--------------------------------------------------------------------------------
|
196
180
|
|
@@ -218,140 +202,157 @@ Computes the numerical result of a given expression, which can evaluate to a con
|
|
218
202
|
|
219
203
|
--------------------------------------------------------------------------------
|
220
204
|
|
221
|
-
### 3. `
|
205
|
+
### 3. `compute_constant_expression_involving_matrices`
|
222
206
|
|
223
|
-
|
207
|
+
Computes the result of a constant expression involving matrices and returns it as a LaTeX string.
|
224
208
|
|
225
209
|
• Parameters:
|
226
|
-
- `expression` (str): The
|
227
|
-
- `subs` (Optional[Dict[str, float]]): An optional dictionary of substitutions where keys are variable names and values are the numbers to substitute them with.
|
210
|
+
- `expression` (str): The constant expression involving matrices. Example format includes operations such as "+", "-", "*", "/".
|
228
211
|
|
229
212
|
• Returns:
|
230
|
-
- `str`: The
|
231
|
-
|
232
|
-
• Example Usage:
|
213
|
+
- `str`: The LaTeX-formatted string representation of the computed matrix, or an error message if the operations cannot be performed due to dimensional mismatches.
|
233
214
|
|
234
|
-
|
215
|
+
• Example:
|
235
216
|
|
236
|
-
|
237
|
-
simplified_expr1 = simplify_polynomial_expression("2*x + 3*x")
|
238
|
-
print(simplified_expr1) # Output: "5 x"
|
217
|
+
from rgwfuncs import compute_constant_expression_involving_matrices
|
239
218
|
|
240
|
-
# Example
|
241
|
-
|
242
|
-
print(
|
219
|
+
# Example with addition of 2D matrices
|
220
|
+
result = compute_constant_expression_involving_matrices("[[2, 6, 9], [1, 3, 5]] + [[1, 2, 3], [4, 5, 6]]")
|
221
|
+
print(result) # Output: \begin{bmatrix}3 & 8 & 12\\5 & 8 & 11\end{bmatrix}
|
243
222
|
|
244
|
-
# Example
|
245
|
-
|
246
|
-
print(
|
223
|
+
# Example of mixed operations with 1D matrices treated as 2D
|
224
|
+
result = compute_constant_expression_involving_matrices("[3, 6, 9] + [1, 2, 3] - [2, 2, 2]")
|
225
|
+
print(result) # Output: \begin{bmatrix}2 & 6 & 10\end{bmatrix}
|
247
226
|
|
248
|
-
# Example
|
249
|
-
|
250
|
-
print(
|
227
|
+
# Example with dimension mismatch
|
228
|
+
result = compute_constant_expression_involving_matrices("[[4, 3, 51]] + [[1, 1]]")
|
229
|
+
print(result) # Output: Operations between matrices must involve matrices of the same dimension
|
251
230
|
|
252
231
|
--------------------------------------------------------------------------------
|
253
232
|
|
254
|
-
### 4. `
|
233
|
+
### 4. `compute_constant_expression_involving_ordered_series`
|
234
|
+
|
235
|
+
Computes the result of a constant expression involving ordered series, and returns it as a Latex string.
|
255
236
|
|
256
|
-
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.
|
257
237
|
|
258
238
|
• Parameters:
|
259
|
-
- `expression` (str): A
|
260
|
-
- `variable` (str): The variable to solve for.
|
261
|
-
- `subs` (Optional[Dict[str, float]]): Substitutions for variables.
|
239
|
+
- `expression` (str): A series operation expression. Supports operations such as "+", "-", "*", "/", and `dd()` for discrete differences.
|
262
240
|
|
263
241
|
• Returns:
|
264
|
-
- `str`:
|
242
|
+
- `str`: The string representation of the resultant series after performing operations, or an error message if series lengths do not match.
|
265
243
|
|
266
244
|
• Example:
|
267
245
|
|
268
|
-
from rgwfuncs import
|
269
|
-
|
270
|
-
|
246
|
+
from rgwfuncs import compute_constant_expression_involving_ordered_series
|
247
|
+
|
248
|
+
# Example with addition and discrete differences
|
249
|
+
result = compute_constant_expression_involving_ordered_series("dd([2, 6, 9, 60]) + dd([78, 79, 80])")
|
250
|
+
print(result) # Output: [4, 3, 51] + [1, 1]
|
251
|
+
|
252
|
+
# Example with elementwise subtraction
|
253
|
+
result = compute_constant_expression_involving_ordered_series("[10, 15, 21] - [5, 5, 5]")
|
254
|
+
print(result) # Output: [5, 10, 16]
|
255
|
+
|
256
|
+
# Example with length mismatch
|
257
|
+
result = compute_constant_expression_involving_ordered_series("[4, 3, 51] + [1, 1]")
|
258
|
+
print(result) # Output: Operations between ordered series must involve series of equal length
|
271
259
|
|
272
|
-
solutions2 = solve_homogeneous_polynomial_expression("x**2 - 4", "x")
|
273
|
-
print(solutions2) # Output: "\left[-2, 2\right]"
|
274
|
-
|
275
260
|
--------------------------------------------------------------------------------
|
276
261
|
|
277
|
-
### 5. `
|
262
|
+
### 5. `python_polynomial_expression_to_latex`
|
278
263
|
|
279
|
-
|
264
|
+
Converts a polynomial expression written in Python syntax to a LaTeX formatted string. This function parses algebraic expressions provided as strings using Python’s syntax and translates them into equivalent LaTeX representations, making them suitable for academic or professional documentation. The function supports inclusion of named variables, with an option to substitute specific values into the expression.
|
280
265
|
|
281
266
|
• Parameters:
|
282
|
-
- `
|
267
|
+
- `expression` (str): The algebraic expression to convert to LaTeX. This should be a string formatted with Python syntax acceptable by SymPy.
|
268
|
+
- `subs` (Optional[Dict[str, float]]): An optional dictionary of substitutions where the keys are variable names in the expression, and the values are the numbers with which to substitute those variables.
|
283
269
|
|
284
270
|
• Returns:
|
285
|
-
- `str`:
|
271
|
+
- `str`: The LaTeX formatted string equivalent to the provided expression.
|
286
272
|
|
287
|
-
•
|
273
|
+
• Raises:
|
274
|
+
- `ValueError`: If the expression cannot be parsed due to syntax errors.
|
288
275
|
|
289
|
-
|
290
|
-
factors1 = get_prime_factors_latex(100)
|
291
|
-
print(factors1) # Output: "2^{2} \cdot 5^{2}"
|
276
|
+
• Example:
|
292
277
|
|
293
|
-
|
294
|
-
|
278
|
+
from rgwfuncs import python_polynomial_expression_to_latex
|
279
|
+
|
280
|
+
# Convert a simple polynomial expression to LaTeX format
|
281
|
+
latex_result1 = python_polynomial_expression_to_latex("x**2 + y**2")
|
282
|
+
print(latex_result1) # Output: "x^{2} + y^{2}"
|
283
|
+
|
284
|
+
# Convert polynomial expression with substituted values
|
285
|
+
latex_result2 = python_polynomial_expression_to_latex("x**2 + y**2", {"x": 3, "y": 4})
|
286
|
+
print(latex_result2) # Output: "25"
|
287
|
+
|
288
|
+
# Another example with partial substitution
|
289
|
+
latex_result3 = python_polynomial_expression_to_latex("x**2 + y**2", {"x": 3})
|
290
|
+
print(latex_result3) # Output: "y^{2} + 9"
|
291
|
+
|
292
|
+
# Trigonometric functions included with symbolic variables
|
293
|
+
latex_result4 = python_polynomial_expression_to_latex("sin(x+z**2) + cos(y)", {"x": 55})
|
294
|
+
print(latex_result4) # Output: "cos y + sin \\left(z^{2} + 55\\right)"
|
295
|
+
|
296
|
+
# Simplified trigonometric functions example with substitution
|
297
|
+
latex_result5 = python_polynomial_expression_to_latex("sin(x) + cos(y)", {"x": 0})
|
298
|
+
print(latex_result5) # Output: "cos y"
|
295
299
|
|
296
|
-
factors3 = get_prime_factors_latex(17)
|
297
|
-
print(factors3) # Output: "17"
|
298
|
-
|
299
300
|
--------------------------------------------------------------------------------
|
300
301
|
|
301
|
-
### 6. `
|
302
|
+
### 6. `simplify_polynomial_expression`
|
302
303
|
|
303
|
-
|
304
|
+
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.
|
304
305
|
|
305
306
|
• Parameters:
|
306
|
-
- `expression` (str):
|
307
|
+
- `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.
|
308
|
+
- `subs` (Optional[Dict[str, float]]): An optional dictionary of substitutions where keys are variable names and values are the numbers to substitute them with.
|
307
309
|
|
308
310
|
• Returns:
|
309
|
-
- `str`: The
|
311
|
+
- `str`: The simplified expression formatted as a LaTeX string.
|
310
312
|
|
311
|
-
• Example:
|
313
|
+
• Example Usage:
|
312
314
|
|
313
|
-
from rgwfuncs import
|
314
|
-
|
315
|
-
# Example with addition of 2D matrices
|
316
|
-
result = compute_matrix_expression("[[2, 6, 9], [1, 3, 5]] + [[1, 2, 3], [4, 5, 6]]")
|
317
|
-
print(result) # Output: \begin{bmatrix}3 & 8 & 12\\5 & 8 & 11\end{bmatrix}
|
318
|
-
|
319
|
-
# Example of mixed operations with 1D matrices treated as 2D
|
320
|
-
result = compute_matrix_expression("[3, 6, 9] + [1, 2, 3] - [2, 2, 2]")
|
321
|
-
print(result) # Output: \begin{bmatrix}2 & 6 & 10\end{bmatrix}
|
315
|
+
from rgwfuncs import simplify_polynomial_expression
|
322
316
|
|
323
|
-
# Example
|
324
|
-
|
325
|
-
print(
|
317
|
+
# Example 1: Simplifying a polynomial expression without substitutions
|
318
|
+
simplified_expr1 = simplify_polynomial_expression("2*x + 3*x")
|
319
|
+
print(simplified_expr1) # Output: "5 x"
|
320
|
+
|
321
|
+
# Example 2: Simplifying a complex expression involving derivatives
|
322
|
+
simplified_expr2 = simplify_polynomial_expression("(np.diff(3*x**8)) / (np.diff(8*x**30) * 11*y**3)")
|
323
|
+
print(simplified_expr2) # Output: r"\frac{1}{110 x^{22} y^{3}}"
|
324
|
+
|
325
|
+
# Example 3: Simplifying with substitutions
|
326
|
+
simplified_expr3 = simplify_polynomial_expression("x**2 + y**2", subs={"x": 3, "y": 4})
|
327
|
+
print(simplified_expr3) # Output: "25"
|
328
|
+
|
329
|
+
# Example 4: Simplifying with partial substitution
|
330
|
+
simplified_expr4 = simplify_polynomial_expression("a*b + b", subs={"b": 2})
|
331
|
+
print(simplified_expr4) # Output: "2 a + 2"
|
326
332
|
|
327
333
|
--------------------------------------------------------------------------------
|
328
334
|
|
329
|
-
### 7. `
|
335
|
+
### 7. `solve_homogeneous_polynomial_expression`
|
330
336
|
|
331
|
-
|
337
|
+
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.
|
332
338
|
|
333
339
|
• Parameters:
|
334
|
-
- `expression` (str): A
|
340
|
+
- `expression` (str): A string of the homogeneous polynomial expression to solve.
|
341
|
+
- `variable` (str): The variable to solve for.
|
342
|
+
- `subs` (Optional[Dict[str, float]]): Substitutions for variables.
|
335
343
|
|
336
344
|
• Returns:
|
337
|
-
- `str`:
|
345
|
+
- `str`: Solutions formatted in LaTeX.
|
338
346
|
|
339
347
|
• Example:
|
340
348
|
|
341
|
-
from rgwfuncs import
|
349
|
+
from rgwfuncs import solve_homogeneous_polynomial_expression
|
350
|
+
solutions1 = solve_homogeneous_polynomial_expression("a*x**2 + b*x + c", "x", {"a": 3, "b": 7, "c": 5})
|
351
|
+
print(solutions1) # Output: "\left[-7/6 - sqrt(11)*I/6, -7/6 + sqrt(11)*I/6\right]"
|
342
352
|
|
343
|
-
|
344
|
-
|
345
|
-
print(result) # Output: [4, 3, 51] + [1, 1]
|
353
|
+
solutions2 = solve_homogeneous_polynomial_expression("x**2 - 4", "x")
|
354
|
+
print(solutions2) # Output: "\left[-2, 2\right]"
|
346
355
|
|
347
|
-
# Example with elementwise subtraction
|
348
|
-
result = compute_ordered_series_expression("[10, 15, 21] - [5, 5, 5]")
|
349
|
-
print(result) # Output: [5, 10, 16]
|
350
|
-
|
351
|
-
# Example with length mismatch
|
352
|
-
result = compute_ordered_series_expression("[4, 3, 51] + [1, 1]")
|
353
|
-
print(result) # Output: Operations between ordered series must involve series of equal length
|
354
|
-
|
355
356
|
--------------------------------------------------------------------------------
|
356
357
|
|
357
358
|
## String Based Functions
|
@@ -0,0 +1,11 @@
|
|
1
|
+
rgwfuncs/__init__.py,sha256=wq3TPi1GdUo5tYtZtmhbBfBxrhhTYgQmiKNWjlDRMmQ,1473
|
2
|
+
rgwfuncs/algebra_lib.py,sha256=alyNFFKsuKJeeNMAyDnQJ-0VGzSORzP3zfWrTGyGmms,21591
|
3
|
+
rgwfuncs/df_lib.py,sha256=G_H3PXNVeseX2YLjkkrmO9eXA_7r29swUZlbPBDZjXA,66612
|
4
|
+
rgwfuncs/docs_lib.py,sha256=y3wSAOPO3qsA4HZ7xAtW8HimM8w-c8hjcEzMRLJ96ao,1960
|
5
|
+
rgwfuncs/str_lib.py,sha256=rtAdRlnSJIu3JhI-tA_A0wCiPK2m-zn5RoGpBxv_g-4,2228
|
6
|
+
rgwfuncs-0.0.32.dist-info/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
|
7
|
+
rgwfuncs-0.0.32.dist-info/METADATA,sha256=rAoDt3FK1ZnhjIvpM4dEH0_lXS2Vl68mPVMDUCdORrk,44946
|
8
|
+
rgwfuncs-0.0.32.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
9
|
+
rgwfuncs-0.0.32.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
|
10
|
+
rgwfuncs-0.0.32.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
|
11
|
+
rgwfuncs-0.0.32.dist-info/RECORD,,
|
rgwfuncs-0.0.30.dist-info/RECORD
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
rgwfuncs/__init__.py,sha256=hHXrHxIBSBVvmuVswZkr56sG4RhlGbx6LM_wRazsJkk,1429
|
2
|
-
rgwfuncs/algebra_lib.py,sha256=O0ux_y9Yt07S3_N0XfzNRFqnolKRxeEIK8eIdperG9Y,21653
|
3
|
-
rgwfuncs/df_lib.py,sha256=G_H3PXNVeseX2YLjkkrmO9eXA_7r29swUZlbPBDZjXA,66612
|
4
|
-
rgwfuncs/docs_lib.py,sha256=y3wSAOPO3qsA4HZ7xAtW8HimM8w-c8hjcEzMRLJ96ao,1960
|
5
|
-
rgwfuncs/str_lib.py,sha256=rtAdRlnSJIu3JhI-tA_A0wCiPK2m-zn5RoGpBxv_g-4,2228
|
6
|
-
rgwfuncs-0.0.30.dist-info/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
|
7
|
-
rgwfuncs-0.0.30.dist-info/METADATA,sha256=-Xi5O4P_KhBLCiRQq8w1j41ClVTOo9qGCyviqskVTcs,44923
|
8
|
-
rgwfuncs-0.0.30.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
9
|
-
rgwfuncs-0.0.30.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
|
10
|
-
rgwfuncs-0.0.30.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
|
11
|
-
rgwfuncs-0.0.30.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|