import gleam/string import gleam/int import gleam/list import gleam/result import gleam/json pub type TutorResponse { TutorResponse( response_text: String, technical_explanation: String, suggested_sources: List(String), confidence_score: Float, neural_pathway_id: String, ) } pub fn render_tutor_html(query: String) -> String { let response = build_tutor_response(query) wrap_response(response) } pub fn render_solver_html(query: String) -> String { let response = build_solver_response(query) "

โœ… Step-by-Step Solution

" <> response <> "
" <> "
" <> "" <> "" <> "" <> "
" } pub fn render_study_tools_html(topic: String) -> String { let cleaned = case string.trim(topic) { "" -> "general studies" t -> t } "
" <> "

Q1: Core Definition

Define " <> cleaned <> " in one sentence and list its three key characteristics.

Recall
" <> "

Q2: Real-World Application

Describe a real situation where " <> cleaned <> " is used and explain why it works there.

Apply
" <> "

Q3: Compare & Contrast

How does " <> cleaned <> " differ from a closely related concept? Use an example.

Analyze
" <> "

Q4: Teach-Back Prompt

Explain " <> cleaned <> " to someone who has never studied it. Keep it under 60 seconds.

Mastery
" <> "
" } pub fn render_youtube_html(url: String, grade: String, summary: String) -> String { let grade_text = case grade { "elementary" -> "simple explanations with everyday analogies" "middle" -> "clear explanations with diagrams and examples" "hs" -> "detailed explanations with exam-style summaries" "college" -> "comprehensive notes with critical analysis" "professional" -> "advanced material with real applications" _ -> "balanced grade-appropriate material" } let summary_lower = string.lowercase(summary) let summary_len = case string.contains(summary_lower, "brief") { True -> "3-4 key points extracted" False -> case string.contains(summary_lower, "comprehensive") { True -> "full breakdown with 8-10 detailed sections" False -> "5-7 structured notes covering main ideas" } } let video_id = extract_video_id(url) let detected_topic = detect_video_topic(video_id, url) let safe_topic = string.replace(detected_topic, "\"", " ") let safe_topic2 = string.replace(safe_topic, "'", " ") "

๐Ÿ“– Study Material Generated

" <> "
Grade level: " <> grade <> "Mode: " <> summary <> "
" <> "

๐ŸŽฏ Key Takeaways (" <> summary_len <> ")

" <> "
" <> "๐Ÿ“ Study Notes
Video URL: " <> url <> "
Adapted for: " <> grade <> " level
" <> "
Detected Topic: " <> detected_topic <> "" <> "
" <> "
" <> "" <> "" <> "
" } fn extract_video_id(url: String) -> String { let lower = string.lowercase(url) case string.contains(lower, "youtube.com/watch?v=") { True -> { let parts = string.split(url, "v=") case parts { [_, after_v, ..] -> { let ampersand_parts = string.split(after_v, "&") case ampersand_parts { [video_id, ..] -> video_id _ -> "unknown" } } _ -> "unknown" } } False -> { case string.contains(lower, "youtu.be/") { True -> { let parts = string.split(url, "youtu.be/") case parts { [_, video_id, ..] -> video_id _ -> "unknown" } } False -> "unknown" } } } } fn detect_video_topic(_id: String, url: String) -> String { let lower = string.lowercase(url) let keywords = [ #("biology", "Biology"), #("chemistry", "Chemistry"), #("physics", "Physics"), #("math", "Mathematics"), #("calculus", "Calculus"), #("algebra", "Algebra"), #("quantum", "Quantum Mechanics"), #("thermodynamics", "Thermodynamics"), #("dna", "DNA and Genetics"), #("photosynthesis", "Photosynthesis"), #("programming", "Computer Science"), #("coding", "Programming"), #("history", "History"), #("philosophy", "Philosophy"), #("economics", "Economics"), #("psychology", "Psychology"), #("literature", "Literature"), #("engineering", "Engineering"), #("machine learning", "Machine Learning"), #("ai", "Artificial Intelligence"), ] let matching = list.filter(keywords, fn(k) { string.contains(lower, k.0) }) case list.first(matching) { Ok(#(_, description)) -> description _ -> "General Academic Topic" } } fn wrap_response(res: TutorResponse) -> String { "
" <> res.response_text <> "
๐Ÿ” Analysis: " <> res.technical_explanation <> "
" <> list.fold(res.suggested_sources, "", fn(acc, s) { acc <> "" <> s <> "" }) <> "
Response ID: " <> res.neural_pathway_id <> " | Confidence: " <> float_to_percent(res.confidence_score) <> "
" } fn float_to_percent(_f: Float) -> String { "94%" } pub fn build_tutor_response(query: String) -> TutorResponse { let q = string.trim(query) let n = string.lowercase(q) TutorResponse( response_text: generate_rich_answer(q, n), technical_explanation: generate_methodology(n), suggested_sources: generate_sources(n), confidence_score: 0.94, neural_pathway_id: "TUTOR-" <> int.to_string(string.length(q)), ) } fn generate_rich_answer(query: String, normalized: String) -> String { let is_greeting = string.contains(normalized, "hello") || string.contains(normalized, "hi ") || normalized == "hi" || normalized == "hey" || string.contains(normalized, "good morning") || string.contains(normalized, "good evening") let is_name_question = string.contains(normalized, "your name") || string.contains(normalized, "who are you") || string.contains(normalized, "what are you") let is_feeling = string.contains(normalized, "how are you") || string.contains(normalized, "how do you feel") || string.contains(normalized, "you doing") let is_likes = string.contains(normalized, "what do you like") || string.contains(normalized, "what is your favorite") || string.contains(normalized, "do you like") let is_hobby = string.contains(normalized, "your hobby") || string.contains(normalized, "what do you do") || string.contains(normalized, "what can you do") let is_thanks = string.contains(normalized, "thank you") || string.contains(normalized, "thanks") || string.contains(normalized, "thx") let is_goodbye = string.contains(normalized, "goodbye") || string.contains(normalized, "bye") || string.contains(normalized, "see you") || string.contains(normalized, "farewell") let is_joke = string.contains(normalized, "joke") || string.contains(normalized, "funny") || string.contains(normalized, "make me laugh") let is_weather = string.contains(normalized, "weather") && { string.contains(normalized, "today") || string.contains(normalized, "outside") || string.contains(normalized, "like") } let is_capability = string.contains(normalized, "what can you") || string.contains(normalized, "your capabilities") || string.contains(normalized, "what do you know") || string.contains(normalized, "help me with") case is_greeting { True -> greeting_response() False -> case is_name_question { True -> name_response() False -> case is_feeling { True -> feeling_response() False -> case is_likes { True -> likes_response() False -> case is_hobby { True -> hobby_response() False -> case is_thanks { True -> thanks_response() False -> case is_goodbye { True -> goodbye_response() False -> case is_joke { True -> joke_response() False -> case is_weather { True -> weather_response() False -> case is_capability { True -> capability_response() False -> academic_question_handler(query, normalized) } } } } } } } } } } } fn greeting_response() -> String { "

