Post Reply 
Gamma function
08-06-2020, 01:56 PM
Post: #1
Gamma function
Hello everyone, I would like to know how to replace "Gamma(a,0)" and "Gamma(a,infinity)" ("a" equal, for example, to 2, or to 1/5, etc.) with "gamma(a)" and with "0" , respectively.
For example the following approach does not work:

"subst(Gamma (2/3,0), Gamma (a,0), Gamma(a))".

How can I do?
Sincerely, robmio
Find all posts by this user
Quote this message in a reply
08-06-2020, 03:49 PM
Post: #2
RE: Gamma function
For example: laplace(t^(-1/3),t,s) -->
(-s*Gamma(2/3,infinity)+s*Gamma(2/3,0))/(s*(s^(2/3))).
Find all posts by this user
Quote this message in a reply
08-06-2020, 06:14 PM
Post: #3
RE: Gamma function
In HP PRIME, Gamma function can take one argument as "complete" gamma function, or 2 arguments as incomplete gamma function:

Gamma(a) = Gamma(a,0) = int(t^(a-1)*exp(-t),t,0,infinity)

Gamma(a,x) = int(t^(a-1)*exp(-t),t,x,infinity).

In HP PRIME, for example, Gamma(0.5,0) = 1.7724
Gamma(0.5,2) = 0.080647.
Find all posts by this user
Quote this message in a reply
08-16-2024, 09:36 AM (This post was last modified: 08-16-2024 09:40 AM by ftneek.)
Post: #4
RE: Gamma function
Hi robmio, I wanted to know the same thing.

You can use subst if you want, but that is manual:
subst(Gamma(16/3,0),Gamma(16/3,0)=Gamma(16/3))

I wrote a program to do exactly this, you can get it here.

sgamma(laplace(t^(-1/3),t,s)) -> s^(1/3)*Gamma(2/3)/s

Hope that helps!

- neek
Find all posts by this user
Quote this message in a reply
08-16-2024, 11:47 AM
Post: #5
RE: Gamma function
Cas> Gamma2(a,b) := piecewise((b==0),Gamma(a), (b==inf),0, Gamma(a,b))

Cas> [Gamma(2/3,0), Gamma(2/3,inf), Gamma(2/3,2)] (Gamma = Gamma2)

[Gamma(2/3), 0, Gamma(2/3,2)]
Find all posts by this user
Quote this message in a reply
08-16-2024, 06:06 PM (This post was last modified: 08-16-2024 06:59 PM by ftneek.)
Post: #6
RE: Gamma function
Nice, simple solution.

It works here:
(((-s)*Gamma((2/3),∞)+s*Gamma((2/3),0))/(s*s^(2/3)))(('Gamma') = Gamma2)
-> s*Gamma((2/3))/((s^(1/3))^2*s)

But not here:
(laplace(t^(-1/3),t,s))(('Gamma') = Gamma2)
-> Bad argument value

I also prefer not to type Gamma=Gamma2 everytime:
Code:
g3:=(ex)->BEGIN  
  ex(('Gamma') = Gamma2);  
END;

Is there an easy way to make the laplace example work using this method?

- neek
Find all posts by this user
Quote this message in a reply
08-16-2024, 08:04 PM (This post was last modified: 08-16-2024 08:15 PM by Albert Chan.)
Post: #7
RE: Gamma function
(08-16-2024 06:06 PM)ftneek Wrote:  Is there an easy way to make the laplace example work using this method?

If I try your g3(laplace(t^(-1/3),t,s), I get this error:

"g3(laplace(t^((-1)/3),t,s)) in g3((-s*Gamma(2/3)+s*Gamma(2/3,0)+Gamma(2/3)*s-Gamma(2/3,∞)*s)/(s*(s^(1/3))^2)) instruction #1 error, try debug(g3((-s*Gamma(2/3)+s*Gamma(2/3,0)+Gamma(2/3)*s-Gamma(2/3,∞)*s)/(s*(s^(1/3))^2)))
Error: Bad Argument Value"

We can fix this 2 ways:
1. normal(ex) to g3, cancel out Gamma(x), before substitution.
2. fix Gamma2 to handle optional 2nd argument.

I think 2nd way to fix Gamma2 is better.
I applied 1st way too, just to show what I meant. (it may also be more efficient, with less substitutions)

Cas> Gamma2(a) := piecewise((len(a)==2 AND a[2]==0),Gamma(a[1]), (len(a)==2 AND a[2]==inf),0, Gamma(a))
Cas> g3(ex) := normal(ex) (Gamma = Gamma2)

Cas> g3(laplace(t^(-1/3),t,s)

s^(1/3)*Gamma(2/3)/s
Find all posts by this user
Quote this message in a reply
08-16-2024, 08:42 PM (This post was last modified: 08-16-2024 10:53 PM by ftneek.)
Post: #8
RE: Gamma function
With normalize(ex)) in g3, symbolic result is different:
g3(Gamma(x)) -> (x-1)!/ABS((x-1)!)

(08-16-2024 08:04 PM)Albert Chan Wrote:  Cas> Gamma2(a) := piecewise((len(a)==2 AND a[2]==0),Gamma(a[1]), (len(a)==2 AND a[2]==inf),0, Gamma(a))

I tried this updated Gamma2 method, it incorrectly applied Gamma(Gamma(x))
Gamma2(Gamma(x))
-> ((x-1)!-1)!

It should have just returned Gamma(x)=(x-1)!

fix is for the last piecewise statement:
Quote:Gamma2(a) := piecewise((len(a)==2 AND a[2]==0),Gamma(a[1]), (len(a)==2 AND a[2]==inf),0, a);
g3(ex) := ex (Gamma = Gamma2);

Gamma2(Gamma(x)) -> (x-1)!
g3(laplace(t^(-1/3),t,s) -> s^(1/3)*Gamma(2/3)/s

No need to normalize g3, and Gamma2 can handle symbolic gamma expression.

Edit: I may have misunderstood because of the optional argument. The arguments are Gamma2(a,[b]). Without b, Gamma(a) is expected. So Gamma(Gamma(x)) is correct, and my change to the last piecewise statement is not necessary (or correct).

- neek
Find all posts by this user
Quote this message in a reply
08-16-2024, 11:46 PM
Post: #9
RE: Gamma function
(08-16-2024 08:04 PM)Albert Chan Wrote:  Cas> Gamma2(a) := piecewise((len(a)==2 AND a[2]==0),Gamma(a[1]), (len(a)==2 AND a[2]==inf),0, Gamma(a))

(08-16-2024 08:42 PM)ftneek Wrote:  I may have misunderstood because of the optional argument. The arguments are Gamma2(a,[b]).

All Gamma2 arguments goes to a. There is no b

Gamma2(2), a = 2         --> Gamma2(a) = Gamma(a) = Gamma(2)

Gamma2(2,3), a = [2,3] --> Gamma2(a) = Gamma(a) = Gamma(2,3)

type(a) = DOM_LIST, but a is not a normal list, we don't get Gamma([2,3])
a get flattened as arguments, similar to Python *lst

p3> lst = [2, 3]
p3> [1, *lst]
[1, 2, 3]

Cas> a = id(2,3)       --> [2,3], but *not* normal list!
Cas> [1,a]                --> [1,2,3], *not* [1,[2,3]]

Another way, we strip off list part to get this "star" list

Cas> a = op([2,3])    --> [2,3]
Cas> [1,a]                --> [1,2,3]
Find all posts by this user
Quote this message in a reply
Post Reply 




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