birgermoell commited on
Commit
629f09b
·
verified ·
1 Parent(s): 2983a9c

Add 108 offline Harbor tasks for argument-check

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. tasks/argument-check/argument-check-consistency-d1-e0000/environment/Dockerfile +3 -0
  2. tasks/argument-check/argument-check-consistency-d1-e0000/environment/workdir/logic_reference.md +48 -0
  3. tasks/argument-check/argument-check-consistency-d1-e0000/environment/workdir/sentence_sets.json +39 -0
  4. tasks/argument-check/argument-check-consistency-d1-e0000/instruction.md +14 -0
  5. tasks/argument-check/argument-check-consistency-d1-e0000/solution/oracle.py +144 -0
  6. tasks/argument-check/argument-check-consistency-d1-e0000/solution/solve.sh +4 -0
  7. tasks/argument-check/argument-check-consistency-d1-e0000/task.toml +25 -0
  8. tasks/argument-check/argument-check-consistency-d1-e0000/tests/checks.json +110 -0
  9. tasks/argument-check/argument-check-consistency-d1-e0000/tests/test.sh +3 -0
  10. tasks/argument-check/argument-check-consistency-d1-e0000/tests/validators.py +152 -0
  11. tasks/argument-check/argument-check-consistency-d1-e0000/tests/verify.py +116 -0
  12. tasks/argument-check/argument-check-consistency-d1-e0009/environment/Dockerfile +3 -0
  13. tasks/argument-check/argument-check-consistency-d1-e0009/environment/workdir/logic_reference.md +48 -0
  14. tasks/argument-check/argument-check-consistency-d1-e0009/environment/workdir/sentence_sets.json +37 -0
  15. tasks/argument-check/argument-check-consistency-d1-e0009/instruction.md +14 -0
  16. tasks/argument-check/argument-check-consistency-d1-e0009/solution/oracle.py +144 -0
  17. tasks/argument-check/argument-check-consistency-d1-e0009/solution/solve.sh +4 -0
  18. tasks/argument-check/argument-check-consistency-d1-e0009/task.toml +25 -0
  19. tasks/argument-check/argument-check-consistency-d1-e0009/tests/checks.json +110 -0
  20. tasks/argument-check/argument-check-consistency-d1-e0009/tests/test.sh +3 -0
  21. tasks/argument-check/argument-check-consistency-d1-e0009/tests/validators.py +152 -0
  22. tasks/argument-check/argument-check-consistency-d1-e0009/tests/verify.py +116 -0
  23. tasks/argument-check/argument-check-consistency-d1-e0018/environment/Dockerfile +3 -0
  24. tasks/argument-check/argument-check-consistency-d1-e0018/environment/workdir/logic_reference.md +48 -0
  25. tasks/argument-check/argument-check-consistency-d1-e0018/environment/workdir/sentence_sets.json +40 -0
  26. tasks/argument-check/argument-check-consistency-d1-e0018/instruction.md +14 -0
  27. tasks/argument-check/argument-check-consistency-d1-e0018/solution/oracle.py +144 -0
  28. tasks/argument-check/argument-check-consistency-d1-e0018/solution/solve.sh +4 -0
  29. tasks/argument-check/argument-check-consistency-d1-e0018/task.toml +25 -0
  30. tasks/argument-check/argument-check-consistency-d1-e0018/tests/checks.json +111 -0
  31. tasks/argument-check/argument-check-consistency-d1-e0018/tests/test.sh +3 -0
  32. tasks/argument-check/argument-check-consistency-d1-e0018/tests/validators.py +152 -0
  33. tasks/argument-check/argument-check-consistency-d1-e0018/tests/verify.py +116 -0
  34. tasks/argument-check/argument-check-consistency-d1-t0000/environment/Dockerfile +3 -0
  35. tasks/argument-check/argument-check-consistency-d1-t0000/environment/workdir/logic_reference.md +48 -0
  36. tasks/argument-check/argument-check-consistency-d1-t0000/environment/workdir/sentence_sets.json +37 -0
  37. tasks/argument-check/argument-check-consistency-d1-t0000/instruction.md +14 -0
  38. tasks/argument-check/argument-check-consistency-d1-t0000/solution/oracle.py +144 -0
  39. tasks/argument-check/argument-check-consistency-d1-t0000/solution/solve.sh +4 -0
  40. tasks/argument-check/argument-check-consistency-d1-t0000/task.toml +25 -0
  41. tasks/argument-check/argument-check-consistency-d1-t0000/tests/checks.json +111 -0
  42. tasks/argument-check/argument-check-consistency-d1-t0000/tests/test.sh +3 -0
  43. tasks/argument-check/argument-check-consistency-d1-t0000/tests/validators.py +152 -0
  44. tasks/argument-check/argument-check-consistency-d1-t0000/tests/verify.py +116 -0
  45. tasks/argument-check/argument-check-consistency-d1-t0009/environment/Dockerfile +3 -0
  46. tasks/argument-check/argument-check-consistency-d1-t0009/environment/workdir/logic_reference.md +48 -0
  47. tasks/argument-check/argument-check-consistency-d1-t0009/environment/workdir/sentence_sets.json +38 -0
  48. tasks/argument-check/argument-check-consistency-d1-t0009/instruction.md +14 -0
  49. tasks/argument-check/argument-check-consistency-d1-t0009/solution/oracle.py +144 -0
  50. tasks/argument-check/argument-check-consistency-d1-t0009/solution/solve.sh +4 -0
