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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:54:36+00:00 2026-05-24T18:54:36+00:00

I am working on a small part of a matching system that uses boolean

  • 0

I am working on a small part of a matching system that uses boolean conditional expressions.

These conditional expressions are contrained to a single variable and a single operator (with an edge case of an Inclusive Between).

I am interested in:

  • Equal To “=”
  • Greater than “>”
  • Greater Than Or Equal To “>=”
  • Less Than “<“
  • Less Than Or Equal To “<=”
  • Inclusive Between “>= AND <=”

I have a requirement to compare two conditional expressions and evaluate:

1) Is there an overlap of possible values?

Does “X > 1000” overlap with “X > 999”? Yes.

2) If there is an overlap, return the overlap:

The overlap of “X > 1000” with “X > 999” is “X > 1000”

3) Is a conditional expression constrained by another?

“X < 999” is constrained by “X < 1000” ; “X < 1001” is not constrained by “X < 1000”


What I have done so far is build up a truth table of all possible combinations and return the results, but I was wondering if there was an easier way to calculate these?

Any Theory / Reference material / C# libraries out there?

  • 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-24T18:54:37+00:00Added an answer on May 24, 2026 at 6:54 pm

    I haven’t heard of any, but you can easily do without them if you represent the constraints as intervals:

    x > 1000 becomes (1000, double.Infinity)
    x == 1000 becomes [1000, 1000]

    etc.

    This way you need only one class

    class Constraint
    {
        double Lower; bool isLowerStrict;
        double Upper; bool isUpperStrict;
        bool isIn(double d)
        { 
            return (isLowerStrict ? Lower < d : Lower <= d) &&
                   (isUpperStrict ? Upper > d : Upper >= d);
        }
    
        Constraint intersect(Constraint other)
        {
            Constraint result = new Constraint();
            if (Lower > other.Lower)
            {
                result.Lower = Lower;
                result.isLowerStrict = isLowerStrict;
            }
            else if (Lower < other.Lower)
            {
                result.Lower = other.Lower;
                result.isLowerStrict = other.isLowerStrict;
            }
            else
            {
                result.Lower = Lower;
                result.IsLowerStrict = isLowerStrict || other.isLowerStrict;
            }
            // the same for upper
            return result;
        }
    
        public bool isEmpty()
        {
            if (Lower > Upper) return true;
            if (Lower == Upper && (isLowerStrict || isUpperStrict)) return true;
            return false;
        }
        public bool Equals(Constraint other)
        {
            if (isEmpty()) return other.isEmpty();
            return (Lower == other.Lower) && (Upper = other.Upper) &&
                   (isLowerStrict == other.IsLowerStrict) &&
                   (isUpperStrict == other.isUpperStrict);
        }
    
        // construction:
        static Constraint GreaterThan(double d)
        {
            return new Constraint()
            {
                Lower = d,
                isLowerStrict = true,
                Upper = double.PositiveInfinity,
                isUpperStrict = false
            };
        }
        static Constraint IsEqualTo(double d)
        {
            return new Constraint()
            {
                Lower = d,
                isLowerStrict = false,
                Upper = d,
                isUpperStrict = false
            };
        }
        // etc.
    }
    

    With this code, you can answer the questions:

    1) overlap: a.Intersect(b).isEmpty()

    2) intersect: a.Intersect(b)

    3) constrain: a.Intersect(b).Equals(a)


    EDIT:
    As @CodeInChaos suggests, you should consider replacing double with decimal. Mind that decimal lacks infinite values, so you should use decimal.MaxValue and decimal.MinValue instead.

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

Sidebar

Related Questions

I'm working on a script, and a small part of that involves taking a
I am working on small scale deployment system for our in-house software that manages
I am working on a form which has a small part that hides and
I am working on a form that requires validation. A small part of the
Iam working on small booking room system. In my solution I have a Reservation
Im working on a small application to try out an idea that I have.
I'm working on a small application in Java that takes a directory structure and
I am working on a project and there is a small part of it
As part of a personal project I am working on I took a small
I'm working on a small project that displays answers for a survey. I'm having

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.