最一般的高阶约束,描述相对于一个关系排序的整数序列 [英] Most general higher-order constraint describing a sequence of integers ordered with respect to a relation

查看:100
本文介绍了最一般的高阶约束,描述相对于一个关系排序的整数序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CLP(FD)中,我们经常需要声明:这是整数和有限域变量的列表(有时(严格地: )升/降序.)

In CLP(FD), we frequently need to state: "This is a list of integers and finite domain variables in (sometimes: strictly) ascending/descending order."

是否有任何CLP(FD)系统为此任务提供常规(可参数设置)内置约束?

Is there any CLP(FD) system that provides a general (parametrisable) built-in constraint for this task?

SWI-Prolog提供了一个称为chain/2的约束,与我正在寻找的约束相似.但是,该名称过于具体,无法包含约束可以描述的所有关系(例如:#<不是部分顺序,但在chain/2中是可接受的,从而导致将序列—视为一组整数— no (如数学阶数理论中所定义的那样,更长的时间作为一个链).因此,该名称不能完全描述约束实际执行的内容.

SWI-Prolog provides a constraint called chain/2, which is similar to what I am looking for. However, the name is slightly too specific to encompass all relations that the constraint can describe (example: #< is not a partial order but admissible in chain/2, leading to the sequence — taken as a set of integers — no longer counting as a chain as defined in mathematical order-theory). Hence, the name does not fully describe what the constraint actually implements.

请针对通常的二进制CLP(FD)约束给出最通用的定义—或包含至少#<#>#=<#>=的合适子集-根据约束定义的代数结构,包括为专有名称.施加的条件是约束描述了在文献中具有专有名称的 actual 数学结构.

Please give the most general definition with respect to the usual binary CLP(FD) constraints — or a suitable subset that contains at least #<, #>, #=< and #>=including the proper name according to the algebraic structure the constraint defines. The condition imposed is that the constraint describe an actual mathematical structure that has a proper name in the literature.

首先,考虑使用SICStus Prolog或SWI:

As a start, consider with SICStus Prolog or SWI:

:- use_module(library(clpfd)).

connex(Relation_2, List) :-
    connex_relation(Relation_2),
    connex_(List, Relation_2).

connex_relation(#=).
connex_relation(#<).
connex_relation(#=<).
connex_relation(#>).
connex_relation(#>=).

connex_([], _).
connex_([L|Ls], Relation_2) :-
    foldl(adjacent(Relation_2), Ls, L, _).

adjacent(Relation_2, X, Prev, X) :- call(Relation_2, Prev, X).

示例:

?- connex(#<, [A,B,C]).
A#=<B+-1,
B#=<C+-1.

?- connex(#=, [A,B,C]).
A = B, B = C,
C in inf..sup.

?- maplist(connex(#<), [[A,B],[C,D]]).
A#=<B+-1,
C#=<D+-1.

请注意,甚至允许使用#\=,因为该关系将描述数学顺序理论中已知的连接.因此,相对于通常的二进制CLP(FD)约束,上面的代码并不是最通用.

Notice that it would even be admissible to allow #\=, because the relation would still describe a connex as known in mathematical order-theory. Hence, the code above is not most general with respect to the usual binary CLP(FD) constraints.

推荐答案

Hoogle不是很有用,但是

Hoogle was not very useful, but Hayoo is!

因此,这是一种特殊的折叠形式,但不适用于length list次,但不多于一次.

so this is a special form of fold for a list, but it does not apply length list times but one time less.

的名称并不完全是通用的,而是其签名.也许坚持使用最通用的名称并没有帮助.否则,我们到处都是实体?

is not entirely general in its name, but in its signature. Maybe insisting on the most general name is not that helpful. Otherwise we just have entities all over?

定义如下:

如果谓词对列表中所有相邻的元素对返回true,则isSortedBy函数将返回True.

The isSortedBy function returns True iff the predicate returns true for all adjacent pairs of elements in the list.

也许是:all_adjacent_pairs(R_2, Xs).在具有adjacent_pair作为某些修饰符的循环构造之后,听起来会有点.

Maybe: all_adjacent_pairs(R_2, Xs). which sounds a bit after having a looping construct that has adjacent_pair as some modifier.

这篇关于最一般的高阶约束,描述相对于一个关系排序的整数序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