rgwfuncs 0.0.50__tar.gz → 0.0.51__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {rgwfuncs-0.0.50/src/rgwfuncs.egg-info → rgwfuncs-0.0.51}/PKG-INFO +30 -30
- {rgwfuncs-0.0.50 → rgwfuncs-0.0.51}/README.md +29 -29
- {rgwfuncs-0.0.50 → rgwfuncs-0.0.51}/pyproject.toml +1 -1
- {rgwfuncs-0.0.50 → rgwfuncs-0.0.51}/setup.cfg +1 -1
- {rgwfuncs-0.0.50 → rgwfuncs-0.0.51/src/rgwfuncs.egg-info}/PKG-INFO +30 -30
- {rgwfuncs-0.0.50 → rgwfuncs-0.0.51}/LICENSE +0 -0
- {rgwfuncs-0.0.50 → rgwfuncs-0.0.51}/src/rgwfuncs/__init__.py +0 -0
- {rgwfuncs-0.0.50 → rgwfuncs-0.0.51}/src/rgwfuncs/algebra_lib.py +63 -63
- {rgwfuncs-0.0.50 → rgwfuncs-0.0.51}/src/rgwfuncs/df_lib.py +0 -0
- {rgwfuncs-0.0.50 → rgwfuncs-0.0.51}/src/rgwfuncs/docs_lib.py +0 -0
- {rgwfuncs-0.0.50 → rgwfuncs-0.0.51}/src/rgwfuncs/interactive_shell_lib.py +0 -0
- {rgwfuncs-0.0.50 → rgwfuncs-0.0.51}/src/rgwfuncs/str_lib.py +0 -0
- {rgwfuncs-0.0.50 → rgwfuncs-0.0.51}/src/rgwfuncs.egg-info/SOURCES.txt +0 -0
- {rgwfuncs-0.0.50 → rgwfuncs-0.0.51}/src/rgwfuncs.egg-info/dependency_links.txt +0 -0
- {rgwfuncs-0.0.50 → rgwfuncs-0.0.51}/src/rgwfuncs.egg-info/entry_points.txt +0 -0
- {rgwfuncs-0.0.50 → rgwfuncs-0.0.51}/src/rgwfuncs.egg-info/requires.txt +0 -0
- {rgwfuncs-0.0.50 → rgwfuncs-0.0.51}/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.51
|
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
|
@@ -430,35 +430,7 @@ Factors a polynomial expression written in Python syntax and converts it into a
|
|
430
430
|
|
431
431
|
--------------------------------------------------------------------------------
|
432
432
|
|
433
|
-
### 8. `
|
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`
|
433
|
+
### 8. `simplify_polynomial_expression`
|
462
434
|
|
463
435
|
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.
|
464
436
|
|
@@ -491,6 +463,34 @@ Simplifies an algebraic expression in polynomial form and returns it in LaTeX fo
|
|
491
463
|
|
492
464
|
--------------------------------------------------------------------------------
|
493
465
|
|
466
|
+
### 9. `cancel_polynomial_expression`
|
467
|
+
|
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
|
+
|
470
|
+
- Parameters:
|
471
|
+
- `expression` (str): The algebraic expression to simplify and convert to LaTeX. This string should be formatted using Python syntax.
|
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
|
+
|
474
|
+
- Returns:
|
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
|
+
|
477
|
+
- Raises:
|
478
|
+
- `ValueError`: If the expression cannot be parsed due to syntax errors or involves undefined operations, such as division by zero.
|
479
|
+
|
480
|
+
- Example:
|
481
|
+
|
482
|
+
from rgwfuncs import cancel_polynomial_expression
|
483
|
+
|
484
|
+
# Cancel common factors within a polynomial expression
|
485
|
+
latex_result1 = cancel_polynomial_expression("(x**2 - 4) / (x - 2)")
|
486
|
+
print(latex_result1) # Output: "x + 2"
|
487
|
+
|
488
|
+
# Cancel with substituted values
|
489
|
+
latex_result2 = cancel_polynomial_expression("(x**2 - 4) / (x - 2)", {"x": 2})
|
490
|
+
print(latex_result2) # Output: "Undefined result. This could be a division by zero error."
|
491
|
+
|
492
|
+
--------------------------------------------------------------------------------
|
493
|
+
|
494
494
|
### 10. `solve_homogeneous_polynomial_expression`
|
495
495
|
|
496
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.
|
@@ -403,35 +403,7 @@ Factors a polynomial expression written in Python syntax and converts it into a
|
|
403
403
|
|
404
404
|
--------------------------------------------------------------------------------
|
405
405
|
|
406
|
-
### 8. `
|
407
|
-
|
408
|
-
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.
|
409
|
-
|
410
|
-
- Parameters:
|
411
|
-
- `expression` (str): The algebraic expression to simplify and convert to LaTeX. This string should be formatted using Python syntax.
|
412
|
-
- `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.
|
413
|
-
|
414
|
-
- Returns:
|
415
|
-
- `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.
|
416
|
-
|
417
|
-
- Raises:
|
418
|
-
- `ValueError`: If the expression cannot be parsed due to syntax errors or involves undefined operations, such as division by zero.
|
419
|
-
|
420
|
-
- Example:
|
421
|
-
|
422
|
-
from rgwfuncs import cancel_polynomial_expression
|
423
|
-
|
424
|
-
# Cancel common factors within a polynomial expression
|
425
|
-
latex_result1 = cancel_polynomial_expression("(x**2 - 4) / (x - 2)")
|
426
|
-
print(latex_result1) # Output: "x + 2"
|
427
|
-
|
428
|
-
# Cancel with substituted values
|
429
|
-
latex_result2 = cancel_polynomial_expression("(x**2 - 4) / (x - 2)", {"x": 2})
|
430
|
-
print(latex_result2) # Output: "Undefined result. This could be a division by zero error."
|
431
|
-
|
432
|
-
--------------------------------------------------------------------------------
|
433
|
-
|
434
|
-
### 9. `simplify_polynomial_expression`
|
406
|
+
### 8. `simplify_polynomial_expression`
|
435
407
|
|
436
408
|
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.
|
437
409
|
|
@@ -464,6 +436,34 @@ Simplifies an algebraic expression in polynomial form and returns it in LaTeX fo
|
|
464
436
|
|
465
437
|
--------------------------------------------------------------------------------
|
466
438
|
|
439
|
+
### 9. `cancel_polynomial_expression`
|
440
|
+
|
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
|
+
|
443
|
+
- Parameters:
|
444
|
+
- `expression` (str): The algebraic expression to simplify and convert to LaTeX. This string should be formatted using Python syntax.
|
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
|
+
|
447
|
+
- Returns:
|
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
|
+
|
450
|
+
- Raises:
|
451
|
+
- `ValueError`: If the expression cannot be parsed due to syntax errors or involves undefined operations, such as division by zero.
|
452
|
+
|
453
|
+
- Example:
|
454
|
+
|
455
|
+
from rgwfuncs import cancel_polynomial_expression
|
456
|
+
|
457
|
+
# Cancel common factors within a polynomial expression
|
458
|
+
latex_result1 = cancel_polynomial_expression("(x**2 - 4) / (x - 2)")
|
459
|
+
print(latex_result1) # Output: "x + 2"
|
460
|
+
|
461
|
+
# Cancel with substituted values
|
462
|
+
latex_result2 = cancel_polynomial_expression("(x**2 - 4) / (x - 2)", {"x": 2})
|
463
|
+
print(latex_result2) # Output: "Undefined result. This could be a division by zero error."
|
464
|
+
|
465
|
+
--------------------------------------------------------------------------------
|
466
|
+
|
467
467
|
### 10. `solve_homogeneous_polynomial_expression`
|
468
468
|
|
469
469
|
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.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: rgwfuncs
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.51
|
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
|
@@ -430,35 +430,7 @@ Factors a polynomial expression written in Python syntax and converts it into a
|
|
430
430
|
|
431
431
|
--------------------------------------------------------------------------------
|
432
432
|
|
433
|
-
### 8. `
|
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`
|
433
|
+
### 8. `simplify_polynomial_expression`
|
462
434
|
|
463
435
|
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.
|
464
436
|
|
@@ -491,6 +463,34 @@ Simplifies an algebraic expression in polynomial form and returns it in LaTeX fo
|
|
491
463
|
|
492
464
|
--------------------------------------------------------------------------------
|
493
465
|
|
466
|
+
### 9. `cancel_polynomial_expression`
|
467
|
+
|
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
|
+
|
470
|
+
- Parameters:
|
471
|
+
- `expression` (str): The algebraic expression to simplify and convert to LaTeX. This string should be formatted using Python syntax.
|
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
|
+
|
474
|
+
- Returns:
|
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
|
+
|
477
|
+
- Raises:
|
478
|
+
- `ValueError`: If the expression cannot be parsed due to syntax errors or involves undefined operations, such as division by zero.
|
479
|
+
|
480
|
+
- Example:
|
481
|
+
|
482
|
+
from rgwfuncs import cancel_polynomial_expression
|
483
|
+
|
484
|
+
# Cancel common factors within a polynomial expression
|
485
|
+
latex_result1 = cancel_polynomial_expression("(x**2 - 4) / (x - 2)")
|
486
|
+
print(latex_result1) # Output: "x + 2"
|
487
|
+
|
488
|
+
# Cancel with substituted values
|
489
|
+
latex_result2 = cancel_polynomial_expression("(x**2 - 4) / (x - 2)", {"x": 2})
|
490
|
+
print(latex_result2) # Output: "Undefined result. This could be a division by zero error."
|
491
|
+
|
492
|
+
--------------------------------------------------------------------------------
|
493
|
+
|
494
494
|
### 10. `solve_homogeneous_polynomial_expression`
|
495
495
|
|
496
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.
|
File without changes
|
File without changes
|
@@ -411,69 +411,6 @@ def factor_polynomial_expression(
|
|
411
411
|
return latex_result
|
412
412
|
|
413
413
|
|
414
|
-
def cancel_polynomial_expression(
|
415
|
-
expression: str,
|
416
|
-
subs: Optional[Dict[str, float]] = None
|
417
|
-
) -> str:
|
418
|
-
"""
|
419
|
-
Cancels common factors within a polynomial expression and converts it to LaTeX format.
|
420
|
-
|
421
|
-
This function parses an algebraic expression given in Python syntax, cancels any common factors,
|
422
|
-
and converts the resulting simplified expression into a LaTeX formatted string. The function can
|
423
|
-
also handle optional substitutions of variables before performing the cancellation.
|
424
|
-
|
425
|
-
Parameters:
|
426
|
-
expression (str): The algebraic expression to simplify and convert to LaTeX.
|
427
|
-
It should be a valid expression formatted using Python syntax.
|
428
|
-
subs (Optional[Dict[str, float]]): An optional dictionary where the keys are variable names in the
|
429
|
-
expression, and the values are the corresponding numbers to substitute
|
430
|
-
into the expression before simplification.
|
431
|
-
|
432
|
-
Returns:
|
433
|
-
str: The LaTeX formatted string of the simplified expression. If the expression involves
|
434
|
-
indeterminate forms due to operations like division by zero, a descriptive error message is returned instead.
|
435
|
-
|
436
|
-
Raises:
|
437
|
-
ValueError: If the expression cannot be parsed due to syntax errors or if operations result in
|
438
|
-
undefined behavior, such as division by zero.
|
439
|
-
|
440
|
-
"""
|
441
|
-
transformations = standard_transformations + (implicit_multiplication_application,)
|
442
|
-
|
443
|
-
def parse_and_cancel_expression(expr_str: str, sym_vars: Dict[str, symbols]) -> symbols:
|
444
|
-
try:
|
445
|
-
expr = parse_expr(expr_str, local_dict=sym_vars, transformations=transformations)
|
446
|
-
if subs:
|
447
|
-
if not isinstance(subs, dict):
|
448
|
-
raise ValueError(f"Substitutions must be a dictionary. Received: {subs}")
|
449
|
-
subs_symbols = {symbols(k): v for k, v in subs.items()}
|
450
|
-
expr = expr.subs(subs_symbols)
|
451
|
-
|
452
|
-
canceled_expr = cancel(expr)
|
453
|
-
|
454
|
-
# Check for NaN or indeterminate forms
|
455
|
-
if canceled_expr.has(S.NaN) or canceled_expr.has(S.Infinity) or canceled_expr.has(S.ComplexInfinity):
|
456
|
-
return "Undefined result. This could be a division by zero error."
|
457
|
-
|
458
|
-
return canceled_expr
|
459
|
-
|
460
|
-
except (SyntaxError, ValueError, TypeError, AttributeError, ZeroDivisionError, SympifyError) as e:
|
461
|
-
return f"Error: {str(e)}"
|
462
|
-
|
463
|
-
variable_names = set(re.findall(r'\b[a-zA-Z]\w*\b', expression))
|
464
|
-
sym_vars = {var: symbols(var) for var in variable_names}
|
465
|
-
|
466
|
-
expr = parse_and_cancel_expression(expression, sym_vars)
|
467
|
-
|
468
|
-
# If the expression is already a string (i.e., "Undefined" or error message), return it directly
|
469
|
-
if isinstance(expr, str):
|
470
|
-
return expr
|
471
|
-
|
472
|
-
# Otherwise, convert to LaTeX as usual
|
473
|
-
latex_result = latex(expr)
|
474
|
-
return latex_result
|
475
|
-
|
476
|
-
|
477
414
|
def simplify_polynomial_expression(
|
478
415
|
expression: str,
|
479
416
|
subs: Optional[Dict[str, float]] = None
|
@@ -649,6 +586,69 @@ def simplify_polynomial_expression(
|
|
649
586
|
raise ValueError(f"Error simplifying expression: {e}")
|
650
587
|
|
651
588
|
|
589
|
+
def cancel_polynomial_expression(
|
590
|
+
expression: str,
|
591
|
+
subs: Optional[Dict[str, float]] = None
|
592
|
+
) -> str:
|
593
|
+
"""
|
594
|
+
Cancels common factors within a polynomial expression and converts it to LaTeX format.
|
595
|
+
|
596
|
+
This function parses an algebraic expression given in Python syntax, cancels any common factors,
|
597
|
+
and converts the resulting simplified expression into a LaTeX formatted string. The function can
|
598
|
+
also handle optional substitutions of variables before performing the cancellation.
|
599
|
+
|
600
|
+
Parameters:
|
601
|
+
expression (str): The algebraic expression to simplify and convert to LaTeX.
|
602
|
+
It should be a valid expression formatted using Python syntax.
|
603
|
+
subs (Optional[Dict[str, float]]): An optional dictionary where the keys are variable names in the
|
604
|
+
expression, and the values are the corresponding numbers to substitute
|
605
|
+
into the expression before simplification.
|
606
|
+
|
607
|
+
Returns:
|
608
|
+
str: The LaTeX formatted string of the simplified expression. If the expression involves
|
609
|
+
indeterminate forms due to operations like division by zero, a descriptive error message is returned instead.
|
610
|
+
|
611
|
+
Raises:
|
612
|
+
ValueError: If the expression cannot be parsed due to syntax errors or if operations result in
|
613
|
+
undefined behavior, such as division by zero.
|
614
|
+
|
615
|
+
"""
|
616
|
+
transformations = standard_transformations + (implicit_multiplication_application,)
|
617
|
+
|
618
|
+
def parse_and_cancel_expression(expr_str: str, sym_vars: Dict[str, symbols]) -> symbols:
|
619
|
+
try:
|
620
|
+
expr = parse_expr(expr_str, local_dict=sym_vars, transformations=transformations)
|
621
|
+
if subs:
|
622
|
+
if not isinstance(subs, dict):
|
623
|
+
raise ValueError(f"Substitutions must be a dictionary. Received: {subs}")
|
624
|
+
subs_symbols = {symbols(k): v for k, v in subs.items()}
|
625
|
+
expr = expr.subs(subs_symbols)
|
626
|
+
|
627
|
+
canceled_expr = cancel(expr)
|
628
|
+
|
629
|
+
# Check for NaN or indeterminate forms
|
630
|
+
if canceled_expr.has(S.NaN) or canceled_expr.has(S.Infinity) or canceled_expr.has(S.ComplexInfinity):
|
631
|
+
return "Undefined result. This could be a division by zero error."
|
632
|
+
|
633
|
+
return canceled_expr
|
634
|
+
|
635
|
+
except (SyntaxError, ValueError, TypeError, AttributeError, ZeroDivisionError, SympifyError) as e:
|
636
|
+
return f"Error: {str(e)}"
|
637
|
+
|
638
|
+
variable_names = set(re.findall(r'\b[a-zA-Z]\w*\b', expression))
|
639
|
+
sym_vars = {var: symbols(var) for var in variable_names}
|
640
|
+
|
641
|
+
expr = parse_and_cancel_expression(expression, sym_vars)
|
642
|
+
|
643
|
+
# If the expression is already a string (i.e., "Undefined" or error message), return it directly
|
644
|
+
if isinstance(expr, str):
|
645
|
+
return expr
|
646
|
+
|
647
|
+
# Otherwise, convert to LaTeX as usual
|
648
|
+
latex_result = latex(expr)
|
649
|
+
return latex_result
|
650
|
+
|
651
|
+
|
652
652
|
def solve_homogeneous_polynomial_expression(
|
653
653
|
expression: str,
|
654
654
|
variable: str,
|
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
|