On 04/23/2014 05:34 PM, [email protected] wrote:

    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%E2%80%93Anger_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
    <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] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>.
Visit this group at http://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Hello.
I had a break from work on this problem, but I still intend to do what I have planned.

To warm up, here is a question about Fricas substitution mechanism.

Suppose I have a following expression

)clear completely
e := exp( sqrt(-1) * a + sqrt(-1) * b )

And I want to substitue a + b -> c.

In a straightforward solution, sqrt(-1) disappears

r := rule a + b == c
s := r( e )

(3) ->
          c
   (3)  %e
Type: Expression(Integer)

This can be fixed by the following rule

r := rule ( %x*'a + %x*'b == %x*c )
s := r( e )

(5) ->
            +---+
          c\|- 1
   (5)  %e
Type: Expression(Integer)

But for a more complicated expression it fails:

e := exp( ( sqrt(-1) * a + sqrt(-1) * b ) * cos( t ) )
s := r( e )

(7) ->
                  +---+
          (b + a)\|- 1 cos(t)
   (7)  %e
Type: Expression(Integer)

Even the following rule doesn't lead to the desired answer:

r := rule ( (b + a) * sqrt(-1) * cos( t ) == c * sqrt(-1) * cos( t ) )
s := r( e )

(9) -> r( e )
                  +---+
          (b + a)\|- 1 cos(t)
   (9)  %e
Type: Expression(Integer)

Now, in my problem, there are operators instead of variables.

A := operator 'A
e := exp( ( sqrt(-1) * A(a) + sqrt(-1) * A(b) ) )

And I want to substitue A(a) + A(b) -> A(c).
In this case, a straightforward attemp fails:

r := rule A(a) + A(b) == A(c)
s := r( e )

(13) -> r( e )
            +---+        +---+
           \|- 1 A(b) + \|- 1 A(a)
   (13)  %e
Type: Expression(Integer)

The following rule works fine though

r := rule sqrt(-1) * A(a) + sqrt(-1) * A(b) == sqrt(-1) * A(c)
s := r( e )

(15) -> r( e )

            +---+
           \|- 1 A(c)
   (15)  %e
Type: Expression(Integer)

Unfortunately, if the expression becomes slightly more complicated, it fails too:

e := exp( ( sqrt(-1) * A(a) + sqrt(-1) * A(b) ) * cos( t ) )
s := r( e )

(17) -> r( e )

             +---+        +---+
           (\|- 1 A(b) + \|- 1 A(a))cos(t)
   (17)  %e
Type: Expression(Integer)

Again, a more complicated rule doesn't help:

r := rule ( ( sqrt(-1) * A(a) + sqrt(-1) * A(b) ) * cos(t) == sqrt(-1) * A(c) * cos(t) )
s := r( e )

(19) -> r( e )

             +---+        +---+
           (\|- 1 A(b) + \|- 1 A(a))cos(t)
   (19)  %e
Type: Expression(Integer)

So, how do I correctly perform the above substitutions?


--
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.

Reply via email to