Skip to content

Commit 0840bca

Browse files
committed
Improve HermiteH for FunctionExpand; move Sinc(z)//FunctionExpand impl.
1 parent 3bd9f13 commit 0840bca

5 files changed

Lines changed: 75 additions & 7 deletions

File tree

symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/ExpTrigsFunctions.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.matheclipse.core.eval.interfaces.AbstractEvaluator;
4848
import org.matheclipse.core.eval.interfaces.AbstractFunctionEvaluator;
4949
import org.matheclipse.core.eval.interfaces.AbstractTrigArg1;
50+
import org.matheclipse.core.eval.interfaces.IFunctionExpand;
5051
import org.matheclipse.core.eval.interfaces.IMatch;
5152
import org.matheclipse.core.eval.interfaces.INumeric;
5253
import org.matheclipse.core.eval.interfaces.IReciprocalTrigonometricFunction;
@@ -3638,7 +3639,20 @@ public IExpr rewriteExp(IExpr arg1, EvalEngine engine) {
36383639
* <p>
36393640
* See <a href="http://en.wikipedia.org/wiki/Sinc_function">Sinc function</a>
36403641
*/
3641-
private static class Sinc extends AbstractTrigArg1 implements INumeric, DoubleUnaryOperator {
3642+
private static class Sinc extends AbstractTrigArg1
3643+
implements INumeric, IFunctionExpand, DoubleUnaryOperator {
3644+
3645+
@Override
3646+
public IExpr functionExpand(IAST ast, EvalEngine engine) {
3647+
if (ast.isAST1()) {
3648+
IExpr z = ast.arg1();
3649+
if (!z.isZero()) {
3650+
// Sinc(z_) := Sin(z) / z /; z!=0
3651+
return F.Times(F.Sin(z), F.Power(z, F.CN1));
3652+
}
3653+
}
3654+
return F.NIL;
3655+
}
36423656

36433657
@Override
36443658
public double applyAsDouble(double operand) {
@@ -3726,6 +3740,7 @@ public void setUp(final ISymbol newSymbol) {
37263740
newSymbol.setAttributes(ISymbol.LISTABLE | ISymbol.NUMERICFUNCTION);
37273741
super.setUp(newSymbol);
37283742
}
3743+
37293744
}
37303745

37313746
// public static BinaryFunctorImpl<IExpr> integerLogFunction() {

symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/PolynomialFunctions.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,47 @@ private static IAST computeGroebnerBasis(IAST listOfPolynomials, IAST listOfVari
19401940
* -28+I*4
19411941
* </pre>
19421942
*/
1943-
private static final class HermiteH extends AbstractFunctionEvaluator {
1943+
private static final class HermiteH extends AbstractFunctionEvaluator implements IFunctionExpand {
1944+
1945+
@Override
1946+
public IExpr functionExpand(IAST ast, EvalEngine engine) {
1947+
IExpr n = ast.arg1();
1948+
int ni = n.toIntDefault();
1949+
if (F.isPresent(ni) && ni < 0) {
1950+
IExpr z = ast.arg2();
1951+
1952+
// HypergeometricU(a,b,z):
1953+
// https://functions.wolfram.com/HypergeometricFunctions/HypergeometricU/26/01/01/
1954+
IRational a = F.QQ(-ni, 2);
1955+
IExpr b = F.C1D2;
1956+
// take the branch for z>=0
1957+
ISymbol zDummy = F.Dummy("z$", F.GreaterEqual(F.Slot1, F.C0));
1958+
IExpr x = zDummy.sqr();
1959+
// Hypergeometric1F1(a,b,x)/(Gamma(1+a-b)*Gamma(b))
1960+
IExpr term1 =
1961+
F.Times(F.Power(F.Times(F.Gamma(F.Plus(F.C1, a, F.Negate(b))), F.Gamma(b)), F.CN1),
1962+
F.Hypergeometric1F1(a, b, x));
1963+
1964+
// x^(1-b)*Hypergeometric1F1(1+a-b,2-b,x)/(Gamma(a)*Gamma(2-b))
1965+
IExpr term2 = F.Times(F.Power(x, F.Subtract(F.C1, b)),
1966+
F.Power(F.Times(F.Gamma(a), F.Gamma(F.Subtract(F.C2, b))), F.CN1),
1967+
F.Hypergeometric1F1(F.Plus(F.C1, a, F.Negate(b)), F.Subtract(F.C2, b), x));
1968+
1969+
// Pi/Sin(Pi*b)*(term1-term2)
1970+
IExpr hyperGeometricU =
1971+
F.Times(F.Pi, F.Power(F.Sin(F.Times(F.Pi, b)), F.CN1), F.Subtract(term1, term2));
1972+
1973+
// HermiteH(n,z): https://functions.wolfram.com/Polynomials/HermiteH/26/01/04/0001/
1974+
// 2^n*u
1975+
IExpr result =
1976+
engine.evaluate(F.FunctionExpand(F.Times(F.Power(F.C2, n), hyperGeometricU)));
1977+
1978+
// back substitution zDummy->z
1979+
result = F.subst(result, zDummy, z);
1980+
return result;
1981+
}
1982+
return F.NIL;
1983+
}
19441984

19451985
@Override
19461986
public boolean evalIsReal(IAST ast) {
@@ -2011,6 +2051,7 @@ public void setUp(final ISymbol newSymbol) {
20112051
newSymbol.setAttributes(ISymbol.NUMERICFUNCTION | ISymbol.LISTABLE);
20122052
super.setUp(newSymbol);
20132053
}
2054+
20142055
}
20152056

20162057
private static final class JacobiP extends AbstractFunctionEvaluator {

symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/rules/FunctionExpandRules.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,6 @@ public class FunctionExpandRules {
261261
// Sin(n_Integer*ArcTan(z_)):=Sum((-1)^k*Binomial(n,2*k+1)*z^(2*k+1),{k,0,Floor(1/2*(-1+n))})/(1+z^2)^(n/2)/;n>0
262262
SetDelayed(Sin(Times(ArcTan(z_),$p(n, Integer))),
263263
Condition(Times(Power(Power(Plus(C1,Sqr(z)),Times(C1D2,n)),CN1),Sum(Times(Power(CN1,k),Binomial(n,Plus(Times(C2,k),C1)),Power(z,Plus(Times(C2,k),C1))),list(k,C0,Floor(Times(C1D2,Plus(CN1,n)))))),Greater(n,C0))),
264-
// Sinc(z_):=Sin(z)/z/;z!=0
265-
SetDelayed(Sinc(z_),
266-
Condition(Times(Power(z,CN1),Sin(z)),Unequal(z,C0))),
267264
// SinIntegral(Sqrt(z_^n_)):=(Sqrt(z^n)*SinIntegral(z^(n/2)))/z^(n/2)
268265
SetDelayed(SinIntegral(Sqrt(Power(z_,n_))),
269266
Times(Power(Power(z,Times(C1D2,n)),CN1),Sqrt(Power(z,n)),SinIntegral(Power(z,Times(C1D2,n))))),

symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/PolynomialFunctionsTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ public void testGegenbauerC() {
154154

155155
@Test
156156
public void testHermiteH() {
157+
158+
check("Gamma(1/2,z)//FunctionExpand", //
159+
"Sqrt(Pi)*(1-Erf(Sqrt(z)))");
160+
check("HermiteH(-2,z) // FunctionExpand", //
161+
"1/4*Pi*((-2*E^z^2*z)/Sqrt(Pi)+(2*(1+E^z^2*Sqrt(Pi)*z*Erf(z)))/Pi)");
162+
check("HermiteH(-3,z) // FunctionExpand", //
163+
"1/8*Pi*((2*E^z^2*(1/2+z^2))/Sqrt(Pi)+(-2*z*(1+(E^z^2*(Sqrt(Pi)+Sqrt(Pi)*(-1+Erf(z))))/(\n" //
164+
+ "2*z)+E^z^2*z*(Sqrt(Pi)+Sqrt(Pi)*(-1+Erf(z)))))/Pi)");
165+
166+
check("HermiteH(1,0)", //
167+
"0");
168+
check("HermiteH(0,0)", //
169+
"1");
170+
check("HermiteH(1,1)", //
171+
"2");
172+
157173
// TODO interrupt long running apfloat calculations
158174
// checkNumeric("HermiteH(2.718281828459045,10007)", //
159175
// "");
@@ -231,6 +247,7 @@ public void testLaguerreL() {
231247
// TODO
232248
// check("LaguerreL(-9223372036854775808/11,-3.141592653589793)", //
233249
// " ");
250+
234251
// test for java.util.TimSort: IllegalArgumentException - Comparison method violates its general
235252
// contract!
236253
check("LaguerreL(42,-1+I)", //

symja_android_library/rules/FunctionExpandRules.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@
129129
Sin(n_Integer*ArcTan(z_)) := Sum((-1)^k*Binomial(n, 2*k + 1)*z^(2*k + 1), {k, 0, Floor((n-1)/2)}) / (1 + z^2)^(n/2)
130130
/; n > 0,
131131

132-
Sinc(z_) := Sin(z) / z
133-
/; z!=0,
134132
SinIntegral(Sqrt(z_^n_)) := (Sqrt(z^n)*SinIntegral(z^(n/2)))/z^(n/2),
135133
SinhIntegral(Sqrt(z_^n_)) := (Sqrt(z^n)*SinhIntegral(z^(n/2)))/z^(n/2),
136134

0 commit comments

Comments
 (0)