Command Overview

Algebrakit offers many functions and commands you can use in your scripts.

Mathematical functions

Expression Description
Sqrt[4x], Sqrt[x,3] Square and cube roots
4x\sqrt{4x}, x3\sqrt[3]{x}
Sin[1/2Pi],
Cos[..], Tan[..]
Trigonometric functions
sin(12π)\sin(\frac{1}{2}\pi), cos(..)\cos(..), tan(..)\tan(..)
ArcSin[..], ArcCos[..], ArcTan[..] Inverse sine, cosine, tangent
Abs[x] Absolute value x\left|x\right|
Log[x,2], Ln[2EulerE] Logarithm and natural logarithm
log2(x)\log_2(x), ln(2e)\ln(2e)
Diff[Sin[x^2],x] Derivative ddxsin(x2)\frac{d}{dx} \sin(x^2)
Integrate[x^2,a,b,x],
Integrate[x^2,x]
Definite and indefinite integral
x2dx\int x^2 dx, abx2dx\int_a^b x^2 dx
Limit[Sin[2x]/x,x,0] Limit limx0sin(2x)x\lim_{x\rightarrow 0} \frac{\sin(2x)}{x}
And[x>=0, x^2=1]
Or[...], Not[...]
Boolean functions
x0x2=1x\geq0 \wedge x^2=1

Mathematical concepts

Units

Expression Description
Quantity[4, 'm'],
Quantity[9.81, 'm'/'s'^2]
Quantity with unit, 4m4\text{m}
9.81m/s29.8 1\text{m}/\text{s}^2

Commands

Commands are instructions for the Algebrakit math engine. Some commands are programming constructs, like conditional clauses and loops. Other commands allow you to work with lists and generate random expressions.

Simplify

The Simplify command is the most important command of all. It triggers the math engine to simplify the expression as much as possible. You can use the tasks explained in the next paragraph to influence this.

Note

Algebrakit will not calculate or simplify expressions unless explicitly instructed by the Simplify command.

Expression Result
res:=2x*x
res:=Simplify[2x*x]
res is defined as the product 2xx2x\cdot x
res is defined as 2x22x^2
Simplify[x^2+x]
Simplify[x(x+1)]
Simplify[x(x+1)-x^2]
x2+xx^2+x, cannot be simplified
x(x+1)x(x+1)
xx, simplification possible

Tasks

Tasks are commands you use inside the Simplify command to instruct the math engine how to process the expression.

Expression Result
Simplify[Factor[x^2+x]]
Simplify[Expand[x(x+1)]]
x(x+1)x(x+1) (Factor expression)
x2+xx^2+x (Expand brackets)

The table below lists the most common tasks. Remember to use tasks inside the Simplify command.

Expression Description
Expand[..]
Expand[(1+x)^2]
Expand the brackets inside the expression
x2+2x+1x^2+2x+1
Factor[..]
Factor[6x^2-7x-3]
Factor the expression
(2x3)(3x+1)(2x-3)(3x+1)
Together[..]
Together[2/x+y]
Combine the fractions
2+xyy\frac{2+xy}{y}
Solve[<expr>, <variable>]
Solve[2x+4=4(x-2),x]
Solve the equation
Solution[x=3,x]

Randomness Commands

To generate random exercises, you need commands that offer random results.

RandomInt

Generate one or more random integers from a range.

Expression Description
RandomInt[{1,10}] A random integer number in the interval 1 to 10
RandomInt[{-10,10}, Exclude=>{0,1}] A random integer number in the interval -10 to 10, excluding 0 and 1
RandomInt[{1,10},4] A list of 4 random integer numbers
RandomInt[{1,10},4, AllowDuplicates=>False] A list of 4 different random integer numbers

RandSelect

Select one or more options from the list.

Expression Description
RandomSelect[{a>b, a=b, b<a}] Select one of the 3 expressions
RandomSelect[{a>b, a=b, b<a},2] Select a list of two items from the three expressions. Items can be selected more than once
RandomSelect[{2,3,5,7,11},2, AllowDuplicates=>False] Select a list of two items from the three expressions. Each item is selected at most once.