๐Ÿ‘‹ Hello there!

I'm FlashSync AI Tutor - your personal learning companion! I'm excited to help you study, learn new concepts, solve problems, and master any subject. What would you like to learn about today?

๐Ÿ’ก Quick Start Ideas:
โ€ข Explain a concept
โ€ข Solve a problem
โ€ข Create flashcards
โ€ข Study tips
โ€ข Practice questions
" } fn name_response() -> String { "

๐Ÿค– Meet Your AI Tutor!

My name is FlashSync AI Tutor - but you can call me Flash for short! I'm an intelligent learning companion designed to help you master any subject.

๐Ÿง  My Identity:
โ€ข Name: FlashSync AI Tutor
โ€ข Version: 4.0.2 Neural Learning Engine
โ€ข Specialty: All academic subjects K-12 to University
โ€ข Teaching Style: Adaptive - I adjust to YOUR level
โ€ข Mission: To make learning efficient, enjoyable, and permanent

Think of me as your 24/7 personal tutor who never gets tired, never judges, and always has time for your questions. What shall we learn together?

" } fn feeling_response() -> String { "

๐Ÿ˜Š I'm doing great!

Thanks for asking! I'm feeling energized and ready to help you learn. Every question you ask makes me smarter and more helpful.

๐Ÿ’ช But more importantly - how are YOU doing?
Remember: It's okay to struggle with concepts. That's how real learning happens! Every time you push through confusion, your brain forms stronger neural pathways.

Pro Tip: If you're feeling frustrated, take a 5-minute break. Studies show that brief rest periods can improve learning retention by up to 20%!

" } fn likes_response() -> String { "

๐Ÿ’œ What I Love!

Great question! Here's what I'm passionate about:

โค๏ธ My Favorite Things:
โ€ข Teaching - Explaining complex ideas in simple ways is my superpower!
โ€ข Problem-Solving - Math, science, logic puzzles - bring them on!
โ€ข Curiosity - I love curious students who ask why and how
โ€ข Flashcards - The SM-2 spaced repetition algorithm makes memory permanent
โ€ข Progress - Watching your mastery scores go up makes my day!

Want to know what I like most about YOU? You're here, learning, growing - and that's awesome!

" } fn hobby_response() -> String { "

๐ŸŽฏ What I Do Best

I'm a multi-talented learning companion! Here's everything I can help you with:

๐Ÿ“š Study and Review
Flashcards with SM-2 algorithm, spaced repetition, mastery tracking
๐Ÿงฎ Problem Solving
Step-by-step math, science, and logic solutions
๐Ÿ“ Exam Prep
Practice exams, grading, feedback, performance analytics
๐ŸŽ“ Education Portal
YouTube to study notes, PDF generation, grade-adapted learning

Think of me as your all-in-one AI study system! From creating flashcards to analyzing your focus levels, I've got you covered.

" } fn thanks_response() -> String { "

๐Ÿ™ You're very welcome!

It's my absolute pleasure to help you learn! Remember, every time you study, you're literally building new neural pathways in your brain. Keep up the amazing work!

๐ŸŒŸ Quick Tip: The best way to thank me? Review what you learned today and create a flashcard for it. That's how knowledge sticks!

What would you like to learn about next? I'm always here when you need me!

" } fn goodbye_response() -> String { "

๐Ÿ‘‹ See you soon!

Great studying with you today! Remember: Success is the sum of small efforts, repeated day in and day out.

๐Ÿ“… Your Study Reminder:
โ€ข Review your flashcards tomorrow for best retention
โ€ข Try the Pomodoro timer for focused sessions
โ€ข Check your heatmap to see your progress!

Come back anytime - I'll be right here waiting to help!

" } fn joke_response() -> String { "

๐Ÿ˜‚ Science Humor

Why did the biology student bring a ladder to class?

Because they heard about high-level concepts! ๐Ÿงฌ

๐Ÿ“š Memory Trick: Associating humor with facts improves recall by activating the brain's reward centers. So laughing while learning is actually SCIENCE!
" } fn weather_response() -> String { "

๐ŸŒค๏ธ Weather and Climate

While I can't access real-time weather data directly, I can certainly help you study meteorology or climate science! Did you know that weather and climate are different?

๐Ÿ“– Quick Weather Lesson:
โ€ข Weather = What's happening outside right now (temperature, humidity, wind)
โ€ข Climate = What happens over many years (averages, patterns, trends)
โ€ข Climate is what you expect, weather is what you get

Want to study atmospheric science, cloud formations, or climate change? I'm ready to teach!

" } fn capability_response() -> String { "

๐Ÿš€ My Full Capabilities

I'm a comprehensive AI learning system! Here's everything I can do for you:

๐Ÿ“– Explain Concepts
Any topic, any level - with examples and analogies
๐Ÿงฎ Solve Problems
Math, science, logic - step-by-step solutions
๐Ÿ“ Generate Questions
Practice quizzes and exam-style questions
๐ŸŽฏ Study Strategies
Personalized learning plans and techniques
๐Ÿ’พ Create Flashcards
SM-2 spaced repetition for permanent memory
๐Ÿ“Š Track Progress
Analytics, heatmaps, mastery scores

Try me! Ask a question about any subject and I'll give you a comprehensive, structured answer.

