# CLAUDE.md This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. ## Project Overview This is a Gradio-based engineering calculator web application that provides multiple calculator modes with advanced functionality. The application serves as a comprehensive calculation tool for engineers, scientists, and developers. ## Application Architecture ### Core Modes - **Standard Mode**: Basic calculator operations with immediate evaluation - **Scientific Mode**: Scientific functions including trigonometry, logarithms, and advanced mathematical operations - **Engineering Mode**: Specialized engineering calculations with dropdown-based function selection - **Programming Mode**: Developer-focused calculations including base conversions and scripting capabilities ### Key Features - Infinite precision arithmetic for basic operations (addition, subtraction, multiplication, division) - Calculation history and memory capabilities - Embedded AI chat interface - Unit converters for various measurements and currencies - Real-time calculation evaluation ### Engineering Functions The engineering mode includes specialized calculations such as: - **3Ph Equivalent Impedance Calculator**: Calculates equivalent impedance and line currents for 5-wire (A,B,C,N,PE) electrical systems using Carson's equations and Kron reduction ## Development Setup ### Dependencies The project requires the following Python packages: - `gradio` - Web interface framework - `numpy` - Numerical computations - `pandas` - Data analysis and manipulation - `matplotlib` - Plotting and visualization - `seaborn` - Statistical visualization ### Installation Commands ```bash pip install gradio numpy pandas matplotlib seaborn ``` ### Running the Application ```bash python app.py # Main application file (to be created) ``` ## Code Structure ### Mathematical Operations - Implement infinite precision arithmetic using Python's `decimal` module for basic operations - Use `numpy` for complex mathematical functions and matrix operations - All trigonometric functions should support both degrees and radians ### Engineering Calculations - The 3Ph Impedance calculator implementation is provided in `app.txt` lines 54-451 - Uses modified Carson's equations for earth return impedance calculations - Implements Kron reduction technique for 5-wire to 3-wire system conversion - Required classes: `PowerSystemImpedanceCalculator`, `ConductorParams`, `Coordinate` ### UI Components - Main calculator interface with mode selection - Button layouts for different calculator modes - Text input/output areas for programming mode - Dropdown selection for engineering functions - History panel for calculation tracking - Embedded chat interface for AI assistance ## Testing and Validation ### Testing Commands ```bash python -m pytest tests/ # Run test suite (when created) python test_calculations.py # Test mathematical accuracy ``` ### Validation Requirements - All basic arithmetic operations must maintain infinite precision - Scientific functions should match standard calculator behavior - Engineering calculations must be validated against known engineering standards - UI responsiveness across different screen sizes ## Development Guidelines ### File Organization - `app.py` - Main Gradio application - `calculator/` - Calculator logic modules - `engineering/` - Engineering calculation implementations - `tests/` - Test files - `static/` - CSS and JavaScript assets ### Key Implementation Notes - Use Gradio's `gr.Interface` or `gr.Blocks` for the main application structure - Implement state management for calculation history and memory - Ensure all engineering calculations follow IEEE standards - Maintain separation between UI logic and calculation logic ### Scientific Function Requirements All scientific functions from app.txt lines 24-47 must be implemented: - Trigonometric: sin, cos, tan, asin, acos, atan - Reciprocal trigonometric: csc, sec, cot - Support for imaginary unit (i/j notation for electrical engineering) - Factorial calculations for positive integers ## Performance Considerations - Implement caching for complex engineering calculations - Use efficient algorithms for matrix operations in impedance calculations - Optimize UI updates for real-time calculation display