复数表示法
我的 DotNET 应用程序内置了有限的脚本语言(在 VBScript 上松散建模),主要用于后处理数字、点和向量。我刚刚添加了对复数的支持,但我在符号上遇到了困难。
我不想使用 A + Bi 表示法,因为如果 A 或 B 已定义为方程,则这不是一个明确的划分:
31 * 5 + 6 + -5i
这可以解释为:
A = 31 * 5 + 6 B = -5i
且:
A = 31 * 5 B = 6 + -5i
我所知道的编程语言都没有对复数的本机支持。我想像下面这样的东西可能会起作用,但我很感激任何对此的输入:
{31 * 5} + {6 + -5}i
complex(31 * 5, 6 + -5)
r{31 * 5我{6 + -5}
My DotNET application has a limited scripting language build in (modelled loosely on VBScript) mainly for post-processing numbers, points and vectors. I've just added support for complex numbers, but I'm struggling with the notation.
I don't want to use the A + Bi notation, since it is not a clear division if A or B are defined as equations already:
31 * 5 + 6 + -5i
This could be interpreted as:
A = 31 * 5 + 6
B = -5i
and:
A = 31 * 5
B = 6 + -5i
None of the programming languages I know have native support for complex numbers. I'm thinking something like the following might work, but I'd appreciate any input on this:
{31 * 5} + {6 + -5}i
complex(31 * 5, 6 + -5)
r{31 * 5} i{6 + -5}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的用户有使用特定的符号吗?你能选出一个尽可能接近他们的吗?就我而言,我会使用 a + bi 所以我会说 {31 * 5} + {6 + -5}i 但是,如果他们习惯了函数形式,那么我建议使用 complex(31 * 5, 6 + -5 )。
由于您使用的是 .net,因此您可能希望使用 DLR 为脚本提供 python 或 ruby 语法?
Do your users have a specific notation they use? Could you pick one as close to theirs as possible? In my case I'd use a + bi so I'd say {31 * 5} + {6 + -5}i however, if they used to the functional form then I suggest complex(31 * 5, 6 + -5).
Since you're using .net you might want to use the DLR to give your scripting python or ruby syntax?
我发现的大多数具有复数内置类型的语言(例如 Python 和 Lisp)都使用以下内容:
Most of the languages I can find that have a complex number builtin type (such as Python and Lisp) use something like:
看来您在示例中使用了显式乘法(即您需要 A * B,而不是 AB )。
在这种情况下,为什么不简单地在值后面直接使用 i 后缀,如“
那么你可能需要决定 i 或 j,我都见过...
这个 i 后缀技巧与科学计数法没有什么不同,是 e (例如 3.1415e7)
编辑(根据 David 的评论)
上面的格式可能会变得令人困惑,具体取决于受众,澄清这一点的一种方法可能是仅允许虚构的文字< /em>,并将它们包含到从现有矢量符号派生的复杂符号中。当虚数或复数需要表达式来指定它们时,语法将需要显式“函数式”语法,例如 Imaginary(i) 和 Complex(r, i)。
解析规则:
简而言之:
这看起来足够一致和简单,但话又说回来,只有真正的最终用户才能知道。
It seems you are using explicit multiplication in your examples (i.e. you require A * B, rather than A B ).
In that case why not simply use the i suffix directly following the value as in
Then you may need to decide about i or j, I've seen both...
This i-suffix trick is not unlike the scientific notication and is e (3.1415e7 for example)
Edit (following David's comments)
The format above can become confusing, depending on the audience, one way to clarify this may be to only allow for imaginary literals, and to include these into a complex notation derived from your existing vector notation. When imaginary numbers or complex number require an expression to designate them, the syntax would require the explicit "function-looking" syntax such as Imaginary(i) and Complex(r, i).
Parsing rules:
In short:
That's seems consistent and simple enough, but then again, only the true end-users can tell.
如果您的愿望是简单地区分复数的实部和虚部,我会执行以下操作之一。
即使使用简单的解析器,它们中的任何一个都可以简单地处理,并且它们足够接近数学符号,以免混淆。我更喜欢第一个,因为它对我来说似乎更明确,并且使用不太可能混淆的符号。
If your desire is to simply differentiate the real from the imaginary component for a complex number, I'd do one of the following.
Either of those would be simple to process even with a simple parser and they're close enough to the mathematical notation so as not to confuse. I prefer the first since it seems more explicit to me and uses symbols that are unlikely to confuse.