## Description

Calcpad uses a simple programming language for the development of engineering worksheets. It mostly includes mathematical expressions, mixed with text/Html comments. Some advanced options for conditional execution, iterations, units and numerical methods are also available. Detailed description is provided in the user manual. Bellow, you can find a quick reference guide:

## Expressions

### Constants

#### Real

All real values are stored in double precision floating point fields. They can range from -1.7976931348623157E+308 to 1.7976931348623157E+308. The smallest nonzero value is 4.94065645841247E-324. Smaller values are considered exactly zero. You can use the following input formats:

The last two formats are nothing but simple expressions.

#### Complex

Complex numbers are represented by a couple of values ±a ± bi, where “a” is the real part, and “bi” is called “imaginary”. The imaginary unit in Calcpad is entered as 1i. It is defined so that (1i)^2 = -1. You must switch to “Complex” mode in order to use complex numbers.

#### Predefined

There are four predefined constants that are stored as named variables:
e = 2.71828182845905 – the base of the natural logarithms (Euler’s number);
π = 3.14159265358979 – (Pi) the ratio of circumference to diameter of a circle;
g = 9.80665 – the gravitational acceleration on Earth;
i = 1i – the imaginary unit.

### Variables

Variable names can contain Latin and Greek letters, digits, commas “,”, underscores “_” and some special symbols: ” ′, ″,  ‴, ⁗, ø, Ø, °, ∡”. The first character must be a letter. The underscore is used to start a subscript. Variables are created by assigning a value, e.g.:
a_1 = 2

### Operators

You can use the following operators with Calcpad:

Instead of special symbols for comparrision operators ≡ ≠ ≤ ≥, you can use C/C++ style shortcuts, respectively: ==, !=, <=, >=.

### Functions

#### Built-in

The following functions are predefined and can be used directly:

#### Custom

You can define custom functions of multiple arguments:
`f(x; y; z; ...) = `expression

Function names are subjected to the same rules as variable names (see above).

### Plotting

There are several different plotting commands:
`\$Plot{y(x) @ x = a : b}` – plots the function y(x) within the interval [a; b].
`\$Plot{y1(x) & y2(x) & ... @ x = a : b}` – plots several functions y1(x), y2(x), etc. in a single plot.
`\$Plot{x(t) | y(t) @ t = a : b}` – plots a curve where both x(t) and y(t) are functions of a single parameter t.
`\$Plot{x1(t) | y1(t) & x2(t) | y2(t) & ... @ t = a : b}`
plots several parametric curves on a single plot.
`\$Map{f(x; y) @ x = a : b & y = c : d}` – plots a function of two variables as a color/grayscale map.

#### Size of plot area

You can specify the size of the plot area in pixels by defining the PlotWidth and PlotHeight variables, e.g.:

``````PlotWidth = 400
PlotHeight = 250``````

The above values are the default ones.

### Numerical and iterative procedures

You can use numerical methods for problems that do not have a closed form solution:
`\$Root{f(x) = const @ x = a : b}` – finds the root of the equation f(x) = const within the interval [a; b], using modified Anderson Bjork method.
`\$Root{f(x) @ x = a : b}` – finds the root of the equation f(x) = 0.
`\$Find{f(x) @ x = a : b}` – finds the point where the function crosses the abscissa (it is not required to be a root).
`\$Inf{f(x) @ x = a : b}` – finds the minimum value f_inf of the function f(x), using the golden section search method. The location of minimum on the abscissa is stored in the x_inf variable.
`\$Sup{f(x) @ x = a : b}` – finds the maximum value f_sup of the function f(x), using the golden section search method. The location of maximum on the abscissa is stored in the x_sup variable.
`\$Area{f(x) @ x = a : b} `– finds the definite integral of the function f(x) in the interval [a; b], using the adaptive Gauss-Lobatto rule.
`\$Integral{f(x) @ x = a : b}` – finds the definite integral of the function f(x) in the interval [a; b], using the double exponential Tanh-Sinh quadrature.
`\$Slope{f(x) @ x = a}` – finds the slope of the tangent to f(x) at point x = a.
`\$Sum{f(k) @ k = a : b}` – sums the values of f(x) for all integer values of k between a and b.
`\$Product{f(k) @ k = a : b}` – multiplies the values of f(x) for all integer values of k between a and b.

