Importance of Python

User avatar

arne_v
Master
Posts: 347
Joined: Fri Apr 17, 2020 7:31 pm
Reputation: 0
Location: Rhode Island, USA
Status: Offline
Contact:

Re: Importance of Python

Post by arne_v » Thu Jul 20, 2023 8:15 pm

neilrieck wrote:
Wed Jul 19, 2023 6:58 am
But here is a practical example: In 2012 I toyed with writing a "Diffie-Hellman Key Exchange" demo but then ran into library limitations of the AlphaServer I was on at the time (this is the point were most people would go off to write their own routines to support math larger than the maximum native size). Four years later I was learning python3 so went back to that demo and coded it with little difficulty.

Code: Select all

1) In BASIC, this statement "PRINT int(2^31)" fails with 32-bit signed integers (longword)
   (written for clarity; you should append % to each number)
2) In BASIC, this statement "PRINT int(2^63)" fails with 64-bit signed integers (quadword)
3) In Python, this statement "PRINT(2**9999)" instantly yields 37x80+50 characters.
   (now repeat by adding more nines)
 
Python is pretty nice but the ability to do big integers is not unique to Python.

Code: Select all

$ type big.py
print('Python:')
print(2**9999)
$ python big.py
Python:
997531558440379192441871081341792541911748415943096227426004474926471941511097331595998084201809729894966556471160456213577824567470
...
104201821088185195577531989450037142683609814045173898726666023418439793429011897610931456004037140977565897407881222414925923075485
2444013637360787344065797375204866057540249095227901708413474893570658031605343195755840887152396298354688
$ type big.php
<?php
echo 'PHP:' . "\r\n";
echo bcpow('2', '9999') . "\r\n";
?>
$ php big.php
PHP:
997531558440379192441871081341792541911748415943096227426004474926471941511097331595998084201809729894966556471160456213577824567470
...
104201821088185195577531989450037142683609814045173898726666023418439793429011897610931456004037140977565897407881222414925923075485
2444013637360787344065797375204866057540249095227901708413474893570658031605343195755840887152396298354688
$ type Big.java
import java.math.BigInteger;

public class Big {
    public static void main(String[] args) throws Exception {
        System.out.println("Java:");
        System.out.println(BigInteger.valueOf(2).pow(9999));
    }
}
$ javac Big.java
$ java "Big"
Java:
997531558440379192441871081341792541911748415943096227426004474926471941511097331595998084201809729894966556471160456213577824567470
...
104201821088185195577531989450037142683609814045173898726666023418439793429011897610931456004037140977565897407881222414925923075485
2444013637360787344065797375204866057540249095227901708413474893570658031605343195755840887152396298354688
$ type big.c
#include <stdio.h>

#include <gmp.h>

int main(int argc, char *argv[])
{
    mpz_t val;
    printf("C:\n");
    mpz_init(val);
    mpz_set_ui(val, 2);
    mpz_pow_ui(val, val, 9999);
    mpz_out_str(stdout, 10, val);
    mpz_clear(val);
    return 0;
}
$ cc /name=as_is /include=gmpdir /define="_GMP_H_HAVE_FILE" big
$ link big + sys$input/opt
libgmp/share
$
$ r big
C:
997531558440379192441871081341792541911748415943096227426004474926471941511097331595998084201809729894966556471160456213577824567470
...
104201821088185195577531989450037142683609814045173898726666023418439793429011897610931456004037140977565897407881222414925923075485
2444013637360787344065797375204866057540249095227901708413474893570658031605343195755840887152396298354688
$ type big.cpp
#include <iostream.h>

#include <integer.h>

int main()
{
    cout << "C++:" << endl;
    Integer val = 2;
    val = pow(val, 9999);
    cout << val << endl;
    return 0;
}
$ gxx big.cpp
$ gxxlink big
$ r big
C++:
997531558440379192441871081341792541911748415943096227426004474926471941511097331595998084201809729894966556471160456213577824567470
...
104201821088185195577531989450037142683609814045173898726666023418439793429011897610931456004037140977565897407881222414925923075485
2444013637360787344065797375204866057540249095227901708413474893570658031605343195755840887152396298354688
I have omitted some of the output lines.

Python, PHP and Java are builtin functionality.

C uses the widely known LIBGMP (it builds on VMS thanks to JoukJ).

C++ uses the old GNU Integer class. There are plenty of other C++ classes available with big integer functionality.
Arne
arne@vajhoej.dk
VMS user since 1986

User avatar

imiller
Master
Posts: 147
Joined: Fri Jun 28, 2019 8:45 am
Reputation: 0
Location: South Tyneside, UK
Status: Offline
Contact:

Re: Importance of Python

Post by imiller » Fri Jul 21, 2023 4:35 am

I've been dabbling with python on VMS doing some T4 analysis stuff. Seems to be handy for that. I hope that VSI expand the range of packages in their Python Wheels package,
Ian Miller
[ personal opinion only. usual disclaimers apply. Do not taunt happy fun ball ].

User avatar

martinv
Master
Posts: 104
Joined: Fri Jun 14, 2019 11:05 pm
Reputation: 0
Location: Goslar, Germany
Status: Offline
Contact:

Re: Importance of Python

Post by martinv » Fri Jul 21, 2023 7:37 am

I've been dabbling with python on VMS doing some T4 analysis stuff.
A bit off-topic, bur WRT T4: I'm importing my T4 data into an InfluxDB database (using a Python script) and vizualize it with Grafana.
Image

