Consider the Prolog gcd program in Figure 1.2. Does this program work backward as well as forward?
Question:
Consider the Prolog gcd program in Figure 1.2. Does this program work “backward” as well as forward? (Given integers d and n, can you use it to generate a sequence of integers m such that gcd(n, m) = d?) Explain your answer.
Figure 1.2:
Transcribed Image Text:
int gcd(int a, int b) { // C while (a != b) { if (a > b) a = a - b; else b = b - a; return a; (* OCaml *) let rec gcd a b = if a = b then a else if a > b then gcd b (a - b) else gcd a (b a) gcd (A, B,G) :- A = B, gcd (A,B,G) :- A > B, C is A-B, gcd(C,B,G). gcd (A,B,G) :- B > A, C is B-A, gcd(C,A,G). G = A. % Prolog %3D
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 75% (16 reviews)
No it only works forwa...View the full answer
Answered By
Charles mwangi
I am a postgraduate in chemistry (Industrial chemistry with management),with writing experience for more than 3 years.I have specialized in content development,questions,term papers and assignments.Majoring in chemistry,information science,management,human resource management,accounting,business law,marketing,psychology,excl expert ,education and engineering.I have tutored in other different platforms where my DNA includes three key aspects i.e,quality papers,timely and free from any academic malpractices.I frequently engage clients in each and every step to ensure quality service delivery.This is to ensure sustainability of the tutoring aspects as well as the credibility of the platform.
4.30+
2+ Reviews
10+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
Find a published example of an architecture. What structure or structures are shown? Given its purpose, what structure or structures should have been shown? What analysis does the architecture...
-
During the 2020 tax year, Sally Jones earns a salary of $600,000 and Bill Smith earns a salary of $600,000. Neither individual had any other income during the year, and neither can itemize...
-
Use the mixed congruential method to generate a sequence of five two-digit random integer numbers such that xn + 1 (41xn + 33) (modulo 100) and x0 = 48.
-
Nanette works for Piroz and is paid a basic wage of $1,000 a week. Piroz operates the following bonus scheme: (1) Each employee gets a bonus of $4 for every unit they produce in excess of 2,000 units...
-
A stream bed has a rectangular cross section 5 m wide and a slope of 0.0002 m/m. The rate of flow in the stream is 8.75 m3/s. A dam is built across the steam, causing the water surface to rise to 2.5...
-
The City of Raylan has a rather large warehouse that it no longer needs. The city had previously used the warehouse to store supplies and equipment for the school system, police department, and other...
-
Regal Rooms Ltd is a rug and drapery retailer. Regal Rooms specialises in selling floor rugs and window dressings. The following information was derived from the shops accounting records for the year...
-
The chairman of the board of directors of the company for which you are chief accountant has told you that he has little use for accounting figures based on cost. He believes that replacement values...
-
Calculate the cost of debt. Calculate the cost of equity. Calculate the weight of debt and equity. Calculate the WACC. Table 4 Stock Info Amount Bond Info Amount Shares Outstanding 100 Face value...
-
Assuming the cost of an associate leaving within 90 days is $3,000, what will be your facility's approximate cost of early turnover for this year? Year-to-Date Turnover Avg. Head- count Total < 90...
-
In the spirit of Example 11.20, write a Prolog program that exploits backtracking to simulate the execution of a nondeterministic finite automaton.
-
Solve Exercise 6.22 in Prolog. Data From Exercise 6.22: Use iterators to construct a program that outputs (in some order) all structurally distinct binary trees of n nodes. Two trees are considered...
-
The concept of chemical equilibrium is very important. Which one of the following statements is the most correct way to think about equilibrium? (a) If a system is at equilibrium, nothing is...
-
Again consider the car sales rep in question 67. What is the probability that she will make at least two sales after speaking to four customers? Question 67 A car sales representative sees an average...
-
Use the normal approximation to the binomial distribution with n = 100 and p = .3. (a) What is the probability that a value from the binomial distribution will have a value greater than 35? (b) What...
-
From past history, we know that 60 % of people audited by the IRS owe money to the government. If we take a random sample of 500 people who are being audited, what is the probability that between 280...
-
Answer question 43 again for an option with an exercise price of $55. How does the exercise value of the call option affect the options price? Question 43 Use the BlackScholes option pricing formula...
-
Repeat question 39 using the current ratio data for MRK. Question 39 Use the data given in Table 3.9 to compute the mean, standard deviation, coefficient of variation, and coefficient of skewness for...
-
In January 2016, Pro-Tech Co. pays $1,550,000 for a tract of land with two buildings. It plans to demolish Building A and build a new shop in its place. Building B will be a company office; it is...
-
Which of the ocean zones shown would be home to each of the following organisms: lobster, coral, mussel, porpoise, and dragonfish? For those organisms you identify as living in the pelagic...
-
Benchmarking is field of study that involves identifying representative workloads to run on specific computing platforms in order to be able to objectively compare performance of one system to...
-
When performing computations on sparse matrices, latency in the memory hierarchy becomes much more of a factor. Sparse matrices lack the spatial locality in the data stream typically found in matrix...
-
In future systems, we expect to see heterogeneous computing platforms constructed out of heterogeneous CPUs. We have begun to see some appear in the embedded processing market in systems that contain...
-
do not use chatgpt or any other ai tool. A monopolist with a linear demand curve will have a marginal revenue curve with intercept and slope as the demand curve..
-
7. Consider the figure below. HO -C pka-COOH-2.19 pka-NH2 = 9.67 pka-sidechain 4.25 CHCH2C OH a. What amino acid is this? (1) b. Is it in the R or S configuration? (2) c. Draw the three forms of the...
-
2. Draw the structure of the missing major organic product(s) or reactant(s) in each of the transformations below including showing stereochemistry when appropriate. For reactions that produce an...
Study smarter with the SolutionInn App