Skip to main content

Sieve Scope v1.3

English | 日本語

"See through the formatting, and look into the pure logic of the algorithm." A fully local, zero-dependency, deterministic (100% reproducible) code plagiarism and structural similarity detection engine. Extends Sieve-Core's deterministic similarity engine and Sieve-Referee's multi-hypothesis LUT judgment philosophy to the source code domain.

CI License: MIT Python Version


💡 Concept & Philosophy

The starting point of this project is Sieve-Core, a core engine that applies the "sieve of set theory" design philosophy of Sieve-AI—inspired by the Sieve of Eratosthenes—to the more general domain of text and data processing.

Next, Sieve Referee, which adds a "sieve of combinatorics" to Sieve-Core, is a zero-dependency Python library that extracts reliable information from noise based on corroboration from multiple independent sources.

Then, Sieve Scope further adds a two-axis evaluation and redesigns the approach, making it an explainable code plagiarism detection engine that observes the surface format (variable names, comments, whitespace) and the essential logic (algorithm structure) separately.

Traditional string comparison and simple similarity measures struggle to distinguish between:

  • Plagiarism by merely renaming variables (variable laundering)
  • Coincidental matches due to shared templates (boilerplate)

Sieve Scope observes two axes independently:

  • AST (Abstract Syntax Tree) — extracting the "logic skeleton" with identifiers removed
  • tokenize — extracting "identifier vocabulary and order"

By inheriting the hypothesis mask (H1–H7) and LUT from Sieve-Referee, it fully explains why a judgment was made.

The name "Sieve Scope" comes from the design philosophy of seeing through the surface of code (format) and comparing only the pure logic, like a microscope.


🔥 Key Features

  • 7-bit Observation Space (H1–H7)
    Independently evaluates AST skeleton, identifier vocabulary, positional/order (g_POS), constants (g_CONST), and vocabulary context (g_FREQ).
  • v0_mask compatibility
    The legacy 4-bit v0_mask is preserved and regression-tested.
  • Strict Cluster Safety Invariant
    H4 is promoted to 1 only when the cluster size is at least 3 and there is direct similarity evidence (H2∨H3). Indirect "telephone game" chains are never mixed into direct judgments.
  • Short-Circuit Optimization
    Pairs with no structural or vocabulary similarity (H2=0 ∧ H3=0) are immediately returned as 1000-000, skipping expensive hash computations.
  • Zero Dependencies & Deterministic
    Implemented using only the Python standard library. No external packages, no API costs, no probabilistic elements.

📐 7-bit Observation Space

The evaluation function f_v1.3(C1, C2) projects a code pair into seven boolean hypotheses (H1, H2, H3, H4, H5, H6, H7).

Hypothesis Name What it measures Criterion / Threshold
H1 Parseability Can both be parsed as Python syntax? Success/failure of AST construction
H2 AST Skeleton Do the AST node type sequences match exactly? Exact match of skeleton strings
H3 Identifier Similarity Jaccard + sequence similarity of identifiers Score > 0.50
H4 Cluster Safety Direct similarity + membership in a valid cluster (size ≥3) Invariant condition satisfied
H5 g_POS SHA-256 hash of recursive AST field representation Exact hash match
H6 g_CONST Constants / literals set match Sorted constant list exact match
H7 g_FREQ Weighted identifier bi-gram Dice coefficient Score >= 0.60

Mask notation is v0_mask (4-bit) - extension (3-bit). Example: 1100-011 → H1=1, H2=1, H3=0, H4=0 / H5=0, H6=1, H7=1


📊 Representative LUT Patterns

v0_mask Extended Example Judgment Label Description
1110 1110-111 EXACT_CLONE Observation-space exact match
1100 1100-110 VARIABLE_LAUNDERING Logic matches but surface differs
1010 1010-011 COINCIDENTAL_FRAMEWORK_MATCH Logic differs but surface matches
1000 1000-000 INDEPENDENT_LOGIC No direct similarity (short-circuit)
1110 1110-101 CONSTANT_MODIFIED_CLONE Only constants differ
1110 1110-011 PERMUTATED_CLONE Non-commutative order reversed

💻 Quick Start

from sieve_scope import SieveScopeEngineV1_3, SieveClusterAnalyzerV1_3

engine = SieveScopeEngineV1_3(jaccard_threshold=0.50, freq_dice_threshold=0.60)

code_a = "def calc_sum(a, b):\n    return a + b"
code_b = "def calc_sum(x, y):\n    return x + y"

result = engine.evaluate_pair(code_a, code_b)

print(result["v0_mask"])   # e.g., 1100
print(result["mask"])      # e.g., 1100-110

---

### Configuration / Thresholds

- `jaccard_threshold` (default: `0.50`): Threshold for H3 Multiset Jaccard + sequence similarity.
- `freq_dice_threshold` (default: `0.60`): Threshold for H7 Weighted identifier bi-gram Dice coefficient.

> **Note on Calibration & Defaults (v1.3)**:
> Exhaustive grid search experiments on synthetic benchmark datasets demonstrate optimal class separation ($F1 = 1.0000$) across a wide threshold range of `0.35` to `0.75`. However, the default threshold parameters are strictly maintained at **`0.50` / `0.60`** in order to preserve backwards compatibility with v0, maintain regression test stability, and prevent potential false positives caused by shared domain vocabulary in production codebases.

---

## 🔬 Testing & Verification
Cross-Python Validation Summary
24 regression cases (test_v1_3_full_suite.py): PASSED

5 compatibility tests (test_v1_3_regression.py): PASSED

6 edge-case & parallel determinism tests (test_v1_3_edge_cases.py): PASSED

81 synthetic threshold configurations (threshold_tuning.py): PASSED

All test suites and synthetic experiments passed completely without errors across Python 3.9, 3.10, 3.11, and 3.12.

Threshold Calibration & Synthetic Validation
The threshold parameters (H3 Multiset Jaccard: 0.50, H7 Weighted Bi-gram Dice: 0.60) were designed and calibrated using a synthetic validation pair set (Positive 6 pairs / Negative 3 pairs).
The engine's 1110-111 indicates an exact match in the current 7-dimensional observation space (Observation Clones), and does not guarantee complete semantic equivalence (Semantic Clones).

---

## 📚 Documentation

- 🏛️ Architecture Specification

- 🔌 API & Integration Guide

- 🚀 Deployment Guide

- 🔐 CI/CD & Security Guide

## 📄 License
MIT License. See LICENSE for details.

## 👤 Author
Kai IWASAKI

Metadata

Release files for sieve-scope 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sieve-scope 1.3.0
File Size Uploaded Provenance
sieve_scope-1.3.0.tar.gz 14.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sieve-scope 1.3.0
File Interpreter ABI Platform
sieve_scope-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.0 kB

Release files / sieve_scope-1.3.0.tar.gz

Download URL sieve_scope-1.3.0.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
bb30d8d7024e3e75cb9535db83aa1817dc27258cc6ef005dc94f89f532d8b527
BLAKE2b-256 checksum
How to use checksums
e6917f72f913956cb8b1458658dee05a8a72ad4b5a37b831441c1d0e0a46f799
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / sieve_scope-1.3.0-py3-none-any.whl

Download URL sieve_scope-1.3.0-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9500320c4c12f1af6196c48ad47123cf534f5a9e8e35acf9de7c7a09cd77ed0f
BLAKE2b-256 checksum
How to use checksums
511f99adf1e3bbc1cb8e7db3b5041d4014ea0d7c1bf5cd288acd8775d5e67dce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for sieve-scope 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page