复数表示法

发布于 2024-08-05 18:17:46 字数 413 浏览 6 评论 0原文

我的 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 技术交流群。

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

发布评论

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

评论(4

彻夜缠绵 2024-08-12 18:17:47

您的用户有使用特定的符号吗?你能选出一个尽可能接近他们的吗?就我而言,我会使用 a + bi 所以我会说 {31 * 5} + {6 + -5}i 但是,如果他们习惯了函数形式,那么我建议使用 complex(31 * 5, 6 + -5 )。

由于您使用的是 .net,因此您可能希望使用 DLR 为脚本提供 pythonruby 语法?

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?

离旧人 2024-08-12 18:17:47

我发现的大多数具有复数内置类型的语言(例如 Python 和 Lisp)都使用以下内容:

c{r, i}

Most of the languages I can find that have a complex number builtin type (such as Python and Lisp) use something like:

c{r, i}
[旋木] 2024-08-12 18:17:47

看来您在示例中使用了显式乘法(即您需要 A * B,而不是 AB )。

在这种情况下,为什么不简单地在值后面直接使用 i 后缀,如“

 myComplex = 12 + 6i
   or
 myOtherComplex = 12/7 + (6 * pi)i

那么你可能需要决定 i 或 j,我都见过...

这个 i 后缀技巧与科学计数法没有什么不同,是 e (例如 3.1415e7)

编辑(根据 David 的评论)

上面的格式可能会变得令人困惑,具体取决于受众,澄清这一点的一种方法可能是仅允许虚构的文字< /em>,并将它们包含到从现有矢量符号派生的复杂符号中。当虚数或复数需要表达式来指定它们时,语法将需要显式“函数式”语法,例如 Imaginary(i) 和 Complex(r, i)。

解析规则

  • 任何直接跟在后缀 i 后面的数字(有符号或无符号、整数或小数、甚至是表达式符号数)都是虚数:-7i 或 1.23i 或 5.76e4i,但不能是 12 i(数字和后缀之间不允许有空格)
  • 两个值向量,第一个实数和第二个虚数是复数:(1, 7i) 或什至 (7, 0i)
  • 当“i”时使用虚数(i) 格式值是一个表达式。 i 的表达不带 i 后缀,这是方法调用语法所隐含的。
  • 当“r”或“i”参数是表达式时,以及当我们希望避免歧义时,使用 Complex(r,i) 格式。

简而言之

  • (7, 1i) 、 (0, -3.1415i)、(13, 0i)、Complex(13, 0) 或 Complex(7x+3, sin(y)+2)都是复数
  • 6i, -1.234e5i, Imaginary(1.234) 或 Imaginary(sqrt(19x+5y)) 都是虚数
  • 中的向量
  • (12, 23, 34) 是 R^3 (12i, -2i) I^2 中的向量(不是复数,因为第一个元素不是实数)
  • ((0,0i), (1,-9.2i), (12, 0i)) 或 ((0, 21i), Complex( 12,3), (44, -55i)) 是 C^3 中的向量

这看起来足够一致和简单,但话又说回来,只有真正的最终用户才能知道。

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

 myComplex = 12 + 6i
   or
 myOtherComplex = 12/7 + (6 * pi)i

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:

  • Any number (signed or unsigned, integer or decimal, or even exp. notation number) directly followed by the suffix i is a imaginary number: -7i or 1.23i or 5.76e4i but not 12 i (no space allowed between number and suffix)
  • a two values vector with the first one real and the 2nd imaginary is a complex: (1, 7i) or even (7, 0i)
  • Imaginary(i) format is used when "i" value is an expression. i is expressed without the i suffix which is implied by the method call syntax.
  • Complex(r,i) format is used when either "r" or "i" params is/are an expression, and also whenever we wish to avoid ambiguity.

In short:

  • (7, 1i) , (0, -3.1415i), (13, 0i), Complex(13, 0) or Complex(7x+3, sin(y)+2) are all complex numbers
  • 6i, -1.234e5i, Imaginary(1.234) or Imaginary(sqrt(19x+5y)) are all imaginary numbers
  • (12, 23, 34) is a vector in R^3
  • (12i, -2i) in a vector in I^2 (not a complex number, since the first element is not real)
  • ((0,0i), (1,-9.2i), (12, 0i)) or ((0, 21i), Complex(12,3), (44, -55i)) are vectors in C^3

That's seems consistent and simple enough, but then again, only the true end-users can tell.

红尘作伴 2024-08-12 18:17:46

如果您的愿望是简单地区分复数的实部和虚部,我会执行以下操作之一。

  • 用某种形式的括号将数字括起来,以确保将其视为一个单位。例如,6+5i 变为 {6,5} 或 {6,5i} 以提高可读性。
  • 引入一个标记来分隔各部分,类似于 6.022e23 中的指数。例如,6+5i 变为 6i5。您仍然需要括号来指定该公式,例如 6 + (b/2)i 变为 6i(b/2),而不是令人困惑的 6ib/2(也可以读作 (6ib)/2)不幸的是你失去了 i 作为变量的使用。

即使使用简单的解析器,它们中的任何一个都可以简单地处理,并且它们足够接近数学符号,以免混淆。我更喜欢第一个,因为它对我来说似乎更明确,并且使用不太可能混淆的符号。

If your desire is to simply differentiate the real from the imaginary component for a complex number, I'd do one of the following.

  • Enclose the number with some form of parentheses to ensure it's treated as a unit. For example, 6+5i becomes {6,5} or {6,5i} for extra readability.
  • Introduce a marker to separate the parts, similar to the exponent in 6.022e23. For example, 6+5i becomes 6i5. You'd still need parentheses to specify formulae for this one, such as 6 + (b/2)i becoming 6i(b/2), not the confusing 6ib/2 (which could also be read as (6ib)/2) and unfortunately you lose the use of i as a variable.

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.

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