Slawomir Kolodynski wrote:
> 
> >Instead, various routines analyze structure of expressions using lower 
> level operations. 
> 
> Could you give some examples of those lower level operations? Pattern 
> matching and rewrite rules seem very useful to me , but I am ok with doing 
> lower level operations if those fail. I know about numerator, denominator 
> and  monomials so for example I can do
> 
> e1 := (y-m)*x/s
> (monomials numerator e1)(1)
> 
> to get x*y
> 
> However when I try to do something similar with 
> 
> e2 := (y-m)*sqrt(x)/s
> numerator e2
> 
> to get (y-m)*sqrt(x), I don't know how then to extract the components of 
> this product.

Actually, it is a sum.
> Also, I could not find a way to extract an argument of a 
> function, for example if I have an expression
> 
> sin(a*x+b)
> 
> how to get the "a*x+b" part?

Crucial notion is "kernel".  Expression above is a single kernel
so you can retract it:

(11) -> ks := retract(sin(a*x + b))@Kernel(Expression(Integer))

   (11)  sin(a x + b)
                                            Type: Kernel(Expression(Integer))

'argument' gives you list of arguments of the kernel, 'operator'
gives the operator:
(12) -> argument(ks)

   (12)  [a x + b]
                                              Type: List(Expression(Integer))
(13) -> operator(ks)

   (13)  sin
                                                          Type: BasicOperator

You can use 'kernels' to get list of top level kernels contained in an
expression:
(14) -> kl := kernels(e2)                                      

           +-+
   (14)  [\|x , y, s, m]
                                      Type: List(Kernel(Expression(Integer)))

Using a kernel you can convert numerator to univariate polynomial
with respect to kernel:
(15) -> nu := univariate(numer(e2), kl(1))                     

   (15)  (y - m)?
Type: 
SparseUnivariatePolynomial(SparseMultivariatePolynomial(Integer,Kernel(Expression(Integer))))

And then extract coefficients:
(16) -> coefficient(nu, 1)

   (16)  y - m
      Type: SparseMultivariatePolynomial(Integer,Kernel(Expression(Integer)))

There is also 'tower', which gives all kernels (top level and nested):
(17) -> tower(e2)

                       +-+
   (17)  [m, s, x, y, \|x ]
                                      Type: List(Kernel(Expression(Integer)))

(Compared to 'kernels' we also get 'x' above).

Pattern matcher is implemented on top of 'numer', 'denom', 'isPlus' and
'isTimes', 'isExpt' and kernels handling.  For example:
(18) -> ne2 := numer(e2)::Expression(Integer)

                 +-+
   (18)  (y - m)\|x
                                                    Type: Expression(Integer)
(19) -> isTimes(ne2)

   (19)  "failed"
                                                    Type: Union("failed",...)
(20) -> isPlus(ne2) 

            +-+      +-+
   (20)  [y\|x , - m\|x ]
                                   Type: Union(List(Expression(Integer)),...)
(21) -> isTimes(isPlus(ne2).1)

           +-+
   (21)  [\|x , y]
                                   Type: Union(List(Expression(Integer)),...)

As you can see structure seen by pattern matcher is somewhat different
from printed form.  Note that 'isPlus' essentially gives you list
of monomials, 'isTimes' gives factors of single monomial.


-- 
                              Waldek Hebisch

-- 
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 https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to