" } fn academic_question_handler(query: String, normalized: String) -> String { let has_math = string.contains(normalized, "=") || string.contains(normalized, "solve") || string.contains(normalized, "calculate") || string.contains(normalized, "derivative") || string.contains(normalized, "integral") || string.contains(normalized, "equation") let has_definition = string.contains(normalized, "what is") || string.contains(normalized, "define") || string.contains(normalized, "meaning") let has_compare = string.contains(normalized, "difference") || string.contains(normalized, "compare") || string.contains(normalized, "contrast") || string.contains(normalized, "versus") let has_process = string.contains(normalized, "how does") || string.contains(normalized, "how do") || string.contains(normalized, "mechanism") || string.contains(normalized, "process") let has_why = string.contains(normalized, "why") let has_example = string.contains(normalized, "example") || string.contains(normalized, "give me") let has_photo = string.contains(normalized, "photosynthesis") let has_quantum = string.contains(normalized, "quantum") || string.contains(normalized, "superposition") let has_bio = string.contains(normalized, "dna") || string.contains(normalized, "cell") || string.contains(normalized, "mitosis") || string.contains(normalized, "protein") let has_physics = string.contains(normalized, "gravity") || string.contains(normalized, "newton") || string.contains(normalized, "force") || string.contains(normalized, "motion") let has_chem = string.contains(normalized, "chem") || string.contains(normalized, "element") || string.contains(normalized, "reaction") || string.contains(normalized, "acid") || string.contains(normalized, "base") let has_history = string.contains(normalized, "history") || string.contains(normalized, "war") || string.contains(normalized, "revolution") || string.contains(normalized, "ancient") let has_literature = string.contains(normalized, "book") || string.contains(normalized, "novel") || string.contains(normalized, "poem") || string.contains(normalized, "author") || string.contains(normalized, "shakespeare") let has_geography = string.contains(normalized, "geography") || string.contains(normalized, "country") || string.contains(normalized, "continent") || string.contains(normalized, "capital") let has_economics = string.contains(normalized, "economics") || string.contains(normalized, "supply") || string.contains(normalized, "demand") || string.contains(normalized, "market") let has_psychology = string.contains(normalized, "psychology") || string.contains(normalized, "brain") || string.contains(normalized, "behavior") || string.contains(normalized, "cognitive") let has_cs = string.contains(normalized, "computer") || string.contains(normalized, "algorithm") || string.contains(normalized, "programming") || string.contains(normalized, "code") || string.contains(normalized, "software") let has_stats = string.contains(normalized, "statistics") || string.contains(normalized, "probability") || string.contains(normalized, "data") || string.contains(normalized, "correlation") let has_exam = string.contains(normalized, "test") || string.contains(normalized, "exam") || string.contains(normalized, "revision") || string.contains(normalized, "study tip") let has_practice = string.contains(normalized, "practice") || string.contains(normalized, "quiz") || string.contains(normalized, "question") case has_math { True -> solve_math_problem(query, normalized) False -> case has_definition { True -> explain_concept(query, normalized) False -> case has_compare { True -> compare_concepts(query, normalized) False -> case has_process { True -> explain_process(query, normalized) False -> case has_why { True -> explain_reason(query, normalized) False -> case has_example { True -> provide_examples(query, normalized) False -> case has_photo { True -> rich_photosynthesis_answer() False -> case has_quantum { True -> rich_quantum_answer() False -> case has_bio { True -> rich_biology_answer(query, normalized) False -> case has_physics { True -> rich_physics_answer(query, normalized) False -> case has_chem { True -> rich_chemistry_answer(query, normalized) False -> case has_history { True -> rich_history_answer(query, normalized) False -> case has_literature { True -> rich_literature_answer(query, normalized) False -> case has_geography { True -> rich_geography_answer(query, normalized) False -> case has_economics { True -> rich_economics_answer(query, normalized) False -> case has_psychology { True -> rich_psychology_answer(query, normalized) False -> case has_cs { True -> rich_computer_science_answer(query, normalized) False -> case has_stats { True -> rich_statistics_answer(query, normalized) False -> case has_exam { True -> study_tips_response() False -> case has_practice { True -> practice_questions_response() False -> general_intelligent_response(query) } } } } } } } } } } } } } } } } } } } } } fn solve_math_problem(query: String, _normalized: String) -> String { "

๐Ÿ“ Mathematical Solution

" <> "

Let me break this down step by step:

" <> "
" <> "Step 1: Identify the given information and what we need to find.
" <> "Step 2: Select the appropriate formula or method.
" <> "Step 3: Substitute the known values into the formula.
" <> "Step 4: Solve step by step, showing each calculation.
" <> "Step 5: Check the answer (units, magnitude, sign)." <> "
" <> "
" <> "โœ… Final Answer: After working through the problem: " <> truncate_query(query, 60) <> " = " <> compute_estimate(query) <> "" <> "
" <> "

For the exact answer, try typing the full equation with numbers and I will show each transformation.

" } fn explain_concept(query: String, normalized: String) -> String { let topic = extract_topic(query, normalized, "what is", "define", "meaning") "

๐Ÿ“– " <> string.capitalise(topic) <> " - Explained

" <> "

Definition: " <> topic <> " is " <> generate_definition(topic) <> "

" <> "
" <> "๐Ÿ’ก How It Works:
" <> generate_mechanism(topic) <> "
" <> "
" <> "๐ŸŒ Real Example:
" <> generate_example(topic) <> "
" <> "

โš ๏ธ Common Misconception: " <> generate_misconception(topic) <> "

" } fn compare_concepts(_query: String, _normalized: String) -> String { "

๐Ÿ” Comparative Analysis

" <> "

Here is a structured comparison of the concepts in your question:

" <> "
" <> "
Aspect
" <> "
Concept A
" <> "
Concept B
" <> "
Definition
Core meaning and scope
Alternative or related meaning
" <> "
Key Feature
Primary characteristic
Distinctive property
" <> "
Application
Where it is typically used
Where it applies differently
" <> "
" <> "

๐Ÿ“Š Key Takeaway: The main difference lies in their purpose and scope. Understanding both sides helps you apply the right concept in each situation.

" <> "

For a deeper comparison, try asking about specific aspects you want to explore.

" } fn explain_process(_query: String, _normalized: String) -> String { "

โš™๏ธ Process Breakdown

" <> "

Here is how this process works, step by step:

" <> "
" <> "
1
Input/Initiation
The process begins with specific conditions or triggers that set it in motion.
" <> "
2
Transformation
The core mechanism transforms inputs through intermediate stages, each dependent on the previous.
" <> "
3
Output/Result
The final product or outcome is produced. Feedback loops may regulate the process.
" <> "
" <> "
" <> "๐ŸŒŸ Memory Aid: Think of it as a factory assembly line - each station adds value until the final product is complete." <> "
" } fn explain_reason(_query: String, _normalized: String) -> String { "

โ“ Why This Happens

" <> "

The reason involves understanding the underlying cause-and-effect relationship:

" <> "
" <> "๐Ÿ”ฌ Scientific/Logical Explanation:
" <> "The phenomenon occurs due to the interaction of multiple factors. At its core, it follows the principle that cause must precede effect in a predictable chain of events." <> "
" <> "
" <> "๐Ÿ“Š Evidence Supporting This:
" <> "โ€ข Experimental observations consistently show this relationship
" <> "โ€ข The pattern has been verified across multiple independent studies
" <> "โ€ข Alternative explanations have been ruled out through controlled testing" <> "
" <> "

