Calculate
c-calculate
`c-calculate` is the most basic and frequently used CalcBot command. Simply run `c-calculate` (or `c-c` for short), followed by an expression to get the result:
1
> c-calculate 0.45/240
2
0.001875
3
4
> c-calculate sin(2pi)
5
0
6
7
> c-calculate 0.279*3.11
8
0.86769
Copied!
You can declare variables and use them within expressions. Use `c-calculate variables` to display your defined evariables, and `c-calculate delete` to delete them:
1
> c-calculate x=5
2
5
3
4
> c-calculate x=x^2
5
25
6
7
> c-calculate y=6!
8
720
9
10
> c-calculate x+y
11
745
12
13
> c-calculate variables
14
x: 25
15
y: 720
16
ans: 745
17
18
> c-calculate delete x y
19
Sucessfuly deleted variables and functions:
20
x: 25
21
y: 720
22
23
> c-calculate x+y
24
`x` is not defined.
Copied!
The special variable `ans` refers to the result of the last calculation you ran:
1
> c-calculate 12+4
2
16
3
4
> c-calculate ans
5
16
Copied!
1
> c-calculate pi
2
3.14159265358979
3
4
> c-calculate tau
5
6.28318530717959
6
7
> c-calculate e
8
2.718281828459045
9
10
> c-calculate phi
11
1.618033988749895
12
13
> c-calculate i
14
i
15
16
> c-calculate true
17
1
18
19
> c-calculate false
20
0
Copied!
CalcBot supports complex numbers:
1
> c-calculate sqrt(-16)
2
4i
3
4
> c-calculate (4i+2)^3
5
-16i-88
6
7
> c-calculate ans+16i+88
8
0
Copied!
You can use prime notation with any function in order to get the estimated nth-order derivative of the function (aka derivative at a point):
1
> c-calculate sin(0)
2
0
3
4
> c-calculate sin'(0)
5
1
6
7
> c-calculate cos(0)
8
1
9
10
> c-calculate cos'(0)
11
0
Copied!

## Predefined functions

The `calculate` command features a large collection of predefined functions. You can find the full list at the function reference.

## Custom functions

You can create custom functions for use in `calculate` and some other commands across CalcBot. You can define custom functions as if they were a variable. For example, here is a custom function that returns an approximation of the `sin` function:
1
> c-calculate approxsin(x) = x - x^3/3! + x^5/5! - x^7/7!
2
approxsin(x) = x - x^3/3! + x^5/5! - x^7/7!
Copied!
You can now use this function like any other function:
1
> c-calculate approxsin(1)
2
0.841
3
4
> c-calculate sin(1)
5
0.841470984808
Copied!
Custom functions can also have more than one parameter:
1
> c-calculate sumthree(a, b, c) = a + b + c
2
sumthree(a, b, c) = a + b + c
3
4
> c-calculate sumthree(3, 5, 7)
5
15
Copied!
Custom functions can even have default / optional parameters. In this example function, if a user does not provide any argument, `x` will by default be set to `5`:
1
> c-calculate opt(x = 5) = if(x is 5, true, false)
2
opt(x = 5) = if(x is 5, true, false)
3
4
> c-calculate opt()
5
1
6
7
> c-calculate opt(5)
8
1
9
10
> c-calculate opt(10)
11
0
Copied!

## Children commands

The `calculate` command also has a very large host of children commands. The most prominent are:

### `c-calculate derivative` / `c-calculate integral` / `c-calculate numintegrate`

Self-explanatory:
1
> c-calculate derivative x^2
2
2*x
3
4
> c-calculate integral 2x
5
x^2
6
7
> c-calculate derivative x^4+15x^3+45x^2+5x-66
8
4*x^3+45*x^2+90*x+5
9
10
> c-calculate integral 4*x^3+45*x^2+90*x+5
11
x^4+15*x^3+45*x^2+5*x
12
13
> c-calculate numintegrate 0 5 x x^2
14
41.666666666666667
Copied!

### `c-calculate limit`

