rgwfuncs 0.0.44__py3-none-any.whl → 0.0.46__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/algebra_lib.py +33 -11
- rgwfuncs/df_lib.py +1 -3
- {rgwfuncs-0.0.44.dist-info → rgwfuncs-0.0.46.dist-info}/METADATA +59 -3
- rgwfuncs-0.0.46.dist-info/RECORD +12 -0
- rgwfuncs-0.0.44.dist-info/RECORD +0 -12
- {rgwfuncs-0.0.44.dist-info → rgwfuncs-0.0.46.dist-info}/LICENSE +0 -0
- {rgwfuncs-0.0.44.dist-info → rgwfuncs-0.0.46.dist-info}/WHEEL +0 -0
- {rgwfuncs-0.0.44.dist-info → rgwfuncs-0.0.46.dist-info}/entry_points.txt +0 -0
- {rgwfuncs-0.0.44.dist-info → rgwfuncs-0.0.46.dist-info}/top_level.txt +0 -0
rgwfuncs/algebra_lib.py
CHANGED
@@ -2,7 +2,9 @@ import re
|
|
2
2
|
import math
|
3
3
|
import ast
|
4
4
|
# import numpy as np
|
5
|
-
from sympy import symbols, latex, simplify, solve, diff, Expr
|
5
|
+
from sympy import symbols, latex, simplify, solve, diff, Expr, factor, cancel
|
6
|
+
from sympy.core.sympify import SympifyError
|
7
|
+
from sympy.core import S
|
6
8
|
from sympy.parsing.sympy_parser import parse_expr
|
7
9
|
from sympy import __all__ as sympy_functions
|
8
10
|
from sympy.parsing.sympy_parser import (standard_transformations, implicit_multiplication_application)
|
@@ -417,18 +419,25 @@ def cancel_polynomial_expression(
|
|
417
419
|
"""
|
418
420
|
Cancels common factors within a polynomial expression and converts it to LaTeX format.
|
419
421
|
|
420
|
-
This function
|
421
|
-
|
422
|
+
This function parses an algebraic expression given in Python syntax, cancels any common factors,
|
423
|
+
and converts the resulting simplified expression into a LaTeX formatted string. The function can
|
424
|
+
also handle optional substitutions of variables before performing the cancellation.
|
422
425
|
|
423
426
|
Parameters:
|
424
|
-
expression (str): The algebraic expression to
|
425
|
-
|
427
|
+
expression (str): The algebraic expression to simplify and convert to LaTeX.
|
428
|
+
It should be a valid expression formatted using Python syntax.
|
429
|
+
subs (Optional[Dict[str, float]]): An optional dictionary where the keys are variable names in the
|
430
|
+
expression, and the values are the corresponding numbers to substitute
|
431
|
+
into the expression before simplification.
|
426
432
|
|
427
433
|
Returns:
|
428
|
-
str: The LaTeX formatted string of the
|
434
|
+
str: The LaTeX formatted string of the simplified expression. If the expression involves
|
435
|
+
indeterminate forms due to operations like division by zero, a descriptive error message is returned instead.
|
429
436
|
|
430
437
|
Raises:
|
431
|
-
ValueError: If the expression cannot be parsed due to syntax errors
|
438
|
+
ValueError: If the expression cannot be parsed due to syntax errors or if operations result in
|
439
|
+
undefined behavior, such as division by zero.
|
440
|
+
|
432
441
|
"""
|
433
442
|
transformations = standard_transformations + (implicit_multiplication_application,)
|
434
443
|
|
@@ -440,19 +449,32 @@ def cancel_polynomial_expression(
|
|
440
449
|
raise ValueError(f"Substitutions must be a dictionary. Received: {subs}")
|
441
450
|
subs_symbols = {symbols(k): v for k, v in subs.items()}
|
442
451
|
expr = expr.subs(subs_symbols)
|
443
|
-
|
444
|
-
|
445
|
-
|
452
|
+
|
453
|
+
canceled_expr = cancel(expr)
|
454
|
+
|
455
|
+
# Check for NaN or indeterminate forms
|
456
|
+
if canceled_expr.has(S.NaN) or canceled_expr.has(S.Infinity) or canceled_expr.has(S.ComplexInfinity):
|
457
|
+
return "Undefined result. This could be a division by zero error."
|
458
|
+
|
459
|
+
return canceled_expr
|
460
|
+
|
461
|
+
except (SyntaxError, ValueError, TypeError, AttributeError, ZeroDivisionError, SympifyError) as e:
|
462
|
+
return f"Error: {str(e)}"
|
446
463
|
|
447
464
|
variable_names = set(re.findall(r'\b[a-zA-Z]\w*\b', expression))
|
448
465
|
sym_vars = {var: symbols(var) for var in variable_names}
|
449
466
|
|
450
467
|
expr = parse_and_cancel_expression(expression, sym_vars)
|
468
|
+
|
469
|
+
# If the expression is already a string (i.e., "Undefined" or error message), return it directly
|
470
|
+
if isinstance(expr, str):
|
471
|
+
return expr
|
472
|
+
|
473
|
+
# Otherwise, convert to LaTeX as usual
|
451
474
|
latex_result = latex(expr)
|
452
475
|
return latex_result
|
453
476
|
|
454
477
|
|
455
|
-
|
456
478
|
def simplify_polynomial_expression(
|
457
479
|
expression: str,
|
458
480
|
subs: Optional[Dict[str, float]] = None
|
rgwfuncs/df_lib.py
CHANGED
@@ -400,7 +400,6 @@ def load_data_from_query(db_preset_name: str, query: str) -> pd.DataFrame:
|
|
400
400
|
|
401
401
|
return pd.DataFrame(rows, columns=columns)
|
402
402
|
|
403
|
-
|
404
403
|
def query_athena(db_preset: Dict[str, Any], query: str) -> pd.DataFrame:
|
405
404
|
|
406
405
|
def execute_athena_query(athena_client, query: str, database: str, output_bucket: str) -> str:
|
@@ -434,11 +433,10 @@ def load_data_from_query(db_preset_name: str, query: str) -> pd.DataFrame:
|
|
434
433
|
data = [[col.get("VarCharValue", None) for col in row["Data"]] for row in rows[1:]]
|
435
434
|
return pd.DataFrame(data, columns=columns)
|
436
435
|
|
437
|
-
|
438
436
|
aws_region = db_preset['aws_region']
|
439
437
|
database = db_preset['database']
|
440
438
|
output_bucket = db_preset['output_bucket']
|
441
|
-
|
439
|
+
|
442
440
|
athena_client = boto3.client(
|
443
441
|
'athena',
|
444
442
|
region_name=aws_region,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: rgwfuncs
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.46
|
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
|
@@ -402,7 +402,63 @@ Expands a polynomial expression written in Python syntax and converts it into a
|
|
402
402
|
|
403
403
|
--------------------------------------------------------------------------------
|
404
404
|
|
405
|
-
###
|
405
|
+
### 7. `factor_polynomial_expression`
|
406
|
+
|
407
|
+
Factors a polynomial expression written in Python syntax and converts it into a LaTeX formatted string. This function parses an algebraic expression, performs polynomial factoring using SymPy, and converts the factored expression into a LaTeX representation, ideal for academic or professional use. Optional substitutions can be made before factoring.
|
408
|
+
|
409
|
+
- Parameters:
|
410
|
+
- `expression` (str): The polynomial expression to factor and convert to LaTeX. This should be a valid expression formatted using Python syntax.
|
411
|
+
- `subs` (Optional[Dict[str, float]]): An optional dictionary of substitutions. The keys are variable names in the expression, and the values are numbers that replace these variables.
|
412
|
+
|
413
|
+
- Returns:
|
414
|
+
- `str`: The LaTeX formatted string representing the factored expression.
|
415
|
+
|
416
|
+
- Raises:
|
417
|
+
- `ValueError`: If the expression cannot be parsed due to syntax errors.
|
418
|
+
|
419
|
+
- Example:
|
420
|
+
|
421
|
+
from rgwfuncs import factor_polynomial_expression
|
422
|
+
|
423
|
+
# Factor a polynomial expression and convert to LaTeX
|
424
|
+
latex_result1 = factor_polynomial_expression("x**2 - 4")
|
425
|
+
print(latex_result1) # Output: "\left(x - 2\right) \left(x + 2\right)"
|
426
|
+
|
427
|
+
# Factor with substituted values
|
428
|
+
latex_result2 = factor_polynomial_expression("x**2 - y**2", {"y": 3})
|
429
|
+
print(latex_result2) # Output: "\left(x - 3\right) \left(x + 3\right)"
|
430
|
+
|
431
|
+
--------------------------------------------------------------------------------
|
432
|
+
|
433
|
+
### 8. `cancel_polynomial_expression`
|
434
|
+
|
435
|
+
Cancels common factors within a polynomial expression written in Python syntax and converts it to a LaTeX formatted string. This function parses an algebraic expression, cancels common factors using SymPy, and translates the reduced expression into a LaTeX representation. It can also accommodate optional substitutions to be made prior to simplification.
|
436
|
+
|
437
|
+
- Parameters:
|
438
|
+
- `expression` (str): The algebraic expression to simplify and convert to LaTeX. This string should be formatted using Python syntax.
|
439
|
+
- `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 to substitute.
|
440
|
+
|
441
|
+
- Returns:
|
442
|
+
- `str`: The LaTeX formatted string of the simplified expression. If the expression involves indeterminate forms due to operations like division by zero, a descriptive error message is returned instead.
|
443
|
+
|
444
|
+
- Raises:
|
445
|
+
- `ValueError`: If the expression cannot be parsed due to syntax errors or involves undefined operations, such as division by zero.
|
446
|
+
|
447
|
+
- Example:
|
448
|
+
|
449
|
+
from rgwfuncs import cancel_polynomial_expression
|
450
|
+
|
451
|
+
# Cancel common factors within a polynomial expression
|
452
|
+
latex_result1 = cancel_polynomial_expression("(x**2 - 4) / (x - 2)")
|
453
|
+
print(latex_result1) # Output: "x + 2"
|
454
|
+
|
455
|
+
# Cancel with substituted values
|
456
|
+
latex_result2 = cancel_polynomial_expression("(x**2 - 4) / (x - 2)", {"x": 2})
|
457
|
+
print(latex_result2) # Output: "Undefined result. This could be a division by zero error."
|
458
|
+
|
459
|
+
--------------------------------------------------------------------------------
|
460
|
+
|
461
|
+
### 9. `simplify_polynomial_expression`
|
406
462
|
|
407
463
|
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.
|
408
464
|
|
@@ -435,7 +491,7 @@ Simplifies an algebraic expression in polynomial form and returns it in LaTeX fo
|
|
435
491
|
|
436
492
|
--------------------------------------------------------------------------------
|
437
493
|
|
438
|
-
###
|
494
|
+
### 10. `solve_homogeneous_polynomial_expression`
|
439
495
|
|
440
496
|
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.
|
441
497
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
rgwfuncs/__init__.py,sha256=vs8xv3IVx7KGpPxEXrIePD3gb_QI1XTXpD_n9817foA,1610
|
2
|
+
rgwfuncs/algebra_lib.py,sha256=cxZdfZuOVz9GUhLIp2WMDxlFTR7A-5c0yP8VlCkyKV0,28359
|
3
|
+
rgwfuncs/df_lib.py,sha256=qqRQdakheLy8wMZRBfHwKyIp8DmdZIWfAiLKWgq03QU,68977
|
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.46.dist-info/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
|
8
|
+
rgwfuncs-0.0.46.dist-info/METADATA,sha256=WKJvt71r9H5-MKOcnIa9q_118-X4OomoA-OpzWAbm6c,55152
|
9
|
+
rgwfuncs-0.0.46.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
10
|
+
rgwfuncs-0.0.46.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
|
11
|
+
rgwfuncs-0.0.46.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
|
12
|
+
rgwfuncs-0.0.46.dist-info/RECORD,,
|
rgwfuncs-0.0.44.dist-info/RECORD
DELETED
@@ -1,12 +0,0 @@
|
|
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,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|