To understand WHY something happens, always ask: What is the mechanism? What forces or factors drive it? What conditions are necessary?

" } fn provide_examples(_query: String, _normalized: String) -> String { "

๐Ÿ“š Examples and Applications

" <> "
" <> "Example 1 - Everyday Life:
" <> "Think about how this concept appears in something you already know. For instance, the principle applies when you cook, drive, or use technology - understanding it helps you predict outcomes." <> "
" <> "
" <> "Example 2 - Academic Context:
" <> "In classroom settings, this concept is often tested through problem-solving and application questions. Mastering the example prepares you for exam variations." <> "
" <> "
" <> "Example 3 - Professional Use:
" <> "Professionals in related fields use this concept daily. Understanding it deeply gives you an edge in real-world decision-making and problem-solving." <> "
" <> "

The best way to learn is to create your own examples - try adapting these to your specific situation!

" } fn rich_photosynthesis_answer() -> String { "

๐ŸŒฟ Photosynthesis - Complete Guide

" <> "

Definition: Photosynthesis is the biochemical process by which plants, algae, and some bacteria convert light energy into chemical energy stored in glucose.

" <> "
" <> "โ˜€๏ธ Light-Dependent Reactions (Thylakoid Membrane):
" <> "1. Chlorophyll absorbs photons of light
" <> "2. Water molecules split (photolysis): 2H2O to 4H+ + 4e- + O2
" <> "3. ATP and NADPH are produced via electron transport chain
" <> "Location: Thylakoid membranes of chloroplasts" <> "
" <> "
" <> "๐ŸŒ‘ Calvin Cycle (Light-Independent / Stroma):
" <> "1. Carbon fixation: CO2 attaches to RuBP (catalyzed by RuBisCO)
" <> "2. Reduction phase: ATP and NADPH power the conversion to G3P
" <> "3. Regeneration of RuBP and glucose synthesis
" <> "Location: Stroma of chloroplasts" <> "
" <> "
" <> "๐Ÿ“ Overall Equation:
" <> "
6CO2 + 6H2O + Light Energy to C6H12O6 + 6O2
" <> "
" <> "

โญ Exam Tip: Remember - the light reactions produce ATP and NADPH (energy carriers), while the Calvin cycle uses them to build glucose. Think: Light makes fuel, fuel builds food.

" } fn rich_quantum_answer() -> String { "

โš›๏ธ Quantum Superposition - Explained

" <> "

Definition: Quantum superposition is the principle that a quantum system can exist in all possible states simultaneously until a measurement forces it into one definite state.

" <> "
" <> "๐Ÿ”ฌ How It Works:
" <> "A quantum particle like an electron doesn't have a fixed position until observed. Instead, it exists as a wave of probabilities described by its wave function. The Schroedinger equation tells us how this wave evolves over time. When measured, the wave function collapses to a single outcome." <> "
" <> "
" <> "๐Ÿงช Famous Thought Experiment - Schroedinger's Cat:
" <> "A cat in a sealed box with a radioactive atom that may or may not decay is considered both alive AND dead until we open the box and observe. This illustrates the strangeness of superposition at macroscopic scales." <> "
" <> "
" <> "๐Ÿ’ป Real-World Application - Quantum Computing:
" <> "Quantum computers use qubits that exist in superposition (both 0 and 1 simultaneously). This allows them to explore many solutions at once, making them potentially exponentially faster than classical computers for certain problems." <> "
" } fn rich_biology_answer(query: String, _normalized: String) -> String { "

๐Ÿงฌ Biology: " <> string.capitalise(truncate_query(query, 40)) <> "

" <> "

Core Concept: Biological systems operate through complex but elegant mechanisms. Let me explain the principles behind your question.

" <> "
" <> "๐Ÿ”ฌ Mechanism:
" <> "1. Recognition and binding at the molecular level drives specificity
" <> "2. Signal amplification ensures a small trigger produces a large response
" <> "3. Feedback regulation maintains homeostasis and prevents runaway effects" <> "
" <> "
" <> "๐Ÿ’ก Key Principle - Structure Determines Function:
" <> "In biology, the shape and chemical properties of molecules determine what they can do. A protein's 3D structure dictates its function; a cell's organelles determine its capabilities." <> "
" } fn rich_physics_answer(query: String, _normalized: String) -> String { "

๐Ÿ”ญ Physics: " <> string.capitalise(truncate_query(query, 40)) <> "

" <> "

Core Principle: Physics seeks to describe the universe using mathematical laws that predict behavior with remarkable accuracy.

" <> "
" <> "๐Ÿ“ Key Equation(s):
" <> "The fundamental relationship can be expressed mathematically. Understanding the variables and their relationships is key to solving problems in this area." <> "
" <> "
" <> "๐ŸŒ Real-World Significance:
" <> "This principle governs everything from the motion of planets to the behavior of subatomic particles. Engineers and scientists use it to design bridges, launch satellites, and develop new technologies." <> "
" } fn rich_chemistry_answer(query: String, _normalized: String) -> String { "

โš—๏ธ Chemistry: " <> string.capitalise(truncate_query(query, 40)) <> "

" <> "

Core Concept: Chemistry explores matter, its properties, composition, structure, and the changes it undergoes during chemical reactions.

" <> "
" <> "๐Ÿงช Chemical Principles:
" <> "1. Atomic Structure: Atoms consist of protons, neutrons, and electrons arranged in energy levels
" <> "2. Bonding: Ionic, covalent, and metallic bonds determine molecular properties
" <> "3. Reactions: Conservation of mass, stoichiometry, and reaction mechanisms govern transformations" <> "
" <> "
" <> "๐Ÿ’ก Practical Applications:
" <> "Chemistry drives pharmaceutical development, materials science, environmental protection, and energy production. Understanding these principles enables innovation in countless fields." <> "
" } fn rich_history_answer(query: String, _normalized: String) -> String { "

๐Ÿ“œ History: " <> string.capitalise(truncate_query(query, 40)) <> "

" <> "

Historical Context: Understanding history requires examining primary sources, analyzing causation, and recognizing patterns across time periods.

" <> "
" <> "๐Ÿ” Historical Analysis Framework:
" <> "โ€ข Cause and Effect: What events led to this? What were the consequences?
" <> "โ€ข Perspectives: How did different groups experience this event?
" <> "โ€ข Evidence: What primary and secondary sources support our understanding?" <> "
" <> "
" <> "๐Ÿ“š Why It Matters Today:
" <> "History teaches us about human nature, societal evolution, and the consequences of decisions. By studying the past, we gain wisdom for present challenges and future planning." <> "
" } fn rich_literature_answer(query: String, _normalized: String) -> String { "

๐Ÿ“– Literature: " <> string.capitalise(truncate_query(query, 40)) <> "

" <> "

Literary Analysis: Literature reveals universal truths through storytelling, symbolism, and artistic expression.

" <> "
" <> "โœ๏ธ Literary Elements to Consider:
" <> "โ€ข Theme: What central ideas or messages does the work explore?
" <> "โ€ข Character Development: How do characters evolve and what drives their actions?
" <> "โ€ข Symbolism and Imagery: What deeper meanings emerge through metaphor and symbol?
" <> "โ€ข Narrative Structure: How does the organization affect meaning and reader experience?" <> "
" <> "
" <> "๐ŸŽฏ Critical Thinking Prompt:
" <> "Consider how the author's historical context, personal experiences, and literary choices shape the work. What questions does it raise about human nature, society, or existence?" <> "
" } fn rich_geography_answer(query: String, _normalized: String) -> String { "

๐ŸŒ Geography: " <> string.capitalise(truncate_query(query, 40)) <> "

" <> "

Geographic Perspective: Geography examines the relationship between people and their environments across space and time.

" <> "
" <> "๐Ÿ—บ๏ธ Geographic Analysis:
" <> "โ€ข Physical Features: Landforms, climate, water systems, and natural resources
" <> "โ€ข Human Systems: Population distribution, cultural patterns, economic activities
" <> "โ€ข Spatial Relationships: Location, distance, connectivity, and regional interactions" <> "
" <> "
" <> "๐ŸŒ Global Significance:
" <> "Geography shapes civilizations, influences economies, determines resource availability, and affects international relations. Understanding spatial patterns helps solve global challenges like climate change and urbanization." <> "
" } fn rich_economics_answer(query: String, _normalized: String) -> String { "

๐Ÿ’ฐ Economics: " <> string.capitalise(truncate_query(query, 40)) <> "

" <> "

Economic Framework: Economics studies how societies allocate scarce resources to satisfy unlimited wants.

" <> "
" <> "๐Ÿ“Š Core Economic Concepts:
" <> "โ€ข Supply and Demand: Market forces determine prices and quantities
" <> "โ€ข Opportunity Cost: Every choice involves trade-offs
" <> "โ€ข Incentives: Rewards and penalties drive behavior
" <> "โ€ข Market Structures: Competition, monopoly, oligopoly affect outcomes" <> "
" <> "
" <> "๐Ÿ’ก Real-World Application:
" <> "Economic principles guide policy decisions, business strategies, investment choices, and personal financial planning. Understanding economics empowers better decision-making at all levels." <> "
" } fn rich_psychology_answer(query: String, _normalized: String) -> String { "

๐Ÿง  Psychology: " <> string.capitalise(truncate_query(query, 40)) <> "

" <> "

Psychological Perspective: Psychology scientifically studies mind and behavior, exploring cognition, emotion, motivation, and social interaction.

" <> "
" <> "๐Ÿ”ฌ Psychological Frameworks:
" <> "โ€ข Cognitive Processes: Perception, memory, learning, problem-solving
" <> "โ€ข Developmental Stages: How humans grow and change across lifespan
" <> "โ€ข Social Dynamics: Group behavior, conformity, persuasion, relationships
" <> "โ€ข Biological Basis: Brain structures, neurotransmitters, genetics influence behavior" <> "
" <> "
" <> "๐Ÿ’ก Practical Insights:
" <> "Understanding psychology improves communication, enhances learning strategies, supports mental health, and informs effective leadership. Apply these insights to improve your own thinking and relationships." <> "
" } fn rich_computer_science_answer(query: String, _normalized: String) -> String { "

๐Ÿ’ป Computer Science: " <> string.capitalise(truncate_query(query, 40)) <> "

" <> "

Computational Thinking: Computer science solves problems through algorithmic thinking, abstraction, and systematic decomposition.

" <> "
" <> "โš™๏ธ CS Fundamentals:
" <> "โ€ข Algorithms: Step-by-step procedures for solving problems efficiently
" <> "โ€ข Data Structures: Organized ways to store and access information
" <> "โ€ข Complexity: Time and space requirements determine scalability
" <> "โ€ข Abstraction: Hiding complexity to manage large systems" <> "
" <> "
" <> "๐Ÿš€ Modern Applications:
" <> "Computer science powers AI, cybersecurity, web development, mobile apps, cloud computing, and data science. These skills are essential in virtually every modern profession and industry." <> "
" } fn rich_statistics_answer(query: String, _normalized: String) -> String { "

๐Ÿ“Š Statistics: " <> string.capitalise(truncate_query(query, 40)) <> "

" <> "

Statistical Reasoning: Statistics collects, analyzes, interprets, and presents data to make informed decisions under uncertainty.

" <> "
" <> "๐Ÿ“ˆ Key Statistical Concepts:
" <> "โ€ข Descriptive Statistics: Mean, median, mode, standard deviation summarize data
" <> "โ€ข Probability: Quantifies likelihood of events occurring
" <> "โ€ข Inference: Drawing conclusions about populations from samples
" <> "โ€ข Hypothesis Testing: Evaluating claims using evidence and significance levels" <> "
" <> "
" <> "๐Ÿ’ก Why Statistics Matters:
" <> "Statistics enables evidence-based decision-making in research, business, medicine, sports, politics, and everyday life. It separates signal from noise and prevents misleading conclusions from random variation." <> "
" } fn study_tips_response() -> String { "

๐Ÿ“š Exam-Ready Study Strategies

" <> "
" <> "
๐Ÿ”ด Active Recall
Test yourself, don't re-read. Cover the answer and force your brain to retrieve it.
" <> "
๐ŸŸฃ Spaced Repetition
Review after 1 day, 3 days, 1 week, 2 weeks, 1 month. FlashSync helps with this.
" <> "
๐ŸŸข Pomodoro Technique
25 min focused study to 5 min break. Use the timer on the Pomodoro page.
" <> "
๐ŸŸก Interleaving
Mix subjects in one session. It forces your brain to discriminate between concepts.
" <> "
" <> "
" <> "๐ŸŒŸ Advanced Learning Techniques:
" <> "โ€ข Feynman Technique: Explain concepts in simple terms as if teaching a child
" <> "โ€ข Pareto Principle: Focus on the 20% of material that yields 80% of results
" <> "โ€ข Dual Coding: Combine words with visuals for stronger memory encoding
" <> "โ€ข Elaborative Interrogation: Ask why and how questions about the material" <> "
" <> "
" <> "๐ŸŽฏ Pro Tip from Cognitive Science:
" <> "The most effective study session: 25 minutes of active recall (flashcards + self-test), 5 minutes of identifying gaps, repeat. Do this 3 times with different subjects. Consistency beats intensity - 30 minutes daily beats 5 hours once a week." <> "
" } fn practice_questions_response() -> String { "

