方程线程:为什么是默认行为? [英] Equation Threading: Why the default behavior?

查看:113
本文介绍了方程线程:为什么是默认行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近重新发现了Roman Maeder的一个小程序包,该程序包告诉Mathematica对诸如x == y的表达式自动执行算术运算和类似函数. 链接到Maeder的软件包.

I recently rediscovered a small package by Roman Maeder that tells Mathematica to automatically thread arithmetic and similar functions over expressions such as x == y. Link to Maeder's package.

首先,为了演示,这是Maeder给出的示例:

First, to demonstrate, here's an example given by Maeder:

In[1]:= Needs["EqualThread`"]

现在继续使用线程行为来解决x'用手'的以下方程式:

Now proceed to use the threading behavior to solve the following equation for x 'by hand':

In[7]:= a == b Log[2 x]
In[8]:= %/b
Out[8]:= a/b == Log[2 x]

现在求幂:

In[9]:= Exp[%]
Out[9]= E^(a/b) == 2 x

然后除以2:

In[10]:= %/2
Out[10]= (E^(a/b))/2 == x

问:从设计的角度来看,有人可以解释为什么Mathematica默认设置为这种行为吗?自动线程化看起来像是Mathematica初学者所期望的行为类型-对我来说,至少-也许有人可以提供一个或两个示例,这可能会导致整个系统出现问题. (并随时指出任何数学上的无知...)

Q: From a design perspective, can someone explain why Mathematica is set to behave this way by default? Automatically threading seems like the type of behavior a Mathematica beginner would expect---to me, at least---perhaps someone can offer an example or two that would cause problems with the system as a whole. (And feel free to point out any mathematica ignorance...)

推荐答案

在考虑算术运算时似乎很自然.但这并非总是如此.

Seems natural when thinking of arithmetic operations. But that is not always the case.

当我写

Boole[a==b]  

我不要

Boole[a] == Boole[b]  

这就是Maeder的包裹所做的.

And that is what Maeder's package does.

修改

在下面回答您的评论:

我注意到在v.5.2中添加了Boole [],而Maeder的软件包是为v.3编写的.我想我的问题的核心仍然围绕着设计"问题.我的意思是,如何解决您指出的问题?对我来说,最清晰的路径是声明一些有关您正在使用的变量的信息,不是吗? -让我感到困惑的是,您通常只能通过假设(全局地或作为简化的一种选择,等等)来做到这一点.还有人认为拥有完整的数值属性会更自然吗? (就此而言,常量属性"是一个挑逗)

I noticed that Boole[] was added in v.5.2, whereas Maeder's package was authored for v.3. I guess the core of my question still revolves around the 'design' issue. I mean, how would one get around the issue you pointed out? To me, the clearest path would be declaring something about variables you're working with, no? -- What puzzles me is the way you can generally only do this with Assumptions (globally or as an option to Simplify, etc). Anyone else think it would be more natural to have a full set of numerical Attributes? (in this regard, the Constant Attribute is a tease)

我的回答绝不是对Maeder软件包的批评,这很好,但是声明它不应该成为在Mma中对待 Equal [] 的主流方法.

My answer is by no means a critic to Maeder's package, which is nice, but a statement that it should not be the mainstream way to treat Equal[ ] in Mma.

Equal []是一个函数,一开始并不容易掌握:

Equal[ ] is a function, and not particularly easy to grasp at first:

  • 如果lhs和rhs相同,则返回True
  • 如果通过数字或其他原始数据(例如字符串)之间的比较确定lhs和rhs不相等,则
  • 返回False.
  • 当lhs或rhs包含诸如Indeterminate和Overflow之类的对象时,
  • 仍未评估.
  • 用于表示符号方程式,可使用Solve之类的函数进行处理.
  • returns True if lhs and rhs are identical
  • returns False if lhs and rhs are determined to be unequal by comparisons between numbers or other raw data, such as strings.
  • remains unevaluated when lhs or rhs contains objects such as Indeterminate and Overflow.
  • is used to represent a symbolic equation, to be manipulated using functions like Solve.

Maeder软件包的目的与您的软件包非常吻合,旨在为表达式 lhs == rhs 提供人类在数学时所使用的相同含义和操作规则.

The intent of Maeder's package, which I understand is well aligned with yours, is to give to the expression lhs == rhs the same meaning and manipulation rules humans use when doing math.

在数学中,相等是等价关系,在集合中强加部分顺序,而等式则是表达式与该特定关系相关的断言.

In math, equality is an equivalence relation, imposing a partial order in a set, and an equation is an assertion that the expressions are related by this particular relation.

将这些差异与其他Mma功能"进行比较. Sin [x] 位于Mma中,在通常的数学运算中,这是同一件事(几乎是),大多数Mma野兽也可以说相同.但是,有一些Mma构造对数学概念没有完全相同的同构性:Equal,SameQ,Equivalent等,它们是从数学世界到编程世界的桥梁.它们不是严格的数学概念,而是经过修改的编程概念来保留它们.

Compare these differences with other Mma "functions". Sin[x] is in Mma, and in usual math the same thing (well, almost), and the same can be said of most Mma beasts. There are a few Mma constructs, however, that do not hold that exact isomorphism to math concepts: Equal, SameQ, Equivalent, etc. They are the bridge from the math world to the programming world. They are not strict math concepts, but modified programming concepts to hold them.

对不起,如果我在哲学方面有所了解.

Sorry if I got a little on the philosophical side.

HTH!

这篇关于方程线程:为什么是默认行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