MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Design by Contracts in Mathematica

  • To: mathgroup at
  • Subject: [mg93382] Re: Design by Contracts in Mathematica
  • From: David Bailey <dave at>
  • Date: Wed, 5 Nov 2008 04:56:19 -0500 (EST)
  • References: <geeeb9$ae5$> <gemjgo$4ru$>

Steve Luttrell wrote:
> Like you, I am impressed by Eiffel's "safety features". However, I have a 
> counter-example that suggests that what you want to do is in general 
> impossible in Mathematica.
> Some of my Mathematica code has been broken by changes in the way that newer 
> versions of Mathematica represent expressions, though in every case the 
> newer representation was equivalent to the older representation. My problems 
> have arisen because I was using Part to pick out parts of algebraic 
> expressions for further processing, and each time I have tried to fix the 
> problem it has been broken by further representation changes in later 
> versions of Mathematica. So I have learnt that anticipating the form (i.e. 
> pattern) of Mathematica output can be problematic, and I don't use Part in 
> this way any more.
> More generally it is difficult/impossible to anticipate in advance what the 
> form of an output expression is going to be, because it is a computationally 
> "hard" problem to prove the equivalence of two (actually equivalent but 
> differently written) expressions. I am not an expert in computation theory, 
> so I might have used the wrong technical term, but you should get the idea 
> of what I mean.
I think it is important to distinguish between purely mathematical 
operations, such as Integrate, D, Simplify, FullSimplify, etc. where 
there is at least some sort of 'contract' that Mathematica is taking 
responsibility for the results (modulo the odd bug, or a different 
choice of branch cuts!), and structural operations, where the onus is on 
the user to use them in sensible ways. For example:

expr = expr /. Sin[Pi/9]->0

It is nonsense, but Mathematica will do it for you if that is what you want!

The use of Part on expressions, obviously comes into this category.

David Bailey

  • Prev by Date: Re: Create a cumulative list
  • Next by Date: Re: NetLink + Intel Fortran DLL (VS2008)
  • Previous by thread: Re: Design by Contracts in Mathematica
  • Next by thread: Re: Trinomial decics x^10+ax+b = 0; Help with Mathematica