Introduction to Conditional Disjunctions

Introduction

A Boolean disjunction is a conditional statement where you combine more than one condition but you are trying to know whether at least one of the conditions produces a true result. This operation is commonly represented by a Boolean operator named "OR" operator. The primary formula to follow is:

condition1 OR condition2

Once again, each condition is formulated as a Boolean operation:

operand1 Boolean-operator operand2 OR operand3 Boolean-operator operand4

In that case, a conditional disjunction can be formulated as follows:

operand1 Boolean-operator operand2

As seen with conjunctions, the whole disjunction operation can be assigned to a Boolean variable or it can be written in the parentheses of a conditional statement.

Practical LearningPractical Learning: Introducing Conditional Conjunctions

  1. Start Microsoft Visual Studio. On the Visual Studio 2022 dialog box, click Create a New Project
  2. Make sure Console App is selected.
    Click Next
  3. Change the project Name to TaxPreparation04. Accept or change the project Location and press Enter
  4. Make sure the Framework combo box is displaying .NET 7.0 (Standard Term Support) and press Enter
  5. Change the document as follows:
    printfn "=========================================="
    printfn " - Amazing DeltaX - State Income Tax -"
    printfn "=========================================="
    
    let mutable taxRate = 0.00
    let mutable stateName = ""
    
    printfn "Enter the information for tax preparation"
    printfn "States"
    printfn " AK - Alaska"
    printfn " AR - Arkansas"
    printfn " CO - Colorado"
    printfn " FL - Florida"
    printfn " GA - Georgia"
    printfn " IL - Illinois"
    printfn " IN - Indiana"
    printfn " KY - Kentucky"
    printfn " MA - Massachusetts"
    printfn " MI - Michigan"
    printfn " MO - Missouri"
    printfn " MS - Mississippi"
    printfn " NV - Nevada"
    printfn " NH - New Hampshire"
    printfn " NC - North Carolina"
    printfn " PA - Pennsylvania"
    printfn " SD - South Dakota"
    printfn " TN - Tennessee"
    printfn " TX - Texas"
    printfn " UT - Utah"
    printfn " WA - Washington"
    printfn " WY - Wyoming"
    printf "Enter State Abbreviation: "
    let abbr = stdin.ReadLine()
    printfn "--------------------------------------------"
    
    printf "Gross Salary: "
    let grossSalary = float(stdin.ReadLine())
    
    let taxAmount   = grossSalary * taxRate / 100.00
    let netPay      = grossSalary - taxAmount
    
    printfn "============================================"
    printfn " - Amazing DeltaX - State Income Tax -"
    printfn "--------------------------------------------"
    printfn $"State Name:   {stateName}"
    printfn $"Gross Salary: {grossSalary:f}"
    printfn "Tax Rate:     %0.2f%c" taxRate '%'
    printfn "--------------------------------------------"
    printfn $"Tax Amount:   {taxAmount:f}"
    printfn $"Net Pay:      {netPay:f}"
    printfn "============================================"
  6. To execute, on the main menu, click Debug -> Start Without Debugging
  7. For the State Abbreviation, type UT and press Enter
  8. For the Gross Salary, type 1495.75 and press Enter
    ==========================================
     - Amazing DeltaX - State Income Tax -
    ==========================================
    Enter the information for tax preparation
    States
     AK - Alaska
     AR - Arkansas
     CO - Colorado
     FL - Florida
     GA - Georgia
     IL - Illinois
     IN - Indiana
     KY - Kentucky
     MA - Massachusetts
     MI - Michigan
     MO - Missouri
     MS - Mississippi
     NV - Nevada
     NH - New Hampshire
     NC - North Carolina
     PA - Pennsylvania
     SD - South Dakota
     TN - Tennessee
     TX - Texas
     UT - Utah
     WA - Washington
     WY - Wyoming
    Enter State Abbreviation: UT
    --------------------------------------------
    Gross Salary: 1495.78
    ============================================
     - Amazing DeltaX - State Income Tax -
    --------------------------------------------
    State Name:
    Gross Salary: 1495.78
    Tax Rate:     0.00%
    --------------------------------------------
    Tax Amount:   0.00
    Net Pay:      1495.78
    ============================================
    
    Press any key to close this window . . .
  9. Press Enter to close the window and return to your programming environment
  10. To execute again, on the main menu, click Debug -> Start Without Debugging
  11. For the State Abbreviation, type MA and press Enter
  12. For the Dross Salary, type 2458.95 and press Enter
    ==========================================
     - Amazing DeltaX - State Income Tax -
    ==========================================
    Enter the information for tax preparation
    States
     AK - Alaska
     AR - Arkansas
     CO - Colorado
     FL - Florida
     GA - Georgia
     IL - Illinois
     IN - Indiana
     KY - Kentucky
     MA - Massachusetts
     MI - Michigan
     MO - Missouri
     MS - Mississippi
     NV - Nevada
     NH - New Hampshire
     NC - North Carolina
     PA - Pennsylvania
     SD - South Dakota
     TN - Tennessee
     TX - Texas
     UT - Utah
     WA - Washington
     WY - Wyoming
    Enter State Abbreviation: MA
    --------------------------------------------
    Gross Salary: 2458.95
    ============================================
     - Amazing DeltaX - State Income Tax -
    --------------------------------------------
    State Name:
    Gross Salary: 2458.95
    Tax Rate:     0.00%
    --------------------------------------------
    Tax Amount:   0.00
    Net Pay:      2458.95
    ============================================
    
    Press any key to close this window . . .
  13. Press R to close the window and return to your programming environment

