Command Overview
Algebrakit offers many functions and commands you can use in your scripts. This page provides an overview of some of the most important ones. For a full overview, refer to the command reference.
Mathematical functions
| Expression | Description |
|---|---|
Sqrt[4x], Sqrt[x,3] |
Square and cube roots , |
Sin[1/2Pi],Cos[..], Tan[..] |
Trigonometric functions , , |
ArcSin[..], ArcCos[..], ArcTan[..] |
Inverse sine, cosine, tangent |
Abs[x] |
Absolute value |
Log[x,2], Ln[2EulerE] |
Logarithm and natural logarithm , |
Diff[Sin[x^2],x] |
Derivative |
Integrate[x^2,a,b,x],Integrate[x^2,x] |
Definite and indefinite integral , |
Limit[Sin[2x]/x,x,0] |
Limit |
And[x>=0, x^2=1]Or[...], Not[...] |
Boolean functions |
Mathematical concepts
Units
| Expression | Description |
|---|---|
Quantity[4, 'm'],Quantity[9.81, 'm'/'s'^2] |
Quantity with unit, |
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.
Algebrakit will not calculate or simplify expressions unless explicitly instructed by the Simplify command.
| Expression | Result |
|---|---|
res:=2x*xres:=Simplify[2x*x] |
res is defined as the product res is defined as |
Simplify[x^2+x]Simplify[x(x+1)]Simplify[x(x+1)-x^2] |
, cannot be simplified , 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)]] |
(Factor expression) (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 |
Factor[..]Factor[6x^2-7x-3] |
Factor the expression |
Together[..]Together[2/x+y] |
Combine the fractions |
Solve[<expr>, <variable>]Solve[2x+4=4(x-2),x] |
Solve the equationSolution[x=3,x] |
Randomness Commands
To generate random exercises, you need commands that offer random results.
RandSample
Select a sample of a given size from the list. Items are not selected more than once.
| Expression | Description |
|---|---|
RandSample[ {1, 2, 3, 4, 5}, 2 ] |
Select a list of two elements from the given list. Each item is selected at most once |
RandSelect
Select one or more options from the list.
| Expression | Description |
|---|---|
RandomSelect[{a>b, a=b, b<a}] |
Select one of the three 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. |
RandSelectWeighted
Select one or more options from the list, with probabilities proportional to a second list.
| Expression | Description |
|---|---|
RandSelectWeighted[ { x, x^2, x^3 }, { 3, 1, 1} ] |
Select one of the three expressions. The first expression is selected 60% of the time; the other two expressions are each selected 20% of the time. |
RandSelectWeighted[ { x, x^2, x^3 }, { 3, 1, 1}, 3 ] |
Select a list of three elements from the given list. The first expression is selected 60% of the time; the other two expressions are each selected 20% of the time. Items can be selected more than once. |
RandVars
Select a given number of random variables.
| Expression | Description |
|---|---|
RandVars[ 1 ] |
Select a single random variable |
RandVars[ 3 ] |
Select a list of three random variables |
RandVars[ 3, Exclude=>{x, t} ] |
Select a list of three random variables. Do not select x or t. |
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 |
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, |
Range[2,5] |
The list |
ConstantArray[0, 5] |
The list |
Concat[L, {a,b}] |
A list created from list L and to additional items |
Unique[{1,x,5,x,1]} |
Create a list without the duplicates, |
Sort[{1,Pi,2,3]} |
Create a sorted list, |
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. |
Intersect[{a,b,g,a}, {a,b}] |
Creates the list with items that occur in both given lists |
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.
If[x>0]
y:= x^2
Else
y:= -x^2
End
The If command evaluates the condition. If the value of is positive, variable is defined as . Otherwise, will be set to .
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 areConstant,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 where and 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.
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.
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.
total:=1
While[total<100]
total:= total*RandomInt[{2,9}]
End
Note that the maximum number of iterations is 100.