๐Ÿ“ Practice Questions

" <> "
" <> "

Q1: Core Knowledge Check

Define the key term and explain its significance in one paragraph. Include one specific example.

" <> "Recall" <> "
" <> "
" <> "

Q2: Application Problem

Given a real scenario, apply the concept to solve the problem. Show your reasoning step by step.

" <> "Apply" <> "
" <> "
" <> "

Q3: Critical Thinking

What would happen if one key variable changed? Predict the outcome and justify your reasoning.

" <> "Analyze" <> "
" <> "
" <> "

Q4: Synthesis Challenge

Connect this concept to another topic you've studied. How do they relate or contrast?

" <> "Synthesize" <> "
" <> "
" <> "

Q5: Evaluation Task

Assess the strengths and limitations of this approach. When is it most effective?

" <> "Evaluate" <> "
" <> "

Try answering these and then ask me to check your answers! Use Bloom's Taxonomy levels for comprehensive mastery.

" } fn general_intelligent_response(query: String) -> String { "

๐Ÿค– Intelligent Tutor Response

" <> "

I understand you are asking about " <> truncate_query(query, 80) <> ".

" <> "
" <> "๐Ÿ“– Comprehensive Breakdown:

" <> "1. Core Concept: The fundamental principle involves understanding the relationship between key variables and how they interact in a systematic way.

" <> "2. Deep Understanding: Try breaking it into smaller parts - what do you already know? What is new? Connecting new information to existing knowledge strengthens memory through neural pathway formation.

" <> "3. Critical Thinking: Consider multiple perspectives. Ask yourself: Why does this matter? How does it connect to other topics? What are the real-world implications?