A Boolean Operator for a Disjunction

As mentioned already, a disjunction consists of evaluating two conditions to find out whether at least one of them is true. This operator is performed with the || operator. It can be represented as follows:

condition1 || condition2

Each of the conditions can be formulated as follows:

operand1 Boolean-operator operand2

As a result, a Boolean disjunction can be formulated as follows:

operand1 operator1 operand2 || operand3 operator2 operand4

A conditional disjunction is an operation that works as follows:

The whole expression can be assigned to a Boolean variable or it can be written in the parentheses of a conditional statement. The operations can be resumed as follows:

Condition-1 Condition-2 Condition-1 && Condition-2 Condition-1 || Condition-2
True True True True
True False False True
False True False True
False False False False

When you are performing a logical disjunction, you can use any of the comparison operators we saw already (!, ==, <>, <, <=, >, >=, is, and not). When we studied conjunctions, we saw that you cannot logically use the same variable in two equality or non-equality conditions of a conjunction. In a disjunction, you can use the same variable or different variables in conditions. Here are examples that perform logical exclusions:

let mutable name = "Gabrielle Towa"
let mutable timeWorked = 42.50
let mutable status1 = "Part-Time"
// The first condition is True BUT the second condition is False:
let mutable verdict = status1 = "Part-Time" || status1 = "Intern"

printfn "Employee Name:              %s" name
printfn "Time Worked:                %0.2f" timeWorked
printfn "Employment Status:          %s" status1
printfn "Condition-1 || Condition-2: %b" verdict
printfn "-------------------------------------------------------------"

if verdict = true then
    printfn "The time sheet has been approved."
else
    printfn "Part-time employees are not allowed to work overtime."
printfn "============================================================="

name <- "Stephen Anders"
let mutable status2 = "Seasonal"
timeWorked <- 38.00
// The first condition is False BUT the second condition is True:
verdict <- status2 = "Full-Time" || status2 = "Seasonal"

printfn "Employee Name:              %s" name
printfn "Time Worked:                %0.2f" timeWorked
printfn "Employment Status:          %s" status2
printfn "Condition-1 || Condition-2: %b" verdict
printfn "-------------------------------------------------------------"

if verdict = true then
    printfn "The time sheet has been approved."
else
    printfn "Time Sheet under review."
printfn "=============================================================="

name <- "Rose Sandt"
let status3 = "Full-Time"
timeWorked <- 44.00
// Both conditions are True:
verdict <- status3 = "Full-Time" || status2 = "Seasonal"

