calc

Version, currently main branch1 version
  • main branchlatestJan 18, 2026

github.com/TSOA2/calc

Integrates/differentiates mathematical expressions.

2 stars
0 dependents
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  calc:
    github: TSOA2/calc
    branch: main

main is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
>= 1.18.2
License
MIT
Author
TSOA2
Target
  • calc from 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