Logic Proof Calculator

Logic Proof Calculator: Verify Your Deductions :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #ddd; –card-background: #fff; –shadow: 0 2px 5px rgba(0,0,0,0.1); } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(–background-color); color: var(–text-color); line-height: 1.6; margin: 0; padding: 0; display: flex; flex-direction: column; align-items: center; padding-top: 20px; padding-bottom: 40px; } .container { width: 100%; max-width: 960px; background-color: var(–card-background); padding: 30px; border-radius: 8px; box-shadow: var(–shadow); margin: 0 auto; box-sizing: border-box; } h1, h2, h3 { color: var(–primary-color); text-align: center; margin-bottom: 20px; } h1 { font-size: 2.2em; } h2 { font-size: 1.8em; margin-top: 30px; border-bottom: 2px solid var(–primary-color); padding-bottom: 10px; } h3 { font-size: 1.4em; margin-top: 25px; } .loan-calc-container { background-color: var(–card-background); padding: 25px; border-radius: 8px; box-shadow: var(–shadow); margin-bottom: 30px; } .input-group { margin-bottom: 20px; text-align: left; } .input-group label { display: block; margin-bottom: 8px; font-weight: bold; color: var(–primary-color); } .input-group input[type="text"], .input-group input[type="number"], .input-group select { width: calc(100% – 22px); padding: 12px; border: 1px solid var(–border-color); border-radius: 4px; font-size: 1em; box-sizing: border-box; } .input-group .helper-text { font-size: 0.85em; color: #666; margin-top: 5px; display: block; } .error-message { color: #dc3545; font-size: 0.85em; margin-top: 5px; display: block; min-height: 1.2em; } .button-group { display: flex; justify-content: space-between; margin-top: 25px; flex-wrap: wrap; gap: 10px; } .button-group button { padding: 12px 20px; border: none; border-radius: 5px; cursor: pointer; font-size: 1em; font-weight: bold; transition: background-color 0.3s ease; flex: 1; min-width: 150px; } .btn-calculate { background-color: var(–primary-color); color: white; } .btn-calculate:hover { background-color: #003366; } .btn-reset { background-color: #6c757d; color: white; } .btn-reset:hover { background-color: #5a6268; } .btn-copy { background-color: var(–success-color); color: white; } .btn-copy:hover { background-color: #218838; } #results-container { margin-top: 30px; padding: 25px; border: 1px solid var(–border-color); border-radius: 8px; background-color: var(–card-background); box-shadow: var(–shadow); } #results-container h3 { margin-top: 0; text-align: left; color: var(–primary-color); border-bottom: none; } .result-item { margin-bottom: 15px; font-size: 1.1em; } .result-item strong { color: var(–primary-color); display: inline-block; min-width: 200px; } .primary-result { background-color: var(–success-color); color: white; padding: 15px; border-radius: 5px; text-align: center; font-size: 1.5em; margin-bottom: 20px; box-shadow: inset 0 0 10px rgba(0,0,0,0.2); } .primary-result span { font-weight: bold; } .formula-explanation { font-size: 0.95em; color: #555; margin-top: 15px; padding-top: 15px; border-top: 1px dashed var(–border-color); } table { width: 100%; border-collapse: collapse; margin-top: 20px; margin-bottom: 30px; box-shadow: var(–shadow); overflow-x: auto; /* Mobile responsiveness */ display: block; /* Needed for overflow-x */ white-space: nowrap; /* Prevent wrapping in cells */ } thead { background-color: var(–primary-color); color: white; } th, td { padding: 12px 15px; text-align: left; border: 1px solid var(–border-color); } tbody tr:nth-child(even) { background-color: #f2f2f2; } caption { font-size: 1.1em; font-weight: bold; color: var(–primary-color); margin-bottom: 10px; text-align: left; } #chartContainer { width: 100%; max-width: 100%; /* Mobile responsiveness */ margin-top: 20px; background-color: var(–card-background); padding: 20px; border-radius: 8px; box-shadow: var(–shadow); overflow: hidden; /* Ensure canvas fits */ } #logicChart { display: block; max-width: 100%; height: auto; } .chart-caption { font-size: 1em; color: #555; text-align: center; margin-top: 10px; } .article-section { margin-top: 40px; padding: 30px; background-color: var(–card-background); border-radius: 8px; box-shadow: var(–shadow); } .article-section p, .article-section ul, .article-section ol { margin-bottom: 15px; } .article-section ul, .article-section ol { padding-left: 25px; } .article-section li { margin-bottom: 8px; } .faq-item { margin-bottom: 15px; } .faq-item strong { display: block; color: var(–primary-color); cursor: pointer; margin-bottom: 5px; } .faq-item p { margin-left: 15px; display: none; /* Hidden by default */ } .faq-item.active p { display: block; } .internal-links ul { list-style: none; padding: 0; } .internal-links li { margin-bottom: 10px; } .internal-links a { color: var(–primary-color); text-decoration: none; font-weight: bold; } .internal-links a:hover { text-decoration: underline; } .internal-links span { font-size: 0.9em; color: #555; display: block; margin-top: 3px; } @media (max-width: 768px) { .container { padding: 20px; } h1 { font-size: 1.8em; } h2 { font-size: 1.5em; } .button-group button { flex: 1 1 100%; min-width: unset; } .result-item strong { min-width: unset; display: block; margin-bottom: 5px; } table { font-size: 0.9em; } th, td { padding: 10px 12px; } }

