Taizun commited on
Commit
96569b8
·
verified ·
1 Parent(s): a11b9a1

Update solver.py

Browse files
Files changed (1) hide show
  1. solver.py +37 -7
solver.py CHANGED
@@ -4,20 +4,50 @@ from sympy.solvers import solve
4
  from sympy import integrate, diff, simplify, expand, log, exp, sin, cos, tan, asin, acos, atan, Symbol, factorial, laplace_transform
5
  import re
6
  def format_expression(expr):
7
- """Format expression to make it more readable."""
8
- # Convert string representation to a more readable format
9
  str_expr = str(expr)
10
  replacements = {
11
- '**': '^',
12
- '*x': 'x',
13
- 'exp': 'e^',
14
- 'sqrt': '',
15
- 'factorial': '!'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  }
17
  for old, new in replacements.items():
18
  str_expr = str_expr.replace(old, new)
19
  return str_expr
20
 
 
 
 
 
21
  def preprocess_equation(equation_str):
22
  """Convert user-friendly equation format to SymPy format."""
23
  try:
 
4
  from sympy import integrate, diff, simplify, expand, log, exp, sin, cos, tan, asin, acos, atan, Symbol, factorial, laplace_transform
5
  import re
6
  def format_expression(expr):
 
 
7
  str_expr = str(expr)
8
  replacements = {
9
+ '**': '^', # Power notation
10
+ '*x': 'x', # Remove unnecessary multiplication signs
11
+ '*(': '(', # Remove multiplication before parentheses
12
+ 'exp': 'e^', # Exponential notation
13
+ 'sqrt': '', # Square root
14
+ 'factorial': '!', # Factorial symbol
15
+ 'gamma': 'Γ', # Gamma function
16
+ 'Gamma': 'Γ', # Sometimes SymPy capitalizes it
17
+ 'fresnels': 'S', # Fresnel S integral
18
+ 'fresnelc': 'C', # Fresnel C integral
19
+ 'hyper': '₁F₂', # Generalized hypergeometric function
20
+ 'log': 'ln', # Natural logarithm
21
+ 'oo': '∞', # Infinity symbol
22
+ 'pi': 'π', # Pi symbol
23
+ 'E': 'ℯ', # Euler's constant
24
+ 'I': '𝒊', # Imaginary unit
25
+ 'Abs': '|', # Absolute value
26
+ 'Integral': '∫', # Integral symbol
27
+ 'Derivative': 'd/dx', # Differentiation
28
+ 'Sum': 'Σ', # Summation symbol
29
+ 'Product': '∏', # Product symbol
30
+ 'sin': 'sin', 'cos': 'cos', 'tan': 'tan', # Trig functions (unchanged)
31
+ 'asin': 'sin⁻¹', 'acos': 'cos⁻¹', 'atan': 'tan⁻¹', # Inverse trig
32
+ 'sinh': 'sinh', 'cosh': 'cosh', 'tanh': 'tanh', # Hyperbolic trig
33
+ 'asinh': 'sinh⁻¹', 'acosh': 'cosh⁻¹', 'atanh': 'tanh⁻¹', # Inverse hyperbolic trig
34
+ 'diff': 'd/dx', # Derivative notation
35
+ 'integrate': '∫', # Integral notation
36
+ 'Limit': 'lim', # Limit notation
37
+ 'floor': '⌊', # Floor function
38
+ 'ceiling': '⌈', # Ceiling function
39
+ 'mod': 'mod', # Modulus (unchanged)
40
+ 'Re': 'ℜ', # Real part
41
+ 'Im': 'ℑ' # Imaginary part
42
  }
43
  for old, new in replacements.items():
44
  str_expr = str_expr.replace(old, new)
45
  return str_expr
46
 
47
+ for old, new in replacements.items():
48
+ str_expr = str_expr.replace(old, new)
49
+ return str_expr
50
+
51
  def preprocess_equation(equation_str):
52
  """Convert user-friendly equation format to SymPy format."""
53
  try: