Background
qsym-rs is a deliberately small symbolic Pauli-algebra engine and qsym CLI (see docs/design/qsym-rs.md). A Pauli string has one operator per site, and the CLI already exposes that length inside qsym show XIZ, which prints a report containing len=3. The CLI also has a script-friendly weight subcommand that prints only the Pauli weight.
There is no script-friendly way to ask only for the length. Users who want just the site count must parse the human-readable show output.
Task
Add a new len subcommand: qsym len <A>.
It should parse one Pauli string the same way show and weight do. On success, print exactly the number of sites as a decimal integer followed by a newline. On parse failure, reuse the existing CLI error path: non-zero exit and error: ... on stderr.
This should be a CLI-only change in src/main.rs: add a Len { a: String } variant to Cmd and a match arm that calls PauliString::parse(&a)?, then prints p.ops.len(). Do not change src/lib.rs.
Verification
cargo run -q -- len XIZ → stdout is exactly 3, exit code 0.
- Distinguishing fixture:
cargo run -q -- len IIIIX → stdout is exactly 5. This catches implementations that hardcode the first example's length.
- Negative control:
cargo run -q -- len XQZ → exits non-zero and stderr contains error: not a Pauli letter. This proves the command reuses normal parsing instead of counting raw characters blindly.
- Regression check:
cargo run -q -- weight XIZ still prints exactly 2, and cargo run -q -- show XIZ still includes len=3 weight=2.
Background
qsym-rs is a deliberately small symbolic Pauli-algebra engine and
qsymCLI (seedocs/design/qsym-rs.md). A Pauli string has one operator per site, and the CLI already exposes that length insideqsym show XIZ, which prints a report containinglen=3. The CLI also has a script-friendlyweightsubcommand that prints only the Pauli weight.There is no script-friendly way to ask only for the length. Users who want just the site count must parse the human-readable
showoutput.Task
Add a new
lensubcommand:qsym len <A>.It should parse one Pauli string the same way
showandweightdo. On success, print exactly the number of sites as a decimal integer followed by a newline. On parse failure, reuse the existing CLI error path: non-zero exit anderror: ...on stderr.This should be a CLI-only change in
src/main.rs: add aLen { a: String }variant toCmdand a match arm that callsPauliString::parse(&a)?, then printsp.ops.len(). Do not changesrc/lib.rs.Verification
cargo run -q -- len XIZ→ stdout is exactly3, exit code0.cargo run -q -- len IIIIX→ stdout is exactly5. This catches implementations that hardcode the first example's length.cargo run -q -- len XQZ→ exits non-zero and stderr containserror: not a Pauli letter. This proves the command reuses normal parsing instead of counting raw characters blindly.cargo run -q -- weight XIZstill prints exactly2, andcargo run -q -- show XIZstill includeslen=3 weight=2.