Logic Derivation Calculator

Logic Derivation Calculator & Guide – Master Logical Reasoning :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; } .container { max-width: 1000px; margin: 20px auto; padding: 20px; background-color: var(–card-background); border-radius: 8px; box-shadow: var(–shadow); } header { background-color: var(–primary-color); color: white; padding: 20px 0; text-align: center; margin-bottom: 20px; border-radius: 8px 8px 0 0; } header h1 { margin: 0; font-size: 2.5em; } h1, h2, h3 { color: var(–primary-color); } h1 { font-size: 2.2em; text-align: center; margin-bottom: 15px; } h2 { font-size: 1.8em; margin-top: 30px; margin-bottom: 15px; border-bottom: 2px solid var(–primary-color); padding-bottom: 5px; } h3 { font-size: 1.4em; margin-top: 20px; margin-bottom: 10px; } .calculator-section { background-color: var(–card-background); padding: 30px; border-radius: 8px; box-shadow: var(–shadow); margin-bottom: 30px; } .loan-calc-container { display: flex; flex-direction: column; gap: 20px; } .input-group { display: flex; flex-direction: column; gap: 8px; } .input-group label { font-weight: bold; color: var(–primary-color); } .input-group input[type="number"], .input-group select { padding: 12px; border: 1px solid var(–border-color); border-radius: 4px; font-size: 1em; box-sizing: border-box; } .input-group input[type="number"]:focus, .input-group select:focus { outline: none; border-color: var(–primary-color); box-shadow: 0 0 0 2px rgba(0, 74, 153, 0.2); } .input-group .helper-text { font-size: 0.85em; color: #666; } .error-message { color: red; font-size: 0.8em; margin-top: 5px; min-height: 1.2em; /* Prevent layout shifts */ } .button-group { display: flex; gap: 10px; margin-top: 25px; flex-wrap: wrap; } button { padding: 12px 20px; border: none; border-radius: 4px; cursor: pointer; font-size: 1em; font-weight: bold; transition: background-color 0.3s ease; } .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: #ffc107; color: #212529; } .btn-copy:hover { background-color: #e0a800; } #results-container { margin-top: 30px; padding: 25px; background-color: #e7f3ff; border-left: 5px solid var(–primary-color); border-radius: 4px; display: none; /* Hidden by default */ } #results-container h3 { margin-top: 0; color: var(–primary-color); } .primary-result { font-size: 2em; font-weight: bold; color: var(–primary-color); margin-bottom: 15px; padding: 10px; background-color: white; border-radius: 4px; text-align: center; } .intermediate-values p, .formula-explanation p { margin: 8px 0; font-size: 1.1em; } .formula-explanation { margin-top: 15px; font-style: italic; color: #555; } table { width: 100%; border-collapse: collapse; margin-top: 20px; box-shadow: var(–shadow); } th, td { padding: 12px 15px; text-align: left; border: 1px solid var(–border-color); } thead { background-color: var(–primary-color); color: white; } 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; } canvas { display: block; margin: 20px auto; max-width: 100%; border: 1px solid var(–border-color); border-radius: 4px; } .article-content { margin-top: 40px; background-color: var(–card-background); padding: 30px; border-radius: 8px; box-shadow: var(–shadow); } .article-content p, .article-content ul, .article-content ol { margin-bottom: 15px; } .article-content ul, .article-content ol { padding-left: 25px; } .article-content li { margin-bottom: 8px; } .faq-item { margin-bottom: 15px; border-bottom: 1px dashed var(–border-color); padding-bottom: 10px; } .faq-item:last-child { border-bottom: none; } .faq-question { font-weight: bold; color: var(–primary-color); cursor: pointer; display: block; margin-bottom: 5px; } .faq-answer { display: none; /* Hidden by default */ padding-left: 10px; font-size: 0.95em; color: #555; } .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: #666; display: block; margin-top: 3px; } @media (min-width: 768px) { .container { padding: 30px; } .loan-calc-container { flex-direction: column; } .input-group input[type="number"], .input-group select { max-width: 300px; /* Limit width for better readability on desktop */ } .button-group { justify-content: flex-start; } }

Logic Derivation Calculator

Logic Derivation Calculator

Input your logical premises and rules to derive conclusions. This calculator helps visualize the process and verify logical steps.

Q">
Modus Ponens (If P->Q and P, then Q) Modus Tollens (If P->Q and not Q, then not P) Hypothetical Syllogism (If P->Q and Q->R, then P->R) Disjunctive Syllogism (If P or Q and not P, then Q)
Select the logical rule to apply.
R">
Required for Hypothetical Syllogism.
Required for Disjunctive Syllogism.

Derivation Results

Intermediate Value 1:

Intermediate Value 2:

Intermediate Value 3:

Formula Used:

Derivation Visualization

Visualization of premise strength and conclusion certainty.

Derivation Steps Summary

Step Premise/Rule Statement Certainty (%)

Summary of logical steps and their certainty.

What is Logic Derivation?

Logic derivation, also known as logical inference or deduction, is the process of deriving new conclusions from existing statements (premises) using established rules of logic. It's a fundamental tool in critical thinking, mathematics, computer science, and philosophy. The goal is to determine if a conclusion necessarily follows from a set of premises. If the premises are true and the rules of inference are valid, then the conclusion derived must also be true. This calculator is designed to help you understand and practice these core principles of logic derivation.

Who Should Use a Logic Derivation Calculator?

Anyone looking to strengthen their reasoning skills can benefit from a logic derivation calculator. This includes:

  • Students: Studying logic, mathematics, computer science, or philosophy.
  • Programmers & Developers: Designing algorithms, debugging code, and understanding formal logic in programming languages.
  • Researchers & Academics: Formulating hypotheses, constructing proofs, and analyzing arguments.
  • Debaters & Critical Thinkers: Evaluating arguments, identifying fallacies, and constructing sound reasoning.
  • Problem Solvers: Applying structured thinking to complex challenges in any field.

Common Misconceptions about Logic Derivation

Several misconceptions can hinder the understanding of logic derivation:

  • Confusing Validity with Truth: A valid argument means the conclusion logically follows from the premises. It doesn't guarantee the premises (or conclusion) are factually true in the real world.
  • Assuming All Reasoning is Deductive: While deduction provides certainty, other forms of reasoning like induction (generalizing from specific observations) and abduction (finding the best explanation) are also crucial but don't offer the same level of certainty.
  • Believing Logic is Rigid and Uncreative: While logic follows strict rules, applying them creatively to new problems and formulating novel arguments is a highly creative process.
  • Overlooking the Importance of Premises: The strength of a derived conclusion is entirely dependent on the truth and relevance of the initial premises. Garbage in, garbage out.

Logic Derivation Formula and Mathematical Explanation

Logic derivation doesn't rely on a single numerical formula like financial calculators. Instead, it uses a set of rules of inference to manipulate logical statements. These rules are essentially templates for valid arguments. The "calculation" involves applying these rules systematically.

Key Rules of Inference:

  • Modus Ponens (MP): If you have a conditional statement "If P, then Q" (P → Q) and you know that the antecedent P is true, you can conclude that the consequent Q is true.
    Formula: (P → Q), P ⊢ Q
  • Modus Tollens (MT): If you have a conditional statement "If P, then Q" (P → Q) and you know that the consequent Q is false (¬Q), you can conclude that the antecedent P is false (¬P).
    Formula: (P → Q), ¬Q ⊢ ¬P
  • Hypothetical Syllogism (HS): If you have two conditional statements, "If P, then Q" (P → Q) and "If Q, then R" (Q → R), you can conclude a new conditional statement "If P, then R" (P → R).
    Formula: (P → Q), (Q → R) ⊢ (P → R)
  • Disjunctive Syllogism (DS): If you have a disjunction "P or Q" (P ∨ Q) and you know that one of the disjuncts is false (e.g., ¬P), you can conclude that the other disjunct must be true (Q).
    Formula: (P ∨ Q), ¬P ⊢ Q

Variable Explanations and Certainty

In logic derivation, variables (like P, Q, R) represent propositions – statements that can be either true or false. The "certainty" is typically binary: 100% if derived validly, or 0% if not. However, for visualization, we can represent the certainty of premises as input and track how it propagates. A conclusion derived from premises with 100% certainty inherits that 100% certainty.

Variables Table

Variable Meaning Unit Typical Range
P, Q, R, … Propositional variables (statements that are true or false) Boolean (True/False) N/A (Represents truth values)
→ (implies) Conditional operator (If… then…) Logical Operator N/A
∨ (or) Disjunction operator (Either… or…) Logical Operator N/A
¬ (not) Negation operator Logical Operator N/A
⊢ (entails) Symbol indicating entailment or derivation Logical Symbol N/A
Certainty (%) Confidence in the truth of a premise or derived conclusion Percentage 0% – 100%

Practical Examples (Real-World Use Cases)

Example 1: Modus Ponens in Action

Scenario: You're trying to determine if it will rain today.

Premise 1: If the sky is cloudy, then it will rain. (Cloudy → Rain)

Premise 2: The sky is cloudy. (Cloudy)

Rule: Modus Ponens

Calculator Inputs:

  • Premise 1: Cloudy -> Rain
  • Premise 2: Cloudy
  • Rule: Modus Ponens

Calculator Output:

  • Primary Result: It will rain. (Certainty: 100%)
  • Intermediate Value 1: Premise 1 (Cloudy → Rain)
  • Intermediate Value 2: Premise 2 (Cloudy)
  • Intermediate Value 3: Antecedent (Cloudy) is true.
  • Formula Used: Modus Ponens: If P implies Q, and P is true, then Q is true.

Interpretation: Based on the given information and the rule of Modus Ponens, the conclusion that it will rain is logically sound and certain.

Example 2: Hypothetical Syllogism for Planning

Scenario: Planning a project timeline.

Premise 1: If Task A is completed, then Task B can begin. (A → B)

Premise 2: If Task B is completed, then Task C can begin. (B → C)

Rule: Hypothetical Syllogism

Calculator Inputs:

  • Premise 1: A -> B
  • Premise 2: (Not used directly for HS, but context)
  • Rule: Hypothetical Syllogism
  • Additional Premise for HS: B -> C

Calculator Output:

  • Primary Result: If Task A is completed, then Task C can begin. (A → C) (Certainty: 100%)
  • Intermediate Value 1: Premise 1 (A → B)
  • Intermediate Value 2: Additional Premise (B → C)
  • Intermediate Value 3: Transitive link established.
  • Formula Used: Hypothetical Syllogism: If P implies Q, and Q implies R, then P implies R.

Interpretation: This allows for efficient planning by establishing a direct dependency between Task A and Task C, even though they are not directly sequential. It simplifies the understanding of the project flow.

How to Use This Logic Derivation Calculator

  1. Identify Premises: Clearly state the initial statements or facts you are working with. These are your premises.
  2. Input Premises: Enter your first premise into the "Premise 1" field. Use standard logical notation (e.g., `P->Q` for "If P, then Q", `P` for "P is true", `~P` for "Not P", `P v Q` for "P or Q").
  3. Input Second Premise: Enter your second relevant statement into the "Premise 2" field.
  4. Select Rule: Choose the appropriate rule of inference from the dropdown menu that best fits the relationship between your premises (e.g., Modus Ponens, Modus Tollens).
  5. Provide Additional Premises (If Needed): For rules like Hypothetical Syllogism or Disjunctive Syllogism, you might need to enter a third statement in the relevant field ("Additional Premise for HS" or "Additional Premise for DS").
  6. Derive Conclusion: Click the "Derive Conclusion" button.

How to Read Results

  • Primary Result: This is the conclusion derived from your inputs. It will state the derived proposition and its certainty (usually 100% if validly derived).
  • Intermediate Values: These show the key components used in the derivation (e.g., the specific premises, the antecedent/consequent, the disjuncts).
  • Formula Explanation: This reiterates the rule of inference applied.
  • Table & Chart: The table summarizes the steps, and the chart visualizes the certainty.

Decision-Making Guidance

Use the results to confirm the logical validity of your reasoning. If the calculator produces a conclusion, it means that conclusion is a necessary consequence of your premises. If you cannot derive a conclusion using the available rules, it might mean your premises are insufficient or the relationship doesn't allow for a direct deduction. This helps in identifying gaps in your arguments or understanding.

Key Factors That Affect Logic Derivation Results

While logic derivation itself aims for certainty, the *applicability* and *interpretation* of its results depend on several factors:

  1. Truth of Premises: This is paramount. Logic guarantees that *if* the premises are true, the conclusion is true. If any premise is false, the conclusion, even if validly derived, might be false. This is the difference between logical validity and factual accuracy.
  2. Correctness of the Rule Applied: Using the wrong rule of inference (e.g., affirming the consequent, which is a fallacy) will lead to an invalid conclusion, even if the premises seem plausible.
  3. Completeness of Premises: Sometimes, a conclusion cannot be derived because not enough information (premises) is provided. The calculator might not yield a result if the inputs don't fit a standard rule.
  4. Clarity of Propositional Statements: Ambiguous or poorly defined statements used as premises can lead to confusion and make logical manipulation difficult or meaningless. Formal logic requires precise statements.
  5. Scope of Logic System: This calculator uses propositional logic. More complex reasoning might require predicate logic, modal logic, or other systems, which have different rules and expressiveness.
  6. Interpretation of Symbols: Ensuring consistent use and understanding of logical symbols (→, ∨, ¬) is crucial. Misinterpreting a symbol changes the meaning of the premise entirely.

Frequently Asked Questions (FAQ)

What is the difference between validity and soundness?
Validity refers to the structure of an argument – whether the conclusion logically follows from the premises. Soundness means an argument is *both* valid *and* has all true premises. A valid argument can be unsound if its premises are false.
Can this calculator handle complex logical statements?
This calculator focuses on basic propositional logic and common inference rules. For highly complex statements involving quantifiers (like "all" or "some") or intricate logical structures, more advanced tools or manual analysis using predicate logic might be necessary.
What does a 0% certainty mean in the results?
A 0% certainty typically indicates that the derivation was not possible with the given inputs and rules, or that the inputs themselves represent a false premise. It signifies a lack of logical entailment or a known falsehood.
How do I represent "not P" or "P or Q" in the input fields?
Use standard logical symbols: `~P` for "not P", and `P v Q` for "P or Q". For conditional statements, use `P->Q` for "If P, then Q".
Is logic derivation only used in math and philosophy?
No, logic derivation is fundamental to computer science (algorithms, boolean logic, AI), law (legal reasoning), medicine (diagnosis), engineering, and everyday critical thinking. It's a universal skill for structured reasoning.
What if my premises are uncertain?
If your premises have uncertain truth values, the derived conclusion will also be uncertain. While this calculator shows 100% for valid derivations, in practice, you'd need to consider the probability or confidence level of your premises to assess the conclusion's reliability.
Can I derive contradictions?
Yes, if your initial premises are contradictory (e.g., P and ~P), you can technically derive anything (principle of explosion). However, this calculator is designed for deriving consistent conclusions from consistent premises.
What are logical fallacies?
Logical fallacies are errors in reasoning that make an argument invalid or unsound. Examples include affirming the consequent, denying the antecedent, and ad hominem attacks. Recognizing fallacies is key to strong critical thinking.

© 2023 Logic Tools Inc. All rights reserved.

var premise1Input = document.getElementById('premise1'); var premise2Input = document.getElementById('premise2'); var ruleSelect = document.getElementById('rule'); var additionalPremiseHsInput = document.getElementById('additional_premise_hs'); var additionalPremiseDsInput = document.getElementById('additional_premise_ds'); var premise1Error = document.getElementById('premise1Error'); var premise2Error = document.getElementById('premise2Error'); var additionalPremiseHsError = document.getElementById('additional_premise_hsError'); var additionalPremiseDsError = document.getElementById('additional_premise_dsError'); var resultsContainer = document.getElementById('results-container'); var primaryResultDiv = document.getElementById('primaryResult'); var intermediate1Span = document.getElementById('intermediate1'); var intermediate2Span = document.getElementById('intermediate2'); var intermediate3Span = document.getElementById('intermediate3'); var formulaExplanationSpan = document.getElementById('formulaExplanation'); var derivationTableBody = document.querySelector('#derivationTable tbody'); var logicChart = document.getElementById('logicChart'); var chartCaption = document.getElementById('chartCaption'); var tableCaption = document.getElementById('tableCaption'); var ctx; // Chart context var myChart; // Chart instance // Initialize chart context and instance window.onload = function() { ctx = logicChart.getContext('2d'); // Initial empty chart myChart = new Chart(ctx, { type: 'bar', data: { labels: ['Premise 1', 'Premise 2', 'Conclusion'], datasets: [{ label: 'Certainty (%)', data: [0, 0, 0], backgroundColor: [ 'rgba(0, 74, 153, 0.6)', 'rgba(0, 74, 153, 0.6)', 'rgba(40, 167, 69, 0.6)' ], borderColor: [ 'rgba(0, 74, 153, 1)', 'rgba(0, 74, 153, 1)', 'rgba(40, 167, 69, 1)' ], borderWidth: 1 }] }, options: { scales: { y: { beginAtZero: true, max: 100 } }, responsive: true, maintainAspectRatio: false } }); // Hide results initially resultsContainer.style.display = 'none'; }; function isValidProposition(prop) { if (!prop) return false; // Basic check: allows letters, numbers, ->, ~, v, parentheses, spaces return /^[a-zA-Z0-9\s~()v→]+$/.test(prop.trim()); } function parseProposition(prop) { var trimmed = prop.trim(); if (trimmed.startsWith('~')) { return { type: 'negation', operand: parseProposition(trimmed.substring(1)) }; } else if (trimmed.includes('->')) { var parts = trimmed.split('->'); if (parts.length === 2) { return { type: 'implication', antecedent: parseProposition(parts[0]), consequent: parseProposition(parts[1]) }; } } else if (trimmed.includes('v')) { var parts = trimmed.split('v'); if (parts.length === 2) { return { type: 'disjunction', operand1: parseProposition(parts[0]), operand2: parseProposition(parts[1]) }; } } else { return { type: 'atomic', name: trimmed }; } return null; // Invalid format } function getAtomicPropositions(parsedProp) { var atoms = new Set(); if (!parsedProp) return atoms; if (parsedProp.type === 'atomic') { atoms.add(parsedProp.name.trim()); } else if (parsedProp.type === 'negation') { getAtomicPropositions(parsedProp.operand).forEach(atom => atoms.add(atom)); } else if (parsedProp.type === 'implication') { getAtomicPropositions(parsedProp.antecedent).forEach(atom => atoms.add(atom)); getAtomicPropositions(parsedProp.consequent).forEach(atom => atoms.add(atom)); } else if (parsedProp.type === 'disjunction') { getAtomicPropositions(parsedProp.operand1).forEach(atom => atoms.add(atom)); getAtomicPropositions(parsedProp.operand2).forEach(atom => atoms.add(atom)); } return atoms; } function calculateLogic() { var p1Str = premise1Input.value; var p2Str = premise2Input.value; var rule = ruleSelect.value; var pHsStr = additionalPremiseHsInput.value; var pDsStr = additionalPremiseDsInput.value; // Reset errors premise1Error.textContent = "; premise2Error.textContent = "; additionalPremiseHsError.textContent = "; additionalPremiseDsError.textContent = "; var isValid = true; var p1 = null, p2 = null, pHs = null, pDs = null; var p1Atoms = new Set(), p2Atoms = new Set(), pHsAtoms = new Set(), pDsAtoms = new Set(); if (!isValidProposition(p1Str)) { premise1Error.textContent = 'Invalid premise format.'; isValid = false; } else { p1 = parseProposition(p1Str); if (!p1) { premise1Error.textContent = 'Could not parse premise 1.'; isValid = false; } else { p1Atoms = getAtomicPropositions(p1); } } if (rule === 'modus_ponens' || rule === 'modus_tollens') { if (!isValidProposition(p2Str)) { premise2Error.textContent = 'Premise 2 is required for this rule.'; isValid = false; } else { p2 = parseProposition(p2Str); if (!p2) { premise2Error.textContent = 'Could not parse premise 2.'; isValid = false; } else { p2Atoms = getAtomicPropositions(p2); } } } if (rule === 'hypothetical_syllogism') { if (!isValidProposition(pHsStr)) { additionalPremiseHsError.textContent = 'Additional premise is required for Hypothetical Syllogism.'; isValid = false; } else { pHs = parseProposition(pHsStr); if (!pHs) { additionalPremiseHsError.textContent = 'Could not parse additional premise.'; isValid = false; } else { pHsAtoms = getAtomicPropositions(pHs); } } // For HS, premise 1 is P->Q and additional premise is Q->R if (p1 && p1.type !== 'implication') { premise1Error.textContent = 'Premise 1 must be a conditional (P->Q) for HS.'; isValid = false; } if (pHs && pHs.type !== 'implication') { additionalPremiseHsError.textContent = 'Additional premise must be a conditional (Q->R) for HS.'; isValid = false; } } if (rule === 'disjunctive_syllogism') { if (!isValidProposition(pDsStr)) { additionalPremiseDsError.textContent = 'Additional premise is required for Disjunctive Syllogism.'; isValid = false; } else { pDs = parseProposition(pDsStr); if (!pDs) { additionalPremiseDsError.textContent = 'Could not parse additional premise.'; isValid = false; } else { pDsAtoms = getAtomicPropositions(pDs); } } // For DS, premise 1 is P v Q and additional premise is ~P or ~Q if (p1 && p1.type !== 'disjunction') { premise1Error.textContent = 'Premise 1 must be a disjunction (P v Q) for DS.'; isValid = false; } if (pDs && pDs.type !== 'negation') { additionalPremiseDsError.textContent = 'Additional premise must be a negation (~P or ~Q) for DS.'; isValid = false; } } if (!isValid) { resultsContainer.style.display = 'none'; return; } var conclusion = null; var conclusionStr = "–"; var intermediate1 = "–"; var intermediate2 = "–"; var intermediate3 = "–"; var formula = ""; var certainty = 0; var tableData = []; // Add initial premises to table tableData.push({ step: 1, premiseRule: "Given", statement: p1Str, certainty: 100 }); if (p2) tableData.push({ step: 2, premiseRule: "Given", statement: p2Str, certainty: 100 }); if (pHs) tableData.push({ step: 2, premiseRule: "Given", statement: pHsStr, certainty: 100 }); if (pDs) tableData.push({ step: 2, premiseRule: "Given", statement: pDsStr, certainty: 100 }); var stepCounter = tableData.length + 1; if (rule === 'modus_ponens') { formula = "Modus Ponens: If P implies Q, and P is true, then Q is true."; intermediate1 = p1Str; // P -> Q intermediate2 = p2Str; // P if (p1 && p1.type === 'implication' && p2 && p2.type === 'atomic' && p1.antecedent.type === 'atomic' && p1.antecedent.name === p2Str) { conclusion = p1.consequent; conclusionStr = conclusion.type === 'atomic' ? conclusion.name : JSON.stringify(conclusion); // Fallback for complex consequents intermediate3 = "Antecedent ('" + p2Str + "') matches."; certainty = 100; tableData.push({ step: stepCounter++, premiseRule: "Modus Ponens", statement: conclusionStr, certainty: certainty }); } else { conclusionStr = "Cannot apply Modus Ponens: Premise 1 is not P->Q or Premise 2 is not P."; intermediate3 = "Rule conditions not met."; } } else if (rule === 'modus_tollens') { formula = "Modus Tollens: If P implies Q, and not Q, then not P."; intermediate1 = p1Str; // P -> Q intermediate2 = p2Str; // ~Q if (p1 && p1.type === 'implication' && p2 && p2.type === 'negation' && p1.consequent.type === 'atomic' && p1.consequent.name === p2.operand.name) { conclusion = { type: 'negation', operand: p1.antecedent }; conclusionStr = "~" + (p1.antecedent.type === 'atomic' ? p1.antecedent.name : JSON.stringify(p1.antecedent)); intermediate3 = "Negation of Consequent ('" + p2Str + "') matches."; certainty = 100; tableData.push({ step: stepCounter++, premiseRule: "Modus Tollens", statement: conclusionStr, certainty: certainty }); } else { conclusionStr = "Cannot apply Modus Tollens: Premise 1 is not P->Q or Premise 2 is not ~Q."; intermediate3 = "Rule conditions not met."; } } else if (rule === 'hypothetical_syllogism') { formula = "Hypothetical Syllogism: If P implies Q, and Q implies R, then P implies R."; intermediate1 = p1Str; // P -> Q intermediate2 = pHsStr; // Q -> R if (p1 && p1.type === 'implication' && pHs && pHs.type === 'implication' && p1.consequent.type === 'atomic' && pHs.antecedent.type === 'atomic' && p1.consequent.name === pHs.antecedent.name) { conclusion = { type: 'implication', antecedent: p1.antecedent, consequent: pHs.consequent }; conclusionStr = (p1.antecedent.type === 'atomic' ? p1.antecedent.name : JSON.stringify(p1.antecedent)) + "->" + (pHs.consequent.type === 'atomic' ? pHs.consequent.name : JSON.stringify(pHs.consequent)); intermediate3 = "Middle term ('" + p1.consequent.name + "') links premises."; certainty = 100; tableData.push({ step: stepCounter++, premiseRule: "Hypothetical Syllogism", statement: conclusionStr, certainty: certainty }); } else { conclusionStr = "Cannot apply Hypothetical Syllogism: Premises not in P->Q and Q->R form or middle term mismatch."; intermediate3 = "Rule conditions not met."; } } else if (rule === 'disjunctive_syllogism') { formula = "Disjunctive Syllogism: If P or Q, and not P, then Q."; intermediate1 = p1Str; // P v Q intermediate2 = pDsStr; // ~P if (p1 && p1.type === 'disjunction' && pDs && pDs.type === 'negation') { var p = p1.operand1.name; var q = p1.operand2.name; var notP = pDs.operand.name; if (p === notP) { conclusion = p1.operand2; conclusionStr = conclusion.type === 'atomic' ? conclusion.name : JSON.stringify(conclusion); intermediate3 = "Negated disjunct ('" + notP + "') found."; certainty = 100; tableData.push({ step: stepCounter++, premiseRule: "Disjunctive Syllogism", statement: conclusionStr, certainty: certainty }); } else if (q === notP) { conclusion = p1.operand1; conclusionStr = conclusion.type === 'atomic' ? conclusion.name : JSON.stringify(conclusion); intermediate3 = "Negated disjunct ('" + notP + "') found."; certainty = 100; tableData.push({ step: stepCounter++, premiseRule: "Disjunctive Syllogism", statement: conclusionStr, certainty: certainty }); } else { conclusionStr = "Cannot apply Disjunctive Syllogism: Negated premise does not match either disjunct."; intermediate3 = "Rule conditions not met."; } } else { conclusionStr = "Cannot apply Disjunctive Syllogism: Premise 1 is not P v Q or Premise 2 is not ~P."; intermediate3 = "Rule conditions not met."; } } primaryResultDiv.textContent = conclusionStr + (certainty > 0 ? " (Certainty: " + certainty + "%)" : ""); intermediate1Span.textContent = intermediate1; intermediate2Span.textContent = intermediate2; intermediate3Span.textContent = intermediate3; formulaExplanationSpan.textContent = formula; // Update table derivationTableBody.innerHTML = "; // Clear previous rows tableData.forEach(function(row) { var tr = document.createElement('tr'); tr.innerHTML = '' + row.step + '' + row.premiseRule + '' + row.statement + '' + row.certainty + '%'; derivationTableBody.appendChild(tr); }); // Update chart var chartData = [ p1 ? 100 : 0, (p2 || pHs || pDs) ? 100 : 0, certainty ]; var chartLabels = ['Premise 1']; if (p2 || pHs || pDs) chartLabels.push('Premise 2 / Add. Premise'); chartLabels.push('Conclusion'); myChart.data.labels = chartLabels; myChart.data.datasets[0].data = chartData; myChart.update(); chartCaption.textContent = "Visualization of premise certainty and derived conclusion certainty."; tableCaption.textContent = "Summary of logical steps and their certainty."; resultsContainer.style.display = 'block'; } function resetCalculator() { premise1Input.value = "P->Q"; premise2Input.value = "P"; ruleSelect.value = "modus_ponens"; additionalPremiseHsInput.value = ""; additionalPremiseDsInput.value = ""; premise1Error.textContent = "; premise2Error.textContent = "; additionalPremiseHsError.textContent = "; additionalPremiseDsError.textContent = "; resultsContainer.style.display = 'none'; // Reset chart to initial state if needed, or just clear values if (myChart) { myChart.data.labels = ['Premise 1', 'Premise 2', 'Conclusion']; myChart.data.datasets[0].data = [0, 0, 0]; myChart.update(); } derivationTableBody.innerHTML = "; } function copyResults() { var resultText = "Logic Derivation Results:\n\n"; resultText += "Conclusion: " + primaryResultDiv.textContent + "\n"; resultText += "Intermediate Value 1: " + intermediate1Span.textContent + "\n"; resultText += "Intermediate Value 2: " + intermediate2Span.textContent + "\n"; resultText += "Intermediate Value 3: " + intermediate3Span.textContent + "\n"; resultText += "Formula Used: " + formulaExplanationSpan.textContent + "\n\n"; resultText += "Derivation Steps Summary:\n"; var rows = derivationTableBody.querySelectorAll('tr'); rows.forEach(function(row) { var cells = row.querySelectorAll('td'); resultText += cells[0].textContent + ". " + cells[1].textContent + ": " + cells[2].textContent + " (" + cells[3].textContent + ")\n"; }); // Use a temporary textarea to copy var textArea = document.createElement("textarea"); textArea.value = resultText; textArea.style.position = "fixed"; // Avoid scrolling to bottom textArea.style.left = "-9999px"; document.body.appendChild(textArea); textArea.focus(); textArea.select(); try { var successful = document.execCommand('copy'); var msg = successful ? 'Results copied!' : 'Copy failed!'; // Optionally show a temporary message to the user console.log(msg); } catch (err) { console.log('Oops, unable to copy'); } document.body.removeChild(textArea); } function toggleFaq(element) { var answer = element.nextElementSibling; if (answer.style.display === "block") { answer.style.display = "none"; } else { answer.style.display = "block"; } } // Add event listeners for real-time updates (optional, but good UX) premise1Input.addEventListener('input', calculateLogic); premise2Input.addEventListener('input', calculateLogic); ruleSelect.addEventListener('change', calculateLogic); additionalPremiseHsInput.addEventListener('input', calculateLogic); additionalPremiseDsInput.addEventListener('input', calculateLogic); // Initial calculation on load if default values are set // calculateLogic(); // Uncomment if you want calculation on page load with defaults

Leave a Comment