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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:47:30+00:00 2026-06-05T19:47:30+00:00

{ ans += (a[i] > a[j]) != (b[i] > b[j]); //ans += ((a[i] >

  • 0
{
ans += (a[i] > a[j]) != (b[i] > b[j]);
//ans += ((a[i] > a[j]) && (b[j] > b[i])) || ((a[j] > a[i]) && (b[i] > b[j]));
}

What you see above is a snippet I took from some where. There are two logic expressions. Supposedly, the one commented out is the same as the one not commented out.

How do you get from:

((a[i] > a[j]) && (b[j] > b[i])) || ((a[j] > a[i]) && (b[i] > b[j])) 

to something like this

(a[i] > a[j]) != (b[i] > b[j])

Are there any guides or books for these kind of logic expression simplifications?

  • 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-05T19:47:31+00:00Added an answer on June 5, 2026 at 7:47 pm

    The code you posted is right if you assume that

    !(p > q) == (p < q)
    

    Meaning that for some reason, you’re ignoring equality.

    With this in mind, let’s say that:

    a1 = a[i]
    a2 = a[j]
    b1 = b[i]
    b2 = b[j]
    

    Then you have:

    ans += ((a1 > a2) && (b2 > b1)) || ((a2 > a1) && (b1 > b2));
    

    Which, since we’re ignoring equality, is the same as:

    ans += ((a1 > a2) && !(b1 > b2)) || (!(a1 > a2) && (b1 > b2));
    

    If you take a closer look, you’ll see that the expressions are repeated, so they can be simplified:

    A = a1 > a2
    B = b1 > b2
    

    Then:

    ans += (A && !B) || (!A && B);
    

    Which means either A or B, but no both
    This is a known boolean operation called XOR, which in your case is the same as different (!=)

    Therefore:

    ans += A != B;
    

    And expanding:

    ans += (a1 > a2) != (b1 > b2)
    

    So:

    ans += (a[i] > a[j]) != (b[i] > b[j])
    

    Hope it’s clear now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Which is a better way to select ans and quest from the table? SELECT
Lets say I have a data frame with two variables x & y and
I am a biginer to Qt and referring to some tutorials on implicit ans
I wanted a text field to take only numbers ans some control keys and
I am working on In App billing ans from last few days i have
I'm writing an application, where I want to store strings as keys ans a
Here is my function: function loadNext(choice) { $(#thequestion).load(question.php, { ans: choice, id: <?php echo
For a project I'm trying to read an int and a string from a
let ans = stringConcat [<a href=,\,str,\,>,strr,</a>] putStr (\nOutput : ++show (ans)) when I print
I am practicing these problems: http://code.google.com/codejam/contest/32016/dashboard#s=p1&a=1 I believe I have the correct solution, (even

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.