import streamlit as st import sympy as sp import numpy as np st.title("Advanced AI-Powered Calculator") # User input: Mathematical expression expr = st.text_input("Enter a mathematical expression (e.g., x^2 + 2*x + 1):") # Operation selection operation = st.selectbox("Choose operation", ["Evaluate", "Derivative", "Integral", "Solve Equation", "Matrix Operations"]) # Define symbol x = sp.symbols('x') # Process based on operation result = None if operation == "Evaluate": try: result = sp.sympify(expr).evalf() except Exception as e: result = f"Error: {e}" elif operation == "Derivative": try: result = sp.diff(sp.sympify(expr), x) except Exception as e: result = f"Error: {e}" elif operation == "Integral": try: result = sp.integrate(sp.sympify(expr), x) except Exception as e: result = f"Error: {e}" elif operation == "Solve Equation": try: equation = sp.sympify(expr) result = sp.solve(equation, x) except Exception as e: result = f"Error: {e}" elif operation == "Matrix Operations": try: # Convert input into matrix matrix_data = [[int(num) for num in row.split()] for row in expr.split(";")] matrix = sp.Matrix(matrix_data) # Show options for matrix calculations matrix_operation = st.selectbox("Choose matrix operation", ["Determinant", "Inverse", "Transpose"]) if matrix_operation == "Determinant": result = matrix.det() elif matrix_operation == "Inverse": result = matrix.inv() if matrix.det() != 0 else "Matrix is singular (no inverse)." elif matrix_operation == "Transpose": result = matrix.T except Exception as e: result = f"Error: {e}" # Display result st.write("Result:") st.success(result)