Logic Proof Calculator

Verify the validity of your logical deductions and proofs with precision.

Logic Proof Verifier

Enter your premises, each on a new line. Use symbols like -> (implication), & (conjunction), | (disjunction), ~ (negation), ^ (for variables like P, Q, R).
Enter the conclusion you want to prove.
List each step of your proof, followed by its justification (rule and line numbers).

Proof Verification Results

Enter premises and steps to verify.
Number of Premises: 0
Number of Proof Steps: 0
Conclusion Verified: N/A
Validity Status: N/A
Verification Logic: The calculator checks if each step in the provided proof logically follows from the premises and previously established steps, using standard inference rules. It verifies if the final conclusion is derivable from the premises through the given sequence of steps.

Proof Analysis Table

Detailed breakdown of each step in your logical proof.
Step # Statement Justification Valid Step? Derivable From

Proof Validity Over Steps

Visual representation of step-by-step proof validity.

What is a Logic Proof Calculator?

A Logic Proof Calculator is a specialized tool designed to assist individuals in verifying the correctness and validity of logical arguments and proofs. In formal logic, a proof is a sequence of statements, each derived from preceding statements or axioms using established rules of inference. This calculator automates the process of checking whether each step in a given proof is sound and whether the final conclusion logically follows from the initial premises.

Who should use it?

  • Students of Logic and Philosophy: Essential for coursework, assignments, and understanding formal systems.
  • Mathematicians: To rigorously check derivations and theorems.
  • Computer Scientists: Particularly those in areas like theoretical computer science, artificial intelligence, and formal verification, where logical reasoning is paramount.
  • Anyone learning or working with formal logic: It provides immediate feedback and helps identify errors in reasoning.

Common Misconceptions:

  • It proves truth: A logic proof calculator verifies the *validity* of an argument (if premises are true, conclusion must be true), not the *truth* of the premises themselves. A valid argument with false premises can lead to a false conclusion.
  • It replaces understanding: While helpful, it doesn't substitute for learning the underlying principles of logic, inference rules, and logical fallacies.
  • It handles all types of logic: Most calculators focus on propositional or predicate logic. Complex modal, temporal, or non-classical logics may not be supported.

Logic Proof Calculator Formula and Mathematical Explanation

The core of a logic proof calculator isn't a single formula in the traditional sense, but rather an algorithmic process that simulates the application of logical inference rules. It systematically checks each step of a proposed proof against the premises and previously validated steps.

