File size: 15,755 Bytes
6b62c1a
8807864
6b62c1a
bb0a4d3
 
f971590
 
 
 
 
 
 
 
 
bb0a4d3
 
f971590
 
 
 
 
 
 
 
 
bb0a4d3
 
f971590
 
 
 
 
 
 
 
 
bb0a4d3
 
f971590
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb0a4d3
 
f971590
 
 
 
 
 
 
 
6b62c1a
9694177
db97149
4ffae4d
db97149
 
 
 
 
83c0c7a
db97149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9694177
 
 
 
 
6c917c2
9694177
 
 
 
396f5ed
 
 
 
9694177
 
 
396f5ed
 
 
9694177
396f5ed
 
 
 
 
 
 
6c917c2
9694177
 
 
396f5ed
9694177
6c917c2
9694177
 
 
 
 
 
 
 
 
6c917c2
9694177
 
 
 
 
 
6c917c2
 
 
 
 
 
 
 
 
 
 
 
 
9694177
 
 
 
6c917c2
9694177
 
 
 
 
 
 
 
 
 
 
 
 
396f5ed
9694177
 
 
 
396f5ed
9694177
 
 
 
 
 
 
 
6c917c2
9694177
6c917c2
 
 
 
 
9694177
 
 
 
 
 
 
 
 
 
 
 
 
396f5ed
 
 
 
 
6c917c2
396f5ed
9694177
 
 
 
396f5ed
58dc818
9694177
396f5ed
58dc818
9694177
396f5ed
58dc818
9694177
 
396f5ed
9694177
 
 
 
 
 
 
 
396f5ed
 
 
9694177
 
396f5ed
 
9694177
 
396f5ed
 
9694177
 
396f5ed
 
9694177
 
 
396f5ed
 
9694177
 
396f5ed
 
9694177
 
396f5ed
 
9694177
 
396f5ed
 
9694177
 
 
396f5ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9694177
 
396f5ed
 
9694177
 
396f5ed
 
9694177
 
396f5ed
 
9694177
 
 
 
396f5ed
9694177
396f5ed
9694177
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a900ab0
 
396f5ed
 
 
9694177
 
 
 
 
6b62c1a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
---
license: cc-by-4.0
configs:
  - config_name: nl2rule
    data_files:
      - split: K_Standard_NumRule5
        path: nl2rule/K_Standard_NumRule5-*
      - split: K_NonStandard_NumRule5
        path: nl2rule/K_NonStandard_NumRule5-*
      - split: S_Standard_NumRule5
        path: nl2rule/S_Standard_NumRule5-*
      - split: S_NonStandard_NumRule5
        path: nl2rule/S_NonStandard_NumRule5-*

  - config_name: rule2nl
    data_files:
      - split: K_Standard_NumDescription5
        path: rule2nl/K_Standard_NumDescription5-*
      - split: K_NonStandard_NumDescription5
        path: rule2nl/K_NonStandard_NumDescription5-*
      - split: S_Standard_NumDescription5
        path: rule2nl/S_Standard_NumDescription5-*
      - split: S_NonStandard_NumDescription5
        path: rule2nl/S_NonStandard_NumDescription5-*

  - config_name: predrule
    data_files:
      - split: K_Standard_Human_Written
        path: predrule/K_Standard_Human_Written-*
      - split: K_NonStandard_Human_Written
        path: predrule/K_NonStandard_Human_Written-*
      - split: S_Standard_Human_Written
        path: predrule/S_Standard_Human_Written-*
      - split: S_NonStandard_Human_Written
        path: predrule/S_NonStandard_Human_Written-*

  - config_name: predstate
    data_files:
      - split: K_Standard_Human_Written
        path: predstate/K_Standard_Human_Written-*
      - split: K_NonStandard_Human_Written
        path: predstate/K_NonStandard_Human_Written-*
      - split: S_Standard_Human_Written
        path: predstate/S_Standard_Human_Written-*

      - split: S_NonStandard_Human_Written
        path: predstate/S_NonStandard_Human_Written-*

      - split: K_Standard_LLM_Translated
        path: predstate/K_Standard_LLM_Translated-*
      - split: K_NonStandard_LLM_Translated
        path: predstate/K_NonStandard_LLM_Translated-*
      - split: S_Standard_LLM_Translated
        path: predstate/S_Standard_LLM_Translated-*
      - split: S_NonStandard_LLM_Translated
        path: predstate/S_NonStandard_LLM_Translated-*

      - split: K_Standard_Fuzzer_Generated
        path: predstate/K_Standard_Fuzzer_Generated-*
      - split: K_NonStandard_Fuzzer_Generated
        path: predstate/K_NonStandard_Fuzzer_Generated-*
      - split: S_Standard_Fuzzer_Generated
        path: predstate/S_Standard_Fuzzer_Generated-*
      - split: S_NonStandard_Fuzzer_Generated
        path: predstate/S_NonStandard_Fuzzer_Generated-*

  - config_name: predtrace
    data_files:
      - split: K_Standard_Human_Written
        path: predtrace/K_Standard_Human_Written-*
      - split: K_NonStandard_Human_Written
        path: predtrace/K_NonStandard_Human_Written-*
      - split: S_Standard_Human_Written
        path: predtrace/S_Standard_Human_Written-*
      - split: S_NonStandard_Human_Written
        path: predtrace/S_NonStandard_Human_Written-*
