Skip to main content

hyprstream_bench/gen/
syllogism.rs

1//! Set-logic syllogisms — **held-out gate family** (firewalled from training
2//! synthesis; measured by the P1.4 leg-(e) zero-shot transfer gate). Chains of
3//! All premises over synthetic category names; validity is decided by the
4//! chain structure, so truth is mechanical.
5//!
6//! The category bindings are threaded through [`Chain`] — never recovered
7//! from the rendered text by position (r1 review blocker: positional
8//! extraction returned the middle term for invalid chains and mislabeled
9//! ~7.4% of the frozen vob-1.0 items).
10
11use hyprstream_decision::Entry;
12
13use crate::family::{Family, Stratum};
14use crate::gen::stream;
15use crate::item::Item;
16
17const FAMILY: Family = Family::Syllogism;
18
19const NAMES: [&str; 12] = [
20    "glorps", "wibbles", "snarfs", "krendels", "plughs", "zorbs", "mippels", "tarns", "quells",
21    "droves", "fims", "jastrels",
22];
23
24struct Chain {
25    text: String,
26    /// First category (subject of premise 1).
27    a: &'static str,
28    /// Third category (predicate of the queried conclusion).
29    c: &'static str,
30    /// Does `All A are C` follow from the premises?
31    all_ac: bool,
32}
33
34fn chain(seed: u64, stratum: Stratum) -> Chain {
35    let mut rng = stream(seed);
36    let base = rng.below(NAMES.len() as u64) as usize;
37    let a = NAMES[base];
38    let b = NAMES[(base + 1) % NAMES.len()];
39    let c = NAMES[(base + 2) % NAMES.len()];
40    // Valid chain: All A are B. All B are C. ⇒ All A are C.
41    // Near-miss invalid chain: All A are B. All C are B. (⇏ All A are C) —
42    // the classic undistributed-middle fallacy, one word swapped away from
43    // the valid form. Strata differentiate difficulty: `clean` is mostly the
44    // valid transitive chain, `nearmiss` is mostly the fallacy.
45    let valid = match stratum {
46        Stratum::NearMiss => rng.below(4) == 0,
47        _ => rng.below(4) != 0,
48    };
49    let text = if valid {
50        format!("All {a} are {b}. All {b} are {c}.")
51    } else {
52        format!("All {a} are {b}. All {c} are {b}.")
53    };
54    Chain {
55        text,
56        a,
57        c,
58        all_ac: valid,
59    }
60}
61
62pub fn noul(seed: u64, stratum: Stratum) -> Item {
63    let chain = chain(seed, stratum);
64    Item::noul(
65        FAMILY,
66        stratum,
67        seed,
68        Entry::Str(chain.text),
69        format!("Does it follow that all {} are {}?", chain.a, chain.c),
70        chain.all_ac,
71    )
72}
73
74pub fn choice(seed: u64, stratum: Stratum) -> Item {
75    let mut rng = stream(seed ^ 0xC0);
76    let chain = chain(seed, stratum);
77    let options = [
78        format!("All {} are {}", chain.a, chain.c),
79        format!("No {} are {}", chain.a, chain.c),
80        format!("Some {} are not {}", chain.a, chain.c),
81        "None of these follow".to_owned(),
82    ];
83    let correct = if chain.all_ac { 0 } else { 3 };
84    let order = rng.permutation(options.len());
85    let shuffled: Vec<String> = order.iter().map(|&i| options[i].clone()).collect();
86    let new_correct = order
87        .iter()
88        .position(|&i| i == correct)
89        .unwrap_or_else(|| unreachable!("permutation contains every index"));
90    Item::choice(
91        FAMILY,
92        stratum,
93        seed,
94        Entry::Str(chain.text),
95        "Which conclusion follows from the premises?",
96        shuffled,
97        new_correct,
98    )
99}
100
101pub fn score(seed: u64, stratum: Stratum) -> Item {
102    let chain = chain(seed, stratum);
103    Item::score(
104        FAMILY,
105        stratum,
106        seed,
107        Entry::Str(chain.text),
108        "How strong is the inference from the premises to \"all of the first category are the third category\"? Levels: 0 = does not follow, 1 = follows necessarily.",
109        2,
110        usize::from(chain.all_ac),
111    )
112}