Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8635643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:01:30+00:00 2026-06-12T10:01:30+00:00

How to write a predicate doublelist(L, R) with L is list of numbers, R

  • 0

How to write a predicate doublelist(L, R) with L is list of numbers, R is also a list and has the same length as L and each element is doubled up.

Example:

?- doublelist([-1, 0, 3], L).  
L = [-2, 0, 6].

I’m a prolog beginner, I confuse to write one myself. Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:01:31+00:00Added an answer on June 12, 2026 at 10:01 am

    Start by writing down your example:

    double_list([-1,0,3],[-2,0,6]).
    

    This is a perfectly valid Prolog. You can use it in all kinds of directions:

    ?- double_list([-1,0,3],L).
    L = [-2,0,6].
    
    ?- double_list([-1,0,3],[-2,0,6]).
    Yes.
    

    So, now you need to make it more general. As a first step, write down what it means:

    double_list([-1,0,3],[-2,0,6]):-
        (-2) is 2*(-1),
        0    is 2*???,
        6    is ?????.
    

    Next step, substitute variables for numbers:

    double_list([-1,0,3],[-2,0,6]):-
        A1 is (-1), B1 is (-2), B1 is 2*A1,
        A2 ????,    B2 ????,    B2 is 2*??,
        A3 ????,    B3 ????,    B3 ???????.
    

    Can you continue from this? Do you see the pattern?

    double_list([X1,X2,X3],[Y1,Y2,Y3]):-
        ......
    

    Now you have a predicate that works for all lists of length 3. Then,

    double_list([X1 | T1], [Y1 | Z1]):-
        ......
    
    double_list( [], ZN) :- ZN = ???? .
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using predicate builder to write the following code: IEnumerable<int> ids= new List<int>
Write a predicate sorted(L) which tests whether a list of integers is sorted, [n1,n2,...,nk]
I'm trying to write a predicate that divides a list into N parts. This
I am trying to write a predicate to analyse common poker hands; for example
I'm having some difficulties in prolog, I'm trying to write a predicate that will
For example I have: pos(10, 20). How can i write the predicate which returns
I can easily write a predicate to get unique elements from a given list
I am trying to write a predicate palindrome/1 in Prolog that is true if
I want to write a program in Prolog that builds a list of all
I was trying to write predicate divide(L,Len,Slist) which will be true when Slist can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.