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...
-
In Exercises 912, use the given conditions to write an equation for each line in point-slope form and general form Passing through (4, -7) and perpendicular to the line whose equation is x - 2y - 3 =...
-
Predicting Flight Delays (Bootstrap Forest and Boosted Trees). We return to the flight delays data for this exercise, and fit both a bootstrap forest and a boosted tree to the data. Use scheduled...
-
Air France-KLM (AF), a Franco-Dutch company, prepares its financial statements according to International Financial Reporting Standards. AF's financial statements and disclosure notes for the year...
-
Image transcription text The following table contains load-extension data from a tensile test on a cylindrical specimen with gauge length 9mm and gauge diameter 5mm. Load-extension Data Load [KN] 0...
-
A telephone line has the following parameters: R = 40 /m, G = 400S/m, L = 0.2H/m, C = 0.5nF/m (a) If the line operates at 10 MHz, calculate the characteristic impedance Zo and velocity u. (b) After...
-
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...
-
What is the reason for your answer to the previous problem? Make sure your answer uses the word probable.
-
What requires incoming inventory to be transferred directly to an outbound carrier? please explain.
-
If you were looking through stock listings and saw the following stock quote for XYZ Ltd, what would you take note of as being the bid price ?
-
IF THE UNIT OF THE HOSPITAL'S CENUS IS 40 PATIENTS AND FOR THE MONTH OF JANUARY THERE HAS BEEN 4 FALLS WHAT IS THE PERCENTAGE OF FALLS FOR THE MONTH OF JANUARY?
-
what does it mean by mattel inc's revenue being recognized when control of the goods is transferred to the customer?
-
Daniel's income is $60,000/yr and Danilla 's income is$40,000.Daniella has sole custody of the 3 children. According to the child support payment schedule, the flat rate is $ 770/mth. What will be...
-
Identify two items on the income statement that generate income tax expense. What is an income tax saving, and how does it arise?
-
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...
-
Create a class named Account that contains: A private int data field named id for the account (default 0). A private double data field named balance for the account (default 0). A private double data...
-
The next Java code needs to be converted from static to dynamic (just addd changes in same code): import java.util.Scanner; class MyIntStaticCircularQueue { int capacity = 2; int queue[] = new...
-
Hi! Would a tutor be able to assist me on this? In a complete graph with 48 vertices, how many vertices will be in each node's adjacency list? How many entries will be in the adjacency matrix for...
Study smarter with the SolutionInn App