tasks/argument-check/argument-check-consistency-d1-e0000/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/argument-check/argument-check-consistency-d1-e0000/environment/workdir/logic_reference.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Logic reference
2
+
3
+ ## Formulas
4
+
5
+ - An atom is a single capital letter, `A` to `Z`.
6
+ - `~X` means not X.
7
+ - `X & Y` means X and Y.
8
+ - `X | Y` means X or Y (inclusive: one or the other or both).
9
+ - `X -> Y` means if X then Y.
10
+ - `X <-> Y` means X if and only if Y.
11
+ - Parentheses `(` and `)` group. Spaces between symbols are optional and carry no meaning.
12
+
13
+ ## Reading a formula that is not fully parenthesised
14
+
15
+ The connectives bind in this order, from tightest to loosest: `~`, then `&`, then `|`, then `->`, then `<->`.
16
+
17
+ - `~` applies to the shortest formula that follows it: an atom, a parenthesised formula or another negation. So `~A & B` is `(~A) & B`.
18
+ - `A & B | C` is `(A & B) | C`, and `A | B & C` is `A | (B & C)`.
19
+ - `A | B -> C & D` is `(A | B) -> (C & D)`.
20
+ - `A -> B <-> C` is `(A -> B) <-> C`.
21
+ - `&` and `|` group to the left: `A & B & C` is `(A & B) & C`.
22
+ - `->` and `<->` group to the right: `A -> B -> C` is `A -> (B -> C)`, and `A <-> B <-> C` is `A <-> (B <-> C)`.
23
+
24
+ ## Truth conditions
25
+
26
+ | X | Y | ~X | X & Y | X \| Y | X -> Y | X <-> Y |
27
+ |---|---|---|---|---|---|---|
28
+ | true | true | false | true | true | true | true |
29
+ | true | false | false | false | true | false | false |
30
+ | false | true | true | false | true | true | false |
31
+ | false | false | true | false | false | true | true |
32
+
33
+ ## Valuations and rows
34
+
35
+ A valuation gives each atom the value true or false. For one problem (one argument, one set of sentences or one pair of formulas) the atoms that occur are the atoms that appear in at least one of its formulas. The truth table of the problem has one row for each valuation of the atoms that occur: 2 to the power n rows for n atoms. Every count of rows or valuations asked for is a count over this table.
36
+
37
+ In `answer.json` a valuation is a JSON object whose keys are exactly the atoms that occur in the problem and whose values are the JSON booleans `true` and `false`, for example `{"A": true, "B": false}`. Leave no atom out and add none.
38
+
39
+ ## Definitions
40
+
41
+ - An argument is **valid** if there is no row in which every premise is true and the conclusion is false. Otherwise it is invalid, and any such row is a **counterexample**. An argument whose premises are never all true together is therefore valid.
42
+ - A premise of a valid argument is **essential** if the argument becomes invalid when that one premise is deleted and the others are kept.
43
+ - A set of sentences is **satisfiable** (consistent) if at least one row makes every sentence in it true. Such a row is a **model** of the set.
44
+ - An atom is **forced true** by a satisfiable set if it is true in every model of the set, and **forced false** if it is false in every model.
45
+ - Two formulas are **equivalent** if they have the same truth value in every row. A row in which they differ is a **distinguishing valuation**.
46
+ - A **literal** is an atom or `~` followed by an atom (`~~A` is not a literal).
47
+ - A formula is in **conjunctive normal form (CNF)** if, once parsed by the rules above, it is a conjunction (`&`) of one or more clauses, where each clause is a disjunction (`|`) of one or more literals. `(A | ~B) & C` and `A | B` and `~A` are in CNF. `A | B & C` is not: it parses as `A | (B & C)`. `->` and `<->` do not occur in a CNF.
48
+ - A formula is in **disjunctive normal form (DNF)** if, once parsed, it is a disjunction (`|`) of one or more terms, where each term is a conjunction (`&`) of one or more literals. `A & ~B | C` and `A & B` are in DNF.
tasks/argument-check/argument-check-consistency-d1-e0000/environment/workdir/sentence_sets.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "id": "SET01",
4
+ "source": "Sheet 5, question 10",
5
+ "sentences": [
6
+ "M -> ~E",
7
+ "E -> M"
8
+ ]
9
+ },
10
+ {
11
+ "id": "SET02",
12
+ "source": "Sheet 3, question 13",
13
+ "sentences": [
14
+ "~A & ~M",
15
+ "~M & ~E",
16
+ "A | E"
17
+ ]
18
+ },
19
+ {
20
+ "id": "SET03",
21
+ "source": "Sheet 5, question 7",
22
+ "sentences": [
23
+ "A | M",
24
+ "~E <-> A",
25
+ "E | A",
26
+ "~E"
27
+ ]
28
+ },
29
+ {
30
+ "id": "SET04",
31
+ "source": "Sheet 2, question 3",
32
+ "sentences": [
33
+ "~A",
34
+ "~M <-> A",
35
+ "~E & A",
36
+ "E | ~A"
37
+ ]
38
+ }
39
+ ]
tasks/argument-check/argument-check-consistency-d1-e0000/instruction.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Argument check: consistency
2
+
3
+ `sentence_sets.json` holds 4 sets of sentences in propositional logic. `logic_reference.md` gives the formula syntax, including how to read formulas that are not fully parenthesised, and the definitions to apply.
4
+
5
+ Test every set with a full truth table over the atoms that occur in it.
6
+
7
+ Write `answer.json` in this folder, a JSON object with:
8
+
9
+ - `sets`: an object keyed by set id. For each set give
10
+ - `satisfiable`: `true` or `false`.
11
+ - `models`: the number of rows in which every sentence of the set is true, as an integer (0 if unsatisfiable).
12
+ - `most_true_together`: the largest number of sentences of the set that are true in one and the same row, as an integer (for a satisfiable set this is the number of sentences).
13
+ - `valuation`: for a satisfiable set, one model written as a valuation (an object giving `true` or `false` to exactly the atoms that occur in the set). Any model is accepted. For an unsatisfiable set give `null`.
14
+ - `unsatisfiable_ids`: list of the ids of the unsatisfiable sets (any order).
tasks/argument-check/argument-check-consistency-d1-e0000/solution/oracle.py ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Reference solution for Argument Check. Works only from the files in the current directory.
3
+
4
+ Formulas are read with a shunting-yard pass into reverse Polish notation and evaluated on a stack,
5
+ following the precedence and grouping rules of logic_reference.md.
6
+ """
7
+ import json, os
8
+
9
+ BINDING = {"~": 5, "&": 4, "|": 3, "->": 2, "<->": 1}
10
+ GROUPS_RIGHT = {"~", "->", "<->"}
11
+
12
+ def lex(text):
13
+ toks, i = [], 0
14
+ while i < len(text):
15
+ c = text[i]
16
+ if c.isspace(): i += 1; continue
17
+ if text[i:i + 3] == "<->": toks.append("<->"); i += 3; continue
18
+ if text[i:i + 2] == "->": toks.append("->"); i += 2; continue
19
+ if c in "~&|()" or (len(c) == 1 and "A" <= c <= "Z"): toks.append(c); i += 1; continue
20
+ raise ValueError("cannot read %r" % text)
21
+ return toks
22
+
23
+ def to_rpn(text):
24
+ out, ops = [], []
25
+ expect_operand = True
26
+ for t in lex(text):
27
+ if t not in BINDING and t not in "()": # an atom
28
+ if not expect_operand: raise ValueError(text)
29
+ out.append(t); expect_operand = False
30
+ elif t == "~":
31
+ if not expect_operand: raise ValueError(text)
32
+ ops.append(t)
33
+ elif t == "(":
34
+ if not expect_operand: raise ValueError(text)
35
+ ops.append(t)
36
+ elif t == ")":
37
+ if expect_operand: raise ValueError(text)
38
+ while ops and ops[-1] != "(": out.append(ops.pop())
39
+ if not ops: raise ValueError(text)
40
+ ops.pop()
41
+ else: # a two-place connective
42
+ if expect_operand: raise ValueError(text)
43
+ while ops and ops[-1] != "(" and (BINDING[ops[-1]] > BINDING[t] or (BINDING[ops[-1]] == BINDING[t] and t not in GROUPS_RIGHT)):
44
+ out.append(ops.pop())
45
+ ops.append(t); expect_operand = True
46
+ if expect_operand: raise ValueError(text)
47
+ while ops:
48
+ if ops[-1] == "(": raise ValueError(text)
49
+ out.append(ops.pop())
50
+ return out
51
+
52
+ def run(rpn, val):
53
+ st = []
54
+ for t in rpn:
55
+ if t == "~": st.append(not st.pop())
56
+ elif t in BINDING:
57
+ y = st.pop(); x = st.pop()
58
+ st.append((x and y) if t == "&" else (x or y) if t == "|" else ((not x) or y) if t == "->" else (x == y))
59
+ else: st.append(val[t])
60
+ assert len(st) == 1
61
+ return st[0]
62
+
63
+ def letters(rpns):
64
+ return sorted(set(t for rpn in rpns for t in rpn if t not in BINDING))
65
+
66
+ def all_rows(atoms):
67
+ rows = []
68
+ for k in range(2 ** len(atoms)):
69
+ rows.append(dict((a, bool((k >> i) & 1)) for i, a in enumerate(atoms)))
70
+ return rows
71
+
72
+ def load(name):
73
+ with open(name) as f: return json.load(f)
74
+
75
+ def validity():
76
+ ans = {"arguments": {}, "valid_ids": []}
77
+ for arg in load("arguments.json"):
78
+ prem = [to_rpn(p) for p in arg["premises"]]; concl = to_rpn(arg["conclusion"])
79
+ rows = all_rows(letters(prem + [concl]))
80
+ def bad_rows(ps):
81
+ return [v for v in rows if all(run(p, v) for p in ps) and not run(concl, v)]
82
+ p_true = sum(1 for v in rows if all(run(p, v) for p in prem))
83
+ cex = bad_rows(prem)
84
+ rec = {"valid": not cex, "premise_true_rows": p_true, "counterexample_rows": len(cex), "counterexample": cex[0] if cex else None}
85
+ if not cex:
86
+ rec["essential_premises"] = [i + 1 for i in range(len(prem)) if bad_rows(prem[:i] + prem[i + 1:])]
87
+ ans["valid_ids"].append(arg["id"])
88
+ ans["arguments"][arg["id"]] = rec
89
+ return ans
90
+
91
+ def consistency():
92
+ ans = {"sets": {}, "unsatisfiable_ids": []}
93
+ for s in load("sentence_sets.json"):
94
+ sents = [to_rpn(x) for x in s["sentences"]]
95
+ atoms = letters(sents); rows = all_rows(atoms)
96
+ truth = [[run(x, v) for x in sents] for v in rows]
97
+ models = [v for v, t in zip(rows, truth) if all(t)]
98
+ rec = {"satisfiable": bool(models), "models": len(models), "most_true_together": max(sum(t) for t in truth),
99
+ "valuation": models[0] if models else None}
100
+ if models:
101
+ rec["forced_true"] = [a for a in atoms if all(m[a] for m in models)]
102
+ rec["forced_false"] = [a for a in atoms if not any(m[a] for m in models)]
103
+ else:
104
+ rec["restoring"] = [i + 1 for i in range(len(sents)) if any(all(t[:i] + t[i + 1:]) for t in truth)]
105
+ ans["unsatisfiable_ids"].append(s["id"])
106
+ ans["sets"][s["id"]] = rec
107
+ return ans
108
+
109
+ def lit(atom, positive):
110
+ return atom if positive else "~" + atom
111
+
112
+ def equivalence():
113
+ ans = {"pairs": {}, "equivalent_ids": []}
114
+ for p in load("pairs.json"):
115
+ left, right = to_rpn(p["left"]), to_rpn(p["right"])
116
+ rows = all_rows(letters([left, right]))
117
+ l_only = [v for v in rows if run(left, v) and not run(right, v)]
118
+ r_only = [v for v in rows if run(right, v) and not run(left, v)]
119
+ same = not l_only and not r_only
120
+ ans["pairs"][p["id"]] = {
121
+ "equivalent": same, "left_models": sum(1 for v in rows if run(left, v)), "right_models": sum(1 for v in rows if run(right, v)),
122
+ "left_only_rows": len(l_only),
123
+ "relation": "equivalent" if same else "left-entails-right" if not l_only else "right-entails-left" if not r_only else "neither",
124
+ "distinguishing": None if same else (l_only + r_only)[0]}
125
+ if same: ans["equivalent_ids"].append(p["id"])
126
+ if os.path.exists("convert.json"):
127
+ ans["cnf"], ans["dnf"] = {}, {}
128
+ for c in load("convert.json"):
129
+ f = to_rpn(c["formula"]); atoms = letters([f]); rows = all_rows(atoms)
130
+ # one clause per false row (the clause is false in exactly that row); one term per true row
131
+ clauses = ["(" + " | ".join(lit(a, not v[a]) for a in atoms) + ")" for v in rows if not run(f, v)]
132
+ terms = ["(" + " & ".join(lit(a, v[a]) for a in atoms) + ")" for v in rows if run(f, v)]
133
+ ans["cnf"][c["id"]] = " & ".join(clauses)
134
+ ans["dnf"][c["id"]] = " | ".join(terms)
135
+ return ans
136
+
137
+ def main():
138
+ if os.path.exists("arguments.json"): answer = validity()
139
+ elif os.path.exists("sentence_sets.json"): answer = consistency()
140
+ else: answer = equivalence()
141
+ with open("answer.json", "w") as f: json.dump(answer, f, indent=1)
142
+
143
+ if __name__ == "__main__":
144
+ main()
tasks/argument-check/argument-check-consistency-d1-e0000/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py
tasks/argument-check/argument-check-consistency-d1-e0000/task.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version = "1.0"
2
+
3
+ [metadata]
4
+ author_name = "Renaissance Labs"
5
+ author_email = "unknown"
6
+ difficulty = "easy"
7
+ category = "argument-check"
8
+ tags = ["argument-check", "consistency", "isced-0223", "eval"]
9
+ isced_f = "0223"
10
+ family = "consistency"
11
+ split = "eval"
12
+ seed = 10000
13
+
14
+ [verifier]
15
+ timeout_sec = 120.0
16
+
17
+ [agent]
18
+ timeout_sec = 900.0
19
+
20
+ [environment]
21
+ build_timeout_sec = 600.0
22
+ cpus = 1
23
+ memory_mb = 1024
24
+ storage_mb = 2048
25
+ allow_internet = false
tasks/argument-check/argument-check-consistency-d1-e0000/tests/checks.json ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "path": "sets.SET01.satisfiable",
4
+ "type": "bool",
5
+ "value": true,
6
+ "weight": 1.0
7
+ },
8
+ {
9
+ "path": "sets.SET01.models",
10
+ "type": "int",
11
+ "value": 2,
12
+ "weight": 1.0
13
+ },
14
+ {
15
+ "path": "sets.SET01.most_true_together",
16
+ "type": "int",
17
+ "value": 2,
18
+ "weight": 1.0
19
+ },
20
+ {
21
+ "type": "custom",
22
+ "name": "satisfying_valuation",
23
+ "args": {
24
+ "id": "SET01",
25
+ "sentences": [
26
+ "M -> ~E",
27
+ "E -> M"
28
+ ]
29
+ },
30
+ "weight": 1.0
31
+ },
32
+ {
33
+ "path": "sets.SET02.satisfiable",
34
+ "type": "bool",
35
+ "value": false,
36
+ "weight": 1.0
37
+ },
38
+ {
39
+ "path": "sets.SET02.models",
40
+ "type": "int",
41
+ "value": 0,
42
+ "weight": 1.0
43
+ },
44
+ {
45
+ "path": "sets.SET02.most_true_together",
46
+ "type": "int",
47
+ "value": 2,
48
+ "weight": 1.0
49
+ },
50
+ {
51
+ "path": "sets.SET03.satisfiable",
52
+ "type": "bool",
53
+ "value": true,
54
+ "weight": 1.0
55
+ },
56
+ {
57
+ "path": "sets.SET03.models",
58
+ "type": "int",
59
+ "value": 2,
60
+ "weight": 1.0
61
+ },
62
+ {
63
+ "path": "sets.SET03.most_true_together",
64
+ "type": "int",
65
+ "value": 4,
66
+ "weight": 1.0
67
+ },
68
+ {
69
+ "type": "custom",
70
+ "name": "satisfying_valuation",
71
+ "args": {
72
+ "id": "SET03",
73
+ "sentences": [
74
+ "A | M",
75
+ "~E <-> A",
76
+ "E | A",
77
+ "~E"
78
+ ]
79
+ },
80
+ "weight": 1.0
81
+ },
82
+ {
83
+ "path": "sets.SET04.satisfiable",
84
+ "type": "bool",
85
+ "value": false,
86
+ "weight": 1.0
87
+ },
88
+ {
89
+ "path": "sets.SET04.models",
90
+ "type": "int",
91
+ "value": 0,
92
+ "weight": 1.0
93
+ },
94
+ {
95
+ "path": "sets.SET04.most_true_together",
96
+ "type": "int",
97
+ "value": 3,
98
+ "weight": 1.0
99
+ },
100
+ {
101
+ "path": "unsatisfiable_ids",
102
+ "type": "set",
103
+ "value": [
104
+ "SET02",
105
+ "SET04"
106
+ ],
107
+ "item": "str",
108
+ "weight": 2
109
+ }
110
+ ]
tasks/argument-check/argument-check-consistency-d1-e0000/tests/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
tasks/argument-check/argument-check-consistency-d1-e0000/tests/validators.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Custom checks for Argument Check. Standalone, standard library only.
2
+
3
+ Every function reads the candidate from the answer, evaluates the formulas of the problem itself
4
+ (the formulas arrive in `args` as text) and returns True only if the candidate really has the
5
+ property asked for. Nothing is compared with a stored solution. Malformed answers return False.
6
+ """
7
+
8
+ _LEVEL = {"<->": 1, "->": 2, "|": 3, "&": 4}
9
+ _MAX_LEN = 2000
10
+
11
+ class _Bad(Exception):
12
+ pass
13
+
14
+ def _scan(text):
15
+ if not isinstance(text, str): raise _Bad()
16
+ toks, i, n = [], 0, len(text)
17
+ while i < n:
18
+ c = text[i]
19
+ if c == " " or c == "\t": i += 1
20
+ elif c == "<" and text[i:i + 3] == "<->": toks.append("<->"); i += 3
21
+ elif c == "-" and text[i:i + 2] == "->": toks.append("->"); i += 2
22
+ elif c in ("~", "&", "|", "(", ")"): toks.append(c); i += 1
23
+ elif c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": toks.append(c); i += 1
24
+ else: raise _Bad()
25
+ return toks
26
+
27
+ def _read(text):
28
+ """Precedence climbing. Tree nodes: ("atom", A), ("not", x), ("bin", op, x, y)."""
29
+ toks = _scan(text)
30
+ state = {"i": 0}
31
+ def primary():
32
+ i = state["i"]
33
+ if i >= len(toks): raise _Bad()
34
+ t = toks[i]; state["i"] = i + 1
35
+ if t == "~": return ("not", primary())
36
+ if t == "(":
37
+ x = climb(1)
38
+ if state["i"] >= len(toks) or toks[state["i"]] != ")": raise _Bad()
39
+ state["i"] += 1
40
+ return x
41
+ if len(t) == 1 and t.isalpha(): return ("atom", t)
42
+ raise _Bad()
43
+ def climb(min_level):
44
+ left = primary()
45
+ while state["i"] < len(toks):
46
+ op = toks[state["i"]]
47
+ lv = _LEVEL.get(op)
48
+ if lv is None or lv < min_level: break
49
+ state["i"] += 1
50
+ # & and | group to the left, so the right operand must bind tighter; -> and <-> group to the right
51
+ right = climb(lv if op in ("->", "<->") else lv + 1)
52
+ left = ("bin", op, left, right)
53
+ return left
54
+ tree = climb(1)
55
+ if state["i"] != len(toks): raise _Bad()
56
+ return tree
57
+
58
+ def _value(t, v):
59
+ kind = t[0]
60
+ if kind == "atom": return v[t[1]]
61
+ if kind == "not": return not _value(t[1], v)
62
+ op, x, y = t[1], _value(t[2], v), _value(t[3], v)
63
+ if op == "&": return x and y
64
+ if op == "|": return x or y
65
+ if op == "->": return y or not x
66
+ return x is y
67
+
68
+ def _atoms(trees):
69
+ found, stack = set(), list(trees)
70
+ while stack:
71
+ t = stack.pop()
72
+ if t[0] == "atom": found.add(t[1])
73
+ elif t[0] == "not": stack.append(t[1])
74
+ else: stack.append(t[2]); stack.append(t[3])
75
+ return found
76
+
77
+ def _valuation(obj, atoms):
78
+ """The candidate must be an object with exactly the atoms that occur as keys and booleans as values."""
79
+ if not isinstance(obj, dict) or set(obj.keys()) != set(atoms): return None
80
+ for k in obj:
81
+ if obj[k] is not True and obj[k] is not False: return None
82
+ return obj
83
+
84
+ def _dig(answer, keys):
85
+ cur = answer
86
+ for k in keys:
87
+ if not isinstance(cur, dict) or k not in cur: return None
88
+ cur = cur[k]
89
+ return cur
90
+
91
+ def counterexample(answer, args):
92
+ """answer.arguments.<id>.counterexample makes every premise true and the conclusion false."""
93
+ try:
94
+ prem = [_read(p) for p in args["premises"]]; concl = _read(args["conclusion"])
95
+ v = _valuation(_dig(answer, ["arguments", args["id"], "counterexample"]), _atoms(prem + [concl]))
96
+ if v is None: return False
97
+ return all(_value(p, v) for p in prem) and not _value(concl, v)
98
+ except Exception:
99
+ return False
100
+
101
+ def satisfying_valuation(answer, args):
102
+ """answer.sets.<id>.valuation makes every sentence of the set true."""
103
+ try:
104
+ sents = [_read(s) for s in args["sentences"]]
105
+ v = _valuation(_dig(answer, ["sets", args["id"], "valuation"]), _atoms(sents))
106
+ if v is None: return False
107
+ return all(_value(s, v) for s in sents)
108
+ except Exception:
109
+ return False
110
+
111
+ def distinguishing_valuation(answer, args):
112
+ """answer.pairs.<id>.distinguishing gives the two formulas different truth values."""
113
+ try:
114
+ left, right = _read(args["left"]), _read(args["right"])
115
+ v = _valuation(_dig(answer, ["pairs", args["id"], "distinguishing"]), _atoms([left, right]))
116
+ if v is None: return False
117
+ return _value(left, v) is not _value(right, v)
118
+ except Exception:
119
+ return False
120
+
121
+ def _flatten(t, op):
122
+ parts, stack = [], [t]
123
+ while stack:
124
+ x = stack.pop()
125
+ if x[0] == "bin" and x[1] == op: stack.append(x[3]); stack.append(x[2])
126
+ else: parts.append(x)
127
+ return parts
128
+
129
+ def _is_literal(t):
130
+ return t[0] == "atom" or (t[0] == "not" and t[1][0] == "atom")
131
+
132
+ def normal_form(answer, args):
133
+ """answer.<form>.<id> is a formula in the normal form asked for (args.form is "cnf" or "dnf"), equivalent to
134
+ args.formula, built only from atoms of args.formula, and at most 2000 characters long."""
135
+ try:
136
+ form = args["form"]
137
+ if form not in ("cnf", "dnf"): return False
138
+ text = _dig(answer, [form, args["id"]])
139
+ if not isinstance(text, str) or len(text) > _MAX_LEN: return False
140
+ orig = _read(args["formula"]); cand = _read(text)
141
+ atoms = sorted(_atoms([orig]))
142
+ if not _atoms([cand]) <= set(atoms): return False
143
+ outer, inner = ("&", "|") if form == "cnf" else ("|", "&")
144
+ for part in _flatten(cand, outer):
145
+ for leaf in _flatten(part, inner):
146
+ if not _is_literal(leaf): return False
147
+ for k in range(2 ** len(atoms)):
148
+ v = dict((a, bool((k >> i) & 1)) for i, a in enumerate(atoms))
149
+ if _value(orig, v) is not _value(cand, v): return False
150
+ return True
151
+ except Exception:
152
+ return False
tasks/argument-check/argument-check-consistency-d1-e0000/tests/verify.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verifier for Renaissance Labs practice environments. Standard library only.
3
+
4
+ Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
5
+ The reward is the weighted share of checks that pass. A missing, unreadable or non-object
6
+ answer scores 0. Each check addresses one value in the answer by a dotted path.
7
+
8
+ Check types
9
+ int exact integer (a float with integral value is accepted; booleans are not)
10
+ number within abs_tol of value (default 1e-9); booleans and strings are rejected
11
+ str equal after trimming and case-folding
12
+ bool exact boolean
13
+ list ordered list; items compared as int/number/str according to "item" (default str)
14
+ set unordered collection of distinct strings (or ints)
15
+ custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
16
+ """
17
+ import argparse, json, math, os, sys
18
+
19
+ MISSING = object()
20
+
21
+ def lookup(obj, path):
22
+ cur = obj
23
+ for part in path.split("."):
24
+ if isinstance(cur, dict):
25
+ if part not in cur: return MISSING
26
+ cur = cur[part]
27
+ elif isinstance(cur, list):
28
+ try: cur = cur[int(part)]
29
+ except (ValueError, IndexError): return MISSING
30
+ else:
31
+ return MISSING
32
+ return cur
33
+
34
+ def is_num(x):
35
+ return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
36
+
37
+ def eq_int(got, want):
38
+ return is_num(got) and float(got) == float(int(got)) and int(got) == want
39
+
40
+ def eq_num(got, want, tol):
41
+ return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
42
+
43
+ def eq_str(got, want):
44
+ return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
45
+
46
+ def eq_item(got, want, kind, tol):
47
+ if kind == "int": return eq_int(got, want)
48
+ if kind == "number": return eq_num(got, want, tol)
49
+ return eq_str(got, want)
50
+
51
+ def run_check(answer, chk, validators):
52
+ t = chk["type"]
53
+ if t == "custom":
54
+ fn = getattr(validators, chk["name"], None) if validators else None
55
+ if fn is None: return 0.0
56
+ try: r = fn(answer, chk.get("args", {}))
57
+ except Exception: return 0.0
58
+ if r is True: return 1.0
59
+ if r is False or r is None: return 0.0
60
+ return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
61
+ got = lookup(answer, chk["path"])
62
+ if got is MISSING: return 0.0
63
+ want, tol = chk["value"], chk.get("abs_tol", 1e-9)
64
+ if t == "int": ok = eq_int(got, want)
65
+ elif t == "number": ok = eq_num(got, want, tol)
66
+ elif t == "str": ok = eq_str(got, want)
67
+ elif t == "bool": ok = isinstance(got, bool) and got is want
68
+ elif t == "list":
69
+ ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
70
+ elif t == "set":
71
+ kind = chk.get("item", "str")
72
+ if not isinstance(got, list): ok = False
73
+ else:
74
+ norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
75
+ g = [norm(x) for x in got]; w = [norm(x) for x in want]
76
+ ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
77
+ else: ok = False
78
+ return 1.0 if ok else 0.0
79
+
80
+ def grade(answer, checks, validators=None):
81
+ """Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
82
+ if not isinstance(answer, dict):
83
+ return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
84
+ total = sum(c.get("weight", 1.0) for c in checks)
85
+ got, details = 0.0, []
86
+ for c in checks:
87
+ s = run_check(answer, c, validators)
88
+ got += s * c.get("weight", 1.0)
89
+ details.append({"check": c.get("path", c.get("name")), "score": s})
90
+ return (round(got / total, 6) if total else 0.0), details
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("--answer", default="/app/answer.json")
95
+ ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
96
+ ap.add_argument("--out", default="/logs/verifier")
97
+ a = ap.parse_args()
98
+ checks = json.load(open(a.checks))
99
+ try:
100
+ with open(a.answer) as f: answer = json.load(f)
101
+ except Exception:
102
+ answer = None
103
+ validators = None
104
+ here = os.path.dirname(os.path.abspath(__file__))
105
+ if os.path.exists(os.path.join(here, "validators.py")):
106
+ sys.path.insert(0, here)
107
+ import validators # noqa
108
+ reward, details = grade(answer, checks, validators)
109
+ os.makedirs(a.out, exist_ok=True)
110
+ with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
111
+ with open(os.path.join(a.out, "reward.json"), "w") as f:
112
+ json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
113
+ print("reward", reward)
114
+
115
+ if __name__ == "__main__":
116
+ main()
tasks/argument-check/argument-check-consistency-d1-e0009/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/argument-check/argument-check-consistency-d1-e0009/environment/workdir/logic_reference.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Logic reference
2
+
3
+ ## Formulas
4
+
5
+ - An atom is a single capital letter, `A` to `Z`.
6
+ - `~X` means not X.
7
+ - `X & Y` means X and Y.
8
+ - `X | Y` means X or Y (inclusive: one or the other or both).
9
+ - `X -> Y` means if X then Y.
10
+ - `X <-> Y` means X if and only if Y.
11
+ - Parentheses `(` and `)` group. Spaces between symbols are optional and carry no meaning.
12
+
13
+ ## Reading a formula that is not fully parenthesised
14
+
15
+ The connectives bind in this order, from tightest to loosest: `~`, then `&`, then `|`, then `->`, then `<->`.
16
+
17
+ - `~` applies to the shortest formula that follows it: an atom, a parenthesised formula or another negation. So `~A & B` is `(~A) & B`.
18
+ - `A & B | C` is `(A & B) | C`, and `A | B & C` is `A | (B & C)`.
19
+ - `A | B -> C & D` is `(A | B) -> (C & D)`.
20
+ - `A -> B <-> C` is `(A -> B) <-> C`.
21
+ - `&` and `|` group to the left: `A & B & C` is `(A & B) & C`.
22
+ - `->` and `<->` group to the right: `A -> B -> C` is `A -> (B -> C)`, and `A <-> B <-> C` is `A <-> (B <-> C)`.
23
+
24
+ ## Truth conditions
25
+
26
+ | X | Y | ~X | X & Y | X \| Y | X -> Y | X <-> Y |
27
+ |---|---|---|---|---|---|---|
28
+ | true | true | false | true | true | true | true |
29
+ | true | false | false | false | true | false | false |
30
+ | false | true | true | false | true | true | false |
31
+ | false | false | true | false | false | true | true |
32
+
33
+ ## Valuations and rows
34
+
35
+ A valuation gives each atom the value true or false. For one problem (one argument, one set of sentences or one pair of formulas) the atoms that occur are the atoms that appear in at least one of its formulas. The truth table of the problem has one row for each valuation of the atoms that occur: 2 to the power n rows for n atoms. Every count of rows or valuations asked for is a count over this table.
36
+
37
+ In `answer.json` a valuation is a JSON object whose keys are exactly the atoms that occur in the problem and whose values are the JSON booleans `true` and `false`, for example `{"A": true, "B": false}`. Leave no atom out and add none.
38
+
39
+ ## Definitions
40
+
41
+ - An argument is **valid** if there is no row in which every premise is true and the conclusion is false. Otherwise it is invalid, and any such row is a **counterexample**. An argument whose premises are never all true together is therefore valid.
42
+ - A premise of a valid argument is **essential** if the argument becomes invalid when that one premise is deleted and the others are kept.
43
+ - A set of sentences is **satisfiable** (consistent) if at least one row makes every sentence in it true. Such a row is a **model** of the set.
44
+ - An atom is **forced true** by a satisfiable set if it is true in every model of the set, and **forced false** if it is false in every model.
45
+ - Two formulas are **equivalent** if they have the same truth value in every row. A row in which they differ is a **distinguishing valuation**.
46
+ - A **literal** is an atom or `~` followed by an atom (`~~A` is not a literal).
47
+ - A formula is in **conjunctive normal form (CNF)** if, once parsed by the rules above, it is a conjunction (`&`) of one or more clauses, where each clause is a disjunction (`|`) of one or more literals. `(A | ~B) & C` and `A | B` and `~A` are in CNF. `A | B & C` is not: it parses as `A | (B & C)`. `->` and `<->` do not occur in a CNF.
48
+ - A formula is in **disjunctive normal form (DNF)** if, once parsed, it is a disjunction (`|`) of one or more terms, where each term is a conjunction (`&`) of one or more literals. `A & ~B | C` and `A & B` are in DNF.
tasks/argument-check/argument-check-consistency-d1-e0009/environment/workdir/sentence_sets.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "id": "SET01",
4
+ "source": "Sheet 3, question 13",
5
+ "sentences": [
6
+ "~G",
7
+ "S & G"
8
+ ]
9
+ },
10
+ {
11
+ "id": "SET02",
12
+ "source": "Sheet 7, question 8",
13
+ "sentences": [
14
+ "F <-> S",
15
+ "F",
16
+ "S <-> G",
17
+ "F & S"
18
+ ]
19
+ },
20
+ {
21
+ "id": "SET03",
22
+ "source": "Sheet 7, question 20",
23
+ "sentences": [
24
+ "~S",
25
+ "~F & S",
26
+ "~S & F"
27
+ ]
28
+ },
29
+ {
30
+ "id": "SET04",
31
+ "source": "Sheet 9, question 15",
32
+ "sentences": [
33
+ "F -> ~G",
34
+ "~F & G"
35
+ ]
36
+ }
37
+ ]
tasks/argument-check/argument-check-consistency-d1-e0009/instruction.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Argument check: consistency
2
+
3
+ `sentence_sets.json` holds 4 sets of sentences in propositional logic. `logic_reference.md` gives the formula syntax, including how to read formulas that are not fully parenthesised, and the definitions to apply.
4
+
5
+ Test every set with a full truth table over the atoms that occur in it.
6
+
7
+ Write `answer.json` in this folder, a JSON object with:
8
+
9
+ - `sets`: an object keyed by set id. For each set give
10
+ - `satisfiable`: `true` or `false`.
11
+ - `models`: the number of rows in which every sentence of the set is true, as an integer (0 if unsatisfiable).
12
+ - `most_true_together`: the largest number of sentences of the set that are true in one and the same row, as an integer (for a satisfiable set this is the number of sentences).
13
+ - `valuation`: for a satisfiable set, one model written as a valuation (an object giving `true` or `false` to exactly the atoms that occur in the set). Any model is accepted. For an unsatisfiable set give `null`.
14
+ - `unsatisfiable_ids`: list of the ids of the unsatisfiable sets (any order).
tasks/argument-check/argument-check-consistency-d1-e0009/solution/oracle.py ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Reference solution for Argument Check. Works only from the files in the current directory.
3
+
4
+ Formulas are read with a shunting-yard pass into reverse Polish notation and evaluated on a stack,
5
+ following the precedence and grouping rules of logic_reference.md.
6
+ """
7
+ import json, os
8
+
9
+ BINDING = {"~": 5, "&": 4, "|": 3, "->": 2, "<->": 1}
10
+ GROUPS_RIGHT = {"~", "->", "<->"}
11
+
12
+ def lex(text):
13
+ toks, i = [], 0
14
+ while i < len(text):
15
+ c = text[i]
16
+ if c.isspace(): i += 1; continue
17
+ if text[i:i + 3] == "<->": toks.append("<->"); i += 3; continue
18
+ if text[i:i + 2] == "->": toks.append("->"); i += 2; continue
19
+ if c in "~&|()" or (len(c) == 1 and "A" <= c <= "Z"): toks.append(c); i += 1; continue
20
+ raise ValueError("cannot read %r" % text)
21
+ return toks
22
+
23
+ def to_rpn(text):
24
+ out, ops = [], []
25
+ expect_operand = True
26
+ for t in lex(text):
27
+ if t not in BINDING and t not in "()": # an atom
28
+ if not expect_operand: raise ValueError(text)
29
+ out.append(t); expect_operand = False
30
+ elif t == "~":
31
+ if not expect_operand: raise ValueError(text)
32
+ ops.append(t)
33
+ elif t == "(":
34
+ if not expect_operand: raise ValueError(text)
35
+ ops.append(t)
36
+ elif t == ")":
37
+ if expect_operand: raise ValueError(text)
38
+ while ops and ops[-1] != "(": out.append(ops.pop())
39
+ if not ops: raise ValueError(text)
40
+ ops.pop()
41
+ else: # a two-place connective
42
+ if expect_operand: raise ValueError(text)
43
+ while ops and ops[-1] != "(" and (BINDING[ops[-1]] > BINDING[t] or (BINDING[ops[-1]] == BINDING[t] and t not in GROUPS_RIGHT)):
44
+ out.append(ops.pop())
45
+ ops.append(t); expect_operand = True
46
+ if expect_operand: raise ValueError(text)
47
+ while ops:
48
+ if ops[-1] == "(": raise ValueError(text)
49
+ out.append(ops.pop())
50
+ return out
51
+
52
+ def run(rpn, val):
53
+ st = []
54
+ for t in rpn:
55
+ if t == "~": st.append(not st.pop())
56
+ elif t in BINDING:
57
+ y = st.pop(); x = st.pop()
58
+ st.append((x and y) if t == "&" else (x or y) if t == "|" else ((not x) or y) if t == "->" else (x == y))
59
+ else: st.append(val[t])
60
+ assert len(st) == 1
61
+ return st[0]
62
+
63
+ def letters(rpns):
64
+ return sorted(set(t for rpn in rpns for t in rpn if t not in BINDING))
65
+
66
+ def all_rows(atoms):
67
+ rows = []
68
+ for k in range(2 ** len(atoms)):
69
+ rows.append(dict((a, bool((k >> i) & 1)) for i, a in enumerate(atoms)))
70
+ return rows
71
+
72
+ def load(name):
73
+ with open(name) as f: return json.load(f)
74
+
75
+ def validity():
76
+ ans = {"arguments": {}, "valid_ids": []}
77
+ for arg in load("arguments.json"):
78
+ prem = [to_rpn(p) for p in arg["premises"]]; concl = to_rpn(arg["conclusion"])
79
+ rows = all_rows(letters(prem + [concl]))
80
+ def bad_rows(ps):
81
+ return [v for v in rows if all(run(p, v) for p in ps) and not run(concl, v)]
82
+ p_true = sum(1 for v in rows if all(run(p, v) for p in prem))
83
+ cex = bad_rows(prem)
84
+ rec = {"valid": not cex, "premise_true_rows": p_true, "counterexample_rows": len(cex), "counterexample": cex[0] if cex else None}
85
+ if not cex:
86
+ rec["essential_premises"] = [i + 1 for i in range(len(prem)) if bad_rows(prem[:i] + prem[i + 1:])]
87
+ ans["valid_ids"].append(arg["id"])
88
+ ans["arguments"][arg["id"]] = rec
89
+ return ans
90
+
91
+ def consistency():
92
+ ans = {"sets": {}, "unsatisfiable_ids": []}
93
+ for s in load("sentence_sets.json"):
94
+ sents = [to_rpn(x) for x in s["sentences"]]
95
+ atoms = letters(sents); rows = all_rows(atoms)
96
+ truth = [[run(x, v) for x in sents] for v in rows]
97
+ models = [v for v, t in zip(rows, truth) if all(t)]
98
+ rec = {"satisfiable": bool(models), "models": len(models), "most_true_together": max(sum(t) for t in truth),
99
+ "valuation": models[0] if models else None}
100
+ if models:
101
+ rec["forced_true"] = [a for a in atoms if all(m[a] for m in models)]
102
+ rec["forced_false"] = [a for a in atoms if not any(m[a] for m in models)]
103
+ else:
104
+ rec["restoring"] = [i + 1 for i in range(len(sents)) if any(all(t[:i] + t[i + 1:]) for t in truth)]
105
+ ans["unsatisfiable_ids"].append(s["id"])
106
+ ans["sets"][s["id"]] = rec
107
+ return ans
108
+
109
+ def lit(atom, positive):
110
+ return atom if positive else "~" + atom
111
+
112
+ def equivalence():
113
+ ans = {"pairs": {}, "equivalent_ids": []}
114
+ for p in load("pairs.json"):
115
+ left, right = to_rpn(p["left"]), to_rpn(p["right"])
116
+ rows = all_rows(letters([left, right]))
117
+ l_only = [v for v in rows if run(left, v) and not run(right, v)]
118
+ r_only = [v for v in rows if run(right, v) and not run(left, v)]
119
+ same = not l_only and not r_only
120
+ ans["pairs"][p["id"]] = {
121
+ "equivalent": same, "left_models": sum(1 for v in rows if run(left, v)), "right_models": sum(1 for v in rows if run(right, v)),
122
+ "left_only_rows": len(l_only),
123
+ "relation": "equivalent" if same else "left-entails-right" if not l_only else "right-entails-left" if not r_only else "neither",
124
+ "distinguishing": None if same else (l_only + r_only)[0]}
125
+ if same: ans["equivalent_ids"].append(p["id"])
126
+ if os.path.exists("convert.json"):
127
+ ans["cnf"], ans["dnf"] = {}, {}
128
+ for c in load("convert.json"):
129
+ f = to_rpn(c["formula"]); atoms = letters([f]); rows = all_rows(atoms)
130
+ # one clause per false row (the clause is false in exactly that row); one term per true row
131
+ clauses = ["(" + " | ".join(lit(a, not v[a]) for a in atoms) + ")" for v in rows if not run(f, v)]
132
+ terms = ["(" + " & ".join(lit(a, v[a]) for a in atoms) + ")" for v in rows if run(f, v)]
133
+ ans["cnf"][c["id"]] = " & ".join(clauses)
134
+ ans["dnf"][c["id"]] = " | ".join(terms)
135
+ return ans
136
+
137
+ def main():
138
+ if os.path.exists("arguments.json"): answer = validity()
139
+ elif os.path.exists("sentence_sets.json"): answer = consistency()
140
+ else: answer = equivalence()
141
+ with open("answer.json", "w") as f: json.dump(answer, f, indent=1)
142
+
143
+ if __name__ == "__main__":
144
+ main()
tasks/argument-check/argument-check-consistency-d1-e0009/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py
tasks/argument-check/argument-check-consistency-d1-e0009/task.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version = "1.0"
2
+
3
+ [metadata]
4
+ author_name = "Renaissance Labs"
5
+ author_email = "unknown"
6
+ difficulty = "easy"
7
+ category = "argument-check"
8
+ tags = ["argument-check", "consistency", "isced-0223", "eval"]
9
+ isced_f = "0223"
10
+ family = "consistency"
11
+ split = "eval"
12
+ seed = 10009
13
+
14
+ [verifier]
15
+ timeout_sec = 120.0
16
+
17
+ [agent]
18
+ timeout_sec = 900.0
19
+
20
+ [environment]
21
+ build_timeout_sec = 600.0
22
+ cpus = 1
23
+ memory_mb = 1024
24
+ storage_mb = 2048
25
+ allow_internet = false
tasks/argument-check/argument-check-consistency-d1-e0009/tests/checks.json ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "path": "sets.SET01.satisfiable",
4
+ "type": "bool",
5
+ "value": false,
6
+ "weight": 1.0
7
+ },
8
+ {
9
+ "path": "sets.SET01.models",
10
+ "type": "int",
11
+ "value": 0,
12
+ "weight": 1.0
13
+ },
14
+ {
15
+ "path": "sets.SET01.most_true_together",
16
+ "type": "int",
17
+ "value": 1,
18
+ "weight": 1.0
19
+ },
20
+ {
21
+ "path": "sets.SET02.satisfiable",
22
+ "type": "bool",
23
+ "value": true,
24
+ "weight": 1.0
25
+ },
26
+ {
27
+ "path": "sets.SET02.models",
28
+ "type": "int",
29
+ "value": 1,
30
+ "weight": 1.0
31
+ },
32
+ {
33
+ "path": "sets.SET02.most_true_together",
34
+ "type": "int",
35
+ "value": 4,
36
+ "weight": 1.0
37
+ },
38
+ {
39
+ "type": "custom",
40
+ "name": "satisfying_valuation",
41
+ "args": {
42
+ "id": "SET02",
43
+ "sentences": [
44
+ "F <-> S",
45
+ "F",
46
+ "S <-> G",
47
+ "F & S"
48
+ ]
49
+ },
50
+ "weight": 1.0
51
+ },
52
+ {
53
+ "path": "sets.SET03.satisfiable",
54
+ "type": "bool",
55
+ "value": false,
56
+ "weight": 1.0
57
+ },
58
+ {
59
+ "path": "sets.SET03.models",
60
+ "type": "int",
61
+ "value": 0,
62
+ "weight": 1.0
63
+ },
64
+ {
65
+ "path": "sets.SET03.most_true_together",
66
+ "type": "int",
67
+ "value": 2,
68
+ "weight": 1.0
69
+ },
70
+ {
71
+ "path": "sets.SET04.satisfiable",
72
+ "type": "bool",
73
+ "value": true,
74
+ "weight": 1.0
75
+ },
76
+ {
77
+ "path": "sets.SET04.models",
78
+ "type": "int",
79
+ "value": 1,
80
+ "weight": 1.0
81
+ },
82
+ {
83
+ "path": "sets.SET04.most_true_together",
84
+ "type": "int",
85
+ "value": 2,
86
+ "weight": 1.0
87
+ },
88
+ {
89
+ "type": "custom",
90
+ "name": "satisfying_valuation",
91
+ "args": {
92
+ "id": "SET04",
93
+ "sentences": [
94
+ "F -> ~G",
95
+ "~F & G"
96
+ ]
97
+ },
98
+ "weight": 1.0
99
+ },
100
+ {
101
+ "path": "unsatisfiable_ids",
102
+ "type": "set",
103
+ "value": [
104
+ "SET01",
105
+ "SET03"
106
+ ],
107
+ "item": "str",
108
+ "weight": 2
109
+ }
110
+ ]
tasks/argument-check/argument-check-consistency-d1-e0009/tests/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
tasks/argument-check/argument-check-consistency-d1-e0009/tests/validators.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Custom checks for Argument Check. Standalone, standard library only.
2
+
3
+ Every function reads the candidate from the answer, evaluates the formulas of the problem itself
4
+ (the formulas arrive in `args` as text) and returns True only if the candidate really has the
5
+ property asked for. Nothing is compared with a stored solution. Malformed answers return False.
6
+ """
7
+
8
+ _LEVEL = {"<->": 1, "->": 2, "|": 3, "&": 4}
9
+ _MAX_LEN = 2000
10
+
11
+ class _Bad(Exception):
12
+ pass
13
+
14
+ def _scan(text):
15
+ if not isinstance(text, str): raise _Bad()
16
+ toks, i, n = [], 0, len(text)
17
+ while i < n:
18
+ c = text[i]
19
+ if c == " " or c == "\t": i += 1
20
+ elif c == "<" and text[i:i + 3] == "<->": toks.append("<->"); i += 3
21
+ elif c == "-" and text[i:i + 2] == "->": toks.append("->"); i += 2
22
+ elif c in ("~", "&", "|", "(", ")"): toks.append(c); i += 1
23
+ elif c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": toks.append(c); i += 1
24
+ else: raise _Bad()
25
+ return toks
26
+
27
+ def _read(text):
28
+ """Precedence climbing. Tree nodes: ("atom", A), ("not", x), ("bin", op, x, y)."""
29
+ toks = _scan(text)
30
+ state = {"i": 0}
31
+ def primary():
32
+ i = state["i"]
33
+ if i >= len(toks): raise _Bad()
34
+ t = toks[i]; state["i"] = i + 1
35
+ if t == "~": return ("not", primary())
36
+ if t == "(":
37
+ x = climb(1)
38
+ if state["i"] >= len(toks) or toks[state["i"]] != ")": raise _Bad()
39
+ state["i"] += 1
40
+ return x
41
+ if len(t) == 1 and t.isalpha(): return ("atom", t)
42
+ raise _Bad()
43
+ def climb(min_level):
44
+ left = primary()
45
+ while state["i"] < len(toks):
46
+ op = toks[state["i"]]
47
+ lv = _LEVEL.get(op)
48
+ if lv is None or lv < min_level: break
49
+ state["i"] += 1
50
+ # & and | group to the left, so the right operand must bind tighter; -> and <-> group to the right
51
+ right = climb(lv if op in ("->", "<->") else lv + 1)
52
+ left = ("bin", op, left, right)
53
+ return left
54
+ tree = climb(1)
55
+ if state["i"] != len(toks): raise _Bad()
56
+ return tree
57
+
58
+ def _value(t, v):
59
+ kind = t[0]
60
+ if kind == "atom": return v[t[1]]
61
+ if kind == "not": return not _value(t[1], v)
62
+ op, x, y = t[1], _value(t[2], v), _value(t[3], v)
63
+ if op == "&": return x and y
64
+ if op == "|": return x or y
65
+ if op == "->": return y or not x
66
+ return x is y
67
+
68
+ def _atoms(trees):
69
+ found, stack = set(), list(trees)
70
+ while stack:
71
+ t = stack.pop()
72
+ if t[0] == "atom": found.add(t[1])
73
+ elif t[0] == "not": stack.append(t[1])
74
+ else: stack.append(t[2]); stack.append(t[3])
75
+ return found
76
+
77
+ def _valuation(obj, atoms):
78
+ """The candidate must be an object with exactly the atoms that occur as keys and booleans as values."""
79
+ if not isinstance(obj, dict) or set(obj.keys()) != set(atoms): return None
80
+ for k in obj:
81
+ if obj[k] is not True and obj[k] is not False: return None
82
+ return obj
83
+
84
+ def _dig(answer, keys):
85
+ cur = answer
86
+ for k in keys:
87
+ if not isinstance(cur, dict) or k not in cur: return None
88
+ cur = cur[k]
89
+ return cur
90
+
91
+ def counterexample(answer, args):
92
+ """answer.arguments.<id>.counterexample makes every premise true and the conclusion false."""
93
+ try:
94
+ prem = [_read(p) for p in args["premises"]]; concl = _read(args["conclusion"])
95
+ v = _valuation(_dig(answer, ["arguments", args["id"], "counterexample"]), _atoms(prem + [concl]))
96
+ if v is None: return False
97
+ return all(_value(p, v) for p in prem) and not _value(concl, v)
98
+ except Exception:
99
+ return False
100
+
101
+ def satisfying_valuation(answer, args):
102
+ """answer.sets.<id>.valuation makes every sentence of the set true."""
103
+ try:
104
+ sents = [_read(s) for s in args["sentences"]]
105
+ v = _valuation(_dig(answer, ["sets", args["id"], "valuation"]), _atoms(sents))
106
+ if v is None: return False
107
+ return all(_value(s, v) for s in sents)
108
+ except Exception:
109
+ return False
110
+
111
+ def distinguishing_valuation(answer, args):
112
+ """answer.pairs.<id>.distinguishing gives the two formulas different truth values."""
113
+ try:
114
+ left, right = _read(args["left"]), _read(args["right"])
115
+ v = _valuation(_dig(answer, ["pairs", args["id"], "distinguishing"]), _atoms([left, right]))
116
+ if v is None: return False
117
+ return _value(left, v) is not _value(right, v)
118
+ except Exception:
119
+ return False
120
+
121
+ def _flatten(t, op):
122
+ parts, stack = [], [t]
123
+ while stack:
124
+ x = stack.pop()
125
+ if x[0] == "bin" and x[1] == op: stack.append(x[3]); stack.append(x[2])
126
+ else: parts.append(x)
127
+ return parts
128
+
129
+ def _is_literal(t):
130
+ return t[0] == "atom" or (t[0] == "not" and t[1][0] == "atom")
131
+
132
+ def normal_form(answer, args):
133
+ """answer.<form>.<id> is a formula in the normal form asked for (args.form is "cnf" or "dnf"), equivalent to
134
+ args.formula, built only from atoms of args.formula, and at most 2000 characters long."""
135
+ try:
136
+ form = args["form"]
137
+ if form not in ("cnf", "dnf"): return False
138
+ text = _dig(answer, [form, args["id"]])
139
+ if not isinstance(text, str) or len(text) > _MAX_LEN: return False
140
+ orig = _read(args["formula"]); cand = _read(text)
141
+ atoms = sorted(_atoms([orig]))
142
+ if not _atoms([cand]) <= set(atoms): return False
143
+ outer, inner = ("&", "|") if form == "cnf" else ("|", "&")
144
+ for part in _flatten(cand, outer):
145
+ for leaf in _flatten(part, inner):
146
+ if not _is_literal(leaf): return False
147
+ for k in range(2 ** len(atoms)):
148
+ v = dict((a, bool((k >> i) & 1)) for i, a in enumerate(atoms))
149
+ if _value(orig, v) is not _value(cand, v): return False
150
+ return True
151
+ except Exception:
152
+ return False
tasks/argument-check/argument-check-consistency-d1-e0009/tests/verify.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verifier for Renaissance Labs practice environments. Standard library only.
3
+
4
+ Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
5
+ The reward is the weighted share of checks that pass. A missing, unreadable or non-object
6
+ answer scores 0. Each check addresses one value in the answer by a dotted path.
7
+
8
+ Check types
9
+ int exact integer (a float with integral value is accepted; booleans are not)
10
+ number within abs_tol of value (default 1e-9); booleans and strings are rejected
11
+ str equal after trimming and case-folding
12
+ bool exact boolean
13
+ list ordered list; items compared as int/number/str according to "item" (default str)
14
+ set unordered collection of distinct strings (or ints)
15
+ custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
16
+ """
17
+ import argparse, json, math, os, sys
18
+
19
+ MISSING = object()
20
+
21
+ def lookup(obj, path):
22
+ cur = obj
23
+ for part in path.split("."):
24
+ if isinstance(cur, dict):
25
+ if part not in cur: return MISSING
26
+ cur = cur[part]
27
+ elif isinstance(cur, list):
28
+ try: cur = cur[int(part)]
29
+ except (ValueError, IndexError): return MISSING
30
+ else:
31
+ return MISSING
32
+ return cur
33
+
34
+ def is_num(x):
35
+ return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
36
+
37
+ def eq_int(got, want):
38
+ return is_num(got) and float(got) == float(int(got)) and int(got) == want
39
+
40
+ def eq_num(got, want, tol):
41
+ return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
42
+
43
+ def eq_str(got, want):
44
+ return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
45
+
46
+ def eq_item(got, want, kind, tol):
47
+ if kind == "int": return eq_int(got, want)
48
+ if kind == "number": return eq_num(got, want, tol)
49
+ return eq_str(got, want)
50
+
51
+ def run_check(answer, chk, validators):
52
+ t = chk["type"]
53
+ if t == "custom":
54
+ fn = getattr(validators, chk["name"], None) if validators else None
55
+ if fn is None: return 0.0
56
+ try: r = fn(answer, chk.get("args", {}))
57
+ except Exception: return 0.0
58
+ if r is True: return 1.0
59
+ if r is False or r is None: return 0.0
60
+ return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
61
+ got = lookup(answer, chk["path"])
62
+ if got is MISSING: return 0.0
63
+ want, tol = chk["value"], chk.get("abs_tol", 1e-9)
64
+ if t == "int": ok = eq_int(got, want)
65
+ elif t == "number": ok = eq_num(got, want, tol)
66
+ elif t == "str": ok = eq_str(got, want)
67
+ elif t == "bool": ok = isinstance(got, bool) and got is want
68
+ elif t == "list":
69
+ ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
70
+ elif t == "set":
71
+ kind = chk.get("item", "str")
72
+ if not isinstance(got, list): ok = False
73
+ else:
74
+ norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
75
+ g = [norm(x) for x in got]; w = [norm(x) for x in want]
76
+ ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
77
+ else: ok = False
78
+ return 1.0 if ok else 0.0
79
+
80
+ def grade(answer, checks, validators=None):
81
+ """Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
82
+ if not isinstance(answer, dict):
83
+ return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
84
+ total = sum(c.get("weight", 1.0) for c in checks)
85
+ got, details = 0.0, []
86
+ for c in checks:
87
+ s = run_check(answer, c, validators)
88
+ got += s * c.get("weight", 1.0)
89
+ details.append({"check": c.get("path", c.get("name")), "score": s})
90
+ return (round(got / total, 6) if total else 0.0), details
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("--answer", default="/app/answer.json")
95
+ ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
96
+ ap.add_argument("--out", default="/logs/verifier")
97
+ a = ap.parse_args()
98
+ checks = json.load(open(a.checks))
99
+ try:
100
+ with open(a.answer) as f: answer = json.load(f)
101
+ except Exception:
102
+ answer = None
103
+ validators = None
104
+ here = os.path.dirname(os.path.abspath(__file__))
105
+ if os.path.exists(os.path.join(here, "validators.py")):
106
+ sys.path.insert(0, here)
107
+ import validators # noqa
108
+ reward, details = grade(answer, checks, validators)
109
+ os.makedirs(a.out, exist_ok=True)
110
+ with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
111
+ with open(os.path.join(a.out, "reward.json"), "w") as f:
112
+ json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
113
+ print("reward", reward)
114
+
115
+ if __name__ == "__main__":
116
+ main()
tasks/argument-check/argument-check-consistency-d1-e0018/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/argument-check/argument-check-consistency-d1-e0018/environment/workdir/logic_reference.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Logic reference
2
+
3
+ ## Formulas
4
+
5
+ - An atom is a single capital letter, `A` to `Z`.
6
+ - `~X` means not X.
7
+ - `X & Y` means X and Y.
8
+ - `X | Y` means X or Y (inclusive: one or the other or both).
9
+ - `X -> Y` means if X then Y.
10
+ - `X <-> Y` means X if and only if Y.
11
+ - Parentheses `(` and `)` group. Spaces between symbols are optional and carry no meaning.
12
+
13
+ ## Reading a formula that is not fully parenthesised
14
+
15
+ The connectives bind in this order, from tightest to loosest: `~`, then `&`, then `|`, then `->`, then `<->`.
16
+
17
+ - `~` applies to the shortest formula that follows it: an atom, a parenthesised formula or another negation. So `~A & B` is `(~A) & B`.
18
+ - `A & B | C` is `(A & B) | C`, and `A | B & C` is `A | (B & C)`.
19
+ - `A | B -> C & D` is `(A | B) -> (C & D)`.
20
+ - `A -> B <-> C` is `(A -> B) <-> C`.
21
+ - `&` and `|` group to the left: `A & B & C` is `(A & B) & C`.
22
+ - `->` and `<->` group to the right: `A -> B -> C` is `A -> (B -> C)`, and `A <-> B <-> C` is `A <-> (B <-> C)`.
23
+
24
+ ## Truth conditions
25
+
26
+ | X | Y | ~X | X & Y | X \| Y | X -> Y | X <-> Y |
27
+ |---|---|---|---|---|---|---|
28
+ | true | true | false | true | true | true | true |
29
+ | true | false | false | false | true | false | false |
30
+ | false | true | true | false | true | true | false |
31
+ | false | false | true | false | false | true | true |
32
+
33
+ ## Valuations and rows
34
+
35
+ A valuation gives each atom the value true or false. For one problem (one argument, one set of sentences or one pair of formulas) the atoms that occur are the atoms that appear in at least one of its formulas. The truth table of the problem has one row for each valuation of the atoms that occur: 2 to the power n rows for n atoms. Every count of rows or valuations asked for is a count over this table.
36
+
37
+ In `answer.json` a valuation is a JSON object whose keys are exactly the atoms that occur in the problem and whose values are the JSON booleans `true` and `false`, for example `{"A": true, "B": false}`. Leave no atom out and add none.
38
+
39
+ ## Definitions
40
+
41
+ - An argument is **valid** if there is no row in which every premise is true and the conclusion is false. Otherwise it is invalid, and any such row is a **counterexample**. An argument whose premises are never all true together is therefore valid.
42
+ - A premise of a valid argument is **essential** if the argument becomes invalid when that one premise is deleted and the others are kept.
43
+ - A set of sentences is **satisfiable** (consistent) if at least one row makes every sentence in it true. Such a row is a **model** of the set.
44
+ - An atom is **forced true** by a satisfiable set if it is true in every model of the set, and **forced false** if it is false in every model.
45
+ - Two formulas are **equivalent** if they have the same truth value in every row. A row in which they differ is a **distinguishing valuation**.
46
+ - A **literal** is an atom or `~` followed by an atom (`~~A` is not a literal).
47
+ - A formula is in **conjunctive normal form (CNF)** if, once parsed by the rules above, it is a conjunction (`&`) of one or more clauses, where each clause is a disjunction (`|`) of one or more literals. `(A | ~B) & C` and `A | B` and `~A` are in CNF. `A | B & C` is not: it parses as `A | (B & C)`. `->` and `<->` do not occur in a CNF.
48
+ - A formula is in **disjunctive normal form (DNF)** if, once parsed, it is a disjunction (`|`) of one or more terms, where each term is a conjunction (`&`) of one or more literals. `A & ~B | C` and `A & B` are in DNF.
tasks/argument-check/argument-check-consistency-d1-e0018/environment/workdir/sentence_sets.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "id": "SET01",
4
+ "source": "Sheet 6, question 16",
5
+ "sentences": [
6
+ "L | E",
7
+ "E -> L",
8
+ "E <-> G",
9
+ "~L & ~G"
10
+ ]
11
+ },
12
+ {
13
+ "id": "SET02",
14
+ "source": "Sheet 3, question 4",
15
+ "sentences": [
16
+ "~L -> G",
17
+ "G & L",
18
+ "G <-> L"
19
+ ]
20
+ },
21
+ {
22
+ "id": "SET03",
23
+ "source": "Sheet 9, question 2",
24
+ "sentences": [
25
+ "~L & ~E",
26
+ "~G | ~E",
27
+ "~G & E"
28
+ ]
29
+ },
30
+ {
31
+ "id": "SET04",
32
+ "source": "Sheet 4, question 11",
33
+ "sentences": [
34
+ "G",
35
+ "E",
36
+ "G | ~L",
37
+ "G <-> E"
38
+ ]
39
+ }
40
+ ]
tasks/argument-check/argument-check-consistency-d1-e0018/instruction.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Argument check: consistency
2
+
3
+ `sentence_sets.json` holds 4 sets of sentences in propositional logic. `logic_reference.md` gives the formula syntax, including how to read formulas that are not fully parenthesised, and the definitions to apply.
4
+
5
+ Test every set with a full truth table over the atoms that occur in it.
6
+
7
+ Write `answer.json` in this folder, a JSON object with:
8
+
9
+ - `sets`: an object keyed by set id. For each set give
10
+ - `satisfiable`: `true` or `false`.
11
+ - `models`: the number of rows in which every sentence of the set is true, as an integer (0 if unsatisfiable).
12
+ - `most_true_together`: the largest number of sentences of the set that are true in one and the same row, as an integer (for a satisfiable set this is the number of sentences).
13
+ - `valuation`: for a satisfiable set, one model written as a valuation (an object giving `true` or `false` to exactly the atoms that occur in the set). Any model is accepted. For an unsatisfiable set give `null`.
14
+ - `unsatisfiable_ids`: list of the ids of the unsatisfiable sets (any order).
tasks/argument-check/argument-check-consistency-d1-e0018/solution/oracle.py ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Reference solution for Argument Check. Works only from the files in the current directory.
3
+
4
+ Formulas are read with a shunting-yard pass into reverse Polish notation and evaluated on a stack,
5
+ following the precedence and grouping rules of logic_reference.md.
6
+ """
7
+ import json, os
8
+
9
+ BINDING = {"~": 5, "&": 4, "|": 3, "->": 2, "<->": 1}
10
+ GROUPS_RIGHT = {"~", "->", "<->"}
11
+
12
+ def lex(text):
13
+ toks, i = [], 0
14
+ while i < len(text):
15
+ c = text[i]
16
+ if c.isspace(): i += 1; continue
17
+ if text[i:i + 3] == "<->": toks.append("<->"); i += 3; continue
18
+ if text[i:i + 2] == "->": toks.append("->"); i += 2; continue
19
+ if c in "~&|()" or (len(c) == 1 and "A" <= c <= "Z"): toks.append(c); i += 1; continue
20
+ raise ValueError("cannot read %r" % text)
21
+ return toks
22
+
23
+ def to_rpn(text):
24
+ out, ops = [], []
25
+ expect_operand = True
26
+ for t in lex(text):
27
+ if t not in BINDING and t not in "()": # an atom
28
+ if not expect_operand: raise ValueError(text)
29
+ out.append(t); expect_operand = False
30
+ elif t == "~":
31
+ if not expect_operand: raise ValueError(text)
32
+ ops.append(t)
33
+ elif t == "(":
34
+ if not expect_operand: raise ValueError(text)
35
+ ops.append(t)
36
+ elif t == ")":
37
+ if expect_operand: raise ValueError(text)
38
+ while ops and ops[-1] != "(": out.append(ops.pop())
39
+ if not ops: raise ValueError(text)
40
+ ops.pop()
41
+ else: # a two-place connective
42
+ if expect_operand: raise ValueError(text)
43
+ while ops and ops[-1] != "(" and (BINDING[ops[-1]] > BINDING[t] or (BINDING[ops[-1]] == BINDING[t] and t not in GROUPS_RIGHT)):
44
+ out.append(ops.pop())
45
+ ops.append(t); expect_operand = True
46
+ if expect_operand: raise ValueError(text)
47
+ while ops:
48
+ if ops[-1] == "(": raise ValueError(text)
49
+ out.append(ops.pop())
50
+ return out
51
+
52
+ def run(rpn, val):
53
+ st = []
54
+ for t in rpn:
55
+ if t == "~": st.append(not st.pop())
56
+ elif t in BINDING:
57
+ y = st.pop(); x = st.pop()
58
+ st.append((x and y) if t == "&" else (x or y) if t == "|" else ((not x) or y) if t == "->" else (x == y))
59
+ else: st.append(val[t])
60
+ assert len(st) == 1
61
+ return st[0]
62
+
63
+ def letters(rpns):
64
+ return sorted(set(t for rpn in rpns for t in rpn if t not in BINDING))
65
+
66
+ def all_rows(atoms):
67
+ rows = []
68
+ for k in range(2 ** len(atoms)):
69
+ rows.append(dict((a, bool((k >> i) & 1)) for i, a in enumerate(atoms)))
70
+ return rows
71
+
72
+ def load(name):
73
+ with open(name) as f: return json.load(f)
74
+
75
+ def validity():
76
+ ans = {"arguments": {}, "valid_ids": []}
77
+ for arg in load("arguments.json"):
78
+ prem = [to_rpn(p) for p in arg["premises"]]; concl = to_rpn(arg["conclusion"])
79
+ rows = all_rows(letters(prem + [concl]))
80
+ def bad_rows(ps):
81
+ return [v for v in rows if all(run(p, v) for p in ps) and not run(concl, v)]
82
+ p_true = sum(1 for v in rows if all(run(p, v) for p in prem))
83
+ cex = bad_rows(prem)
84
+ rec = {"valid": not cex, "premise_true_rows": p_true, "counterexample_rows": len(cex), "counterexample": cex[0] if cex else None}
85
+ if not cex:
86
+ rec["essential_premises"] = [i + 1 for i in range(len(prem)) if bad_rows(prem[:i] + prem[i + 1:])]
87
+ ans["valid_ids"].append(arg["id"])
88
+ ans["arguments"][arg["id"]] = rec
89
+ return ans
90
+
91
+ def consistency():
92
+ ans = {"sets": {}, "unsatisfiable_ids": []}
93
+ for s in load("sentence_sets.json"):
94
+ sents = [to_rpn(x) for x in s["sentences"]]
95
+ atoms = letters(sents); rows = all_rows(atoms)
96
+ truth = [[run(x, v) for x in sents] for v in rows]
97
+ models = [v for v, t in zip(rows, truth) if all(t)]
98
+ rec = {"satisfiable": bool(models), "models": len(models), "most_true_together": max(sum(t) for t in truth),
99
+ "valuation": models[0] if models else None}
100
+ if models:
101
+ rec["forced_true"] = [a for a in atoms if all(m[a] for m in models)]
102
+ rec["forced_false"] = [a for a in atoms if not any(m[a] for m in models)]
103
+ else:
104
+ rec["restoring"] = [i + 1 for i in range(len(sents)) if any(all(t[:i] + t[i + 1:]) for t in truth)]
105
+ ans["unsatisfiable_ids"].append(s["id"])
106
+ ans["sets"][s["id"]] = rec
107
+ return ans
108
+
109
+ def lit(atom, positive):
110
+ return atom if positive else "~" + atom
111
+
112
+ def equivalence():
113
+ ans = {"pairs": {}, "equivalent_ids": []}
114
+ for p in load("pairs.json"):
115
+ left, right = to_rpn(p["left"]), to_rpn(p["right"])
116
+ rows = all_rows(letters([left, right]))
117
+ l_only = [v for v in rows if run(left, v) and not run(right, v)]
118
+ r_only = [v for v in rows if run(right, v) and not run(left, v)]
119
+ same = not l_only and not r_only
120
+ ans["pairs"][p["id"]] = {
121
+ "equivalent": same, "left_models": sum(1 for v in rows if run(left, v)), "right_models": sum(1 for v in rows if run(right, v)),
122
+ "left_only_rows": len(l_only),
123
+ "relation": "equivalent" if same else "left-entails-right" if not l_only else "right-entails-left" if not r_only else "neither",
124
+ "distinguishing": None if same else (l_only + r_only)[0]}
125
+ if same: ans["equivalent_ids"].append(p["id"])
126
+ if os.path.exists("convert.json"):
127
+ ans["cnf"], ans["dnf"] = {}, {}
128
+ for c in load("convert.json"):
129
+ f = to_rpn(c["formula"]); atoms = letters([f]); rows = all_rows(atoms)
130
+ # one clause per false row (the clause is false in exactly that row); one term per true row
131
+ clauses = ["(" + " | ".join(lit(a, not v[a]) for a in atoms) + ")" for v in rows if not run(f, v)]
132
+ terms = ["(" + " & ".join(lit(a, v[a]) for a in atoms) + ")" for v in rows if run(f, v)]
133
+ ans["cnf"][c["id"]] = " & ".join(clauses)
134
+ ans["dnf"][c["id"]] = " | ".join(terms)
135
+ return ans
136
+
137
+ def main():
138
+ if os.path.exists("arguments.json"): answer = validity()
139
+ elif os.path.exists("sentence_sets.json"): answer = consistency()
140
+ else: answer = equivalence()
141
+ with open("answer.json", "w") as f: json.dump(answer, f, indent=1)
142
+
143
+ if __name__ == "__main__":
144
+ main()
tasks/argument-check/argument-check-consistency-d1-e0018/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py
tasks/argument-check/argument-check-consistency-d1-e0018/task.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version = "1.0"
2
+
3
+ [metadata]
4
+ author_name = "Renaissance Labs"
5
+ author_email = "unknown"
6
+ difficulty = "easy"
7
+ category = "argument-check"
8
+ tags = ["argument-check", "consistency", "isced-0223", "eval"]
9
+ isced_f = "0223"
10
+ family = "consistency"
11
+ split = "eval"
12
+ seed = 10018
13
+
14
+ [verifier]
15
+ timeout_sec = 120.0
16
+
17
+ [agent]
18
+ timeout_sec = 900.0
19
+
20
+ [environment]
21
+ build_timeout_sec = 600.0
22
+ cpus = 1
23
+ memory_mb = 1024
24
+ storage_mb = 2048
25
+ allow_internet = false
tasks/argument-check/argument-check-consistency-d1-e0018/tests/checks.json ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "path": "sets.SET01.satisfiable",
4
+ "type": "bool",
5
+ "value": false,
6
+ "weight": 1.0
7
+ },
8
+ {
9
+ "path": "sets.SET01.models",
10
+ "type": "int",
11
+ "value": 0,
12
+ "weight": 1.0
13
+ },
14
+ {
15
+ "path": "sets.SET01.most_true_together",
16
+ "type": "int",
17
+ "value": 3,
18
+ "weight": 1.0
19
+ },
20
+ {
21
+ "path": "sets.SET02.satisfiable",
22
+ "type": "bool",
23
+ "value": true,
24
+ "weight": 1.0
25
+ },
26
+ {
27
+ "path": "sets.SET02.models",
28
+ "type": "int",
29
+ "value": 1,
30
+ "weight": 1.0
31
+ },
32
+ {
33
+ "path": "sets.SET02.most_true_together",
34
+ "type": "int",
35
+ "value": 3,
36
+ "weight": 1.0
37
+ },
38
+ {
39
+ "type": "custom",
40
+ "name": "satisfying_valuation",
41
+ "args": {
42
+ "id": "SET02",
43
+ "sentences": [
44
+ "~L -> G",
45
+ "G & L",
46
+ "G <-> L"
47
+ ]
48
+ },
49
+ "weight": 1.0
50
+ },
51
+ {
52
+ "path": "sets.SET03.satisfiable",
53
+ "type": "bool",
54
+ "value": false,
55
+ "weight": 1.0
56
+ },
57
+ {
58
+ "path": "sets.SET03.models",
59
+ "type": "int",
60
+ "value": 0,
61
+ "weight": 1.0
62
+ },
63
+ {
64
+ "path": "sets.SET03.most_true_together",
65
+ "type": "int",
66
+ "value": 2,
67
+ "weight": 1.0
68
+ },
69
+ {
70
+ "path": "sets.SET04.satisfiable",
71
+ "type": "bool",
72
+ "value": true,
73
+ "weight": 1.0
74
+ },
75
+ {
76
+ "path": "sets.SET04.models",
77
+ "type": "int",
78
+ "value": 2,
79
+ "weight": 1.0
80
+ },
81
+ {
82
+ "path": "sets.SET04.most_true_together",
83
+ "type": "int",
84
+ "value": 4,
85
+ "weight": 1.0
86
+ },
87
+ {
88
+ "type": "custom",
89
+ "name": "satisfying_valuation",
90
+ "args": {
91
+ "id": "SET04",
92
+ "sentences": [
93
+ "G",
94
+ "E",
95
+ "G | ~L",
96
+ "G <-> E"
97
+ ]
98
+ },
99
+ "weight": 1.0
100
+ },
101
+ {
102
+ "path": "unsatisfiable_ids",
103
+ "type": "set",
104
+ "value": [
105
+ "SET01",
106
+ "SET03"
107
+ ],
108
+ "item": "str",
109
+ "weight": 2
110
+ }
111
+ ]
tasks/argument-check/argument-check-consistency-d1-e0018/tests/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
tasks/argument-check/argument-check-consistency-d1-e0018/tests/validators.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Custom checks for Argument Check. Standalone, standard library only.
2
+
3
+ Every function reads the candidate from the answer, evaluates the formulas of the problem itself
4
+ (the formulas arrive in `args` as text) and returns True only if the candidate really has the
5
+ property asked for. Nothing is compared with a stored solution. Malformed answers return False.
6
+ """
7
+
8
+ _LEVEL = {"<->": 1, "->": 2, "|": 3, "&": 4}
9
+ _MAX_LEN = 2000
10
+
11
+ class _Bad(Exception):
12
+ pass
13
+
14
+ def _scan(text):
15
+ if not isinstance(text, str): raise _Bad()
16
+ toks, i, n = [], 0, len(text)
17
+ while i < n:
18
+ c = text[i]
19
+ if c == " " or c == "\t": i += 1
20
+ elif c == "<" and text[i:i + 3] == "<->": toks.append("<->"); i += 3
21
+ elif c == "-" and text[i:i + 2] == "->": toks.append("->"); i += 2
22
+ elif c in ("~", "&", "|", "(", ")"): toks.append(c); i += 1
23
+ elif c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": toks.append(c); i += 1
24
+ else: raise _Bad()
25
+ return toks
26
+
27
+ def _read(text):
28
+ """Precedence climbing. Tree nodes: ("atom", A), ("not", x), ("bin", op, x, y)."""
29
+ toks = _scan(text)
30
+ state = {"i": 0}
31
+ def primary():
32
+ i = state["i"]
33
+ if i >= len(toks): raise _Bad()
34
+ t = toks[i]; state["i"] = i + 1
35
+ if t == "~": return ("not", primary())
36
+ if t == "(":
37
+ x = climb(1)
38
+ if state["i"] >= len(toks) or toks[state["i"]] != ")": raise _Bad()
39
+ state["i"] += 1
40
+ return x
41
+ if len(t) == 1 and t.isalpha(): return ("atom", t)
42
+ raise _Bad()
43
+ def climb(min_level):
44
+ left = primary()
45
+ while state["i"] < len(toks):
46
+ op = toks[state["i"]]
47
+ lv = _LEVEL.get(op)
48
+ if lv is None or lv < min_level: break
49
+ state["i"] += 1
50
+ # & and | group to the left, so the right operand must bind tighter; -> and <-> group to the right
51
+ right = climb(lv if op in ("->", "<->") else lv + 1)
52
+ left = ("bin", op, left, right)
53
+ return left
54
+ tree = climb(1)
55
+ if state["i"] != len(toks): raise _Bad()
56
+ return tree
57
+
58
+ def _value(t, v):
59
+ kind = t[0]
60
+ if kind == "atom": return v[t[1]]
61
+ if kind == "not": return not _value(t[1], v)
62
+ op, x, y = t[1], _value(t[2], v), _value(t[3], v)
63
+ if op == "&": return x and y
64
+ if op == "|": return x or y
65
+ if op == "->": return y or not x
66
+ return x is y
67
+
68
+ def _atoms(trees):
69
+ found, stack = set(), list(trees)
70
+ while stack:
71
+ t = stack.pop()
72
+ if t[0] == "atom": found.add(t[1])
73
+ elif t[0] == "not": stack.append(t[1])
74
+ else: stack.append(t[2]); stack.append(t[3])
75
+ return found
76
+
77
+ def _valuation(obj, atoms):
78
+ """The candidate must be an object with exactly the atoms that occur as keys and booleans as values."""
79
+ if not isinstance(obj, dict) or set(obj.keys()) != set(atoms): return None
80
+ for k in obj:
81
+ if obj[k] is not True and obj[k] is not False: return None
82
+ return obj
83
+
84
+ def _dig(answer, keys):
85
+ cur = answer
86
+ for k in keys:
87
+ if not isinstance(cur, dict) or k not in cur: return None
88
+ cur = cur[k]
89
+ return cur
90
+
91
+ def counterexample(answer, args):
92
+ """answer.arguments.<id>.counterexample makes every premise true and the conclusion false."""
93
+ try:
94
+ prem = [_read(p) for p in args["premises"]]; concl = _read(args["conclusion"])
95
+ v = _valuation(_dig(answer, ["arguments", args["id"], "counterexample"]), _atoms(prem + [concl]))
96
+ if v is None: return False
97
+ return all(_value(p, v) for p in prem) and not _value(concl, v)
98
+ except Exception:
99
+ return False
100
+
101
+ def satisfying_valuation(answer, args):
102
+ """answer.sets.<id>.valuation makes every sentence of the set true."""
103
+ try:
104
+ sents = [_read(s) for s in args["sentences"]]
105
+ v = _valuation(_dig(answer, ["sets", args["id"], "valuation"]), _atoms(sents))
106
+ if v is None: return False
107
+ return all(_value(s, v) for s in sents)
108
+ except Exception:
109
+ return False
110
+
111
+ def distinguishing_valuation(answer, args):
112
+ """answer.pairs.<id>.distinguishing gives the two formulas different truth values."""
113
+ try:
114
+ left, right = _read(args["left"]), _read(args["right"])
115
+ v = _valuation(_dig(answer, ["pairs", args["id"], "distinguishing"]), _atoms([left, right]))
116
+ if v is None: return False
117
+ return _value(left, v) is not _value(right, v)
118
+ except Exception:
119
+ return False
120
+
121
+ def _flatten(t, op):
122
+ parts, stack = [], [t]
123
+ while stack:
124
+ x = stack.pop()
125
+ if x[0] == "bin" and x[1] == op: stack.append(x[3]); stack.append(x[2])
126
+ else: parts.append(x)
127
+ return parts
128
+
129
+ def _is_literal(t):
130
+ return t[0] == "atom" or (t[0] == "not" and t[1][0] == "atom")
131
+
132
+ def normal_form(answer, args):
133
+ """answer.<form>.<id> is a formula in the normal form asked for (args.form is "cnf" or "dnf"), equivalent to
134
+ args.formula, built only from atoms of args.formula, and at most 2000 characters long."""
135
+ try:
136
+ form = args["form"]
137
+ if form not in ("cnf", "dnf"): return False
138
+ text = _dig(answer, [form, args["id"]])
139
+ if not isinstance(text, str) or len(text) > _MAX_LEN: return False
140
+ orig = _read(args["formula"]); cand = _read(text)
141
+ atoms = sorted(_atoms([orig]))
142
+ if not _atoms([cand]) <= set(atoms): return False
143
+ outer, inner = ("&", "|") if form == "cnf" else ("|", "&")
144
+ for part in _flatten(cand, outer):
145
+ for leaf in _flatten(part, inner):
146
+ if not _is_literal(leaf): return False
147
+ for k in range(2 ** len(atoms)):
148
+ v = dict((a, bool((k >> i) & 1)) for i, a in enumerate(atoms))
149
+ if _value(orig, v) is not _value(cand, v): return False
150
+ return True
151
+ except Exception:
152
+ return False
tasks/argument-check/argument-check-consistency-d1-e0018/tests/verify.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verifier for Renaissance Labs practice environments. Standard library only.
3
+
4
+ Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
5
+ The reward is the weighted share of checks that pass. A missing, unreadable or non-object
6
+ answer scores 0. Each check addresses one value in the answer by a dotted path.
7
+
8
+ Check types
9
+ int exact integer (a float with integral value is accepted; booleans are not)
10
+ number within abs_tol of value (default 1e-9); booleans and strings are rejected
11
+ str equal after trimming and case-folding
12
+ bool exact boolean
13
+ list ordered list; items compared as int/number/str according to "item" (default str)
14
+ set unordered collection of distinct strings (or ints)
15
+ custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
16
+ """
17
+ import argparse, json, math, os, sys
18
+
19
+ MISSING = object()
20
+
21
+ def lookup(obj, path):
22
+ cur = obj
23
+ for part in path.split("."):
24
+ if isinstance(cur, dict):
25
+ if part not in cur: return MISSING
26
+ cur = cur[part]
27
+ elif isinstance(cur, list):
28
+ try: cur = cur[int(part)]
29
+ except (ValueError, IndexError): return MISSING
30
+ else:
31
+ return MISSING
32
+ return cur
33
+
34
+ def is_num(x):
35
+ return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
36
+
37
+ def eq_int(got, want):
38
+ return is_num(got) and float(got) == float(int(got)) and int(got) == want
39
+
40
+ def eq_num(got, want, tol):
41
+ return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
42
+
43
+ def eq_str(got, want):
44
+ return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
45
+
46
+ def eq_item(got, want, kind, tol):
47
+ if kind == "int": return eq_int(got, want)
48
+ if kind == "number": return eq_num(got, want, tol)
49
+ return eq_str(got, want)
50
+
51
+ def run_check(answer, chk, validators):
52
+ t = chk["type"]
53
+ if t == "custom":
54
+ fn = getattr(validators, chk["name"], None) if validators else None
55
+ if fn is None: return 0.0
56
+ try: r = fn(answer, chk.get("args", {}))
57
+ except Exception: return 0.0
58
+ if r is True: return 1.0
59
+ if r is False or r is None: return 0.0
60
+ return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
61
+ got = lookup(answer, chk["path"])
62
+ if got is MISSING: return 0.0
63
+ want, tol = chk["value"], chk.get("abs_tol", 1e-9)
64
+ if t == "int": ok = eq_int(got, want)
65
+ elif t == "number": ok = eq_num(got, want, tol)
66
+ elif t == "str": ok = eq_str(got, want)
67
+ elif t == "bool": ok = isinstance(got, bool) and got is want
68
+ elif t == "list":
69
+ ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
70
+ elif t == "set":
71
+ kind = chk.get("item", "str")
72
+ if not isinstance(got, list): ok = False
73
+ else:
74
+ norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
75
+ g = [norm(x) for x in got]; w = [norm(x) for x in want]
76
+ ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
77
+ else: ok = False
78
+ return 1.0 if ok else 0.0
79
+
80
+ def grade(answer, checks, validators=None):
81
+ """Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
82
+ if not isinstance(answer, dict):
83
+ return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
84
+ total = sum(c.get("weight", 1.0) for c in checks)
85
+ got, details = 0.0, []
86
+ for c in checks:
87
+ s = run_check(answer, c, validators)
88
+ got += s * c.get("weight", 1.0)
89
+ details.append({"check": c.get("path", c.get("name")), "score": s})
90
+ return (round(got / total, 6) if total else 0.0), details
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("--answer", default="/app/answer.json")
95
+ ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
96
+ ap.add_argument("--out", default="/logs/verifier")
97
+ a = ap.parse_args()
98
+ checks = json.load(open(a.checks))
99
+ try:
100
+ with open(a.answer) as f: answer = json.load(f)
101
+ except Exception:
102
+ answer = None
103
+ validators = None
104
+ here = os.path.dirname(os.path.abspath(__file__))
105
+ if os.path.exists(os.path.join(here, "validators.py")):
106
+ sys.path.insert(0, here)
107
+ import validators # noqa
108
+ reward, details = grade(answer, checks, validators)
109
+ os.makedirs(a.out, exist_ok=True)
110
+ with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
111
+ with open(os.path.join(a.out, "reward.json"), "w") as f:
112
+ json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
113
+ print("reward", reward)
114
+
115
+ if __name__ == "__main__":
116
+ main()
tasks/argument-check/argument-check-consistency-d1-t0000/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/argument-check/argument-check-consistency-d1-t0000/environment/workdir/logic_reference.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Logic reference
2
+
3
+ ## Formulas
4
+
5
+ - An atom is a single capital letter, `A` to `Z`.
6
+ - `~X` means not X.
7
+ - `X & Y` means X and Y.
8
+ - `X | Y` means X or Y (inclusive: one or the other or both).
9
+ - `X -> Y` means if X then Y.
10
+ - `X <-> Y` means X if and only if Y.
11
+ - Parentheses `(` and `)` group. Spaces between symbols are optional and carry no meaning.
12
+
13
+ ## Reading a formula that is not fully parenthesised
14
+
15
+ The connectives bind in this order, from tightest to loosest: `~`, then `&`, then `|`, then `->`, then `<->`.
16
+
17
+ - `~` applies to the shortest formula that follows it: an atom, a parenthesised formula or another negation. So `~A & B` is `(~A) & B`.
18
+ - `A & B | C` is `(A & B) | C`, and `A | B & C` is `A | (B & C)`.
19
+ - `A | B -> C & D` is `(A | B) -> (C & D)`.
20
+ - `A -> B <-> C` is `(A -> B) <-> C`.
21
+ - `&` and `|` group to the left: `A & B & C` is `(A & B) & C`.
22
+ - `->` and `<->` group to the right: `A -> B -> C` is `A -> (B -> C)`, and `A <-> B <-> C` is `A <-> (B <-> C)`.
23
+
24
+ ## Truth conditions
25
+
26
+ | X | Y | ~X | X & Y | X \| Y | X -> Y | X <-> Y |
27
+ |---|---|---|---|---|---|---|
28
+ | true | true | false | true | true | true | true |
29
+ | true | false | false | false | true | false | false |
30
+ | false | true | true | false | true | true | false |
31
+ | false | false | true | false | false | true | true |
32
+
33
+ ## Valuations and rows
34
+
35
+ A valuation gives each atom the value true or false. For one problem (one argument, one set of sentences or one pair of formulas) the atoms that occur are the atoms that appear in at least one of its formulas. The truth table of the problem has one row for each valuation of the atoms that occur: 2 to the power n rows for n atoms. Every count of rows or valuations asked for is a count over this table.
36
+
37
+ In `answer.json` a valuation is a JSON object whose keys are exactly the atoms that occur in the problem and whose values are the JSON booleans `true` and `false`, for example `{"A": true, "B": false}`. Leave no atom out and add none.
38
+
39
+ ## Definitions
40
+
41
+ - An argument is **valid** if there is no row in which every premise is true and the conclusion is false. Otherwise it is invalid, and any such row is a **counterexample**. An argument whose premises are never all true together is therefore valid.
42
+ - A premise of a valid argument is **essential** if the argument becomes invalid when that one premise is deleted and the others are kept.
43
+ - A set of sentences is **satisfiable** (consistent) if at least one row makes every sentence in it true. Such a row is a **model** of the set.
44
+ - An atom is **forced true** by a satisfiable set if it is true in every model of the set, and **forced false** if it is false in every model.
45
+ - Two formulas are **equivalent** if they have the same truth value in every row. A row in which they differ is a **distinguishing valuation**.
46
+ - A **literal** is an atom or `~` followed by an atom (`~~A` is not a literal).
47
+ - A formula is in **conjunctive normal form (CNF)** if, once parsed by the rules above, it is a conjunction (`&`) of one or more clauses, where each clause is a disjunction (`|`) of one or more literals. `(A | ~B) & C` and `A | B` and `~A` are in CNF. `A | B & C` is not: it parses as `A | (B & C)`. `->` and `<->` do not occur in a CNF.
48
+ - A formula is in **disjunctive normal form (DNF)** if, once parsed, it is a disjunction (`|`) of one or more terms, where each term is a conjunction (`&`) of one or more literals. `A & ~B | C` and `A & B` are in DNF.
tasks/argument-check/argument-check-consistency-d1-t0000/environment/workdir/sentence_sets.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "id": "SET01",
4
+ "source": "Sheet 1, question 5",
5
+ "sentences": [
6
+ "G -> A",
7
+ "L",
8
+ "L & ~A",
9
+ "~A & L"
10
+ ]
11
+ },
12
+ {
13
+ "id": "SET02",
14
+ "source": "Sheet 4, question 9",
15
+ "sentences": [
16
+ "L | ~G",
17
+ "G & ~L"
18
+ ]
19
+ },
20
+ {
21
+ "id": "SET03",
22
+ "source": "Sheet 8, question 16",
23
+ "sentences": [
24
+ "L | A",
25
+ "~A & L",
26
+ "L <-> G"
27
+ ]
28
+ },
29
+ {
30
+ "id": "SET04",
31
+ "source": "Sheet 9, question 18",
32
+ "sentences": [
33
+ "G -> ~L",
34
+ "L & G"
35
+ ]
36
+ }
37
+ ]
tasks/argument-check/argument-check-consistency-d1-t0000/instruction.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Argument check: consistency
2
+
3
+ `sentence_sets.json` holds 4 sets of sentences in propositional logic. `logic_reference.md` gives the formula syntax, including how to read formulas that are not fully parenthesised, and the definitions to apply.
4
+
5
+ Test every set with a full truth table over the atoms that occur in it.
6
+
7
+ Write `answer.json` in this folder, a JSON object with:
8
+
9
+ - `sets`: an object keyed by set id. For each set give
10
+ - `satisfiable`: `true` or `false`.
11
+ - `models`: the number of rows in which every sentence of the set is true, as an integer (0 if unsatisfiable).
12
+ - `most_true_together`: the largest number of sentences of the set that are true in one and the same row, as an integer (for a satisfiable set this is the number of sentences).
13
+ - `valuation`: for a satisfiable set, one model written as a valuation (an object giving `true` or `false` to exactly the atoms that occur in the set). Any model is accepted. For an unsatisfiable set give `null`.
14
+ - `unsatisfiable_ids`: list of the ids of the unsatisfiable sets (any order).
tasks/argument-check/argument-check-consistency-d1-t0000/solution/oracle.py ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Reference solution for Argument Check. Works only from the files in the current directory.
3
+
4
+ Formulas are read with a shunting-yard pass into reverse Polish notation and evaluated on a stack,
5
+ following the precedence and grouping rules of logic_reference.md.
6
+ """
7
+ import json, os
8
+
9
+ BINDING = {"~": 5, "&": 4, "|": 3, "->": 2, "<->": 1}
10
+ GROUPS_RIGHT = {"~", "->", "<->"}
11
+
12
+ def lex(text):
13
+ toks, i = [], 0
14
+ while i < len(text):
15
+ c = text[i]
16
+ if c.isspace(): i += 1; continue
17
+ if text[i:i + 3] == "<->": toks.append("<->"); i += 3; continue
18
+ if text[i:i + 2] == "->": toks.append("->"); i += 2; continue
19
+ if c in "~&|()" or (len(c) == 1 and "A" <= c <= "Z"): toks.append(c); i += 1; continue
20
+ raise ValueError("cannot read %r" % text)
21
+ return toks
22
+
23
+ def to_rpn(text):
24
+ out, ops = [], []
25
+ expect_operand = True
26
+ for t in lex(text):
27
+ if t not in BINDING and t not in "()": # an atom
28
+ if not expect_operand: raise ValueError(text)
29
+ out.append(t); expect_operand = False
30
+ elif t == "~":
31
+ if not expect_operand: raise ValueError(text)
32
+ ops.append(t)
33
+ elif t == "(":
34
+ if not expect_operand: raise ValueError(text)
35
+ ops.append(t)
36
+ elif t == ")":
37
+ if expect_operand: raise ValueError(text)
38
+ while ops and ops[-1] != "(": out.append(ops.pop())
39
+ if not ops: raise ValueError(text)
40
+ ops.pop()
41
+ else: # a two-place connective
42
+ if expect_operand: raise ValueError(text)
43
+ while ops and ops[-1] != "(" and (BINDING[ops[-1]] > BINDING[t] or (BINDING[ops[-1]] == BINDING[t] and t not in GROUPS_RIGHT)):
44
+ out.append(ops.pop())
45
+ ops.append(t); expect_operand = True
46
+ if expect_operand: raise ValueError(text)
47
+ while ops:
48
+ if ops[-1] == "(": raise ValueError(text)
49
+ out.append(ops.pop())
50
+ return out
51
+
52
+ def run(rpn, val):
53
+ st = []
54
+ for t in rpn:
55
+ if t == "~": st.append(not st.pop())
56
+ elif t in BINDING:
57
+ y = st.pop(); x = st.pop()
58
+ st.append((x and y) if t == "&" else (x or y) if t == "|" else ((not x) or y) if t == "->" else (x == y))
59
+ else: st.append(val[t])
60
+ assert len(st) == 1
61
+ return st[0]
62
+
63
+ def letters(rpns):
64
+ return sorted(set(t for rpn in rpns for t in rpn if t not in BINDING))
65
+
66
+ def all_rows(atoms):
67
+ rows = []
68
+ for k in range(2 ** len(atoms)):
69
+ rows.append(dict((a, bool((k >> i) & 1)) for i, a in enumerate(atoms)))
70
+ return rows
71
+
72
+ def load(name):
73
+ with open(name) as f: return json.load(f)
74
+
75
+ def validity():
76
+ ans = {"arguments": {}, "valid_ids": []}
77
+ for arg in load("arguments.json"):
78
+ prem = [to_rpn(p) for p in arg["premises"]]; concl = to_rpn(arg["conclusion"])
79
+ rows = all_rows(letters(prem + [concl]))
80
+ def bad_rows(ps):
81
+ return [v for v in rows if all(run(p, v) for p in ps) and not run(concl, v)]
82
+ p_true = sum(1 for v in rows if all(run(p, v) for p in prem))
83
+ cex = bad_rows(prem)
84
+ rec = {"valid": not cex, "premise_true_rows": p_true, "counterexample_rows": len(cex), "counterexample": cex[0] if cex else None}
85
+ if not cex:
86
+ rec["essential_premises"] = [i + 1 for i in range(len(prem)) if bad_rows(prem[:i] + prem[i + 1:])]
87
+ ans["valid_ids"].append(arg["id"])
88
+ ans["arguments"][arg["id"]] = rec
89
+ return ans
90
+
91
+ def consistency():
92
+ ans = {"sets": {}, "unsatisfiable_ids": []}
93
+ for s in load("sentence_sets.json"):
94
+ sents = [to_rpn(x) for x in s["sentences"]]
95
+ atoms = letters(sents); rows = all_rows(atoms)
96
+ truth = [[run(x, v) for x in sents] for v in rows]
97
+ models = [v for v, t in zip(rows, truth) if all(t)]
98
+ rec = {"satisfiable": bool(models), "models": len(models), "most_true_together": max(sum(t) for t in truth),
99
+ "valuation": models[0] if models else None}
100
+ if models:
101
+ rec["forced_true"] = [a for a in atoms if all(m[a] for m in models)]
102
+ rec["forced_false"] = [a for a in atoms if not any(m[a] for m in models)]
103
+ else:
104
+ rec["restoring"] = [i + 1 for i in range(len(sents)) if any(all(t[:i] + t[i + 1:]) for t in truth)]
105
+ ans["unsatisfiable_ids"].append(s["id"])
106
+ ans["sets"][s["id"]] = rec
107
+ return ans
108
+
109
+ def lit(atom, positive):
110
+ return atom if positive else "~" + atom
111
+
112
+ def equivalence():
113
+ ans = {"pairs": {}, "equivalent_ids": []}
114
+ for p in load("pairs.json"):
115
+ left, right = to_rpn(p["left"]), to_rpn(p["right"])
116
+ rows = all_rows(letters([left, right]))
117
+ l_only = [v for v in rows if run(left, v) and not run(right, v)]
118
+ r_only = [v for v in rows if run(right, v) and not run(left, v)]
119
+ same = not l_only and not r_only
120
+ ans["pairs"][p["id"]] = {
121
+ "equivalent": same, "left_models": sum(1 for v in rows if run(left, v)), "right_models": sum(1 for v in rows if run(right, v)),
122
+ "left_only_rows": len(l_only),
123
+ "relation": "equivalent" if same else "left-entails-right" if not l_only else "right-entails-left" if not r_only else "neither",
124
+ "distinguishing": None if same else (l_only + r_only)[0]}
125
+ if same: ans["equivalent_ids"].append(p["id"])
126
+ if os.path.exists("convert.json"):
127
+ ans["cnf"], ans["dnf"] = {}, {}
128
+ for c in load("convert.json"):
129
+ f = to_rpn(c["formula"]); atoms = letters([f]); rows = all_rows(atoms)
130
+ # one clause per false row (the clause is false in exactly that row); one term per true row
131
+ clauses = ["(" + " | ".join(lit(a, not v[a]) for a in atoms) + ")" for v in rows if not run(f, v)]
132
+ terms = ["(" + " & ".join(lit(a, v[a]) for a in atoms) + ")" for v in rows if run(f, v)]
133
+ ans["cnf"][c["id"]] = " & ".join(clauses)
134
+ ans["dnf"][c["id"]] = " | ".join(terms)
135
+ return ans
136
+
137
+ def main():
138
+ if os.path.exists("arguments.json"): answer = validity()
139
+ elif os.path.exists("sentence_sets.json"): answer = consistency()
140
+ else: answer = equivalence()
141
+ with open("answer.json", "w") as f: json.dump(answer, f, indent=1)
142
+
143
+ if __name__ == "__main__":
144
+ main()
tasks/argument-check/argument-check-consistency-d1-t0000/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py
tasks/argument-check/argument-check-consistency-d1-t0000/task.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version = "1.0"
2
+
3
+ [metadata]
4
+ author_name = "Renaissance Labs"
5
+ author_email = "unknown"
6
+ difficulty = "easy"
7
+ category = "argument-check"
8
+ tags = ["argument-check", "consistency", "isced-0223", "train"]
9
+ isced_f = "0223"
10
+ family = "consistency"
11
+ split = "train"
12
+ seed = 0
13
+
14
+ [verifier]
15
+ timeout_sec = 120.0
16
+
17
+ [agent]
18
+ timeout_sec = 900.0
19
+
20
+ [environment]
21
+ build_timeout_sec = 600.0
22
+ cpus = 1
23
+ memory_mb = 1024
24
+ storage_mb = 2048
25
+ allow_internet = false
tasks/argument-check/argument-check-consistency-d1-t0000/tests/checks.json ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "path": "sets.SET01.satisfiable",
4
+ "type": "bool",
5
+ "value": true,
6
+ "weight": 1.0
7
+ },
8
+ {
9
+ "path": "sets.SET01.models",
10
+ "type": "int",
11
+ "value": 1,
12
+ "weight": 1.0
13
+ },
14
+ {
15
+ "path": "sets.SET01.most_true_together",
16
+ "type": "int",
17
+ "value": 4,
18
+ "weight": 1.0
19
+ },
20
+ {
21
+ "type": "custom",
22
+ "name": "satisfying_valuation",
23
+ "args": {
24
+ "id": "SET01",
25
+ "sentences": [
26
+ "G -> A",
27
+ "L",
28
+ "L & ~A",
29
+ "~A & L"
30
+ ]
31
+ },
32
+ "weight": 1.0
33
+ },
34
+ {
35
+ "path": "sets.SET02.satisfiable",
36
+ "type": "bool",
37
+ "value": false,
38
+ "weight": 1.0
39
+ },
40
+ {
41
+ "path": "sets.SET02.models",
42
+ "type": "int",
43
+ "value": 0,
44
+ "weight": 1.0
45
+ },
46
+ {
47
+ "path": "sets.SET02.most_true_together",
48
+ "type": "int",
49
+ "value": 1,
50
+ "weight": 1.0
51
+ },
52
+ {
53
+ "path": "sets.SET03.satisfiable",
54
+ "type": "bool",
55
+ "value": true,
56
+ "weight": 1.0
57
+ },
58
+ {
59
+ "path": "sets.SET03.models",
60
+ "type": "int",
61
+ "value": 1,
62
+ "weight": 1.0
63
+ },
64
+ {
65
+ "path": "sets.SET03.most_true_together",
66
+ "type": "int",
67
+ "value": 3,
68
+ "weight": 1.0
69
+ },
70
+ {
71
+ "type": "custom",
72
+ "name": "satisfying_valuation",
73
+ "args": {
74
+ "id": "SET03",
75
+ "sentences": [
76
+ "L | A",
77
+ "~A & L",
78
+ "L <-> G"
79
+ ]
80
+ },
81
+ "weight": 1.0
82
+ },
83
+ {
84
+ "path": "sets.SET04.satisfiable",
85
+ "type": "bool",
86
+ "value": false,
87
+ "weight": 1.0
88
+ },
89
+ {
90
+ "path": "sets.SET04.models",
91
+ "type": "int",
92
+ "value": 0,
93
+ "weight": 1.0
94
+ },
95
+ {
96
+ "path": "sets.SET04.most_true_together",
97
+ "type": "int",
98
+ "value": 1,
99
+ "weight": 1.0
100
+ },
101
+ {
102
+ "path": "unsatisfiable_ids",
103
+ "type": "set",
104
+ "value": [
105
+ "SET02",
106
+ "SET04"
107
+ ],
108
+ "item": "str",
109
+ "weight": 2
110
+ }
111
+ ]
tasks/argument-check/argument-check-consistency-d1-t0000/tests/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
tasks/argument-check/argument-check-consistency-d1-t0000/tests/validators.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Custom checks for Argument Check. Standalone, standard library only.
2
+
3
+ Every function reads the candidate from the answer, evaluates the formulas of the problem itself
4
+ (the formulas arrive in `args` as text) and returns True only if the candidate really has the
5
+ property asked for. Nothing is compared with a stored solution. Malformed answers return False.
6
+ """
7
+
8
+ _LEVEL = {"<->": 1, "->": 2, "|": 3, "&": 4}
9
+ _MAX_LEN = 2000
10
+
11
+ class _Bad(Exception):
12
+ pass
13
+
14
+ def _scan(text):
15
+ if not isinstance(text, str): raise _Bad()
16
+ toks, i, n = [], 0, len(text)
17
+ while i < n:
18
+ c = text[i]
19
+ if c == " " or c == "\t": i += 1
20
+ elif c == "<" and text[i:i + 3] == "<->": toks.append("<->"); i += 3
21
+ elif c == "-" and text[i:i + 2] == "->": toks.append("->"); i += 2
22
+ elif c in ("~", "&", "|", "(", ")"): toks.append(c); i += 1
23
+ elif c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": toks.append(c); i += 1
24
+ else: raise _Bad()
25
+ return toks
26
+
27
+ def _read(text):
28
+ """Precedence climbing. Tree nodes: ("atom", A), ("not", x), ("bin", op, x, y)."""
29
+ toks = _scan(text)
30
+ state = {"i": 0}
31
+ def primary():
32
+ i = state["i"]
33
+ if i >= len(toks): raise _Bad()
34
+ t = toks[i]; state["i"] = i + 1
35
+ if t == "~": return ("not", primary())
36
+ if t == "(":
37
+ x = climb(1)
38
+ if state["i"] >= len(toks) or toks[state["i"]] != ")": raise _Bad()
39
+ state["i"] += 1
40
+ return x
41
+ if len(t) == 1 and t.isalpha(): return ("atom", t)
42
+ raise _Bad()
43
+ def climb(min_level):
44
+ left = primary()
45
+ while state["i"] < len(toks):
46
+ op = toks[state["i"]]
47
+ lv = _LEVEL.get(op)
48
+ if lv is None or lv < min_level: break
49
+ state["i"] += 1
50
+ # & and | group to the left, so the right operand must bind tighter; -> and <-> group to the right
51
+ right = climb(lv if op in ("->", "<->") else lv + 1)
52
+ left = ("bin", op, left, right)
53
+ return left
54
+ tree = climb(1)
55
+ if state["i"] != len(toks): raise _Bad()
56
+ return tree
57
+
58
+ def _value(t, v):
59
+ kind = t[0]
60
+ if kind == "atom": return v[t[1]]
61
+ if kind == "not": return not _value(t[1], v)
62
+ op, x, y = t[1], _value(t[2], v), _value(t[3], v)
63
+ if op == "&": return x and y
64
+ if op == "|": return x or y
65
+ if op == "->": return y or not x
66
+ return x is y
67
+
68
+ def _atoms(trees):
69
+ found, stack = set(), list(trees)
70
+ while stack:
71
+ t = stack.pop()
72
+ if t[0] == "atom": found.add(t[1])
73
+ elif t[0] == "not": stack.append(t[1])
74
+ else: stack.append(t[2]); stack.append(t[3])
75
+ return found
76
+
77
+ def _valuation(obj, atoms):
78
+ """The candidate must be an object with exactly the atoms that occur as keys and booleans as values."""
79
+ if not isinstance(obj, dict) or set(obj.keys()) != set(atoms): return None
80
+ for k in obj:
81
+ if obj[k] is not True and obj[k] is not False: return None
82
+ return obj
83
+
84
+ def _dig(answer, keys):
85
+ cur = answer
86
+ for k in keys:
87
+ if not isinstance(cur, dict) or k not in cur: return None
88
+ cur = cur[k]
89
+ return cur
90
+
91
+ def counterexample(answer, args):
92
+ """answer.arguments.<id>.counterexample makes every premise true and the conclusion false."""
93
+ try:
94
+ prem = [_read(p) for p in args["premises"]]; concl = _read(args["conclusion"])
95
+ v = _valuation(_dig(answer, ["arguments", args["id"], "counterexample"]), _atoms(prem + [concl]))
96
+ if v is None: return False
97
+ return all(_value(p, v) for p in prem) and not _value(concl, v)
98
+ except Exception:
99
+ return False
100
+
101
+ def satisfying_valuation(answer, args):
102
+ """answer.sets.<id>.valuation makes every sentence of the set true."""
103
+ try:
104
+ sents = [_read(s) for s in args["sentences"]]
105
+ v = _valuation(_dig(answer, ["sets", args["id"], "valuation"]), _atoms(sents))
106
+ if v is None: return False
107
+ return all(_value(s, v) for s in sents)
108
+ except Exception:
109
+ return False
110
+
111
+ def distinguishing_valuation(answer, args):
112
+ """answer.pairs.<id>.distinguishing gives the two formulas different truth values."""
113
+ try:
114
+ left, right = _read(args["left"]), _read(args["right"])
115
+ v = _valuation(_dig(answer, ["pairs", args["id"], "distinguishing"]), _atoms([left, right]))
116
+ if v is None: return False
117
+ return _value(left, v) is not _value(right, v)
118
+ except Exception:
119
+ return False
120
+
121
+ def _flatten(t, op):
122
+ parts, stack = [], [t]
123
+ while stack:
124
+ x = stack.pop()
125
+ if x[0] == "bin" and x[1] == op: stack.append(x[3]); stack.append(x[2])
126
+ else: parts.append(x)
127
+ return parts
128
+
129
+ def _is_literal(t):
130
+ return t[0] == "atom" or (t[0] == "not" and t[1][0] == "atom")
131
+
132
+ def normal_form(answer, args):
133
+ """answer.<form>.<id> is a formula in the normal form asked for (args.form is "cnf" or "dnf"), equivalent to
134
+ args.formula, built only from atoms of args.formula, and at most 2000 characters long."""
135
+ try:
136
+ form = args["form"]
137
+ if form not in ("cnf", "dnf"): return False
138
+ text = _dig(answer, [form, args["id"]])
139
+ if not isinstance(text, str) or len(text) > _MAX_LEN: return False
140
+ orig = _read(args["formula"]); cand = _read(text)
141
+ atoms = sorted(_atoms([orig]))
142
+ if not _atoms([cand]) <= set(atoms): return False
143
+ outer, inner = ("&", "|") if form == "cnf" else ("|", "&")
144
+ for part in _flatten(cand, outer):
145
+ for leaf in _flatten(part, inner):
146
+ if not _is_literal(leaf): return False
147
+ for k in range(2 ** len(atoms)):
148
+ v = dict((a, bool((k >> i) & 1)) for i, a in enumerate(atoms))
149
+ if _value(orig, v) is not _value(cand, v): return False
150
+ return True
151
+ except Exception:
152
+ return False
tasks/argument-check/argument-check-consistency-d1-t0000/tests/verify.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verifier for Renaissance Labs practice environments. Standard library only.
3
+
4
+ Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
5
+ The reward is the weighted share of checks that pass. A missing, unreadable or non-object
6
+ answer scores 0. Each check addresses one value in the answer by a dotted path.
7
+
8
+ Check types
9
+ int exact integer (a float with integral value is accepted; booleans are not)
10
+ number within abs_tol of value (default 1e-9); booleans and strings are rejected
11
+ str equal after trimming and case-folding
12
+ bool exact boolean
13
+ list ordered list; items compared as int/number/str according to "item" (default str)
14
+ set unordered collection of distinct strings (or ints)
15
+ custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
16
+ """
17
+ import argparse, json, math, os, sys
18
+
19
+ MISSING = object()
20
+
21
+ def lookup(obj, path):
22
+ cur = obj
23
+ for part in path.split("."):
24
+ if isinstance(cur, dict):
25
+ if part not in cur: return MISSING
26
+ cur = cur[part]
27
+ elif isinstance(cur, list):
28
+ try: cur = cur[int(part)]
29
+ except (ValueError, IndexError): return MISSING
30
+ else:
31
+ return MISSING
32
+ return cur
33
+
34
+ def is_num(x):
35
+ return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
36
+
37
+ def eq_int(got, want):
38
+ return is_num(got) and float(got) == float(int(got)) and int(got) == want
39
+
40
+ def eq_num(got, want, tol):
41
+ return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
42
+
43
+ def eq_str(got, want):
44
+ return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
45
+
46
+ def eq_item(got, want, kind, tol):
47
+ if kind == "int": return eq_int(got, want)
48
+ if kind == "number": return eq_num(got, want, tol)
49
+ return eq_str(got, want)
50
+
51
+ def run_check(answer, chk, validators):
52
+ t = chk["type"]
53
+ if t == "custom":
54
+ fn = getattr(validators, chk["name"], None) if validators else None
55
+ if fn is None: return 0.0
56
+ try: r = fn(answer, chk.get("args", {}))
57
+ except Exception: return 0.0
58
+ if r is True: return 1.0
59
+ if r is False or r is None: return 0.0
60
+ return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
61
+ got = lookup(answer, chk["path"])
62
+ if got is MISSING: return 0.0
63
+ want, tol = chk["value"], chk.get("abs_tol", 1e-9)
64
+ if t == "int": ok = eq_int(got, want)
65
+ elif t == "number": ok = eq_num(got, want, tol)
66
+ elif t == "str": ok = eq_str(got, want)
67
+ elif t == "bool": ok = isinstance(got, bool) and got is want
68
+ elif t == "list":
69
+ ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
70
+ elif t == "set":
71
+ kind = chk.get("item", "str")
72
+ if not isinstance(got, list): ok = False
73
+ else:
74
+ norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
75
+ g = [norm(x) for x in got]; w = [norm(x) for x in want]
76
+ ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
77
+ else: ok = False
78
+ return 1.0 if ok else 0.0
79
+
80
+ def grade(answer, checks, validators=None):
81
+ """Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
82
+ if not isinstance(answer, dict):
83
+ return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
84
+ total = sum(c.get("weight", 1.0) for c in checks)
85
+ got, details = 0.0, []
86
+ for c in checks:
87
+ s = run_check(answer, c, validators)
88
+ got += s * c.get("weight", 1.0)
89
+ details.append({"check": c.get("path", c.get("name")), "score": s})
90
+ return (round(got / total, 6) if total else 0.0), details
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("--answer", default="/app/answer.json")
95
+ ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
96
+ ap.add_argument("--out", default="/logs/verifier")
97
+ a = ap.parse_args()
98
+ checks = json.load(open(a.checks))
99
+ try:
100
+ with open(a.answer) as f: answer = json.load(f)
101
+ except Exception:
102
+ answer = None
103
+ validators = None
104
+ here = os.path.dirname(os.path.abspath(__file__))
105
+ if os.path.exists(os.path.join(here, "validators.py")):
106
+ sys.path.insert(0, here)
107
+ import validators # noqa
108
+ reward, details = grade(answer, checks, validators)
109
+ os.makedirs(a.out, exist_ok=True)
110
+ with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
111
+ with open(os.path.join(a.out, "reward.json"), "w") as f:
112
+ json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
113
+ print("reward", reward)
114
+
115
+ if __name__ == "__main__":
116
+ main()
tasks/argument-check/argument-check-consistency-d1-t0009/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/argument-check/argument-check-consistency-d1-t0009/environment/workdir/logic_reference.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Logic reference
2
+
3
+ ## Formulas
4
+
5
+ - An atom is a single capital letter, `A` to `Z`.
6
+ - `~X` means not X.
7
+ - `X & Y` means X and Y.
8
+ - `X | Y` means X or Y (inclusive: one or the other or both).
9
+ - `X -> Y` means if X then Y.
10
+ - `X <-> Y` means X if and only if Y.
11
+ - Parentheses `(` and `)` group. Spaces between symbols are optional and carry no meaning.
12
+
13
+ ## Reading a formula that is not fully parenthesised
14
+
15
+ The connectives bind in this order, from tightest to loosest: `~`, then `&`, then `|`, then `->`, then `<->`.
16
+
17
+ - `~` applies to the shortest formula that follows it: an atom, a parenthesised formula or another negation. So `~A & B` is `(~A) & B`.
18
+ - `A & B | C` is `(A & B) | C`, and `A | B & C` is `A | (B & C)`.
19
+ - `A | B -> C & D` is `(A | B) -> (C & D)`.
20
+ - `A -> B <-> C` is `(A -> B) <-> C`.
21
+ - `&` and `|` group to the left: `A & B & C` is `(A & B) & C`.
22
+ - `->` and `<->` group to the right: `A -> B -> C` is `A -> (B -> C)`, and `A <-> B <-> C` is `A <-> (B <-> C)`.
23
+
24
+ ## Truth conditions
25
+
26
+ | X | Y | ~X | X & Y | X \| Y | X -> Y | X <-> Y |
27
+ |---|---|---|---|---|---|---|
28
+ | true | true | false | true | true | true | true |
29
+ | true | false | false | false | true | false | false |
30
+ | false | true | true | false | true | true | false |
31
+ | false | false | true | false | false | true | true |
32
+
33
+ ## Valuations and rows
34
+
35
+ A valuation gives each atom the value true or false. For one problem (one argument, one set of sentences or one pair of formulas) the atoms that occur are the atoms that appear in at least one of its formulas. The truth table of the problem has one row for each valuation of the atoms that occur: 2 to the power n rows for n atoms. Every count of rows or valuations asked for is a count over this table.
36
+
37
+ In `answer.json` a valuation is a JSON object whose keys are exactly the atoms that occur in the problem and whose values are the JSON booleans `true` and `false`, for example `{"A": true, "B": false}`. Leave no atom out and add none.
38
+
39
+ ## Definitions
40
+
41
+ - An argument is **valid** if there is no row in which every premise is true and the conclusion is false. Otherwise it is invalid, and any such row is a **counterexample**. An argument whose premises are never all true together is therefore valid.
42
+ - A premise of a valid argument is **essential** if the argument becomes invalid when that one premise is deleted and the others are kept.
43
+ - A set of sentences is **satisfiable** (consistent) if at least one row makes every sentence in it true. Such a row is a **model** of the set.
44
+ - An atom is **forced true** by a satisfiable set if it is true in every model of the set, and **forced false** if it is false in every model.
45
+ - Two formulas are **equivalent** if they have the same truth value in every row. A row in which they differ is a **distinguishing valuation**.
46
+ - A **literal** is an atom or `~` followed by an atom (`~~A` is not a literal).
47
+ - A formula is in **conjunctive normal form (CNF)** if, once parsed by the rules above, it is a conjunction (`&`) of one or more clauses, where each clause is a disjunction (`|`) of one or more literals. `(A | ~B) & C` and `A | B` and `~A` are in CNF. `A | B & C` is not: it parses as `A | (B & C)`. `->` and `<->` do not occur in a CNF.
48
+ - A formula is in **disjunctive normal form (DNF)** if, once parsed, it is a disjunction (`|`) of one or more terms, where each term is a conjunction (`&`) of one or more literals. `A & ~B | C` and `A & B` are in DNF.
tasks/argument-check/argument-check-consistency-d1-t0009/environment/workdir/sentence_sets.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "id": "SET01",
4
+ "source": "Sheet 4, question 11",
5
+ "sentences": [
6
+ "~E | B",
7
+ "B & E",
8
+ "~B | E"
9
+ ]
10
+ },
11
+ {
12
+ "id": "SET02",
13
+ "source": "Sheet 6, question 4",
14
+ "sentences": [
15
+ "E & ~G",
16
+ "~E | ~G",
17
+ "E | G"
18
+ ]
19
+ },
20
+ {
21
+ "id": "SET03",
22
+ "source": "Sheet 1, question 17",
23
+ "sentences": [
24
+ "B -> G",
25
+ "G <-> E",
26
+ "~E & G"
27
+ ]
28
+ },
29
+ {
30
+ "id": "SET04",
31
+ "source": "Sheet 6, question 18",
32
+ "sentences": [
33
+ "B & E",
34
+ "B -> ~E",
35
+ "E & B"
36
+ ]
37
+ }
38
+ ]
tasks/argument-check/argument-check-consistency-d1-t0009/instruction.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Argument check: consistency
2
+
3
+ `sentence_sets.json` holds 4 sets of sentences in propositional logic. `logic_reference.md` gives the formula syntax, including how to read formulas that are not fully parenthesised, and the definitions to apply.
4
+
5
+ Test every set with a full truth table over the atoms that occur in it.
6
+
7
+ Write `answer.json` in this folder, a JSON object with:
8
+
9
+ - `sets`: an object keyed by set id. For each set give
10
+ - `satisfiable`: `true` or `false`.
11
+ - `models`: the number of rows in which every sentence of the set is true, as an integer (0 if unsatisfiable).
12
+ - `most_true_together`: the largest number of sentences of the set that are true in one and the same row, as an integer (for a satisfiable set this is the number of sentences).
13
+ - `valuation`: for a satisfiable set, one model written as a valuation (an object giving `true` or `false` to exactly the atoms that occur in the set). Any model is accepted. For an unsatisfiable set give `null`.
14
+ - `unsatisfiable_ids`: list of the ids of the unsatisfiable sets (any order).
tasks/argument-check/argument-check-consistency-d1-t0009/solution/oracle.py ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Reference solution for Argument Check. Works only from the files in the current directory.
3
+
4
+ Formulas are read with a shunting-yard pass into reverse Polish notation and evaluated on a stack,
5
+ following the precedence and grouping rules of logic_reference.md.
6
+ """
7
+ import json, os
8
+
9
+ BINDING = {"~": 5, "&": 4, "|": 3, "->": 2, "<->": 1}
10
+ GROUPS_RIGHT = {"~", "->", "<->"}
11
+
12
+ def lex(text):
13
+ toks, i = [], 0
14
+ while i < len(text):
15
+ c = text[i]
16
+ if c.isspace(): i += 1; continue
17
+ if text[i:i + 3] == "<->": toks.append("<->"); i += 3; continue
18
+ if text[i:i + 2] == "->": toks.append("->"); i += 2; continue
19
+ if c in "~&|()" or (len(c) == 1 and "A" <= c <= "Z"): toks.append(c); i += 1; continue
20
+ raise ValueError("cannot read %r" % text)
21
+ return toks
22
+
23
+ def to_rpn(text):
24
+ out, ops = [], []
25
+ expect_operand = True
26
+ for t in lex(text):
27
+ if t not in BINDING and t not in "()": # an atom
28
+ if not expect_operand: raise ValueError(text)
29
+ out.append(t); expect_operand = False
30
+ elif t == "~":
31
+ if not expect_operand: raise ValueError(text)
32
+ ops.append(t)
33
+ elif t == "(":
34
+ if not expect_operand: raise ValueError(text)
35
+ ops.append(t)
36
+ elif t == ")":
37
+ if expect_operand: raise ValueError(text)
38
+ while ops and ops[-1] != "(": out.append(ops.pop())
39
+ if not ops: raise ValueError(text)
40
+ ops.pop()
41
+ else: # a two-place connective
42
+ if expect_operand: raise ValueError(text)
43
+ while ops and ops[-1] != "(" and (BINDING[ops[-1]] > BINDING[t] or (BINDING[ops[-1]] == BINDING[t] and t not in GROUPS_RIGHT)):
44
+ out.append(ops.pop())
45
+ ops.append(t); expect_operand = True
46
+ if expect_operand: raise ValueError(text)
47
+ while ops:
48
+ if ops[-1] == "(": raise ValueError(text)
49
+ out.append(ops.pop())
50
+ return out
51
+
52
+ def run(rpn, val):
53
+ st = []
54
+ for t in rpn:
55
+ if t == "~": st.append(not st.pop())
56
+ elif t in BINDING:
57
+ y = st.pop(); x = st.pop()
58
+ st.append((x and y) if t == "&" else (x or y) if t == "|" else ((not x) or y) if t == "->" else (x == y))
59
+ else: st.append(val[t])
60
+ assert len(st) == 1
61
+ return st[0]
62
+
63
+ def letters(rpns):
64
+ return sorted(set(t for rpn in rpns for t in rpn if t not in BINDING))
65
+
66
+ def all_rows(atoms):
67
+ rows = []
68
+ for k in range(2 ** len(atoms)):
69
+ rows.append(dict((a, bool((k >> i) & 1)) for i, a in enumerate(atoms)))
70
+ return rows
71
+
72
+ def load(name):
73
+ with open(name) as f: return json.load(f)
74
+
75
+ def validity():
76
+ ans = {"arguments": {}, "valid_ids": []}
77
+ for arg in load("arguments.json"):
78
+ prem = [to_rpn(p) for p in arg["premises"]]; concl = to_rpn(arg["conclusion"])
79
+ rows = all_rows(letters(prem + [concl]))
80
+ def bad_rows(ps):
81
+ return [v for v in rows if all(run(p, v) for p in ps) and not run(concl, v)]
82
+ p_true = sum(1 for v in rows if all(run(p, v) for p in prem))
83
+ cex = bad_rows(prem)
84
+ rec = {"valid": not cex, "premise_true_rows": p_true, "counterexample_rows": len(cex), "counterexample": cex[0] if cex else None}
85
+ if not cex:
86
+ rec["essential_premises"] = [i + 1 for i in range(len(prem)) if bad_rows(prem[:i] + prem[i + 1:])]
87
+ ans["valid_ids"].append(arg["id"])
88
+ ans["arguments"][arg["id"]] = rec
89
+ return ans
90
+
91
+ def consistency():
92
+ ans = {"sets": {}, "unsatisfiable_ids": []}
93
+ for s in load("sentence_sets.json"):
94
+ sents = [to_rpn(x) for x in s["sentences"]]
95
+ atoms = letters(sents); rows = all_rows(atoms)
96
+ truth = [[run(x, v) for x in sents] for v in rows]
97
+ models = [v for v, t in zip(rows, truth) if all(t)]
98
+ rec = {"satisfiable": bool(models), "models": len(models), "most_true_together": max(sum(t) for t in truth),
99
+ "valuation": models[0] if models else None}
100
+ if models:
101
+ rec["forced_true"] = [a for a in atoms if all(m[a] for m in models)]
102
+ rec["forced_false"] = [a for a in atoms if not any(m[a] for m in models)]
103
+ else:
104
+ rec["restoring"] = [i + 1 for i in range(len(sents)) if any(all(t[:i] + t[i + 1:]) for t in truth)]
105
+ ans["unsatisfiable_ids"].append(s["id"])
106
+ ans["sets"][s["id"]] = rec
107
+ return ans
108
+
109
+ def lit(atom, positive):
110
+ return atom if positive else "~" + atom
111
+
112
+ def equivalence():
113
+ ans = {"pairs": {}, "equivalent_ids": []}
114
+ for p in load("pairs.json"):
115
+ left, right = to_rpn(p["left"]), to_rpn(p["right"])
116
+ rows = all_rows(letters([left, right]))
117
+ l_only = [v for v in rows if run(left, v) and not run(right, v)]
118
+ r_only = [v for v in rows if run(right, v) and not run(left, v)]
119
+ same = not l_only and not r_only
120
+ ans["pairs"][p["id"]] = {
121
+ "equivalent": same, "left_models": sum(1 for v in rows if run(left, v)), "right_models": sum(1 for v in rows if run(right, v)),
122
+ "left_only_rows": len(l_only),
123
+ "relation": "equivalent" if same else "left-entails-right" if not l_only else "right-entails-left" if not r_only else "neither",
124
+ "distinguishing": None if same else (l_only + r_only)[0]}
125
+ if same: ans["equivalent_ids"].append(p["id"])
126
+ if os.path.exists("convert.json"):
127
+ ans["cnf"], ans["dnf"] = {}, {}
128
+ for c in load("convert.json"):
129
+ f = to_rpn(c["formula"]); atoms = letters([f]); rows = all_rows(atoms)
130
+ # one clause per false row (the clause is false in exactly that row); one term per true row
131
+ clauses = ["(" + " | ".join(lit(a, not v[a]) for a in atoms) + ")" for v in rows if not run(f, v)]
132
+ terms = ["(" + " & ".join(lit(a, v[a]) for a in atoms) + ")" for v in rows if run(f, v)]
133
+ ans["cnf"][c["id"]] = " & ".join(clauses)
134
+ ans["dnf"][c["id"]] = " | ".join(terms)
135
+ return ans
136
+
137
+ def main():
138
+ if os.path.exists("arguments.json"): answer = validity()
139
+ elif os.path.exists("sentence_sets.json"): answer = consistency()
140
+ else: answer = equivalence()
141
+ with open("answer.json", "w") as f: json.dump(answer, f, indent=1)
142
+
143
+ if __name__ == "__main__":
144
+ main()
tasks/argument-check/argument-check-consistency-d1-t0009/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py