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 7431081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:14:24+00:00 2026-05-29T09:14:24+00:00

I have this scenario wherein I get a linear equation in the Prolog query

  • 0

I have this scenario wherein I get a linear equation in the Prolog query like below:

?- myquery( 3X + 5Y = 10, Result).

So my query has an equation 3X + 5Y = 10, which in general assumes the form AX + BY = C, where A=3, B=5 and C=10.

Now, in my prolog program, I am trying to define a predicate that can take in the expression mentioned in the query above. That is, I somehow want to get A, B and C values and also the operator involved (in the above case the plus operator) stored and then used on the logic that I define withing the program. I am wondering how this can be done.

To be more generic, the question is how do I identify the constants and the operator involved in an equation that is passed on through the goal/query?

  • 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-05-29T09:14:24+00:00Added an answer on May 29, 2026 at 9:14 am

    The following transcript may prove illuminating:

    32 ?- Term = (3*_X + 5*_Y = 10), functor(Term,F,A).
    
    Term = 3*_G527+5*_G530=10
    F = =
    A = 2 
    
    33 ?- Term = (3*_X + 5*_Y = 10), arg(Arg,Term,Val).
    
    Term = 3*_G459+5*_G462=10
    Arg = 1
    Val = 3*_G459+5*_G462 ; % user pressed ';' interactively
    
    Term = 3*_G459+5*_G462=10
    Arg = 2
    Val = 10 ; % user pressed ';' interactively
    
    No
    35 ?- Term = (3*_X + 5*_Y = 10), arg(1,Term,Val1), functor(Val1,F1,A1),
          arg(2,Val1,Val12).
    
    Term = 3*_G693+5*_G696=10
    Val1 = 3*_G693+5*_G696
    F1 = +
    A1 = 2
    Val12 = 5*_G696 
    

    The last query reads: for Term as given, 1st arg of Term is Val1, the functor of Val1 is F1 with arity A1 (meaning, it has A1 args – subparts – itself), and 2nd arg of the term in Val1 is stored under Val12 name. To clarify, any symbolic data in Prolog is in the form of fff(aa,bb,cc,...) where fff is some name, called functor, and the “arguments” in that expression can be accessed through the arg call.

    That means that the original expression (3*_X + 5*_Y = 10) is actually stored in Prolog as '='( '+'( '*'(3,_X), '*'(5,_Y)), 10). When you get to the atomic parts (functors with arity 0), you can check them further:

    47 ?- arg(1,(3*X),V), functor(V,F,A), number(V).
    
    X = _G441
    V = 3
    F = 3
    A = 0 
    
    Yes
    

    EDIT: to answer your other question (from the comments):

    1 ?- (3*_X + 5*_Y = 10) = (A*X + B*Y = C).
    
    A = 3
    X = _G412
    B = 5
    Y = _G415
    C = 10 
    
    Yes
    

    If you insist on not writing out the multiplication sign * explicitly, you will have to represent your terms as strings, and to analyze that string. That would be a much more involved task.

    EDIT: another thing to try is =.. predicate, called “Univ”:

    4 ?- (3*_X + 5*_Y = 10) =.. X.
    
    X = [=, 3*_G454+5*_G457, 10] 
    
    Yes
    5 ?- (3*_X + 5*_Y = 10) =.. X, X=[X1,X2,X3], X2 =.. Y.
    
    X = [=, 3*_G545+5*_G548, 10]
    X1 = =
    X2 = 3*_G545+5*_G548
    X3 = 10
    Y = [+, 3*_G545, 5*_G548] 
    
    Yes
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have this scenario: A server which contains needed data and client component which
Imagine this scenario: You have a desktop and a laptop. The desktop has a
I have this scenario: One custom class (Customer) with some properties, like this: public
I have this scenario: I have a chain of query handlers, the first is
I have this scenario where I want to display the xml which is coming
I have this scenario, can anybody fill the gaps for me? Its like this:
I have this scenario: class A { public virtual int Id { get; set;
I have this scenario: public class Member { public int MemberID { get; set;
I have this scenario in which memory conservation is paramount. I am trying to
I have this scenario, which I think must be pretty common: class Parameter {

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.