File size: 2,333 Bytes
f3992a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import streamlit as st
from sympy import symbols, Eq, solve, log, sin, cos, tan, diff, integrate
from sympy.parsing.sympy_parser import parse_expr
from transformers import pipeline

# Initialize the Hugging Face model for math question answering
math_model = pipeline("text2text-generation", model="google/t5-small-ssm-nq")

def solve_math_problem(problem):
    try:
        # Attempt to parse and solve mathematical expressions
        expr = parse_expr(problem)
        # Solve algebraic equations or expressions
        if isinstance(expr, Eq):
            return solve(expr)
        else:
            return expr
    except:
        # Handle complex cases or when sympy can't solve the problem
        result = math_model(problem)
        return result[0]['generated_text']

def solve_trigonometric(problem):
    # Process trigonometric expressions
    try:
        if 'sin' in problem or 'cos' in problem or 'tan' in problem:
            expr = parse_expr(problem)
            return expr
        else:
            return "This doesn't seem to be a trigonometric expression."
    except:
        return "Unable to solve the trigonometric expression."

def solve_de_morgan_law(problem):
    # Example function to handle de Morgan's law
    if "not" in problem and "or" in problem or "and" in problem:
        # This is a basic check, for detailed handling we can implement a parser
        return f"De Morgan's transformation for: {problem}."
    return "No de Morgan's law expression found."

# Streamlit UI
st.title("Math Solver App")

st.write("This app can solve mathematical problems like algebra, trigonometry, and logic.")

question = st.text_input("Enter your math question here:")

if question:
    if "log" in question:
        # Handle logarithmic expressions
        result = solve_math_problem(question)
        st.write(f"Logarithmic result: {result}")
    elif "sin" in question or "cos" in question or "tan" in question:
        result = solve_trigonometric(question)
        st.write(f"Trigonometric result: {result}")
    elif "not" in question or "and" in question or "or" in question:
        result = solve_de_morgan_law(question)
        st.write(result)
    else:
        # For algebraic or other mathematical expressions
        result = solve_math_problem(question)
        st.write(f"Result: {result}")