back to list

Python again (programming language syntax)

🔗Aaron K. Johnson <akjmicro@...>

8/29/2004 8:30:38 AM

On Sunday 29 August 2004 12:50 am, Gene Ward Smith wrote:
> It didn't seem that perspicuous to me, but you quickly get used to
> wierd syntax--even in the case of APL or Lisp, but maybe not Forth.
> I've not tried to learn it, because I don't know why people like it
> and what advatages, if any, I'd get by doing so. Mostly I just use
> Maple, which is fine unless I need speed. It gives me a nifty toolbox
> of built-in functions I can use for both theory and composing.

Let's finish this thread on metatuning...I've cc'ed this to there as well.

For now: for me, having to 'get used to' a new syntax is not as desirable as
just using one that makes sense right away. Like I said, when programming, I
don't want to fight the syntax, I want to get a job done. Python is about as
ideal as you could get, IMO.

Maple I guess *is* fine for you Gene, but Python would do those things, too,
if you developed a small library of tuning-realted functions as I have. Plus,
it's nice to know you are not stuck in a spreadsheet-paradigm, but are using
a general programming language (at least for me--maybe its fine for you ;) )

Best,
Aaron Krister Johnson
http://www.dividebypi.com
http://www.akjmusic.com

🔗Graham Breed <graham@...>

8/29/2004 9:52:24 AM

Aaron K. Johnson wrote:

> Maple I guess *is* fine for you Gene, but Python would do those things, too, > if you developed a small library of tuning-realted functions as I have. Plus, > it's nice to know you are not stuck in a spreadsheet-paradigm, but are using > a general programming language (at least for me--maybe its fine for you ;) )

I don't see Maple has a "spreadsheet-paradigm". It is clunky as a programming language. The barrier between it and Python is the huge library of mathematical operations, before you can even start on the mathematics. There are efforts to provide such libraries for Python, but I don't know how far they're getting. You can also get Python to talk to Matlab.

I don't know how much infrastructure we need for Gene's music theory. I have wedge products built into my temperament finding library. And attempt at LLL reduction is here by the looks of it:

http://x31eq.com/temper/LLL.py

I think it works, but doesn't give identical results to Maple. Otherwise, optimization algorithms keep being used for things like TOP, and I suppose may exist in libraries.

Graham

🔗Gene Ward Smith <gwsmith@...>

8/29/2004 11:01:08 AM

--- In metatuning@yahoogroups.com, "Aaron K. Johnson" <akjmicro@c...>
wrote:

> Maple I guess *is* fine for you Gene, but Python would do those
things, too,
> if you developed a small library of tuning-realted functions as I have.

Nope. You'd need a huge library of math functions also.

Plus,
> it's nice to know you are not stuck in a spreadsheet-paradigm, but
are using
> a general programming language (at least for me--maybe its fine for
you ;) )

Maple is not a spreadsheet. It is, in fact, classed as a high-level
proramming language among other things, though of course it is hardly
competition for "real" languages in what they do best. It is not
fancy, a feature I like. It isn't oo. It does not fuss very much about
data types. It has a syntax which looks about as much like standard
math as possible--more so than Mathematica, and certainly more so than
Python. Information is easily entered in via ascii files with a
straightforward syntax. It also has some features other programming
languages might try--it has sets as well as lists, and I've found sets
to be an incredibly useful datatype when programming.

But Maple is dead easy. Really, really easy. And easy is good. It also
has a library of functions which I would hate to have to program for
myself. How much of that is availble for Python, I wonder?

🔗Aaron K. Johnson <akjmicro@...>

8/29/2004 11:32:56 AM

On Sunday 29 August 2004 01:01 pm, Gene Ward Smith wrote:
> --- In metatuning@yahoogroups.com, "Aaron K. Johnson" <akjmicro@c...>
>
> wrote:
> > Maple I guess *is* fine for you Gene, but Python would do those
>
> things, too,
>
> > if you developed a small library of tuning-realted functions as I have.
>
> Nope. You'd need a huge library of math functions also.

The libraries available to Python are listed at www.python.org, and they have
a math library, plus 3rd party developers are constantly contributing things.
But you sound happy with Maple. I wasn't trying to convert you anyway ;)