Shuffle

Randomly shuffle the items in a list

Expression Description
Shuffle[{2,3,5,7,11}] The list with the order of the items changed.

List Commands

Expression Description
L:={2,x,3x-4} Define variable L as a list with three items
L[[3]] The third item in the list, 3x43x-4
Range[2,5] The list {2,3,4,5}\{2,3,4,5\}
ConstantArray[0, 5] The list {0,0,0,0,0}\{0, 0, 0, 0, 0\}
Concat[L, {a,b}] A list created from list L and to additional items
{2,x,3x4,a,b}\{2,x,3x-4,a,b\}
Unique[{1,x,5,x,1]} Create a list without the duplicates, {1,x,5}\{1,x,5\}
Sort[{1,Pi,2,3]} Create a sorted list, {1,2,3,π}\{1,2,3,\pi\}
Shuffle[{1,2,3,4}] Create a list with the items at random positions
Difference[{a,b,g,a}, {a,b}] Copies the first list with the items of the second list removed. Duplicates are counted separately.
{g,a}\{g,a\}
Intersect[{a,b,g,a}, {a,b}] Creates the list with items that occur in both given lists
{a,b}\{a,b\}

Applying commands on list items

You can use standard operations on lists. The operations will apply to all items.
2*{2,3,4}^2 becomes {2*2^2, 2*3^2,2*4^2}.

For other commands, use the Map command.
Map[Sqrt, {1,2,3,4}] becomes {Sqrt[1], Sqrt[2], Sqrt[3], Sqrt[4]}.

You can also use lists as arguments for commands using the Apply command.
Apply[Plus, {1,2,3,4}] becomes Plus[1,2,3,4] which is 1+2+3+4.

The converse is also possible.
Apply[List, 1+2+3+4] is Apply[List, Plus[1,2,3,4]] which becomes List[1,2,3,4], which is {1,2,3,4}.

To understand the Apply command, you should know how the engine represents the standard operations:

  • a+b = Plus[a,b]
  • a*b = Times[a,b]
  • a^b = Power[a,b]
  • a/b = Division[a,b]
  • -x = Negative[x]
  • a-b = Minus[a,b]
  • a=b = Equals[a,b]
  • a>b = Greater[a,b]
  • a>=b = GreaterEqual[a,b]
  • a<b = Smaller[a,b]
  • a<=b = SmallerEqual[a,b]
  • 2x^2 = Times[2, Power[x,2]]

Conditions

Algebrakit allows to conditionally execute scripts based on conditions.

Example
If[x>0]
 y:= x^2
Else
 y:= -x^2
End

The If command evaluates the condition. If the value of xx is positive, variable yy is defined as x2x^2. Otherwise, yy will be set to x2-x^2.

You can omit the Else section, but you must always end the If block with End.

Examples of conditions

  • Mathematical relations like a<=b, x=1, Sqrt[x]>10, etc.
  • Type conditions like Type[expr] = NaturalNumber.
    Other types are Constant, SimpleFraction, FloatingPointNumber, Boolean, Variable, Unit, List

Strict conditions

When Algebrakit evaluates a condition, the result is True, False, or indeterminate. An example of an indeterminate condition is a>ba>b where aa and bb have no definition.

The If command will execute the first script block if the condition is indeterminate. You can prevent executing the script for indeterminate conditions using the Strict command. This command replaces such indeterminate conditions by False.

Example
If[a>b]
 # This block is executed
 ...
End
If[Strict[a>b]]
 # This block is not executed
 ...
End
a:=10
b:=2*Pi
If[Strict[a>b]]
 # This block is executed
 ...
End

Repetitions

You can repeatedly execute a block of commands using the While or For commands.

The For command executes a script for each item in a list.

Example
res:=1
For[v, {x, y, z}]
 # This script is executed three times,
 # with variable v equal to x, y, and z. 
 res:= res^v
End

The definition of res is ((1^x)^y)^z.

The While block executes a script until a condition is False.

Example
total:=1
While[total<100]
 total:= total*RandomInt[{2,9}]
End

Note that the maximum number of iterations is 100.