将代码从 Mathematica 复制到其他平台的已知问题?
我刚刚注意到,如果你在 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):
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将 Mathematica 代码复制到 Usenet Mathematica 组有时会在您的代码中散布各种奇怪的字符(您永远不知道什么时候会发生在您身上)。解决方法是:
Cell >转换为> InputForm
然后进行复制Edit>复制为>纯文本
或输入文本
后者在这种情况下不起作用。您将得到的转换在数学上仍然是不正确的。前者似乎确实有效。
更新
如果您在 Mathematica 新闻组的帖子中遇到奇怪的字符(例如,如 这里)以下函数将对其进行解码(在我测试的所有情况下)。
只需将整个帖子粘贴到
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:
Cell > Convert To > InputForm
and then do a copyEdit > Copy As > Plain Text
orInput 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).
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.将示例复制到电子邮件也会失败,而且(如果它延续到其他示例)对于 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.
这是一个很好的例子,说明了如何设置 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?