Lune

ACL Findings2023

The Magic of IF: Investigating Causal Reasoning Abilities in Large Language Models of Code

Xiao Liu, Da Yin, Chen Zhang, Yansong Feng, Dongyan Zhao

Abstract

Causal reasoning, the ability to identify causeand-effect relationship, is crucial in human thinking. Although large language models (LLMs) succeed in many NLP tasks, it is still challenging for them to conduct complex causal reasoning like abductive reasoning and counterfactual reasoning. Given the fact that programming code may express causal relations more often and explicitly with conditional statements like if, we want to explore whether Code-LLMs acquire better causal reasoning abilities. Our experiments show that compared to textonly LLMs, Code-LLMs with code prompts are significantly better in causal reasoning. We further intervene on the prompts from different aspects, and discover that the programming structure is crucial in code prompt design, while Code-LLMs are robust towards format perturbations. Code and data are available at https://github.com/xxxiaol/magic-if.

Ask Lune

Ask anything. The answer quotes the paper.

Lune reads all of it and the papers around it, then shows you the passages behind every answer.

Questions to start from

Lune answers from

the full paper · 7 top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Cited by top-tier papers7

  1. COLD: Causal reasOning in cLosed Daily activitiesAbhinav Joshi, Areeb Ahmad, Ashutosh ModiNeurIPS 2024 · 11 citations
  2. Read it in Two Steps: Translating Extremely Low-Resource Languages with Code-Augmented Grammar BooksChen Zhang, Jiuheng Lin, Xiao Liu, Zekai Zhang et al.ACL 2025 · 5 citations
  3. Code Prompting Elicits Conditional Reasoning Abilities in Text+Code LLMsHaritz Puerto, Martin Tutek, Somak Aditya, Xiaodan Zhu et al.EMNLP 2024 · 4 citations
  4. LLaRA: Supercharging Robot Learning Data for Vision-Language PolicyXiang Li, Cristina Mata, Jongwoo Park, Kumara Kahatapitiya et al.ICLR 2025 · 2 citations
  5. Understanding Long Videos with Multimodal Language ModelsKanchana Ranasinghe, Xiang Li, Kumara Kahatapitiya, Michael S. RyooICLR 2025

Builds on15

  1. Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
  2. Training language models to follow instructions with human feedbackLong Ouyang, Jeffrey Wu, Xu Jiang, Diogo Almeida et al.NeurIPS 2022 · 24,707 citations
  3. BERTScore: Evaluating Text Generation with BERTTianyi Zhang, Varsha Kishore, Felix Wu, Kilian Q. Weinberger et al.ICLR 2020 · 8,443 citations
  4. Diffusion-LM Improves Controllable Text GenerationXiang Lisa Li, John Thickstun, Ishaan Gulrajani, Percy Liang et al.NeurIPS 2022 · 1,546 citations
  5. PAL: Program-aided Language ModelsLuyu Gao, Aman Madaan, Shuyan Zhou, Uri Alon et al.ICML 2023 · 700 citations

Related papers

  1. Causality-Aided Evaluation and Explanation of Large Language Model-Based Code GenerationZhenlan Ji, Pingchuan Ma, Zongjie Li, Zhaoyu Wang et al.ISSTA 2025 · 1 citation
  2. Do Large Code Models Understand Programming Concepts? Counterfactual Analysis for Code PredicatesAshish Hooda, Mihai Christodorescu, Miltiadis Allamanis, Aaron Wilson et al.ICML 2024 · 16 citations
  3. NoisyCausal: A Benchmark for Evaluating Causal Reasoning Under Structured NoiseZhi Xu, Yun FuACL 2026
  4. Unveiling Causal Reasoning in Large Language Models: Reality or Mirage?Haoang Chi, He Li, Wenjing Yang, Feng Liu et al.NeurIPS 2024 · 124 citations
  5. CausalityCheck: A Framework for Evaluating Causal Reasoning in Large Language ModelsJiang Li, Zehua Duo, Guanglai Gao, Xiangdong SuACL Findings 2026
Dusk over the sea between two cliffs drawn in fine vertical lines