Simplifies Mixed Boolean-Arithmetic (MBA) expressions used in code obfuscation. Combines BFS lookup over a pre-computed expression table, symbolic rewriting (40+ rules), and a neural-guided search driven by a small Transformer classifier. Every output is oracle-verified correct.
This repo is the Ascend NPU-adapted version of qox/mba-simplifier:
torch.device('npu:0') (Ascend910 ×2).model_weights/qox/mba-simplifier/
first, falling back to the repo root — no re-download.HF_ENDPOINT=https://hf-mirror.com if weights must be pulled from the mirror.pip install -r requirements.txt
# CLI mode: --img accepts a text file OR the expression directly
python inference.py --img "(x & y) + (x | y)"
# → {"model": "mba-simplifier", "result": {"simplified": "x + y", ...}}
echo "(x & y) + (x | y)" > expr.txt
python inference.py --img expr.txt
# FastAPI mode
uvicorn inference:app --host 0.0.0.0 --port 8000
curl -s -F "file=@expr.txt" http://127.0.0.1:8000/predict
# → {"model":"mba-simplifier","result":{...}}{
"model": "mba-simplifier",
"result": {
"simplified": "x + y",
"original": "(x & y) + (x | y)",
"reduction": 0.571,
"score": 0.571,
"strategy": "bfs",
"latency_ms": 393.5
}
}from inference import simplify
result = simplify("(x & y) + (x | y)")
print(result["simplified"]) # "x + y"
print(result["score"]) # 0.571
print(result["strategy"]) # "bfs"| Field | Type | Description |
|---|---|---|
simplified | str | Simplified infix expression |
original | str | Input expression |
reduction | float | Tree-size reduction (0.0–1.0) |
score | float | Alias of reduction |
strategy | str | bfs / symbolic / neural / none |
latency_ms | float | Wall-clock time in milliseconds |
| Input | Output | Strategy |
|---|---|---|
(x & y) + (x | y) | x + y | bfs |
(x | y) - (x & y) | x ^ y | bfs |
(x + y) - 2 * (x & y) | x ^ y | bfs |
(x & ~y) | (x & y) | x | bfs |
~(~x & ~y) | x | y | symbolic |
x & (x | y) | x | symbolic |
(x + y) ^ (x + z) | no simplification | neural (classifier on npu:0) |
The neural Transformer classifier (vocab 41, d_model 256, 4 layers, 8 heads)
runs on npu:0 and guides the beam search when BFS/symbolic do not fully reduce.
| File | Description |
|---|---|
inference.py | NPU-adapted standalone inference (CLI + FastAPI) |
bfs_table_6.json | Pre-computed BFS table, 18K entries (1.7MB) |
mba_classifier.safetensors | Transformer classifier, 2.2M params (8.9MB) |
config.json / char_vocab.json / rule_vocab.json | Model sidecars |
model_weights/qox/mba-simplifier/ | Local weight cache (source of truth) |
assets/ | Deployment / CLI / API screenshots |
x and y only; other cases fall through.