Theme 4. Programming elements in Maple. Types of data. Operands and operations
Site: | Навчально-інформаційний портал НУБіП України |
Course: | Computers and Computer Technology (БЦІ). P2 ☑️ |
Book: | Theme 4. Programming elements in Maple. Types of data. Operands and operations |
Printed by: | Гість-користувач |
Date: | Tuesday, 13 May 2025, 3:06 AM |
1. Elements of the Maple language
The output file is a text file that includes a part or all program code. The program can consist of a single file, as well as several hundreds of source code files.
Functions, variables, and constants are the main objects that make up the source program (source files).
Elements of the Maple language are basic constructs that are used when writing programs. These include alphabet, identifiers, keywords, commentary, etc.
Alphabet - a set of characters that can be typed on the keyboard to create Maple language constructs.
The alphabet is used to form lexemes - the minimum lexical units that are recognized by the interpreter. These include keywords (reserved words), operations symbols, variable names, functions and commands, rows, numbers, delimiters.
The Maple interpreter reads each line and divides it into tokens that run immediately.
The Ukrainian alphabet can only be used in character strings, constants or in comments (in the explanations to the program).
The space characters are the space bar, the transition to a new line, the horizontal and vertical tabs, the new page. These symbols share tokens from each other.
The interpreter ignores several space characters in a row, which allows them to be used to improve the visuality of the program.
Separators are used by the interpreter for various tasks - from organizing the text of the program to instructing the compiler to perform specific actions:
, coma (comma) - when transferring;
; semicolon - ending the operator;
[] square brackets (square brackets) - definition of the sequence (array);
{} curly brackets - the definition of a plural;
() parentheses - function definitions and others.
Constants are a number, a character, or a string of characters that does not change during the execution of the program.
There are constants: goals; valid (with a floating point); symbolic; timely
Maple contains a number of named constants - those whose values can be accessed by name. Some of these constants cannot be changed.
These include:
- true, false - logical values "true" and "false";
- infinity - infinity;
- I - the imaginary unit;
- Pi is a constant of 3.14159265.
Some constants can be overridden, for example, Digits, which specifies the number of significant digits for floating point numbers (default 10).
To view all the constants in Maple, follow the command:.
Maple works with the following types of numbers :
- ( integer ) integer decimal (0, 1, 123, -456, etc.),
- ( fraction ) rational in the form of the ratio of integers (7/9, -123/127, etc.),
- ( float ) valid from the mantissa and order (1.23E5, 123.456E-10)
- ( complex ) complex (2 + 3I).
Numbers are any sequence of numbers. Maple ignores the left zeros.
Whole numbers are natural numbers with or. Whole numbers are given as a sequence of digits from 0 to 9. Example of integer constants: 10, 32767, -32767.
Maple can work with whole numbers of arbitrary value, the number of digits is limited to 2 28. Large numbers that do not fit on one line, Maple moves to the next line, using the reverse slash (\).
When checking the type of a natural number, the command whattype() returns the whole type of integer, since the natural type natural is considered as one of the subtypes of the integer type.
To specify a subtype of an integer, you must use the type () command with a parameter that describes the subtypes of the whole type: natural, negint (negative integer), posint(positive integer), even (odd), odd (odd) and prime (simple )
Calculations with integers implement four arithmetic operations ( adding +, subtraction -, multiplication *, division /) and calculating the factorial (!).
Get a list of all the commands for working with integers can be typing the command: ?Integer. Some of these commands:
- irem - calculation of the balance in the whole division operation irem(53,7) = 4
- igcd - finding the largest common divisor of integers igcd(192,90) = 6
- isprime - check whether the integer is simple.
Ordinary fractions are asked by dividing the two integers. Maple automatically performs fraction reduction, for example, 32/12;
Above the fractions, you can perform all basic arithmetic operations.
To convert a common fraction into a decimal value, the command evalf() is used.
The second parameter of this command specifies the number of significant digits, for example: evalf(3/8, 4) = 0.3750.
The fraction and its decimal representation are not identical to the Maple objects.
A floating point number is a real number that has an integer and fractional part. The whole part of the fraction is separated by a dot, not a comma. To write a valid constancy in the exponential form, use the symbol ' e ' or ' E ', for example: 15.78, 0.5, 1.0, 1.2e7,.00075, -2.5e-2. The calculation of real numbers is made by default with 10 significant digits.
If all numbers in the expression are integers, fractions or radicals, the result is also represented using these types of data. If, in the expression, there is a float number, then the result of such a "mixed" expression is a floating point number. For example, 3e2 + 3/4 + sqrt (5) + 3/4 * 0.1 + surd (6.3) * 43/10;
Radicals are defined as the result of inputting into fractional degrees of whole or fractional numbers, or calculating from them the same square root sqrt (), or calculating the root n -th degree surd (number, n). In Maple, the rise to a degree is given by a symbol or a sequence of two asterisks.
Unlike floating point numbers, calculations with integers, fractions, and radicals are absolutely accurate, since Maple does not perform any rounding.
Complex numbers. For the imaginary unit in Maple constant is used. If at least one of the parts of a complex number (real or imaginary) is calculated as a floating point, then the result will be the same.
Basic commands for working with complex numbers:
- allocation of a valid part of a complex number
- allocation of the imaginary part of the complex number.
Special characters (or sequences) are used to perform characteristic actions, such as moving to a new line, tab, sound.
A string is any set of symbols taken in double quotes, for example. The line length in Maple can have 268435439 characters. A string connection can be performed using the concatenation operation ||, or by calling to the cat function (line 1, line 2).
Comment - explanatory text to the program, which can be written in any part of it. The comment, as a sequence of characters, is ignored by the compiler and interpreted as spaces. It is recommended that you use the comment as often as possible, which will make it easier to understand the code when it is modified.
Identifiers are the names of the variables and functions that are created in the program.
The identifier uses only two sets of characters that can be typed on the keyboard:
- Letters of the Latin alphabet - A ... Z, a ... z , underscore "_";
- Arabic numerals 0, 1, 2..9 .
Requirements for writing identifiers:
- must start with a letter or an underline mark;
- must carry a clear meaning of the name of the variable or function;
- should not match the keyword.
Examples: temp1 , Skip _ 1 , Alpha , Fi , Sum , Ad , aD .
It Maple is case sensitive - small and large letters of the alphabet are different.
Key (service) words - predefined identifiers that have a special meaning.
and break by catch description do elif else end error export fi for finally from global if in intersect local minus mod module next no od option options or proc quit read return save stop then try union use while
Service words cannot be used as their own identifiers.
2. Types of data
Message A along with the corresponding information B is called the value.
Information B is called the value of the value, and the message A is denoted by the value. A set of values for which a certain set of operations is defined is called a set of values of a certain type.
The object type determines the set of values that this object can accept and the operations that can be performed on them.
Whole numbers, fractional numbers, floating point numbers are the main types of data. More complex data types include arrays, sets, and lists.
Single and multidimensional arrays are created by declaring arrays of elements of simple data types.
Elements of a multidimensional array are stored in rows.
To create an array, the array command ( i 1 .. j 1, i 2 .. j 2, ..., M ) is used that returns an array with elements from the list M.
An appeal to the elements of the plural, the list, and the array is indicated by the index of the element in square brackets.
Index names are character names with a lower index.
For their task, it is necessary to set the sequence of expressions after the symbolic name in square brackets, and the index name itself may also have a lower index.
Computer variable is a named part of the memory location, where data of a certain type is stored. By default, the variable is a scalar value.
If the expression uses a variable that does not have any numerical value, then such a variable is considered by the Maple system as an unknown value, and the expression containing the unknown is called a symbolic expression.
Just to work with such expressions, first and foremost, Maple was developed.
Variables allow you to store and process various types of data. By default, the Maple variable has a type, represents a character variable, and its value is its own name.
When assigning a variable to any value, its type changes to the value assigned to it.
3. Expressions, operations, operands
Maple distinguishes the concept of function, command, and operator.
An expression is a combination of names of variables, numbers, and other objects connected by symbols of permissible operations. Operators are used to record expressions, for example, adding +, subtraction, multiplication, division, assignment, equality, and others.
The introduction of expressions (questions) is set according to the rules of the editorial editor. The sign of the end of the expression is a semicolon, which indicates the output of the monitor. The two-dot sign cancels the output and can be used to write multiple expressions in one line.
Operations determine actions over operands - constants, variables, or character strings.
Each operand has a type.
Operands can be combined with operations in the original expressions, which in turn become operands. Their combination leads to the formation of more complex expressions, etc.
There are three types of expressions:
- mathematical - the result of the expression is the number;
- text - the result is a string of characters;
- logical - the result is the statement "yes" or "no".
Depending on the type of operations, the expressions are divided into primary, unary, binary, ternary, assignment, and type according to the number of operators in this expression. Assigning is an expression.
Character action:
: a lock of the expression that prevents the output of the calculation result in a string;
; lock of the expression, which forms the output of the calculation result in a separate line;
# comment pointer;
: = assignment operator;
'variable limiter, which prevents previous data from being used;
% returns the last result of the calculation.
Priority affects the order in which operations are calculated in expressions
Operations |
The name is |
() [] -> |
primary |
* / |
multiplicative |
+ - |
additive |
<<=> = |
relation |
: = |
appropriation |
4. Analysis of mathematical expressions
Maple has extensive capabilities for analytical transformations of mathematical formulas. These include such operations as bringing similar, decomposing into multipliers, disclosing brackets, etc.
In Maple, you can convert both the whole expression as well as its individual parts.
Each expression is subjected to parsing, which results in the construction of the expression tree.
In the first, the root node is the type of expression, and each branch corresponds to one of the constituent expressions of members, or operands.
The node in each branch corresponds to the type of operand, since it can itself be a complex expression, and its branches define the constituent members of this member of the expression.
This process continues until it reaches the leaves of the tree representing the names of the variables or numerical constants.
The user can independently perform parsing expressions using the commands: whattype (), type (), nops () and op () .
As a result, the expression will be equal to one of the main Maple objects :
Object |
Type |
Subtype |
Line |
string |
|
Name |
name |
symbol, indexed |
Integer |
integer |
negint, posint, nonnegint, even, odd, prime |
Fraction or rational number |
rational |
integer, fraction |
Decimal numbers |
numeric |
integer, fraction |
Complex numbers |
complex |
|
List |
the list |
|
Plural |
Set |
|
Call of function |
function |
|
The choice of the left or right part of the mathematical expression is carried out by the operators lhs (A = B); rhs (A = B) For numerator and denominator use numeric (expression) operators; denom (expression). To select part of the expression or list is the operator op (i, expression), where i - the number that defines the position in the expression.
The simplify () command is intended to simplify a variety of expressions that include rational fractions (algebraic expressions) containing trigonometric, reciprocal trigonometric functions, logarithms, and exponents. Maple can simplify it (or not simplify it because of complexity).
The most commonly used commands and Maple functions are located in its system core, which is constantly in the memory of the PC.
5. Questions for self-examination
- How many numbers in the whole number is Maple?
- What are the Constants of Digits and Order?
- Give an object type definition.
- What is the data type?
- What are the main types of data?
- What are the types of expressions?
- What is an expression in Maple?
- What should each operator or team in Maple necessarily complete?
- With the help of which the function calculates the root n-th degree number?
- Calculating which numbers are absolutely accurate in the Maple program?
Font Face
Font Size
Text Colour
Background Colour
Font Kerning
Image Visibility
Letter Spacing
Line Height
Link Highlight