Estimate the limit of an expression in terms of `x` as `x` approaches a certain value:
1
> c-calculate limit 1 (x^2-1)/(x-1)
2
2
3
4
> c-calculate limit 4 (2x^3-128)/(sqrt(x)-2)
5
384
6
7
> c-calculate limit pi/4 sin(pi)
8
0
9
10
> c-calculate limit -∞ 1/x+5
11
5
12
13
> c-calculate limit 0+ 1/x
14
15
16
> c-calculate limit 0- 1/x
17
-∞
Copied!

### Piecewise functions

CalcBot's limit command allows you to input piecewise functions. To enter a piecewise function, type the condition, followed by a colon (`:`), and the expression for that condition. For example:
1
> c-calculate limit pi/2 0<=x<=pi : sin(x)
2
1
Copied!
This computes the limit of a piecewise function defined in the region `0 <= x <= pi`, with the function `sin(x)`, as `x` approaches `pi/2`.
You can add more condition / function pairs after the first one by separating each condition / function pair with a colon (`:`):
1
c-calculate limit pi 0<=x<=pi : sin(x) : pi<x<=10 : x/pi-1
2
0
Copied!
Here, `0 <= x <= pi` is associated with the expression `sin(x)`, and `pi < x <= 10` is associated with the expression `x/pi-1`.
To summarize, this is the syntax for inputting piecewise functions:
1
c-calculate limit <x approaches> <condition> : <expression> : <condition 2> : <expression 2> ...
Copied!

### `c-calculate mode`

Change the calculation mode of `c-calculate` to radians or degrees (you can type `r` or `d` for short):
1
2
3
4
> c-calculate mode degree
5
Set calculation mode to degrees
Copied!

### `c-calculate newtonmethod`

Utilizes the Newton-Raphson method to solve for roots of an expression equal to 0. There are a few caveats to this method, however: (1) the method requires that the derivative of the expression be calculable, which isn't possible for certain expressions; (2) the method can't reliably detect if there are no roots; (3) the results are an approximation of the roots, which is why the precision of the result can sometimes be relatively awkward.
Despite this, Newton's method is still very powerful and can compute highly accurate approximations of roots if the conditions above are laid out.
1
> c-calculate newtonmethod x 2 x^2+5x+6
2
-2
3
4
> c-calculate newtonmethod x -5.5 x^2+5x+6
5
-3
Copied!

### `c-calculate simplify`

Simplify an algebraic expression:
1
> c-calculate simplify sqrt(1048)
2
2*sqrt(262)
Copied!
Clicking the show steps button on the response message will display a list of steps taken to reach the result:
1
> c-calculate simplify sqrt(1048)
2
sqrt(1048)
3
Start
4
5
sqrt(2*2*2*131)
6
Express constants with their prime factorization
7
8
2*sqrt(2*131)
9
Apply radical rule: sqrt(a^2) = a, a >= 0
10
11
2*sqrt(262)
12
Final
Copied!

### `c-calculate solvefor`

This is also a popular children command of CalcBot. Use it to algebraically solve for a variable in an equation. Note, that by not including an equal sign (`=`), CalcBot assumes the expression is equal to 0, like the first example below:
1
> c-calculate solvefor x x^2+5x+6
2
-2, -3
3
4
> c-calculate solvefor y 3y+2=x
5
(1/3)*(x-2)
6
7
> c-calculate solvefor x y=log(2x-1)
8
(1/2)*(1+10^y)
9
10
> c-calculate solvefor c a+2b+c=-2
11
-2-2*b-a
Copied!

### `c-calculate tofraction`

This command accepts an expression / decimal number and converts it to a fraction. You can also use this command to simplify fractions. Enclose a number / section of numbers with parenthesis to specify that that section repeats, and / or enter a value for the fourth argument to return the result as a mixed fraction:
1
> c-calculate tofraction 0.15
2
3/20
3
4
> c-calculate tofraction 0.(3)
5
1/3
6
7
> c-calculate tofraction 1.17 mixed
8
1 17/100
9
10
> c-calculate tofraction 0.(142857)
11
1/7
12
13
> c-calculate tofraction 65/100
14
13/20
Copied!