MathGroup Archive 2006

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

Search the Archive

Re: Re: EUREKA Re: Types in Mathematica, a practical example

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63611] Re: [mg63185] Re: EUREKA Re: [mg62800] Types in Mathematica, a practical example
  • From: "Ingolf Dahl" <ingolf.dahl at telia.com>
  • Date: Sat, 7 Jan 2006 02:29:36 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Kristen,
Comments are interlaced in the text below, 

> -----Original Message-----
> From: Kristen W Carlson [mailto:carlsonkw at gmail.com] 
To: mathgroup at smc.vnet.net
> Subject: [mg63611] Re: EUREKA Re: [mg62800] Types in Mathematica, a 
> practical example
> 
> Ingolf,
> 
> I am happy for your Archimedean insight and admire how you 
> have delved into this area and found a solution, and come out 
> the other side appreciating Mathematica all the more.
> 
> So don't feel insulted at this question, and it's my 
> ignorance of either your task or the style in other languages 
> that generates it.
> It's asked in the context of the various threads that reveal 
> a "world-view" conflict between programming styles, mainly 
> those inherited from other languages, I believe.
> 
> Can you help me understand why you need to do this? Are you 
> adapting Mathematica to do something that you have done 
> easily in another language, rather than doing it the 
> Mathematica Way (i.e. the way that is built in, since you 
> have created a new Mathematica Way on top of it)?

I began programming 1969, by reading and doing all exercises in a textbook
in Algol and also by programming a Olivetti Programma (a huge programmable
table-top machine which needed 21 operations just to calculate exp(x)). Then
I proceeded with DEC's Focal and PL/1 (symbolic calculations of expressions
using string manipulation!) on a large IBM machine. Then MINC Basic and
GW-Basic (for taking measurements over serial and GPIB bus), ASYST, some
little C programming (but I did not get along with the compiler), AutoLisp
(a variant of LISP built into AutoCAD), and also a six-letter CAS program,
not to be named here. Plus LabView and half-a-dozen instrument control
languages. But I do not think I want the functionality of these programs
transferred into Mathematica. On the other hand, I found the Mathematica
relieved some of the frustration I felt with the other programs, even if I
had to use a Macintosh to use it in the beginning. When version 2 of
Mathematica came, I obtained a license for PC.
  I am a physicist and not a full-time programmer, but have used computer
aid both for experiments and theory. In the evaluation of measurement data,
I found that "tagged" data in text files were very convenient: If I measured
a temperature, it should be stated in the log file not only the temperature
value, but also that the value represented a temperature and not a voltage.
In this way the measurement system became much more robust and flexible than
if I had used some fixed-format binary files with just the measurement
values. Maybe I have got my interest in typed data from that experience.
Measurement data also almost always are naturally structured into some kind
of "objects" in the form of data pairs or more complex structures (vectors,
matrices, etc.). If I want Mathematica to take care of such data, it must be
somewhat "object oriented" at least on the input side.
In the elasticity theory of liquid crystals there are a lot of symbolic
vector expressions (objects or functions?), and I looked for the best way to
represent them. A better support for indexed variables had made the task
easier, and also made it easier to create something that could be
transferred to other people. If the program becomes too messy, it will not
be possible for another person to penetrate the program.      
  But what really spawned my interest for undefined array elements was a
childish vision. I wanted to have a "universal solver" that was able to
solve many typical school homework exercises in a pedagogic way. You know,
one problem might be that you have two sides and an angle defined in a
triangle, and you should find the rest. In the next problem you have three
sides given, etc. There are surely several ways to do that, but I wanted to
do it in a way outlined in my triangle example in mg63184 (Dec 17, 2005).
Just in idle curiosity, but anyway maybe of interest at least to the
marketing department of Wolfram.
 
> >The functionality we
> > obtain by defining an array by g=Array[f,{n1,n2}] could be 
> built into  
> >Mathematica in a hidden way, in such a way that g[[1,2]] behaved as 
> >f[1,2]  in expressions. But it is not so now.
> 
> In an earlier post I redefined Part with two upvalues so it 
> worked fine for arrays or matrices, extending the 
> "unfinished" definition as you point out.
> 
> >None of these methods gives the effect
> > that g[[1,2]] is returned unevaluated if it is undefined, 
> as is done 
> >with an  undefined variable g
> 
> & did this with a symbol, 'undefined', which could return the 
> string "undefined" or anything you want. In any event you 
> could reset all the undefined terms through the variable of 
> that name, or selectively via f[i] in indexed arrays or 
> ReplacePart in matrices.
> 
> & others had various other suggestions. So what exactly is missing?

No it could not return "anything I want", since I stubbornly want g[[1,2]]
returned. I can just get anything else, but not this. That is exactly what
is missing. Especially I do not want the unique variable names
{{a$17,a$18},{a$19,a$20}} suggested by Andrzej. It is as simple as this: If
I enter x, and x is undefined, x is returned (not 0, undefined, y or x$527).
If I enter f[1,2], and f[1,2] is undefined, f[1,2] is returned. And I want
g[[1,2]] to behave in the same way. I think that that is in some way
logical.

My suggestion how to make an undefined indexed variable is not completely
taken out of the air. Enter the following:

   x := y; y := x;

Of course there is no protest from Mathematica. Then enter

   x

Mathematica protests:

   $IterationLimit::"itlim" : "Iteration limit of (4096) exceeded. More...

but it also politely returns 

   Hold[x]

which is similar to my suggestion for a undefined a[[1,2]]. Enter now 

   x =.; y =.; x := x; x

A sillier program would make a protest about iteration limit exceeded also
for these statements. Mathematica, however, knows how to handle this special
case, and returns just x. When the variable named x gets the value x, the
variable should be treated as undefined. The same mechanism works for the
function value f[1,2]. But if I enter the following 

   ax = {ax[[1]], ax[[2]], ax[[3]]}

then Mathematica does not even understand that it should stop execution. It
is the Mathematica Way, but it is not logical, since this case is not
included in the special treatment x=x or x:=x gets. If I put Hold or
HoldForm around each ax[[i]], I provide a mechanism that almost mimics the
behavior for x=x, and I can at the same time tell Mathematica that ax is a
list with three elements.

  
> Even if you are adapting Mathematica to your own 'desire' 
> rather than necessity, a package may be very helpful to all 
> those who feel the same way, and more generally in other 
> areas as well to help people transition from 'native' 
> languages to Mathematica. The other possibility is that it's 
> an overly complex workaround for personal preference (still 
> apparently worth it to you in that case, tho).
> 
> Kris
> 
> PS Yet another general way to do typing--we have now 
> accumulated a bunch--is by setting a flag in a "named 
> argument", as Maeder calls options. The functions are 
> built-in for initializing and changing them, and we need the 
> package FilterOptions to pass the options between functions, 
> which I see exists but haven't explored.

Yes, this can be very useful, especially if we want to have several
different properties for an object or function. It can be blue and symmetric
at the same time. 

Best regards

Ingolf Dahl
Sweden
http://web.telia.com/~u31815170/Mathematica/



  • Prev by Date: Re: Re: EUREKA Re: Types in Mathematica, a practical example
  • Next by Date: Re: Re: Types in Mathematica, a practical example
  • Previous by thread: Re: Re: EUREKA Re: Types in Mathematica, a practical example
  • Next by thread: Re: Re: Types in Mathematica, a practical example