{"id":25573110,"url":"https://github.com/jeffasante/mathexpr","last_synced_at":"2025-08-18T11:05:46.899Z","repository":{"id":277761708,"uuid":"933413292","full_name":"jeffasante/mathexpr","owner":"jeffasante","description":"A simple, functional Rust library for parsing and evaluating mathematical expressions.","archived":false,"fork":false,"pushed_at":"2025-02-15T22:33:38.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-01T16:47:53.554Z","etag":null,"topics":["math-engine","parsing-and-tokenization"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jeffasante.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-15T22:19:55.000Z","updated_at":"2025-02-15T23:01:18.000Z","dependencies_parsed_at":"2025-02-15T23:25:25.158Z","dependency_job_id":"67adf84e-705c-4966-b6b8-56eee4ce580c","html_url":"https://github.com/jeffasante/mathexpr","commit_stats":null,"previous_names":["jeffasante/mathexpr"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jeffasante/mathexpr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffasante%2Fmathexpr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffasante%2Fmathexpr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffasante%2Fmathexpr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffasante%2Fmathexpr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeffasante","download_url":"https://codeload.github.com/jeffasante/mathexpr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffasante%2Fmathexpr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270982194,"owners_count":24679447,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["math-engine","parsing-and-tokenization"],"created_at":"2025-02-21T01:20:04.161Z","updated_at":"2025-08-18T11:05:46.837Z","avatar_url":"https://github.com/jeffasante.png","language":"Rust","readme":"# MathExpr - Mathematical Expression Calculator in Rust\n\nA Rust library and command-line tool that parses and evaluates mathematical expressions. It handles basic arithmetic operations, scientific notation, and complex expressions with proper operator precedence.\n\n## Architecture\n\n```mermaid \n    graph TD\n    subgraph DataFlow\n        A[Input String] --\u003e B[Tokenizer]\n        B --\u003e C[Token Stream]\n        C --\u003e D[Parser]\n        D --\u003e E[AST]\n        E --\u003e F[Expression Tree]\n        F --\u003e G[Evaluator]\n        G --\u003e H[Result]\n    end\n\n    subgraph Components\n        Token[Token]\n        Op[Op]\n        Expr[Expr]\n        TokenStream[TokenStream]\n        Parser[Parser]\n        Evaluator[Evaluator]\n        Error[Error]\n    end\n\n    subgraph TokenDef[Token Types]\n        Token --- Number[Number]\n        Token --- Operator[Operator]\n        Token --- LParen[LParen]\n        Token --- RParen[RParen]\n        Token --- Scientific[Scientific]\n    end\n\n    subgraph OpDef[Operators]\n        Op --- Add[Add]\n        Op --- Sub[Subtract]\n        Op --- Mul[Multiply]\n        Op --- Div[Divide]\n        Op --- Pow[Power]\n    end\n\n    subgraph ExprDef[Expression Types]\n        Expr --- Literal[Literal]\n        Expr --- BinOp[BinOp]\n        Expr --- UnaryMinus[UnaryMinus]\n        Expr --- SciExpr[Scientific]\n    end\n\n    subgraph ErrorDef[Error Types]\n        Error --- ET[UnexpectedToken]\n        Error --- UP[UnmatchedParenthesis]\n        Error --- IN[InvalidNumber]\n        Error --- DB[DivisionByZero]\n        Error --- IE[InvalidExpression]\n    end\n\n    TokenStream --\u003e Token\n    Parser --\u003e TokenStream\n    Parser --\u003e Expr\n    Parser --\u003e Error\n    Evaluator --\u003e Expr\n    Evaluator --\u003e Error\n    Token --\u003e Op\n\n    style DataFlow fill:#bbf,stroke:#333,stroke-width:2px\n    style Components fill:#bfb,stroke:#333,stroke-width:2px\n    style TokenDef fill:#fbf,stroke:#333,stroke-width:2px\n    style OpDef fill:#fbb,stroke:#333,stroke-width:2px\n    style ExprDef fill:#bff,stroke:#333,stroke-width:2px\n    style ErrorDef fill:#ffb,stroke:#333,stroke-width:2px\n```\n\n## Features\n\n- Basic arithmetic operations: `+`, `-`, `*`, `/`, `^` (power)\n- Scientific notation: `1.5e3` (1500), `2.4e-2` (0.024)\n- Parentheses for grouping operations\n- Proper operator precedence\n- Comprehensive error handling\n- Pure functional approach\n- Command-line interface\n\n\n## Installation\n\nClone the repository:\n   ```bash\n   git clone https://github.com/jeffasante/mathexpr\n   cd mathexpr\n   ```\n\n\n\n\n## Command Line Usage\n\nRun directly using cargo:\n```bash\n# Install\ncargo install --path .\n# Use the default example\nmathexpr\n# Evaluate a specific expression\nmathexpr \"2 + 3 * 4\"\n# Show help\nmathexpr --help\n```\n\nExample outputs:\n```bash\n$ mathexpr \"1.5e3 + 2 * (3.7 - 4)^2\"\nInput: 1.5e3 + 2 * (3.7 - 4)^2\n\nTokens: [\n    Scientific {\n        base: 1.5,\n        exponent: 3\n    },\n    Operator(Add),\n    Number(2.0),\n    Operator(Multiply),\n    LParen,\n    Number(3.7),\n    Operator(Subtract),\n    Number(4.0),\n    RParen,\n    Operator(Power),\n    Number(2.0)\n]\n\nParsed Expression: 1.5e3 + 2 * (3.7 - 4)^2\nExpression Tree: BinOp {\n    op: Add,\n    lhs: Scientific {\n        base: 1.5,\n        exponent: 3\n    },\n    rhs: BinOp {\n        op: Multiply,\n        lhs: Literal(2.0),\n        rhs: BinOp {\n            op: Power,\n            lhs: BinOp {\n                op: Subtract,\n                lhs: Literal(3.7),\n                rhs: Literal(4.0)\n            },\n            rhs: Literal(2.0)\n        }\n    }\n}\n\nResult: 1500.18\n```\n\n## Library Usage\n\nAdd to your `Cargo.toml`:\n```toml\n[dependencies]\nmathexpr = \"0.1.0\"\n```\n\nUse in your code:\n```rust\nuse mathexpr::{Tokenizer, Parser, Evaluator};\n\nfn main() {\n    let input = \"1.5e3 + 2 * (3.7 - 4)^2\";\n    \n    // Tokenize\n    let tokens = Tokenizer::tokenize(input).unwrap();\n    \n    // Parse\n    let mut parser = Parser::new(tokens);\n    let expr = parser.parse().unwrap();\n    \n    // Evaluate\n    let result = Evaluator::evaluate(\u0026expr).unwrap();\n    println!(\"Result: {}\", result);\n}\n```\n\n## Project Structure\n```\nmathexpr/\n├── src/\n│   ├── token/      # Token definitions and tokenizer\n│   │   ├── mod.rs     # Token types and traits\n│   │   └── tokenizer.rs# Token parsing logic\n│   ├── parser.rs   # Expression parsing\n│   ├── expr.rs     # Expression types\n│   ├── evaluator.rs# Expression evaluation\n│   ├── main.rs     # CLI interface\n│   ├── lib.rs      # Library interface\n│   └── error.rs    # Error handling\n```\n\n## Design Principles\n\n1. **Type Safety**\n   - Strong type system\n   - Comprehensive error types\n   - Safe error handling\n\n2. **Functional Approach**\n   - Immutable data structures\n   - Pure functions\n   - Clear data flow\n\n3. **Pipeline Architecture**\n   - Input → Tokenizer → Parser → Evaluator → Result\n   - Each stage has clear responsibilities\n   - Clean error propagation\n\n## Testing\n\nRun the test suite:\n```bash\ncargo test\n```\n\nTest coverage includes:\n- Basic arithmetic expressions\n- Scientific notation parsing\n- Error handling\n- Operator precedence\n- Complex expressions\n- CLI functionality\n\n## TODO (Upcoming Features)\n- **Symbolic Computation:** Expanding algebraic expressions (e.g., expanding `(x + 1)^2` to `x^2 + 2x + 1`).\n- **Graph Plotting:** Rendering expressions visually using `gnuplot` or `plotters`.\n- **Differentiation:** Implementing basic calculus (e.g., `d/dx (x^2) = 2x`).\n\n## Contributing\n\nContributions welcome:\n1. Report issues\n2. Submit pull requests\n3. Suggest new features\n4. Improve documentation\n\n## License\n\nMIT License - See LICENSE file for details","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffasante%2Fmathexpr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeffasante%2Fmathexpr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffasante%2Fmathexpr/lists"}