支持正方形交集的几何定理证明器

标签 geometry computational-geometry z3 theorem-proving

我试图自动证明/反驳几何中与正方形相关的一些定理,例如“对于 7 个不相交正方形的每 3 个集合,可以从每个集合中选择 1 个正方形,使得 3 个代表内部不相交?”。

我尝试使用 OpenGeoProver并提出了以下关于正方形的描述:

    <!-- define a 'free' point - the south-western corner of the square: -->
    <pfree       label="square1southwest"/>

    <!-- define a line that is parallel to the x axis and goes throught that point - the southern boundary: -->
    <lparallel   label="square1south" point="square1southwest" baseline="xaxis" />

    <!-- define a random point on the southern line, which will be the south-eastern corner: -->
    <prandline   label="square1southeast" line="square1south" />

    <!-- rotate the south-eastern corner 90 degrees around the south-western corner, to create the north-western corner: -->
    <protated    label="square1northwest" origpt="square1southeast" center="square1southwest" angmeasure="-90"/>

    <!-- translate the north-western corner by the vector between the two southern corners, to create the north-eastern corner of the square: -->
    <ptranslated label="square1northeast" origpt="square1northwest" point1="square1southwest" point2="square1southeast"/>

这就是我被困的地方:如何定义简单的语句“正方形 A 和正方形 B 相交”?

如何在 Z3 中解决这个问题?

最佳答案

我试图用 MiniZinc 来反驳你的定理:

int: noOfCollections = 3;
int: noOfDisjoints = 7;
int: noOfSquares = noOfCollections * noOfDisjoints;
set of int: Squares = 1..noOfSquares;
int: maxDim = 10000;  %  somewhat arbitrary limit!
int: maxLeft = maxDim;
int: maxRight = maxDim;
int: maxTop = maxDim;
int: maxBottom = maxDim;
int: maxHeight = maxBottom - 1;
int: maxWidth = maxRight - 1;

array[Squares] of var 1..maxLeft: Left;
array[Squares] of var 1..maxTop: Top;
array[Squares] of var 1..maxHeight: Height;
array[Squares] of var 1..maxWidth: Width;
array[Squares] of var bool: Representative;
array[Squares] of 1..noOfCollections: 
      Collection = [1 + (s mod noOfCollections) | s in Squares];

%  Squares must fit in the overall frame
constraint
    forall(s in Squares)(
        (Left[s] + Width[s] - 1 <= maxRight) /\
        (Top[s] + Height[s] - 1 <= maxBottom)
    );

predicate disjoint(var int: s1, var int: s2) =
    (Left[s1] + Width[s1] - 1 < Left[s2]) \/
    (Left[s2] + Width[s2] - 1 < Left[s1]) \/
    (Top[s1] + Height[s1] - 1 < Top[s2]) \/
    (Top[s2] + Height[s2] - 1 < Top[s1]);

%  Squares in a collection must be disjoint
constraint
    forall(s1 in Squares, s2 in Squares 
           where (s1 > s2) /\ (Collection[s1] == Collection[s2]))(
        disjoint(s1, s2)
    );

%   Exactly one Representative per Collection
constraint
    1 == sum(c in 1..noOfCollections, s in Squares 
             where c == 1 + (s mod noOfCollections))
           (bool2int(Representative[s]));

%   Is it possible to select 1 square from each collection such 
%   that the 3 representatives are interior disjoint?
constraint
    forall(s1 in Squares, s2 in Squares, s3 in Squares
           where (Collection[s1] == 1) /\
                 (Collection[s2] == 2) /\
                 (Collection[s3] == 3))(
        disjoint(s1, s2) /\
        disjoint(s1, s3) /\
        disjoint(s2, s3) /\
        Representative[s1] /\
        Representative[s2] /\
        Representative[s3]
    );

solve satisfy;

MiniZinc 在 45 毫秒后出现“UNSAT”。

关于支持正方形交集的几何定理证明器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21252065/

相关文章:

algorithm - 如何旋转粒子系统(大小为 =num_particles*3 的二维矩阵),以便某些条目变为零

html - 如何仅使用 CSS 创建一个圆或正方形 - 中心是空心的?

R/Index 下三角向量(按成对索引)

c++ - 使用直线划分两组点

algorithm - 比质心更好的 "centerpoint"

z3 - Z3 应该证明 <= (相对于乘法)的单调性吗?

algorithm - 在最接近给定点的圆上找到点的最佳方法

algorithm - 次线性但简单的动态凸包算法?

z3 - 使用取模和优化的 z3py 的性能问题

python - z3py 中的 if 断言