Post Reply 
How can I define cas function of an operator(mathematical term)?
09-02-2023, 03:29 PM
Post: #1
How can I define cas function of an operator(mathematical term)?
I have hp prime v2. I want to define operator, let's say I want to create user defined CAS operator, that computes indefinite integral: limit(int(Y,X,-A,A),-infinity,+infinity).
1) I tried to do this trough shift+ define with no success.
I was able to obtain correct integrals by using CAS.int(Y,X), but was inable to compute limits via CAS.limit(Y, X). Because it was impossible to obtain right result for limit, I was inable to obtain correct indefinite integral.
2) I tried to do this thought shift + program. I was unable to compute integral.
I used
EXPORT MYFUNC(x,y);
RETURN CAS(int(y,x));
3) I also tried to do this thought
# cas;
myfunc(x,y):=
BEGIN
int(y,x);
Result it gave was incorrect.
How can I do this?
Find all posts by this user
Quote this message in a reply
09-02-2023, 04:37 PM
Post: #2
RE: How can I define cas function of an operator(mathematical term)?
(09-02-2023 03:29 PM)Aleksandr94 Wrote:  I have hp prime v2. I want to define operator, let's say I want to create user defined CAS operator, that computes indefinite integral: limit(int(Y,X,-A,A),-infinity,+infinity).
1) I tried to do this trough shift+ define with no success.
I was able to obtain correct integrals by using CAS.int(Y,X), but was inable to compute limits via CAS.limit(Y, X). Because it was impossible to obtain right result for limit, I was inable to obtain correct indefinite integral.
2) I tried to do this thought shift + program. I was unable to compute integral.
I used
EXPORT MYFUNC(x,y);
RETURN CAS(int(y,x));
3) I also tried to do this thought
# cas;
myfunc(x,y):=
BEGIN
int(y,x);
Result it gave was incorrect.
How can I do this?

Try this:

Code:

#cas
MYFUNCTION(fnz,a,b):=
BEGIN
LOCAL fnz1;
vr:=lname(fnz)[1];
fnz1:=(vr)→int(fnz(vr),vr,a,b);
RETURN fnz1(vr);
END;
#end

For example:

MYFUNCTION((x)->2*x-x^2/15,0,30) equal to 300
Find all posts by this user
Quote this message in a reply
09-03-2023, 09:03 AM
Post: #3
RE: How can I define cas function of an operator(mathematical term)?
Than you for the reply!
I wanted to be able to choose integration variable explicitly.
So I tried
#CAS
MYINT(f,x):=
BEGIN
LOCAL fnz1;
vr1:=lname(f);
fnz1:=(vr1)->int(f,x);
RETURN fnz1(vr1);
END;
#end
Most likely HpPPPL mixes up "x" variables. So I need the way to tell him that "x" must be from MYINT(f,x).
These cas function didn't gave the correct result.
Find all posts by this user
Quote this message in a reply
09-03-2023, 12:58 PM
Post: #4
RE: How can I define cas function of an operator(mathematical term)?
(09-02-2023 04:37 PM)robmio Wrote:  vr:=lname(fnz)[1];
fnz1:=(vr)→int(fnz(vr),vr,a,b);
RETURN fnz1(vr);

If fnz is function of 1 variable, we don't need parameter's name (it is just a dummy)
I think above is equivalent to this:

LOCAL vr;
RETURN int(fnz(vr), vr, a, b);
Find all posts by this user
Quote this message in a reply
09-03-2023, 01:25 PM
Post: #5
RE: How can I define cas function of an operator(mathematical term)?
(09-03-2023 12:58 PM)Albert Chan Wrote:  
(09-02-2023 04:37 PM)robmio Wrote:  vr:=lname(fnz)[1];
fnz1:=(vr)→int(fnz(vr),vr,a,b);
RETURN fnz1(vr);

If fnz is function of 1 variable, we don't need parameter's name (it is just a dummy)
I think above is equivalent to this:

LOCAL vr;
RETURN int(fnz(vr), vr, a, b);

It is true, we don't need parameter's name.

However, an easier way to program the function could be as follows:

Code:

#cas
MYFUNCTION(fnz,a,b):=
BEGIN
LOCAL x;
RETURN int(fnz(x),x,a,b);
END;
#end

To prevent the function variable from being stored in "CAS Vars" I choose "x" as the local variable. kind regards, Roberto
Find all posts by this user
Quote this message in a reply
09-03-2023, 05:51 PM
Post: #6
RE: How can I define cas function of an operator(mathematical term)?
Thank you for replies!
There is one issue with answers you gave. I most practical cases functions are multivariable. In most cases we don't know the name of variable. So I don't know wether it will be x or other variable. Say l asked this question with intention to define normalisation operator for wavefunctions. I also want to define several other operators like various Hamiltonian operators and so on. So I started with this baby example of indefinite integral. To solve this question I should be able to solve at least any arbitrary integral from CAS. So we stopped there.
So I am asking to help me construct user defined cas function for an mathematical operator (say integration), where we can insert any arbitrary variables.
I tried this:
#CAS
MYINT(f,x):=
BEGIN
RETURN int(f,x);
END;
#end

