CAS (beta): usage notes

Discussions about extensions and frameworks

CAS (beta): usage notes

Postby oliver » Thu Jul 26, 2012 12:45 pm

ND1's CAS uses Mathematica™ via Wolfram|Alpha™ commercial API.
An Internet connection is required. Every command takes ~3s to execute. This can be slow or fast, depending on what you're doing. In any case, you're getting results from the best CAS on the planet.


Naming conventions

ALL CAPS ==> 50g command; example: INTVX
Capitalized ==> Mathematica command; example: Integrate
small letters ==> ND1-specific; example: desolve

Usually, if there's a Mathematica command, there won't be an equivalent ND1-specific command and vice versa.
There's likely a 50g command in either case, and likely the input parameters (formatting/order/count) will be slightly different.

For 50g and Mathematica commands, the respective documentation can be used. Mathematica commands continue to work with ND1 types, of course. So you keep typing sin(45) (not Sin[45] as in Mathematica), (4,5) (not 4+5i, though '4+5*i' also works) for a complex number, [3 4 5] (not {3, 4, 5}; although that also works) for an array, etc.


"Intelligent" ∫ and ∂ commands

Arguably the most important CAS functions, and sit on the keypad and are getting some extra love in this CAS: They accept multiple arguments styles to make them really easy to use.

∂:
In addition to the traditional syntax of
'2*X^2' 'X' ∂
this
'2*X^2' ∂
also works. The second form will figure the independent from the expression and use it. This is convenient, as it minimizes what you have to type, but it may not pick the right variable if you have an expression with multiple variables. In that case, use the first form.

Also, you can specify multiple variables in a vector
'2*x^2*y+3*y^2*z+z*x' ['x','y','z'] ∂
and you may drop the tick marks inside the vector:
'2*x^2*y+3*y^2*z+z*x' [x,y,z] ∂

You may also use Mathematica syntax, with flexibility on the input args:
'2*x^2*y+3*y^2*z+z*x' [x,y,z] Derivative
'2*x^2*y+3*y^2*z+z*x' [x] Derivative
'2*x^2*y+3*y^2*z+z*x' ['y'] Derivative
'2*x^2*y+3*y^2*z+z*x' 'y' Derivative
'2*x^2*y+3*y^2*z+z*x' 'y' D (note D is different from ∂, as it requires the name of the variable, while ∂ accepts it optionally)

Or use classic 50g commands for the derivative:
'2*x^2' DERIVX
'2*x^2' 'x' DERIV

∫:
Accepts both
'1/ln(x)' 'x' ∫
and
'1/ln(x)' ∫
for symbolic integration, with the same feature of automatically figuring the variable of integration.

In addition, you can use the same symbol for numeric integration with the option of dropping the variable of integration:
'x^2*sin(x^3)' 'x' 0 10 ∫
'x^2*sin(x^3)' 0 10 ∫
If one of the domain numbers are a BigFloat, a result to the precision set with setBigFPrecision, will be returned:
'x^2*sin(x^3)' 'x' 0 10 toBigF ∫

You may also use Mathematica syntax for both symbolic and numeric integration:
'e^(x^2)' 'x' Integrate
'x^2*sin(x^3)' ['x' 0 10] NIntegrate
'x^2*sin(x^3)' ['x' 0 '2*π'] NIntegrate (note the use of an expression to define the domain; you may drop the tick marks)

or classic 50g commands:
'1/ln(x)' INTVX
'1/ln(x)' RISCH
The old use of the ∫ command on the 50g was to do numeric integration with range arguments first. This has not survived. If you want that style of argument ordering, use the ND-1 command integrate created for that purpose:
0 10 'x^2*sin(x^3)' 'x' integrate
It too accepts BigFloat domain numbers to compute a BigFloat result
0 10 toBigF 'x^2*sin(x^3)' 'x' integrate

The Mathematica syntax supports multiple integration for both symbolic and numerical integration:
'x*y' [x, y] Integrate
'x^2+4*y' [[x 11 14][y 7 10]] NIntegrate
and numerical integrations that return a symbolic result:
'(x^2*y^2)/4' [x 0 2] Integrate

