> > The problem is that the rule does not have the right type. Manual > intervention is necessary. > <cut> >
Ok, thanks. It works. Now, I'm still stuck with Jacobi-Anger expansion<http://en.wikipedia.org/wiki/Jacobi–Anger_expansion> Suppose I have an expression test_eqn := exp( sqrt(-1) * a * sin( omg * t ) ) * exp( sqrt(-1) * b * sin( 2 * omg * t ) ) and I need to apply the expansion to both of the exponents. If I simply define and use a rule exp_to_bessel_rule := rule exp( sqrt(-1) * z * sin(t) ) == besselJ( N, z ) * exp( sqrt( -1 ) * N * t ) exp_to_bessel_rule( test_eqn ) then I'll get expression with 2 identical summation indices ( 'N' in this case ), which is clearly not something I want. (23) -> exp_to_bessel_rule2( test_eqn ) +---+ +---+ N omg t\|- 1 2N omg t\|- 1 (23) %e %e besselJ(N,a)besselJ(N,b) Type: Expression(Integer) I can think of two workarounds for this problem. The first one is to supply a substitution command with a list of expressions to substitute, so that each time it encounters a pattern, it takes a new expression from the list. The second solution is to stop substitution after the first match. Then redefine the rule to have another index, then substitute again and so on. Is it possible to implement something like that in FriCAS? Are there any other methods? If not, than I have to resort to eval. Unfortunately, this is not a straightforward thing to do. Eval works in the following situation test_eqn := exp( sqrt(-1) * a * sin( omg * t ) ) * exp( sqrt(-1) * b * sin( 2 * omg * t ) ) test_eqn := eval( test_eqn, [ exp( sqrt(-1) * a * sin( omg * t ) ) = besselJ( N, a ) * exp( sqrt( -1 ) * N * omg * t ) ] ) test_eqn := eval( test_eqn, [ exp( sqrt(-1) * b * sin( 2 * omg * t ) ) = besselJ( L, b ) * exp( sqrt( -1 ) * L * 2 * omg * t ) ] ) +---+ +---+ 2L omg t\|- 1 N omg t\|- 1 (27) %e %e besselJ(L,b)besselJ(N,a) Type: Expression(Integer) But if the test_eqn is slightly modified ( see '1 / omg' factor after 'a' ) and a simplification is performed, then it fails. test_eqn := exp( sqrt(-1) * a / omg * sin( omg * t ) ) * exp( sqrt(-1) * b * sin( 2 * omg * t ) ) test_eqn := simplifyExp( test_eqn ) test_eqn := eval( test_eqn, [ exp( sqrt(-1) * a / omg * sin( omg * t ) ) = besselJ( N, a ) * exp( sqrt( -1 ) * N * omg * t ) ] ) +---+ +---+ b omg\|- 1 sin(2omg t) + a\|- 1 sin(omg t) ------------------------------------------ omg (30) %e Type: Expression(Integer) I have to type the whole exponent argument in the pattern to perform the substitution test_eqn := _ eval( test_eqn, _ [ exp( ( sqrt(-1) * a * sin( omg * t ) + sqrt(-1) * b * omg * sin( 2 * omg * t ) )/omg ) = _ besselJ( N, a ) * exp( sqrt( -1 ) * N * omg * t ) * exp( sqrt(-1) * b * sin( 2 * omg * t ) ) ] ) +---+ +---+ N omg t\|- 1 b\|- 1 sin(2omg t) (32) %e besselJ(N,a)%e Type: Expression(Integer) A possible solution is to drop the simplifyExp. But in my case it sufficiently reduces a number of terms in the exponet. So, are there any other ways around? среда, 23 апреля 2014 г., 7:08:30 UTC+4 пользователь Waldek Hebisch написал: > > a.a.letterbox wrote: > > > My idea is to use substitution rules. > > For xi ( eq. 10 ) it may look like > > > > xi_rule := rule xi(t) == Up * t - beta * sin( 2 * omg * t ) > > > > However, the application of xi_rule works only for Real-valued exponents > > and fails for complex-valued > > > > (17) -> xi_rule( exp( %i * xi(t) ) ) > > Cannot find a definition or applicable library operation named=20 > > xi_rule with argument type(s)=20 > > Expression(Complex(Integer)) > > <snip> > > Eq. (12) is a bigger problem however. > > It is necessary to define an identity > > > > exp( i * z * sin( theta ) ) = sum_{ N = -infty }^{+ infty } > > BesselJ_N( z ) * exp( i * N * theta ) > > > > ( see http://en.wikipedia.org/wiki/Jacobi=E2=80=93Anger_expansion ) > > My first idea was to use streams to represent infinite summations. > > Stream are good if you have order such that there is only finitely > many elements smaller than given element and you are satified > with finite approximation. Strength of streams is that you > do not need to specify how many elements are needed (they are > computed on demand). But usually streams loose information > about "tail". > > Problem with summation is similar to integral: you must fake > infinite bounds using symbols and there is problem trying > to evaluate unevaluated summation. There is no operator > to create unevaluated sum. > > > My second attempt was to define a rule without summation > > > > exp_to_bessel_rule := rule exp( %i * z * sin( t ) ) == _ > > besselJ(N, z ) * exp( %i * N * t ) > > > > This is not the best idea, since in the case of expression =20 > > > > exp( i * z * sin( theta ) ) * exp( i * x * sin( phi ) )=20 > > > > I'll get identical summation indices after substitution. > > But I was not able to apply even such simple rule: > > > > (23) -> exp_to_bessel_rule( exp( %i * z * sin(t) ) ) > > > > %i z sin(t) > > (23) %e > > Type: > Expression(Complex(Integer)) > > > > So, how do I do the substitution? > > This is just a bug. Possible workaround is to use 'sqrt(-1)' instead > of '%i': > > (19) -> exp_to_bessel_rule := rule exp(sqrt(-1)*z*sin(t)) == besselJ(N, > z)*exp(sexp_to_bessel_rule := rule exp(sqrt(-1)*z*sin(t)) == besselJ(N, > z)*exp(sqrt(-1)*N*t) > > +---+ +---+ > z\|- 1 sin(t) N t\|- 1 > (19) %e == 'besselJ(N,z)%e > Type: > RewriteRule(Integer,Integer,Expression(Integer)) > (20) -> exp_to_bessel_rule(exp(sqrt(-1)*z*sin(t))) > > +---+ > N t\|- 1 > (20) %e besselJ(N,z) > Type: > Expression(Integer) > > Using 'sqrt(-1)' you can compute complex conjugate of many expressions > via 'eval': > > (21) -> eval(exp(sqrt(-1)*z*sin(t)), sqrt(-1) = -sqrt(-1)) > > +---+ > - z\|- 1 sin(t) > (21) %e > Type: > Expression(Integer) > > I just commited fix for the bug to the repository, but note then > even with fix you may prefer to use 'sqrt(-1)' insted of '%i' in > rules, because '%i' does not match imaginary part of '2 + %i': > complex pattern matching considers '%i' and '2 + %i' to be to > distinct complex constants. OTOH 'sqrt(-1)' is considered "kernel" > and is matched separately form constants. > > If you do changes that are not mathematical equalities, then > 'eval' may be useful: > > (23) -> eval(exp(%i*u*sin(v)), exp(%i*u*sin(v)) = > besselJ(N,u)*exp(%i*N*v)) > > %i N v > (23) %e besselJ(N,u) > Type: > Expression(Complex(Integer)) > > because it gives more control (rules ignore variable names, while > eval matches only exact kernel). > > -- > Waldek Hebisch > [email protected] <javascript:> > -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/fricas-devel. For more options, visit https://groups.google.com/d/optout.
