rgwfuncs 0.0.29__py3-none-any.whl → 0.0.31__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 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, compute_matrix_expression, compute_ordered_series_expression, get_prime_factors_latex, simplify_polynomial_expression, solve_homogeneous_polynomial_expression
4
+ from .algebra_lib import compute_constant_expression, compute_constant_expression_involving_matrices, compute_constant_expression_involving_ordered_series, get_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
@@ -4,6 +4,9 @@ import ast
4
4
  # import numpy as np
5
5
  from sympy import symbols, latex, simplify, solve, diff, Expr
6
6
  from sympy.parsing.sympy_parser import parse_expr
7
+ from sympy import __all__ as sympy_functions
8
+ from sympy.parsing.sympy_parser import (standard_transformations, implicit_multiplication_application)
9
+
7
10
  from typing import Tuple, List, Dict, Optional
8
11
 
9
12
 
@@ -37,6 +40,258 @@ def compute_constant_expression(expression: str) -> float:
37
40
  raise ValueError(f"Error computing expression: {e}")
38
41
 
39
42
 
43
+ def compute_constant_expression_involving_matrices(expression: str) -> str:
44
+ """
45
+ Computes the result of a constant expression involving matrices and returns it as a LaTeX string.
46
+
47
+ Parameters:
48
+ expression (str): The constant expression involving matrices. Example format includes operations such as "+",
49
+ "-", "*", "/".
50
+
51
+ Returns:
52
+ str: The LaTeX-formatted string representation of the result or a message indicating an error in dimensions.
53
+ """
54
+
55
+ def elementwise_operation(matrix1: List[List[float]], matrix2: List[List[float]], operation: str) -> List[List[float]]:
56
+ if len(matrix1) != len(matrix2) or any(len(row1) != len(row2) for row1, row2 in zip(matrix1, matrix2)):
57
+ return "Operations between matrices must involve matrices of the same dimension"
58
+
59
+ if operation == '+':
60
+ return [[a + b for a, b in zip(row1, row2)] for row1, row2 in zip(matrix1, matrix2)]
61
+ elif operation == '-':
62
+ return [[a - b for a, b in zip(row1, row2)] for row1, row2 in zip(matrix1, matrix2)]
63
+ elif operation == '*':
64
+ return [[a * b for a, b in zip(row1, row2)] for row1, row2 in zip(matrix1, matrix2)]
65
+ elif operation == '/':
66
+ return [[a / b for a, b in zip(row1, row2) if b != 0] for row1, row2 in zip(matrix1, matrix2)]
67
+ else:
68
+ return f"Unsupported operation {operation}"
69
+
70
+ try:
71
+ # Use a stack-based method to properly parse matrices
72
+ elements = []
73
+ buffer = ''
74
+ bracket_level = 0
75
+ operators = set('+-*/')
76
+
77
+ for char in expression:
78
+ if char == '[':
79
+ if bracket_level == 0 and buffer.strip():
80
+ elements.append(buffer.strip())
81
+ buffer = ''
82
+ bracket_level += 1
83
+ elif char == ']':
84
+ bracket_level -= 1
85
+ if bracket_level == 0:
86
+ buffer += char
87
+ elements.append(buffer.strip())
88
+ buffer = ''
89
+ continue
90
+ if bracket_level == 0 and char in operators:
91
+ if buffer.strip():
92
+ elements.append(buffer.strip())
93
+ buffer = ''
94
+ elements.append(char)
95
+ else:
96
+ buffer += char
97
+
98
+ if buffer.strip():
99
+ elements.append(buffer.strip())
100
+
101
+ result = ast.literal_eval(elements[0])
102
+
103
+ if not any(isinstance(row, list) for row in result):
104
+ result = [result] # Convert 1D matrix to 2D
105
+
106
+ i = 1
107
+ while i < len(elements):
108
+ operation = elements[i]
109
+ matrix = ast.literal_eval(elements[i + 1])
110
+
111
+ if not any(isinstance(row, list) for row in matrix):
112
+ matrix = [matrix]
113
+
114
+ operation_result = elementwise_operation(result, matrix, operation)
115
+
116
+ # Check if the operation resulted in an error message
117
+ if isinstance(operation_result, str):
118
+ return operation_result
119
+
120
+ result = operation_result
121
+ i += 2
122
+
123
+ # Create a LaTeX-style matrix representation
124
+ matrix_entries = '\\\\'.join(' & '.join(str(x) for x in row) for row in result)
125
+ return r"\begin{bmatrix}" + f"{matrix_entries}" + r"\end{bmatrix}"
126
+
127
+ except Exception as e:
128
+ return f"Error computing matrix operation: {e}"
129
+
130
+
131
+ def compute_constant_expression_involving_ordered_series(expression: str) -> str:
132
+ """
133
+ Computes the result of a constant expression involving ordered series, and returns it as a Latex string.
134
+ Supports operations lile "+", "-", "*", "/", as well as "dd()" (the discrete difference operator).
135
+
136
+ The function first applies the discrete difference operator to any series where applicable, then evaluates
137
+ arithmetic operations between series.
138
+
139
+ Parameters:
140
+ expression (str): The series operation expression to compute. Includes operations "+", "-", "*", "/", and "dd()".
141
+
142
+ Returns:
143
+ str: The string representation of the resultant series after performing operations, or an error message
144
+ if the series lengths do not match.
145
+
146
+ Raises:
147
+ ValueError: If the expression cannot be evaluated.
148
+ """
149
+
150
+ def elementwise_operation(series1: List[float], series2: List[float], operation: str) -> List[float]:
151
+ if len(series1) != len(series2):
152
+ return "Operations between ordered series must involve series of equal length"
153
+
154
+ if operation == '+':
155
+ return [a + b for a, b in zip(series1, series2)]
156
+ elif operation == '-':
157
+ return [a - b for a, b in zip(series1, series2)]
158
+ elif operation == '*':
159
+ return [a * b for a, b in zip(series1, series2)]
160
+ elif operation == '/':
161
+ return [a / b for a, b in zip(series1, series2) if b != 0]
162
+ else:
163
+ return f"Unsupported operation {operation}"
164
+
165
+ def discrete_difference(series: list) -> list:
166
+ """Computes the discrete difference of a series."""
167
+ return [series[i + 1] - series[i] for i in range(len(series) - 1)]
168
+
169
+ try:
170
+ # First, apply the discrete difference operator where applicable
171
+ pattern = r'dd\((\[[^\]]*\])\)'
172
+ matches = re.findall(pattern, expression)
173
+
174
+ for match in matches:
175
+ if match.strip() == '[]':
176
+ result_series = [] # Handle the empty list case
177
+ else:
178
+ series = ast.literal_eval(match)
179
+ result_series = discrete_difference(series)
180
+ expression = expression.replace(f'dd({match})', str(result_series))
181
+
182
+ # Now parse and evaluate the full expression with basic operations
183
+ elements = []
184
+ buffer = ''
185
+ bracket_level = 0
186
+ operators = set('+-*/')
187
+
188
+ for char in expression:
189
+ if char == '[':
190
+ if bracket_level == 0 and buffer.strip():
191
+ elements.append(buffer.strip())
192
+ buffer = ''
193
+ bracket_level += 1
194
+ elif char == ']':
195
+ bracket_level -= 1
196
+ if bracket_level == 0:
197
+ buffer += char
198
+ elements.append(buffer.strip())
199
+ buffer = ''
200
+ continue
201
+ if bracket_level == 0 and char in operators:
202
+ if buffer.strip():
203
+ elements.append(buffer.strip())
204
+ buffer = ''
205
+ elements.append(char)
206
+ else:
207
+ buffer += char
208
+
209
+ if buffer.strip():
210
+ elements.append(buffer.strip())
211
+
212
+ result = ast.literal_eval(elements[0])
213
+
214
+ i = 1
215
+ while i < len(elements):
216
+ operation = elements[i]
217
+ series = ast.literal_eval(elements[i + 1])
218
+ operation_result = elementwise_operation(result, series, operation)
219
+
220
+ # Check if the operation resulted in an error message
221
+ if isinstance(operation_result, str):
222
+ return operation_result
223
+
224
+ result = operation_result
225
+ i += 2
226
+
227
+ return str(result)
228
+
229
+ except Exception as e:
230
+ return f"Error computing ordered series operation: {e}"
231
+
232
+
233
+
234
+
235
+ def python_polynomial_expression_to_latex(
236
+ expression: str,
237
+ subs: Optional[Dict[str, float]] = None
238
+ ) -> str:
239
+ """
240
+ Converts a polynomial expression written in Python syntax to LaTeX format.
241
+
242
+ This function takes an algebraic expression written in Python syntax and converts it
243
+ to a LaTeX formatted string. The expression is assumed to be in terms acceptable by
244
+ sympy, with named variables, and optionally includes substitutions for variables.
245
+
246
+ Parameters:
247
+ expression (str): The algebraic expression to convert to LaTeX. The expression should
248
+ be written using Python syntax.
249
+ subs (Optional[Dict[str, float]]): An optional dictionary of substitutions for variables
250
+ in the expression.
251
+
252
+ Returns:
253
+ str: The expression represented as a LaTeX string.
254
+
255
+ Raises:
256
+ ValueError: If the expression cannot be parsed due to syntax errors.
257
+ """
258
+
259
+ transformations = standard_transformations + (implicit_multiplication_application,)
260
+
261
+ def parse_and_convert_expression(expr_str: str, sym_vars: Dict[str, Expr]) -> Expr:
262
+ try:
263
+ # Parse with transformations to handle implicit multiplication
264
+ expr = parse_expr(expr_str, local_dict=sym_vars, transformations=transformations)
265
+ if subs:
266
+ subs_symbols = {symbols(k): v for k, v in subs.items()}
267
+ expr = expr.subs(subs_symbols)
268
+ return expr
269
+ except (SyntaxError, ValueError, TypeError) as e:
270
+ raise ValueError(f"Error parsing expression: {expr_str}. Error: {e}")
271
+
272
+ # Extract variable names used in the expression
273
+ variable_names = set(re.findall(r'\b[a-zA-Z]\w*\b', expression))
274
+ sym_vars = {var: symbols(var) for var in variable_names}
275
+
276
+ # Import all general function names from SymPy into local scope
277
+
278
+ # Dynamically add SymPy functions to the symbol dictionary
279
+ for func_name in sympy_functions:
280
+ try:
281
+ candidate = globals().get(func_name) or locals().get(func_name)
282
+ if callable(candidate): # Ensure it's actually a callable
283
+ sym_vars[func_name] = candidate
284
+ except KeyError:
285
+ continue # Skip any non-callable or unavailable items
286
+
287
+ # Attempt to parse the expression
288
+ expr = parse_and_convert_expression(expression, sym_vars)
289
+
290
+ # Convert the expression to LaTeX format
291
+ latex_result = latex(expr)
292
+ return latex_result
293
+
294
+
40
295
  def simplify_polynomial_expression(
41
296
  expression: str,
42
297
  subs: Optional[Dict[str, float]] = None
@@ -45,7 +300,7 @@ def simplify_polynomial_expression(
45
300
  Simplifies an algebraic expression in polynomial form and returns it in LaTeX format.
46
301
 
47
302
  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
303
+ The result is returned as a LaTeX formatted string, suitable for academic or professional
49
304
  documentation.
50
305
 
51
306
  Parameters:
@@ -218,11 +473,11 @@ def solve_homogeneous_polynomial_expression(
218
473
  subs: Optional[Dict[str, float]] = None
219
474
  ) -> str:
220
475
  """
221
- Solves a homogeneous polynomial expression for a specified variable and returns solutions
476
+ Solves a homogeneous polynomial expression for a specified variable and returns solutions
222
477
  in LaTeX format.
223
478
 
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
479
+ Assumes that the expression is homoegeneous (i.e. equal to zero), and solves for a
480
+ designated variable. May optionally include substitutions for other variables in the
226
481
  equation. The solutions are provided as a LaTeX formatted string.
227
482
 
228
483
  Parameters:
@@ -265,196 +520,6 @@ def solve_homogeneous_polynomial_expression(
265
520
  raise ValueError(f"Error solving the expression: {e}")
266
521
 
267
522
 
268
- def compute_matrix_expression(expression: str) -> str:
269
- """
270
- Computes the result of a matrix-like operation on 1D or 2D list inputs and returns it as a LaTeX string.
271
-
272
- Evaluates an operation where lists are treated as matrices, performs operations on them sequentially, and
273
- returns the result formatted as a LaTeX-style string.
274
-
275
- Parameters:
276
- expression (str): The matrix operation expression to compute. Example format includes operations such as "+", "-", "*", "/".
277
-
278
- Returns:
279
- str: The LaTeX-formatted string representation of the result or a message indicating an error in dimensions.
280
- """
281
-
282
- def elementwise_operation(matrix1: List[List[float]], matrix2: List[List[float]], operation: str) -> List[List[float]]:
283
- if len(matrix1) != len(matrix2) or any(len(row1) != len(row2) for row1, row2 in zip(matrix1, matrix2)):
284
- return "Operations between matrices must involve matrices of the same dimension"
285
-
286
- if operation == '+':
287
- return [[a + b for a, b in zip(row1, row2)] for row1, row2 in zip(matrix1, matrix2)]
288
- elif operation == '-':
289
- return [[a - b for a, b in zip(row1, row2)] for row1, row2 in zip(matrix1, matrix2)]
290
- elif operation == '*':
291
- return [[a * b for a, b in zip(row1, row2)] for row1, row2 in zip(matrix1, matrix2)]
292
- elif operation == '/':
293
- return [[a / b for a, b in zip(row1, row2) if b != 0] for row1, row2 in zip(matrix1, matrix2)]
294
- else:
295
- return f"Unsupported operation {operation}"
296
-
297
- try:
298
- # Use a stack-based method to properly parse matrices
299
- elements = []
300
- buffer = ''
301
- bracket_level = 0
302
- operators = set('+-*/')
303
-
304
- for char in expression:
305
- if char == '[':
306
- if bracket_level == 0 and buffer.strip():
307
- elements.append(buffer.strip())
308
- buffer = ''
309
- bracket_level += 1
310
- elif char == ']':
311
- bracket_level -= 1
312
- if bracket_level == 0:
313
- buffer += char
314
- elements.append(buffer.strip())
315
- buffer = ''
316
- continue
317
- if bracket_level == 0 and char in operators:
318
- if buffer.strip():
319
- elements.append(buffer.strip())
320
- buffer = ''
321
- elements.append(char)
322
- else:
323
- buffer += char
324
-
325
- if buffer.strip():
326
- elements.append(buffer.strip())
327
-
328
- result = ast.literal_eval(elements[0])
329
-
330
- if not any(isinstance(row, list) for row in result):
331
- result = [result] # Convert 1D matrix to 2D
332
-
333
- i = 1
334
- while i < len(elements):
335
- operation = elements[i]
336
- matrix = ast.literal_eval(elements[i + 1])
337
-
338
- if not any(isinstance(row, list) for row in matrix):
339
- matrix = [matrix]
340
-
341
- operation_result = elementwise_operation(result, matrix, operation)
342
-
343
- # Check if the operation resulted in an error message
344
- if isinstance(operation_result, str):
345
- return operation_result
346
-
347
- result = operation_result
348
- i += 2
349
-
350
- # Create a LaTeX-style matrix representation
351
- matrix_entries = '\\\\'.join(' & '.join(str(x) for x in row) for row in result)
352
- return r"\begin{bmatrix}" + f"{matrix_entries}" + r"\end{bmatrix}"
353
-
354
- except Exception as e:
355
- return f"Error computing matrix operation: {e}"
356
-
357
-
358
- def compute_ordered_series_expression(expression: str) -> str:
359
- """
360
- Computes the result of operations on ordered series expressed as 1D lists, including discrete difference (ddd),
361
- and returns it as a string.
362
-
363
- The function first applies the discrete difference operator to any series where applicable, then evaluates
364
- arithmetic operations between series.
365
-
366
- Parameters:
367
- expression (str): The series operation expression to compute. Includes operations "+", "-", "*", "/", and "ddd".
368
-
369
- Returns:
370
- str: The string representation of the resultant series after performing operations, or an error message
371
- if the series lengths do not match.
372
-
373
- Raises:
374
- ValueError: If the expression cannot be evaluated.
375
- """
376
-
377
- def elementwise_operation(series1: List[float], series2: List[float], operation: str) -> List[float]:
378
- if len(series1) != len(series2):
379
- return "Operations between ordered series must involve series of equal length"
380
-
381
- if operation == '+':
382
- return [a + b for a, b in zip(series1, series2)]
383
- elif operation == '-':
384
- return [a - b for a, b in zip(series1, series2)]
385
- elif operation == '*':
386
- return [a * b for a, b in zip(series1, series2)]
387
- elif operation == '/':
388
- return [a / b for a, b in zip(series1, series2) if b != 0]
389
- else:
390
- return f"Unsupported operation {operation}"
391
-
392
- def discrete_difference(series: list) -> list:
393
- """Computes the discrete difference of a series."""
394
- return [series[i + 1] - series[i] for i in range(len(series) - 1)]
395
-
396
- try:
397
- # First, apply the discrete difference operator where applicable
398
- pattern = r'ddd\((\[[^\]]*\])\)'
399
- matches = re.findall(pattern, expression)
400
-
401
- for match in matches:
402
- if match.strip() == '[]':
403
- result_series = [] # Handle the empty list case
404
- else:
405
- series = ast.literal_eval(match)
406
- result_series = discrete_difference(series)
407
- expression = expression.replace(f'ddd({match})', str(result_series))
408
-
409
- # Now parse and evaluate the full expression with basic operations
410
- elements = []
411
- buffer = ''
412
- bracket_level = 0
413
- operators = set('+-*/')
414
-
415
- for char in expression:
416
- if char == '[':
417
- if bracket_level == 0 and buffer.strip():
418
- elements.append(buffer.strip())
419
- buffer = ''
420
- bracket_level += 1
421
- elif char == ']':
422
- bracket_level -= 1
423
- if bracket_level == 0:
424
- buffer += char
425
- elements.append(buffer.strip())
426
- buffer = ''
427
- continue
428
- if bracket_level == 0 and char in operators:
429
- if buffer.strip():
430
- elements.append(buffer.strip())
431
- buffer = ''
432
- elements.append(char)
433
- else:
434
- buffer += char
435
-
436
- if buffer.strip():
437
- elements.append(buffer.strip())
438
-
439
- result = ast.literal_eval(elements[0])
440
-
441
- i = 1
442
- while i < len(elements):
443
- operation = elements[i]
444
- series = ast.literal_eval(elements[i + 1])
445
- operation_result = elementwise_operation(result, series, operation)
446
-
447
- # Check if the operation resulted in an error message
448
- if isinstance(operation_result, str):
449
- return operation_result
450
-
451
- result = operation_result
452
- i += 2
453
-
454
- return str(result)
455
-
456
- except Exception as e:
457
- return f"Error computing ordered series operation: {e}"
458
523
 
459
524
 
460
525
  def get_prime_factors_latex(n: int) -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rgwfuncs
3
- Version: 0.0.29
3
+ Version: 0.0.31
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
@@ -178,7 +178,104 @@ Computes the numerical result of a given expression, which can evaluate to a con
178
178
 
179
179
  --------------------------------------------------------------------------------
180
180
 
181
- ### 2. `simplify_polynomial_expression`
181
+ ### 2. `compute_constant_expression_involving_matrices`
182
+
183
+ Computes the result of a constant expression involving matrices and returns it as a LaTeX string.
184
+
185
+ • Parameters:
186
+ - `expression` (str): The constant expression involving matrices. Example format includes operations such as "+", "-", "*", "/".
187
+
188
+ • Returns:
189
+ - `str`: The LaTeX-formatted string representation of the computed matrix, or an error message if the operations cannot be performed due to dimensional mismatches.
190
+
191
+ • Example:
192
+
193
+ from rgwfuncs import compute_constant_expression_involving_matrices
194
+
195
+ # Example with addition of 2D matrices
196
+ result = compute_constant_expression_involving_matrices("[[2, 6, 9], [1, 3, 5]] + [[1, 2, 3], [4, 5, 6]]")
197
+ print(result) # Output: \begin{bmatrix}3 & 8 & 12\\5 & 8 & 11\end{bmatrix}
198
+
199
+ # Example of mixed operations with 1D matrices treated as 2D
200
+ result = compute_constant_expression_involving_matrices("[3, 6, 9] + [1, 2, 3] - [2, 2, 2]")
201
+ print(result) # Output: \begin{bmatrix}2 & 6 & 10\end{bmatrix}
202
+
203
+ # Example with dimension mismatch
204
+ result = compute_constant_expression_involving_matrices("[[4, 3, 51]] + [[1, 1]]")
205
+ print(result) # Output: Operations between matrices must involve matrices of the same dimension
206
+
207
+ --------------------------------------------------------------------------------
208
+
209
+ ### 3. `compute_constant_expression_involving_ordered_series`
210
+
211
+ Computes the result of a constant expression involving ordered series, and returns it as a Latex string.
212
+
213
+
214
+ • Parameters:
215
+ - `expression` (str): A series operation expression. Supports operations such as "+", "-", "*", "/", and `dd()` for discrete differences.
216
+
217
+ • Returns:
218
+ - `str`: The string representation of the resultant series after performing operations, or an error message if series lengths do not match.
219
+
220
+ • Example:
221
+
222
+ from rgwfuncs import compute_constant_expression_involving_ordered_series
223
+
224
+ # Example with addition and discrete differences
225
+ result = compute_constant_expression_involving_ordered_series("dd([2, 6, 9, 60]) + dd([78, 79, 80])")
226
+ print(result) # Output: [4, 3, 51] + [1, 1]
227
+
228
+ # Example with elementwise subtraction
229
+ result = compute_constant_expression_involving_ordered_series("[10, 15, 21] - [5, 5, 5]")
230
+ print(result) # Output: [5, 10, 16]
231
+
232
+ # Example with length mismatch
233
+ result = compute_constant_expression_involving_ordered_series("[4, 3, 51] + [1, 1]")
234
+ print(result) # Output: Operations between ordered series must involve series of equal length
235
+
236
+ --------------------------------------------------------------------------------
237
+
238
+ ### 4. `python_polynomial_expression_to_latex`
239
+
240
+ 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.
241
+
242
+ • Parameters:
243
+ - `expression` (str): The algebraic expression to convert to LaTeX. This should be a string formatted with Python syntax acceptable by SymPy.
244
+ - `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.
245
+
246
+ • Returns:
247
+ - `str`: The LaTeX formatted string equivalent to the provided expression.
248
+
249
+ • Raises:
250
+ - `ValueError`: If the expression cannot be parsed due to syntax errors.
251
+
252
+ • Example:
253
+
254
+ from rgwfuncs import python_polynomial_expression_to_latex
255
+
256
+ # Convert a simple polynomial expression to LaTeX format
257
+ latex_result1 = python_polynomial_expression_to_latex("x**2 + y**2")
258
+ print(latex_result1) # Output: "x^{2} + y^{2}"
259
+
260
+ # Convert polynomial expression with substituted values
261
+ latex_result2 = python_polynomial_expression_to_latex("x**2 + y**2", {"x": 3, "y": 4})
262
+ print(latex_result2) # Output: "25"
263
+
264
+ # Another example with partial substitution
265
+ latex_result3 = python_polynomial_expression_to_latex("x**2 + y**2", {"x": 3})
266
+ print(latex_result3) # Output: "y^{2} + 9"
267
+
268
+ # Trigonometric functions included with symbolic variables
269
+ latex_result4 = python_polynomial_expression_to_latex("sin(x+z**2) + cos(y)", {"x": 55})
270
+ print(latex_result4) # Output: "cos y + sin \\left(z^{2} + 55\\right)"
271
+
272
+ # Simplified trigonometric functions example with substitution
273
+ latex_result5 = python_polynomial_expression_to_latex("sin(x) + cos(y)", {"x": 0})
274
+ print(latex_result5) # Output: "cos y"
275
+
276
+ --------------------------------------------------------------------------------
277
+
278
+ ### 5. `simplify_polynomial_expression`
182
279
 
183
280
  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.
184
281
 
@@ -211,7 +308,7 @@ Simplifies an algebraic expression in polynomial form and returns it in LaTeX fo
211
308
 
212
309
  --------------------------------------------------------------------------------
213
310
 
214
- ### 3. `solve_homogeneous_polynomial_expression`
311
+ ### 6. `solve_homogeneous_polynomial_expression`
215
312
 
216
313
  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.
217
314
 
@@ -234,7 +331,7 @@ Solves a homogeneous polynomial expression for a specified variable and returns
234
331
 
235
332
  --------------------------------------------------------------------------------
236
333
 
237
- ### 4. `get_prime_factors_latex`
334
+ ### 7. `get_prime_factors_latex`
238
335
 
239
336
  Computes prime factors of a number and presents them in LaTeX format.
240
337
 
@@ -258,62 +355,6 @@ Computes prime factors of a number and presents them in LaTeX format.
258
355
 
259
356
  --------------------------------------------------------------------------------
260
357
 
261
- ### 5. `compute_matrix_expression`
262
-
263
- Computes the results of expressions containing 1D or 2D matrix operations and formats them as LaTeX strings.
264
-
265
- • Parameters:
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 (`/`).
267
-
268
- • Returns:
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.
270
-
271
- • Example:
272
-
273
- from rgwfuncs import compute_matrix_expression
274
-
275
- # Example with addition of 2D matrices
276
- result = compute_matrix_expression("[[2, 6, 9], [1, 3, 5]] + [[1, 2, 3], [4, 5, 6]]")
277
- print(result) # Output: \begin{bmatrix}3 & 8 & 12\\5 & 8 & 11\end{bmatrix}
278
-
279
- # Example of mixed operations with 1D matrices treated as 2D
280
- result = compute_matrix_expression("[3, 6, 9] + [1, 2, 3] - [2, 2, 2]")
281
- print(result) # Output: \begin{bmatrix}2 & 6 & 10\end{bmatrix}
282
-
283
- # Example with dimension mismatch
284
- result = compute_matrix_expression("[[4, 3, 51]] + [[1, 1]]")
285
- print(result) # Output: Operations between matrices must involve matrices of the same dimension
286
-
287
- --------------------------------------------------------------------------------
288
-
289
- ### 6. `compute_ordered_series_expression`
290
-
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.
292
-
293
- • Parameters:
294
- - `expression` (str): A series operation expression. Supports operations such as "+", "-", "*", "/", and `ddd()` for discrete differences.
295
-
296
- • Returns:
297
- - `str`: The string representation of the resultant series after performing operations, or an error message if series lengths do not match.
298
-
299
- • Example:
300
-
301
- from rgwfuncs import compute_ordered_series_expression
302
-
303
- # Example with addition and discrete differences
304
- result = compute_ordered_series_expression("ddd([2, 6, 9, 60]) + ddd([78, 79, 80])")
305
- print(result) # Output: [4, 3, 51] + [1, 1]
306
-
307
- # Example with elementwise subtraction
308
- result = compute_ordered_series_expression("[10, 15, 21] - [5, 5, 5]")
309
- print(result) # Output: [5, 10, 16]
310
-
311
- # Example with length mismatch
312
- result = compute_ordered_series_expression("[4, 3, 51] + [1, 1]")
313
- print(result) # Output: Operations between ordered series must involve series of equal length
314
-
315
- --------------------------------------------------------------------------------
316
-
317
358
  ## String Based Functions
318
359
 
319
360
  ### 1. send_telegram_message
@@ -0,0 +1,11 @@
1
+ rgwfuncs/__init__.py,sha256=Xei98Hu6tuFZMCAthCMgmkiD2ZWKKypArV4zcJ9Qtds,1469
2
+ rgwfuncs/algebra_lib.py,sha256=96rXb82urUVlrRgkpaNYNsap_ndSQc3NeWjFCG3aTYc,21587
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.31.dist-info/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
7
+ rgwfuncs-0.0.31.dist-info/METADATA,sha256=_oeyab985L-gFGP6woQfHRIg3jnX4XlLX6lU3BuxOts,44925
8
+ rgwfuncs-0.0.31.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
9
+ rgwfuncs-0.0.31.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
10
+ rgwfuncs-0.0.31.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
11
+ rgwfuncs-0.0.31.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- rgwfuncs/__init__.py,sha256=DdRwXNEo_bN8R3WOWhysKmuHMNiyC6dpBj0GWP4HR0E,1390
2
- rgwfuncs/algebra_lib.py,sha256=h3gGCcu6BOo1yTwprxx4pyaFO6MTYqKeiiJIruDcMhg,19037
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.29.dist-info/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
7
- rgwfuncs-0.0.29.dist-info/METADATA,sha256=hAU47MpLVyGntoeVhv1bqgeAM3KJnhgJKKDZzmK76mk,42739
8
- rgwfuncs-0.0.29.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
9
- rgwfuncs-0.0.29.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
10
- rgwfuncs-0.0.29.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
11
- rgwfuncs-0.0.29.dist-info/RECORD,,