HP Forums
newRPL: DATA TYPES USING [] AS ELEMENT CONTAINER - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: Not HP Calculators (/forum-7.html)
+--- Forum: Not quite HP Calculators - but related (/forum-8.html)
+--- Thread: newRPL: DATA TYPES USING [] AS ELEMENT CONTAINER (/thread-8160.html)



newRPL: DATA TYPES USING [] AS ELEMENT CONTAINER - compsystems - 04-14-2017 03:23 AM

Hello

Sorry for my bad English, this post was born to propose the rectangular and vector form of a complex number for newRPL

An alternative representation maths object for calculators is using brackets [ ] as container and with prefixes to identify the type of object, in addition we can have more or expand types of objects using a same container and each with its respective algebra, and by the way flags switch between symbolic (algebraic) and [ ] (Could be called VECTOR FORM) but only in the display of the stack or history (within a program code, the object does not change form)

This idea is inspired by hp-prime Xcas Entering maths objects in vector form is much faster and easier than the symbolic form, In addition, each of its elements is best seen by being separated by spaces or commas

Integers in bases (b:bin, d:dec, o:octal, h:hex) (prefix+number+suffix): #65d

prefix for vector form (Xcas): list,set,poly1(1var)

list[ a, b, "hello" ] returns { a, b, "hello" }
or directly { a, b, "hello" }

set[ 1, 1, 2, 2, 3, 3, 3, 3 ] returns set[1, 2, 3]

poly1[ 1, 2, 3 ] returns poly1[ 1, 2, 3 ] and not a vector

poly1[ 1, 2, 3 ] ^ 2 returns poly1[ 1, 4, 10, 12, 9] Coefficients of x^4+4*x^3+10*x^2+12*x+9.

[ 1, 2, 3 ] .^ 2 (alg notation) → [ 1, 4, 9 ] /!\ ".^" dot operator (element by element) ≠ "^" operator

[ 1, 2, 3 ] 2 .^ (rpn) → [ 1, 4, 9 ]

others dot operatos (./, .*, .+, .-)


For NEWRPL I propose the following prefix


[Image: complexNumbersForms_image00.png]

/!\ Examples in algebraic notation but that can be applied in RPL

