1 个稳定版本
| 1.0.2 | 2023年4月18日 |
|---|
#40 在 #评估器
24KB
119 代码行
逻辑求解器
逻辑求解器是一个用于求解和解析逻辑方程的 Rust 库。
支持的操作
| 谓词 | 用法 |
|---|---|
| 合取(AND) ∧ | and |
| 析取(OR) ∨ | or |
| 否定(NOT) ¬ | not |
| 条件(IF...THEN) ⇒/→ | => |
| 双条件(IF AND ONLY IF) ⇔/↔ | <=> |
| 变量(用于真值表)* | [A-Z]+ |
变量可以是单个或多个大写字母。
用法
let expr = parse_expression("true => not false or (true and false)");
let result = enumerate(expr, HashMap::new());
assert_eq!(result, true);
let vars = vec!(String::from("A"), String::from("B"))
let expr = parse_expression("A => not B");
let states = permutate(vars);
let result = solve_truth_table(expr, vars);
assert_eq!(result, [true, true, true, false]);
请查看/examples 文件夹中的完整示例。使用以下命令运行: cargo run --example <example_name>
依赖项
~2.2–4.5MB
~72K SLoC