Compound Inequality Calculator
Understanding Compound Inequalities
A compound inequality combines two or more simple inequalities with either the word "AND" or the word "OR." These inequalities are used to describe a range of values that a variable can take.
"AND" Compound Inequalities (Intersection)
When two inequalities are joined by "AND," the solution set includes only the values that satisfy *both* inequalities simultaneously. This is often referred to as the intersection of the two individual solution sets. Graphically, it represents the overlapping region of the two inequalities.
Example: If you have x > 3 AND x ≤ 7, the solution includes all numbers greater than 3 but less than or equal to 7. This can be written as 3 < x ≤ 7 in inequality form, or (3, 7] in interval notation.
- If the solution sets of the individual inequalities do not overlap, there is "No Solution."
- If one inequality's solution set is entirely contained within the other, the solution is the smaller (more restrictive) set.
"OR" Compound Inequalities (Union)
When two inequalities are joined by "OR," the solution set includes any value that satisfies *at least one* of the inequalities. This is known as the union of the two individual solution sets. Graphically, it represents all regions covered by either inequality.
Example: If you have x < 2 OR x ≥ 5, the solution includes all numbers less than 2, as well as all numbers greater than or equal to 5. These are two separate, disjoint intervals. In inequality form, it remains x < 2 OR x ≥ 5, and in interval notation, it's (-∞, 2) ∪ [5, ∞).
- If the solution sets overlap or touch, the "OR" condition often results in a single, larger interval. For instance,
x > 5 OR x < 10 covers all real numbers, as every number is either greater than 5 or less than 10 (or both).
- If one inequality's solution set completely contains the other, the solution is the larger (less restrictive) set.
How to Use the Calculator
- Select First Inequality Operator: Choose
<, ≤, >, or ≥ for the first inequality (e.g., x > value1).
- Enter First Inequality Value: Input the numerical value for the first inequality.
- Choose Logical Connector: Select "AND" or "OR" to combine the two inequalities.
- Select Second Inequality Operator: Choose the operator for the second inequality (e.g.,
x ≤ value2).
- Enter Second Inequality Value: Input the numerical value for the second inequality.
- Click "Calculate Solution": The calculator will display the combined solution in both inequality form and interval notation.
Examples:
- Example 1 (AND):
x > 3 AND x ≤ 7
- First Operator:
>, Value: 3
- Connector:
AND
- Second Operator:
≤, Value: 7
- Result:
3 < x ≤ 7, Interval: (3, 7]
- Example 2 (OR – Disjoint):
x < 2 OR x ≥ 5
- First Operator:
<, Value: 2
- Connector:
OR
- Second Operator:
≥, Value: 5
- Result:
x < 2 OR x ≥ 5, Interval: (-∞, 2) ∪ [5, ∞)
- Example 3 (AND – No Solution):
x ≥ 0 AND x < 0
- First Operator:
≥, Value: 0
- Connector:
AND
- Second Operator:
<, Value: 0
- Result:
No Solution, Interval: {}
- Example 4 (OR – All Real Numbers):
x > 5 OR x < 10
- First Operator:
>, Value: 5
- Connector:
OR
- Second Operator:
<, Value: 10
- Result:
All Real Numbers, Interval: (-∞, ∞)
- Example 5 (AND – Overlapping):
x > 5 AND x > 2
- First Operator:
>, Value: 5
- Connector:
AND
- Second Operator:
>, Value: 2
- Result:
x > 5, Interval: (5, ∞)
.calculator-container {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f9f9f9;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
max-width: 700px;
margin: 20px auto;
color: #333;
}
.calculator-container h2 {
text-align: center;
color: #0056b3;
margin-bottom: 20px;
}
.calculator-form .form-group {
display: flex;
align-items: center;
margin-bottom: 15px;
gap: 10px;
}
.calculator-form label {
flex: 1;
font-weight: bold;
color: #555;
}
.calculator-form select,
.calculator-form input[type="number"] {
flex: 2;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
}
.calculator-form button {
display: block;
width: 100%;
padding: 12px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 18px;
cursor: pointer;
transition: background-color 0.3s ease;
margin-top: 20px;
}
.calculator-form button:hover {
background-color: #0056b3;
}
.result-container {
background-color: #e9f7ef;
border: 1px solid #d4edda;
border-radius: 4px;
padding: 15px;
margin-top: 25px;
color: #155724;
text-align: center;
}
.result-container h3 {
color: #0056b3;
margin-top: 0;
margin-bottom: 10px;
}
.result-container p {
margin: 5px 0;
font-size: 1.1em;
}
.calculator-article {
margin-top: 30px;
padding-top: 20px;
border-top: 1px solid #eee;
}
.calculator-article h3 {
color: #0056b3;
margin-bottom: 15px;
}
.calculator-article h4 {
color: #0056b3;
margin-top: 20px;
margin-bottom: 10px;
}
.calculator-article p,
.calculator-article ul {
line-height: 1.6;
margin-bottom: 10px;
}
.calculator-article ul {
list-style-type: disc;
margin-left: 20px;
}
.calculator-article ul li {
margin-bottom: 5px;
}
function parseInequality(operator, value) {
var lower = -Infinity;
var upper = Infinity;
var lower_inc = false;
var upper_inc = false;
if (operator === '>') {
lower = value;
lower_inc = false;
} else if (operator === '>=') {
lower = value;
lower_inc = true;
} else if (operator === '<') {
upper = value;
upper_inc = false;
} else if (operator === '<=') {
upper = value;
upper_inc = true;
}
return { lower: lower, upper: upper, lower_inc: lower_inc, upper_inc: upper_inc };
}
function intervalToString(interval) {
var lower_str = (interval.lower === -Infinity) ? "-∞" : interval.lower;
var upper_str = (interval.upper === Infinity) ? "∞" : interval.upper;
var lower_bracket = interval.lower_inc ? "[" : "(";
var upper_bracket = interval.upper_inc ? "]" : ")";
return lower_bracket + lower_str + ", " + upper_str + upper_bracket;
}
function inequalityToString(interval, variable) {
variable = variable || 'x';
var lower_val = interval.lower;
var upper_val = interval.upper;
var lower_inc = interval.lower_inc;
var upper_inc = interval.upper_inc;
if (lower_val === -Infinity && upper_val === Infinity) {
return "All Real Numbers";
} else if (lower_val === -Infinity) {
return variable + " " + (upper_inc ? "≤" : "") + " " + lower_val;
} else if (lower_val === upper_val) {
if (lower_inc && upper_inc) {
return variable + " = " + lower_val;
} else {
return "No Solution";
}
} else if (lower_val > upper_val) {
return "No Solution";
} else {
var lower_op = lower_inc ? "≤" : "<";
var upper_op = upper_inc ? "≤" : "<";
return lower_val + " " + lower_op + " " + variable + " " + upper_op + " " + upper_val;
}
}
function doIntervalsOverlapOrTouch(intA, intB) {
// Intervals overlap or touch if they are not strictly disjoint.
// They are strictly disjoint if A ends before B starts, OR B ends before A starts.
// A ends before B starts: intA.upper < intB.lower
// OR (intA.upper == intB.lower AND neither intA.upper_inc NOR intB.lower_inc)
var A_ends_before_B_starts = intA.upper < intB.lower || (intA.upper === intB.lower && !(intA.upper_inc || intB.lower_inc));
var B_ends_before_A_starts = intB.upper < intA.lower || (intB.upper === intA.lower && !(intB.upper_inc || intA.lower_inc));
return !(A_ends_before_B_starts || B_ends_before_A_starts);
}
function calculateCompoundInequality() {
var op1 = document.getElementById('operator1').value;
var val1 = parseFloat(document.getElementById('value1').value);
var connector = document.getElementById('connector').value;
var op2 = document.getElementById('operator2').value;
var val2 = parseFloat(document.getElementById('value2').value);
if (isNaN(val1) || isNaN(val2)) {
document.getElementById('result').innerHTML = "
Error:
Please enter valid numbers for both values.";
return;
}
var interval1 = parseInequality(op1, val1);
var interval2 = parseInequality(op2, val2);
var final_lower, final_upper, final_lower_inc, final_upper_inc;
var resultText = "";
var intervalText = "";
if (connector === 'AND') {
// Intersection
final_lower = Math.max(interval1.lower, interval2.lower);
final_upper = Math.min(interval1.upper, interval2.upper);
// Determine inclusivity for lower bound
if (interval1.lower > interval2.lower) {
final_lower_inc = interval1.lower_inc;
} else if (interval2.lower > interval1.lower) {
final_lower_inc = interval2.lower_inc;
} else { // interval1.lower == interval2.lower
final_lower_inc = interval1.lower_inc && interval2.lower_inc;
}
// Determine inclusivity for upper bound
if (interval1.upper < interval2.upper) {
final_upper_inc = interval1.upper_inc;
} else if (interval2.upper < interval1.upper) {
final_upper_inc = interval2.upper_inc;
} else { // interval1.upper == interval2.upper
final_upper_inc = interval1.upper_inc && interval2.upper_inc;
}
var combinedInterval = {
lower: final_lower,
upper: final_upper,
lower_inc: final_lower_inc,
upper_inc: final_upper_inc
};
resultText = inequalityToString(combinedInterval);
intervalText = intervalToString(combinedInterval);
} else if (connector === 'OR') {
// Union
var interval1_str_ineq = inequalityToString(interval1);
var interval2_str_ineq = inequalityToString(interval2);
var interval1_str_int = intervalToString(interval1);
var interval2_str_int = intervalToString(interval2);
if (doIntervalsOverlapOrTouch(interval1, interval2)) {
// They overlap or touch, so the union is a single interval
final_lower = Math.min(interval1.lower, interval2.lower);
final_upper = Math.max(interval1.upper, interval2.upper);
// Determine inclusivity for final_lower
if (interval1.lower < interval2.lower) {
final_lower_inc = interval1.lower_inc;
} else if (interval2.lower interval2.upper) {
final_upper_inc = interval1.upper_inc;
} else if (interval2.upper > interval1.upper) {
final_upper_inc = interval2.upper_inc;
} else { // interval1.upper == interval2.upper
final_upper_inc = interval1.upper_inc || interval2.upper_inc;
}
var combinedInterval = {
lower: final_lower,
upper: final_upper,
lower_inc: final_lower_inc,
upper_inc: final_upper_inc
};
resultText = inequalityToString(combinedInterval);
intervalText = intervalToString(combinedInterval);
} else {
// Disjoint intervals
// Order them for display if needed, but for OR, the order doesn't change the set.
// Just display them as "ineq1 OR ineq2" and "interval1 U interval2″
resultText = interval1_str_ineq + " OR " + interval2_str_ineq;
intervalText = interval1_str_int + " ∪ " + interval2_str_int;
}
}
document.getElementById('result').innerHTML = "
Solution:
Inequality Form: " + resultText + "
Interval Notation: " + intervalText + "";
}