object #1: Vector: v[ 3, 4 ] → [3,4]
or without prefix [ 3, 4 ] (A single bracket [ at the beginning implies vector) Unless it is of the form [1, 2,; 3, 4] → [[ 1, 2 ],[ 3, 4 ]] (matrix)

[ 3, 4 ] ^ 2 → "Error: operation not valid on vectorial algebra"
[ 3, 4 ] .^ 2 → [ 9, 16 ]

object #2: List: L[ 3, {4}, "hello" ] → { 3, { 4 }, "hello" }
or directly { 3, { 4 }, "hello" } → { 3, { 4 }, "hello" }

object #3: Matriz: m[ 3, 4 ] → [[ 3, 4 ]]

or without prefix (Double continuous bracket [[ implies matrix)

m[[ 3, 4 ]]' (matrix 1x2) Transposed -> [[ 3 ],[ 4 ]] // arrray 2x1

v[ 3, 4 ]' (row vector 2 elements) Transposed -> [ 3,: 4 ] or [ 3,; 4 ] // (column vector 2 elements, With the purpose only of show it vertically on the stack)

m[[ 1, 2 ],[ 3, 4]] → [[ 1, 2 ],[ 3, 4 ]]
[1, 2,; 3, 4] → [[ 1, 2 ],[ 3, 4 ]]
m[1, 2,; 3, 4] → [[ 1, 2 ],[ 3, 4 ]]

v[1, 2,; 3, 4] → "Error: Dimension invalid for vectors"
v[1,; 2, 3, 4] → [1,; 2,; 3,; 4]

m[1, 2,; 3, 4, 5, 6, 7, 8, 9, 10, 11,12] → [[ 1, 2 ],[ 3, 4 ],[ 5, 6 ],[ 7, 8 ],[ 9, 10 ],[ 11, 12 ]]

object #4: Set[3, 3, 4, 5, 4, 4] → s[ 3, 4, 5 ]

object #5: Polynomial: pl[ 3, 4 ] → '3*x+4' (Stack Flag: SYMBOLIC POLYNOMIAL ON) or
pl[3,4] (Flag SYMBOLIC POLYNOMIAL OFF) COEFFICIENT/VECTOR FORM

object #6:
6.1 Rectangular complex or cartesian coordiantes (dot) r[ 3, 4 ] → '3+4*i' (Stack Flag: SYMBOLIC RECTANGULAR FORM ON) or
r[ 3,4 ] (Stack Flag: SYMBOLIC RECTANGULAR FORM OFF) "COEFFICIENT"/VECTOR FORM

6.2 Polar

z=r*(cos(Φ)+i*sin(Φ) (full polar form)
z=r*e^(i*Φ) (exponential form)
z=rΦ (Abbreviated form aka Angular Form)

p[ 5, ∡53.13° ] → '5∡53.13°' (Stack Flag: SYMB FORM ON) But including the symbol of degrees radians, gradians to be able to identify it later when it is stored in a variable.
p[ 5, ∡53.13 ] → p[ 5, ∡53.13° ] (Stack Flag: DEG MODE & SYMB FORM OFF)

p[ 5, ∡0.92r ] → '5∡0.92r' (Stack Flag: SYMB FORM ON)
p[ 5, ∡0.92r ] → p[ 5, ∡0.92r ] (Stack Flag: SYMB FORM OFF)

Operations (÷,*) in polar form are many cases simpler than in the Cartesian form


object #7: Using the complex prefixes R and P for vectors others coordinates

Rectangular Coo Vector r[ 3, 4, 1 ] → r[ 3, 4, 1 ]
P Cylindrical Coo Vector p[ 5, ∡53.13°, 1 ] → p[ 5, ∡53.13°, 1 ]
Sp Spherical Coo Vector sp[ 5, ∡53.13°, ∡78.69° ] → sp[ 5.09, ∡53.13°, ∡78.69° ]

In the hp50 does not work, the change of coordinate in a vector, please to recover this characteristic of the hp48 series

[Image: vectorsForms_image00.png]

Representations of a complex number in ti68k (rectangular, polar), including the possibility of specifying the angular mode as a suffix and superscripts (_r/_°/_g/...)
[Image: complexNumbersForms_image01.png]


8: q quaternions: q[...]

9: Graph coordinate x, y: g[0,0] Coordinate of the screen, starting (0 pxls,0 pxls) upper left end. No negative numbers allowed
g[0...130, 0...79]

//
Only 7 Conversion commands


A: To convert to algebraic

conv2sym( pl[ 1, 2, 3 ] ) → 'x^2+2*x+3' // equal to coeff2symb()
conv2sym( pl[ 3, 4 ] ) → '3*x+4'
conv2sym( r[ 3, 4 ] ) → '3+4*i'
conv2sym( p[ 5, ∡53.13° ] ) → '5∡53.13°'
conv2sym( p[ 5, ∡0.92r ] ) → '5∡0.92r'

B: To convert to vector form

conv2vform( 'x^2+2*x+3' ) → pl[ 1, 2, 3 ] // equal to symb2coeff()
conv2vform( '3*x+4' ) → pl[ 3, 4 ]
conv2vform( '3+4*i' ) → r[ 3, 4 ]
conv2vform( '5∡53.13°' ) → p[ 5, ∡53.13° ]
conv2vform( '5∡0.92r' ) → p[ 5, ∡0.92r ]
conv2vform( '5∡0.92r' ) → p[ 5, ∡0.92r ]

conv2vform( g[65,40] ) → [ 0, 0 ] // same PX→C (CMD) { # 65d # 40d } PX→C (0,0)

conv2vform( pl[ 3, 4, 1 ] ) → [ 3, 4, 1 ]
conv2vform( r[ 3, 4 ] ) → [ 3, 4 ]
conv2vform( p[ 5, ∡53.13° ] ) → [5, 53.13°]
conv2vform( p[ 5, ∡0.92r ] ) → [5, 0.92r ]
conv2vform( s[ 3, 4, 5 ] ) → [ 3, 4, 5 ]

C: Vector to matrix and vice versa

vectorXmatrix( v[ 3, 4, 1 ] ) → [[ 3, 4, 1 ]]
vectorXmatrix( [ 3, 4, 1 ] ) → [[ 3, 4, 1 ]]
vectorXmatrix( [ 3,; 4,; 1 ] ) → [[ 3, 4, 1 ]] an not [[3],[4]] // For conversion to be reversible and to preserve the vector type
vectorXmatrix( v[ 3,; 4,; 1 ] ) → [[ 3, 4, 1 ]]

vectorXmatrix( m[[ 3, 4, 1 ]] ) → [ 3, 4, 1 ]
vectorXmatrix( [[ 3, 4, 1 ]] ) → [ 3, 4, 1 ]
vectorXmatrix( m[ 3, 4, 1 ] ) → [ 3, 4, 1 ]

vectorXmatrix( m[[ 1, 2 ],[ 3, 4 ]] ) → [ 1,2; 3, 4 ]
vectorXmatrix( [[ 1, 2 ],[ 3, 4 ]] ) → [ 1,2; 3, 4 ]
vectorXmatrix( [ 1,2; 3, 4 ] ) → [[ 1, 2 ],[ 3, 4 ]]

can also accept a list as an argument

vectorXmatrix( { {1,2}, {3, 4}} ) → [[ 1, 2 ],[ 3, 4 ]]
vectorXmatrix( { 1,2 } ) → [ 1, 2 ]
vectorXmatrix( { { 1,2 } } ) → [[ 1, 2 ]]
vectorXmatrix( { { 1,2 }, 2 } ) → "Error: invalid dimension"
vectorXmatrix( { { 1,2 } ,{ "hello", 0} } ) → "Error: invalid internal data type"

D: to List

toList( "hello" ) → { "h", "e", "l", "l", "o" }
toList( m[[ 1, 2 ],[ 3, 4 ]] ) → { { 1, 2 }, { 3, 4 }}
toList( v[ 1, 2 ] ) → { 1, 2 }
toList( pl[ 3, 4, 1 ] ) → { 3, 4, 1 } **
toList( r[ 3, 4 ] ) → { 3, 4 } **
toList( p[ 5, ∡53.13° ] ) → { 5, 53.13° }
toList( p[ 5, ∡0.92r ] ) → { 5, 0.92r }
toList( s[ 3, 4, 5 ] ) → { 3, 4, 5 } **
** The primitive type is lost.

E: convert to angle form (polar and cylindrical)

conv2polar( r[ 3, 4 ] ) → p[ 5, ∡53.13° ]
conv2polar( 3+4*i ) → p[ 5, ∡53.13° ]

conv2polar( r[ 3, 4, 1 ] ) → p[ 5, ∡53.13°, 1 ]

E.1: convert to angle form (spherical)

conv2spherical( r[ 3, 4, 1 ] ) → sp[ 5.09, ∡53.13°, ∡78.69° ]
conv2spherical( p[ 5, ∡53.13°, 1 ] ) → sp[ 5.09, ∡53.13°, ∡78.69° ]

F: convert to rect form

conv2rectangular( p[ 5, ∡53.13°, 1 ] ) → r[ 3, 4, 1 ]
conv2rectangular( p[ 5, ∡53.13° ] ) → r[ 3, 4 ]
conv2rectangular( sp[ 5.09, ∡53.13°, ∡78.69° ] ] ) → r[ 3, 4, 1 ]

//

Use examples

s[ 1,1,5,6,3,3 ] union s[ 1,1,2,2,2,4 ] → s[ 1,2,3,4,5,6 ]

s[ 1,1,5,6,3,3 ] intersection s[ 1,1,2,2,2,4 ] → s[1]

r[ 3, 4 ]^2 → r[-7, 24]
conv2sym( Ans(1) ) →-7+24*i

pl[2, 1, -3, -5] - pl[1, -3, 4, -7] → pl[1, 4, -7, 2] // coeff of
conv2sym( Ans(1) ) → x^3+4*x^2-7*x+2

(2*x^3+x^2-3*x-5)-(x^3-3*x^2+4*x-7) → x^3+4*x^2-7*x+2

pl[ 1,-2 ] * pl[ 1, 2, 4 ] → pl[ 1, 0, 0, -8 ]
pl[ 0,1,-2 ] * pl[ 1, 2, 4 ] → pl[ 1, 0, 0, -8 ]

[0, 1,-2] .* [1, 2, 4] → [ 0, 2, -8 ]
hadamard([0, 1,-2],[1, 2, 4]) → [ 0, 2, -8 ]
[ 1,-2] .* [1, 2, 4] → [ 0, 2, -8 ] // Adjusting zeros.

[0, 1,-2] * [1, 2, 4] → "Error: operation not valid on vectorial algebra"
[[0, 1,-2]] * [[1, 2, 4]] → "Error: invalid dimension (1x3)*(1x3)"
[[0, 1,-2]] * [[1], [2], [4]] → [[6]] // (1x3)*(3x1) -> (1x1)
[[1], [2], [4]] * [[0, 1,-2]] → [[ 0. 1. -2. ], [ 0. 2. -4. ], [ 0. 4. -8. ]] // (3x1)*(1x3) -> (3x3)

[[1], [2], [4]] * [0, 1,-2] → [[1], [2], [4]] * [[0, 1,-2]] → [[ 0. 1. -2. ], [ 0. 2. -4. ], [ 0. 4. -8. ]] // Matrix*Vector or Vector*Matrix, the row vector is converted to an 1*n matrix

[0, 1,-2] * [[1], [2], [4]] → [[0, 1,-2]] * [[1], [2], [4]] → [[6]]

p[4∡23°] * (5+7*i) → 7.46962547135+33.5887584665*i
p[4∡23°] * r[5, 7] → r[ 7.46962547135, 33.5887584665]
conv2polar(Ans(1)) → p[34.4093010682, ∡77.4623222081°]


p[4∡0.401425727959r]*p[8.60232526704∡54.462322208°] →
p[34.4093010682∡77.4623222081°]
conv2rectangular( Ans(1)) → r[ 7.46962547135, 33.5887584665]
...

I hope your comments, problems of interpretation by the compiler, inconsistencies, ambiguities, other types of data that can be included etc.

They like the idea?

Thanks


RE: newRPL: DATA TYPES USING [] AS ELEMENT CONTAINER - Vtile - 04-14-2017 08:51 PM

I don't understand, why. What one would archieve with these compared to the current way of doing things.

In example. list[ a, b, "hello" ] returns { a, b, "hello" }

I much more prefer to write { a b "hello" } NOT list[ a, b, "hello" ]
It makes 3 extra keys, compared the list[,,] aproach with 7 or 9 keypresses for object structure alone.

It is in my opinion against the way RPL do things.


RE: newRPL: DATA TYPES USING [] AS ELEMENT CONTAINER - compsystems - 04-15-2017 04:10 AM

Vtile thanks for your reply


For the case L[ 3, {4}, "hello" ] → { 3, { 4 }, "hello" } is simply a container conversion, you can write directly { 3, { 4 }, "hello" }

The prefixes are
Set: s[]
PoLynomial: pl[]
Rectangular (complex or vector) : r[]
Polar for complex numbers or vectors in cylindrical coordinates : p[]
SPherical coordinates for vectors: sp[]
Coordinates (Graphics): g[]

without prefix or optional
vector: [] optional v[]
matrix: [[]], optional m[]
list: {} , optional L[]

With templates the number of keystrokes is reduced, it also includes the prefixes and posfixes automatically
[Image: 2Dtemplates_image00.png]

Circular Parentesis () is the most common option, but it is used as container args of functions f(x,y), complex numbers (x,y) or (r,Φ), to represent a point (x,y) (x,y,z), extraction of elements of a vector o list {9,8,7}(3), [4,5,6](2), etc another option is to use other special containers for each object which are very scarce and even in UNICODE
« » occupied
´ ´ free
` ` free
¨ ¨ free
' ' occupied
" " occupied

Now think if you want to subtract two polynomials, with the vectorial form that I propose you save several pulsations, you can check the coefficients better, not depend on a variable or have to delete it previously etc,

(2*x^3+x^2-3*x-5)-(x^3-3*x^2+4*x-7) // 33 chars, ALG format
pl[2,1,-3,-5]-pl[1,-3,4,-7] // 27 chars, "vector" format
pl[2,1,-3,-5] pl[1,-3,4,-7] - // 29 chars, "vector" format RPL
2 x 3 ^ * x 2 ^ + 3 x * - 5 - x 3 ^ 3 x 2 ^ * - 4 x * + 7 - - // 61 chars, RPL
'(2*x^3+x^2-3*x-5)-(x^3-3*x^2+4*x-7)' // 35 chars symb ALG format

you can also extract each part or element easily
pl[2,1,-3,-5](2) → 1 // ALG
pl[2,1,-3,-5] 2 GET → 1 // RPL

Using prefixes, prefixes[], each object respects its algebra, vector algebra, algebra of complex numbers, polynomials, sets and any other type of data included in the future


RE: newRPL: DATA TYPES USING [] AS ELEMENT CONTAINER - compsystems - 04-16-2017 04:33 PM

Another example of manipulation "vectorial" (RPL with "vectors")

1: FACTOR
factor( x^2+6*x+8 ); [enter] (x+2)*(x+4) // (input expr:Symbolic) & ALG (output expr:Symbolic)
factor( pl[1, 6 , 8] ); [enter] { pl[1 2], pl[1 4] } // (input expr:"vectors" as MatLab) & ALG (output expr:"vectors")

x 2 ^ 6 x * + 8 + factor [enter] '(x+2)*(x+4)' // (input expr:RPN) & RPL (output expr:Symbolic)
'x^2+6*x+8' factor [enter] '(x+2)*(x+4)' // (input expr:Symbolic) & RPL (output expr:Symbolic)
pl[1, 6 , 8] factor [enter] { pl[1 2], pl[1 4] } // (input expr:"vectors") RPL (output expr:"vectors")

HP50
'x^2+6*x+8' FACTOR [enter] '(x+2)*(x+4)' // (expr:Symbolic) RPL

2:
expand( (x+2)*(x+4) ); [enter] x^2+6*x+8 // 100% ALG
expand( { pl[ 1 2], pl[1 4] } ); [enter] pl[1, 6 , 8] // ALG with "vectors"

x 2 + x 4 + * expand [enter] 'x^2+6*x+8' // RPL
'(x+2)*(x+4)' expand [enter] 'x^2+6*x+8' // RPL
{ pl[ 1 2], pl[1 4] } expand [enter] pl[1, 6 , 8] // RPL with "vectors"

HP50
'(x+2)*(x+4)' EXPAND 'x^2+6*x+8' // RPL
x 2 + x 4 + * EXPAND 'x^2+6*x+8' // RPL


RE: newRPL: DATA TYPES USING [] AS ELEMENT CONTAINER - Claudio L. - 04-16-2017 07:20 PM

(04-14-2017 03:23 AM)compsystems Wrote:  I hope your comments, problems of interpretation by the compiler, inconsistencies, ambiguities, other types of data that can be included etc.

They like the idea?

Thanks

I think you misunderstood the problem and took it too far in your own direction. The problem is not the choice of a particular syntax, it's that allowing those objects in a symbolic expression turns the expression into something else, with a huge number of special cases that the CAS will have to (magically?) handle.

Your FACTOR example: the factor command would have to work with symbolic expressions and with those polynomials in vector form embedded in the symbolic expression as a special case, and then the mixing of thos vectors and symbolic terms, and then also any other strange object that you embed into the symbolic as well. Calling it p[] or pl[] or v[] doesn't solve the main problem at all. Still, every command and the CAS will have to deal with all those objects independently, intermixed, etc. It's a coding nightmare. The idea is that unless we can figure out a way for the CAS to treat those cases uniformly there's no point in choosing a particular syntax.
Your syntax is not bad but doesn't add anything that could help solve the problem, and I also see it as a departure from the RPL syntax we all know. Your examples also do a lot of numeric work using algebraic expressions: that's what you'd do on a Prime, not on an RPL machine.


RE: newRPL: DATA TYPES USING [] AS ELEMENT CONTAINER - The Shadow - 05-16-2017 02:29 PM

While I would welcome commands to treat lists as sets, and polynomials as vectors in the style of PROOT, I think creating those as new object types would be a headache of massive proportions.

RPL already gives us the ability to tag a list or vector with a prefix so we (and our programs) don't forget what they mean. (Though newRPL doesn't have that capability yet.)