Step-by-Step Derivation (Algorithmic Process):

  1. Input Parsing: The calculator first parses the provided premises, conclusion, and the sequence of proof steps. It identifies the logical symbols and structures within each statement.
  2. Premise Validation: It confirms that the statements labeled as 'Premises' in the proof steps are indeed identical to the input premises.
  3. Step-by-Step Rule Application Check: For each subsequent step in the proof (beyond the initial premises):
    • It identifies the justification provided (e.g., "Modus Ponens", "Hypothetical Syllogism", "Premise").
    • It checks if the statement in the current step logically follows from the line numbers cited in the justification, using the specified inference rule.
    • It verifies that all variables (propositional letters like P, Q) used in the step are consistent.
  4. Conclusion Verification: After checking all steps, it verifies if the final stated conclusion is present as the last valid step in the proof sequence.
  5. Overall Validity Determination: The proof is deemed valid if all steps are correctly derived and the final conclusion is reached. If any step is invalid or the conclusion isn't reached, the proof is invalid.

Variable Explanations:

While not traditional variables in a numerical formula, the components of a logical statement act as variables:

  • Propositional Variables (e.g., P, Q, R): Represent basic declarative statements that can be true or false.
  • Logical Connectives: Symbols that combine or modify propositions (~ negation, & conjunction, | disjunction, -> implication, biconditional).
  • Inference Rules: Predefined rules that allow deriving new statements from existing ones (e.g., Modus Ponens, Modus Tollens, Hypothetical Syllogism).

Variables Table:

Variable/Component Meaning Unit Typical Range/Set
Propositional Variable (P, Q, etc.) A basic statement that is either true or false. Boolean (True/False) {True, False}
Premise An initial statement assumed to be true for the purpose of the proof. Logical Statement Any valid logical statement
Proof Step A statement derived within the proof sequence. Logical Statement Any valid logical statement
Inference Rule A rule governing the derivation of one statement from others. Rule Name (e.g., MP, MT) {Modus Ponens, Modus Tollens, HS, DC, Simp, Conj, Add, UI, UG, EI, EG, etc.}
Justification The rule and line numbers used to derive a proof step. Text String e.g., "Modus Ponens 1, 3"
Conclusion The final statement the proof aims to establish. Logical Statement Any valid logical statement

Practical Examples (Real-World Use Cases)

Logic proofs are fundamental in many fields. Here are a couple of examples demonstrating how a logic proof calculator can be used:

Example 1: Simple Propositional Logic (Modus Ponens)

Scenario: You are given two premises and want to see if a conclusion can be derived using a common rule.

Inputs:

  • Premises:
    If it is raining (R), then the ground is wet (W).
    It is raining (R).
  • Conclusion: The ground is wet (W).
  • Proof Steps:
    1. R -> W (Premise)
    2. R (Premise)
    3. W (Modus Ponens 1, 2)

Calculator Output:

  • Number of Premises: 2
  • Number of Proof Steps: 3
  • Conclusion Verified: Yes
  • Validity Status: Valid

Interpretation: The calculator confirms that the proof is valid. The conclusion 'The ground is wet' logically follows from the premises using the Modus Ponens rule, which states that if P implies Q, and P is true, then Q must be true.

Example 2: Slightly More Complex Proof (Hypothetical Syllogism)

Scenario: Verifying a chain of implications.

Inputs:

  • Premises:
    If I study hard (S), then I will pass the exam (P).
    If I pass the exam (P), then I will get a good grade (G).
  • Conclusion: If I study hard (S), then I will get a good grade (G).
  • Proof Steps:
    1. S -> P (Premise)
    2. P -> G (Premise)
    3. S -> G (Hypothetical Syllogism 1, 2)

Calculator Output:

  • Number of Premises: 2
  • Number of Proof Steps: 3
  • Conclusion Verified: Yes
  • Validity Status: Valid

Interpretation: The calculator validates this proof. The conclusion is reached using the Hypothetical Syllogism rule, demonstrating that if S implies P and P implies G, then S implies G. This is a transitive property of implication.

How to Use This Logic Proof Calculator

