Program Computability
[20/100%]Determine which of the following strings are syntactically correct structured programs:
; if then ; else ; end;
; if then ; else ; end;
; while do ; ; end;
; if then ; else ; end;
;
; while do ; end
; if then ; ; else ; end;
For the following structured program , find , where :
For the structured program П in Fig. 34 (left) find , where .
| if then |
| if then |
| else |
| end; |
| else |
| end; |
| : Fig. 34 (left): Program from Problems 540 and 541. |
For the structured program П in Fig. 34 (right) find , where .
| while do |
| if then |
| else |
| end; |
| end; |
| : Fig. 34 (right): Program from Problems 540 and 541. |
Write a structured program that has input variables and and computes the function in the variable , without changing .
Let be a program that computes the function in the variable , without changing and using additional variables and . Which of the structured programs in Fig. 35 compute the product in the variable ?
| ; | |
|---|---|
| while do | while do |
| ; | |
| end; | |
| end; | |
| : Fig. 35: Programs from Problem 543. |
Let be a program that computes the function in the variable , using auxiliary variables , as constructed in Problem 543. is the program that zeros out the variables ;. Which of the structured programs in Fig. 36 compute in the variable the square root of , that is, the function ?
| while do | while do | while do |
| end; | ||
| end; | end; | |
| if then | ||
| else | if then | |
| end; | end; | |
| : Fig. 36: Programs from Problem 544. |
Let and be the programs from Problem 544. Which of the structured programs in Fig. 37 compute in the variable the integer part of the quotient: ? For the result should also equal zero.
| ; | ||
|---|---|---|
| while do | while do | |
| while do | ||
| if then | ||
| end; | end; | end; |
| end; | if then | |
| end; | ||
| : Fig. 37: Programs from Problem 545. |
Construct programs that compute the following functions in the variable , and prove their correctness. For two-place functions, the value of the variable must remain unchanged.
;
, where and ;
, where if , and otherwise;
— factorial;
— integer quotient;
;
— exponentiation;
;
— the remainder of dividing by ;
— the number of distinct divisors of , .
Construct a program with labels that computes the Fibonacci number from a natural number .
Construct programs that compute the following functions in the variable :
For each of the functions , and given below by recursive relations, construct a structured program computing it:
,
,
,
,
, ,
, ,
, , , .
Write a program that implements the assignment ;, using assignments of the forms ; and . The latter changes the value of to 1 if the values of and are equal, or to 0 otherwise.
Prove that for computing any computable function one can write a structured program without branching. Hint. First show that one can write a program without complete branches.
Let a program П with one input variable compute in the variable some everywhere-defined one-to-one function whose range coincides with the set of all natural numbers . Let . Construct a program that computes the inverse function to : , if .
Let П be a program with . From the definitions it follows that, for different choices of input variables and output variables, the program can compute different functions.
What is the maximum number of functions of variables that П can compute? How many different functions in total can П compute? Functions with different numbers of arguments are considered different a priori.
Construct a program that computes the maximum number of distinct functions of variables.
Construct a program , that for every computes the maximum number of distinct functions of variables.
Determine how many pairwise nonequivalent programs with labels there are in total, having at most statements and only one variable that is simultaneously an input and an output variable.
Determine which everywhere-defined functions can be computed by programs with labels that have only one variable, which is simultaneously an input and an output variable, and use only branches and assignments of the forms ; and ;.
Let a program with labels contain only propositional variables , branches, and assignments with Boolean connectives: ;. Propose a way to determine which function such a program computes.
Prove that none of the functions , and can be computed by any structured program without loops.