Edit: As I'm obviously to dumb to integrate an image into my post: please see here
Last edited by martinv on Fri Jul 21, 2023 7:40 am, edited 3 times in total.
There is something wrong with everything that is popular.
(Charles Fort)

User avatar

neilrieck
Contributor
Posts: 21
Joined: Tue Jan 10, 2023 10:41 am
Reputation: 0
Location: Waterloo, Ontario, Canada
Status: Offline
Contact:

Re: Importance of Python

Post by neilrieck » Fri Jul 21, 2023 9:17 am

You are correct. Languages like Python and Perl do large integers natively while other languages do it with optional libraries. Heck, OpenSSL (written in C) first appeared in the late 1990s when 32-bit computers were all the rage and yet this application could easily deal with key lengths several thousand of bits long with their own custom libraries. But teaching students how to program in C (or C++) can be problematic which is one of the reasons why Python has become so popular. But Python really shines when attending classes on "machine learning" or "deep learning". This began slowly back in 2006 when the Python community released NumPy (multidimensional arrays, etc), and 2007 when Google released Scikit-learn. Then in 2015, Google released TensorFlow and Keras. Not to be outdone, Facebook stepped in with PyTorch. Note that all this stuff can be had for free. But back to pure Python for a moment: Python yields the same floating point values on your laptop as it does on your OpenVMS or Linux server (I do not think I have ever seen this before).Then last summer I had to write a financial billing program in python which was my first exposure to the decimal data type (worked like a charm). One last point. In 2016 I met a British scientist who was doing active research at the LHC in Geneva. I asked him what language he used to analyze his data to which he replied "Fortran" because it has native support for complex math. I suggested he check out Python because it can support complex math by importing the cmath library.

User avatar

arne_v
Master
Posts: 347
Joined: Fri Apr 17, 2020 7:31 pm
Reputation: 0
Location: Rhode Island, USA
Status: Offline
Contact:

Re: Importance of Python

Post by arne_v » Fri Jul 21, 2023 11:36 am

Getting exact same FP results is a lot easier today than 40 years ago. Everybody (almost everyone) use IEEE FP so the results are usually the same on different platforms and with different languages. In some cases optimization and reordering of operation may result in slightly different result, but that should be the exception.

Python has become the dominant language in the numeric field (with the old competitor being R and the new competitor being Julia) that was once the domain of Fortran.

But it is worth noting that the developer writes Python code to express what the program should do. But usually (for the numeric stuff) there will be C, Fortran or Fortran auto-converted to C doing the actual number crunching.

That is similar to many other contexts. I don't think there are many VMS system managers that write their backup scripts in Fortran or C using callable backup routines. They write them in DCL. Way easier.
Arne
arne@vajhoej.dk
VMS user since 1986

User avatar

imiller
Master
Posts: 147
Joined: Fri Jun 28, 2019 8:45 am
Reputation: 0
Location: South Tyneside, UK
Status: Offline
Contact:

Re: Importance of Python

Post by imiller » Fri Jul 21, 2023 12:09 pm

martinv wrote:
Fri Jul 21, 2023 7:37 am
I've been dabbling with python on VMS doing some T4 analysis stuff.
A bit off-topic, bur WRT T4: I'm importing my T4 data into an InfluxDB database (using a Python script) and vizualize it with Grafana.
Image

Edit: As I'm obviously to dumb to integrate an image into my post: please see here
What do you gain by storing the T4 data in such a DB?
I'm doing graphs, linear trends, excel outputs by reading the T4 csv's from zip files and processing. I suppose using a Time Series DB could be more efficient. Ideally I would like all of this to run on VMS not on Windows but I'm not there yet.
Ian Miller
[ personal opinion only. usual disclaimers apply. Do not taunt happy fun ball ].

User avatar

neilrieck
Contributor
Posts: 21
Joined: Tue Jan 10, 2023 10:41 am
Reputation: 0
Location: Waterloo, Ontario, Canada
Status: Offline
Contact:

Re: Importance of Python

Post by neilrieck » Fri Jul 21, 2023 12:12 pm

Funny thing. For the past 20 years we've been running an employee safety server program written in DEC-BASIC interfacing with ISAM-RMS. Primary access was via Apache-CGI so our program contained numerous system calls (some just to retrieve shell variables). Secondary access was via cell phone messages. Anyway, a new (to our group) employee rewrote the whole thing in one afternoon using python and MariaDB. We old farts were instant converts.

User avatar

arne_v
Master
Posts: 347
Joined: Fri Apr 17, 2020 7:31 pm
Reputation: 0
Location: Rhode Island, USA
Status: Offline
Contact:

Re: Importance of Python

Post by arne_v » Sat Jul 22, 2023 11:05 am

neilrieck wrote:
Fri Jul 21, 2023 12:12 pm
Funny thing. For the past 20 years we've been running an employee safety server program written in DEC-BASIC interfacing with ISAM-RMS. Primary access was via Apache-CGI so our program contained numerous system calls (some just to retrieve shell variables). Secondary access was via cell phone messages. Anyway, a new (to our group) employee rewrote the whole thing in one afternoon using python and MariaDB. We old farts were instant converts.
The world progresses.

That a 90's language (Python) + 80's persistence technology (RDBMS) + recent web technology(whatever) is more efficient than a 70's language (DEC flavor Basic) + 60's persistence technology (ISAM) + 90's web technology (CGI) is not surprising.

And VMS Basic is not even bad. For this kind of stuff I consider VMS Basic and VMS Pascal the best among the VMS native languages.
Arne
arne@vajhoej.dk
VMS user since 1986

Post Reply