Using the Logic Proof Calculator is straightforward. Follow these steps to verify your logical arguments:

  1. Enter Premises: In the "Premises" text area, list each of your starting assumptions or known facts. Ensure each premise is on a new line. Use standard logical symbols (e.g., `->` for implication, `&` for conjunction, `|` for disjunction, `~` for negation).
  2. Enter Conclusion: In the "Conclusion" field, type the specific statement you aim to prove or verify.
  3. Enter Proof Steps: In the "Proof Steps" text area, meticulously list each step of your logical derivation. For each step, provide the statement itself and its justification, including the rule of inference used and the line numbers from which it was derived (e.g., "Modus Ponens 1, 3"). Steps that are premises should be marked as such.
  4. Verify Proof: Click the "Verify Proof" button.

How to Read Results:

  • Primary Result: This will clearly state whether the proof is "Valid" or "Invalid".
  • Intermediate Values: The calculator shows the count of premises and steps, and confirms if your stated conclusion was indeed the final derived statement.
  • Proof Analysis Table: This table provides a detailed breakdown. It shows each step, its justification, whether the step itself is valid based on its justification, and which preceding lines it logically derives from. This is crucial for pinpointing errors in invalid proofs.
  • Proof Validity Over Steps Chart: This visualizes the validity of each step. A consistent upward trend (or staying valid) indicates a sound proof.

Decision-Making Guidance:

  • If the calculator returns "Valid", your proof is logically sound, meaning the conclusion necessarily follows from the premises.
  • If it returns "Invalid", carefully examine the "Proof Analysis Table". Look for steps marked "No" in the "Valid Step?" column. The table will indicate which lines were used for the invalid derivation, helping you identify the specific error in your reasoning.

Key Factors That Affect Logic Proof Results

While the validity of a logic proof is determined by the rules of inference, several factors influence the process and the interpretation of results:

  1. Correctness of Inference Rules: The calculator relies on a predefined set of standard inference rules (like Modus Ponens, Modus Tollens, Hypothetical Syllogism, etc.). If the proof uses non-standard or incorrectly applied rules, the calculator will flag it as invalid.
  2. Accuracy of Justifications: Each step must be correctly justified with the appropriate rule and the correct line numbers. A typo in a line number or rule name can invalidate the entire proof sequence.
  3. Consistency of Propositional Variables: Ensure that the same propositional variable (e.g., 'P') consistently represents the same underlying statement throughout the proof. Mixing meanings will lead to invalid derivations.
  4. Completeness of Premises: The proof is only as strong as its premises. If essential premises are missing, a valid conclusion might not be derivable. The calculator verifies derivability from *given* premises.
  5. Scope of the Logical System: The calculator typically operates within propositional or first-order predicate logic. Proofs requiring more advanced logics (e.g., modal logic, temporal logic) might not be verifiable by this tool.
  6. Formalization Accuracy: Translating real-world statements into formal logical notation can be challenging. Ambiguities in natural language can lead to incorrect formalization, making a seemingly valid argument appear invalid in its formal representation.
  7. Order of Steps: While the final conclusion matters, the sequence of steps is critical. Each step must build logically on the ones before it. Reordering steps incorrectly can break the chain of reasoning.
  8. Typographical Errors: Simple typos in symbols, variable names, or structure can cause the calculator to reject a step, even if the intended logic was sound.

Frequently Asked Questions (FAQ)

What is the difference between a valid proof and a true conclusion?

A proof is valid if the conclusion logically follows from the premises. This means that *if* the premises were true, the conclusion *must* also be true. A conclusion is true if it corresponds to reality. A valid proof can have a false conclusion if one or more of its premises are false.

Can this calculator find errors in my reasoning?

Yes, that is its primary function. If your proof is invalid, the calculator will indicate it and the analysis table will help pinpoint the specific step and justification that is incorrect.

What logical symbols should I use?

Common symbols include: `~` (negation), `&` (conjunction), `|` (disjunction), `->` (implication), " (biconditional). Variables are typically represented by capital letters like P, Q, R. Check the helper text for specific guidance.

What are common inference rules?

Common rules include Modus Ponens (MP), Modus Tollens (MT), Hypothetical Syllogism (HS), Disjunctive Syllogism (DS), Simplification (Simp), Conjunction (Conj), Addition (Add), Universal Instantiation (UI), Universal Generalization (UG), Existential Instantiation (EI), and Existential Generalization (EG).

My proof is complex. Can the calculator handle it?