printfn "Employee Name:              %s" name
printfn "Time Worked:                %0.2f" timeWorked
printfn "Employment Status:          %s" status3
printfn "Condition-1 || Condition-2: %b" verdict
printfn "-------------------------------------------------------------"

if verdict = true then
    printfn "The time sheet has been approved."
else
    printfn "Part-time and seasonal employees must consult the management."
printfn "============================================================="

name <- "Joseph Lee"
let status4 = "Intern"
timeWorked <- 36.50
// Both conditions are False:
verdict <- status4 = "Unknown" || status4 = "No Availability"

printfn "Employee Name:              %s" name
printfn "Time Worked:                %0.2f" timeWorked
printfn "Employment Status:          %s" status4
printfn "Condition-1 || Condition-2: %b" verdict
printfn "-------------------------------------------------------------"

if verdict = true then
    printfn "Employees time sheets are subject to approval."
else
    printfn "New employees must consult the Human Resources department."
printfn "============================================================="

This would produce:

Employee Name:             Gabrielle Towa
Time Worked:               42.5
Employment Status:         Part-Time
Condition-1 ^ Condition-2: True
-------------------------------------------------------------
The time sheet has been approved.
=============================================================
Employee Name:             Stephen Anders
Time Worked:               38
Employment Status:         Seasonal
Condition-1 ^ Condition-2: True
-------------------------------------------------------------
The time sheet has been approved.
==============================================================
Employee Name:             Rose Sandt
Time Worked:               44
Employment Status:         Full-Time
Condition-1 ^ Condition-2: False
-------------------------------------------------------------
Part-time and seasonal employees must consult the management.
=============================================================
Employee Name:             Joseph Lee
Time Worked:               36.5
Employment Status:         Intern
Condition-1 ^ Condition-2: False
-------------------------------------------------------------
New employees must consult the Human Resources department.
=============================================================

Press any key to close this window . . .

Disjunction Equality

Remember that, in a Boolean conjunction or disjunction, you use two conditions and each condition performs its own comparison. As we saw with conjunctions, each condition of a disjunction can use its own variable for its comparison. Here is an example:

printfn "Job Requirements Evaluation"
printfn "========================================================================================================="
printf "Do you hold a degree - Undergraduate or Graduate (y/n)? "
let degree = char(stdin.ReadLine())
printf "Are you a certified programmer (Microsoft, Oracle, etc) (Type 1 for Yes or any number for No)? "
let certified = int(stdin.ReadLine())
printfn "---------------------------------------------------------------------------------------------------------"

if degree = 'y' || certified = 1 then
    printfn "Congratulations: We need to schedule the next interview (Human Resources) for you."
else
    printfn "This job requires either a college degree or a professional certification in application programming."

printfn "========================================================================================================="

Here is an example of running the application:

Job Requirements Evaluation
=========================================================================================================
Do you hold a degree - Undergraduate or Graduate (y/n)? n
Are you a certified programmer (Microsoft, Oracle, etc) (Type 1 for Yes or any number for No)? 1
---------------------------------------------------------------------------------------------------------
Congratulations: We need to schedule the next interview (Human Resources) for you.
=========================================================================================================

Press any key to close this window . . .

Here is another example of running the program:

Job Requirements Evaluation
=========================================================================================================
Do you hold a degree - Undergraduate or Graduate (y/n)? y
Are you a certified programmer (Microsoft, Oracle, etc) (Type 1 for Yes or any number for No)? 2
---------------------------------------------------------------------------------------------------------
Congratulations: We need to schedule the next interview (Human Resources) for you.
=========================================================================================================

Press any key to close this window . . .

Here is another example of the program:

Job Requirements Evaluation
=========================================================================================================
Do you hold a degree - Undergraduate or Graduate (y/n)? q
Are you a certified programmer (Microsoft, Oracle, etc) (Type 1 for Yes or any number for No)? 4
---------------------------------------------------------------------------------------------------------
This job requires either a college degree or a professional certification in application programming.
=========================================================================================================

Press any key to close this window . . .

