将代码从 Mathematica 复制到其他平台的已知问题?

发布于 2024-11-01 18:06:32 字数 602 浏览 1 评论 0原文

我刚刚注意到,如果你在 MMA (8.0.1 / win7-64) 中有这个:

在此处输入图像描述

并且你将其复制到 SO(只需 ctrl-c ctrl-v),您会得到:

(maxY - minY)/stepy/(maxX - minX)/stepx  

在数学上不等效。它应该是这样的:

((maxY - minY)/stepy)/((maxX - minX)/stepx)

或者这样(上面的InputForm):

((maxY - minY)*stepx)/((maxX - minX)*stepy)

它不是由StackOverflow的内部结构引起的,因为复制到记事本时也会发生同样的情况。

是否还有更多类似的问题(尤其是在使用 SO 时,但一般情况下)我们应该注意?

造成这种情况的原因是什么?我们可以解决这个问题吗?如果不能,最好的解决方法是什么?

I just noticed that if you have this in MMA (8.0.1 / win7-64):

enter image description here

and you copy it to SO (just ctrl-c ctrl-v), you get this:

(maxY - minY)/stepy/(maxX - minX)/stepx  

which is not mathematically equivalent. It should be this:

((maxY - minY)/stepy)/((maxX - minX)/stepx)

or this (the InputForm of the above):

((maxY - minY)*stepx)/((maxX - minX)*stepy)

It's not caused by StackOverflow's internals as the same happens with a copy to NotePad.

Are there more issues like this (especially when working with SO, but also in general) that we should be aware of?

What causes this, can it be fixed on our side, and if not, what is the best work-around?

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

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

发布评论

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

评论(3

你另情深 2024-11-08 18:06:32

将 Mathematica 代码复制到 Usenet Mathematica 组有时会在您的代码中散布各种奇怪的字符(您永远不知道什么时候会发生在您身上)。解决方法是:

  1. Cell >转换为> InputForm 然后进行复制

  2. Edit>复制为>纯文本输入文本

后者在这种情况下不起作用。您将得到的转换在数学上仍然是不正确的。前者似乎确实有效。

更新
如果您在 Mathematica 新闻组的帖子中遇到奇怪的字符(例如,如 这里)以下函数将对其进行解码(在我测试的所有情况下)。

translateQuotedPrintable[str_String] := 
  StringReplace[str, {"=" ~~ c1:HexadecimalCharacter~~c2:HexadecimalCharacter :> 
    FromCharacterCode[FromDigits[c1 <> c2, 16], "Math1"],"=" ~~ EndOfLine -> ""}]

只需将整个帖子粘贴到 translateQuotedPrintable[" ... "] 的引号之间,帖子就会被清理。

出于好奇:您可能会在这些 usenet 帖子中看到的编码称为 Quoted Printable。它用于将与标准 7 位 ASCII 集不同的字符编码转换为 ASCII。许多常见的 MMA 符号(例如规则符号)如果之前没有通过 InputForm cs 转换为 ASCII,都会以这种方式进行编码。要解码代码,需要知道原始字符集,因为 QP 仅产生字符集中的十六进制位置。对于 MMA 来说,最常见的是 Math1。

Copying Mathematica code to the Usenet Mathematica group sometimes scatters all kinds of weird characters throughout your code (you never knew when it would happen to you). The workaround would be either:

  1. Cell > Convert To > InputForm and then do a copy

  2. Edit > Copy As > Plain Text or Input Text

The latter doesn't work in this case. It's still a mathematically incorrect conversion that you'll get. The former does seem to work.

Update
If you ever encounter strange characters in posts in the Mathematica newsgroup (e.g., as in here) the following function will decode it (in all the cases that I tested).

translateQuotedPrintable[str_String] := 
  StringReplace[str, {"=" ~~ c1:HexadecimalCharacter~~c2:HexadecimalCharacter :> 
    FromCharacterCode[FromDigits[c1 <> c2, 16], "Math1"],"=" ~~ EndOfLine -> ""}]

Just paste the whole posting between quotes in translateQuotedPrintable[" ... "] and the post will be cleaned up.

For the curious: the encoding that you may see in these usenet postings is called Quoted Printable. It is used to convert character encodings that differ from the standard 7-bit ASCII set to ASCII. Many common MMA symbols, like the Rule symbol, are encoded this way if not previously converted to ASCII by InputForm cs. To decode a code one needs to know the original character set because QP only yields the hexadecimal position in the character set. In MMA's case this will most commonly be Math1.

站稳脚跟 2024-11-08 18:06:32

将示例复制到电子邮件也会失败,而且(如果它延续到其他示例)对于 Mathgroup、SO 和任何其他基于文本的讨论论坛来说似乎非常糟糕。复制为>纯文本和复制为>输入表单都可以正常工作,但我已经用简单的方法完成了数千次,并且从来不知道它会以这种方式失败,没有奇怪的十六进制字符。

Copying the example to e-mail ALSO fails, and that -- if it carries over to other examples -- seems very bad for Mathgroup, SO, and any other text-based discussion forum. Copy As>Plain Text and Copy As>Input Form both work properly, but I've done it the easy way thousands of times, and never knew it could fail this way, WITHOUT strange hexadecimal characters.

未蓝澄海的烟 2024-11-08 18:06:32

这是一个很好的例子,说明了如何设置 MMA 来解决排版中引入的数学歧义。 (+1)

失败的原因是您尚未计算原始表达式。当您评估时,Mathematica 正确解析两个块之间的“/”,并且可以(正确)复制和粘贴输出。

也许 WRI 应该做到这一点,以便“复制”强制解析机制在对表达式进行剪贴板之前发生——即某种“软”评估。想法?

This is a good example of how MMA is set up to resolve mathematical ambiguity introduced in typesetting. (+1)

The reason it fails is that you've not yet evaluated the original expression. When you evaluate, Mathematica correctly parses the "/" between the two chunks and the output can be copied and pasted (correctly).

Perhaps WRI should make it so that 'Copy' forces the parsing mechanism to occur prior to clip-boarding the expression --- i.e., some sort of 'soft' evaluation. Thoughts?

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