Command examples

This is a list of currently supported commands and example usage. This list will grow quickly during the beta period.

['x^2+y^2=1', '(x-2)^2+(y-1)^2=4'] solve => [ 'x=0 and y=1' 'x=4/5 and y=-3/5' ] (Solve a system of equations)
'sin(x)' solve => [ 'x=2*pi*n and n∈Z' 'x=2*pi*n+pi and n∈Z' ]
'3*Y+SIN(X)/e^X=1/Y' 'Y' SOLVE => [ 'e^X!=0 and Y=-1/6*e^(-X)*(√(12*e^(2*X)+sin^2(X))+sin(X))' 'e^X!=0 and Y=1/6*e^(-X)*(√(12*e^(2*X)+sin^2(X))-sin(X))' ]
'3.8^98' solve => 6.5885897827574538991039790322691172146294557523073304e+56
'X^3-X-9' 'X' SOLVE right toNumber toNumber => [ 2.24004098746944, (-1.12002049373472, -1.66232900448656), (-1.12002049373472, 1.66232900448656) ]

'x^5+x+1=0' 'x' NSolve => [ '-0.5-0.866025*i' '-0.5+0.866025*i' -0.754878 '0.877439-0.744862*i' '0.877439+0.744862*i' ]
['x=ln(y)' 'y=ln(x)'] [[x I], [y 2]] FindRoot => [ 'x->0.318132+1.33724*i' 'y->0.318132+1.33724*i' ]

'tan(x)' 'x' 5 taylor => 'x+x^3/3+(2*x^5)/15' (TAYLOR)
'x^2+5*x+6' Factor => '(x+2)*(x+3)' (FACTOR)
'(x+2)*(x+3)' expand => 'x^2+5*x+6'
'(x^2+2*x+1)/(x+1)' EXPAND => 'x+1'
'x^2+5*x+6' simplify => [ '(x+2)*(x+3)' 'x*(x+5)+6' 'x^2+5*x+6' ] (simplify may return multiple results; pick the first one with head.)

'(X^3+4*X+12)/(11*X^11+1)' [X 0 4] Series => '12+4*X+X^3'
'(X^3+4*X+12)/(11*X^11+1)' [X 1 4] Series => '17/12-(1973*(X-1))/144+(115745*(X-1)^2)/1728-(4122557*(X-1)^3)/20736+(67549097*(X-1)^4)/248832'

'X^3+4*X+12' '11*X^11+1' 4 DIVPC => '12+4*X+X^3'

{ 'x^2 + z', 'y*sin(x)', 'e^(3*z)' } Div => '2*x+sin(x)+3*e^(3*z)'
{ 'x^2*y', 'x^2*y', 'y^2*z' } [x y z] DIV => '(x+y)^2'

'e^x' LAP => '1/(s-1)'
'e^x*cos(z*y)' [x y z] LaplaceTransform => '(e^x*cos(y*z))/s' (LAPL)
'1/(x-5)^2' 'x' InverseLaplaceTransform => 'e^(5*t)*t' (ILAPL)

'd1y(x)*2*y(x)=exp(3*x)' 'y(x)' 'x' desolve => [ '-√(e^(3*x)+6*C[1])/√(3)' '√(e^(3*x)+6*C[1])/√(3)' ]
'd1y(x)+y(x)=sin(x)' 'y(x)' DESOLVE => ['e^(-x)*C[1]+1/2*(-Cos[x]+Sin[x])']

'x^2-17=x^3+2*x' 'x' Exponent => 3
'x^2-17=x^3+2*x' DEGREE => 3