Practical LearningPractical Learning: Applying a Disjunction

  1. Change the document as follows:
    printfn "=========================================="
    printfn " - Amazing DeltaX - State Income Tax -"
    printfn "=========================================="
    
    let mutable taxRate = 0.00
    let mutable stateName = ""
    
    printfn "Enter the information for tax preparation"
    printfn "States"
    printfn " AK - Alaska"
    printfn " AR - Arkansas"
    printfn " CO - Colorado"
    printfn " FL - Florida"
    printfn " GA - Georgia"
    printfn " IL - Illinois"
    printfn " IN - Indiana"
    printfn " KY - Kentucky"
    printfn " MA - Massachusetts"
    printfn " MI - Michigan"
    printfn " MO - Missouri"
    printfn " MS - Mississippi"
    printfn " NV - Nevada"
    printfn " NH - New Hampshire"
    printfn " NC - North Carolina"
    printfn " PA - Pennsylvania"
    printfn " SD - South Dakota"
    printfn " TN - Tennessee"
    printfn " TX - Texas"
    printfn " UT - Utah"
    printfn " WA - Washington"
    printfn " WY - Wyoming"
    printf "Enter State Abbreviation: "
    let abbr = stdin.ReadLine()
    printfn "--------------------------------------------"
            
    if (abbr = "IL") || (abbr = "UT") then
        taxRate <- 4.95
    
    printf "Gross Salary: "
    let grossSalary = float(stdin.ReadLine())
    
    let taxAmount   = grossSalary * taxRate / 100.00
    let netPay      = grossSalary - taxAmount
    
    printfn "============================================"
    printfn " - Amazing DeltaX - State Income Tax -"
    printfn "--------------------------------------------"
    printfn $"State Name:   {stateName}"
    printfn $"Gross Salary: {grossSalary:f}"
    printfn "Tax Rate:     %0.2f%c" taxRate '%'
    printfn "--------------------------------------------"
    printfn $"Tax Amount:   {taxAmount:f}"
    printfn $"Net Pay:      {netPay:f}"
    printfn "============================================"
  2. To execute the project, on the main menu, click Debug -> Start Without Debugging
  3. For the State Abbreviation, type UT and press Enter
  4. For the Gross Salary, type 1495.75 and press Enter:
    ==========================================
     - Amazing DeltaX - State Income Tax -
    ==========================================
    Enter the information for tax preparation
    States
     AK - Alaska
     AR - Arkansas
     CO - Colorado
     FL - Florida
     GA - Georgia
     IL - Illinois
     IN - Indiana
     KY - Kentucky
     MA - Massachusetts
     MI - Michigan
     MO - Missouri
     MS - Mississippi
     NV - Nevada
     NH - New Hampshire
     NC - North Carolina
     PA - Pennsylvania
     SD - South Dakota
     TN - Tennessee
     TX - Texas
     UT - Utah
     WA - Washington
     WY - Wyoming
    Enter State Abbreviation: UT
    --------------------------------------------
    Gross Salary: 1495.75
    ============================================
     - Amazing DeltaX - State Income Tax -
    --------------------------------------------
    Gross Salary: 1495.75
    Tax Rate:     4.95%
    --------------------------------------------
    Tax Amount:   74.04
    Net Pay:      1421.71
    ============================================
    Press any key to close this window . . .
  5. Close the form and return to your programming environment

Options on Performing Disjunctions

Omitting Checking Equality

In our introduction to conditional statements, we saw that, when a condition evaluates equality, apply an = true expression for the condition. Here is an example:

printfn "Job Requirements Evaluation"
printfn "=================================================================================="
let hasDegree = true
let certification = "F#"

printfn "Application has a degree:     %b" hasDegree
printfn "Application is ceretified in: %s" certification
printfn "----------------------------------------------------------------------------------"

// This job requires that an applicant either have a degree
// or have a certification in F#, Python, C#, Java, C++, or Java
if hasDegree = true || certification = "Python" then
    printfn "Congratulations: We need to schedule the next interview (Human Resources) for you."
else
    printfn "This job requires either a college degree or a professional certification in application programming."

printfn "=================================================================================="

This would produce:

