如何利用实体关系图来建模数学表达式?
我是实体关系图(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
但这是谁给你的?老师?真正的?
ER 图不是为此而制作的!你的老师知道什么是 ER 图吗?对于这种建模,有活动图和其他图。
但一开始我看到了一种递归关系:
表达式是一个实体,括号是一个实体。里面和包含是关系。括号有一个又回到自身的关系。不要绘制两个实体..等等....
只需看这里: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 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...
如果您愿意将所有表达式视为“括号内”并将玩具存储视为表达式树,这可能比您想象的要简单。所有操作都是从左到右进行的,这很有帮助。只需考虑一个递归设计,其中每个操作数可以是另一个表达式的 id(递归)或文字(基本情况)。
您本身不会有太多的 ER 图。
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.
如果我要以表的形式表达表达式,我会使用嵌套集来表达某些操作数本身就是表达式的事实。
我将运算符优先级视为语法糖,使得用基于文本的编程语言编写公式变得更容易。我认为在内部模型中明确优先级可能比制定消歧优先级规则更有价值。
至于详细设计,我就留作作业吧。
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.