5 'x' ChebyshevT => '16*x^5-20*x^3+5*x'
5 TCHEBYCHEFF => '16*X^5-20*X^3+5*X'
5 'x' ChebyshevU => '32*x^5-32*x^3+6*x'
4 'x' HermiteH => '16*x^4-48*x^2+12'
4 HERMITE => '16*X^4-48*X^2+12'
4 't' LegendreP => '1/8*(35*t^4-30*t^2+3)'
4 LEGENDRE => '1/8*(35*X^4-30*X^2+3)'
4 'X' LaguerreL => '1/24*(x^4-16*x^3+72*x^2-96*x+24)'
"LaguerreL" [4, p] orthopoly => '1/24*(p^4-16*p^3+72*p^2-96*p+24)'
"SphericalHarmonicY" [3, 1, theta, phi] orthopoly => '-1/8*√(21/pi)*e^(i*phi)*sin(theta)*(5*cos^2(theta)-1)'
"JacobiP" [2, a, b, z] orthopoly => '1/8*(z-1)^2*(a+b+3)*(a+b+4)+1/2*(a+2)*(z-1)*(a+b+3)+1/2*(a+1)*(a+2)'

3 HILBERT => [[ 1 '1/2' '1/3' ] [ '1/2' '1/3' '1/4' ] [ '1/3' '1/4' '1/5' ]]
HilbertMatrix(4) => [[ 1 '1/2' '1/3' '1/4' ] [ '1/2' '1/3' '1/4' '1/5' ] [ '1/3' '1/4' '1/5' '1/6' ] [ '1/4' '1/5' '1/6' '1/7' ]]
HilbertMatrix([3,4]) => [[ 1 '1/2' '1/3' '1/4' ] [ '1/2' '1/3' '1/4' '1/5' ]]

'x^2+x+1' '2*x+4' 'x' PolynomialQuotientRemainder => [ 'x/2-1/2' 3 ]
'x^2+x+1' '2*x+4' DIV2 => [ 'x/2-1/2' 3 ]

['x^2*y', 'x^2*y', 'y^2*z'] Curl => ['2*y*z',0,'-x*(x-2*y)'] (CURL)

20 Cyclotomic => 'x^8-x^6+x^4-x^2+1' (CYCLOTOMIC)

[[4 1][2 -1]] eigenvectors => [[ '1/2+1/4*(3+√(33))' 1 ][ '1/2+1/4*(3-√(33))' 1 ]]
[[4 1][2 -1]] eigenvalues => [ '1/2*(3+√(33))' '1/2*(3-√(33))' ]
[[4 1][2 -1]] EGV => [[ '1/2+1/4*(3+√(33))' 1 ] [ '1/2+1/4*(3-√(33))' 1 ]] [ '1/2*(3+√(33))' '1/2*(3-√(33))' ]
[[1 1][1 5]] Cholesky => [[1 1][0 2]]
[[3 1][1 x]] Cholesky => [[ '√(3)' '1/√(3)' ] [ 0 '√(-1/3+x)' ]]

[[3,6,0],[2,4,1],[1,1,1]] charpoly => '-λ^3+8*λ^2-6*λ+3'

6 11 3 IABCUV => [ '11*n+6' '-6*n-3' ]
{3, 4} {4, 5} ICHINREM => 19
[{3, 4} {4, 5}] ChineseRemainder => 19

[3,4,5,2,1] P2C => (1 3 5) (2 4)

0.5 erfi => 0.614952094696511
0.5 C => 0.492344225871446 (or use FresnelC)
0.5 S => 0.064732432859999 (or use FresnelS)
these work with complex args too:
(0.5, 0.8) erfi => (0.28851, 0.869945)
(0.5, 0.8) C => (0.420532, 0.978019)
(0.5, 0.8) S => (-0.479225, -0.00188725)

Plotting:
'LegendreP(10, x)' {x, -1, 1} plot => graph
plot(LegendreP(10, x), [x, -1, 1]) => graph
'sin(x)' [x, -1, 6*pi] plot => graph
plot(sin(x), [x, -1, 6*pi]) => graph
['sin(x)', 'LaguerreL(5, x)'] {x, 0, 2*pi} plot => graph


Wolfram|Alpha command family

There're three commands which can be used to create W|A queries. You can use these commands to design new CAS commands using RPL code snippets, or query W|A for completely different things.