You can use this command to define your own function for calculation of factorial and binomial coefficients:

``````F(n) = \$Product{k @ k = 1 : n}
C(n; k) = \$Product{(i + n - k)/i @ i = 1 : k}``````

`\$Repeat{f(k) @ k = a : b}` – calculates f(x) repeatedly for all integer values of k between a and b.
`\$Repeat{x = f(x; k) @ k = a : b}` – similar to the above, but sores the result into a variable to be used for the next iteration.

### Units of measurement

Calcpad supports the use of physical units in the calculations. Just write the units next to the respective values. You can also specify target units for the result, separated by a vertical bar at the end:

1.23m + 35cm + 12mm|cm

The above expression will evaluate to 159.2 cm. Version 3.0 supports metric, imperial and US units.

#### Imperial/USCS units:

Everything inside a Calcpad script is considered to be math expressions unless it is enclosed by quotes. Then it is treated as comments. You can use them to add contents to your calculation notes, such as titles, text, images, tables etc.

Comments can be enclosed in double (“) or single (‘) quotes. Double quotes are used for “titles” and single quotes for ‘normal text’. You can have several expressions in a single line, separated by comments. The closing quote is not required if there is nothing else in the line.

Comments can contain plain text as well as Html, CSS, JS (jQuery), SVG, etc. for providing rich formatting and user experience for your calculation notes. For example, you can use Html to fold part of the content:

``````'<div class="fold">
"This is a folded content
'This line is hidden until you unfold it
'</div>``````

## Program flow control

You can split the flow of your calculation notes depending on certain intermediate values. It will not only use different formulas for calculations, but it can also display different text and images in your report.
You can use the following patterns:

### Conditions

``````#If condition1
'code if condition1 is true
#Else If condition2
'code if condition2 is true
#Else If condition3
...
#Else
'code if non of the conditions is true
#end if``````

Shorter forms are also possible:

``````#If condition
'code if condition is true
#Else
'code if conditions is false
#end if``````

or:

``````#If condition
'code if condition is true
#end if``````

### Loops

Simple:

``````#Repeat n
'Put some code here
#Loop``````

Here n is the number of iterations and not the counter. If you need a counter, you have to define it as follows:

``````i = 0
#Repeat n
i = i + 1
'Put some code here
#Loop``````

With conditional break or continue:

``````#Repeat
'Put some code here
#If condition
#Break or #Continue
#End if
'Some more code
#Loop``````

### Modules and macros/string variables

Modules:

`#Include filename `– incudes external file/module
`#Local `– starts a local section in a module (not to be included)
`#Global `– starts a global section in a module (to be included)

Inline string variable:

``#def variable_name\$ = content``

Multiline string variable:

``````#def variable_name\$
content line 1
content line 2
...
#end def``````

Inline macro:

``#def macro_name\$(param1\$; param2\$; ...) = content``

Multiline macro:

``````#def macro_name\$(param1\$; param2\$; ...)
content line 1
content line 2
...
#end def``````

## Output control

You can control the visibility of your code in the output using the following keywords:
`#Hide` – hide the contents after the current line;
`#Pre` – show the contents in input form mode only (see “Input forms” bellow) and hide it otherwise;
`#Post` – show the contents in calculated mode only and hide it in input form mode;
`#Show` – always show the contents (revoke all other commands);

You can also modify the rendering style of the calculations as follows:
`#Val` – shows only the result as a single value;
`#Equ` – shows the complete equation and the result;
`#Noc` – shows only the equation without the result (no-calculations).

The next two keywords allows you to select the default units for angles inside your calculation notes:
`#deg` – assumes that angles are in degrees: sin(90) = 1;
`#rad` – assumes that angles are in radians: sin(π/2) = 1;
`#gra` – assumes that angles are in grades: sin(100) = 1;

Rounding options:
`#round n` – rounds the output to n digits after the decimal point;

Breakpoints for step-by-step execution:
`#pause` – calculates to the current line and waits for the user to resume manually;
`#input` – renders an input form to the current line and waits for user input.

These settings affect all calculations after the current line.