Skip to content

Fix #447: [Model] BoyceCoddNormalFormViolation#685

Merged
isPANN merged 7 commits intomainfrom
issue-447-boycecnoddnormalformviolation
Mar 19, 2026
Merged

Fix #447: [Model] BoyceCoddNormalFormViolation#685
isPANN merged 7 commits intomainfrom
issue-447-boycecnoddnormalformviolation

Conversation

@GiggleLiu
Copy link
Copy Markdown
Contributor

Summary

Add the BoyceCoddNormalFormViolation satisfaction problem model (Garey & Johnson A4 SR29). Given attributes, functional dependencies, and a target subset, determines whether the subset violates Boyce-Codd Normal Form.

Fixes #447

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.42%. Comparing base (482c75a) to head (dfa26f7).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main     #685    +/-   ##
========================================
  Coverage   97.42%   97.42%            
========================================
  Files         347      349     +2     
  Lines       44459    44686   +227     
========================================
+ Hits        43315    43537   +222     
- Misses       1144     1149     +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add the Boyce-Codd Normal Form Violation satisfaction problem model
(Garey & Johnson A4 SR29). Given attributes, functional dependencies,
and a target subset, determines whether a BCNF violation exists.

- Model: src/models/misc/boyce_codd_normal_form_violation.rs
- Tests: 20 unit tests covering evaluation, solver, serialization, edge cases
- CLI: create support with --n, --sets (lhs:rhs format), --target
- Paper: problem-def entry in docs/paper/reductions.typ
- Example-db: canonical example with violation witness X={2}
@GiggleLiu
Copy link
Copy Markdown
Contributor Author

Implementation Summary

Changes

  • src/models/misc/boyce_codd_normal_form_violation.rs — New satisfaction problem model with struct, constructor validation, closure computation, evaluate(), declare_variants!
  • src/unit_tests/models/misc/boyce_codd_normal_form_violation.rs — 20 unit tests: creation, evaluation (violation/non-violation/cyclic-keys/multi-step/out-of-target FDs), solver, serialization, constructor panics, normalization
  • src/models/misc/mod.rs — Module registration
  • problemreductions-cli/src/commands/create.rs — CLI create support with --n, --sets (FD format: lhs:rhs;...), --target
  • docs/paper/reductions.typ — Display name + problem-def entry
  • src/example_db/fixtures/examples.json — Regenerated with canonical BCNF example

Deviations from Plan

  • None

Open Questions

  • None

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new satisfaction problem model for Boyce–Codd Normal Form Violation (G&J A4 SR29) and wires it into the library, CLI instance creation, example database fixtures, and the reductions paper.

Changes:

  • Introduces BoyceCoddNormalFormViolation model with schema registration, variant declaration, and example-db spec.
  • Adds comprehensive unit tests covering evaluation behavior, validation, solver integration, and serialization.
  • Integrates the model into the CLI pred create flow and the curated example fixtures/docs.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/models/misc/boyce_codd_normal_form_violation.rs New model implementation + schema registration + variants + example-db spec + test module hook
src/models/misc/mod.rs Exposes the new model and includes its canonical example spec
problemreductions-cli/src/commands/create.rs Adds CLI construction/parsing for BoyceCoddNormalFormViolation
src/unit_tests/models/misc/boyce_codd_normal_form_violation.rs Unit tests for correctness, validation, solver behavior, and serde roundtrip
src/example_db/fixtures/examples.json Adds canonical model example fixture entry (samples + satisfying solutions)
docs/paper/reductions.typ Adds name mapping and formal problem definition to the paper

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

#problem-def("BoyceCoddNormalFormViolation")[
*Instance:* A set $A$ of attribute names, a collection $F$ of functional dependencies on $A$, and a subset $A' subset.eq A$.

*Question:* Is there a subset $X subset.eq A'$ and two attributes $y, z in A' without X$ such that $y in X^+$ but $z in.not X^+$, where $X^+$ is the closure of $X$ under $F$?
Comment on lines 26 to +29
mod subset_sum;