The calculator can handle proofs of considerable length and complexity within standard propositional and predicate logic. However, extremely convoluted proofs or those requiring advanced logical systems might exceed its capabilities or require careful input formatting.

What if my justification uses a rule not listed?

If your proof relies on a less common rule or a derived rule, you may need to break it down into steps that use the standard rules supported by the calculator, or ensure the rule is commonly accepted within the logical system you are working with.

How does the calculator handle predicate logic (quantifiers)?

This calculator primarily focuses on propositional logic for simplicity, but the input format allows for basic predicate logic statements if you use standard notation. Full predicate logic verification requires more complex parsing and rule application, which might be limited in this version.

Can I use this for informal arguments?

This calculator is designed for formal logical proofs. While it can help analyze the structure of informal arguments if they are translated into formal statements, it cannot directly assess the nuances or potential fallacies in everyday language arguments.

Related Tools and Internal Resources

© 2023 Logic Tools Inc. All rights reserved.

// — Calculator Logic — function getElement(id) { return document.getElementById(id); } function parseLogicStatement(statement) { statement = statement.trim(); if (!statement) return null; // Basic parsing: identify variables, connectives. More complex parsing needed for full predicate logic. // For now, we'll treat the whole string as the statement representation. return statement; } function parsePremises(premisesString) { var premises = []; if (premisesString) { var lines = premisesString.split('\n'); for (var i = 0; i < lines.length; i++) { var premise = lines[i].trim(); if (premise) { premises.push(premise); } } } return premises; } function parseProofSteps(stepsString) { var steps = []; if (stepsString) { var lines = stepsString.split('\n'); for (var i = 0; i 1) { justification = parts.slice(1).join('(').replace(/\)$/, ").trim(); // Remove trailing parenthesis } steps.push({ statement: statement, justification: justification, isValid: false, derivedFrom: [] }); } } } return steps; } function getLineNumbersFromJustification(justification) { var numbers = []; var regex = /(\d+)/g; var match; while ((match = regex.exec(justification)) !== null) { numbers.push(parseInt(match[1], 10)); } return numbers; } // Mock function for checking rule validity – in a real scenario, this would be complex. // This simplified version checks if the justification format is plausible and if line numbers exist. function isStepValid(stepIndex, steps, premises, conclusion) { var currentStep = steps[stepIndex]; var justification = currentStep.justification; var rule = justification.split(' ')[0]; var lineNumbers = getLineNumbersFromJustification(justification); // Basic checks if (!rule) return { valid: false, reason: "Missing rule name." }; if (rule.toLowerCase() === 'premise') { if (lineNumbers.length > 0) return { valid: false, reason: "Premises should not cite line numbers." }; // Check if the statement is actually one of the input premises var isActualPremise = false; for (var i = 0; i < premises.length; i++) { if (currentStep.statement === premises[i]) { isActualPremise = true; break; } } if (!isActualPremise) return { valid: false, reason: "Statement is not listed as a premise." }; return { valid: true, reason: "Correctly identified as a premise." }; } if (lineNumbers.length === 0 && rule.toLowerCase() !== 'premise') { return { valid: false, reason: "Rule requires line numbers for justification." }; } // Check if cited line numbers are valid and exist for (var i = 0; i < lineNumbers.length; i++) { var citedLineNum = lineNumbers[i]; if (citedLineNum steps.length) { return { valid: false, reason: "Invalid line number cited: " + citedLineNum }; } // Ensure cited line is before the current step if (citedLineNum > (stepIndex + 1)) { return { valid: false, reason: "Cannot cite future steps: " + citedLineNum }; } } // Simulate rule checks (highly simplified) var citedStatements = []; for (var i = 0; i = 0 && citedLineIndex Q, P, therefore Q) if (rule.toLowerCase() === 'modus ponens' || rule.toLowerCase() === 'mp') { if (citedStatements.length === 2) { var premise1 = citedStatements[0]; var premise2 = citedStatements[1]; // Check if one is implication and the other is the antecedent var implication = null; var antecedent = null; if (premise1.statement.includes('->')) { var parts = premise1.statement.split('->'); if (parts.length === 2) { implication = { antecedent: parts[0].trim(), consequent: parts[1].trim() }; } } if (premise2.statement.includes('->')) { var parts = premise2.statement.split('->'); if (parts.length === 2) { implication = { antecedent: parts[0].trim(), consequent: parts[1].trim() }; } } if (implication) { if (premise1.statement === premise2.statement) { // Avoid using the same line twice return { valid: false, reason: "Cannot use the same line twice for MP." }; } if (premise1.statement === implication.antecedent && premise2.statement === implication.antecedent) { // Both are antecedents, need one implication } else if (premise1.statement === implication.antecedent && premise2.statement !== implication.antecedent) { antecedent = premise1.statement; } else if (premise2.statement === implication.antecedent && premise1.statement !== implication.antecedent) { antecedent = premise2.statement; } else { // Check if one is implication and the other is antecedent if (premise1.statement.includes('->')) { var impParts = premise1.statement.split('->'); if (impParts.length === 2 && impParts[0].trim() === premise2.statement) { implication = { antecedent: impParts[0].trim(), consequent: impParts[1].trim() }; antecedent = premise2.statement; } } if (!implication || !antecedent) { if (premise2.statement.includes('->')) { var impParts = premise2.statement.split('->'); if (impParts.length === 2 && impParts[0].trim() === premise1.statement) { implication = { antecedent: impParts[0].trim(), consequent: impParts[1].trim() }; antecedent = premise1.statement; } } } } } if (implication && antecedent && implication.antecedent === antecedent) { if (currentStep.statement === implication.consequent) { return { valid: true, reason: "Correct application of Modus Ponens." }; } else { return { valid: false, reason: "Statement does not match the consequent of the implication." }; } } else { return { valid: false, reason: "Incorrect format for Modus Ponens premises." }; } } else { return { valid: false, reason: "Modus Ponens requires exactly two cited lines." }; } } // Example: Hypothetical Syllogism (P -> Q, Q -> R, therefore P -> R) if (rule.toLowerCase() === 'hypothetical syllogism' || rule.toLowerCase() === 'hs') { if (citedStatements.length === 2) { var imp1 = null; var imp2 = null; if (citedStatements[0].statement.includes('->')) { var parts = citedStatements[0].statement.split('->'); if (parts.length === 2) imp1 = { antecedent: parts[0].trim(), consequent: parts[1].trim() }; } if (citedStatements[1].statement.includes('->')) { var parts = citedStatements[1].statement.split('->'); if (parts.length === 2) imp2 = { antecedent: parts[0].trim(), consequent: parts[1].trim() }; } if (imp1 && imp2) { if (imp1.consequent === imp2.antecedent) { if (currentStep.statement === (imp1.antecedent + " -> " + imp2.consequent)) { return { valid: true, reason: "Correct application of Hypothetical Syllogism." }; } else { return { valid: false, reason: "Resulting implication does not match." }; } } else if (imp2.consequent === imp1.antecedent) { // Check reversed order if (currentStep.statement === (imp2.antecedent + " -> " + imp1.consequent)) { return { valid: true, reason: "Correct application of Hypothetical Syllogism." }; } else { return { valid: false, reason: "Resulting implication does not match." }; } } else { return { valid: false, reason: "Consequent of one implication must match antecedent of the other." }; } } else { return { valid: false, reason: "Both cited lines must be implications." }; } } else { return { valid: false, reason: "Hypothetical Syllogism requires exactly two cited lines." }; } } // Add more rule checks here… // For now, assume unknown rules are invalid for simplicity return { valid: false, reason: "Rule '" + rule + "' not recognized or implemented." }; } function calculateLogicProof() { var premisesString = getElement("premises").value; var conclusionString = getElement("conclusion").value.trim(); var proofStepsString = getElement("proofSteps").value; // Clear previous errors and results getElement("premisesError").textContent = ""; getElement("conclusionError").textContent = ""; getElement("proofStepsError").textContent = ""; getElement("numPremises").textContent = "0"; getElement("numSteps").textContent = "0"; getElement("conclusionVerified").textContent = "N/A"; getElement("validityStatus").textContent = "N/A"; getElement("primaryResult").innerHTML = "Enter premises and steps to verify."; getElement("proofTable").getElementsByTagName('tbody')[0].innerHTML = ""; clearChart(); var premises = parsePremises(premisesString); var proofSteps = parseProofSteps(proofStepsString); var conclusion = parseLogicStatement(conclusionString); if (premises.length === 0) { getElement("premisesError").textContent = "Please enter at least one premise."; return; } if (!conclusion) { getElement("conclusionError").textContent = "Please enter a conclusion."; return; } if (proofSteps.length === 0) { getElement("proofStepsError").textContent = "Please enter the proof steps."; return; } getElement("numPremises").textContent = premises.length; getElement("numSteps").textContent = proofSteps.length; var allStepsValid = true; var stepValidityData = []; var validStepsCount = 0; var chartData = []; // [stepNumber, isValid (0 or 1)] for (var i = 0; i 0) { if (proofSteps[proofSteps.length – 1].statement === conclusion) { conclusionVerified = true; } } getElement("conclusionVerified").textContent = conclusionVerified ? "Yes" : "No"; var finalStatus = "Invalid"; if (allStepsValid && conclusionVerified) { finalStatus = "Valid"; getElement("primaryResult").innerHTML = "Proof is VALID!"; } else { getElement("primaryResult").innerHTML = "Proof is INVALID."; } getElement("validityStatus").textContent = finalStatus; // Populate table var tableBody = getElement("proofTable").getElementsByTagName('tbody')[0]; for (var i = 0; i Q\nP"; getElement("conclusion").value = "Q"; getElement("proofSteps").value = "1. P -> Q (Premise)\n2. P (Premise)\n3. Q (Modus Ponens 1, 2)"; getElement("premisesError").textContent = ""; getElement("conclusionError").textContent = ""; getElement("proofStepsError").textContent = ""; getElement("numPremises").textContent = "0"; getElement("numSteps").textContent = "0"; getElement("conclusionVerified").textContent = "N/A"; getElement("validityStatus").textContent = "N/A"; getElement("primaryResult").innerHTML = "Enter premises and steps to verify."; getElement("proofTable").getElementsByTagName('tbody')[0].innerHTML = ""; clearChart(); } function copyResults() { var premises = getElement("premises").value; var conclusion = getElement("conclusion").value; var proofSteps = getElement("proofSteps").value; var numPremises = getElement("numPremises").textContent; var numSteps = getElement("numSteps").textContent; var conclusionVerified = getElement("conclusionVerified").textContent; var validityStatus = getElement("validityStatus").textContent; var primaryResult = getElement("primaryResult").innerText; // Use textContent for plain text var tableRows = getElement("proofTable").getElementsByTagName('tbody')[0].rows; var tableContent = "Step # | Statement | Justification | Valid Step? | Derivable From\n"; for (var i = 0; i < tableRows.length; i++) { var cells = tableRows[i].cells; tableContent += cells[0].textContent + " | " + cells[1].textContent + " | " + cells[2].textContent + " | " + cells[3].textContent + " | " + cells[4].textContent + "\n"; } var copyText = `— Logic Proof Verification — Premises: ${premises} Conclusion: ${conclusion} Proof Steps: ${proofSteps} — Results — Number of Premises: ${numPremises} Number of Proof Steps: ${numSteps} Conclusion Verified: ${conclusionVerified} Validity Status: ${validityStatus} Primary Result: ${primaryResult} — Analysis Table — ${tableContent} — Key Assumptions — – Standard logical inference rules are applied. – Propositional variables maintain consistent meaning. – Input format adheres to standard logical notation.`; navigator.clipboard.writeText(copyText).then(function() { // Optional: Show a confirmation message var originalText = getElement("results-container").querySelector('.btn-copy').textContent; getElement("results-container").querySelector('.btn-copy').textContent = "Copied!"; setTimeout(function() { getElement("results-container").querySelector('.btn-copy').textContent = originalText; }, 2000); }, function(err) { console.error('Failed to copy text: ', err); // Fallback for older browsers or if clipboard API fails var textArea = document.createElement("textarea"); textArea.value = copyText; textArea.style.position = "fixed"; textArea.style.left = "-9999px"; document.body.appendChild(textArea); textArea.focus(); textArea.select(); try { document.execCommand('copy'); var originalText = getElement("results-container").querySelector('.btn-copy').textContent; getElement("results-container").querySelector('.btn-copy').textContent = "Copied!"; setTimeout(function() { getElement("results-container").querySelector('.btn-copy').textContent = originalText; }, 2000); } catch (err) { console.error('Fallback copy failed: ', err); var originalText = getElement("results-container").querySelector('.btn-copy').textContent; getElement("results-container").querySelector('.btn-copy').textContent = "Copy Failed"; setTimeout(function() { getElement("results-container").querySelector('.btn-copy').textContent = originalText; }, 2000); } document.body.removeChild(textArea); }); } // — Charting Logic (Pure JS/Canvas) — var myChart; // Global variable to hold chart instance function updateChart(data) { var ctx = getElement('logicChart').getContext('2d'); // Clear previous chart if it exists if (myChart) { myChart.destroy(); } // Ensure canvas is cleared before drawing ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); // Set canvas dimensions to fill container, respecting aspect ratio var chartContainer = getElement('chartContainer'); ctx.canvas.width = chartContainer.clientWidth; ctx.canvas.height = Math.min(chartContainer.clientWidth * 0.5, 400); // Limit height var labels = data.map(function(item) { return 'Step ' + item[0]; }); var validityValues = data.map(function(item) { return item[1]; }); // 1 for valid, 0 for invalid myChart = new Chart(ctx, { type: 'bar', // Use bar chart for step-by-step validity data: { labels: labels, datasets: [{ label: 'Step Validity (1=Valid, 0=Invalid)', data: validityValues, backgroundColor: validityValues.map(function(val) { return val === 1 ? 'rgba(40, 167, 69, 0.7)' : 'rgba(220, 53, 69, 0.7)'; // Green for valid, Red for invalid }), borderColor: validityValues.map(function(val) { return val === 1 ? 'rgba(40, 167, 69, 1)' : 'rgba(220, 53, 69, 1)'; }), borderWidth: 1 }] }, options: { responsive: true, maintainAspectRatio: false, // Allow custom aspect ratio scales: { y: { beginAtZero: true, max: 1, // Only 0 or 1 ticks: { callback: function(value) { if (value === 1) return 'Valid'; if (value === 0) return 'Invalid'; return ''; } } } }, plugins: { legend: { display: true, position: 'top', }, tooltip: { callbacks: { label: function(context) { var label = context.dataset.label || ''; if (label) { label += ': '; } if (context.parsed.y === 1) { label += 'Valid'; } else { label += 'Invalid'; } return label; } } } } } }); } function clearChart() { var ctx = getElement('logicChart').getContext('2d'); ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); if (myChart) { myChart.destroy(); myChart = null; } // Reset chart caption if needed getElement('chartContainer').querySelector('.chart-caption').textContent = "Visual representation of step-by-step proof validity."; } // — FAQ Toggle — function toggleFaq(element) { var parent = element.parentElement; parent.classList.toggle('active'); } // — Initial Setup — document.addEventListener('DOMContentLoaded', function() { // Initialize chart with placeholder data or clear it clearChart(); // Set initial values for calculation if needed, or wait for user input // calculateLogicProof(); // Optionally run calculation on load if defaults are set }); // — Chart.js Library (Embedded) — // NOTE: In a real-world scenario, Chart.js would be included via a CDN or local file. // For this self-contained HTML, we'll assume it's available globally. // If running this code directly, you MUST include Chart.js library. // Example CDN: // Since we cannot include external scripts, this is a placeholder. // The code above assumes `new Chart(…)` is available. // Placeholder for Chart.js if not loaded externally if (typeof Chart === 'undefined') { console.warn("Chart.js library not found. Charts will not render. Please include Chart.js."); // Define a dummy Chart object to prevent runtime errors if the library is missing window.Chart = function() { this.destroy = function() {}; }; window.Chart.prototype.destroy = function() {}; }

Leave a Comment