关于 UML 和图灵完备性的一个天真的问题

发布于 2024-09-28 11:18:49 字数 176 浏览 10 评论 0原文

众所周知,UML 并不是图灵完备的(与通常的编程语言相比)。但在我看来,UML 比传统语言更加灵活。我无法想象一个问题可以用C++(fe)这样的语言来描述,但同时又不能用UML来描述。恰恰相反,我更容易喜欢 UML 中存在但 C++ 中不可靠的构造(Java、Delphi、VB 等......) 你能帮我理解这一刻吗?我实在是抓不住了。

It'a a well-known fact that UML does not Turing complete (in contrast to usual programming languages). But it seems to me UML is even more flexible than traditional languages. I can't imagine a problem you can describe by means of such language as C++ (f.e) but at the same time can't describe by means of UML. Quite the contrary it's much more easier for me to fancy a construction existing in UML but unreliazable in C++ (Java, Delphi, VB and so on...)
Could you help me to understand this moment? I really can't catch it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

肥爪爪 2024-10-05 11:18:49

我想说,自从添加了 Action Semantics 包(这发生在 UML 1.5 版本中)以来,UML 是一种图灵完备语言。

现在,UML 包含命令式操作语言(不要与 OCL 混淆),它允许精确定义类方法的行为。这种命令式操作语言包括典型的赋值集、if 条件、迭代器……您期望从任何编程语言中获得。

这种动作语言是可执行 UML 方法的流行组件之一,但它现在是 UML 标准本身的一部分

I´d say that UML IS a turing complete language since the addition of the Action Semantics package (this happened in UML 1.5 version).

Now UML includes an imperative action language (not to be confused with OCL) that allows a precise definition of the behaviour of class methods. This imperative action language includes the typical set of assignments, if conditions, iterators,... you´d expect from any programming language.

This action language is one of the popular components of Executable UML approaches but it´s now part of the UML standard itself

夜未央樱花落 2024-10-05 11:18:49

有趣的问题。我想到了几点,尽管可能还有更多。抱歉,它很长。

什么是你可以用 C++ 来描述而不能用 UML 描述的?

首先,你必须定义“UML”的含义。一般来说,人们倾向于指“核心”元素——类图、状态图、活动图等上的元素——加上 OCL(约束语言)。

考虑到这些元素,您无法指定命令式算法。具体来说,任何需要分配的事情。然而,您可以非常接近:步骤和决策逻辑可以使用活动图等来表达,并且每个步骤的功能在 OCL 中定义为前置条件和后置条件。但是,您永远无法完全指定该行为。举一个原子步骤的例子,其目的是增加整数的值。输入是一个整数 - 比如说X。输出由后置条件 X == X@pre+1 描述。然而,UML 中没有任何内容可以实际实现该步骤。

现在完全可以想象扩展 UML 的使用来解决上述问题。 UML 动作语义的开发正是为了实现动作规范。这样做使该语言在计算上变得完整。这些问题仅仅是实际问题:

  1. 没有普遍同意和采用的语义语法;
  2. 实现很少

什么可以用UML 描述而不能在例如C++ 中实现?

本质上什么都没有。然而,存在两个实际限制:

  1. UML“规范”通常不精确、不明确和/或不完整。例如,活动图通常会留下悬空的路径。可以直接用C++表示吗?是的。它会编译吗?不。
  2. UML 结构到命令式、基于堆栈的语言的一些映射是非常重要的。状态模型就是一个例子:虽然有众所周知的模式,但映射相当复杂。对于分层和/或并发行为尤其如此。在活动图中,很容易表达两个活动并行发生,然后在进入下一步之前同步。这当然可以在 C++ 中完成,但需要使用线程库等。

然而这是可以做到的。事实上,这就是可执行 UML 工具的作用:模型编译器采用可执行 UML 模型并将其转换为 100% 正常运行的命令式代码。

嗯。

Interesting question. A couple of points come to mind, although there's probably a whole more to it. Apologies it's quite long.

