Question

In: Computer Science

Prolog, Please create a prolog predicate pell(N,Pn), which is true if 'Pn' is Nth term of...

Prolog,

Please create a prolog predicate pell(N,Pn), which is true if 'Pn' is Nth term of the sequence of Pell Numbers. such as 'pell(7,169)' results in true and pell(6,Pn)' results in 70.

Pell sequence = 0,1,2,5,12,29,70,169,408,..

Solutions

Expert Solution

Given the pell sequence = 0,1,2,5,12,29,70,169,408..

First let us know the logic of the sequence.The sequence goes as follows-each number is doubled then added to the number that precedes it.

1.1+1=2

2.2+2+1=5 i.e.,2 is doubled(by adding it to itself) then added to 1 which is the number directly preceding it

3.5+5+2=12i.e.,5 is doubled(by adding it to itself) then added to 2 which is the number directly preceding it.

The rest of the sequence is below:(The same rule applies)

4.12+12+5=29

5.29+29+12=70

6.70+70+21=169

7.169+169+70=408

Java code for the sequence:

import java.util.Scanner;

public class main

{

public static void main(String args[])

{

int n,a=1,b=0,c;

for(n=1;n<=10;n++)

{

c=a+2*b;

System.out.print(c+" ");

a=b;

b=c;

}

}

}

From the program we can know that the logic is

Pn=2*Pn-1+Pn-2

with P0=0and P1=1

The result will be stored in an array and extract the numbers based on thier index which is starting from 0 and ends at n-1 where n is the total elements in an array.

In the array give the index for the elements and get the elements by its key value and store in the form of pell(N,PN) where N is the index of the element and PN is the value of the element at Nth index.

In pell(N,PN),if Nth index contains the element PN then return true else return false.

In other case,index is given and need to find the element at that index.By using array indexing we find the element in that particular indexing and print the value of the element.



Related Solutions

1. Which of the following predicate calculus statements is true? Question 1 options: ∀n ∈ ℤ,...
1. Which of the following predicate calculus statements is true? Question 1 options: ∀n ∈ ℤ, n + 1 > n ∃n ∈ ℤ, n + 1 < n ∀n ∈ ℤ, n > 2n ∀n ∈ ℤ, 2n > n 2. Which of the following is the correct predicate calculus translation of the sentence "Some natural numbers are at least 100"? Question 2 options: ∃n ∈ ℕ, n > 100 ∀n ∈ ℕ, n ≥ 100 ∃n ∈ ℕ,...
If the pth term of an AP is q and the qth term is p, prove that its nth term is (p + q - n).
If the pth term of an AP is q and the qth term is p, prove that its nth term is (p + q - n).
(a) Someone offers you a security which pays $n at the end of the nth year...
(a) Someone offers you a security which pays $n at the end of the nth year until forever (i.e., it pays $1 at the end of the first year, $2 at the end of the second year, and so on). If the annually compounded interest rate is10% per year, what is the fair price of such security? (b) (Rule of 69) People in the banks have a quick way of finding outhow long it takes to double your money. The...
You have purchased a long-term coupon bond maturing in n periods selling for the price pn,t...
You have purchased a long-term coupon bond maturing in n periods selling for the price pn,t in the secondary market. You expect the Federal Reserve to raise the Federal Funds rate (interest rates) in the very near future. Should you sell your bond today or continue to hold on to it? What do you expect the price of the bond to be in one period? What do you expect to happen to the yield to maturity? What is your expected...
Which of the following is not true of a divestiture? a. It may create cash infusion...
Which of the following is not true of a divestiture? a. It may create cash infusion for the parent firm. b. Parent entity ceases to exist. c. The proceeds of the sale is taxable if returned to shareholders through a dividend or stock buyback. d. A new legal subsidiary may be created. e. B and C.
Write a C++ program that has a function which given n>=0, create an array length n*n...
Write a C++ program that has a function which given n>=0, create an array length n*n with the following pattern, shown here for n=3 : {0, 0, 1, 0, 2, 1, 3, 2, 1} (spaces added to show the 3 groups) generateGroups(3) → [0, 0, 1, 0, 2, 1, 3, 2, 1] generateGroups(2) → [0, 1, 2, 1] generateGroups(4) → [0, 0, 0, 1, 0, 0, 2, 1, 0, 3, 2, 1, 4, 3, 2, 1]
Which of the following statements is not true? A Bank's primary reserves are short-term assets that...
Which of the following statements is not true? A Bank's primary reserves are short-term assets that can provide the bank with additional liquidity while safely earning some interest income B Bank liquidity refers to the bank's ability to accommodate deposit withdrawals and loan requests, and pay off other liabilities as they come due C Higher concentration ratios imply higher correlation among default rates for banks' loan portfolio D Value at risk(VAR)is a common approach to assessing risk in financial firm's...
Which the following statements about Histidine are true? The shape around the N of the NH2...
Which the following statements about Histidine are true? The shape around the N of the NH2 group (N1) is trigonal planar. There are 6 pi bonds in Histidine.The C-C-O bond angle around the C-O double bond (C2-C9-O11 angle) is greater than 120o. The shape around the carbon of the C-O double bond (C9) is trigonal planar .There are 4 sp2 hybridized carbon atoms in Histidine. The N-H bond in the ring of atoms (N6-H18) is lying in the same plane...
Which statement is true of symmetric encryption? Question 2 options: a) It is impossible to create...
Which statement is true of symmetric encryption? Question 2 options: a) It is impossible to create digital signatures using symmetric encryption. b) It requires more processing power than asymmetric encryption. c) It is difficult to share a key over the Internet in symmetric encryption. d) It uses two different keys to encrypt and decrypt a message. Which type of access control is used to protect systems from unauthorized access? Question 4 options: a) Electronic trackers b) Identification badges c) Passwords...
Which one of the following statements is true? Please explain each choice: why it is true/false....
Which one of the following statements is true? Please explain each choice: why it is true/false. (a) The Burgers vector of an edge dislocation is normal to the dislocation line and normal to the slip plane. (b) The Burgers vector of a screw dislocation is normal to the dislocation line and parallel to the slip plane. (c) When a screw dislocation enables slip in a single crystal, the dislocation line remains in the slip plane. (d) BCC crystals do not...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT