The Logic of Counterfactuals in Causal Inference