cana.function_properties.redundancy module

Redundancy

Input and edge redundancy of a Boolean node from one-symbol prime implicants.

For k <= exact_k_max (default 14) values are exact averages over the full prime-implicant coverage. For larger k, minterms are sampled (default n_samples = 2**exact_k_max) and the same per-minterm contributions are averaged — a UserWarning is emitted on that automatic fallback (suppress by passing exact_k_max=-1, or force exact with exact_k_max >= k). Pass return_mode=True to get "exact" / "sampled" alongside the value. Bootstrap confidence intervals resample contributions from a preserved SampledPiCoverage without re-matching primes.

Shared sampling / bootstrap plumbing lives in sampling and is re-exported here for backwards compatibility.

class cana.function_properties.redundancy.BootstrapResult(estimate, ci_low, ci_high, boot_mean, boot_std, n_samples, n_boot, ci)[source]

Bases: object

Point estimate with a percentile bootstrap confidence interval.

Parameters:
  • estimate (float)

  • ci_low (float)

  • ci_high (float)

  • boot_mean (float)

  • boot_std (float)

  • n_samples (int)

  • n_boot (int)

  • ci (float)

estimate: float
ci_low: float
ci_high: float
boot_mean: float
boot_std: float
n_samples: int
n_boot: int
ci: float
class cana.function_properties.redundancy.SampledPiCoverage(coverage, k, n_samples, outputs)[source]

Bases: object

Partial pi_coverage from sampled minterms.

coverage maps each sampled binary state to the one-symbol primes that cover it (same shape as a full pi_coverage() dict, but only for the sample). outputs stores the polarity (0/1) of each sampled minterm so bias can be estimated without re-matching primes. Bootstrap helpers derive per-minterm contributions from this coverage without re-matching primes.

Parameters:
  • coverage (Dict[str, Tuple[str, ...]])

  • k (int)

  • n_samples (int)

  • outputs (Dict[str, int])

coverage: Dict[str, Tuple[str, ...]]
k: int
n_samples: int
outputs: Dict[str, int]
property minterms: List[str]
input_contributions(operator=<function mean>)[source]
Parameters:

operator (Callable[[Sequence[float]], float])

Return type:

ndarray

edge_contributions(bound='mean')[source]
Parameters:

bound (str)

Return type:

ndarray | Tuple[ndarray, ndarray]

bias_contributions()[source]

Per-minterm output bits as float64, shape (n_samples,).

Return type:

ndarray

cana.function_properties.redundancy.pi_covers(schema, binstate)[source]

Return True if one-symbol schema covers binary binstate.

Parameters:
  • schema (str)

  • binstate (str)

Return type:

bool

cana.function_properties.redundancy.covering_primes(binstate, schemata)[source]

Return one-symbol PIs covering binstate (ON and OFF scanned).

Raises:

ValueError – if no prime covers binstate (incomplete cover), or ON and OFF primes both cover it (polarity conflict).

Parameters:
  • binstate (str)

  • schemata (Mapping[int, Set[str]])

Return type:

List[str]

cana.function_properties.redundancy.covering_primes_with_polarity(binstate, schemata)[source]

Return covering one-symbol PIs and the output polarity of binstate.

Raises:

ValueError – if no prime covers binstate, or ON and OFF primes both cover it (polarity conflict).

Parameters:
  • binstate (str)

  • schemata (Mapping[int, Set[str]])

Return type:

Tuple[List[str], int]

cana.function_properties.redundancy.sample_binstates(k, n, *, rng=None, replace=False)[source]

Uniform sample of n binary strings of length k.

If not replace and n >= 2**k, returns the full space 0..2**k-1 (exact enumeration path).

For large k (where 2**k does not fit in int64), samples bitstrings directly instead of indexing into range(2**k).

Parameters:
  • k (int)

  • n (int)

  • rng (Generator | None)

  • replace (bool)

Return type:

List[str]

cana.function_properties.redundancy.sample_pi_coverage(schemata, n_samples, *, rng=None, minterms=None, k=None)[source]

Sample minterms and build a partial pi-coverage dict.

Parameters:
  • schemata (Mapping[int, Set[str]])

  • n_samples (int)

  • rng (Generator | None)

  • minterms (Sequence[str] | None)

  • k (int | None)

Return type:

SampledPiCoverage

cana.function_properties.redundancy.input_redundancy_from_coverage(pi_coverage, k=None, *, operator=<function mean>, norm=True)[source]

Average input redundancy over entries of a (full or sampled) coverage.

Parameters:
  • pi_coverage (Mapping[str, Sequence[str]])

  • k (int | None)

  • operator (Callable[[Sequence[float]], float])

  • norm (bool)

Return type:

float

cana.function_properties.redundancy.edge_redundancy_from_coverage(pi_coverage, k=None, *, bound='mean')[source]

Per-input edge redundancy over a (full or sampled) coverage.

Parameters:
  • pi_coverage (Mapping[str, Sequence[str]])

  • k (int | None)

  • bound (str)

Return type:

List[float] | List[Tuple[float, float]]