evalWA takes one arguments: a string to be evaluated by W|A; the string may contain a command and any number of arguments, or just a datum of any kind; it will submit a query using this string and return whatever W|A returns, expecting an algebraic expression or number.
Example: "Cyclotomic 20" evalWA => 'x^8-x^6+x^4-x^2+1'

WA takes two arguments: an any-type arg and a command string; it will submit a query using this command and arg and return whatever W|A returns, expecting it to be an algebraic expression (or number).
Example: 20 "Cyclotomic" WA => 'x^8-x^6+x^4-x^2+1'
Example: 4.5677 "W_2[" WA => (-0.874385, 10.9156) (W_n = analytic continuation of the product log function)
Example: "San Francisco" "population" WA => '805235*people**(country*rank:*13th)**(2010*estimate)'

WAopt takes three arguments: an any-type arg, a command string, and an options object; it will submit a query using this command and arg and options and return whatever W|A returns, but already suspecting it to be an algebraic expression (or number). The options object choices are documented in CAS: how to extend it. (Note that, yes, this is a JavaScript Object in RPL.)
Example: "San Francisco" "population" {"expr": true, "erase": /.people.+/ } WAopt => 805235
Example: 'x^2' "D[" {"pod": "Input" } WAopt => 'd/dx(x^2)=2*x'
Example: 'x^2' "D[" {"pod": "Input", "right": true } WAopt => '2*x'


In comparison with 50g

Many commands, even when they have a 50g name such as DERIVX, can produce different results, or accept a wider range of inputs. That's, of course, because Mathematica is processing the commands. For example, you can integrate or differentiate a lot more functions successfully. The simplify command is so powerful it can be used for many uses for which you'd probably use specific commands on the 50g (if there was one). For example, polynomial division is something you can do using the simplify command. (Just type your division as an expression '(x^2+x+1)/(2*x+4)' and simplify, instead of using the DIV2 command. (Which can still give more focused/better results at times.))

Many 50g commands are missing. Let me know if there's something you'd really like to see added.


right

Some commands like the solve command in the first example above, produce equations as output.

Use the right command to strip the left side off of an equation:
'y+5=1+x^2' right => '1+x^2'
[ 'x=0' 'y=1+x^2' ] right => [ '0' '1+x^2' ]
[[ 'x=0' 'y=1+x^2' ][ 'x=4/5' 'y=-3/5' ]] right => [[ '0' '1+x^2' ][ '4/5' '3/5' ]]
[ 'x->0.318132+1.33724*i' 'y->0.318132+1.33724*i' ] right => [ '0.318132+1.33724*i' '0.318132+1.33724*i' ]


Arbitrary precision constants

There's the APConstants folder which has code to compute various constants at arbitrary precision, but you can also use the CAS for that:
'π' 50 N => 3.1415926535897932384626433832795028841971693993751
'e' asBigFloat => 2.7182818284590452353602874713527

Set the desired precision with setBigFPrecision:
200 setBigFPrecision 'pi' asBigFloat
oliver
Site Admin
 
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Update: 1.0beta2

Postby oliver » Tue Jul 31, 2012 3:32 pm

Over 20 new commands have just been added.

The plot command works like the basic Mathematica Plot command and will display one or multiple graphs. See the examples.
oliver
Site Admin
 
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Update: 1.0beta3

Postby oliver » Sun Aug 12, 2012 3:41 pm

Significant internal improvements have been made as to symbolic processing of expressions.

A few new commands have been added.

Most significantly: evalWA, WA, WAopt allow you to do custom W|A queries. This includes building your own CAS functions in RPL (vs. JavaScript) and using W|A for completely different things. See the examples in the new section about these commands in the first post.

Multiple integration (integration with respect to multiple variables) and mixed integration (numerical integration with respect to one variable that yields a symbolic result) is now supported.

Also added have been numerical solving (NSolve) and root finding (FindRoot).

The first post has been updated with examples for all new commands.
oliver
Site Admin
 
Posts: 433
Joined: Sat May 01, 2010 2:11 pm


Return to Extensions

Who is online

Users browsing this forum: No registered users and 1 guest

cron