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

  • Home
  • SEARCH
  • 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 3277372
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:21:40+00:00 2026-05-17T19:21:40+00:00

I am newbie in C and new to stackoveflow too. I have some problems

  • 0

I am newbie in C and new to stackoveflow too. I have some problems in coding first oder formula like

forall([X],implies(X,f(X)))

Here x is a variable, implies is predicate and f is function. It sounds like for all x, x implies function of x i’e f(x).

using C. Any kind of suggestions and help will be appreciated.

  • 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-17T19:21:40+00:00Added an answer on May 17, 2026 at 7:21 pm

    First order formulas have boolean propositional parts (in your example, “implies(x,f(x))”) and quantifiers (“Forall x”).

    You should already know that coding a function call “f(x)” is coded exactly that way in C.

    You code the propositional part as boolean C code using logic connectives. For your example, “implication” isn’t a native C operator so you have to substitute slightly different code for it. In c, the “?” operator does the trick. “a?b:c” produces “b” if “a” is true, and “c” otherwise. For your example:

       x?f(x):false
    

    Quantifiers mean you have to enumerate the set of possible values of the quantified variable, which always has some abstract type. In logic, this set might be infinite, but it computers it is not. In your case, you need to enumerate the set of values which could be “x”s. To do that, you need a way to represent a set; a cheesy way to do that in C is to use an array to hold the set members X, and to iterate through the array:

    type_of_x set_of_x[1000];
      ... fill x somehow ...
    for(i=1;i<number_of_set_elements;i++)
    {   x= set_of_x[i];
          ... evaluate formula ...
    }
    

    Since a “forall” is false if any propositional instance is false, you need to exit the enumeration when you find a false example:

    boolean set_of_x[1000]; // in your example, x must be a boolean variable
    // forall x
    ... fill x somehow ...
    final_value=true;
    for (i=1;i<number_set_elements; i++)
    {  x= set_of_x[i];
       if (x?f(x):false)
          { final_value=false;
             break;
          }
    }
    ... final_value set correctly here...
    

    “exists” is true if any propositional instance is true, so you need to exit the enumeration when you find a true result:

    // exists x
    ... fill x somehow ...
    final_value=false;
    for (i=1;i<number_set_elements; i++)
    {  x= set_of_x[i];
       if (x?f(x):false)
          { final_value=true;
             break;
          }
    }
    ... final_value set correctly here...
    

    If you have multiple quantifiers, you’ll end up with nested loops, one loop for each quantifier. If your formula is complex, you’ll likely need several intermediate boolean variables to compute the values of the various parts.

    You’ll also end up with a variety of “sets” (some arrays, some linked lists, some hash tables) so you’ll need to learn how to use these data structures. Also, your quantified values might not be booleans, but that’s OK;
    you can still pass them to functions that compute boolean values. To compute the FOL for:

     forall p:Person old(p) and forall f:Food ~likes(p,f)
    

    the following code skeleton would be used (details left to the reader):

     person array_of_persons[...];
     foods array_of_foods[...]
    
     for (i=...
     { p=array_of_persons[i];
       is_old = old(p);
       for(j=...
        { f=array_of_foods[j];
          ...
             if (is_old && !likes(p,f)) ...
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to PHP and have installed on Linux to boot (also a newbie).
Java Newbie here. I have a JFrame that I added to my netbeans project,
.NET newbie here... I'd like to make a button in a Windows form that
I'm still a newbie to Adobe Air/Flex, and still fairly new with SQL. I've
I'm sure this is a newbie question, but every time I've compiled/dl'ed a new
Newbie question. I have a NSMutableArray that holds multiple objects (objects that stores Bezier
Newbie here...can I write one program which incorporates .NET LINQ and also various Java
I'm a newbie to pgsql. I have few questionss on it: 1) I know
I have a snippet to create a 'Like' button for our news site: <iframe
Newbie to LINQ, and trying to write the following query... select f.Section_ID, f.Page_ID, f.SortOrder,

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.