Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I show the type of something in maxima?

Tags:

types

maxima

How do I show the type of an object in maxima?

And why do I keep getting a red box for a simple question? (I had to append that to my type question or the filter wouldn't allow it.)

like image 910
cybervigilante Avatar asked Dec 05 '25 09:12

cybervigilante


1 Answers

Maxima types have a representation in lisp and you can get their types, using lisp. as far as I know there isn't a function like type-of (in cl) written in maxima.

the types in maxima are defined in the manual:

http://maxima.sourceforge.net/docs/manual/maxima_5.html#SEC11

and there exists predicate functions for getting the type of a variable

for example:

(%i8) a : 3;
(%o8)                                  3

(%i9) numberp(a);
(%o9)                                true

But you can acces to lisp for this variables, even inspect it using :lisp

(%i10) :lisp $a

3
(%i10) :lisp (type-of $a)

(INTEGER 0 4611686018427387903)
(%i10) :lisp (describe $a)

3
  [fixnum]

Or going directly to lisp console

(%i10) to_lisp();

Type (to-maxima) to restart, ($quit) to quit Maxima.

MAXIMA> $a

3
MAXIMA> (inspect $a)

The object is an ATOM:
  3
> ^D
MAXIMA> (to-maxima)
Returning to Maxima
(%o10)                               true

If you take the manual there is a desciption of an implementation of typeof

http://maxima.sourceforge.net/docs/manual/maxima_11.html#SEC57

it works as follow:

(%i11) typeof (expr) := block ([q],
        if numberp (expr)
        then return ('algebraic),
        if not atom (expr)
        then return (maplist ('typeof, expr)),
        q: get (expr, 'type),
        if q=false
        then errcatch (error(expr,"is not numeric.")) else q)$

(%i12) typeof(a);
(%o12)                             algebraic

let's take a loox for expressions:

(%i14) put (%e, 'transcendental, 'type);
(%o14)                          transcendental
(%i15) put (%pi, 'transcendental, 'type)$
(%i17) put (%i, 'algebraic, 'type)$
(%i18) typeof (2*%e + x*%pi);

x is not numeric.
(%o18)        [[transcendental, []], [algebraic, transcendental]]

and seeing it with lisp:

(%i20) expre : 2*%e + x*%pi;
(%o20)                           %pi x + 2 %e
(%i21) typeof(expre)
;

x is not numeric.
(%o21)        [[transcendental, []], [algebraic, transcendental]]
(%i22) :lisp $expre

((MPLUS SIMP) ((MTIMES SIMP) 2 $%E) ((MTIMES SIMP) $%PI $X))
(%i22) :lisp (type-of $expre)

CONS
(%i22) :lisp (describe $expre)

((MPLUS . #1=(SIMP)) (#2=(MTIMES . #1#) 2 $%E) (#2# $%PI $X))
  [list]
like image 104
anquegi Avatar answered Dec 09 '25 15:12

anquegi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!