Here’s a problem that occurs in automatic program analysis. For a set of variablesx1,......,xn, you are given some equality constraints, of the form “ xi=xj” and some disequality constraints, of the form “ xixj.” Is it possible to satisfy all of them?

For instance, the constraints.

x1=x2,x2=x3,x3=x4,x1x4

cannot be satisfied. Give an efficient algorithm that takes as input m constraints over n variables and decides whether the constraints can be satisfied.

Short Answer

Expert verified

Yes, it is possible to satisfy all of them and its efficient algorithm that takes as input and constraints over variables is given below.

Step by step solution

01

Automatic program analysis.

The Automatic program analysis program analysis is the process of automatically analyzing the behavior of computer programs regarding a property such as correctness, robustness, safety and likeness. Automatic program analysis program analysis focuses on two major areas that are program optimization and program correctness.

02

Efficient algorithm for satisfy the condition.

A problem where you maximize or minimize a real function by systematically choosing input values from an allowed set and computing the value of the function and a set of variables x1,......,xn, with some equality constraints of the form “xi=xj” and some disequality constraints, of the form “ xi=xj.” For that instance, the constraints is given in the question is,

x1=x2,x2=x3,x3=x4,x1x4

Cannot be satisfied. And that will takes as input m constraints over n variables.

Let’s take input: m and n, which contain variables as x and y also contains constraints over these all variable, the program analysis using constraints is divisible into constraint generation and constraint resolution. Constraint generation produces constraints from a program text that give a declarative speciation of the desired information about the program. Constraint resolution (i.e., solving the constraints) then computes this desired information. In the author’s view, the constraint-based analysis paradigm is appealing for three primary reasons constraints separate speciation from implementation, constraints yield natural speculations and constraints enable sophisticated implementations.

Here, set of variablesx1,......,xn, with some equality constraints of the form “ xi=xj” and some disequality constraints, of the form isxixj. An inequality constraint can be either active, ε-active, violated, or inactive at a design point. On the other hand, an equality constraint is either active or violated at a design point.

For equality constraints of the form the condition must be follows: “xi=xj”.

And for disequality constraints, of the form the condition must be follows: “inequality constraints”.

And by the definition of the equality constraints and from the disequality constraints these above both the conditions satisfy the instances which are showing in the equation.

x1=x2,x2=x3,x3=x4,x1x4, hence it is shown in the equation that in the prefix constraints it follows equality constraints and in the end equation it shows the inequality constraints with the variable here and treated it as input variable x1=x2,x2=x3,x3=x4,. follows equality constraints. And herex1x4is inequality constraints with this condition .Hence, it satisfy the constraints.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Question: 0.1. In each of the following situations, indicate whether f=O(g),orf=Ω(g),or both (in which case f=(g))

How long does the recursive multiplication algorithm (page 25) take to multiply an n -bit number by an m -bit number? Justify your answer.

Is there a faster way to compute the nth Fibonacci number than by fib2 (page 4)? One idea involves matrices.

We start by writing the equations F1=F1 and F2=F0+F1 in matrix notation:


role="math" localid="1659767046297" (F1F2)=(0111).(F0F1).

Similarly,

F2F3=(0111).(F1F2)=(0111)2.(F0F1)

And in general

(FnFn+1)=(0111)n.(F0F1)

So, in order to compute Fn, it suffices to raise this 2×2 matrix, call it X, to the nth power.

a. Show that two 2×2matrices can be multiplied using 4additions and 8multiplications.

But how many matrix multiplications does it take to compute Xn?

b. Show that O(logn) matrix multiplications suffice for computing Xn. (Hint: Think about computing X8.)

Thus, the number of arithmetic operations needed by our matrix-based algorithm, call it fib3, is just O(logn), as compared to O(n)for fib2. Have we broken another exponential barrier? The catch is that our new algorithm involves multiplication, not just addition; and multiplications of large numbers are slower than additions. We have already seen that, when the complexity of arithmetic operations is taken into account, the running time offib2becomes O(n).

c. Show that all intermediate results of fib3 are O(n) bits long.


d. Let M(n)be the running time of an algorithm for multiplying n-bit numbers, and assume that M(n)=O(n2) (the school method for multiplication, recalled in Chapter 1, achieves this). Prove that the running time of fib3 is O(M(n)logn).


e. Can you prove that the running time of fib3 is O(M(n))? Assume M(n)=Θ(na)for some 1a2. (Hint: The lengths of the numbers being multiplied get doubled with every squaring.)


In conclusion, whether fib3 is faster than fib2 depends on whether we can multiply n-bit integers faster thanO(n2) . Do you think this is possible? (The answer is in Chapter 2.) Finally, there is a formula for the Fibonacci numbers:

role="math" localid="1659768125292" Fn=15(1+52)n15(152)n.

So, it would appear that we only need to raise a couple of numbers to the nth power in order to computeFn . The problem is that these numbers are irrational, and computing them to sufficient accuracy is nontrivial. In fact, our matrix method fib3 can be seen as a roundabout way of raising these irrational numbers to the nth power. If you know your linear algebra, you should see why. (Hint: What are the eigenvalues of the matrix X?)

The Fibonacci numbers F0,F1,F2,... are defined by the rule

F0=0,F1=1,Fn=Fn1+Fn2.

In this problem we will confirm that this sequence grows exponentially fast and obtain some bounds on its growth.

(a) Use induction to prove that Fn20.5nfor n6.

(b) Find a constant c<1such thatFn2cn for all n0. Show that your answer is correct.

(c) What is the largestc you can find for which Fn=Ω(2cn)?

Mean and median. One of the most basic tasks in statistics is to summarize a set of observations x1,x2,,xnR by a single number. Two popular choices for this summary statistic are:

• The median, which we’ll callμ1

• The mean, which we’ll callμ2

(a) Show that the median is the value of μthat minimizes the function

i|xi-μ|

You can assume for simplicity that is odd. (Hint: Show that for any , the function decreases if you move either slightly to the left or slightly to the right.)

(b) Show that the mean is the value of μ that minimizes the function

i(xi-μ)2

One way to do this is by calculus. Another method is to prove that for any μR,

i(xi-μ)2=i(xi-μ2)2+n(μ-μ2)2

Notice how the function for μ2 penalizes points that are far from much more heavily than the function for μ1 . Thus μ2 tries much harder to be close to all the observations. This might sound like a good thing at some level, but it is statistically undesirable because just a few outliers can severely throw off the estimate of μ2 . It is therefore sometimes said that μ1 is a more robust estimator than μ2 . Worse than either of them, however, is μ , the value of μthat minimizes the function

maxi|xi-μ|

(c) Show that μ can be computed in O(n) time (assuming the numbers are xismall enough that basic arithmetic operations on them take unit time).

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free