User Tools

Site Tools


prime:cashome

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
prime:cashome [2017/10/31 21:05]
webmasterpdx
prime:cashome [2017/11/06 23:44] (current)
webmasterpdx
Line 20: Line 20:
 There are unusual ops that will get translated into functions when you manually enter them, but it's good to learn them as they can allow you faster entry. e.g. a+=3 gets translated to increment(a,​3) etc.. These include +=, *=, /=, etc. as listed [[https://​tiplanet.org/​hpwiki/​index.php?​title=HP_Prime/​Commands|here.]] However, they are documented in the XCas documentation. =< is a reference store and gets translated to array_sto(). It's a good idea to become familiar with these operators. Remember that the HP Prime CAS is converted from XCas, documented [[http://​www-fourier.ujf-grenoble.fr/​~parisse/​giac/​doc/​en/​cascmd_en/​index.html|here.]] Good HP Prime CAS manual (but in French) [[http://​www-fourier.ujf-grenoble.fr/​~parisse/​calc/​hprime2.pdf|here.]] There are unusual ops that will get translated into functions when you manually enter them, but it's good to learn them as they can allow you faster entry. e.g. a+=3 gets translated to increment(a,​3) etc.. These include +=, *=, /=, etc. as listed [[https://​tiplanet.org/​hpwiki/​index.php?​title=HP_Prime/​Commands|here.]] However, they are documented in the XCas documentation. =< is a reference store and gets translated to array_sto(). It's a good idea to become familiar with these operators. Remember that the HP Prime CAS is converted from XCas, documented [[http://​www-fourier.ujf-grenoble.fr/​~parisse/​giac/​doc/​en/​cascmd_en/​index.html|here.]] Good HP Prime CAS manual (but in French) [[http://​www-fourier.ujf-grenoble.fr/​~parisse/​calc/​hprime2.pdf|here.]]
  
-Indexing in HP Basic is done using () braces, as in L1(5). ​In CAS, () can be used with a constant index in read only mode, but when a variable index is used, due to parsing issues (it thinks ​L1(x) is a function call), you must use [] braces instead, as in L1[i]. So, it is recommended ​if in CAS mode or in a CAS program, it is best to use [] to index always. This applies to Lists, Matrices and Vectors (1D Matrix). In XCas, lists, matrices and vectors are all lists. Note that XCas uses [] always anyway, so this keeps the Prime'​s CAS compatible with XCas.+Any variable assigned in Home mode or in a Home Program is a Home Variable. Likewise any variable assigned in CAS mode or in a CAS Program is a CAS Variable. ​Indexing in HP Basic into Home Variables ​is done using () braces, as in L1(5). ​With CAS Variables, () can be used with a constant index in read only mode, but when a variable index is used, due to parsing issues (it thinks ​l1(x) is a function call), you must use [] braces instead, as in l1[i]. So, it is recommended ​when using CAS variables, it is best to use [] to index always. This applies to Lists, Matrices and Vectors (1D Matrix). In XCas, lists, matrices and vectors are all lists. Note that XCas uses [] always anyway, so this keeps the Prime'​s CAS compatible with XCas. Even if in a CAS Program, Home Variables should use () to index. If a Home Variable is passed into a CAS program as an argument, it will be passed by value and will be converted into a CAS variable. e.g. L1 is one of the default Home List variables. If it is passed into a CAS program, internally to that program, the variable will be a CAS variable and [] indexing should be used. 
 + 
 +Global variables can be made from Home and CAS modes manually. From a program, global variables are made by not declaring the name as LOCAL and just assigning a value. However, the program type from which it's defined determines if it's a CAS or a Home variable. e.g. If in a CAS program you defined m:​={1,​2,​3,​4};​ then m will be a CAS list, but if you define m the same way in a Home program, it'll be a Home list. EXPORT is only needed in variable definition if outside a program definition, but EXPORT defined variables are always Home variables.
  
 In Home mode, to return multiple values, return it as a list. e.g. f1(x) returns a list containing 3 integers. The values returned can be assigned to variables like this: L:​=f1(x);​A:​=L(1);​B:​=L(2);​C:​=L(3);​ In Home mode, to return multiple values, return it as a list. e.g. f1(x) returns a list containing 3 integers. The values returned can be assigned to variables like this: L:​=f1(x);​A:​=L(1);​B:​=L(2);​C:​=L(3);​
Line 29: Line 31:
  
 To remove characters from a string, you can use S:​=suppress(S,​3);​ to remove the 3rd character from the string S. However, the optimal way to drop characters from a string is to use the following function, STRDEL(). This function is orders of magnitude faster than suppress as suppress() is a CAS function. Note that this version uses substrings, but you could use RIGHT/LEFT function calls to implement it. Note that when using RIGHT/LEFT that there also exist other CAS functions right/left (lower case) related to expressions. Note that to insert string, can use format S(1):​="​substring";​ to insert "​substring"​ into the string S. If "​substring"​ runs past end of S, it'll get truncated. To remove characters from a string, you can use S:​=suppress(S,​3);​ to remove the 3rd character from the string S. However, the optimal way to drop characters from a string is to use the following function, STRDEL(). This function is orders of magnitude faster than suppress as suppress() is a CAS function. Note that this version uses substrings, but you could use RIGHT/LEFT function calls to implement it. Note that when using RIGHT/LEFT that there also exist other CAS functions right/left (lower case) related to expressions. Note that to insert string, can use format S(1):​="​substring";​ to insert "​substring"​ into the string S. If "​substring"​ runs past end of S, it'll get truncated.
-[code] +<code> 
-// Remove ​chars between LEFT and RIGHT POS +// Drop chars from string.
-// from String. Returns adjusted ​string.+
 // S   ​String. // S   ​String.
-// L   Pos of last char on left+// L   Pos of leftmost ​char before deletion
-// R   Pos of first char on right.+// R   Pos of first char on right after deletion.
 EXPORT STRDEL(S,​L,​R) EXPORT STRDEL(S,​L,​R)
 BEGIN BEGIN
Line 40: Line 41:
 RETURN IFTE(L<​1,"",​S(1,​L))+IFTE(R>​N,"",​S(R,​N));​ // N just has to go past end of string RETURN IFTE(L<​1,"",​S(1,​L))+IFTE(R>​N,"",​S(R,​N));​ // N just has to go past end of string
 END; // BEGIN... END; // BEGIN...
-[/code]+</code
 + 
 +In the declaration of local variables in a CAS program, you need to keep track of priorities. e.g. local a:=1;b:=0; in a Home program is interpreted as local (a:​=1);​(b:​=0);​ whereas in a CAS program it is interpreted as local a:​=(1;​b:​=0;​),​ which is different. For this reason, it is recommended in CAS programs to keep declaration separate from assignment of local variables.
  
 +There are some more tips in [[http://​www.hpmuseum.org/​forum/​thread-3590.html|this]] article worth reading.
  
  
  
prime/cashome.1509509101.txt.gz · Last modified: 2017/10/31 21:05 by webmasterpdx