So I tried this new cas function in CAS mode
MYINT(y^2,y)
And I have obtained this:
Int(f(x)dx)
Find all posts by this user
Quote this message in a reply
09-03-2023, 06:48 PM (This post was last modified: 09-03-2023 08:22 PM by Albert Chan.)
Post: #7
RE: How can I define cas function of an operator(mathematical term)?
HP Prime cannot generate unique symbol, like lisp gensym. (correct this if I was wrong ...)
Here, we use a fixed-name global symbol as a bridge.

If symbol is then used for other purpose, we may get into trouble.
See thread, HP Prime undef for Limes. Maybe a Bug?

Code:
#CAS
MYINT(f,x) :=
BEGIN
subst(int(f(x=x_), x_), x_=x);
END;
#END

CAS> MYINT(x*sin(y), x)      → 1/2*x^2*sin(y)
CAS> MYINT(x*sin(y), y)      → -x*cos(y)
CAS> MYINT(x*sin(y), z)      → x*z*sin(y)

Update: removed ASSUME(x_, symbol).
Find all posts by this user
Quote this message in a reply
09-04-2023, 02:08 PM
Post: #8
RE: How can I define cas function of an operator(mathematical term)?
(09-03-2023 06:48 PM)Albert Chan Wrote:  HP Prime cannot generate unique symbol, like lisp gensym. (correct this if I was wrong ...)
Here, we use a fixed-name global symbol as a bridge.

If symbol is then used for other purpose, we may get into trouble.
See thread, HP Prime undef for Limes. Maybe a Bug?

Code:
#CAS
MYINT(f,x) :=
BEGIN
subst(int(f(x=x_), x_), x_=x);
END;
#END

CAS> MYINT(x*sin(y), x)      → 1/2*x^2*sin(y)
CAS> MYINT(x*sin(y), y)      → -x*cos(y)
CAS> MYINT(x*sin(y), z)      → x*z*sin(y)

Update: removed ASSUME(x_, symbol).
Thank you for the reply!
I have aso tried something like

#CAS
NORM1(fn,a,b):=
BEGIN
LOCAL x
RETURN int(fn(x=x_),x_,a,b);
END;
#end
And tis didn't work.
I also tried this.

#CAS
NORM1(fn,a,b):=
BEGIN
LOCAL x
RETURN int(fn(x),x,a,b);
END;
#end
And this also didn't work.

How do I find this, assuming that there may be several variables and variable of integration is unknown?
It is a bit dissaponying thing about this calculator, that one just can't define mathematical operators by simply writing some formula. It is dissapoinnting, that there is no good queck start manual about defining user defined CAS functions. I think that a user defined function is the most important feature of calculator like this.
Find all posts by this user
Quote this message in a reply
09-04-2023, 03:40 PM
Post: #9
RE: How can I define cas function of an operator(mathematical term)?
(09-04-2023 02:08 PM)Aleksandr94 Wrote:  How do I find this, assuming that there may be several variables and variable of integration is unknown?

It may be best not to "find this" yourself, whatever it is.
Just show with a concrete example, and what is needed.
Find all posts by this user
Quote this message in a reply
09-04-2023, 04:59 PM
Post: #10
RE: How can I define cas function of an operator(mathematical term)?
Aleksandr94,

Try this:

Code:
#cas
MYINT(f,var):=
BEGIN
 local fnc;
 fnc:="int(" + f + "," + var + ")";
 RETURN expr(fnc);
END;
#end

I "think" this is what you are looking for.

-road
Find all posts by this user
Quote this message in a reply
09-04-2023, 04:59 PM
Post: #11
RE: How can I define cas function of an operator(mathematical term)?
(09-04-2023 03:40 PM)Albert Chan Wrote:  
(09-04-2023 02:08 PM)Aleksandr94 Wrote:  How do I find this, assuming that there may be several variables and variable of integration is unknown?
It may be best not to "find this" yourself, whatever it is.
Just show with a concrete example, and what is needed.
Thank you for the reply.
I would like define several quantum mechanical operators as CAS functions.
First of all I want to define normalization operator for wavefunction with single coordinate variable.
Operator is like this: f(x)/int(f(x)f(x)^*,x, a, b). This operator converts a wavefunction to its normalized variant.
I also would like to define eigenvalue operator for differential equations.
I thought that it is batter to start with baby examples, so I asked about infinite integral, indefinite integral and definite integral.
I hope, that if enough examples of CAS UDF-s will be shown, one will be able to write any other quantum mechanical operator.
Find all posts by this user
Quote this message in a reply
09-04-2023, 06:26 PM (This post was last modified: 09-05-2023 12:09 PM by Albert Chan.)
Post: #12
RE: How can I define cas function of an operator(mathematical term)?
Code:
NORM1(f,a,b) :=
BEGIN
LOCAL c := int(f(¬x)*conj(f(¬x)), ¬x, a, b);
unapply( f(¬x)/sqrt(c), ¬x);
END;

Cas> NORM1(t -> sin(2*pi*t), 0, 1)

(¬x) -> sin(2*π*¬x)/√2*2

Cas> NORM1((x)->x*(LL-x),0,LL)

(¬x) -> ¬x*(LL-¬x)/√(LL^5/30)

Examples taken from video, How to Normalize a Wave function in Quantum Mechanics

Update:
CyperAngel had suggested "¬x", to reduce chances of name conflict.
If variables used always start with alphabet, we are safe.
Find all posts by this user
Quote this message in a reply
Post Reply 




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