rgwfuncs 0.0.52__tar.gz → 0.0.54__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {rgwfuncs-0.0.52/src/rgwfuncs.egg-info → rgwfuncs-0.0.54}/PKG-INFO +16 -15
- {rgwfuncs-0.0.52 → rgwfuncs-0.0.54}/README.md +15 -14
- {rgwfuncs-0.0.52 → rgwfuncs-0.0.54}/pyproject.toml +1 -1
- {rgwfuncs-0.0.52 → rgwfuncs-0.0.54}/setup.cfg +1 -1
- {rgwfuncs-0.0.52 → rgwfuncs-0.0.54}/src/rgwfuncs/algebra_lib.py +77 -25
- {rgwfuncs-0.0.52 → rgwfuncs-0.0.54/src/rgwfuncs.egg-info}/PKG-INFO +16 -15
- {rgwfuncs-0.0.52 → rgwfuncs-0.0.54}/LICENSE +0 -0
- {rgwfuncs-0.0.52 → rgwfuncs-0.0.54}/src/rgwfuncs/__init__.py +0 -0
- {rgwfuncs-0.0.52 → rgwfuncs-0.0.54}/src/rgwfuncs/df_lib.py +0 -0
- {rgwfuncs-0.0.52 → rgwfuncs-0.0.54}/src/rgwfuncs/docs_lib.py +0 -0
- {rgwfuncs-0.0.52 → rgwfuncs-0.0.54}/src/rgwfuncs/interactive_shell_lib.py +0 -0
- {rgwfuncs-0.0.52 → rgwfuncs-0.0.54}/src/rgwfuncs/str_lib.py +0 -0
- {rgwfuncs-0.0.52 → rgwfuncs-0.0.54}/src/rgwfuncs.egg-info/SOURCES.txt +0 -0
- {rgwfuncs-0.0.52 → rgwfuncs-0.0.54}/src/rgwfuncs.egg-info/dependency_links.txt +0 -0
- {rgwfuncs-0.0.52 → rgwfuncs-0.0.54}/src/rgwfuncs.egg-info/entry_points.txt +0 -0
- {rgwfuncs-0.0.52 → rgwfuncs-0.0.54}/src/rgwfuncs.egg-info/requires.txt +0 -0
- {rgwfuncs-0.0.52 → rgwfuncs-0.0.54}/src/rgwfuncs.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: rgwfuncs
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.54
|
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
|
@@ -370,17 +370,17 @@ Converts a polynomial expression written in Python syntax to a LaTeX formatted s
|
|
370
370
|
|
371
371
|
Expands a polynomial expression written in Python syntax and converts it into a LaTeX formatted string. This function takes algebraic expressions provided as strings using Python's syntax, applies polynomial expansion through SymPy, and translates them into LaTeX representations, suitable for academic or professional documentation. It supports expressions with named variables and provides an option to substitute specific values into the expression before expansion.
|
372
372
|
|
373
|
-
|
373
|
+
• Parameters:
|
374
374
|
- `expression` (str): The algebraic expression to expand and convert to LaTeX. This string should be formatted using Python syntax acceptable by SymPy.
|
375
375
|
- `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 before expanding.
|
376
376
|
|
377
|
-
|
377
|
+
• Returns:
|
378
378
|
- `str`: The LaTeX formatted string of the expanded expression.
|
379
379
|
|
380
|
-
|
380
|
+
• Raises:
|
381
381
|
- `ValueError`: If the expression cannot be parsed due to syntax errors.
|
382
382
|
|
383
|
-
|
383
|
+
• Example:
|
384
384
|
|
385
385
|
from rgwfuncs import expand_polynomial_expression
|
386
386
|
|
@@ -406,17 +406,17 @@ Expands a polynomial expression written in Python syntax and converts it into a
|
|
406
406
|
|
407
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
408
|
|
409
|
-
|
409
|
+
• Parameters:
|
410
410
|
- `expression` (str): The polynomial expression to factor and convert to LaTeX. This should be a valid expression formatted using Python syntax.
|
411
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
412
|
|
413
|
-
|
413
|
+
• Returns:
|
414
414
|
- `str`: The LaTeX formatted string representing the factored expression.
|
415
415
|
|
416
|
-
|
416
|
+
• Raises:
|
417
417
|
- `ValueError`: If the expression cannot be parsed due to syntax errors.
|
418
418
|
|
419
|
-
|
419
|
+
• Example:
|
420
420
|
|
421
421
|
from rgwfuncs import factor_polynomial_expression
|
422
422
|
|
@@ -441,7 +441,7 @@ Simplifies an algebraic expression in polynomial form and returns it in LaTeX fo
|
|
441
441
|
• Returns:
|
442
442
|
- `str`: The simplified expression formatted as a LaTeX string.
|
443
443
|
|
444
|
-
• Example
|
444
|
+
• Example:
|
445
445
|
|
446
446
|
from rgwfuncs import simplify_polynomial_expression
|
447
447
|
|
@@ -467,17 +467,17 @@ Simplifies an algebraic expression in polynomial form and returns it in LaTeX fo
|
|
467
467
|
|
468
468
|
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.
|
469
469
|
|
470
|
-
|
470
|
+
• Parameters:
|
471
471
|
- `expression` (str): The algebraic expression to simplify and convert to LaTeX. This string should be formatted using Python syntax.
|
472
472
|
- `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.
|
473
473
|
|
474
|
-
|
474
|
+
• Returns:
|
475
475
|
- `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.
|
476
476
|
|
477
|
-
|
477
|
+
• Raises:
|
478
478
|
- `ValueError`: If the expression cannot be parsed due to syntax errors or involves undefined operations, such as division by zero.
|
479
479
|
|
480
|
-
|
480
|
+
• Example:
|
481
481
|
|
482
482
|
from rgwfuncs import cancel_polynomial_expression
|
483
483
|
|
@@ -524,13 +524,14 @@ This function plots polynomial functions described by a list of expressions and
|
|
524
524
|
- A value which is a dictionary containing substitutions for the expression. Must include an `"x"` key, either as `"*"` for default domain or a NumPy array.
|
525
525
|
- `zoom` (`float`): Determines the numeric axis range from `-zoom` to `+zoom` for both x and y axes (default is `10.0`).
|
526
526
|
- `show_legend` (`bool`): Specifies whether to include a legend in the plot (default is `True`).
|
527
|
+
- `open_file` (`bool`): If saving to path is not desireable, opens the svg as a temp file, else opens the file from the actual location using the system's default viewer (defaults to False).
|
528
|
+
- `save_path` (`Optional[str]`): If specified, saves the output string as a .svg at the indicated path (defaults to None).
|
527
529
|
|
528
530
|
• Returns:
|
529
531
|
- `str`: The raw SVG markup of the resulting plot.
|
530
532
|
|
531
533
|
• Example:
|
532
534
|
|
533
|
-
import subprocess
|
534
535
|
from rgwfuncs import plot_polynomial_functions
|
535
536
|
|
536
537
|
# Generate the SVG
|
@@ -343,17 +343,17 @@ Converts a polynomial expression written in Python syntax to a LaTeX formatted s
|
|
343
343
|
|
344
344
|
Expands a polynomial expression written in Python syntax and converts it into a LaTeX formatted string. This function takes algebraic expressions provided as strings using Python's syntax, applies polynomial expansion through SymPy, and translates them into LaTeX representations, suitable for academic or professional documentation. It supports expressions with named variables and provides an option to substitute specific values into the expression before expansion.
|
345
345
|
|
346
|
-
|
346
|
+
• Parameters:
|
347
347
|
- `expression` (str): The algebraic expression to expand and convert to LaTeX. This string should be formatted using Python syntax acceptable by SymPy.
|
348
348
|
- `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 before expanding.
|
349
349
|
|
350
|
-
|
350
|
+
• Returns:
|
351
351
|
- `str`: The LaTeX formatted string of the expanded expression.
|
352
352
|
|
353
|
-
|
353
|
+
• Raises:
|
354
354
|
- `ValueError`: If the expression cannot be parsed due to syntax errors.
|
355
355
|
|
356
|
-
|
356
|
+
• Example:
|
357
357
|
|
358
358
|
from rgwfuncs import expand_polynomial_expression
|
359
359
|
|
@@ -379,17 +379,17 @@ Expands a polynomial expression written in Python syntax and converts it into a
|
|
379
379
|
|
380
380
|
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.
|
381
381
|
|
382
|
-
|
382
|
+
• Parameters:
|
383
383
|
- `expression` (str): The polynomial expression to factor and convert to LaTeX. This should be a valid expression formatted using Python syntax.
|
384
384
|
- `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.
|
385
385
|
|
386
|
-
|
386
|
+
• Returns:
|
387
387
|
- `str`: The LaTeX formatted string representing the factored expression.
|
388
388
|
|
389
|
-
|
389
|
+
• Raises:
|
390
390
|
- `ValueError`: If the expression cannot be parsed due to syntax errors.
|
391
391
|
|
392
|
-
|
392
|
+
• Example:
|
393
393
|
|
394
394
|
from rgwfuncs import factor_polynomial_expression
|
395
395
|
|
@@ -414,7 +414,7 @@ Simplifies an algebraic expression in polynomial form and returns it in LaTeX fo
|
|
414
414
|
• Returns:
|
415
415
|
- `str`: The simplified expression formatted as a LaTeX string.
|
416
416
|
|
417
|
-
• Example
|
417
|
+
• Example:
|
418
418
|
|
419
419
|
from rgwfuncs import simplify_polynomial_expression
|
420
420
|
|
@@ -440,17 +440,17 @@ Simplifies an algebraic expression in polynomial form and returns it in LaTeX fo
|
|
440
440
|
|
441
441
|
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.
|
442
442
|
|
443
|
-
|
443
|
+
• Parameters:
|
444
444
|
- `expression` (str): The algebraic expression to simplify and convert to LaTeX. This string should be formatted using Python syntax.
|
445
445
|
- `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.
|
446
446
|
|
447
|
-
|
447
|
+
• Returns:
|
448
448
|
- `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.
|
449
449
|
|
450
|
-
|
450
|
+
• Raises:
|
451
451
|
- `ValueError`: If the expression cannot be parsed due to syntax errors or involves undefined operations, such as division by zero.
|
452
452
|
|
453
|
-
|
453
|
+
• Example:
|
454
454
|
|
455
455
|
from rgwfuncs import cancel_polynomial_expression
|
456
456
|
|
@@ -497,13 +497,14 @@ This function plots polynomial functions described by a list of expressions and
|
|
497
497
|
- A value which is a dictionary containing substitutions for the expression. Must include an `"x"` key, either as `"*"` for default domain or a NumPy array.
|
498
498
|
- `zoom` (`float`): Determines the numeric axis range from `-zoom` to `+zoom` for both x and y axes (default is `10.0`).
|
499
499
|
- `show_legend` (`bool`): Specifies whether to include a legend in the plot (default is `True`).
|
500
|
+
- `open_file` (`bool`): If saving to path is not desireable, opens the svg as a temp file, else opens the file from the actual location using the system's default viewer (defaults to False).
|
501
|
+
- `save_path` (`Optional[str]`): If specified, saves the output string as a .svg at the indicated path (defaults to None).
|
500
502
|
|
501
503
|
• Returns:
|
502
504
|
- `str`: The raw SVG markup of the resulting plot.
|
503
505
|
|
504
506
|
• Example:
|
505
507
|
|
506
|
-
import subprocess
|
507
508
|
from rgwfuncs import plot_polynomial_functions
|
508
509
|
|
509
510
|
# Generate the SVG
|
@@ -1,16 +1,15 @@
|
|
1
1
|
import re
|
2
2
|
import math
|
3
3
|
import ast
|
4
|
+
import subprocess
|
5
|
+
import tempfile
|
4
6
|
from sympy import symbols, latex, simplify, solve, diff, Expr, factor, cancel, Eq
|
5
7
|
from sympy.core.sympify import SympifyError
|
6
8
|
from sympy.core import S
|
7
9
|
from sympy.parsing.sympy_parser import parse_expr
|
8
10
|
from sympy import __all__ as sympy_functions
|
9
11
|
from sympy.parsing.sympy_parser import (standard_transformations, implicit_multiplication_application)
|
10
|
-
|
11
12
|
from typing import Tuple, List, Dict, Optional, Any
|
12
|
-
|
13
|
-
|
14
13
|
import numpy as np
|
15
14
|
import matplotlib.pyplot as plt
|
16
15
|
from io import BytesIO
|
@@ -710,7 +709,9 @@ def solve_homogeneous_polynomial_expression(
|
|
710
709
|
def plot_polynomial_functions(
|
711
710
|
functions: List[Dict[str, Dict[str, Any]]],
|
712
711
|
zoom: float = 10.0,
|
713
|
-
show_legend: bool = True
|
712
|
+
show_legend: bool = True,
|
713
|
+
open_file: bool = False,
|
714
|
+
save_path: Optional[str] = None,
|
714
715
|
) -> str:
|
715
716
|
"""
|
716
717
|
Plots expressions described by a list of dictionaries of the form:
|
@@ -742,6 +743,13 @@ def plot_polynomial_functions(
|
|
742
743
|
Sets the numeric axis range from -zoom..+zoom in both x and y.
|
743
744
|
show_legend : bool
|
744
745
|
Whether to add a legend to the plot (defaults to True).
|
746
|
+
open_file : bool
|
747
|
+
If saving to path is not desirable, opens the SVG as a temp file;
|
748
|
+
otherwise opens the file from the actual location using the system's
|
749
|
+
default viewer (defaults to False).
|
750
|
+
save_path : Optional[str]
|
751
|
+
If specified, saves the output string as a .svg at the indicated path
|
752
|
+
(defaults to None).
|
745
753
|
|
746
754
|
Returns
|
747
755
|
-------
|
@@ -764,71 +772,113 @@ def plot_polynomial_functions(
|
|
764
772
|
|
765
773
|
expr_tmp = re.sub(DIFF_PATTERN, diff_replacer, expr_str)
|
766
774
|
expr_tmp = expr_tmp.replace("np.", "")
|
775
|
+
|
776
|
+
# Attempt to convert basic Pythonic polynomial expressions to LaTeX
|
767
777
|
try:
|
778
|
+
# Suppose you have a helper function python_polynomial_expression_to_latex
|
779
|
+
# If not, you can do a naive replacement or skip
|
780
|
+
from python_latex_helpers import python_polynomial_expression_to_latex
|
768
781
|
latex_expr = python_polynomial_expression_to_latex(expr_tmp)
|
769
782
|
return latex_expr
|
770
783
|
except Exception:
|
771
|
-
# Fallback:
|
784
|
+
# Fallback: naive ** -> ^
|
772
785
|
return expr_tmp.replace("**", "^")
|
773
786
|
|
787
|
+
def handle_open_and_save(svg_string: str, open_it: bool, path: Optional[str]) -> None:
|
788
|
+
# Save the SVG to a file if a path is provided
|
789
|
+
if path:
|
790
|
+
try:
|
791
|
+
with open(path, 'w', encoding='utf-8') as file:
|
792
|
+
file.write(svg_string)
|
793
|
+
print(f"[INFO] SVG saved to: {path}")
|
794
|
+
except IOError as e:
|
795
|
+
print(f"[ERROR] Failed to save SVG to {path}. IOError: {e}")
|
796
|
+
|
797
|
+
# Handle opening the file if requested
|
798
|
+
if open_it and path:
|
799
|
+
result = subprocess.run(["xdg-open", path], stderr=subprocess.DEVNULL)
|
800
|
+
if result.returncode != 0:
|
801
|
+
print("[ERROR] Failed to open the SVG file with the default viewer.")
|
802
|
+
elif open_it:
|
803
|
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".svg") as tmpfile:
|
804
|
+
temp_svg_path = tmpfile.name
|
805
|
+
tmpfile.write(svg_string.encode('utf-8'))
|
806
|
+
result = subprocess.run(["xdg-open", temp_svg_path], stderr=subprocess.DEVNULL)
|
807
|
+
if result.returncode != 0:
|
808
|
+
print("[ERROR] Failed to open the SVG file with the default viewer.")
|
809
|
+
|
774
810
|
buffer = BytesIO()
|
775
811
|
fig, ax = plt.subplots()
|
776
812
|
|
777
813
|
for entry in functions:
|
814
|
+
# Each entry is something like {"x**2": {"x": "*", "a": ...}}
|
778
815
|
if len(entry) != 1:
|
779
|
-
print("Skipping invalid item. Must have exactly 1 expression->substitutions pair.")
|
816
|
+
print("[WARNING] Skipping invalid item. Must have exactly 1 expression->substitutions pair.")
|
780
817
|
continue
|
781
818
|
|
782
|
-
expression
|
819
|
+
# Extract the expression string and substitutions
|
820
|
+
expression, sub_dict = next(iter(entry.items()))
|
821
|
+
|
822
|
+
# Check presence of "x"
|
783
823
|
if "x" not in sub_dict:
|
784
|
-
print(f"Skipping '{expression}' because
|
824
|
+
print(f"[WARNING] Skipping '{expression}' because there is no 'x' key.")
|
785
825
|
continue
|
786
826
|
|
787
|
-
# If "x" is "*", create a default domain
|
788
827
|
x_val = sub_dict["x"]
|
828
|
+
|
829
|
+
# 1) If x == "*", generate from -zoom..+zoom
|
789
830
|
if isinstance(x_val, str) and x_val == "*":
|
790
831
|
x_values = np.linspace(-zoom, zoom, 1201)
|
791
|
-
sub_dict["x"] = x_values
|
832
|
+
sub_dict["x"] = x_values # might as well update it in place
|
833
|
+
# 2) If x is already a NumPy array, use as-is
|
792
834
|
elif isinstance(x_val, np.ndarray):
|
793
835
|
x_values = x_val
|
794
836
|
else:
|
795
|
-
print(f"Skipping '{expression}' because 'x' is neither '*' nor a NumPy array.")
|
837
|
+
print(f"[WARNING] Skipping '{expression}' because 'x' is neither '*' nor a NumPy array.")
|
796
838
|
continue
|
797
839
|
|
798
|
-
# Evaluate the expression
|
840
|
+
# Evaluate the expression with the variables from sub_dict
|
841
|
+
# We'll inject them into an eval() context, including 'np'
|
799
842
|
try:
|
800
843
|
eval_context = {"np": np}
|
844
|
+
# Put all user-provided variables (like a=1.23) in:
|
801
845
|
eval_context.update(sub_dict)
|
802
846
|
y_values = eval(expression, {"np": np}, eval_context)
|
803
847
|
except Exception as e:
|
804
|
-
print(f"
|
848
|
+
print(f"[ERROR] Could not evaluate '{expression}' -> {e}")
|
805
849
|
continue
|
806
850
|
|
851
|
+
# Check we got a NumPy array
|
807
852
|
if not isinstance(y_values, np.ndarray):
|
808
|
-
print(f"Skipping '{expression}' because it did not produce a NumPy array.")
|
853
|
+
print(f"[WARNING] Skipping '{expression}' because it did not produce a NumPy array.")
|
809
854
|
continue
|
810
855
|
|
811
|
-
# If
|
856
|
+
# If y is shorter (like np.diff), truncate x
|
812
857
|
if len(y_values) < len(x_values):
|
813
858
|
x_values = x_values[:len(y_values)]
|
814
859
|
|
815
|
-
# Convert expression to a
|
860
|
+
# Convert the expression to a LaTeX label
|
816
861
|
label_expr = latexify_expression(expression)
|
817
862
|
ax.plot(x_values, y_values, label=rf"${label_expr}$")
|
818
863
|
|
819
864
|
# Configure axes
|
820
865
|
ax.set_xlim(-zoom, zoom)
|
821
866
|
ax.set_ylim(-zoom, zoom)
|
867
|
+
|
868
|
+
# Place spines at center
|
822
869
|
ax.spines['left'].set_position('zero')
|
823
870
|
ax.spines['bottom'].set_position('zero')
|
871
|
+
# Hide the right and top spines
|
824
872
|
ax.spines['right'].set_color('none')
|
825
873
|
ax.spines['top'].set_color('none')
|
826
|
-
ax.set_aspect('equal', 'box')
|
827
874
|
ax.xaxis.set_ticks_position('bottom')
|
828
875
|
ax.yaxis.set_ticks_position('left')
|
876
|
+
|
877
|
+
# Ensure equal aspect ratio
|
878
|
+
ax.set_aspect('equal', 'box')
|
829
879
|
ax.grid(True)
|
830
880
|
|
831
|
-
#
|
881
|
+
# If requested, show the legend
|
832
882
|
if show_legend:
|
833
883
|
leg = ax.legend(
|
834
884
|
loc='upper center',
|
@@ -837,13 +887,15 @@ def plot_polynomial_functions(
|
|
837
887
|
shadow=True,
|
838
888
|
ncol=1
|
839
889
|
)
|
840
|
-
plt.savefig(
|
841
|
-
buffer,
|
842
|
-
format='svg',
|
843
|
-
bbox_inches='tight',
|
844
|
-
bbox_extra_artists=[leg] # ensures the legend is fully captured
|
845
|
-
)
|
890
|
+
plt.savefig(buffer, format='svg', bbox_inches='tight', bbox_extra_artists=[leg])
|
846
891
|
else:
|
847
892
|
plt.savefig(buffer, format='svg', bbox_inches='tight')
|
893
|
+
|
848
894
|
plt.close(fig)
|
849
|
-
|
895
|
+
svg_string = buffer.getvalue().decode('utf-8')
|
896
|
+
|
897
|
+
# Optionally open/save the file
|
898
|
+
handle_open_and_save(svg_string, open_file, save_path)
|
899
|
+
|
900
|
+
return svg_string
|
901
|
+
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: rgwfuncs
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.54
|
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
|
@@ -370,17 +370,17 @@ Converts a polynomial expression written in Python syntax to a LaTeX formatted s
|
|
370
370
|
|
371
371
|
Expands a polynomial expression written in Python syntax and converts it into a LaTeX formatted string. This function takes algebraic expressions provided as strings using Python's syntax, applies polynomial expansion through SymPy, and translates them into LaTeX representations, suitable for academic or professional documentation. It supports expressions with named variables and provides an option to substitute specific values into the expression before expansion.
|
372
372
|
|
373
|
-
|
373
|
+
• Parameters:
|
374
374
|
- `expression` (str): The algebraic expression to expand and convert to LaTeX. This string should be formatted using Python syntax acceptable by SymPy.
|
375
375
|
- `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 before expanding.
|
376
376
|
|
377
|
-
|
377
|
+
• Returns:
|
378
378
|
- `str`: The LaTeX formatted string of the expanded expression.
|
379
379
|
|
380
|
-
|
380
|
+
• Raises:
|
381
381
|
- `ValueError`: If the expression cannot be parsed due to syntax errors.
|
382
382
|
|
383
|
-
|
383
|
+
• Example:
|
384
384
|
|
385
385
|
from rgwfuncs import expand_polynomial_expression
|
386
386
|
|
@@ -406,17 +406,17 @@ Expands a polynomial expression written in Python syntax and converts it into a
|
|
406
406
|
|
407
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
408
|
|
409
|
-
|
409
|
+
• Parameters:
|
410
410
|
- `expression` (str): The polynomial expression to factor and convert to LaTeX. This should be a valid expression formatted using Python syntax.
|
411
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
412
|
|
413
|
-
|
413
|
+
• Returns:
|
414
414
|
- `str`: The LaTeX formatted string representing the factored expression.
|
415
415
|
|
416
|
-
|
416
|
+
• Raises:
|
417
417
|
- `ValueError`: If the expression cannot be parsed due to syntax errors.
|
418
418
|
|
419
|
-
|
419
|
+
• Example:
|
420
420
|
|
421
421
|
from rgwfuncs import factor_polynomial_expression
|
422
422
|
|
@@ -441,7 +441,7 @@ Simplifies an algebraic expression in polynomial form and returns it in LaTeX fo
|
|
441
441
|
• Returns:
|
442
442
|
- `str`: The simplified expression formatted as a LaTeX string.
|
443
443
|
|
444
|
-
• Example
|
444
|
+
• Example:
|
445
445
|
|
446
446
|
from rgwfuncs import simplify_polynomial_expression
|
447
447
|
|
@@ -467,17 +467,17 @@ Simplifies an algebraic expression in polynomial form and returns it in LaTeX fo
|
|
467
467
|
|
468
468
|
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.
|
469
469
|
|
470
|
-
|
470
|
+
• Parameters:
|
471
471
|
- `expression` (str): The algebraic expression to simplify and convert to LaTeX. This string should be formatted using Python syntax.
|
472
472
|
- `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.
|
473
473
|
|
474
|
-
|
474
|
+
• Returns:
|
475
475
|
- `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.
|
476
476
|
|
477
|
-
|
477
|
+
• Raises:
|
478
478
|
- `ValueError`: If the expression cannot be parsed due to syntax errors or involves undefined operations, such as division by zero.
|
479
479
|
|
480
|
-
|
480
|
+
• Example:
|
481
481
|
|
482
482
|
from rgwfuncs import cancel_polynomial_expression
|
483
483
|
|
@@ -524,13 +524,14 @@ This function plots polynomial functions described by a list of expressions and
|
|
524
524
|
- A value which is a dictionary containing substitutions for the expression. Must include an `"x"` key, either as `"*"` for default domain or a NumPy array.
|
525
525
|
- `zoom` (`float`): Determines the numeric axis range from `-zoom` to `+zoom` for both x and y axes (default is `10.0`).
|
526
526
|
- `show_legend` (`bool`): Specifies whether to include a legend in the plot (default is `True`).
|
527
|
+
- `open_file` (`bool`): If saving to path is not desireable, opens the svg as a temp file, else opens the file from the actual location using the system's default viewer (defaults to False).
|
528
|
+
- `save_path` (`Optional[str]`): If specified, saves the output string as a .svg at the indicated path (defaults to None).
|
527
529
|
|
528
530
|
• Returns:
|
529
531
|
- `str`: The raw SVG markup of the resulting plot.
|
530
532
|
|
531
533
|
• Example:
|
532
534
|
|
533
|
-
import subprocess
|
534
535
|
from rgwfuncs import plot_polynomial_functions
|
535
536
|
|
536
537
|
# Generate the SVG
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|