1. Operators conditions

Operators are the commands for running the computer over the program.

They perform certain actions against the data. Operators are represented by appropriate identifiers in the form of special mathematical signs and words.

Operator conditions if

The basis of any computing device is elementary logic schemes, which are based on the laws and rules of the algebra of logic.

The apparatus of logic algebra was developed in 1854 by J. Boolem as an attempt to study the logic of thinking by mathematical methods. In 1938, K. Shannon used the Boolean algebra for the analysis of relay nets.

The main logical operations are:

  • and - logical multiplication or conjunction;
  • or - logical addition or disjunction;
  • not - logical subtraction or inversion.

These logical operations allow you to form a new expression.

Truth tables:

a     

     and    

b

                   

a     

   or    

b

1

1

1

 

1

1

1

1

0

0

 

1

1

0

0

0

1

 

0

1

1

0

0

0

 

0

0

0

Operations of the relation of values and expressions

The operations of the relation <,>, <=,> =, = and <> associate two algebraic expressions, form a new type of expression.

The type of equation is represented by the `=` character, and the type of inequality can be represented by one of the characters ``> `,` <`or` <= `.

In Maple, the branching in the program is implemented by the if operator, whose general form has the following syntax:

if boolean_expression then sequence_operators

 [Elif boolean_expression then sequence_operators]

 [Else sequence of operators]

end if

The semantics of this statement is simple: if true boolean expression after the keyword if, it runs a sequence of operators after the keyword then the first met elif, else or end if , if its value is false, it is checked for validity boolean expression after the keyword elif, if it is given, and in case of truth, operators after the key then are executed.

If none of the Boolean conditions is false, operators of the block else are executed, again, in the event of its task. Blocks elif can be as much as you like, while blockelse is always the only one.

Examples of constructs if :

x: = 5: g: = 0:

if x <0 then g: = - 1; end if;

if x <0 then g: = - 1; else g: = 1; end if;

if x <0 then g: = - 1; elif x <1 then g: = 0; else g: = 1; end if;

The Maple syntax allows you to use nested constructions if - operators in blocks then and else can contain branching operators.

x: = 5:

if x <0 then g: = - 1;

 elif x <1 then g: = 0;

 else g: = 1; end if;

g: = 1

Operation ` if ` syntax is: `and f ` (condition operand1, operand2).

Its semantics are as follows: the value of the condition, which should be a Boolean expression, is calculated, and if it is true, the result of the operation will be the operand1, otherwise operand2:

a: = 4: b: = 3:

c: = `if` (ab, a, b) + sin (` if` (a> b, a, b));

c: = 4 + sin (4)

In a boolean relationship in the if statement, the relation can be equal to true or false.

You can compute the relation in the boolean context by the command evalb().

Using the 'if' construct: plot ([`if` (cos (x)> 0, 1, -1), cos (x)], x = -Pi .. Pi);