> Plus,
>
> > it's nice to know you are not stuck in a spreadsheet-paradigm, but
>
> are using
>
> > a general programming language (at least for me--maybe its fine for
>
> you ;) )
>
> Maple is not a spreadsheet. It is, in fact, classed as a high-level
> proramming language among other things, though of course it is hardly
> competition for "real" languages in what they do best. It is not
> fancy, a feature I like. It isn't oo. It does not fuss very much about
> data types. It has a syntax which looks about as much like standard
> math as possible--more so than Mathematica, and certainly more so than
> Python. Information is easily entered in via ascii files with a
> straightforward syntax. It also has some features other programming
> languages might try--it has sets as well as lists, and I've found sets
> to be an incredibly useful datatype when programming.
>
> But Maple is dead easy. Really, really easy. And easy is good.

I'd like to check it out!

Aaron Krister Johnson
http://www.dividebypi.com
http://www.akjmusic.com

🔗Gene Ward Smith <gwsmith@...>

8/29/2004 1:02:51 PM

--- In metatuning@yahoogroups.com, "Aaron K. Johnson" <akjmicro@c...>
wrote:

> I'd like to check it out!

I forgot to add that it is frickin' expensive. :(

🔗Graham Breed <graham@...>

8/29/2004 2:15:52 PM

Gene Ward Smith wrote:

> Maple is not a spreadsheet. It is, in fact, classed as a high-level
> proramming language among other things, though of course it is hardly
> competition for "real" languages in what they do best. It is not
> fancy, a feature I like. It isn't oo. It does not fuss very much about
> data types. It has a syntax which looks about as much like standard
> math as possible--more so than Mathematica, and certainly more so than
> Python. Information is easily entered in via ascii files with a
> straightforward syntax. It also has some features other programming
> languages might try--it has sets as well as lists, and I've found sets
> to be an incredibly useful datatype when programming.

Maple syntax is like standard math? I hadn't thought of that before, and I don't see why it is the case. It has an easy way of treating formulae as first class objects, but otherwise it looks like a standard block-imperative language. What differences with Python did you have in mind?

Now Haskell, that's like standard math.

If Maple somehow fails to be oo, that's a shame, because it means it can't handle group theory correctly.

C++, Java and Python can also use ASCII files, and sets. Does Maple have any useful features they lack?

> But Maple is dead easy. Really, really easy. And easy is good. It also
> has a library of functions which I would hate to have to program for
> myself. How much of that is availble for Python, I wonder?

you can always have a look:

http://py.vaults.ca/parnassus/apyllo.py/684222876

http://www.gnu.org/software/gsl/manual/gsl-ref_toc.html

http://starship.python.net/~hinsen/ScientificPython/

http://www.scipy.org/documentation/

I'd be interested to know what is missing for music theory. The linear algebra support seems to have improved since I last looked.

Graham

🔗Gene Ward Smith <gwsmith@...>

8/29/2004 3:00:28 PM

--- In metatuning@yahoogroups.com, Graham Breed <graham@m...> wrote:

> Maple syntax is like standard math? I hadn't thought of that before,
> and I don't see why it is the case. It has an easy way of treating
> formulae as first class objects, but otherwise it looks like a standard
> block-imperative language.

It *is* a standard imperative language with definable functions. What
I meant is that it doesn't have a lot of idiolectic syntax all its
own. It is written in C and uses C syntax for writing to files, but
doesn't have any special C stuff such as i++ or the way C uses braces.
A typical Maple idea is to use braces to mean sets, just as in
standard math terminology; this is generally how it proceeds. If you
want the sine of x, you write sin(x), if you want the sin of 2.3, you
write sin(2.3), if you want the sin of pi, you write sin(Pi). If you
want the square of x, you write x^2. Statements will be immediately
interpreted and evaluated after you've finished writing them (and
Maple knows to wait until you have), but you can also write a program
as a special type of assignment. If you want to write 2/3, you write
2/3. If you want to write a loop, you write "for i from 1 to 3 do" or
"while j<7 do" or something of that sort. An assignment is ":=", a
statement of equality "=".

You don't declare data types, construct classes, allocate space, worry
about how big your integers are or whether or not they are unsigned,
or do anything very nerdy. The result is that you almost know how to
program in Maple already without being told; it is dead easy.

What differences with Python did you have in
> mind?

Python code requires you to learn Python to make any sense of, the
learning curve for Maple is much less. Plus, of course, it has a lot
of stuff built-in.

> Now Haskell, that's like standard math.

Haskell isn't even imperative, is it? It may be like math but I doubt
it would be very intuitive.

> If Maple somehow fails to be oo, that's a shame, because it means it
> can't handle group theory correctly.

It has a built-in group datatype and a collection of group functions,
but if you seriously want to do group theory I suggest downloading and
compiling GAP (which is free.)

