squarewidget-3

FSharp · Script

/Program.cs

open System

// "Elementary propositions [p,q] are the truth-arguments of propositions" (5.01).

// "All propositions are results ['] of truth-operations on elementary propositions" (5.3).

// "Every truth-function is the result of  successive applications to elementary 
// propositions of the operation..." N(x) (5.5) where N(x) is the NOR operator below.

// Every truth-possibility for two elementary propositions p and q
// represented as rows in a truth table (4.31).
let truthTable = [
    (true,  true)   // Row 1
    (false,  true)  // Row 2
    (true, false)   // Row 3
    (false, false)  // Row 4
]

// Define a truth operation that evaluates a row (5.101). This replaces a 
// Fregean logical constant with a Sheffer Stroke.
let nor (a, b) = not (a || b)

// Helper for single-input negation using the Sheffer Stroke where  
// NOR ~a is equivalent to (a | a)
let neg a = nor (a, a)

// Replace logical constant AND with NOR: 
// a ∧ b is equivalent to (a | a) | (b | b)
let And = fun (a, b) -> nor (neg a, neg b)

// Replace logical constant OR with NOR: 
// a ∨ b is equivalent to (a | b) | (a | b)
let Or = fun (a, b) -> neg (nor (a, b))

// Replace logical constant IF-THEN with NOR: 
// a → b is equivalent to ((a | a) | b) | ((a | a) | b)
let Implies = fun (a, b) -> neg (nor (neg a, b))


// Evaluation operation runs over the truth-possibilities,
// enabling (T) or disabling (F) each row in logical space.
let evaluateOperation opName op =
    printfn "\nOperation: %s" opName
    printfn "------------"
    printfn "| p | q | ' "
    printfn "------------"
    
    // Helper to turn a bool into 'T' or 'F'
    let letterBool b = if b then 'T' else 'F'
    
    truthTable 
    |> List.iter (fun (p, q) ->
        let output = op (p, q)
        printfn "| %c | %c | %c" (letterBool p) (letterBool q) (letterBool output)
    )
    printfn ""

let main() =

    printfn "Generated propositional signs:"
    printfn ""
    
    printfn "\n(TFFF)(p, q)"
    evaluateOperation "AND (p ∧ q)" And

    printfn "\n(TTTF)(p, q)"
    evaluateOperation "OR (p ∨ q)" Or

    printfn "\n(TTFT)(p, q)"
    evaluateOperation "IF-THEN (p → q)" Implies // see 4.442

main()
;