Files changed (3) hide show
  1. README.md +4 -36
  2. app.py +384 -377
  3. requirements.txt +0 -2
README.md CHANGED
@@ -1,7 +1,7 @@
1
  ---
2
- title: Mathematics Question Generator
3
- emoji: 🧮
4
- colorFrom: blue
5
  colorTo: green
6
  sdk: gradio
7
  sdk_version: 5.29.0
@@ -9,36 +9,4 @@ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- # Mathematics Question Generator
13
-
14
- This application generates customized mathematics questions on any topic you specify. Simply enter a mathematics chapter or concept you want to practice, and the AI will create questions with step-by-step solutions.
15
-
16
- ## Features
17
-
18
- - Generate mathematics questions on any topic
19
- - Choose the number of questions (1-10)
20
- - Select difficulty level (elementary to advanced)
21
- - View detailed step-by-step solutions
22
-
23
- ## How to Use
24
-
25
- 1. Enter a mathematics topic (e.g., "Linear Algebra: Eigenvalues", "Calculus: Integration")
26
- 2. Adjust the number of questions and difficulty level as needed
27
- 3. Click "Generate Questions"
28
- 4. Study the generated questions and their solutions
29
-
30
- ## Setup Requirements
31
-
32
- This application requires a Hugging Face API token with access to the DeepSeek models. To set up your token:
33
-
34
- 1. Generate a Hugging Face API token with read access from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens)
35
- 2. Add this token to your Space as a secret with the key `HUGGINGFACE_TOKEN`
36
- - Go to your Space settings
37
- - Click on "Secrets"
38
- - Add a new secret with name `HUGGINGFACE_TOKEN` and your token as the value
39
-
40
- ## About
41
-
42
- This application uses DeepSeek's mathematics-focused language model to generate high-quality mathematics questions tailored to your learning needs.
43
-
44
- Created by Kamagelo Mosia
 
1
  ---
2
+ title: Math
3
+ emoji: 🌍
4
+ colorFrom: indigo
5
  colorTo: green
6
  sdk: gradio
7
  sdk_version: 5.29.0
 
9
  pinned: false
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py CHANGED
@@ -1,396 +1,403 @@
1
- import os
2
- import torch
3
  import json
4
- import time
5
- import logging
6
  from datetime import datetime
7
- from threading import Thread
8
- from queue import Queue
9
- from transformers import AutoTokenizer, AutoModelForCausalLM
10
 