What can you describe with e.g. C++ that you can't describe with UML?

First, you have to define what you mean by "UML". Generally, people tend to mean the 'core' elements - those on Class Diagrams, State Diagrams, Activity Diagrams etc. - plus OCL (the constraint language).

Given those elements you can't specify imperative algorithms. Specifically, anything that requires assignment. You can however get very close: the steps and decision logic can be expressed using e.g. Activity Diagrams, and the function of each step defined as pre- and post-conditions in OCL. However, you never quite get to fully specifying the behaviour. Take an example of an atomic step whose purpose is to increment the value of an integer. The input is an integer - say X. The output is described by the post-condition X == X@pre+1. However, there's nothing in UML to actually implement the step.

Now it's entirely conceivable to extend usage of UML to address above. The UML Action Semantics were developed precisely to enable specification of actions. Doing so makes the language computationally complete. The problems are merely practical:

  1. There's no universally agreed and adopted syntax for the semantics;
  2. There are very few implementations

What can you describe with UML that can't be implemented in e.g. C++?

In essence nothing. However there are two practical limitations:

  1. UML "specifications" are usually imprecise, ambiguous and/or incomplete. Activity Diagrams, for example, often leave paths dangling. Could it be represented directly in C++? Yes. Would it compile? No.
  2. Some of the mappings for UML constructs to imperative, stack based languages are non-trivial. State Models are an example: while there are well-known patterns, the mapping is quite complex. This is especially true for hierarchical and/or concurrent behaviour. In an activity Diagram, it's easy to express that two activities happen in parallel and then synchronise before moving to the next step. That can of course be done in C++ but requires the use of e.g. threading libraries.

It can however be done. In fact, it's what the Executable UML tools do: Model Compilers take an executable UML model and translate it into 100% functioning imperative code.

hth.

灰色世界里的红玫瑰 2024-10-05 11:18:49

顾名思义,UML 是一种建模语言。它有时可以用作设计软件的方法。

曾几何时,他们梦想着自动代码生成的方法,它们被称为 CASE 工具。尽管他们确实从语言中删除了许多样板代码,但他们未能使代码生成器有效地工作。这种增强成为 UML 的关键,因为它提供了一种增强软件设计和编程体验的方法。

我不知道 UML 是否是“图灵完备”,我希望它是,通过以图形格式向计算机描述问题并让计算机完成所有那些困难的讨厌的编程来提出解决方案不是很棒吗?你。

UML 是代码中操作的元语言。它描述了人工制品、它们如何关联/交互以及它们的作用。

UML 正在被添加,新的设计制品正在逐年添加,如果它还不是图灵完备,我不明白为什么它不能。

然而,我认为在某个地方,我读到了一些关于语言是“图灵等效”的内容,如果它们都可以表达和解决相同的解决方案。

由于 UML 是设计语言,代码是基于 UML 设计的实现语言,所以我想说 UML 和代码(c#、java 等)是图灵等效的。如果它们被同意是图灵等效的,那么 UML 必须是图灵完备的。

As the name implies UML is a modelling language. It can sometimes be applied as a methodology for designing software.

Once upon a time they were dreaming up ways of automatic code generation, they were called CASE tools. They failed to get the code generators to work effectively, although they did remove a lot of boiler plate code from the language. This augmentation became the key to UML as it provided a way to augment the experience of designing and programming software.

I don't know if UML is "Turing Complete", I hope it is, wouldn't it be great to come up with solutions by describing the problem to the computer in pictorial format and letting the computer do all that hard nasty programming for you.

UML is the meta language to the doing in the code. It describes artefacts, how they relate/interact and what they do.

UML is being added to, new design artefacts are being added year by year, and if it is not already Turing Complete I don't see why it couldn't be.

However I think somewhere along the line I read something about languages being "Turing Equivalent" if they could both express and solve the same solution.

Since UML is the design language and code is the implementation language based on the UML design I would say that UML and code (c#, java, etc) are Turing Equivalent. If they are agreed to be Turing Equivalent then UML must be Turing Complete.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文