Job Requirements Evaluation
==================================================================================
Application has a degree:     true
Application is ceretified in: F#
----------------------------------------------------------------------------------
Congratulations: We need to schedule the next interview (Human Resources) for you.
==================================================================================

Press any key to close this window . . .

As we know already, you can omit the = true expression for the condition. Here is an example:

printfn "Job Requirements Evaluation"
printfn "=================================================================================="
let hasDegree = true
let certification = "F#"

printfn "Application has a degree:     %b" hasDegree
printfn "Application is ceretified in: %s" certification
printfn "----------------------------------------------------------------------------------"

// This job requires that an applicant either have a degree
// or have a certification in F#, Python, C#, Java, C++, or Java
if hasDegree || certification = "Python" then
    printfn "Congratulations: We need to schedule the next interview (Human Resources) for you."
else
    printfn "This job requires either a college degree or a professional certification in application programming."

printfn "=================================================================================="

In the same way, if both conditions evaluates the truthfulness, you can omit the = true expression of each, from this:

printfn "Job Requirements Evaluation"
printfn "=================================================================================="
let hasDegree = true
let certified = true

printfn "Application has a degree:  %b" hasDegree
printfn "Application is ceretified: %b" certified
printfn "----------------------------------------------------------------------------------"

// This job requires that an applicant either have a degree
// or have a certification in F#, Python, C#, Java, C++, or Java
if hasDegree = true || certified = true then
    printfn "Congratulations: We need to schedule the next interview (Human Resources) for you."
else
    printfn "This job requires either a college degree or a professional certification in application programming."

printfn "=================================================================================="

To this:

printfn "Job Requirements Evaluation"
printfn "=================================================================================="
let hasDegree = true
let certified = true

printfn "Application has a degree:  %b" hasDegree
printfn "Application is ceretified: %b" certified
printfn "----------------------------------------------------------------------------------"

// This job requires that an applicant either have a degree
// or have a certification in F#, Python, C#, Java, C++, or Java
if hasDegree || certified then
    printfn "Congratulations: We need to schedule the next interview (Human Resources) for you."
else
    printfn "This job requires either a college degree or a professional certification in application programming."

printfn "=================================================================================="

Combining Disjunctions

You can create a conditional statement that includes as many disjunctions as you want. The formula to follow is:

condition1 || condition2 || . . . || condition_n

The rule is: If any one of the individual operations is true, the whole operation is true. The whole operation is false only if all the operations are false. Here is an example that uses three conoditions:

printfn "================================================================"

printfn "To grant you this job, we need to ask a few questions."
printfn "Levels of Security Clearance:"
printfn "0. Unknown or None"
printfn "1. Non-Sensitive"
printfn "2. National Security - Non-Critical Sensitive"
printfn "3. National Security - Critical Sensitive"
printfn "4. National Security - Special Sensitive"
printfn "----------------------------------------------------------------"
printf "Type your level (1-4): "
let level = int(stdin.ReadLine());
        
printfn "================================================================"
        
if level = 2 || level = 3 || level = 4 then
    printfn "Welcome on board."
else
    printfn "We will get back to you..."

printfn "================================================================"