cana.function_properties.redundancy.input_redundancy_contributions(coverage_or_schemata, minterms, operator=<function mean>)[source]

Per-minterm Φ(#wildcards among covering PIs); shape (n,).

coverage_or_schemata may be a pi-coverage dict (binstate → PIs) or one-symbol ON/OFF schemata (polarity → PIs). Coverage is detected by whether keys look like binstates.

Parameters:
  • coverage_or_schemata (Mapping[str, Sequence[str]] | Mapping[int, Set[str]])

  • minterms (Sequence[str])

  • operator (Callable[[Sequence[float]], float])

Return type:

ndarray

cana.function_properties.redundancy.edge_redundancy_contributions(coverage_or_schemata, minterms, bound='mean')[source]

Per-minterm edge contributions.

For bound in lower / mean / upper: shape (n, k). For bound == "tuple": (lower, upper) each shape (n, k).

Parameters:
  • coverage_or_schemata (Mapping[str, Sequence[str]] | Mapping[int, Set[str]])

  • minterms (Sequence[str])

  • bound (str)

Return type:

ndarray | Tuple[ndarray, ndarray]

cana.function_properties.redundancy.input_redundancy(schemata, k=None, *, operator=<function mean>, norm=True, exact_k_max=14, n_samples=None, rng=None, minterms=None, return_coverage=False, return_mode=False)[source]

Input redundancy \(k_r\) with exact / sampled two-track.

If k <= exact_k_max and minterms is not provided, enumerates the full 2**k space. Otherwise samples n_samples (default 2**exact_k_max) minterms.

When sampling is used because k > exact_k_max (and exact_k_max >= 0), a UserWarning is emitted. Pass exact_k_max=-1 to force sampling without that warning, or exact_k_max >= k for the exact value. With return_mode=True, the second (or third) return value is "exact" or "sampled".

Parameters:
  • schemata (Mapping[int, Set[str]])

  • k (int | None)

  • operator (Callable[[Sequence[float]], float])

  • norm (bool)

  • exact_k_max (int)

  • n_samples (int | None)

  • rng (Generator | None)

  • minterms (Sequence[str] | None)

  • return_coverage (bool)

  • return_mode (bool)

Return type:

float | Tuple[float, SampledPiCoverage] | Tuple[float, str] | Tuple[float, SampledPiCoverage, str]

cana.function_properties.redundancy.edge_redundancy(schemata, k=None, *, bound='mean', exact_k_max=14, n_samples=None, rng=None, minterms=None, return_coverage=False, return_mode=False)[source]

Per-input edge redundancy \(r_i\) with exact / sampled two-track.

Same exact/sampled two-track and warning / return_mode behaviour as input_redundancy().

Parameters:
  • schemata (Mapping[int, Set[str]])

  • k (int | None)

  • bound (str)

  • exact_k_max (int)

  • n_samples (int | None)

  • rng (Generator | None)

  • minterms (Sequence[str] | None)

  • return_coverage (bool)

  • return_mode (bool)

Return type:

List[float] | List[Tuple[float, float]] | Tuple[List[float] | List[Tuple[float, float]], SampledPiCoverage] | Tuple[List[float] | List[Tuple[float, float]], str] | Tuple[List[float] | List[Tuple[float, float]], SampledPiCoverage, str]

cana.function_properties.redundancy.bootstrap_input_redundancy(sampled_or_schemata=None, *, schemata=None, n_samples=None, n_boot=1000, ci=0.95, operator=<function mean>, norm=True, rng=None, minterms=None)[source]

Estimate \(k_r\) with a percentile bootstrap CI on the sample mean.

Prefer passing a preserved SampledPiCoverage so primes are not re-matched. Schemata + n_samples / minterms still work (including the legacy positional schemata call).

Parameters:
  • sampled_or_schemata (SampledPiCoverage | Mapping[int, Set[str]] | None)

  • schemata (Mapping[int, Set[str]] | None)

  • n_samples (int | None)

  • n_boot (int)

  • ci (float)

  • operator (Callable[[Sequence[float]], float])

  • norm (bool)

  • rng (Generator | None)

  • minterms (Sequence[str] | None)

Return type:

BootstrapResult

cana.function_properties.redundancy.bootstrap_edge_redundancy(sampled_or_schemata=None, *, schemata=None, n_samples=None, n_boot=1000, ci=0.95, bound='mean', rng=None, minterms=None)[source]

Estimate per-input \(r_i\) with percentile bootstrap CIs.

For bound == "tuple", returns [(lower_result, upper_result), ...]. Prefer a preserved SampledPiCoverage; schemata + n_samples still work (legacy positional schemata included).

Parameters:
  • sampled_or_schemata (SampledPiCoverage | Mapping[int, Set[str]] | None)

  • schemata (Mapping[int, Set[str]] | None)

  • n_samples (int | None)

  • n_boot (int)

  • ci (float)

  • bound (str)

  • rng (Generator | None)

  • minterms (Sequence[str] | None)

Return type:

List[BootstrapResult] | List[Tuple[BootstrapResult, BootstrapResult]]