> C++, Java and Python can also use ASCII files, and sets. Does Maple
> have any useful features they lack?

Tons, obviously, but this is apples and oranges.

🔗Aaron K. Johnson <akjmicro@...>

8/29/2004 9:55:06 PM

On Sunday 29 August 2004 05:00 pm, Gene Ward Smith wrote:
> --- In metatuning@yahoogroups.com, Graham Breed <graham@m...> wrote:
> > Maple syntax is like standard math? I hadn't thought of that before,
> > and I don't see why it is the case. It has an easy way of treating
> > formulae as first class objects, but otherwise it looks like a standard
> > block-imperative language.
>
> It *is* a standard imperative language with definable functions. What
> I meant is that it doesn't have a lot of idiolectic syntax all its
> own. It is written in C and uses C syntax for writing to files, but
> doesn't have any special C stuff such as i++ or the way C uses braces.
> A typical Maple idea is to use braces to mean sets, just as in
> standard math terminology; this is generally how it proceeds. If you
> want the sine of x, you write sin(x), if you want the sin of 2.3, you
> write sin(2.3), if you want the sin of pi, you write sin(Pi). If you
> want the square of x, you write x^2. Statements will be immediately
> interpreted and evaluated after you've finished writing them (and
> Maple knows to wait until you have), but you can also write a program
> as a special type of assignment. If you want to write 2/3, you write
> 2/3. If you want to write a loop, you write "for i from 1 to 3 do" or
> "while j<7 do" or something of that sort. An assignment is ":=", a
> statement of equality "=".
>
> You don't declare data types, construct classes, allocate space, worry
> about how big your integers are or whether or not they are unsigned,
> or do anything very nerdy. The result is that you almost know how to
> program in Maple already without being told; it is dead easy.

All these things happen the same way in Python, which make me think you aren't
familiar with Python at all. The difference is that Python doesn't have a
rational data type built in, and Pi has to be defined (but I think there are
3rd party modules that handle both features)

Aaron Krister Johnson
http://www.dividebypi.com
http://www.akjmusic.com

🔗Graham Breed <graham@...>

8/30/2004 2:07:11 AM

Aaron K. Johnson wrote:

> All these things happen the same way in Python, which make me think you aren't > familiar with Python at all. The difference is that Python doesn't have a > rational data type built in, and Pi has to be defined (but I think there are > 3rd party modules that handle both features)

The math library includes pi (along with sin, etc.). There's a PEP for adding a rational type, which doesn't seem to be getting anywhere. A third party module is at:

http://www.spiritone.com/~english/code/fraction.html

Graham

🔗Graham Breed <graham@...>

8/30/2004 3:30:05 AM

Gene Ward Smith wrote:

> It *is* a standard imperative language with definable functions. What
> I meant is that it doesn't have a lot of idiolectic syntax all its
> own. It is written in C and uses C syntax for writing to files, but
> doesn't have any special C stuff such as i++ or the way C uses braces.
> A typical Maple idea is to use braces to mean sets, just as in
> standard math terminology; this is generally how it proceeds. If you
> want the sine of x, you write sin(x), if you want the sin of 2.3, you
> write sin(2.3), if you want the sin of pi, you write sin(Pi). If you
> want the square of x, you write x^2. Statements will be immediately
> interpreted and evaluated after you've finished writing them (and
> Maple knows to wait until you have), but you can also write a program
> as a special type of assignment. If you want to write 2/3, you write
> 2/3. If you want to write a loop, you write "for i from 1 to 3 do" or
> "while j<7 do" or something of that sort. An assignment is ":=", a
> statement of equality "=". So "like standard math" means "doesn't have a lot of idiolectic syntax all it's own". That's a bizarre definition. Not only is standard math full of idiolects, but how can a language "have" an idiolect? It looks as if "like standard math" means "meets with the approval of Gene Ward Smith".

Maple follows Pascal rather than C. Neither Maple nor C has special syntax for dealing with files. I'm not sure what you mean there.

You make Maple sound more mundane than it is. Statements may be evaluated immediately (probably this follows from the definitions of "statement" and "evaluation") but expressions use a form of lazy evaluation. This is how a formula can be used as input to a function, and "=" used in a declarative manner. Hence it works well as a domain specific language for symbolic algebra. There may be general purpose languages that can do the same, but not Pascal, C, C++, Java or Python. You should really make a bigger point of this.

> You don't declare data types, construct classes, allocate space, worry
> about how big your integers are or whether or not they are unsigned,
> or do anything very nerdy. The result is that you almost know how to
> program in Maple already without being told; it is dead easy.