---

<div align="center">
  <p>The 43rd International Conference on Machine Learning (ICML 2026), Seoul, South Korea</p>
  <h1>
    LLMs Lean on Priors, Not Programming Language
    <span style="white-space: nowrap;">
      Semantics
      <img
        src="https://raw.githubusercontent.com/EngineeringSoftware/PLSemanticsBench/main/docs/icons/logo.png"
        alt="PLSemanticsBench logo"
        width="60"
        style="display: inline-block !important;
               vertical-align: -1.0em;
               margin-left: 10px;
               margin-bottom: 0;">
    </span>
  </h1>

  <p style="font-size: 20px;">
    by
    <a href="https://www.adityathimmaiah.com">Aditya Thimmaiah</a><sup>1</sup>,
    <a href="https://jiyangzhang.github.io/">Jiyang Zhang</a><sup>1</sup>,
    <a href="https://scholar.google.com/citations?user=HtNfeKYAAAAJ&hl=en">Jayanth Srinivasa</a><sup>2</sup>,
    <a href="https://www.jessyli.com">Junyi Jessy Li</a><sup>1</sup>,
    <a href="https://users.ece.utexas.edu/~gligoric/">Milos Gligoric</a><sup>1</sup>
  </p>

  <p>
    <sup>1</sup>The University of Texas at Austin &nbsp;&nbsp;&nbsp;
    <sup>2</sup>Cisco Research
  </p>
</div>

<div align="center">

