Overview
Thefol_to_cvc.py script converts first-order logic formulas into SMT-LIB format and executes the CVC4 solver to check satisfiability. This determines whether logical arguments are valid or contain fallacies.
How It Works
1
Load FOL Formulas
Reads the CSV file generated by
nl_to_fol.py containing logical formulas.2
Generate SMT Scripts
Uses the
CVCGenerator class to convert FOL formulas to SMT-LIB format.3
Run CVC4 Solver
Executes the SMT solver on each formula to check satisfiability.
4
Handle Unknown Results
If solver returns “unknown”, retries with finite model finding enabled.
5
Interpret Results
Maps solver output to validity classification:
unsat= Valid argumentsat/unknown= Logical fallacy (LF)
6
Save Results
Outputs results to CSV with validity predictions.
Command Usage
Basic Command
Parameters
The name of the run from nl_to_fol.py. The script will:
- Read from:
results/<run_name>.csv - Create SMT files in:
results/<run_name>_smt/ - Save results to:
results/<run_name>_results.csv
Example Usage
Prerequisites
SMT-LIB Format
The FOL formulas are converted to SMT-LIB2 format. The system handles:Operator Conversions
Example Conversion
Input FOL:Output Files
For each datapointi, the script generates:
SMT Files
results/<run_name>_smt/i.smt2
The SMT-LIB formatted formula file.
results/<run_name>_smt/i_out.txt
The solver output containing:
- First line:
sat,unsat, orunknown - Remaining lines: Counter-model (if sat)
Results CSV
results/<run_name>_results.csv
Adds a result column to the original CSV:
Valid- Formula is unsatisfiable (valid argument)LF- Formula is satisfiable or unknown (logical fallacy)- Empty string - Processing error
Finite Model Finding
When the solver returnsunknown, the script automatically retries with finite model finding:
Finite model finding can significantly increase solving time but improves coverage for complex formulas.
Understanding Results
UNSAT (Valid Argument)
When the SMT solver returnsunsat, it means:
- The negation of the formula is unsatisfiable
- No counter-example exists
- The original argument is logically valid
SAT (Logical Fallacy)
When the SMT solver returnssat, it means:
- A counter-example exists
- The argument contains a logical fallacy
- The model shows why the implication doesn’t hold
Unknown
When the solver returnsunknown:
- The formula is too complex for automatic decision
- Classified as potential fallacy (conservative approach)
- Retry with finite model finding may resolve
Processing Flow
Performance Considerations
Error Handling
The script includes comprehensive error handling:CVCGenerator Class
TheCVCGenerator class (from cvc.py) handles:
- FOL parsing
- SMT-LIB syntax generation
- Sort and function declarations
- Formula negation (for validity checking)
The solver checks the negation of the formula. If the negation is unsatisfiable, the original formula is valid.
Troubleshooting
Common Issues
CVC4 not found- Check that FOL formulas are well-formed
- Verify all operators are properly converted
- Review
Logical Form 2column for malformed expressions
Alternative Solvers
While the script uses CVC4, you can adapt it for other SMT solvers: CVC5 (newer version)Next Steps
After generating SMT results:- Interpret individual results with counter-examples using
interpret_smt_results.py - Evaluate overall performance using
get_metrics.py - Analyze error cases and improve FOL translation