Practical LearningPractical Learning: Introducing Logical Disjunctions

  1. Change the code as follows:
    printfn "=========================================="
    printfn " - Amazing DeltaX - State Income Tax -"
    printfn "=========================================="
    
    let mutable taxRate = 0.00
    let mutable stateName = ""
    
    printfn "Enter the information for tax preparation"
    printfn "States"
    printfn " AK - Alaska"
    printfn " AR - Arkansas"
    printfn " CO - Colorado"
    printfn " FL - Florida"
    printfn " GA - Georgia"
    printfn " IL - Illinois"
    printfn " IN - Indiana"
    printfn " KY - Kentucky"
    printfn " MA - Massachusetts"
    printfn " MI - Michigan"
    printfn " MO - Missouri"
    printfn " MS - Mississippi"
    printfn " NV - Nevada"
    printfn " NH - New Hampshire"
    printfn " NC - North Carolina"
    printfn " PA - Pennsylvania"
    printfn " SD - South Dakota"
    printfn " TN - Tennessee"
    printfn " TX - Texas"
    printfn " UT - Utah"
    printfn " WA - Washington"
    printfn " WY - Wyoming"
    printf "Enter State Abbreviation: "
    let abbr = stdin.ReadLine()
    printfn "--------------------------------------------"
            
    if (abbr = "IL") || (abbr = "UT") then
        taxRate <- 4.95
    elif (abbr = "KY") || (abbr = "MA") || (abbr = "NH") then
        taxRate <- 5.00
    elif (abbr = "FL") || (abbr = "NV") || (abbr = "TX") || (abbr = "WA") || (abbr = "WY") then
        taxRate <- 0.00
    
    printf "Gross Salary: "
    let grossSalary = float(stdin.ReadLine())
    
    let taxAmount   = grossSalary * taxRate / 100.00
    let netPay      = grossSalary - taxAmount
    
    printfn "============================================"
    printfn " - Amazing DeltaX - State Income Tax -"
    printfn "--------------------------------------------"
    printfn $"State Name:   {stateName}"
    printfn $"Gross Salary: {grossSalary:f}"
    printfn "Tax Rate:     %0.2f%c" taxRate '%'
    printfn "--------------------------------------------"
    printfn $"Tax Amount:   {taxAmount:f}"
    printfn $"Net Pay:      {netPay:f}"
    printfn "============================================"
  2. To execute the project, on the main menu, click Debug -> Start Without Debugging:
  3. For the State Abbreviation, type MA
  4. For the Gross Salary, type 2458.95 and press Enter
    ==========================================
     - Amazing DeltaX - State Income Tax -
    ==========================================
    Enter the information for tax preparation
    States
     AK - Alaska
     AR - Arkansas
     CO - Colorado
     FL - Florida
     GA - Georgia
     IL - Illinois
     IN - Indiana
     KY - Kentucky
     MA - Massachusetts
     MI - Michigan
     MO - Missouri
     MS - Mississippi
     NV - Nevada
     NH - New Hampshire
     NC - North Carolina
     PA - Pennsylvania
     SD - South Dakota
     TN - Tennessee
     TX - Texas
     UT - Utah
     WA - Washington
     WY - Wyoming
    Enter State Abbreviation: MA
    --------------------------------------------
    Gross Salary: 2458.95
    ============================================
     - Amazing DeltaX - State Income Tax -
    --------------------------------------------
    Gross Salary: 2458.95
    Tax Rate:     5.00%
    --------------------------------------------
    Tax Amount:   122.95
    Net Pay:      2336.00
    ============================================
    Press any key to close this window . . .
  5. Press T to close the window and return to your programming environment
  6. To execute the project, on the main menu, click Debug -> Start Without Debugging:
  7. For the State Abbreviation, type TX
  8. For the Gross Salary, type 2458.95 and press Enter
    ==========================================
     - Amazing DeltaX - State Income Tax -
    ==========================================
    Enter the information for tax preparation
    States
     AK - Alaska
     AR - Arkansas
     CO - Colorado
     FL - Florida
     GA - Georgia
     IL - Illinois
     IN - Indiana
     KY - Kentucky
     MA - Massachusetts
     MI - Michigan
     MO - Missouri
     MS - Mississippi
     NV - Nevada
     NH - New Hampshire
     NC - North Carolina
     PA - Pennsylvania
     SD - South Dakota
     TN - Tennessee
     TX - Texas
     UT - Utah
     WA - Washington
     WY - Wyoming
    Enter State Abbreviation: TX
    --------------------------------------------
    Gross Salary: 2458.95
    ============================================
     - Amazing DeltaX - State Income Tax -
    --------------------------------------------
    Gross Salary: 2458.95
    Tax Rate:     0.00%
    --------------------------------------------
    Tax Amount:   0.00
    Net Pay:      2458.95
    ============================================
    Press any key to close this window . . .
  9. Press G to close the window and return to your programming environment
  10. Close your programming environment

Previous Copyright © 2009-2024, FunctionX Sunday 17 September 2023 Next