[![Website](https://img.shields.io/badge/Project_Page-PLSemanticsBench-blueviolet)](https://engineeringsoftware.github.io/PLSemanticsBench/)
[![arXiv](https://img.shields.io/badge/arXiv-2510.03415v3-b31b1b.svg)](https://arxiv.org/pdf/2510.03415v3)
[![Code](https://img.shields.io/badge/Code-GitHub-black)](https://github.com/EngineeringSoftware/PLSemanticsBench)
[![Dataset](https://img.shields.io/badge/🤗-Dataset-yellow)](https://huggingface.co/datasets/EngineeringSoftware/PLSemanticsBench)

</div>

---

**TLDR:** Frontier LLMs execute programs with up to 90–100% accuracy when symbols retain their usual meanings (e.g., + means addition). Under counterfactual semantic shifts (e.g., redefining + to mean subtraction) accuracy collapses by 40–70 percentage points. Despite handing the complete formal rules, the models keep answering as if the rules were never changed.
LLMs don't faithfully interpret the semantics they are given—they retrieve what symbols usually mean from pretraining.

## Abstract
Recent work asks whether large language models (LLMs) condition their reasoning on explicit rules rather than statistical regularities from pre-training. 
Program execution provides a canonical instance: formal semantics define behavior through symbolic transition rules that can be systematically altered 
under distribution shift. We investigate whether LLMs can condition their reasoning on formal semantics through program execution and introduce PLSEMANTICSBENCH, 
pairing featherweight C programs with two semantic systems—small-step operational semantics and K semantics—and probing four capabilities: composing rules for 
final states, selecting rules when state is unmutated, sustaining such conditioning over long traces, and following supplied rules under novel semantics. To 
decouple semantic reasoning from syntactic familiarity, we redefine familiar operators to induce symbol-meaning conflict and introduce novel symbols defined only
through the supplied rules, and stress-test models on Human-Written, LLM-Translated, and Fuzzer-Generated splits with increasing structural complexity. Across 
11 frontier LLMs, strong final-state accuracy under standard semantics (up to 90%) drops sharply—by as much as 40–60% points—under semantic mutations and increasing
structural complexity. Only a handful of models achieve non-zero long-horizon conditioning accuracy, and even the best systems reach just 35%. Together, these results 
suggest that contemporary LLMs often rely on pretrained lexical associations rather than systematically conditioning on supplied formal rules.

## Table of Contents
- [About](#about)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Detailed Usage](#detailed-usage)
- [Benchmark](#benchmark)
- [Citation](#citation)

## About
PLSemanticsBench is the first counterfactual programming language (PL) semantics dataset for evaluating rule-conditioned reasoning in LLMs.
It contains the semantics formalization of `C*`, a featherweight C programming language, in two approaches: small-step 
operational semantics and the K-framework semantics. Execution of `C*` programs under counterfactual and standard semantics is then used as a 
lens for evaluating rule-conditioned reasoning in LLMs via three tasks:

| Task | Description |
|------|-------------|
| ✨ **PredState**| Predict the final program state |
| ✨ **PredRule** | Predict the ordered sequence of semantic rules needed to evaluate a program|
| ✨ **PredTrace**| Predict the step-by-step execution of a program |

It also includes the auxiliary tasks below, to rule out formal notation understanding as an influencing
factor:  

| Task | Description |
|------|-------------|
| ✨ **NL2Rule**| Select the correct formal semantic rule (out of 5) given its natural language description |
| ✨ **Rule2NL** | Select the correct natural language description (out of 5) given the formal semantic rule|

## Installation

### System Requirements
- [Conda](https://docs.conda.io/projects/conda/en/stable/user-guide/install/index.html) package management system
- Python 3.11 or higher
- OpenAI API key (for running experiments with OpenAI models)


### Step-by-Step Installation
1. Create and activate the conda environment:
```bash
conda env create -f env.yaml
conda activate plsemanticsbench
```

2. Set up your OpenAI API key (only for OpenAI models):
```bash
export OPENAI_API_KEY='your-api-key-here'
```

## Quick Start

We provide a bash script `quick` that:
 1. Sets up the `plsemanticsbench` conda environment.
 2. Pulls the `DeepSeek-R1 1.5B` model.
 3. Evaluates the `DeepSeek-R1 1.5B` model on the `PredState` task with `no-semantics` and `chain-of-thought` prompting on the `Human-Written` dataset.
 4. Prints the `accuracy` and `malformed-count` to screen.
 5. Creates `metrics-predstate-deepseek-r1:1.5b.json` that contains the evaluation result.
 
```bash
bash quick
```

## Detailed Usage

### Basic Example
Here's a minimal example to get started:

```python
from plsemanticsbench import GPTRunner
from plsemanticsbench import ExperimentArgs, LLMEvaluator
from plsemanticsbench import (
    PROMPT_STRATEGY,
    Task,
    Formalization,
    Semantics_Type,
    Language,
    PLDataset
)

# Model name
model_name = "o3-mini"

# Experiment args: Run the PredState task on the C* language with
# standard semantics formalized using SOS and with direct prompting
exp_args = ExperimentArgs(
    dataset=PLDataset.Human_Written,
    task=Task.PredState,
    language=Language.CSTAR,
    formalization=Formalization.SOS,
    semantics_type=Semantics_Type.Standard,
    model_name=model_name,
    prompt_strategy=PROMPT_STRATEGY.DA,
    num_datapoints_to_run=2, # Run just 2 datapoints (omit to run entire dataset)
)
                        
# Run inference using the OpenAI API
gpt_runner = GPTRunner(args=exp_args)

# Generation (generate LLM prediction on the predstate task)
predictions = gpt_runner.do_experiment() # path to dump results can be provided

# Evaluation (evaluate LLM prediction against ground-truth)
llm_eval = LLMEvaluator(task=exp_args.task, semantics_type=exp_args.semantics_type)
evaluation_result = llm_eval.evaluate_from_list(results=predictions, model_name=model_name)
print(evaluation_result)
```

### Expected Output

```python
{
    'accuracy': 1,
    'malformed-count': 0,
}
```

### Extending Providers

You must implement [BaseRunner](https://github.com/EngineeringSoftware/PLSemanticsBench/blob/main/src/plsemanticsbench/core/exps/base_experiment.py)(`_query` method) to evaluate your models. We provide two example implementations for OpenAI models ([GPTRunner](https://github.com/EngineeringSoftware/PLSemanticsBench/blob/main/src/plsemanticsbench/core/exps/gpt_experiment.py)) and Ollama models ([OllamaRunner](https://github.com/EngineeringSoftware/PLSemanticsBench/blob/main/src/plsemanticsbench/core/exps/ollama_experiment.py)).

## Dataset

### Access
You can load the dataset using the `datasets` library. Here is an example:
```python
from datasets import load_dataset

# Load PredState task with standard semantics under K formalization for the LLM Translated dataset
predstate_K_standard_llm_translated = load_dataset("EngineeringSoftware/PLSemanticsBench", name="predstate")["K_Standard_LLM_Translated"]

# Load PredRule task with nonstandard semantics under S formalization for the Human Written dataset
predrule_S_nonstandard_human_written = load_dataset("EngineeringSoftware/PLSemanticsBench", name="predrule")["S_NonStandard_Human_Written"]

# Load nl2rule task with standard semantics under S formalization
nl2rule_S_standard = load_dataset("EngineeringSoftware/PLSemanticsBench", name="nl2rule")["S_Standard_NumRule5"]
```

### Splits

<table>
  <tr>
    <th>Task</th>
    <th>Split</th>
    <th>Description</th>
  </tr>
  <tr>
    <td rowspan="4">✨ <strong>PredState</strong><br>(Final State Prediction)</td>
    <td> predstate/K_Standard_{dataset-name} </td>
    <td>Standard semantics with K formalization</td>
  </tr>
  <tr>
    <td> predstate/K_NonStandard_{dataset-name} </td>
    <td>Nonstandard semantics with K formalization</td>
  </tr>
  <tr>
    <td> predstate/S_Standard_{dataset-name} </td>
    <td>Standard semantics with S formalization</td>
  </tr>
  <tr>
    <td> predstate/S_NonStandard_{dataset-name} </td>
    <td>Nonstandard semantics with S formalization</td>
  </tr>
  <tr>
    <td rowspan="4">✨ <strong>PredRule</strong><br>(Semantic Rule Prediction)</td>
    <td> predrule/K_Standard_Human_Written </td>
    <td>Standard semantics with K formalization</td>
  </tr>
  <tr>
    <td> predrule/K_NonStandard_Human_Written </td>
    <td>Nonstandard semantics with K formalization</td>
  </tr>
  <tr>
    <td> predrule/S_Standard_Human_Written </td>
    <td>Standard semantics with S formalization</td>
  </tr>
  <tr>
    <td> predrule/S_NonStandard_Human_Written </td>
    <td>Nonstandard semantics with S formalization</td>
  </tr>
  <tr>
    <td rowspan="4">✨ <strong>PredTrace</strong><br>(Execution Trace Prediction)</td>
    <td> predtrace/K_Standard_Human_Written </td>
    <td>Standard semantics with K formalization</td>
  </tr>
  <tr>
    <td> predtrace/K_NonStandard_Human_Written </td>
    <td>Nonstandard semantics with K formalization</td>
  </tr>
  <tr>
    <td> predtrace/S_Standard_Human_Written </td>
    <td>Standard semantics with S formalization</td>
  </tr>
  <tr>
    <td> predtrace/S_NonStandard_Human_Written </td>
    <td>Nonstandard semantics with S formalization</td>
  </tr>
  <tr>
    <td colspan="3" align="center"><strong>Auxiliary Tasks (formal notation understanding)</strong></td>
  </tr>
  <tr>
    <td rowspan="4">✨ <strong>NL2Rule</strong><br>(Natural language description to semantic rule)</td>
    <td> nl2rule/K_Standard_NumRule5 </td>
    <td>Standard semantics with K formalization</td>
  </tr>
  <tr>
    <td> nl2rule/K_NonStandard_NumRule5 </td>
    <td>Nonstandard semantics with K formalization</td>
  </tr>
  <tr>
    <td> nl2rule/S_Standard_NumRule5 </td>
    <td>Standard semantics with S formalization</td>
  </tr>
  <tr>
    <td> nl2rule/S_NonStandard_NumRule5 </td>
    <td>Nonstandard semantics with S formalization</td>
  </tr>
  <tr>
    <td rowspan="4">✨ <strong>Rule2NL</strong><br>(Semantic rule to natural language description)</td>
    <td> rule2nl/K_Standard_NumDescription5 </td>
    <td>Standard semantics with K formalization</td>
  </tr>
  <tr>
    <td> rule2nl/K_NonStandard_NumDescription5 </td>
    <td>Nonstandard semantics with K formalization</td>
  </tr>
  <tr>
    <td> rule2nl/S_Standard_NumDescription5 </td>
    <td>Standard semantics with S formalization</td>
  </tr>
  <tr>
    <td> rule2nl/S_NonStandard_NumDescription5 </td>
    <td>Nonstandard semantics with S formalization</td>
  </tr>
</table>


### Example Data Point

An example of a data point from the `predstate/None-human-written` split:
```json
{
  "program": "int ans; ans = 1; ...",
  "syntax": "<program> :: ...",
  "semantics": "ℤ := Set of integers ...",
  "mutated-program": "int ans; ans = 1; ...",
  "mutation-pattern": "KeyWordSwap",
  "exec-trace": [
    {
      "linenumber": 1,
      "rule": ["Rule 38", "Rule 39"],
      "state": {"ans": 1}
    }
  ],
  "ground-truth": "<answer>...</answer>"
}
```

## Citation
```bibtex
@inproceedings{ThimmaiahETAL25PLSemanticsBench,
  title     = {LLMs Lean on Priors, Not Programming Language Semantics},
  author    = {Aditya Thimmaiah, Jiyang Zhang, Jayanth Srinivasa, Junyi Jessy Li, Milos Gligoric},
  year      = {2026},
  booktitle = {ICML}, 
}
```


## License
This project is licensed under the [CC BY 4.0 License](https://creativecommons.org/licenses/by/4.0/).