calc
Version, currently main branch1 version
- main branchlatestJan 18, 2026
github.com/TSOA2/calc
Integrates/differentiates mathematical expressions.
Installation
# Add this to your shard.yml
dependencies:
calc:
github: TSOA2/calc
branch: mainmain is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
>= 1.18.2- License
- MIT
- Author
- TSOA2
- Target
calcfrom src/main.cr
Dependencies
This version declares no dependencies.
README
Calculator
About
A commandline tool to calculate integrals/derivatives (and maybe more later) of mathematical expressions. For now, the expressions can only have one variable in them (derivatives always differentiate with respect to X, as do integrals integrate).
Made in school on a Chromebook using Godbolt.
Usage
Integration
calc "x^2 + 3*x + 5" i midpoint 0 5 4
^- expression ^ ^ ^ ^ ^- # of parts
^ ^ ^ ^- high
^ ^ ^- low
^ ^- method
^- i for integration
Methods include:
- “lefthand”
- “righthand”
- “midpoint”
- “trapezoid”
- “simpsons”
A higher # of parts will give you more precision.
Differentiation
calc "x^2 + 3*x + 5" d
^- d for differentiation
Finds the derivative with respect to x.
Simplification
calc "5 * x / 5 + 2 - 2" s
^- s for simplification
Simplifies the expression by eliminating unnecessary terms, using a few rules. There's definitely more to add here.
Chained
You can chain together operations like this:
calc "x^(3/2) - 2 * (1 / x) i midpoint 1 2 3 d d s
Building
This was also written to learn Crystal. I think it's a nice language, but I added a Makefile for simplicity:
Build (debug)
make all
Build ("release")
make MODE=release all
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
main- Seen
- Jan 18, 2026
- Crystal
>= 1.18.2- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/TSOA2/calc
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 13, 2026
- Synced
- Aug 13, 2026
- Versions
- 1