rgwfuncs 0.0.29__py3-none-any.whl → 0.0.30__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 +64 -0
- {rgwfuncs-0.0.29.dist-info → rgwfuncs-0.0.30.dist-info}/METADATA +47 -7
- rgwfuncs-0.0.30.dist-info/RECORD +11 -0
- rgwfuncs-0.0.29.dist-info/RECORD +0 -11
- {rgwfuncs-0.0.29.dist-info → rgwfuncs-0.0.30.dist-info}/LICENSE +0 -0
- {rgwfuncs-0.0.29.dist-info → rgwfuncs-0.0.30.dist-info}/WHEEL +0 -0
- {rgwfuncs-0.0.29.dist-info → rgwfuncs-0.0.30.dist-info}/entry_points.txt +0 -0
- {rgwfuncs-0.0.29.dist-info → rgwfuncs-0.0.30.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, 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_matrix_expression, compute_ordered_series_expression, 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,67 @@ def compute_constant_expression(expression: str) -> float:
|
|
37
40
|
raise ValueError(f"Error computing expression: {e}")
|
38
41
|
|
39
42
|
|
43
|
+
def python_polynomial_expression_to_latex(
|
44
|
+
expression: str,
|
45
|
+
subs: Optional[Dict[str, float]] = None
|
46
|
+
) -> str:
|
47
|
+
"""
|
48
|
+
Converts a polynomial expression written in Python syntax to LaTeX format.
|
49
|
+
|
50
|
+
This function takes an algebraic expression written in Python syntax and converts it
|
51
|
+
to a LaTeX formatted string. The expression is assumed to be in terms acceptable by
|
52
|
+
sympy, with named variables, and optionally includes substitutions for variables.
|
53
|
+
|
54
|
+
Parameters:
|
55
|
+
expression (str): The algebraic expression to convert to LaTeX. The expression should
|
56
|
+
be written using Python syntax.
|
57
|
+
subs (Optional[Dict[str, float]]): An optional dictionary of substitutions for variables
|
58
|
+
in the expression.
|
59
|
+
|
60
|
+
Returns:
|
61
|
+
str: The expression represented as a LaTeX string.
|
62
|
+
|
63
|
+
Raises:
|
64
|
+
ValueError: If the expression cannot be parsed due to syntax errors.
|
65
|
+
"""
|
66
|
+
|
67
|
+
transformations = standard_transformations + (implicit_multiplication_application,)
|
68
|
+
|
69
|
+
def parse_and_convert_expression(expr_str: str, sym_vars: Dict[str, Expr]) -> Expr:
|
70
|
+
try:
|
71
|
+
# Parse with transformations to handle implicit multiplication
|
72
|
+
expr = parse_expr(expr_str, local_dict=sym_vars, transformations=transformations)
|
73
|
+
if subs:
|
74
|
+
subs_symbols = {symbols(k): v for k, v in subs.items()}
|
75
|
+
expr = expr.subs(subs_symbols)
|
76
|
+
return expr
|
77
|
+
except (SyntaxError, ValueError, TypeError) as e:
|
78
|
+
raise ValueError(f"Error parsing expression: {expr_str}. Error: {e}")
|
79
|
+
|
80
|
+
# Extract variable names used in the expression
|
81
|
+
variable_names = set(re.findall(r'\b[a-zA-Z]\w*\b', expression))
|
82
|
+
sym_vars = {var: symbols(var) for var in variable_names}
|
83
|
+
|
84
|
+
# Import all general function names from SymPy into local scope
|
85
|
+
|
86
|
+
# Dynamically add SymPy functions to the symbol dictionary
|
87
|
+
for func_name in sympy_functions:
|
88
|
+
try:
|
89
|
+
candidate = globals().get(func_name) or locals().get(func_name)
|
90
|
+
if callable(candidate): # Ensure it's actually a callable
|
91
|
+
sym_vars[func_name] = candidate
|
92
|
+
except KeyError:
|
93
|
+
continue # Skip any non-callable or unavailable items
|
94
|
+
|
95
|
+
# Attempt to parse the expression
|
96
|
+
expr = parse_and_convert_expression(expression, sym_vars)
|
97
|
+
|
98
|
+
# Convert the expression to LaTeX format
|
99
|
+
latex_result = latex(expr)
|
100
|
+
return latex_result
|
101
|
+
|
102
|
+
|
103
|
+
|
40
104
|
def simplify_polynomial_expression(
|
41
105
|
expression: str,
|
42
106
|
subs: Optional[Dict[str, float]] = None
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: rgwfuncs
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.30
|
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,7 +154,47 @@ 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. `python_polynomial_expression_to_latex`
|
158
|
+
|
159
|
+
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.
|
160
|
+
|
161
|
+
• Parameters:
|
162
|
+
- `expression` (str): The algebraic expression to convert to LaTeX. This should be a string formatted with Python syntax acceptable by SymPy.
|
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.
|
164
|
+
|
165
|
+
• Returns:
|
166
|
+
- `str`: The LaTeX formatted string equivalent to the provided expression.
|
167
|
+
|
168
|
+
• Raises:
|
169
|
+
- `ValueError`: If the expression cannot be parsed due to syntax errors.
|
170
|
+
|
171
|
+
• Example:
|
172
|
+
|
173
|
+
from rgwfuncs import python_polynomial_expression_to_latex
|
174
|
+
|
175
|
+
# Convert a simple polynomial expression to LaTeX format
|
176
|
+
latex_result1 = python_polynomial_expression_to_latex("x**2 + y**2")
|
177
|
+
print(latex_result1) # Output: "x^{2} + y^{2}"
|
178
|
+
|
179
|
+
# Convert polynomial expression with substituted values
|
180
|
+
latex_result2 = python_polynomial_expression_to_latex("x**2 + y**2", {"x": 3, "y": 4})
|
181
|
+
print(latex_result2) # Output: "25"
|
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"
|
194
|
+
|
195
|
+
--------------------------------------------------------------------------------
|
196
|
+
|
197
|
+
### 2. `compute_constant_expression`
|
158
198
|
|
159
199
|
Computes the numerical result of a given expression, which can evaluate to a constant, represented as a float. Evaluates an constant expression provided as a string and returns the computed result. Supports various arithmetic operations, including addition, subtraction, multiplication, division, and modulo, as well as mathematical functions from the math module.
|
160
200
|
|
@@ -178,7 +218,7 @@ Computes the numerical result of a given expression, which can evaluate to a con
|
|
178
218
|
|
179
219
|
--------------------------------------------------------------------------------
|
180
220
|
|
181
|
-
###
|
221
|
+
### 3. `simplify_polynomial_expression`
|
182
222
|
|
183
223
|
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
224
|
|
@@ -211,7 +251,7 @@ Simplifies an algebraic expression in polynomial form and returns it in LaTeX fo
|
|
211
251
|
|
212
252
|
--------------------------------------------------------------------------------
|
213
253
|
|
214
|
-
###
|
254
|
+
### 4. `solve_homogeneous_polynomial_expression`
|
215
255
|
|
216
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.
|
217
257
|
|
@@ -234,7 +274,7 @@ Solves a homogeneous polynomial expression for a specified variable and returns
|
|
234
274
|
|
235
275
|
--------------------------------------------------------------------------------
|
236
276
|
|
237
|
-
###
|
277
|
+
### 5. `get_prime_factors_latex`
|
238
278
|
|
239
279
|
Computes prime factors of a number and presents them in LaTeX format.
|
240
280
|
|
@@ -258,7 +298,7 @@ Computes prime factors of a number and presents them in LaTeX format.
|
|
258
298
|
|
259
299
|
--------------------------------------------------------------------------------
|
260
300
|
|
261
|
-
###
|
301
|
+
### 6. `compute_matrix_expression`
|
262
302
|
|
263
303
|
Computes the results of expressions containing 1D or 2D matrix operations and formats them as LaTeX strings.
|
264
304
|
|
@@ -286,7 +326,7 @@ Computes the results of expressions containing 1D or 2D matrix operations and fo
|
|
286
326
|
|
287
327
|
--------------------------------------------------------------------------------
|
288
328
|
|
289
|
-
###
|
329
|
+
### 7. `compute_ordered_series_expression`
|
290
330
|
|
291
331
|
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
332
|
|
@@ -0,0 +1,11 @@
|
|
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,,
|
rgwfuncs-0.0.29.dist-info/RECORD
DELETED
@@ -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,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|