[Edu-sig] using Python as a calculator

Edward Cherlin echerlin at gmail.com
Sun Apr 11 21:00:04 CEST 2010


On Sat, Apr 10, 2010 at 09:33, Christian Mascher
<christian.mascher at gmx.de> wrote:
> Edward Cherlin wrote:
>>
>> [sigh]
>>
>> Do math tables in a math array language.
>>
>> degrees =. i. 91  NB. 0..90
>>
>> radians =. degrees * o. % 180
>>
>> table =. |: degrees, 1 2 3 o./ radians
>
> Sorry, I don't know J (Kirby does), but this is exactly the reason I prefer
> Python. Readability counts (for me).

That's what they said to Fibonacci when he tried to explain why Arabic
numerals were better for math than Roman numerals. But Roman numerals
are better in readability and algorithmic complexity if you rarely do
anything but add and subtract, as merchants did before interest
payments became critical. Roman numerals are precisely equivalent to
abacus notation. It is odd that the distinction between math/science
programming and business programming is nearly a thousand years old,
but there it is.

In fact, APL is the only computer language that uses the same symbols,
+ - × ÷, as first grade arithmetic texts. (Presumably, with the
acceptance of Unicode, this will change someday.) Back in the 1960s,
Ken Iverson successfully taught teachers how to teach children
arithmetic on IBM Selectric terminals connected to a loaned 360
mainframe. An addition table up to 10 is simply

numbers =. i. 11  NB. 0..10

numbers +/ numbers

or, with a bit more complexity or a bit more simplicity, depending on
your viewpoint,

+/~ i. 11

where f~ x is x f x .

> For creating a table, most people would
> probably use a spreadsheet anyway, but as I happen to know Python, I use it
> for such tasks from time to time. I can even remember the syntax without
> having used Python for months. Don't think that would be the case with J.

This turns out not to be the case. The complete syntax table for J
consists of 12 lines. You are talking glibly about a topic on which
you have no information.

> Not very inclined to learn that.

Obviously.

>> where
>>
>> =. is assignment
>> i. creates a list of consecutive numbers starting at 0.
>
> Who on earth would think of that without a manual?

And without a lesson? Do you believe that Python syntax is intuitive,
and can be guessed without a manual or lessons? In i., the i stands
for index. It is easy to learn, and reasonably mnemonic.

>> NB. is the comment marker o. x is pi times x
>
> Why not pi?

Why?

>> % x is reciprocal of x, so o. % 180 is pi/180
>
> Don't think that is very useful.

These objections are trivial and uninformed. You aren't a
mathematician, you don't like math and math notation, so there is
nothing more to say, except please stand out of the way of people who
can benefit from it and want it.

>> |: is transpose
>
> Another very special symbol.
>>
>> , appends an array to another. It turns a list into a table in order
>> to match dimensions.
>
> Lost you there...

You can append a table to a table if they have a dimension in common.
You can't append a table to a list unless the list is turned into a
one-row table.

>> 1 2 3 o. x gives sine, cosine, tangent of x
>
> Why don't they use sin(), cos(), tan() like the rest of the mathematical
> world?
>>
>> / creates a table with the given function (o.) applied to two list
>> arguments
>>
>> The result is a 91 row, 4 column table of angles and trig function values.
>>
> Impressive ;-))
>>
>> I can easily give you a short sequence of lessons leading to this
>> level, introducing some other arithmetic, transcendental, and
>> array-handling functions along the way, and a little more about
>> operating on functions to define new functions.
>
> Python is much nearer to standard Math-notation, that is a good thing.

LOL. Math notation is what mathematicians use, not schoolchildren.
They are constantly inventing more of it. What you call math notation
is known to mathematicians as "arithmetic".

There is no standard math notation.

Polish: + 1 2
Infix: 1 + 2
Reverse Polish: 1 2 +

Reverse Polish is one of the two standard calculator input systems,
the one used by engineers, from HP. Polish is standard in LISP and
combinatory logic. Neither requires parentheses. Infix notation, as on
TI and related calculators, requires parentheses, and is much more
difficult for complex expressions.

> I
> like to learn new languages - up to a point. I don't see the added value of
> J in this case.

I like to learn languages a lot more than you, then. I don't consider
anybody educated in computing without knowing something of languages
from the LISP, APL, FORTH, OOP, and scalar language families.

> Just my 2c
>
> Christian
>
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>



-- 
Edward Mokurai (默雷/धर्ममेघशब्दगर्ज/دھرممیگھشبدگر ج) Cherlin
Silent Thunder is my name, and Children are my nation.
The Cosmos is my dwelling place, the Truth my destination.
http://www.earthtreasury.org/


More information about the Edu-sig mailing list