11
- # Configuration
12
- PRIMARY_MODEL = "TinyLlama/TinyLlama-1.1B-Chat-v1.0" # First model to try
13
- SECONDARY_MODEL = "facebook/opt-1.3b" # More powerful backup model
14
- DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
15
- BATCH_SIZE = 5 # Process 5 chapters at a time
16
- MAX_RETRIES = 3
17
- OUTPUT_DIR = "calculus_textbook_output"
18
- LOG_FILE = "textbook_generation.log"
19
-
20
- # Setup logging
21
- os.makedirs(OUTPUT_DIR, exist_ok=True)
22
- logging.basicConfig(
23
- filename=os.path.join(OUTPUT_DIR, LOG_FILE),
24
- level=logging.INFO,
25
- format='%(asctime)s - %(levelname)s - %(message)s'
26
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
- class ModelManager:
29
- """Manages loading and switching between language models for text generation."""
 
 
30
 
31
- def __init__(self):
32
- self.models = {}
33
- self.tokenizers = {}
34
- self.current_model = None
35
-
36
- def load_model(self, model_name):
37
- """Load a model and its tokenizer if not already loaded."""
38
- if model_name not in self.models:
39
- try:
40
- logging.info(f"Loading model: {model_name}")
41
- tokenizer = AutoTokenizer.from_pretrained(model_name)
42
- model = AutoModelForCausalLM.from_pretrained(
43
- model_name,
44
- torch_dtype=torch.float16 if DEVICE == "cuda" else torch.float32,
45
- device_map="auto" if DEVICE == "cuda" else None
46
- )
47
- model.eval()
48
-
49
- self.models[model_name] = model
50
- self.tokenizers[model_name] = tokenizer
51
- logging.info(f"Successfully loaded model: {model_name}")
52
- return True
53
- except Exception as e:
54
- logging.error(f"Failed to load model {model_name}: {str(e)}")
55
- return False
56
- return True
57
 
58
- def set_current_model(self, model_name):
59
- """Set the current model to use for generation."""
60
- if model_name not in self.models and not self.load_model(model_name):
61
- return False
62
- self.current_model = model_name
63
- return True
64
 
65
- def generate_text(self, prompt, max_length=1024):
66
- """Generate text using the current model."""
67
- if not self.current_model:
68
- raise ValueError("No model selected. Call set_current_model first.")
69
-
70
- model = self.models[self.current_model]
71
- tokenizer = self.tokenizers[self.current_model]
72
-
73
- inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
74
-
75
- # Generate with some randomness for creativity
76
- with torch.no_grad():
77
- outputs = model.generate(
78
- **inputs,
79
- max_length=max_length,
80
- temperature=0.7,
81
- top_p=0.9,
82
- do_sample=True,
83
- pad_token_id=tokenizer.eos_token_id
84
- )
85
-
86
- response = tokenizer.decode(outputs[0], skip_special_tokens=True)
87
- # Extract only the generated part
88
- generated_text = response[len(tokenizer.decode(inputs['input_ids'][0], skip_special_tokens=True)):].strip()
89
- return generated_text
90
-
91
- class CalculusTextbookGenerator:
92
- """Generates a complete calculus textbook with questions and solutions."""
93
 
94
- def __init__(self):
95
- self.model_manager = ModelManager()
96
- self.textbook_data = self.create_initial_textbook_structure()
97
-
98
- def create_initial_textbook_structure(self):
99
- """Create the initial structure of the calculus textbook."""
100
- return {
101
- "books": [
102
- {
103
- "name": "Calculus 1: Early Transcendentals",
104
- "details": "Introduction to single-variable calculus including limits, derivatives, and basic integration techniques.",
105
- "chapters": [
106
- {
107
- "chapterTitle": "Chapter 6: Applications of Integration",
108
- "subChapters": [
109
- "6.1: Areas Between Curves",
110
- "6.2: Volumes",
111
- "6.3: Volumes by Cylindrical Shells",
112
- "6.4: Work",
113
- "6.5: Average Value of a Function"
114
- ],
115
- "questions": [] # Will be filled with generated questions
116
- },
117
- {
118
- "chapterTitle": "Chapter 8: Further Applications of Integration",
119
- "subChapters": [
120
- "8.1: Arc Length",
121
- "8.2: Area of a Surface of Revolution",
122
- "8.3: Applications to Physics and Engineering",
123
- "8.4: Applications to Economics and Biology",
124
- "8.5: Probability"
125
- ],
126
- "questions": []
127
- },
128
- {
129
- "chapterTitle": "Chapter 9: Differential Equations",
130
- "subChapters": [
131
- "9.1: Modeling with Differential Equations",
132
- "9.2: Direction Fields and Euler's Method",
133
- "9.3: Separable Equations",
134
- "9.4: Models for Population Growth",
135
- "9.5: Linear Equations",
136
- "9.6: Predator–Prey Systems"
137
- ],
138
- "questions": []
139
- },
140
- {
141
- "chapterTitle": "Chapter 10: Parametric Equations and Polar Coordinates",
142
- "subChapters": [
143
- "10.1: Curves Defined by Parametric Equations",
144
- "10.2: Calculus with Parametric Curves",
145
- "10.3: Polar Coordinates",
146
- "10.4: Calculus in Polar Coordinates",
147
- "10.5: Conic Sections",
148
- "10.6: Conic Sections in Polar Coordinates"
149
- ],
150
- "questions": []
151
- },
152
- {
153
- "chapterTitle": "Chapter 11: Sequences, Series, and Power Series",
154
- "subChapters": [
155
- "11.1: Sequences",
156
- "11.2: Series",
157
- "11.3: The Integral Test and Estimates of Sums",
158
- "11.4: The Comparison Tests",
159
- "11.5: Alternating Series and Absolute Convergence",
160
- "11.6: The Ratio and Root Tests",
161
- "11.7: Power Series"
162
- ],
163
- "questions": []
164
- }
165
- ]
166
- },
167
- {
168
- "name": "Calculus 2: Advanced Concepts",
169
- "details": "Advances into series, sequences, techniques of integration, and vector calculus.",
170
- "chapters": [
171
- {
172
- "chapterTitle": "Chapter 12: Vectors and the Geometry of Space",
173
- "subChapters": [
174
- "12.1: Three-Dimensional Coordinate Systems",
175
- "12.2: Vectors",
176
- "12.3: The Dot Product",
177
- "12.4: The Cross Product",
178
- "12.5: Equations of Lines and Planes",
179
- "12.6: Cylinders and Quadric Surfaces"
180
- ],
181
- "questions": []
182
- },
183
- {
184
- "chapterTitle": "Chapter 13: Vector Functions",
185
- "subChapters": [
186
- "13.1: Vector Functions and Space Curves",
187
- "13.2: Derivatives and Integrals of Vector Functions",
188
- "13.3: Arc Length and Curvature",
189
- "13.4: Motion in Space: Velocity and Acceleration"
190
- ],
191
- "questions": []
192
- },
193
- {
194
- "chapterTitle": "Chapter 14: Partial Derivatives",
195
- "subChapters": [
196
- "14.1: Functions of Several Variables",
197
- "14.2: Limits and Continuity",
198
- "14.3: Partial Derivatives",
199
- "14.4: Tangent Planes and Linear Approximation",
200
- "14.5: The Chain Rule"
201
- ],
202
- "questions": []
203
- }
204
- ]
205
- }
206
- ]
207
- }
208
-
209
- def generate_question_set(self, chapter_title, subchapter_titles, num_questions=3):
210
- """Generate a set of questions with step-by-step solutions for a chapter."""
211
-
212
- # Try the primary model first
213
- self.model_manager.set_current_model(PRIMARY_MODEL)
214
-
215
- prompt = f"""Create {num_questions} calculus questions with detailed step-by-step solutions for:
216
- {chapter_title}
217
-
218
- The questions should cover these subchapters:
219
- {', '.join(subchapter_titles)}
220
 
221
- For each question:
222
- 1. Write a clear, university-level calculus problem
223
- 2. Provide a comprehensive step-by-step solution with all math steps shown
224
- 3. Include a final answer
225
 
226
- Format each question as:
227
- QUESTION: [Problem statement]
228
- SOLUTION:
229
- Step 1: [First step with explanation]
230
- Step 2: [Next step]
231
- ...
232
- Final Answer: [The solution]
233
-
234
- Make sure to use proper mathematical notation and include a variety of question types.
235
- """
 
 
 
 
 
 
 
236
 
237
- try:
238
- generated_content = self.model_manager.generate_text(prompt, max_length=2048)
239
-
240
- # Check if the content looks good
241
- if len(generated_content) < 200 or "QUESTION" not in generated_content:
242
- # Try the secondary model if the primary one gave poor results
243
- logging.warning(f"Primary model gave insufficient results for {chapter_title}. Trying secondary model.")
244
- self.model_manager.set_current_model(SECONDARY_MODEL)
245
- generated_content = self.model_manager.generate_text(prompt, max_length=2048)
246
-
247
- # Parse the generated content into question objects
248
- questions = self.parse_questions(generated_content)
249
-
250
- if not questions or len(questions) == 0:
251
- logging.warning(f"Failed to parse any questions from content for {chapter_title}")
252
- return []
253
-
254
- return questions
255
-
256
- except Exception as e:
257
- logging.error(f"Error generating questions for {chapter_title}: {str(e)}")
258
- return []
259
-
260
- def parse_questions(self, content):
261
- """Parse the generated content into structured question objects."""
262
- questions = []
263
-
264
- # Split by "QUESTION:" or similar markers
265
- parts = content.split("QUESTION:")
266
-
267
- for i, part in enumerate(parts):
268
- if i == 0:
269
- continue # Skip the first part (before the first QUESTION:)
270
-
271
- try:
272
- # Split into question and solution
273
- if "SOLUTION:" in part:
274
- question_text, solution = part.split("SOLUTION:", 1)
275
- else:
276
- # Try alternative formats
277
- for marker in ["Solution:", "STEPS:", "Steps:"]:
278
- if marker in part:
279
- question_text, solution = part.split(marker, 1)
280
- break
281
- else:
282
- question_text = part
283
- solution = ""
284
-
285
- questions.append({
286
- "question": question_text.strip(),
287
- "solution": solution.strip()
288
- })
289
- except Exception as e:
290
- logging.error(f"Error parsing question {i}: {str(e)}")
291
- continue
292
-
293
- return questions
294
 
295
- def worker_function(self, queue, results):
296
- """Worker thread function to process chapters from queue."""
297
- while True:
298
- item = queue.get()
299
- if item is None: # None signals to exit
300
- queue.task_done()
301
- break
302
-
303
- book_idx, chapter_idx, chapter = item
304
- chapter_title = chapter["chapterTitle"]
305
- subchapters = chapter.get("subChapters", [])
306
-
307
- logging.info(f"Processing: {chapter_title}")
308
-
309
- # Try to generate questions with retries
310
- for attempt in range(MAX_RETRIES):
311
- try:
312
- questions = self.generate_question_set(chapter_title, subchapters, num_questions=4)
313
- if questions:
314
- # Save the questions to the chapter
315
- self.textbook_data["books"][book_idx]["chapters"][chapter_idx]["questions"] = questions
316
-
317
- logging.info(f"✓ Generated {len(questions)} questions for {chapter_title}")
318
- break # Success, exit retry loop
319
- else:
320
- logging.warning(f"No questions generated for {chapter_title} on attempt {attempt+1}")
321
-
322
- except Exception as e:
323
- logging.error(f"Attempt {attempt+1}/{MAX_RETRIES} failed for {chapter_title}: {str(e)}")
324
- time.sleep(2) # Wait before retrying
325
-
326
- # Save current state to file
327
- self.save_current_state()
328
- queue.task_done()
329
 
330
- def save_current_state(self):
331
- """Save the current state of the textbook generation."""
332
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
333
- with open(os.path.join(OUTPUT_DIR, f"textbook_state_{timestamp}.json"), "w") as f:
334
- json.dump(self.textbook_data, f, indent=2)
335
-
336
- # Also save to a fixed filename for the latest state
337
- with open(os.path.join(OUTPUT_DIR, "textbook_latest.json"), "w") as f:
338
- json.dump(self.textbook_data, f, indent=2)
339
 
340
- def process_in_batches(self):
341
- """Process all chapters in batches."""
342
- queue = Queue()
343
-
344
- # Queue all chapters for processing
345
- for book_idx, book in enumerate(self.textbook_data["books"]):
346
- for chapter_idx, chapter in enumerate(book["chapters"]):
347
- queue.put((book_idx, chapter_idx, chapter))
348
-
349
- # Create and start worker thread
350
- worker = Thread(target=self.worker_function, args=(queue, None))
351
- worker.daemon = True # Allow the program to exit even if the thread is running
352
- worker.start()
353
-
354
- # Process in batches
355
- total_chapters = queue.qsize()
356
- processed = 0
357
-
358
- while processed < total_chapters:
359
- # Wait for the batch to be processed
360
- start_size = queue.qsize()
361
- batch_size = min(BATCH_SIZE, start_size)
362
-
363
- logging.info(f"Processing batch of {batch_size} chapters. {start_size} remaining.")
364
-
365
- # Wait until this batch is done
366
- while queue.qsize() > start_size - batch_size:
367
- time.sleep(2)
368
-
369
- processed += batch_size
370
- logging.info(f"Batch complete. {processed}/{total_chapters} chapters processed.")
371
-
372
- # Save current state
373
- self.save_current_state()
374
-
375
- # Signal worker to exit
376
- queue.put(None)
377
- worker.join()
378
-
379
- # Save final state
380
- self.save_current_state()
381
- logging.info("All chapters processed. Textbook generation complete.")
382
 
383
- def main():
384
- start_time = datetime.now()
385
- logging.info(f"Starting textbook generation at {start_time}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
386
 
387
- generator = CalculusTextbookGenerator()
388
- generator.process_in_batches()
 
 
 
389
 
390
- end_time = datetime.now()
391
- duration = end_time - start_time
392
- logging.info(f"Textbook generation completed in {duration}")
393
- logging.info(f"Final textbook saved to {os.path.join(OUTPUT_DIR, 'textbook_latest.json')}")
394
 
 
395
  if __name__ == "__main__":
396
- main()
 
1
+ import gradio as gr
2
+ import random
3
  import json
4
+ import tempfile
5
+ import os
6
  from datetime import datetime
 
 
 
7
 
8
+ # Define a comprehensive list of calculus topics based on James Stewart's textbook
9
+ TOPICS = {
10
+ "Limits and Continuity": {
11
+ "formula": "For a function $f(x)$, $\\lim_{x \\to a} f(x) = L$",
12
+ "functions": {
13
+ "easy": [
14
+ {"func": "$\\lim_{x \\to 2} (3x+4)$", "domain": ["$x \\to 2$"], "solution": "$10$"},
15
+ {"func": "$\\lim_{x \\to 0} \\frac{\\sin(x)}{x}$", "domain": ["$x \\to 0$"], "solution": "$1$"},
16
+ {"func": "$\\lim_{x \\to 3} (x^2-5x+2)$", "domain": ["$x \\to 3$"], "solution": "$-4$"},
17
+ {"func": "$\\lim_{x \\to 1} \\frac{x^2-1}{x-1}$", "domain": ["$x \\to 1$"], "solution": "$2$"},
18
+ {"func": "$\\lim_{x \\to \\infty} \\frac{2x^2+3x-5}{x^2}$", "domain": ["$x \\to \\infty$"], "solution": "$2$"}
19
+ ],
20
+ "hard": [
21
+ {"func": "$\\lim_{x \\to 0} \\frac{1-\\cos(x)}{x^2}$", "domain": ["$x \\to 0$"], "solution": "$\\frac{1}{2}$"},
22
+ {"func": "$\\lim_{x \\to 0} (\\frac{1}{x} - \\frac{1}{\\sin(x)})$", "domain": ["$x \\to 0$"], "solution": "$0$"},
23
+ {"func": "$\\lim_{x \\to 0} \\frac{e^x-1-x}{x^2}$", "domain": ["$x \\to 0$"], "solution": "$\\frac{1}{2}$"},
24
+ {"func": "$\\lim_{x \\to \\infty} (1 + \\frac{1}{x})^x$", "domain": ["$x \\to \\infty$"], "solution": "$e$"},
25
+ {"func": "$\\lim_{x \\to 0^+} x^{\\alpha}\\ln(x)$ where $\\alpha > 0$", "domain": ["$x \\to 0^+$"], "solution": "$0$"}
26
+ ]
27
+ }
28
+ },
29
+ "Derivatives and Differentiation": {
30
+ "formula": "$f'(x) = \\lim_{h \\to 0} \\frac{f(x+h) - f(x)}{h}$",
31
+ "functions": {
32
+ "easy": [
33
+ {"func": "$f(x) = x^3 - 4x^2 + 7x - 2$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = 3x^2 - 8x + 7$"},
34
+ {"func": "$f(x) = \\sin(2x)$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = 2\\cos(2x)$"},
35
+ {"func": "$f(x) = e^{3x}$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = 3e^{3x}$"},
36
+ {"func": "$f(x) = \\ln(x^2 + 1)$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = \\frac{2x}{x^2+1}$"},
37
+ {"func": "$f(x) = x^2 e^x$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = x^2 e^x + 2x e^x$"}
38
+ ],
39
+ "hard": [
40
+ {"func": "$f(x) = \\frac{\\sin(x)}{\\cos(x) + 2}$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = \\frac{\\cos(x)(\\cos(x) + 2) + \\sin^2(x)}{(\\cos(x) + 2)^2}$"},
41
+ {"func": "$f(x) = \\int_{0}^{x^2} \\sin(t^2) dt$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = 2x\\sin(x^4)$"},
42
+ {"func": "$f(x) = \\arctan(e^x)$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = \\frac{e^x}{1 + e^{2x}}$"},
43
+ {"func": "$f(x) = x^{\\sin(x)}$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = x^{\\sin(x)}(\\cos(x)\\ln(x) + \\frac{\\sin(x)}{x})$"},
44
+ {"func": "$f(x) = \\ln(\\sin(x))$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = \\cot(x)$"}
45
+ ]
46
+ }
47
+ },
48
+ "Applications of Derivatives": {
49
+ "formula": "Related Rates, Optimization, L'Hôpital's Rule",
50
+ "functions": {
51
+ "easy": [
52
+ {"func": "A particle moves according to $s(t) = t^3 - 6t^2 + 9t$. Find its velocity at $t = 2$", "domain": ["$t = 2$"], "solution": "$v(2) = -3$ units/sec"},
53
+ {"func": "Find the critical points of $f(x) = x^3 - 3x^2 - 9x + 5$", "domain": ["$x \\in \\mathbb{R}$"], "solution": "$x = -1$ and $x = 3$"},
54
+ {"func": "Find the absolute maximum and minimum of $f(x) = x^2 - 4x + 3$ on $[0, 3]$", "domain": ["$[0, 3]$"], "solution": "Maximum: $f(0) = 3$, Minimum: $f(2) = -1$"},
55
+ {"func": "Use L'Hôpital's Rule to evaluate $\\lim_{x \\to 0} \\frac{\\tan(3x)}{x}$", "domain": ["$x \\to 0$"], "solution": "$3$"},
56
+ {"func": "Find the equation of the tangent line to $f(x) = x^2 + 2x - 3$ at $x = 1$", "domain": ["$x = 1$"], "solution": "$y = 4x - 2$"}
57
+ ],
58
+ "hard": [
59
+ {"func": "A ladder 10 feet long leans against a wall. If the bottom slides away at 2 ft/s, how fast is the top sliding down when it's 6 feet above ground?", "domain": ["Rate problem"], "solution": "$\\frac{3}{2}$ ft/s"},
60
+ {"func": "Find the dimensions of the rectangle with perimeter 100 m that has the maximum area", "domain": ["Optimization"], "solution": "25 m × 25 m square"},
61
+ {"func": "Use Newton's method to approximate a root of $f(x) = x^3 - 2x - 5$ starting with $x_1 = 2$", "domain": ["Newton's Method"], "solution": "$x \\approx 2.0946$ after 3 iterations"},
62
+ {"func": "Find the absolute extrema of $f(x) = xe^{-x^2}$ on $[0, \\infty)$", "domain": ["$[0, \\infty)$"], "solution": "Maximum: $f(\\frac{1}{\\sqrt{2}}) = \\frac{1}{\\sqrt{2e}}$, Minimum: $f(0) = f(\\infty) = 0$"},
63
+ {"func": "Use implicit differentiation to find $\\frac{dy}{dx}$ for $x^3 + y^3 = 6xy$", "domain": ["Implicit"], "solution": "$\\frac{dy}{dx} = \\frac{6y - 3x^2}{3y^2 - 6x}$"}
64
+ ]
65
+ }
66
+ },
67
+ "Integration Techniques": {
68
+ "formula": "$\\int f(x) dx$ using various methods",
69
+ "functions": {
70
+ "easy": [
71
+ {"func": "$\\int x^3(x^2+1)^4 dx$", "domain": ["Use Substitution"], "solution": "$\\frac{1}{10}(x^2+1)^5 - \\frac{1}{6}(x^2+1)^3 + C$"},
72
+ {"func": "$\\int \\frac{1}{x^2-4} dx$", "domain": ["Use Partial Fractions"], "solution": "$\\frac{1}{4}\\ln|\\frac{x-2}{x+2}| + C$"},
73
+ {"func": "$\\int x\\sin(x) dx$", "domain": ["Use Integration by Parts"], "solution": "$\\sin(x) - x\\cos(x) + C$"},
74
+ {"func": "$\\int \\sec^2(3x) dx$", "domain": ["Trigonometric"], "solution": "$\\frac{1}{3}\\tan(3x) + C$"},
75
+ {"func": "$\\int \\frac{5}{3x+6} dx$", "domain": ["Substitution"], "solution": "$\\frac{5}{3}\\ln|3x+6| + C$"}
76
+ ],
77
+ "hard": [
78
+ {"func": "$\\int \\frac{x^2}{\\sqrt{1-x^2}} dx$", "domain": ["Trigonometric Substitution"], "solution": "$-\\frac{x\\sqrt{1-x^2}}{2} - \\frac{\\arcsin(x)}{2} + C$"},
79
+ {"func": "$\\int \\frac{\\ln(x)}{x^2} dx$", "domain": ["Integration by Parts"], "solution": "$-\\frac{\\ln(x)}{x} - \\frac{1}{x} + C$"},
80
+ {"func": "$\\int e^x\\sin(x) dx$", "domain": ["Integration by Parts twice"], "solution": "$\\frac{e^x(\\sin(x)-\\cos(x))}{2} + C$"},
81
+ {"func": "$\\int \\frac{1}{x^2-x-6} dx$", "domain": ["Partial Fractions"], "solution": "$\\frac{1}{5}\\ln|\\frac{x+2}{x-3}| + C$"},
82
+ {"func": "$\\int \\frac{1}{\\sqrt{x^2-a^2}} dx$", "domain": ["$a > 0$"], "solution": "$\\ln|x + \\sqrt{x^2-a^2}| + C$"}
83
+ ]
84
+ }
85
+ },
86
+ "Average Value": {
87
+ "formula": "$f_{avg} = \\frac{1}{b-a} \\int_{a}^{b} f(x) dx$",
88
+ "functions": {
89
+ "easy": [
90
+ {"func": "$x^2$", "domain": [0, 2], "solution": "$\\frac{4}{3}$"},
91
+ {"func": "$\\sin(x)$", "domain": [0, "π"], "solution": "$\\frac{2}{\\pi}$"},
92
+ {"func": "$e^x$", "domain": [0, 1], "solution": "$(e-1)$"},
93
+ {"func": "$x$", "domain": [1, 4], "solution": "$\\frac{5}{2}$"},
94
+ {"func": "$x^3$", "domain": [0, 1], "solution": "$\\frac{1}{4}$"}
95
+ ],
96
+ "hard": [
97
+ {"func": "$x\\sin(x)$", "domain": [0, "π"], "solution": "$\\frac{\\pi}{2}$"},
98
+ {"func": "$\\ln(x)$", "domain": [1, "e"], "solution": "$1-\\frac{1}{e}$"},
99
+ {"func": "$x^2e^x$", "domain": [0, 1], "solution": "$2e-2$"},
100
+ {"func": "$\\frac{1}{1+x^2}$", "domain": [0, 1], "solution": "$\\frac{\\pi}{4}$"},
101
+ {"func": "$\\sqrt{x}$", "domain": [0, 4], "solution": "$\\frac{4}{3}$"}
102
+ ]
103
+ }
104
+ },
105
+ "Arc Length": {
106
+ "formula": "$L = \\int_{a}^{b} \\sqrt{1 + (f'(x))^2} dx$",
107
+ "functions": {
108
+ "easy": [
109
+ {"func": "$x^2$", "domain": [0, 1], "solution": "$\\approx 1.4789$"},
110
+ {"func": "$x^{3/2}$", "domain": [0, 1], "solution": "$\\approx 1.1919$"},
111
+ {"func": "$2x+1$", "domain": [0, 2], "solution": "$2\\sqrt{5}$"},
112
+ {"func": "$x^3$", "domain": [0, 1], "solution": "$\\approx 1.0801$"},
113
+ {"func": "$\\sin(x)$", "domain": [0, "π/2"], "solution": "$\\approx 1.9118$"}
114
+ ],
115
+ "hard": [
116
+ {"func": "$\\ln(x)$", "domain": [1, 3], "solution": "$\\approx 2.3861$"},
117
+ {"func": "$e^x$", "domain": [0, 1], "solution": "$\\approx 1.1752$"},
118
+ {"func": "$\\cosh(x)$", "domain": [0, 1], "solution": "$\\sinh(1)$"},
119
+ {"func": "$x^2 - \\ln(x)$", "domain": [1, 2], "solution": "$\\approx 3.1623$"},
120
+ {"func": "$x = \\cos(t)$, $y = \\sin(t)$ for $t\\in[0,\\pi]$", "domain": [0, "π"], "solution": "$\\pi$"}
121
+ ]
122
+ }
123
+ },
124
+ "Surface Area": {
125
+ "formula": "$S = 2\\pi \\int_{a}^{b} f(x) \\sqrt{1 + (f'(x))^2} dx$",
126
+ "functions": {
127
+ "easy": [
128
+ {"func": "$x$", "domain": [0, 3], "solution": "$2\\pi \\cdot 4.5$"},
129
+ {"func": "$x^2$", "domain": [0, 1], "solution": "$\\approx 2\\pi \\cdot 0.7169$"},
130
+ {"func": "$\\sqrt{x}$", "domain": [0, 4], "solution": "$\\approx 2\\pi \\cdot 4.5177$"},
131
+ {"func": "$1$", "domain": [0, 2], "solution": "$2\\pi \\cdot 2$"},
132
+ {"func": "$\\frac{x}{2}$", "domain": [0, 4], "solution": "$2\\pi \\cdot 4.1231$"}
133
+ ],
134
+ "hard": [
135
+ {"func": "$x^3$", "domain": [0, 1], "solution": "$\\approx 2\\pi \\cdot 0.6004$"},
136
+ {"func": "$e^x$", "domain": [0, 1], "solution": "$\\approx 2\\pi \\cdot 1.1793$"},
137
+ {"func": "$\\sin(x)$", "domain": [0, "π/2"], "solution": "$\\approx 2\\pi \\cdot 0.6366$"},
138
+ {"func": "$\\frac{1}{x}$", "domain": [1, 2], "solution": "$\\approx 2\\pi \\cdot 1.1478$"},
139
+ {"func": "$\\ln(x)$", "domain": [1, 2], "solution": "$\\approx 2\\pi \\cdot 0.5593$"}
140
+ ]
141
+ }
142
+ },
143
+ "Differential Equations": {
144
+ "formula": "Various types",
145
+ "functions": {
146
+ "easy": [
147
+ {"func": "$\\frac{dy}{dx} = 2x$", "domain": ["$y(0)=1$"], "solution": "$y = x^2 + 1$"},
148
+ {"func": "$\\frac{dy}{dx} = y$", "domain": ["$y(0)=1$"], "solution": "$y = e^x$"},
149
+ {"func": "$\\frac{dy}{dx} = 3x^2$", "domain": ["$y(0)=2$"], "solution": "$y = x^3 + 2$"},
150
+ {"func": "$\\frac{dy}{dx} = -y$", "domain": ["$y(0)=4$"], "solution": "$y = 4e^{-x}$"},
151
+ {"func": "$\\frac{dy}{dx} = x+1$", "domain": ["$y(0)=-2$"], "solution": "$y = \\frac{x^2}{2} + x - 2$"}
152
+ ],
153
+ "hard": [
154
+ {"func": "$y'' + 4y = 0$", "domain": ["$y(0)=1$, $y'(0)=0$"], "solution": "$y = \\cos(2x)$"},
155
+ {"func": "$y'' - y = x$", "domain": ["$y(0)=0$, $y'(0)=1$"], "solution": "$y = \\frac{e^x}{2} - \\frac{e^{-x}}{2} - x$"},
156
+ {"func": "$y' + y = e^x$", "domain": ["$y(0)=0$"], "solution": "$y = xe^x$"},
157
+ {"func": "$y'' + 2y' + y = 0$", "domain": ["$y(0)=1$, $y'(0)=-1$"], "solution": "$y = (1-x)e^{-x}$"},
158
+ {"func": "$y'' - 2y' + y = x^2$", "domain": ["$y(0)=1$, $y'(0)=1$"], "solution": "$y = \\frac{x^2}{2} + 2x + 1$"}
159
+ ]
160
+ }
161
+ },
162
+ "Area and Volume": {
163
+ "formula": "$A = \\int_{a}^{b} f(x) dx$, $V = \\pi \\int_{a}^{b} [f(x)]^2 dx$",
164
+ "functions": {
165
+ "easy": [
166
+ {"func": "$f(x) = x^2$, find area under the curve", "domain": [0, 3], "solution": "$9$"},
167
+ {"func": "$f(x) = \\sin(x)$, find area under the curve", "domain": [0, "π"], "solution": "$2$"},
168
+ {"func": "$f(x) = 4-x^2$, find area under the curve", "domain": [-2, 2], "solution": "$\\frac{16}{3}$"},
169
+ {"func": "$f(x) = \\sqrt{x}$, find volume of revolution around x-axis", "domain": [0, 4], "solution": "$\\frac{16\\pi}{3}$"},
170
+ {"func": "$f(x) = x$, find volume of revolution around x-axis", "domain": [0, 2], "solution": "$\\frac{8\\pi}{3}$"}
171
+ ],
172
+ "hard": [
173
+ {"func": "Area between $f(x) = x^2$ and $g(x) = x^3$", "domain": [0, 1], "solution": "$\\frac{1}{12}$"},
174
+ {"func": "Volume of solid bounded by $z = 4-x^2-y^2$ and $z = 0$", "domain": ["$x^2+y^2\\leq 4$"], "solution": "$8\\pi$"},
175
+ {"func": "Volume of solid formed by rotating region bounded by $y = x^2$, $y = 0$, $x = 2$ around y-axis", "domain": [0, 2], "solution": "$\\frac{8\\pi}{5}$"},
176
+ {"func": "Area between $f(x) = \\sin(x)$ and $g(x) = \\cos(x)$", "domain": [0, "π/4"], "solution": "$\\sqrt{2}-1$"},
177
+ {"func": "Volume of solid formed by rotating region bounded by $y = e^x$, $y = 0$, $x = 0$, $x = 1$ around x-axis", "domain": [0, 1], "solution": "$\\frac{\\pi(e^2-1)}{2}$"}
178
+ ]
179
+ }
180
+ },
181
+ "Parametric Curves and Equations": {
182
+ "formula": "$x = x(t)$, $y = y(t)$, Arc length = $\\int_{a}^{b} \\sqrt{(\\frac{dx}{dt})^2 + (\\frac{dy}{dt})^2} dt$",
183
+ "functions": {
184
+ "easy": [
185
+ {"func": "$x = t$, $y = t^2$, find $\\frac{dy}{dx}$", "domain": ["$t$"], "solution": "$\\frac{dy}{dx} = 2t$"},
186
+ {"func": "$x = \\cos(t)$, $y = \\sin(t)$, find the arc length", "domain": [0, "π/2"], "solution": "$\\frac{\\pi}{2}$"},
187
+ {"func": "$x = t^2$, $y = t^3$, find $\\frac{dy}{dx}$", "domain": ["$t$"], "solution": "$\\frac{dy}{dx} = \\frac{3t}{2}$"},
188
+ {"func": "$x = 2t$, $y = t^2$, find the area under the curve", "domain": [0, 2], "solution": "$\\frac{4}{3}$"},
189
+ {"func": "$x = t$, $y = \\sin(t)$, find $\\frac{dy}{dx}$", "domain": ["$t$"], "solution": "$\\frac{dy}{dx} = \\cos(t)$"}
190
+ ],
191
+ "hard": [
192
+ {"func": "$x = e^t\\cos(t)$, $y = e^t\\sin(t)$, find $\\frac{dy}{dx}$", "domain": ["$t$"], "solution": "$\\frac{dy}{dx} = \\tan(t) + 1$"},
193
+ {"func": "$x = t-\\sin(t)$, $y = 1-\\cos(t)$, find the arc length", "domain": [0, "2π"], "solution": "$8$"},
194
+ {"func": "$x = \\ln(\\sec(t))$, $y = \\tan(t)$, find $\\frac{dy}{dx}$", "domain": ["$t$"], "solution": "$\\frac{dy}{dx} = \\sec^2(t)$"},
195
+ {"func": "$x = \\cos^3(t)$, $y = \\sin^3(t)$, find the area enclosed", "domain": [0, "2π"], "solution": "$\\frac{3\\pi}{8}$"},
196
+ {"func": "$x = \\cos(t)+t\\sin(t)$, $y = \\sin(t)-t\\cos(t)$, find the arc length", "domain": [0, "2π"], "solution": "$2\\pi\\sqrt{1+4\\pi^2}$"}
197
+ ]
198
+ }
199
+ },
200
+ "Infinite Sequences and Series": {
201
+ "formula": "$\\sum_{n=1}^{\\infty} a_n = a_1 + a_2 + a_3 + ...$",
202
+ "functions": {
203
+ "easy": [
204
+ {"func": "Determine if the sequence $a_n = \\frac{n+3}{2n+1}$ converges and find its limit", "domain": ["$n \\to \\infty$"], "solution": "Converges to $\\frac{1}{2}$"},
205
+ {"func": "Find the sum of the geometric series $\\sum_{n=0}^{\\infty} \\frac{1}{3^n}$", "domain": ["Geometric Series"], "solution": "$\\frac{3}{2}$"},
206
+ {"func": "Determine if the series $\\sum_{n=1}^{\\infty} \\frac{1}{n^2}$ converges", "domain": ["p-series"], "solution": "Converges (p-series with $p=2 > 1$)"},
207
+ {"func": "Find the first three non-zero terms in the Taylor series for $f(x) = e^x$ centered at $a = 0$", "domain": ["Taylor Series"], "solution": "$1 + x + \\frac{x^2}{2} + ...$"},
208
+ {"func": "Find the radius of convergence of the power series $\\sum_{n=1}^{\\infty} \\frac{x^n}{n}$", "domain": ["Power Series"], "solution": "$R = 1$"}
209
+ ],
210
+ "hard": [
211
+ {"func": "Test the convergence of the alternating series $\\sum_{n=1}^{\\infty} (-1)^{n+1}\\frac{\\ln(n)}{n}$", "domain": ["Alternating Series"], "solution": "Converges by the Alternating Series Test"},
212
+ {"func": "Find the radius and interval of convergence for $\\sum_{n=1}^{\\infty} \\frac{n^2 x^n}{3^n}$", "domain": ["Power Series"], "solution": "$R = 3$, interval of convergence is $(-3, 3)$"},
213
+ {"func": "Determine if the series $\\sum_{n=2}^{\\infty} \\frac{1}{n\\ln(n)}$ converges", "domain": ["Integral Test"], "solution": "Diverges by the Integral Test"},
214
+ {"func": "Find the sum of the series $\\sum_{n=1}^{\\infty} \\frac{1}{n(n+1)}$", "domain": ["Telescoping Series"], "solution": "$1$"},
215
+ {"func": "Find the Taylor series of $f(x) = \\ln(1+x)$ and its radius of convergence", "domain": ["Taylor Series"], "solution": "$\\sum_{n=1}^{\\infty} \\frac{(-1)^{n+1}x^n}{n}$, $R = 1$"}
216
+ ]
217
+ }
218
+ },
219
+ "Polar Coordinates": {
220
+ "formula": "$x = r\\cos(\\theta)$, $y = r\\sin(\\theta)$, Area = $\\frac{1}{2}\\int_{\\alpha}^{\\beta} r^2 d\\theta$",
221
+ "functions": {
222
+ "easy": [
223
+ {"func": "Convert the Cartesian point $(1, \\sqrt{3})$ to polar coordinates", "domain": ["Conversion"], "solution": "$r = 2$, $\\theta = \\frac{\\pi}{3}$"},
224
+ {"func": "Find the area enclosed by the circle $r = 3\\sin(\\theta)$", "domain": ["Polar Area"], "solution": "$\\frac{9\\pi}{2}$"},
225
+ {"func": "Convert the polar equation $r = 2$ to Cartesian form", "domain": ["Conversion"], "solution": "$x^2 + y^2 = 4$"},
226
+ {"func": "Find the area enclosed by $r = 2\\cos(\\theta)$", "domain": ["Polar Area"], "solution": "$2\\pi$"},
227
+ {"func": "Convert the Cartesian equation $x^2 + y^2 = 4y$ to polar form", "domain": ["Conversion"], "solution": "$r = 4\\sin(\\theta)$"}
228
+ ],
229
+ "hard": [
230
+ {"func": "Find the area of the region enclosed by the lemniscate $r^2 = 4\\cos(2\\theta)$", "domain": ["Polar Area"], "solution": "$4$"},
231
+ {"func": "Find the area of the region inside $r = 1 + \\cos(\\theta)$ and outside $r = 1$", "domain": ["Polar Area"], "solution": "$\\frac{\\pi}{2}$"},
232
+ {"func": "Find the points of intersection of the polar curves $r = 1 + \\sin(\\theta)$ and $r = 1 - \\sin(\\theta)$", "domain": ["Polar Curves"], "solution": "$(0, 0)$ and $(1, \\frac{\\pi}{2})$, $(1, \\frac{3\\pi}{2})$"},
233
+ {"func": "Find the area of the region enclosed by the cardioid $r = 1 + \\cos(\\theta)$", "domain": ["Polar Area"], "solution": "$\\frac{3\\pi}{2}$"},
234
+ {"func": "Find the length of the spiral $r = \\theta$ for $0 \\leq \\theta \\leq 2\\pi$", "domain": ["Polar Arc Length"], "solution": "$\\frac{1}{2}\\sqrt{1+4\\pi^2} + \\frac{1}{2}\\ln(2\\pi + \\sqrt{1+4\\pi^2})$"}
235
+ ]
236
+ }
237
+ },
238
+ "Vector Calculus": {
239
+ "formula": "$\\vec{r}(t) = x(t)\\vec{i} + y(t)\\vec{j} + z(t)\\vec{k}$, $\\vec{v}(t) = \\vec{r}'(t)$, $\\vec{a}(t) = \\vec{v}'(t)$",
240
+ "functions": {
241
+ "easy": [
242
+ {"func": "Find the derivative of the vector function $\\vec{r}(t) = t^2\\vec{i} + \\sin(t)\\vec{j} + e^t\\vec{k}$", "domain": ["Vector Function"], "solution": "$\\vec{r}'(t) = 2t\\vec{i} + \\cos(t)\\vec{j} + e^t\\vec{k}$"},
243
+ {"func": "Find the unit tangent vector of $\\vec{r}(t) = \\cos(t)\\vec{i} + \\sin(t)\\vec{j}$ at $t = 0$", "domain": ["$t = 0$"], "solution": "$\\vec{T}(0) = \\vec{j}$"},
244
+ {"func": "Calculate $\\nabla f$ where $f(x,y,z) = x^2y + yz^2$", "domain": ["Gradient"], "solution": "$\\nabla f = 2xy\\vec{i} + (x^2 + z^2)\\vec{j} + 2yz\\vec{k}$"},
245
+ {"func": "Find the divergence of the vector field $\\vec{F}(x,y,z) = x^2\\vec{i} + 2xy\\vec{j} + yz\\vec{k}$", "domain": ["Divergence"], "solution": "$\\nabla \\cdot \\vec{F} = 2x + 2x + z = 4x + z$"},
246
+ {"func": "Find the curl of $\\vec{F}(x,y,z) = y\\vec{i} + z\\vec{j} + x\\vec{k}$", "domain": ["Curl"], "solution": "$\\nabla \\times \\vec{F} = (1-0)\\vec{i} + (1-0)\\vec{j} + (1-0)\\vec{k} = \\vec{i} + \\vec{j} + \\vec{k}$"}
247
+ ],
248
+ "hard": [
249
+ {"func": "Find the curvature of $\\vec{r}(t) = t\\vec{i} + t^2\\vec{j} + t^3\\vec{k}$ at $t = 1$", "domain": ["Curvature at $t = 1$"], "solution": "$\\kappa = \\frac{2\\sqrt{37}}{49\\sqrt{3}}$"},
250
+ {"func": "Verify Stokes' Theorem for $\\vec{F} = x^2\\vec{i} + xy\\vec{j} + z^2\\vec{k}$ on the hemisphere $z = \\sqrt{1-x^2-y^2}$, $z \\geq 0$", "domain": ["Stokes' Theorem"], "solution": "Both integrals equal $\\frac{\\pi}{2}$"},
251
+ {"func": "Use the Divergence Theorem to evaluate $\\iint_S \\vec{F} \\cdot \\vec{n} \\, dS$ where $\\vec{F}(x,y,z) = x\\vec{i} + y\\vec{j} + z\\vec{k}$ and $S$ is the sphere $x^2+y^2+z^2=4$", "domain": ["Divergence Theorem"], "solution": "$\\iint_S \\vec{F} \\cdot \\vec{n} \\, dS = \\iiint_V 3 \\, dV = 3 \\cdot \\frac{4}{3}\\pi \\cdot 4^{3/2} = 16\\pi$"},
252
+ {"func": "Find the potential function $f$ for the conservative vector field $\\vec{F} = (2x+y)\\vec{i} + (x+2z)\\vec{j} + (2y)\\vec{k}$", "domain": ["Potential Function"], "solution": "$f(x,y,z) = x^2 + xy + 2yz + C$"},
253
+ {"func": "Use Green's Theorem to evaluate $\\oint_C (y^2\\,dx + x^2\\,dy)$ where $C$ is the boundary of the region enclosed by $y = x^2$ and $y = 4$", "domain": ["Green's Theorem"], "solution": "$\\frac{256}{15}$"}
254
+ ]
255
+ }
256
+ },
257
+ "Partial Derivatives and Multiple Integrals": {
258
+ "formula": "$\\frac{\\partial f}{\\partial x}$, $\\frac{\\partial f}{\\partial y}$, $\\iint_D f(x,y) \\, dA$, $\\iiint_E f(x,y,z) \\, dV$",
259
+ "functions": {
260
+ "easy": [
261
+ {"func": "Find $\\frac{\\partial z}{\\partial x}$ and $\\frac{\\partial z}{\\partial y}$ for $z = x^2 + 3xy - y^3$", "domain": ["Partial Derivatives"], "solution": "$\\frac{\\partial z}{\\partial x} = 2x + 3y$, $\\frac{\\partial z}{\\partial y} = 3x - 3y^2$"},
262
+ {"func": "Evaluate $\\iint_D (x + y) \\, dA$ where $D = \\{(x, y) | 0 \\leq x \\leq 1, 0 \\leq y \\leq 2\\}$", "domain": ["Double Integral"], "solution": "$3$"},
263
+ {"func": "Find all critical points of $f(x,y) = x^2 + y^2 - 4x - 6y + 12$", "domain": ["Critical Points"], "solution": "$(2, 3)$"},
264
+ {"func": "Convert the double integral $\\iint_D x^2y \\, dA$ to polar coordinates where $D$ is the disc $x^2 + y^2 \\leq 4$", "domain": ["Change to Polar"], "solution": "$\\int_0^{2\\pi} \\int_0^2 r^3 \\cos^2(\\theta)\\sin(\\theta) \\, dr \\, d\\theta$"},
265
+ {"func": "Evaluate $\\iint_D xy \\, dA$ where $D$ is the triangle with vertices $(0,0)$, $(1,0)$, and $(0,1)$", "domain": ["Double Integral"], "solution": "$\\frac{1}{24}$"}
266
+ ],
267
+ "hard": [
268
+ {"func": "Find the absolute maximum and minimum values of $f(x,y) = 2x^2 + y^2 - 4x + 6y + 10$ on the closed disc $x^2 + y^2 \\leq 25$", "domain": ["Extrema on Region"], "solution": "Maximum: $135$ at $(5,0)$, Minimum: $1$ at $(1,-3)$"},
269
+ {"func": "Evaluate $\\iiint_E xy^2z^3 \\, dV$ where $E$ is the solid bounded by $x=0$, $y=0$, $z=0$, $x+y+z=1$", "domain": ["Triple Integral"], "solution": "$\\frac{1}{840}$"},
270
+ {"func": "Use Lagrange multipliers to find the maximum value of $f(x,y) = xy$ subject to the constraint $x^2 + y^2 = 8$", "domain": ["Lagrange Multipliers"], "solution": "$4$ at $(\\pm 2, \\pm 2)$"},
271
+ {"func": "Change the order of integration in $\\int_0^1 \\int_y^1 e^{xy} \\, dx \\, dy$", "domain": ["Change of Order"], "solution": "$\\int_0^1 \\int_0^x e^{xy} \\, dy \\, dx$"},
272
+ {"func": "Evaluate $\\iint_D \\frac{1}{1+x^2+y^2} \\, dA$ where $D = \\{(x,y) | x^2 + y^2 \\leq 4\\}$", "domain": ["Double Integral"], "solution": "$\\pi\\ln(5)$"}
273
+ ]
274
+ }
275
+ }
276
+ }
277
 
278
+ # Function to generate a question for a given topic and difficulty
279
+ def generate_question(topic_name, difficulty):
280
+ topic_data = TOPICS[topic_name]
281
+ formula = topic_data["formula"]
282
 
283
+ # Select a random function from the available ones for this topic and difficulty
284
+ function_data = random.choice(topic_data["functions"][difficulty])
285
+ func = function_data["func"]
286
+ domain = function_data["domain"]
287
+ solution = function_data["solution"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
 
289
+ # Format domain for display
290
+ if isinstance(domain, list) and len(domain) == 2:
291
+ domain_str = f"[{domain[0]}, {domain[1]}]"
292
+ else:
293
+ domain_str = str(domain)
 
294
 
295
+ # Create question and solution based on difficulty
296
+ if difficulty == "easy":
297
+ question = f"Find the {topic_name.lower()} of {func} over the domain {domain_str}."
298
+ solution_text = f"Step 1: Apply the formula for {topic_name.lower()}: {formula}\n\n"
299
+ solution_text += f"Step 2: Substitute $f(x) = {func}$ and evaluate over {domain_str}\n\n"
300
+ solution_text += f"Step 3: Solve the resulting integral or calculation\n\n"
301
+ solution_text += f"Final Answer: {solution}"
302
+ else:
303
+ question = f"Compute the {topic_name.lower()} for {func} over {domain_str}."
304
+ solution_text = f"Step 1: Apply the formula for {topic_name.lower()}: {formula}\n\n"
305
+ solution_text += f"Step 2: For {func}, substitute into the formula and evaluate over {domain_str}\n\n"
306
+ solution_text += f"Step 3: This requires advanced integration techniques or careful analysis\n\n"
307
+ solution_text += f"Final Answer: {solution}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
 
309
+ return {
310
+ "topic": topic_name,
311
+ "difficulty": difficulty,
312
+ "question": question,
313
+ "solution": solution_text
314
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
315
 
316
+ # Store the latest generated questions
317
+ latest_questions = []
 
 
318
 
319
+ # Generate questions function for Gradio
320
+ def generate_calculus_questions(topic, difficulty, count):
321
+ global latest_questions
322
+ latest_questions = []
323
+
324
+ for _ in range(int(count)):
325
+ question_data = generate_question(topic, difficulty)
326
+ latest_questions.append(question_data)
327
+
328
+ # Format the output for display
329
+ result = ""
330
+ for i, q in enumerate(latest_questions):
331
+ result += f"Question {i+1}: {q['question']}\n\n"
332
+ result += f"Solution {i+1}: {q['solution']}\n\n"
333
+ result += "-" * 40 + "\n\n"
334
+
335
+ return result
336
 
337
+ # Function to export questions to JSON
338
+ def export_to_json():
339
+ if not latest_questions:
340
+ return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341
 
342
+ # Create a JSON file
343
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
344
+ json_data = {
345
+ "generated_at": timestamp,
346
+ "questions": latest_questions
347
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
348
 
349
+ # Create a temporary file
350
+ with tempfile.NamedTemporaryFile(mode="w+", delete=False, suffix=".json") as temp_file:
351
+ json.dump(json_data, temp_file, indent=2)
352
+ temp_file_path = temp_file.name
 
 
 
 
 
353
 
354
+ return temp_file_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
 
356
+ # Create the Gradio interface
357
+ with gr.Blocks(title="Math Mento - Calculus Questions Generator") as demo:
358
+ gr.Markdown("# Math Mento - Calculus Questions Generator")
359
+ gr.Markdown("Generate LaTeX-formatted calculus practice questions with solutions based on James Stewart's calculus textbook")
360
+
361
+ with gr.Row():
362
+ with gr.Column():
363
+ topic = gr.Dropdown(
364
+ choices=list(TOPICS.keys()),
365
+ label="Calculus Topic",
366
+ value="Limits and Continuity"
367
+ )
368
+ difficulty = gr.Radio(
369
+ choices=["easy", "hard"],
370
+ label="Difficulty",
371
+ value="easy"
372
+ )
373
+ count = gr.Slider(
374
+ minimum=1,
375
+ maximum=10,
376
+ step=1,
377
+ value=3,
378
+ label="Number of Questions"
379
+ )
380
+ generate_button = gr.Button("Generate Questions")
381
+ export_button = gr.Button("Export to JSON")
382
+
383
+ with gr.Column():
384
+ output = gr.Markdown()
385
+ json_file = gr.File(label="Exported JSON")
386
+
387
+ generate_button.click(
388
+ generate_calculus_questions,
389
+ inputs=[topic, difficulty, count],
390
+ outputs=output
391
+ )
392
 
393
+ export_button.click(
394
+ export_to_json,
395
+ inputs=[],
396
+ outputs=json_file
397
+ )
398
 
399
+ gr.Markdown("### Created by Kamogelo Mosia | Math Mento © 2025")
 
 
 
400
 
401
+ # Launch the app
402
  if __name__ == "__main__":
403
+ demo.launch()
requirements.txt DELETED
@@ -1,2 +0,0 @@
1
- torch
2
- transformers