when will be ready a program editor for the CAS MODE ?
01-26-2014, 11:06 PM (This post was last modified: 01-27-2014 02:01 PM by compsystems.)
Post: #1
 compsystems Senior Member Posts: 1,198 Joined: Dec 2013
when will be ready a program editor for the CAS MODE ?
La convolución de 2 vectores es equivalente a la multiplicación de 2 polinomios de una variable (es decir que el vector de coeficientes del producto de 2 polinomios es igual a la convolución de los vectores de coeficientes de los polinomios).
Nota:los coeficientes pueden ser números reales o complejos.

Example:

CAS MODE

step to step on CAS mode, simplify maximum and put entry line

v1:= [1,2,3,4];
v2:= [5,6,7,8];
p1:=poly2symb(v1); // x^3+2*x²+3*x+4,
p2:=poly2symb(v2); // 5*x^3+6*x²+7*x+8
c:=symb2poly(simplify(p1*p2)); // poly1[5,16,34,60,61,52,32] // OK

but on a program =(

Code:
//convolution Version1: con la multiplicación de polinomios  export  convolution1(v1,v2) begin    local p1,p2,c;    p1:=poly2symb(v1);    p2:=poly2symb(v2);    c:=symb2poly(simplify(p1*p2));   return(c);  end;

convolution1([1,2,3,4],[5,6,7,8]); [enter] return [32] =( BUG?

the problem occurs because the program runs on HOME MODE

one solution

change the header export convolution1(v1,v2) to convolution1(v1,v2):= and store on input/entry line, edit is too complicated in large programs, I have been waiting two months for a program editor for the CAS

Code:
[code]//convolution Version1: con la multiplicación de polinomios  convolution1(v1,v2):= begin    local p1,p2,c;    p1:=poly2symb(v1);    p2:=poly2symb(v2);    c:=symb2poly(simplify(p1*p2));   return(c);  end;

Now
convolution1([1,2,3,4],[5,6,7,8]); [enter] return poly1[5,16,34,60,61,52,32] // OK

HP-Prime TEAM when will be ready a program editor for the CAS ?

Thanks
01-26-2014, 11:40 PM
Post: #2
 eried Senior Member Posts: 737 Joined: Dec 2013
RE: when will be ready a program editor for the CAS MODE ?
Works OK in the emulator, for Home and CAS: http://screencast.com/t/6R9u6DQdSAl2

My website: erwin.ried.cl
01-27-2014, 12:50 PM
Post: #3
 compsystems Senior Member Posts: 1,198 Joined: Dec 2013
RE: when will be ready a program editor for the CAS MODE ?
Hello ... in spanish =(

Erwin observando el video, tienes tu hp-prime en la APP Advanced Graphing, y ahí si funciona, muy estraño, pero si cambias a [APP]/function se presenta un BUG, por que sucede esto? y por favor me confirmas si en tu calculadora arroja un vector de 1x1 con valor de 32

Gracias
01-27-2014, 02:25 PM
Post: #4
 eried Senior Member Posts: 737 Joined: Dec 2013
RE: when will be ready a program editor for the CAS MODE ?
Tienes razón, pero no se si es un bug. Ejecuta esto:

Code:
export  convolution1(v1,v2) begin    local p1,p2,c,xx:="xx";    p1:=poly2symb(v1,xx);    p2:=poly2symb(v2,xx);    c:=symb2poly(simplify(p1*p2),xx);   return(c);  end;

En MATH, X sería interpretado antes entonces da el resultado "erroneo". Gracias a debug( ); puedes ver lo que sucede fácilmente, ejemplo:

Code:
export  convolution1(v1,v2) begin    debug();   local p1,p2,c,xx:="xx";    p1:=poly2symb(v1,xx);    p2:=poly2symb(v2,xx);    c:=symb2poly(simplify(p1*p2),xx);   return(c);  end;

My website: erwin.ried.cl
01-27-2014, 04:32 PM (This post was last modified: 01-27-2014 04:51 PM by compsystems.)
Post: #5
 compsystems Senior Member Posts: 1,198 Joined: Dec 2013
RE: when will be ready a program editor for the CAS MODE ?
Ya detecte el problema, es que poly2symb([1,2,3,4]) genera una expresión algebraica en 'X', y como 'X' esta predefina en 0 en HOME (X -> 0), entonces el polinomio se convierte en el valor independiente dando como resultado un escalar o valor indeseado. Un resultado indeseado se conoce como BUG. Ahora en la aplicación GRAPH esa 'X' se mantiene simbólica y entonces no se genera dicho horror, no error =), en la HP-Prime no hay uniformidad algunas cosas funcionan en ciertos lugares y en otras no, por ejemplo ejecuntando en la entry line los sentencias de un programa trabaja OK pero dentro de un programa NO, para mi esto es por que le falta madurez en el firmware o que aun no han podido unificar los motores de HOME con CAS ademas con las diversas aplicaciones pre-incluidas

El problema del programa simple anterior se soluciona ejecutándolo en la aplicacion GRAPH, o realizando TRUCOS por ejemplo que el segundo argumento sea una variable que contiene una cadena xx:="xx", esto se ve muy feo en un sistema algebraico computarizado de ultima generación, es primitivo e inpractico, extiende los códigos, complica al estudiante, complica la re-edición etc etc

La solución verdadera es que el EDITOR de programas de la HP-Prime permita crear programas tipo CAS, asi de simple, no hay acondicionar ningún código

Erwin si copias el siguiente código en la entry line del emulador veras que se almacena en el editor de programas como convolution1 (CAS) y permite la re-edición, y al ejecutarlo funciona perfectamente

Code:
//convolution Version1: con la multiplicación de polinomios  convolution1(v1,v2):= begin    local p1,p2,c;    p1:=poly2symb(v1);    p2:=poly2symb(v2);    c:=symb2poly(simplify(p1*p2));   return(c);  end;

Como te comente antes descubrí que los programas tipo CAS se incrustan en un archivo llamado cas.settings en la siguiente ruta

C:\Users\user Name\AppData\Roaming\HP_Prime

Ahora si realizas ingeniería inversa podrías incorporar en PrimeCOMM enviar archivos tipos CAS al emulador, por que no se cuando el HP TEAM dará soporte o mas bien desarrollara un verdadero editor de programas para CAS MODE (NUMERIC AND SYMBOLIC), que es lo que me interesa, no programas numericos para HOME MODE
01-27-2014, 04:49 PM
Post: #6
 Han Senior Member Posts: 1,810 Joined: Dec 2013
RE: when will be ready a program editor for the CAS MODE ?
You are mislabeling a mis-use of shortcut notation as a bug. The choice of xx:="xx"; seems ugly only because it was a spur-of-the-moment choice. You could have easily just used:

Code:
 export  convolution1(v1,v2) begin    local p1,p2,c,var:="x";   purge(var);   p1:=poly2symb(v1,var);    p2:=poly2symb(v2,var);    c:=symb2poly(simplify(p1*p2),var);   return(c);  end;

The issue you are having is that you are using a shortcut notation (by not specifying the variable), and the system therefore has to guess what variable you intended -- and it can only do this based on its current settings. Since you are in the Function [App], it can only assume that the variable you meant was 'X'. This, of course, does not work well in CAS, since 'X' is a global variable. So instead of using the shortcut notation, be explicit with the parameters for CAS functions.

Graph 3D | QPI | SolveSys
01-27-2014, 05:31 PM (This post was last modified: 01-27-2014 05:47 PM by compsystems.)
Post: #7
 compsystems Senior Member Posts: 1,198 Joined: Dec 2013
RE: when will be ready a program editor for the CAS MODE ?
Quote:poly2symb  Syntax: poly2symb(Lst,Var)
Returns a polynomial (orthe polynomial and its value) in Var (by default x CAS MODE X home MODE), the polynomial being defined
by the vector of coefficents in Vect .
Examples

CAS MODE and simplify none:

poly2symb([1,2,3]); [enter] returns (x+2)*x+3
poly2symb([1,2,3],x); [enter] returns (x+2)*x+3
poly2symb([1,2,3],x=2); [enter] returns (x+2)*x+3=11 ?

HOME MODE and simplify none:

poly2symb([1,2,3]); [enter] returns (X+2)*X+3
poly2symb([1,2,3],x); [enter] returns  "error: sintaxis error"
poly2symb([1,2,3],x=2); [enter] returns  "error: sintaxis error"

Quote:symb2poly  Syntax: symb2poly(Expr,[Var]) or symb2poly(Expr, ListVar)
Returns the coefficients of a polynomial Expr with respect tothe variable Var or if the second argument is
a list returns the internal format of the polynomial. Essentaiilly the inverse of poly2symb().
Example:

symb2poly( (x+2)*x+3,x) returns [1,2,3]

Code:
//convolution Version2 convolution2(v1,v2,var):= begin    local p1,p2,c;    p1:=poly2symb(v1,var);    p2:=poly2symb(v2,var);    c:=symb2poly(simplify(p1*p2),var);   return(c);  end;

CAS MODE

convolution2([1,2,3,4],[5,6,7,8],y); [enter] returns [5,16,34,60,61,52,32] // OK

HOME MODE

convolution2([1,2,3,4],[5,6,7,8],y); [enter] returns "error: sintaxis error"
01-27-2014, 05:42 PM
Post: #8
 eried Senior Member Posts: 737 Joined: Dec 2013
RE: when will be ready a program editor for the CAS MODE ?
use "y"

My website: erwin.ried.cl
01-27-2014, 05:55 PM (This post was last modified: 01-27-2014 05:57 PM by compsystems.)
Post: #9
 compsystems Senior Member Posts: 1,198 Joined: Dec 2013
RE: when will be ready a program editor for the CAS MODE ?
according to the manual poly2symb and symb2poly, the second argument is a variable, not a string

Code:
//convolution Version2 export convolution2(v1,v2,var) begin    local p1,p2,c;    p1:=poly2symb(v1,var);    p2:=poly2symb(v2,var);    c:=symb2poly(simplify(p1*p2),var);   return(c);  end;

CAS MODE

convolution2([1,2,3,4],[5,6,7,8], "y" ); [enter] returns "Error: Bad Argument Value" // OK the second arg is a string

HOME MODE

convolution2([1,2,3,4],[5,6,7,8], "y" ); [enter] returns warning evalution ... =(
01-27-2014, 06:14 PM
Post: #10
 eried Senior Member Posts: 737 Joined: Dec 2013
RE: when will be ready a program editor for the CAS MODE ?
Oh, right, it should be '"y"' as parameter (with single quotes first)

My website: erwin.ried.cl
01-27-2014, 07:06 PM (This post was last modified: 01-27-2014 07:53 PM by compsystems.)
Post: #11
 compsystems Senior Member Posts: 1,198 Joined: Dec 2013
RE: when will be ready a program editor for the CAS MODE ?
OK

CAS MODE

convolution2([1,2,3,4],[5,6,7,8], ' "y" ' ); [enter] returns [5,16,34,60,61,52,32]

HOME MODE

convolution2([1,2,3,4],[5,6,7,8], ' "y" ' ); [enter] returns [5,16,34,60,61,52,32]

BUT

TYPE( "y" ) ; [enter] returns 2

TYPE( ' "y" ' ) ; [enter] returns 2

"y" = '"y"' =( // aca surge un problema cuando se desea detectar el tipo de entrada

Quote:TYPE  Syntax: TYPE(object)
Returns the type of the object:
0: Real
1: Integer
2: String
3: Complex
4: Matrix
5: Error
6: List
8: Function
9: Unit
14.?: cas object. the fractional part is the cas type
01-27-2014, 07:21 PM
Post: #12
 eried Senior Member Posts: 737 Joined: Dec 2013
RE: when will be ready a program editor for the CAS MODE ?
Yes I see, it is not consistent. There should be some explanation, maybe TYPE is similar to the one in UserRPL (masking another complex TYPES all in another simpler category)

My website: erwin.ried.cl
01-27-2014, 07:28 PM
Post: #13
 Han Senior Member Posts: 1,810 Joined: Dec 2013
RE: when will be ready a program editor for the CAS MODE ?
(01-27-2014 05:55 PM)compsystems Wrote:  according to the manual poly2symb and symb2poly, the second argument is a variable, not a string

While that is true, you must remember that if you are writing a program, you cannot pass variables the same way you pass them in CAS view. Those are CAS commands, and therefore do not behave the same way in the Home view.

symb2poly(expr,var)

In CAS mode, you can simply type: symb2poly(x^2+1,x) and get [1 0 1]. However, in Home view, you obviously cannot use x since the parser in Home view only recognizes global variables. So to avoid this problem, you can quote your input:

symb2poly("x^2+1","x")

Moreover, the var parameter itself can be a variable whose contents is a string representing your variable. This is why:

Code:
 LOCAL myvar:="x"; symb2poly("x^2+1",myvar);

also works. Your issues seem to stem from not keeping Home and CAS views separate. When executing CAS commands in the Home view, the rules change. And since programs are essentially executed in Home view, you have to account for than when adding in CAS commands into your program.

Graph 3D | QPI | SolveSys
01-27-2014, 07:40 PM (This post was last modified: 01-27-2014 07:57 PM by compsystems.)
Post: #14
 compsystems Senior Member Posts: 1,198 Joined: Dec 2013
RE: when will be ready a program editor for the CAS MODE ?

an object must be distinguished between single quotes and double quotes, otherwise within a program can not detect

example

Code:
//convolution Version3 export convolution3(v1,v2,var) begin    local p1,p2,c;    if type( var ) == 2   then      print("Invalid third parameter, must be a variable");    else     p1:=poly2symb(v1,var);      p2:=poly2symb(v2,var);      c:=symb2poly(simplify(p1*p2),var);     return(c);    end; end;

convolution3([1.,2.,3.,4.],[5.,6.,7.,8.],'"y"'); returns "Invalid third parameter, must be a variable" =( =[

request for HP-team

'y' should be interpreted as a symbolic variable, no string

TYPE( "y" ) ; [enter] returns 2

TYPE( 'y' ) ; [enter] returns 2.1 // idea
01-27-2014, 08:05 PM (This post was last modified: 01-27-2014 08:15 PM by Han.)
Post: #15
 Han Senior Member Posts: 1,810 Joined: Dec 2013
RE: when will be ready a program editor for the CAS MODE ?
(01-27-2014 06:14 PM)eried Wrote:  Oh, right, it should be '"y"' as parameter (with single quotes first)

The ' "y" ' behavior is actually a bug (discussed in another thread about indirection). The ' ' quote signifies an algebraic object. The current firmware allows ' "y" ' and will likely be fixed come next update, because this is clearly not a valid algebraic object. In home view, pass "y", and in CAS view, simply use y (no quotes).

What I don't understand, though, is that the variable is really just a dummy variable. So why even have it as an input parameter when it has no bearing on the output?

Code:
 export convolution1(v1,v2) begin    local p1,p2,c,var:="x_";   purge(var);   p1:=poly2symb(v1,var);    p2:=poly2symb(v2,var);    c:=symb2poly(simplify(p1*p2),var);   return(c);  end;

This code should work in both Home and CAS and the user does not have to worry about specifying any "variable" parameter.

Graph 3D | QPI | SolveSys
 « Next Oldest | Next Newest »

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