1

Texas Instruments recently added direct python programming to their TI Nspire CX II models.

The calculator's built-in functions already consists of a list of very powerful math APIs. For example, can you invoke in python the isPrime() built-in function?

I am aware, this function can easily be re-created as a python module in NSpire. But there are more built-ins functions aside from this. Is there a way for Nspire's python to invoke these built-ins?

MattDMo
  • 100,794
  • 21
  • 241
  • 231
daparic
  • 3,794
  • 2
  • 36
  • 38

2 Answers2

0

Use eval:

Module: Built-in
Syntax: eval(x)
Description: Returns the evaluation of the expression x.
Example:
>>>a=7
>>>eval(“a+9”)
16
>>>eval(‘a+10’)
17

https://education.ti.com/html/webhelp/EG_TI84PlusCE-T/ES/content/eg_pythonappprog/m_pyref/m_e.HTML

Nope: This doesn't work. See comments.

soegaard
  • 30,661
  • 4
  • 57
  • 106
  • In my TI Nspire CX CAS II, in python shell I tried, `eval("isPrime(69)")` , and it gave `name 'isPrime' isn't defined` – daparic Nov 10 '20 at 11:09
  • Sorry - I assumed that the Python integration worked the same as the Lua one. Turns out that `eval` in NSpire Python calls Python's `eval` not the NSpire one. Looking at the modules available in NSpire Python, I can't see anything usable. – soegaard Nov 10 '20 at 11:21
  • It's kind of a crippled python without access to these built-ins. – daparic Nov 10 '20 at 16:31
  • I agree! As far as I know, it is also impossible to implement a new command in Lua (/Python) and then use it from a Notes-window. – soegaard Nov 10 '20 at 16:32
  • Take a look at my library here, it helps with that using undocumented functions in the ti_system module: https://github.com/TI-Planet/eval_expr – Adriweb Aug 24 '21 at 17:21
  • @Adriweb This looks promising. How did you find out that `ti_system` contains `writeST` and `readST`? And do `ti_system` contain other undocumented functions? – soegaard Aug 24 '21 at 17:29
  • 1
    @sorgaard you can execute the `help` and `dir` command on modules to know what they contain, that's how I found it, then tried things until it worked :) – Adriweb Aug 25 '21 at 20:49
0

After installing Ndless and khicas into my two calculators TI Nspire CX CAS II and TI Nspire CX CAS, in the khicas documentation describes something like:

Unlike adaptations of Micro-Python by calculator manufacturers (including Casio), the Python syntax in Xcas is fully integrated. You can therefore use all Xcas commands and data types in your programs. This corresponds approximatively to importing Python modules math, cmath, random, scipy, numpy, turtle, giacpy. There is also a small pixelised graphic commands set (set_pixel(x,y,c), set_pixel() to synchronize display, clearscreen(), draw_line(x1,y1,x2,y2,c), draw_polygon([[x1,y1],[x2,y2],...],c), draw_rectangle(x,y,w,h,c), draw_circle(x,y,r,c), the color+width+filled c parameter is optional, draw_arc(x,y,rx,ry,t1,t2,c) draws an ellipsis arc). And you can somewhat replace matplotlib with graphic commands of χ CAS (point, line, segment, circle, barplot, histogram and all ...plot... commands). Plus you have natural access to data types like rationnals or expressions, and you can run CAS commands on them. The complete list of commands available on the calculator is given in appendix. For documentation on commands not listed in the catalog categories, please refer to Xcas documentation.

At present for TI Nspire CX CAS II, its python environment could not call the nspire's built-in math functions.

daparic
  • 3,794
  • 2
  • 36
  • 38