{"id":22686460,"url":"https://github.com/ElectrifyPro/cas-rs","last_synced_at":"2025-08-07T00:32:50.945Z","repository":{"id":162761962,"uuid":"631784950","full_name":"ElectrifyPro/cas-rs","owner":"ElectrifyPro","description":"An opinionated computer algebra system written in Rust, used by CalcBot.","archived":false,"fork":false,"pushed_at":"2024-10-21T19:35:28.000Z","size":995,"stargazers_count":35,"open_issues_count":2,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-22T12:50:37.927Z","etag":null,"topics":["algebra","calculator","computer","parser","rust"],"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/ElectrifyPro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2023-04-24T03:45:09.000Z","updated_at":"2024-10-21T19:35:32.000Z","dependencies_parsed_at":"2023-06-26T13:58:54.078Z","dependency_job_id":"64766841-c5b7-4345-8ba1-75ead310b592","html_url":"https://github.com/ElectrifyPro/cas-rs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElectrifyPro%2Fcas-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElectrifyPro%2Fcas-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElectrifyPro%2Fcas-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElectrifyPro%2Fcas-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ElectrifyPro","download_url":"https://codeload.github.com/ElectrifyPro/cas-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228976848,"owners_count":18000682,"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","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":["algebra","calculator","computer","parser","rust"],"created_at":"2024-12-09T23:01:32.395Z","updated_at":"2025-08-07T00:32:50.936Z","avatar_url":"https://github.com/ElectrifyPro.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# cas-rs\n\n`cas-rs` is an opinionated computer algebra system written in Rust, originally made for use with the Discord bot [CalcBot](https://discord.com/application-directory/674457690646249472/). It is currently in a very early stage of development.\n\nSee below for a guide on the REPL and some code examples.\n\n# Features\n\n- Simplification of algebraic expressions, learn more [here](cas-compute/README.md)\n- Graphing calculator, learn more [here](cas-graph/README.md)\n- Robust expression parser and evaluator with very human-friendly output\n- Arbitrary precision arithmetic\n- Real and complex numbers\n- Radix notation (e.g. `2'1010` = 10)\n- 60+ built-in functions, covering many expected use cases ([see here](https://github.com/ElectrifyPro/cas-rs/blob/dev/cas-compute/src/funcs/mod.rs))\n- Powerful formatting options, including LaTeX code output\n- Builtin REPL\n- And more!\n\n# Quick start\n\nBelow are some routine examples of how `cas-rs` can be used.\n\n## REPL\n\n`cas-rs` comes with a builtin scripting language called \"CalcScript\" along with a REPL to help you try out the library. CalcScript is a compiled, mostly imperative, expression-oriented language, and attempts to keep syntax and visual noise minimal, while still readable. See the [`examples/`](examples) directory for examples of basic programs written in CalcScript.\n\nTo install the REPL, run the following command (Rust needs to be installed):\n\n```sh\ncargo install cas-rs --locked\n```\n\nYou can then run the REPL with:\n\n```sh\ncas-rs\n```\n\nWhich will immediately drop you into a REPL session where you can run CalcScript code:\n\n```text\n\u003e x = (1 + sqrt(5))/2\n1.61803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748475408807538689175212663386222353693179318006077\n\u003e x == phi\ntrue\n```\n\nTo learn more about CalcScript and example REPL usage, see the [`cas-parser`](cas-parser/README.md) crate.\n\n## General expression evaluation\n\n`cas-rs` can also be used as a library to evaluate mathematical expressions and run CalcScript code. Use [`cas-parser`](cas-parser/README.md) to parse an expression, and [`cas-vm`](cas-vm/README.md) to compile and execute it. Here is an example of evaluating the expression `x^2 + 5x + 6` where `x = 2`:\n\n```rust\nuse cas_parser::parser::Parser;\nuse cas_vm::Vm;\n\nlet mut parser = Parser::new(\"x = 2; x^2 + 5x + 6\");\nlet stmts = parser.try_parse_full_many().unwrap();\n\nlet result = Vm::compile_program(stmts)\n    .unwrap()\n    .run()\n    .unwrap();\n\nassert_eq!(result, 20.into());\n```\n\nLearn more about this in the [`cas-vm`](cas-vm/README.md) crate.\n\n## Algebraic simplification\n\n`cas-rs` includes a rudimentary algebraic simplifier that can simplify expressions using a variety of rules. Try it out with [`cas-compute`](cas-compute/README.md):\n\n```rust\nuse cas_compute::symbolic::simplify;\nuse cas_parser::parser::{ast::Expr, Parser};\n\nlet mut parser = Parser::new(\"6x + 11x + 4y - 2y\");\nlet expr = parser.try_parse_full::\u003cExpr\u003e().unwrap();\nprintln!(\"Original: {}\", expr); // 6x+11x+4y-2y\n\nlet simplified = simplify(\u0026expr.into());\nprintln!(\"Simplified: {}\", simplified); // 2 * y + 17 * x\n```\n\n```rust\n\n## Graphing calculator\n\nA customizable graphing calculator is provided with the `cas-graph` crate. You can create a graph of multiple functions and points, customize the appearance of the viewport, functions, and points, and render the graph to a PNG file (or any format supported by the [`cairo`](https://gtk-rs.org/gtk-rs-core/stable/latest/docs/cairo/) crate.\n\n```rust\nuse cas_graph::Graph;\nuse std::fs::File;\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    let surface = Graph::default()\n        .try_add_expr(\"x^2 + 5x + 6\").unwrap()\n        .add_point((-5.0, 6.0))\n        .add_point((-4.0, 2.0))\n        .add_point((-3.0, 0.0))\n        .add_point((-2.0, 0.0))\n        .add_point((-1.0, 2.0))\n        .center_on_points()\n        .draw()?;\n\n    let mut file = File::create(\"parabola.png\")?;\n    surface.write_to_png(\u0026mut file)?;\n\n    Ok(())\n}\n```\n\nOutput (note: colors were randomly chosen; random color selection is not\nincluded in the example code):\n\n\u003cimg src=\"https://raw.githubusercontent.com/ElectrifyPro/cas-rs/main/cas-graph/img/parabola.png\" width=\"500\" height=\"500\"/\u003e\n\n# Acknowledgements\n\n- Arbitrary precision arithmetic is implemented using the [`rug`](https://gitlab.com/tspiteri/rug) crate.\n- The design of `cas-parser` is heavily inspired by the Rust compiler, [`syn`](https://github.com/dtolnay/syn), and [`ariadne`](https://github.com/zesterer/ariadne).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FElectrifyPro%2Fcas-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FElectrifyPro%2Fcas-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FElectrifyPro%2Fcas-rs/lists"}