You construct classes using the assemble() function. If I really didn't have to worry about the size of integers, that would be great. I also expect it would be widely reported as it would break many forms of strong encryption. Maple V, at any rate, doesn't seem to be any cleverer than Python in his regard.

You certainly don't know how to program without being told. You must be assuming it's simpler than it is because you've forgotten how long it took to learn. Of course, it's that bit easier if you already know a Pascal-like language.

> Python code requires you to learn Python to make any sense of, the
> learning curve for Maple is much less. Plus, of course, it has a lot
> of stuff built-in. Well, of course Python requires you to learn Python. Like Maple requires you to learn Maple. Where do you get this idea about the learning curve?

> Haskell isn't even imperative, is it? It may be like math but I doubt
> it would be very intuitive.

No, Haskell is declarative which is what makes it like mathematical notation. It will be less intuitive if you only know imperative languages. I don't think it's particularly difficult to learn in and of itself. I didn't get that far myself, don't see the point, but it is like math.

> It has a built-in group datatype and a collection of group functions,
> but if you seriously want to do group theory I suggest downloading and
> compiling GAP (which is free.)

I was only saying that if it can support group theory it must be object oriented. I can't actually work out how to do arithmetic with group elements. But if you can, and work with infinite groups, and subgroups and homomorphisms, you have all the principles of object oriented programming. Except for data hiding, but Python doesn't have that either. And they may not be of general use, but that's hardly a good thing.

>>C++, Java and Python can also use ASCII files, and sets. Does Maple >>have any useful features they lack?
> > Tons, obviously, but this is apples and oranges.

You said before "It also has some features other programming
languages might try". That's what I was querying. If they'll work in other languages, it can't be apples and oranges at all.

Graham

🔗Gene Ward Smith <gwsmith@...>

8/30/2004 4:58:40 PM

--- In metatuning@yahoogroups.com, Graham Breed <graham@m...> wrote:

> So "like standard math" means "doesn't have a lot of idiolectic syntax
> all it's own". That's a bizarre definition.

Why?

Not only is standard math
> full of idiolects, but how can a language "have" an idiolect?

By inventing its own special, goofy-looking syntax. Which programming
languages do all the time, and even Mathematica does. Macsyma and
Maple followed a path of trying to minimize that.

It looks
> as if "like standard math" means "meets with the approval of Gene Ward
> Smith".

No, I really do mean Maple looks more like standard math than either C
or Pascal, for instance.

> You construct classes using the assemble() function.

That's in the hackware package, which if you look at the code people
actually produce is very seldom used outside of Waterloo.

If I really didn't
> have to worry about the size of integers, that would be great.

You don't unless you want to use really, really big integers. I stuck
in, for old times stake, the Amdahl 6 prime (391581*2^216193-1) and
Maple simply shrugged and displayed all 65086 digits (a number I got
by asking Maple for the log base 10.) That's enough digits for most
people. Asking Maple if it is a prime is indeed a bad idea, but only
because it really will try to find the answer (I checked.)

I also
> expect it would be widely reported as it would break many forms of
> strong encryption.

???

Maple V, at any rate, doesn't seem to be any
> cleverer than Python in his regard.

How big are the integers Python can tackle? And you've told us it
cannot handle rational numbers.

> You certainly don't know how to program without being told. You
must be
> assuming it's simpler than it is because you've forgotten how long it
> took to learn. Of course, it's that bit easier if you already know a
> Pascal-like language.

It's not a Pascal-type at all; this is a very misleading comparison.
It *is* a lot like Macsyma, which with I was already familiar.

🔗Graham Breed <graham@...>

8/31/2004 7:09:49 AM

Me:
>>So "like standard math" means "doesn't have a lot of idiolectic syntax >>all it's own". That's a bizarre definition.

Gene:
> Why?

