rgwfuncs 0.0.42__py3-none-any.whl → 0.0.44__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_constant_expression_involving_matrices, compute_constant_expression_involving_ordered_series, compute_prime_factors, expand_polynomial_expression, python_polynomial_expression_to_latex, simplify_polynomial_expression, solve_homogeneous_polynomial_expression
4
+ from .algebra_lib import cancel_polynomial_expression, compute_constant_expression, compute_constant_expression_involving_matrices, compute_constant_expression_involving_ordered_series, compute_prime_factors, expand_polynomial_expression, factor_polynomial_expression, 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 .interactive_shell_lib import interactive_shell
rgwfuncs/algebra_lib.py CHANGED
@@ -320,6 +320,7 @@ def python_polynomial_expression_to_latex(
320
320
  latex_result = latex(expr)
321
321
  return latex_result
322
322
 
323
+
323
324
  def expand_polynomial_expression(
324
325
  expression: str,
325
326
  subs: Optional[Dict[str, float]] = None
@@ -327,15 +328,15 @@ def expand_polynomial_expression(
327
328
  """
328
329
  Expands a polynomial expression written in Python syntax and converts it to LaTeX format.
329
330
 
330
- This function takes an algebraic expression written in Python syntax,
331
- applies polynomial expansion, and converts the expanded expression
331
+ This function takes an algebraic expression written in Python syntax,
332
+ applies polynomial expansion, and converts the expanded expression
332
333
  to a LaTeX formatted string. The expression should be compatible with sympy.
333
334
 
334
335
  Parameters:
335
- expression (str): The algebraic expression to expand and convert to LaTeX.
336
+ expression (str): The algebraic expression to expand and convert to LaTeX.
336
337
  The expression should be written using Python syntax.
337
- subs (Optional[Dict[str, float]]): An optional dictionary of substitutions
338
- to apply to variables in the expression
338
+ subs (Optional[Dict[str, float]]): An optional dictionary of substitutions
339
+ to apply to variables in the expression
339
340
  before expansion.
340
341
 
341
342
  Returns:
@@ -345,15 +346,18 @@ def expand_polynomial_expression(
345
346
  ValueError: If the expression cannot be parsed due to syntax errors.
346
347
  """
347
348
  transformations = standard_transformations + (implicit_multiplication_application,)
348
-
349
+
349
350
  def parse_and_expand_expression(expr_str: str, sym_vars: Dict[str, symbols]) -> symbols:
350
351
  try:
351
352
  expr = parse_expr(expr_str, local_dict=sym_vars, transformations=transformations)
352
353
  if subs:
354
+ # Ensure that subs is a dictionary
355
+ if not isinstance(subs, dict):
356
+ raise ValueError(f"Substitutions must be a dictionary. Received: {subs}")
353
357
  subs_symbols = {symbols(k): v for k, v in subs.items()}
354
358
  expr = expr.subs(subs_symbols)
355
359
  return expr.expand()
356
- except (SyntaxError, ValueError, TypeError) as e:
360
+ except (SyntaxError, ValueError, TypeError, AttributeError) as e:
357
361
  raise ValueError(f"Error parsing expression: {expr_str}. Error: {e}")
358
362
 
359
363
  variable_names = set(re.findall(r'\b[a-zA-Z]\w*\b', expression))
@@ -364,6 +368,90 @@ def expand_polynomial_expression(
364
368
  return latex_result
365
369
 
366
370
 
371
+ def factor_polynomial_expression(
372
+ expression: str,
373
+ subs: Optional[Dict[str, float]] = None
374
+ ) -> str:
375
+ """
376
+ Factors a polynomial expression written in Python syntax and converts it to LaTeX format.
377
+
378
+ This function accepts an algebraic expression in Python syntax, performs polynomial factoring,
379
+ and translates the factored expression into a LaTeX formatted string.
380
+
381
+ Parameters:
382
+ expression (str): The algebraic expression to factor and convert to LaTeX.
383
+ subs (Optional[Dict[str, float]]): An optional dictionary of substitutions to apply before factoring.
384
+
385
+ Returns:
386
+ str: The LaTeX formatted string of the factored expression.
387
+
388
+ Raises:
389
+ ValueError: If the expression cannot be parsed due to syntax errors.
390
+ """
391
+ transformations = standard_transformations + (implicit_multiplication_application,)
392
+
393
+ def parse_and_factor_expression(expr_str: str, sym_vars: Dict[str, symbols]) -> symbols:
394
+ try:
395
+ expr = parse_expr(expr_str, local_dict=sym_vars, transformations=transformations)
396
+ if subs:
397
+ if not isinstance(subs, dict):
398
+ raise ValueError(f"Substitutions must be a dictionary. Received: {subs}")
399
+ subs_symbols = {symbols(k): v for k, v in subs.items()}
400
+ expr = expr.subs(subs_symbols)
401
+ return factor(expr)
402
+ except (SyntaxError, ValueError, TypeError, AttributeError) as e:
403
+ raise ValueError(f"Error parsing expression: {expr_str}. Error: {e}")
404
+
405
+ variable_names = set(re.findall(r'\b[a-zA-Z]\w*\b', expression))
406
+ sym_vars = {var: symbols(var) for var in variable_names}
407
+
408
+ expr = parse_and_factor_expression(expression, sym_vars)
409
+ latex_result = latex(expr)
410
+ return latex_result
411
+
412
+
413
+ def cancel_polynomial_expression(
414
+ expression: str,
415
+ subs: Optional[Dict[str, float]] = None
416
+ ) -> str:
417
+ """
418
+ Cancels common factors within a polynomial expression and converts it to LaTeX format.
419
+
420
+ This function takes an algebraic expression written in Python syntax,
421
+ cancels common factors, and converts the reduced expression into a LaTeX formatted string.
422
+
423
+ Parameters:
424
+ expression (str): The algebraic expression to cancel and convert to LaTeX.
425
+ subs (Optional[Dict[str, float]]): An optional dictionary of substitutions to apply before canceling.
426
+
427
+ Returns:
428
+ str: The LaTeX formatted string of the canceled expression.
429
+
430
+ Raises:
431
+ ValueError: If the expression cannot be parsed due to syntax errors.
432
+ """
433
+ transformations = standard_transformations + (implicit_multiplication_application,)
434
+
435
+ def parse_and_cancel_expression(expr_str: str, sym_vars: Dict[str, symbols]) -> symbols:
436
+ try:
437
+ expr = parse_expr(expr_str, local_dict=sym_vars, transformations=transformations)
438
+ if subs:
439
+ if not isinstance(subs, dict):
440
+ raise ValueError(f"Substitutions must be a dictionary. Received: {subs}")
441
+ subs_symbols = {symbols(k): v for k, v in subs.items()}
442
+ expr = expr.subs(subs_symbols)
443
+ return cancel(expr)
444
+ except (SyntaxError, ValueError, TypeError, AttributeError) as e:
445
+ raise ValueError(f"Error parsing expression: {expr_str}. Error: {e}")
446
+
447
+ variable_names = set(re.findall(r'\b[a-zA-Z]\w*\b', expression))
448
+ sym_vars = {var: symbols(var) for var in variable_names}
449
+
450
+ expr = parse_and_cancel_expression(expression, sym_vars)
451
+ latex_result = latex(expr)
452
+ return latex_result
453
+
454
+
367
455
 
368
456
  def simplify_polynomial_expression(
369
457
  expression: str,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rgwfuncs
3
- Version: 0.0.42
3
+ Version: 0.0.44
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
@@ -0,0 +1,12 @@
1
+ rgwfuncs/__init__.py,sha256=vs8xv3IVx7KGpPxEXrIePD3gb_QI1XTXpD_n9817foA,1610
2
+ rgwfuncs/algebra_lib.py,sha256=SePb004VpQpmd95FIfpmqjuj8Bu9qgq43aTJtRpe_Og,27162
3
+ rgwfuncs/df_lib.py,sha256=b6uMBbj7JrTUusbBGSlGI6jJ37yCN5lb6Oiq-C9oGzg,68987
4
+ rgwfuncs/docs_lib.py,sha256=y3wSAOPO3qsA4HZ7xAtW8HimM8w-c8hjcEzMRLJ96ao,1960
5
+ rgwfuncs/interactive_shell_lib.py,sha256=A7EWsYxAfDev_N0-2GjRvAtp0bAwBPHIczXb8Gu9fzI,1107
6
+ rgwfuncs/str_lib.py,sha256=rtAdRlnSJIu3JhI-tA_A0wCiPK2m-zn5RoGpBxv_g-4,2228
7
+ rgwfuncs-0.0.44.dist-info/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
8
+ rgwfuncs-0.0.44.dist-info/METADATA,sha256=5aCULg0UJ8Mylbzkv1TopiApMKAIS_y0-oHOKmIko5o,52072
9
+ rgwfuncs-0.0.44.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
10
+ rgwfuncs-0.0.44.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
11
+ rgwfuncs-0.0.44.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
12
+ rgwfuncs-0.0.44.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- rgwfuncs/__init__.py,sha256=j1SH_GGf9EPXWvhKd_RWDMUI8GXvJGniq4whdmC-tRk,1550
2
- rgwfuncs/algebra_lib.py,sha256=OWltGhJqlP7mS0VszjeSICKQZjNlCrLjWVlaKwrb4Og,23435
3
- rgwfuncs/df_lib.py,sha256=b6uMBbj7JrTUusbBGSlGI6jJ37yCN5lb6Oiq-C9oGzg,68987
4
- rgwfuncs/docs_lib.py,sha256=y3wSAOPO3qsA4HZ7xAtW8HimM8w-c8hjcEzMRLJ96ao,1960
5
- rgwfuncs/interactive_shell_lib.py,sha256=A7EWsYxAfDev_N0-2GjRvAtp0bAwBPHIczXb8Gu9fzI,1107
6
- rgwfuncs/str_lib.py,sha256=rtAdRlnSJIu3JhI-tA_A0wCiPK2m-zn5RoGpBxv_g-4,2228
7
- rgwfuncs-0.0.42.dist-info/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
8
- rgwfuncs-0.0.42.dist-info/METADATA,sha256=xxKivycP7sQ5oLN65i5CIzl3H_yAMTf7HgO9uLUM_Vk,52072
9
- rgwfuncs-0.0.42.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
10
- rgwfuncs-0.0.42.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
11
- rgwfuncs-0.0.42.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
12
- rgwfuncs-0.0.42.dist-info/RECORD,,