pub use bin_packing::BinPacking;
pub use boyce_codd_normal_form_violation::BoyceCoddNormalFormViolation;
Comment on lines +928 to +946
let fds: Vec<(Vec<usize>, Vec<usize>)> = sets_str
.split(';')
.map(|fd_str| {
let parts: Vec<&str> = fd_str.split(':').collect();
anyhow::ensure!(
parts.len() == 2,
"Each FD must be lhs:rhs, got '{}'",
fd_str
);
let lhs: Vec<usize> = util::parse_comma_list(parts[0])?;
let rhs: Vec<usize> = util::parse_comma_list(parts[1])?;
Ok((lhs, rhs))
})
.collect::<Result<_>>()?;
let target: Vec<usize> = util::parse_comma_list(target_str)?;
(
ser(BoyceCoddNormalFormViolation::new(n, fds, target))?,
resolved_variant.clone(),
)
Comment on lines +72 to +83
/// Create a new Boyce-Codd Normal Form Violation instance.
///
/// # Panics
///
/// Panics if any attribute index in `functional_deps` or `target_subset` is
/// out of range (≥ `num_attributes`), if `target_subset` is empty, or if any
/// functional dependency has an empty LHS.
pub fn new(
num_attributes: usize,
functional_deps: Vec<(Vec<usize>, Vec<usize>)>,
target_subset: Vec<usize>,
) -> Self {
@GiggleLiu
Copy link
Copy Markdown
Contributor Author

Agentic Review Report

Structural Check

# Check Status
1 Model file exists (src/models/misc/boyce_codd_normal_form_violation.rs) PASS
2 inventory::submit! present PASS
3 #[derive(...Serialize, Deserialize)] on struct PASS
4 Problem trait impl PASS
5 SatisfactionProblem impl PASS
6 #[cfg(test)] + #[path = "..."] test link PASS
7 Test file exists PASS
8 Test file has >= 3 test functions PASS — 20 test functions
9 Registered in misc/mod.rs PASS
10 Re-exported in models/mod.rs FAILBoyceCoddNormalFormViolation missing from pub use misc::{...} in src/models/mod.rs (line 23-27). All other misc models are listed there.
11 declare_variants! entry exists PASS
12 CLI alias resolution PASS — aliases BCNFViolation, BCNF
13 CLI create support PASS
14 Canonical model example registered PASS
15 Paper display-name entry PASS
16 Paper problem-def block PASS

Semantic Review:

  • evaluate() correctness: OK — correctly builds X from config, computes attribute closure via fixed-point, checks BCNF violation condition (∃ y∈X⁺∩(A'\X), ∃ z∉X⁺∩(A'\X))
  • dims() correctness: OK — vec![2; target_subset.len()]
  • Constructor validation: OK — rejects empty target_subset, empty FD LHS, out-of-range indices; normalizes by sorting/dedup
  • Paper entry: OK — matches G&J A4 SR29 definition, cites Beeri & Bernstein (1979)

Issue Compliance: 8/8 checks passed

Findings:

  • FAIL (structural Design Decision: Type-erased names in ReductionGraph topology #10): BoyceCoddNormalFormViolation not re-exported in src/models/mod.rs. The prelude in src/lib.rs works correctly, so this is a consistency gap rather than build-breaking.
  • Minor: Complexity string "2^num_target_attributes * num_target_attributes^2 * num_functional_deps" uses num_target_attributes^2 for closure cost, but the closure can visit num_attributes (which may exceed num_target_attributes). More precise: num_attributes^2. Equivalent when A'=A.

Quality Check

Design Principles:

  • DRY: OK — ensure_attribute_indices_in_range helper properly extracts repeated validation; no duplication
  • KISS: OK — straightforward struct + fixed-point closure + two-flag check; no over-engineering
  • HC/LC: OK — model file self-contained; CLI block follows existing patterns

HCI (CLI changed):

  • Error messages: OK — full usage lines with concrete examples in every error path
  • Discoverability: OK — example_for function provides canonical example
  • Consistency: OK — reuses --n, --sets, --target flags
  • Feedback: OK — validates all inputs before construction

Test Quality:

  • 20 unit tests covering: value verification, adversarial/boundary cases (empty X, full X, invalid configs), non-trivial instances (6 attrs, cyclic keys), constructor validation (4 #[should_panic] tests), normalization, multi-step transitive closure
  • 3 CLI tests for index bounds validation
  • 1 integration test for prelude accessibility
  • Assert density appropriate throughout

Findings:

  • Minor: Complexity string uses num_target_attributes^2 where num_attributes^2 would be more precise for closure computation (src/models/misc/boyce_codd_normal_form_violation.rs:219)
  • Minor: --sets flag semantically overloaded for functional dependencies vs set collections (problemreductions-cli/src/commands/create.rs:930). Follows existing codebase pattern; error messages document expected format.

Agentic Feature Tests

# Test Command Result
1 Model in catalog pred list PASS
2 Details display pred show BoyceCoddNormalFormViolation PASS
3 Alias (BCNF) pred show BCNF PASS
4 Alias (BCNFViolation) pred show BCNFViolation PASS
5 Example creation pred create --example BoyceCoddNormalFormViolation PASS
6 Solve (satisfiable) pred solve --solver brute-force PASS — returns valid BCNF violation witness
7 Solve (unsatisfiable) pred solve --solver brute-force on trivial instance PASS — "No solution found"
8 Schema-driven create pred create BoyceCoddNormalFormViolation --n 6 --sets "..." --target ... PASS
9 Unit tests cargo test -- boyce PASS — 20/20
10 Doc tests cargo test (doc-tests) PASS
11 Full test suite cargo test PASS — 2271 tests, 0 failures
12 Clippy cargo clippy --all-targets PASS
13 Formatting cargo fmt -- --check PASS

Findings:

  • Confirmed (low): Duplicate Vec<u64> match arm in problemreductions-cli/src/commands/create.rs (line 251 duplicates line 244) — produces unreachable_patterns compiler warning. Recommended fix: remove duplicate arm.
  • Confirmed (low): BoyceCoddNormalFormViolation not listed in pred create --help flags-by-problem table. Schema-driven fallback works correctly. Cosmetic omission.

Generated by review-pipeline

@isPANN isPANN self-assigned this Mar 19, 2026
isPANN and others added 2 commits March 20, 2026 00:58
@isPANN isPANN mentioned this pull request Mar 19, 2026
3 tasks
@isPANN isPANN merged commit 90f8733 into main Mar 19, 2026
3 checks passed
@GiggleLiu GiggleLiu deleted the issue-447-boycecnoddnormalformviolation branch April 12, 2026 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Model] BoyceCoddNormalFormViolation

3 participants