Post Reply 
newRPL: DATA TYPES USING [] AS ELEMENT CONTAINER
04-14-2017, 03:23 AM (This post was last modified: 04-17-2017 03:02 AM by compsystems.)
Post: #1
newRPL: DATA TYPES USING [] AS ELEMENT CONTAINER
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
Find all posts by this user
Quote this message in a reply
Post Reply 


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



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