Post Reply 
Prime programming Python vs CAS / xCAS etc
11-16-2021, 06:56 PM
Post: #2
RE: Prime programming Python vs CAS / xCAS etc
(11-16-2021 11:51 AM)dougie Wrote:  Hi all,

I'm using my Prime now quite a while, even when only at 5% of its capabilities.

I just installed the 20210505 Software and was happy about the Python support, which immediately triggered the interest of using it.

However: I'm new to programming the Prime and in principle it doesn't matter which language I'm going to use, as long it is able to solve my tasks.

Only as an example: I would like CAS to perform a polynominal division using quot and rem.

I would like to enter the polynomic and the quotient using the INPUT function and store them in User Variables like e.g. P and Q for later use.

The results from 'quot' and 'rem' should also be stored in User Variables for later use.

I tried to do that in Python by studying a number of Examples, but the existing documentation is sparse. Therefore it might be easier using any other possible language, which is better documented?

Here's my work so far... I've no Idea now how to store and read User Variables from within a program and to call CAS functions.
In case there's a good documentation I could use, that would be also great. (then I don't have to bother you :-) )

Code:

#PYTHON name
# PYTHTEST
import math

def pintro():
  print ("Basic Python Test Program")
  polynom = input("Enter Polynom p: ")
  print ("(",polynom,")") 
  quotient = input("Enter Quotient q: ")
  print ("(",quotient,")") 
  return

def api():
  return 355/113

def pout():
  q1 = api()
  print ("pi = ", q1)

pintro()
pout()

#end 

EXPORT pythtest()
BEGIN
  PRINT;
  PYTHON(name);
END;

For the most part, Python is totally separate from Home and CAS. You can execute their functions by using exec("command") where command is the command you want to execute. This must be used sparingly if you don't want to bog down your program, however. exec is very wasteful of time. I hope that a future revision will include the time module which includes monotonic() rather than have to use exec("time") to time programs.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Prime programming Python vs CAS / xCAS etc - toml_12953 - 11-16-2021 06:56 PM



User(s) browsing this thread: 1 Guest(s)