Firstly, because it's oxymoronic. An idiolect isn't part of a language by definition. Secondly, because standard math has a large syntax entirely its own, and allows for idiolects (although I suppose they aren't "standard").

There are programming languages that support idiolectic syntax. Lisp is one. Thats why Macsyma is able to run on top of it.

> By inventing its own special, goofy-looking syntax. Which programming
> languages do all the time, and even Mathematica does. Macsyma and
> Maple followed a path of trying to minimize that.

Yes, languages tend to have their own syntax. That's one of the things that makes them languages. If you don't need new syntax, it's a clue that you should be writing libraries for an existing language.

> No, I really do mean Maple looks more like standard math than either C
> or Pascal, for instance.

You originally said the *syntax* of Maple was more like standard math than Python's. Which I found surprising. Instead of backing it up, you've been entertaining us with banalities.

> You don't unless you want to use really, really big integers. I stuck
> in, for old times stake, the Amdahl 6 prime (391581*2^216193-1) and
> Maple simply shrugged and displayed all 65086 digits (a number I got
> by asking Maple for the log base 10.) That's enough digits for most
> people. Asking Maple if it is a prime is indeed a bad idea, but only
> because it really will try to find the answer (I checked.)

Yes, you don't worry about how big your integers are until they get too big.

You should have used a more direct way of counting. Either you've found a bug in Maple (unlikely) or you just demonstrated you don't understand logarithms.

> How big are the integers Python can tackle? And you've told us it
> cannot handle rational numbers.

I don't know. If 391581*2^216193-1 really has 65086 digits, it must be going wrong somewhere because it throws in an extra one. It gets very slow when you get to millions of decimal digits.

I most certainly did not say that Python couldn't handle rational numbers. The only time I remember talking about rational numbers I actually provided a link to a library that supports them. Here's another one:

http://x31eq.com/temper/rational.py

which isn't as good, but does appear to work. How, after writing a library for Python to handle rational numbers, could I have been struck by such an attack of imbecility as to suggest that Python couldn't handle rational numbers?

It is, BTW, used by the LLL function that you still haven't reviewed:

http://x31eq.com/temper/LLL.py

Graham

🔗Gene Ward Smith <gwsmith@...>

8/31/2004 1:40:31 PM

--- In metatuning@yahoogroups.com, Graham Breed <graham@m...> wrote:

> Firstly, because it's oxymoronic. An idiolect isn't part of a language
> by definition.

Did you really fail to understand my meaning? I meant things that are
specific to that language. For instance, in Maple, you can hardly be
expected to know off the bat that you write a function by making an
assignment "func := proc(x)"; that's what I'd mean by an ideolectic
feature.

Even oddball things which are not specific to that language are going
to be harder to learn if you don't know some other language which uses
them. If you see something like "+=" in Python, it helps to know C,
because this isn't any kind of standard terminology.

Pascal, and in fact the whole Algol language family, deliberately
tried for code which was easy to read, so that you might not even need
to know Pascal in order to understand it--sort of jacked-up
pseudocode. Maple is like Pascal in the sense of looking like this
more or less standard pseudocode. Unlike Pascal, it is interpreted,
and not fanatical about datatyping. It is by no means intended to
prevent you from writing sloppy code, but it isn't a good language to
write obfuscated code.

> Yes, you don't worry about how big your integers are until they get
too big.

Obviously if any computation, including inputting an integer, is too
big for your machine to handle you are in trouble. Major duh. The
question is whether some size limitation is built into the integer
data type itself. Very often it is. With some languages it isn't.

> You should have used a more direct way of counting. Either you've
found
> a bug in Maple (unlikely) or you just demonstrated you don't understand
> logarithms.

Sorry I didn't round up for you. If I had known someone gave a rat's
ass or would have been checking I would have been more careful.

> I most certainly did not say that Python couldn't handle rational
> numbers. The only time I remember talking about rational numbers I
> actually provided a link to a library that supports them. Here's
> another one:
>
> http://x31eq.com/temper/rational.py

If you need a library, then they are not a datatype built into Python
already. Python, therefore, cannot "handle them" in the sense that it
doesn't know about them from the getgo. Using your definition, C can
handle rational numbers. How does saying that help us?

Maple can "handle" real numbers (with an assignable precision),
complex numbers, rational numbers, integers, and (if you know how to
define them) algebraic numbers. All the arithmetic works with standard
infix notation. It "handles" the rational function field over any of
these in the same way. This is all there from the start. It can also
in some sense handle, for instance, padic numbers, but this works a
little differently--the padic package has to be loaded in, and you
need to know how the padic package expresses padic numbers. Knowing
how to define and multiply matrices requires you to know the special
syntax for that. Both of these seem to me to be a little different
than that original set of things it "handles".

Anyway, clearly there are different sense one can attach to "handle".

> http://x31eq.com/temper/LLL.py

What do you want me to do about that? Give it a test run?

🔗Graham Breed <graham@...>

9/1/2004 1:35:32 AM

Gene Ward Smith wrote:

>>http://x31eq.com/temper/LLL.py
> > What do you want me to do about that? Give it a test run?

Yes, please. And check if the code looks right. I notice there's a comment where I say I'm not doing what I think the book says, because that doesn't work.

Graham