bsolver
bsolver est une bibliothèque Python pour la résolution de problèmes logiques et de contraintes, avec un accent particulier sur la recherche de solutions minimales.
Installation
Installez bsolver et ses dépendances avec pip :
pip install .
Utilisation
Exemple d'importation et d'utilisation :
from bsolver import Var
A, B, C, D = Var("A"), Var("B"), Var("C"), Var("D")
expr = ((A & B)|(~A & C)) & D
# Affichage de la formule (forme FND réduite)
print(expr) # (!A & C & D)|(B & C & D)|(A & B & D)
# Affiche l'arbre ROBDD
expr.print()
# A
# ├── T: B
# │ ├── T: D
# │ └── F: FALSE
# └── F: C
# ├── T: D
# └── F: FALSE
# Affiche la table de verité de l'expression
expr.print_table()
# A | B | C | D | Résultat
# --------------------------
# 0 | 0 | 0 | 0 | 0
# 0 | 0 | 0 | 1 | 0
# 0 | 0 | 1 | 0 | 0
# 0 | 0 | 1 | 1 | 1
# 0 | 1 | 0 | 0 | 0
# 0 | 1 | 0 | 1 | 0
# 0 | 1 | 1 | 0 | 0
# 0 | 1 | 1 | 1 | 1
# 1 | 0 | 0 | 0 | 0
# 1 | 0 | 0 | 1 | 0
# 1 | 0 | 1 | 0 | 0
# 1 | 0 | 1 | 1 | 0
# 1 | 1 | 0 | 0 | 0
# 1 | 1 | 0 | 1 | 1
# 1 | 1 | 1 | 0 | 0
# 1 | 1 | 1 | 1 | 1
# Affiche les solutions de l'expression
expr.print_table(solutions_only=True)
# A | B | C | D | Résultat
# --------------------------
# 0 | * | 1 | 1 | 1
# * | 1 | 1 | 1 | 1
# 1 | 1 | * | 1 | 1
# les solutions peuvent être obtenues et parcourues via la propriété "solutions"
for s in expr.solutions:
env = {var: val for var, val in s}
# Il est possible d'évaluer une expression pour des valeurs de variable données
assert expr.eval(env), f"{env} n'est pas une solution de {expr} ??"
print(f"{env} est bien une solution de {expr}")
# {'D': True, 'B': True, 'A': True} est bien une solution de (A & B & D)|(B & C & D)|(!A & C & D)
# {'D': True, 'C': True, 'B': True} est bien une solution de (A & B & D)|(B & C & D)|(!A & C & D)
# {'D': True, 'C': True, 'A': False} est bien une solution de (A & B & D)|(B & C & D)|(!A & C & D)
# Fixer des variables à des valeurs données
print(expr.fix({'A': True})) # (B & D)
print(expr.fix({'A': True, 'B': True})) # (D)
print(expr.fix({'D': False})) # FALSE
# Verifier l'implication de deux expressions
print(expr.implies(D)) # True
print(expr.implies(A & B)) # False
print(expr.implies(~A | B)) # True
Tests
Lancez les tests avec :
pytest
Licence
Ce projet est sous licence MIT.
Metadata
Release files for bsolver 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bsolver-0.1.1.tar.gz | 15.0 kB | Without provenance | Details for bsolver-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bsolver-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for bsolver-0.1.1-py3-none-any.whl |
Total release size: 25.4 kB
Release files / bsolver-0.1.1.tar.gz
| Download URL | bsolver-0.1.1.tar.gz |
|---|---|
| Size | 15.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f162412d6d9b26ed83097b006d48bc266bc61fd78373e12f3b3783ca00ff1f73
|
|
BLAKE2b-256 checksum How to use checksums |
b49d42852d88a49cef36a9ce792686b24c1c778bcc1c4949234d122adb72c847
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / bsolver-0.1.1-py3-none-any.whl
| Download URL | bsolver-0.1.1-py3-none-any.whl |
|---|---|
| Size | 10.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9eac88bfbcc301d520eb33c7b1f0dba598c5324b1ff120c08d8fd03f81e5cdc6
|
|
BLAKE2b-256 checksum How to use checksums |
1e6157498ad778fcfefdb9530505f3d6d93bc1f0725622c64b5c7d308f6dcbaf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for bsolver 0.1.1
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.