如何利用实体关系图来建模数学表达式?

发布于 2024-10-11 11:54:35 字数 376 浏览 8 评论 0原文

我是实体关系图(ERD)的新手,在尝试为以下问题提出图表/模型时遇到一些困难 - 我什至不知道从哪里开始。这可能吗?任何建议或解决方案将不胜感激。

ERD 如何通用地用于 模型数学表达式(加上, 减、乘、除) 考虑到以下因素 表达式的优先级是 待评估。

  • 必须首先计算括号中的表达式(请注意,括号可以嵌套在其他括号内,深度不受限制)。
  • 乘法和除法必须先于加法和减法计算
  • 乘法和除法必须从左到右计算
  • 加号和减号必须从左到右计算

请指出找到的属性 在您描述的每个实体中 建议的解决方案/图表。

I am a newbie in Entity-Relationship diagrams (ERD) and have some difficulty in trying to come up with the diagram/model for the following problem - I don't even have a clue on where to start. Is this even possible? Any advice or solution would be greatly appreciated.

How can the ERD be used to generically
model mathematical expressions (plus,
minus, multiply and divide) taking
into account of the following
precedence in which the expression is
to be evaluated.

  • Expressions in brackets must be evaluated first (Note that brackets can be nested within other brackets up to an unlimited depth).
  • Multiply and divide must be evaluated before plus and minus
  • Multiply and divide must be evaluated from left to right
  • Plus and minus must be evaluated from left to right

Please indicate the attributes found
in each entity as depicted in your
proposed solution/diagram.

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

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

发布评论

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

评论(3

浪菊怪哟 2024-10-18 11:54:35

但这是谁给你的?老师?真正的?

ER 图不是为此而制作的!你的老师知道什么是 ER 图吗?对于这种建模,有活动图和其他图。

但一开始我看到了一种递归关系:

Expression ----inside----> Bracket ------->cotains------->Bracket 

表达式是一个实体,括号是一个实体。里面和包含是关系。括号有一个又回到自身的关系。不要绘制两个实体..等等....

只需看这里:http:// en.wikipedia.org/wiki/File:ER_Diagram_MMORPG.png
表达式等于图形中的字符,括号等于帐户...

But who gave you this? A teacher? For real?

ER-Diagrams are not made for this! Does your teacher know what ER-Diagrams are? For this kind of modelling there are Activity and other diagrams.

But for the beginning I see a recursive relation:

Expression ----inside----> Bracket ------->cotains------->Bracket 

Expression is an entity,Bracket is ONE an entity. Inside and contains are relations. Bracket has a relation which gos to itself again. Dont draw two entities.. and so on....

Just look here: http://en.wikipedia.org/wiki/File:ER_Diagram_MMORPG.png
Expression is equal to Character in the graphic, and Bracket is equal to Account...

勿忘初心 2024-10-18 11:54:35

如果您愿意将所有表达式视为“括号内”并将玩具存储视为表达式树,这可能比您想象的要简单。所有操作都是从左到右进行的,这很有帮助。只需考虑一个递归设计,其中每个操作数可以是另一个表达式的 id(递归)或文字(基本情况)。

您本身不会有太多的 ER 图。

Expression: id, leftOperand, rightOperand, operator

You may or may not want an operator table.  Depends on what you foresee being done in database and what you foresee being done in application code.
Operators: id, symbol, 

This is probably simpler than you think if you are willing to think of all expressions as "bracketed" and think of toyr storage as an expression tree. It helps that all operations are left-to-right. Just consider a recursive design in which each operand can be the id of another expression (recursive) or a literal (basecase).

You aren't going to have much of an ER diagram per se.

Expression: id, leftOperand, rightOperand, operator

You may or may not want an operator table.  Depends on what you foresee being done in database and what you foresee being done in application code.
Operators: id, symbol, 
梅窗月明清似水 2024-10-18 11:54:35

如果我要以表的形式表达表达式,我会使用嵌套集来表达某些操作数本身就是表达式的事实。

我将运算符优先级视为语法糖,使得用基于文本的编程语言编写公式变得更容易。我认为在内部模型中明确优先级可能比制定消歧优先级规则更有价值。

至于详细设计,我就留作作业吧。

If I were going to express expressions in the form of tables, I would use nested sets to express the fact that some operands are themselves expressions.

I regard operator precedence as syntactic sugar, making it easier to write formulas in text based programming languages. I think making the precedence explicit in an internal model is probably more worthwhile than having precedence rules for disambiguation.

As to the detailed design, I'll leave that as homework.

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