- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Windows 7 以及 Java 7 64 位上使用 Z3 版本 4.3.2 64 位的 Java-API。
我正在尝试使用简化来获取有关断言集中冗余信息的知识。
我的第一次尝试是简化 boolean 表达式并像这样评估结果
Expr e = ctx.mkImplies(ctx.mkBoolConst("A"),ctx.mkBoolConst("B")).simplify();
在我的例子中
(=> A B)
(=> (not B) C)
(=> A B)
(=> B A)
(=> D E)
(=> B F)
(=> G D)
(=> H I)
(=> I (not D))
(=> (not D) I)
(=> C (not B))
C)
这会产生一个简化的公式
(and
(or (not A) B)
or B C)
or (not B) A)
(or (not D) E)
(or (not B) F)
(or (not G) D)
(or (not H) I)
(or (not I) (not D))
(or D I)
(or (not C) (not B))
C
)
我之前将含义包装在 AND 表达式中,以便将它们简化为一个表达式。
这个结果还不是我想要的。原始代码第三行中的重复规则被删除(这很好)。但如果 C 为真(示例的最后一行),则 B 必定为假((=> C(不是 B))
)。如果 B 为假,则 A 必定为假 ((=> A B)
)。等等...
我的expexted更像是下面的(我手工完成的,所以转换可能有错误)
(and
(or (not A) B) ; transformed to (not A)
or B C) ; transformed to C
or (not B) A) ; deleted
(or (not D) E) ; left unchanged
(or (not B) F) ; deleted
(or (not G) D) ; left unchanged
(or (not H) I) ; left unchanged
(or (not I) (not D)) ; left unchanged
(or D I) ; left unchanged
(or (not C) (not B)) ; transformed to (not B)
C ; C
)
接下来,我尝试使用如下策略
Tactic simplifyTactic = ctx.mkTactic("ctx-solver-simplify");
Tactic smtTactic = ctx.mkTactic("smt");
Tactic then = ctx.then(simplifyTactic, smtTactic, new Tactic[] {});
Solver solver = ctx.mkSolver(then);
solver.add(bel2.toArray(new BoolExpr[0])); // bel2 is List<BoolExpr>
Status status = solver.check();
这样做会产生一个模型,而不是简化。此外,对我来说,让简化策略发挥作用有点困难。通常结果是未知的,原因是“不完整”。
我上面描述的预期结果可以用 Z3 计算吗?怎么办?
我已经在这个论坛上环顾四周了,但我的观点没有得到真正的回答......
最佳答案
作为一种策略,smt
不会导致您试图实现的断言的任何转换或简化,这是可满足性策略,因此对于某些断言,它将返回 sat 、未饱和、未知或可能超时。
使用简化策略更符合您的需求,但您可能需要应用不同的策略来实现您想要的转换。但是,当我以 SMT-LIB 格式对您的问题进行编码并在您尝试时使用 ctx-solver-simplify 策略时,它返回了我认为您正在寻找的内容(rise4fun 链接:http://rise4fun.com/Z3/r2id ):
(declare-fun A () Bool)
(declare-fun B () Bool)
(declare-fun C () Bool)
(declare-fun D () Bool)
(declare-fun E () Bool)
(declare-fun F () Bool)
(declare-fun G () Bool)
(declare-fun H () Bool)
(declare-fun I () Bool)
(assert (and (=> A B)
(=> (not B) C)
(=> A B)
(=> B A)
(=> D E)
(=> B F)
(=> G D)
(=> H I)
(=> I (not D))
(=> (not D) I)
(=> C (not B))
C))
(apply ctx-solver-simplify)
; result:
; (goals
; (goal
; (=> A B)
; (or (not D) E)
; (or (not G) D)
; (or (not H) I)
; (or (not I) (not D))
; (or D I)
; (not B)
; C
; :precision precise :depth 1)
;)
对于您的实验,您可能需要先回顾一下策略(http://rise4fun.com/z3/tutorialcontent/strategies#h21),并在使用 API 之前在 SMT-LIB 界面中尝试一些,因为这样您的实验可能会更快。另外,正如您所看到的,这会返回一个目标。在 Java API 中,尝试更改为以下内容并查看 ApplyResult
对象的 Subgoals
字段(它是 Goal
对象的集合)以查看如果它有你想要的:
Tactic simplifyTactic = ctx.mkTactic("ctx-solver-simplify");
Goal g = ctx.mkGoal();
g.Assert(bel2.toArray(new BoolExpr[0]));
ApplyResult a = simplifyTactic.Apply(g);
// look at a.Subgoals
这是基于我使用 .NET API 的经验,可能与 Java 略有不同,但您可以在此处查看 Goal
Java 文档: https://z3.codeplex.com/SourceControl/changeset/view/8bfbdf1e680d#src/api/java/Goal.java
关于java - Z3:使用Java API来简化断言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21622706/
hello1 hello2 hello3 hello4 hello5 hello6
有没有更简短的写法: (apply f (cons a (cons b (cons c d)))) ? 谢谢! (我正在编写一些调用其他函数的辅助函数,这种“模式”似乎经常出现
.NET团队北京时间2024年5月22日已正式发布.NET Aspire ,在博客文章里做了详细的介绍:.NET Aspire 正式发布:简化 .NET 云原生开发 - .NET 博客 (micros
在this dbfiddle demo我有一个 DELETE FROM...WHERE 最后像这样: ...... DELETE FROM data_table WHERE
我有几个 if 语句,如下面的一个。我假设这是一种非常糟糕/长期的编码方式,但不确定我应该做些什么不同的事情。有人有什么建议吗? 谢谢 For a = 1 To Leagues If a =
有什么类似的战术simpl为 Program Fixpoint ? 特别是,如何证明以下无关紧要的陈述? Program Fixpoint bla (n:nat) {measure n} := mat
我使用此代码来跟踪表单上是否有任何更改: $(document).on('input', '.track', function() { var form = $(this); }); 由于这不
我有以下函数,我想用 for 循环来简化它,但不知道该怎么做。任何帮助都感激不尽。基本上,如果字段值为 0 或 null,则我的总值(字段)应为 0,否则,如果字段值从 1 到 1000,则总值变为
我正在尝试对时间字符串执行非常简单的解析 data Time = Time Int Int Int String -- example input: 07:00:00AM timeParser ::
为了使我的代码更具可读性和更简单,我对这段代码绞尽脑汁: var refresh = setInterval(datumTijd, 1000); function datumTijd() { do
这个问题已经有答案了: Check if a variable is in an ad-hoc list of values (8 个回答) 已关闭 9 年前。 只是一个基本的if声明,试图使其更简单
我有一个这样的 if 语句 int val = 1; if (val == 0 || val == 1 || val == 2 || ...); 有没有更简单的方法?例如: int val = 1;
我有一个程序,其中有一些 if 语句,与我将要向您展示的程序类似。我想知道你们是否可以帮助我以任何方式简化这个方程。我之所以问这个问题,是因为在我的 Notepad++ 中,它持续了 443 列,如果
是否可以简化这个 if 语句? 如果是,答案是什么? if (type) { if(NdotL >= 0.0) { color
我有一个包含亚马逊大河的 shapefile。仅 shapefile 就有 37.9 MB,连同属性表高达 42.1 MB。我正在生成所有巴西亚马逊的 PNG 图像,每个 1260x940 像素,sh
System.out.printf("%7s", "a"); System.out.printf("%7s", "b"); System.out.printf("%7s", "c"); S
假设我们有客户端-服务器应用程序,由一个 makefile 编译。服务器使用 libtask 为并行客户端提供服务。客户端使用 ncurses 来处理某些图形。目录树如下所示: ./ --bin/ -
我在 Mono 密码转换的重新实现中找到了这段代码。 我没有修改或简化任何东西 - 这就是它的实际运行方式(有评论如//Dispose unmanaged objects,但实际上什么也没做)。 现在
我需要一些帮助来简化这个包含数百行的庞大代码,但我真的不知道该怎么做。代码看起来真的很乱,我需要的是返回具有预定义文本颜色的模型。有什么简单的方法吗? 我必须多解释一点:- 有一个包含许多型号的手机列
这里有一些代码可以正常工作,但我认为可以简化/缩短。它基本上是点击一个列表项,获取它的 ID,然后根据 ID 显示/隐藏/删除元素。 关于如何使用函数或循环来简化它的建议? $("#btn_remov
我是一名优秀的程序员,十分优秀!