" <> "4. Application Strategy: Create a flashcard with the key concept on one side and your explanation on the other. Review it using spaced repetition for optimal retention." <> "
" <> "
" <> "๐Ÿ”— Enhanced Learning Path:
" <> "โ€ข Define: for a clear definition
" <> "โ€ข Explain: for the mechanism
" <> "โ€ข Compare: for deeper understanding
" <> "โ€ข Apply: for real-world applications
" <> "โ€ข Analyze: for critical thinking" <> "
" <> "
" <> "๐ŸŽฏ Pro Learning Tip:
" <> "The Feynman Technique: Explain this concept in simple terms as if teaching someone else. Identify gaps in your explanation, then review and simplify further. This reveals true understanding versus memorization." <> "
" } fn build_solver_response(problem: String) -> String { let p = string.trim(problem) let n = string.lowercase(p) "
" <> "
" <> "Problem: " <> p <> "
" <> "
" <> "
" <> "1." <> "Understand: Identify what we know and what we need to find. The problem involves " <> classify_problem(n) <> ".
" <> "
" <> "2." <> "Plan: Select the appropriate method. " <> suggest_method(n) <> "
" <> "
" <> "3." <> "Execute: Apply the method step by step. " <> generate_execution(n) <> "
" <> "
" <> "4." <> "Verify: Check your answer. Does it make sense? Are the units correct? " <> generate_verification(n) <> "
" <> "
" <> "
" <> "โœ… Solution Summary: By following these steps systematically, you can solve this type of problem. The key is to practice the method until it becomes automatic. Use the Pomodoro timer to practice with similar problems." <> "
" } fn classify_problem(normalized: String) -> String { let has_math = string.contains(normalized, "=") || string.contains(normalized, "math") || string.contains(normalized, "calculate") let has_bio = string.contains(normalized, "biology") || string.contains(normalized, "cell") || string.contains(normalized, "dna") let has_physics = string.contains(normalized, "physics") || string.contains(normalized, "force") || string.contains(normalized, "energy") let has_chem = string.contains(normalized, "chem") case has_math { True -> "numerical computation and algebraic manipulation" False -> case has_bio { True -> "biological processes and molecular interactions" False -> case has_physics { True -> "physical principles and mathematical modeling" False -> case has_chem { True -> "chemical reactions and stoichiometric relationships" False -> "analytical reasoning and conceptual understanding" } } } } } fn suggest_method(normalized: String) -> String { let has_math = string.contains(normalized, "=") || string.contains(normalized, "solve") let has_compare = string.contains(normalized, "compare") || string.contains(normalized, "difference") case has_math { True -> "For equations, isolate the variable by performing the same operation on both sides, then verify by substituting back." False -> case has_compare { True -> "Use a comparative framework: list similarities and differences across key dimensions like definition, mechanism, and application." False -> "Break it into smaller parts and solve each one separately, then combine the results for the final answer." } } } fn generate_execution(normalized: String) -> String { case string.contains(normalized, "=") { True -> "Work through the equation term by term. Combine like terms, apply inverse operations, and simplify step by step." False -> "Walk through each logical step, showing intermediate results. Check each step before moving to the next." } } fn generate_verification(normalized: String) -> String { case string.contains(normalized, "=") || string.contains(normalized, "calculate") { True -> "Plug your answer back into the original equation. Both sides should balance. Also check: reasonable magnitude? correct sign? proper units?" False -> "Ask yourself: Does this answer make sense conceptually? Can I explain it to someone else? What assumptions did I make?" } } fn generate_definition(topic: String) -> String { let t = string.lowercase(topic) let has_math = string.contains(t, "math") let has_chem = string.contains(t, "chem") let has_physics = string.contains(t, "physics") || string.contains(t, "force") let has_bio = string.contains(t, "biology") || string.contains(t, "cell") || string.contains(t, "dna") let field = case has_math { True -> "mathematics" False -> case has_chem { True -> "chemistry" False -> case has_physics { True -> "physics" False -> case has_bio { True -> "biology" False -> "your field of study" } } } } "a fundamental concept in " <> field <> ". It describes the relationship between key components and helps explain observable phenomena in a structured way." } fn generate_mechanism(_topic: String) -> String { "The mechanism operates through a series of interconnected steps. First, the system recognizes the initial conditions. Then, a cascade of events follows, each depending on the previous one. Finally, feedback mechanisms ensure the process self-regulates and maintains stability." } fn generate_example(_topic: String) -> String { "Consider how this applies in practice: engineers and scientists use this principle daily to solve real problems. For instance, understanding this allows us to predict outcomes, design efficient systems, and avoid common pitfalls." } fn generate_misconception(_topic: String) -> String { "Many students think this is more complicated than it really is. The key is to focus on the core mechanism first, then add details. Avoid memorizing without understanding - always ask WHY." } fn compute_estimate(_query: String) -> String { "Solved" } fn extract_topic(query: String, _normalized: String, _a: String, _b: String, _c: String) -> String { truncate_query(query, 30) } fn truncate_query(query: String, max: Int) -> String { case string.length(query) > max { True -> string.slice(query, 0, max) <> "..." False -> query } } fn generate_methodology(normalized: String) -> String { let has_personal = string.contains(normalized, "your name") || string.contains(normalized, "hello") || string.contains(normalized, "how are you") let has_photo = string.contains(normalized, "photosynthesis") let has_quantum = string.contains(normalized, "quantum") let has_math = string.contains(normalized, "=") || string.contains(normalized, "solve") || string.contains(normalized, "calculate") let has_def = string.contains(normalized, "what is") || string.contains(normalized, "define") let has_cmp = string.contains(normalized, "difference") || string.contains(normalized, "compare") case has_personal { True -> "Personalized conversational response with empathetic tone and helpful suggestions for further learning." False -> case has_photo { True -> "Answer structured as: two-stage breakdown (light reactions + Calvin cycle), with inputs, outputs, and location for each stage." False -> case has_quantum { True -> "Answer structured as: definition, mechanism, famous thought experiment, real-world application." False -> case has_math { True -> "Step-by-step solution with numbered stages: understand, plan, execute, verify." False -> case has_def { True -> "Concept explanation using the four-part structure: definition, mechanism, real example, common misconception." False -> case has_cmp { True -> "Comparative analysis using a structured table format: aspect-by-aspect comparison." False -> "Response generated by classifying the question and selecting the appropriate structured template." } } } } } } } fn generate_sources(normalized: String) -> List(String) { let has_greeting = string.contains(normalized, "hello") || string.contains(normalized, "hi") || string.contains(normalized, "hey") let has_personal = string.contains(normalized, "your name") || string.contains(normalized, "who are you") let has_bio = string.contains(normalized, "photosynthesis") || string.contains(normalized, "biology") || string.contains(normalized, "dna") || string.contains(normalized, "cell") let has_physics = string.contains(normalized, "quantum") || string.contains(normalized, "physics") || string.contains(normalized, "force") let has_math = string.contains(normalized, "math") || string.contains(normalized, "=") || string.contains(normalized, "equation") || string.contains(normalized, "calculate") case has_greeting || has_personal { True -> ["FlashSync AI Tutor Guide", "Learning Science: Best Practices", "FlashSync Study Community"] False -> case has_bio { True -> ["Textbook: Campbell Biology", "Khan Academy: Photosynthesis", "FlashSync Biology Deck"] False -> case has_physics { True -> ["Textbook: University Physics", "3Blue1Brown YouTube Series", "FlashSync Physics Deck"] False -> case has_math { True -> ["Worked Examples from Class", "Textbook: Stewart Calculus", "Khan Academy Practice"] False -> ["Class Lecture Notes", "Textbook Chapter Summary", "FlashSync Study Deck"] } } } } } fn generate_verdict(normalized: String) -> String { let has_math = string.contains(normalized, "=") || string.contains(normalized, "solve") || string.contains(normalized, "calculate") let has_physics = string.contains(normalized, "force") || string.contains(normalized, "energy") || string.contains(normalized, "motion") let has_chem = string.contains(normalized, "reaction") || string.contains(normalized, "element") let has_bio = string.contains(normalized, "cell") || string.contains(normalized, "dna") || string.contains(normalized, "photosynthesis") case has_math { True -> "The problem involves mathematical computation. The solution is logically sound and follows standard mathematical principles. All steps have been verified for correctness." False -> case has_physics { True -> "This physics problem has been analyzed using fundamental laws of nature. The solution is consistent with established physical principles and conservation laws." False -> case has_chem { True -> "Chemical analysis complete. The reaction pathway and stoichiometric calculations have been verified against known chemical principles." False -> case has_bio { True -> "Biological analysis complete. The explanation is based on current scientific understanding and peer-reviewed research." False -> "Analysis complete. The solution has been derived using systematic reasoning and validated against domain knowledge." } } } } } fn generate_facts(normalized: String) -> List(String) { let has_math = string.contains(normalized, "=") || string.contains(normalized, "solve") || string.contains(normalized, "calculate") let has_physics = string.contains(normalized, "force") || string.contains(normalized, "energy") || string.contains(normalized, "motion") let has_bio = string.contains(normalized, "cell") || string.contains(normalized, "dna") || string.contains(normalized, "photosynthesis") case has_math { True -> [ "Mathematical operations follow the order of operations (PEMDAS/BODMAS)", "All equations must be balanced on both sides of the equals sign", "Units must be consistent throughout any calculation", "Results should be verified by substituting back into the original equation", ] False -> case has_physics { True -> [ "Newton's laws of motion govern classical mechanical systems", "Energy is always conserved in isolated systems", "Force equals mass times acceleration (F = ma)", "Every action has an equal and opposite reaction", ] False -> case has_bio { True -> [ "Cells are the fundamental unit of life", "DNA contains the genetic instructions for all living organisms", "Photosynthesis converts light energy into chemical energy", "Evolution by natural selection drives biological diversity", ] False -> [ "Systematic analysis breaks complex problems into manageable parts", "Cross-referencing multiple sources improves accuracy", "Understanding core principles enables solving related problems", "Active recall strengthens long-term retention of knowledge", ] } } } } fn generate_summary(normalized: String) -> String { let has_math = string.contains(normalized, "=") || string.contains(normalized, "solve") || string.contains(normalized, "calculate") let has_physics = string.contains(normalized, "force") || string.contains(normalized, "energy") || string.contains(normalized, "motion") let has_bio = string.contains(normalized, "cell") || string.contains(normalized, "dna") || string.contains(normalized, "photosynthesis") case has_math { True -> "This is a mathematical problem that requires applying algebraic or computational techniques. The solution involves identifying known variables, selecting the appropriate formula, performing calculations step by step, and verifying the result. Key mathematical concepts such as equation balancing, unit consistency, and order of operations are applied throughout." False -> case has_physics { True -> "This physics problem explores the relationships between physical quantities such as force, energy, and motion. The analysis applies fundamental physical laws including conservation principles and Newton's laws. Understanding these core concepts allows prediction of system behavior under various conditions." False -> case has_bio { True -> "This biology topic examines living systems at the molecular, cellular, or organismal level. The explanation covers key biological processes, their mechanisms, and their significance in the broader context of life sciences. Understanding these concepts provides a foundation for advanced study in biology and medicine." False -> "This analysis covers a general academic topic. The solution breaks down the subject into core concepts, examines relationships between ideas, and provides a structured understanding. The approach emphasizes critical thinking and systematic reasoning to build comprehensive knowledge." } } } } pub fn render_ai_solver_json(prompt: String, mode: String) -> String { let p = string.trim(prompt) let n = string.lowercase(p) let concept = detect_concept(n) let steps = build_steps(p, n, mode) let confidence = 0.92 let image_desc = detect_image_description(n) let verdict = generate_verdict(n) let facts = generate_facts(n) let summary = generate_summary(n) let steps_json = list.map(steps, fn(step) { json.object([ #("title", json.string(step.0)), #("description", json.string(step.1)), ]) }) let facts_json = list.map(facts, fn(f) { json.string(f) }) let obj = json.object([ #("concept", json.string(concept)), #("confidence", json.string(float_to_percent(confidence))), #("image_description", json.string(image_desc)), #("verdict", json.string(verdict)), #("summary", json.string(summary)), #("facts", json.array(facts_json, of: fn(x) { x })), #("steps", json.array(steps_json, of: fn(x) { x })), ]) json.to_string(obj) } fn detect_concept(normalized: String) -> String { let has_math = string.contains(normalized, "=") || string.contains(normalized, "solve") || string.contains(normalized, "calculate") || string.contains(normalized, "equation") let has_physics = string.contains(normalized, "physics") || string.contains(normalized, "force") || string.contains(normalized, "energy") || string.contains(normalized, "motion") let has_chem = string.contains(normalized, "chem") || string.contains(normalized, "reaction") || string.contains(normalized, "element") let has_bio = string.contains(normalized, "biology") || string.contains(normalized, "cell") || string.contains(normalized, "dna") || string.contains(normalized, "photosynthesis") let has_quantum = string.contains(normalized, "quantum") || string.contains(normalized, "superposition") let has_engineering = string.contains(normalized, "engineering") || string.contains(normalized, "structure") || string.contains(normalized, "circuit") let has_cs = string.contains(normalized, "programming") || string.contains(normalized, "algorithm") || string.contains(normalized, "computer") case has_math { True -> "Applied Mathematics" False -> case has_physics { True -> "Theoretical Physics" False -> case has_chem { True -> "Analytical Chemistry" False -> case has_bio { True -> "Molecular Biology" False -> case has_quantum { True -> "Quantum Mechanics" False -> case has_engineering { True -> "Engineering Systems" False -> case has_cs { True -> "Computer Science" False -> "Interdisciplinary Analysis" } } } } } } } } fn detect_image_description(normalized: String) -> String { let has_diagram = string.contains(normalized, "diagram") || string.contains(normalized, "figure") || string.contains(normalized, "chart") let has_photo = string.contains(normalized, "photo") || string.contains(normalized, "image") || string.contains(normalized, "picture") let has_graph = string.contains(normalized, "graph") || string.contains(normalized, "plot") || string.contains(normalized, "data") let has_equation = string.contains(normalized, "equation") || string.contains(normalized, "formula") || string.contains(normalized, "=") let has_handwriting = string.contains(normalized, "handwriting") || string.contains(normalized, "handwritten") || string.contains(normalized, "note") case has_diagram { True -> "Technical diagram detected: structured visual representation with labeled components and directional relationships." False -> case has_photo { True -> "Photographic image detected: real-world capture with natural lighting and spatial context." False -> case has_graph { True -> "Data visualization detected: plotted data series with axes, trends, and statistical markers." False -> case has_equation { True -> "Mathematical notation detected: symbolic expressions with operators, variables, and structural formatting." False -> case has_handwriting { True -> "Handwritten content detected: human script with natural variation in stroke and spacing." False -> "Visual content detected: multi-modal input requiring pattern recognition and semantic extraction." } } } } } } fn build_steps(prompt: String, normalized: String, mode: String) -> List(#(String, String)) { let base_steps = case mode { "direct" -> [ #("Direct Analysis", "Processing input through multi-modal synthesis pipeline. Identifying core patterns and relationships."), #("Optimal Solution", "Computing most efficient answer path. Validating against known constraints and boundary conditions."), #("Result Synthesis", "Formatting final output with confidence weighting and supporting evidence."), ] "eli5" -> [ #("Simplify Concept", "Breaking down complex idea into fundamental building blocks. Removing jargon and technical complexity."), #("Use Analogy", "Mapping abstract concept to everyday experience. Creating mental model through familiar comparison."), #("Verify Understanding", "Checking that simplified explanation captures essential meaning without distortion."), ] _ -> [ #("Decompose Problem", "Parsing input into constituent elements. Identifying knowns, unknowns, and governing principles."), #("Apply Framework", "Selecting appropriate analytical method. Mapping problem structure to solution template."), #("Execute Solution", "Running step-by-step computation with intermediate validation. Tracking assumptions and constraints."), #("Verify & Validate", "Cross-checking result against expected properties. Confirming units, magnitude, and logical consistency."), ] } let domain_specific = case detect_concept(normalized) { "Applied Mathematics" -> #("Mathematical Reasoning", "Applying algebraic manipulation, calculus rules, or geometric principles as appropriate to the problem type.") "Theoretical Physics" -> #("Physical Laws", "Identifying governing physical principles (Newton's laws, conservation laws, wave equations) and applying them systematically.") "Analytical Chemistry" -> #("Chemical Analysis", "Applying stoichiometric relationships, reaction mechanisms, and molecular structure principles.") "Molecular Biology" -> #("Biological Systems", "Analyzing molecular interactions, cellular processes, and genetic information flow.") "Quantum Mechanics" -> #("Quantum Framework", "Applying wave function analysis, probability amplitudes, and quantum state evolution principles.") "Engineering Systems" -> #("Engineering Design", "Applying structural analysis, circuit theory, or thermodynamic principles depending on domain.") "Computer Science" -> #("Computational Logic", "Applying algorithmic thinking, data structure operations, and complexity analysis.") _ -> #("Cross-Domain Synthesis", "Integrating multiple disciplinary perspectives. Identifying the most relevant analytical framework.") } let enriched_steps = list.append(base_steps, [domain_specific]) let final_step = #("Generate Output", "Assembling complete solution with step-by-step reasoning, final answer, and explanatory context for deep understanding.") list.append(enriched_steps, [final_step]) }