Hi Constantine see below ...
Am 25.01.2017 um 17:56 schrieb Constantine Frangos: > > Hi Kurt, > > Thanks for the fast and very detailed response - much > appreciated. > > (1) Can the re-write rules be expressed in a "generic" way > so that they will work for: Yes. See e.g. https://kfp.bitbucket.io/fricas_book/section-6.21.xhtml how it works in detail ... > > (a) any symbolic arguments appearing in the trigonometric > functions, for example, > cos(x1)*sin(y)-sin(x1)*cos(y), > cos(x3)*sin(z)-sin(x3)*cos(z), etc rs:=rule cos(x)*sin(y)-sin(x)*cos(y) == sin(y-x) rs (cos(x1)*sin(y)-sin(x1)*cos(y)) --> sin(y - x1) > > (b) any order of appearance of the terms, > -sin(x1)*cos(y) + sin(y)*cos(x1), > -sin(x2)*sin(x3) + cos(x3)*cos(x2), etc rs (-sin(x1)*cos(y) + sin(y)*cos(x1)) --> sin(y - x1) > > (2) In your example below, you used "equations" for t1, t2, etc. > > In my question I was simply using t1 and t2 as auxiliary > variables and assigning the rhs to t1, t2, etc, in order to > construct the expression expr. That's the point. If you're using t1,t2 this way, look what happens: (1) -> t1 := cos(x)*sin(y) - cos(y)*sin(x) (1) cos(x)sin(y) - cos(y)sin(x) Type: Expression(Integer) (2) -> t2 := - sin(x)*sin(y) + cos(x)*cos(y) (2) - sin(x)sin(y) + cos(x)cos(y) Type: Expression(Integer) (3) -> expr := tan(q)*tan(w) + t1*cos(x3) + t2*w*cos(a) + r3*t1*t2 + 5 (3) 2 tan(q)tan(w) - r3 cos(x)sin(x)sin(y) + 2 2 (r3 cos(y)sin(x) - w cos(a)sin(x) + r3 cos(x) cos(y) + cos(x)cos(x3)) * sin(y) + 2 (- r3 cos(x)cos(y) - cos(x3)cos(y))sin(x) + w cos(a)cos(x)cos(y) + 5 Type: Expression(Integer) (4) -> As you can see there already is some automated simplification so that the simple rules rs,rc usually won't have any effect. Although FriCAS has a function "simplify", it's probably not what you want: (4) -> simplify expr (4) - w cos(a)cos(q)cos(w)sin(x) + r3 cos(q)cos(w)cos(y) + cos(q)cos(w)cos(x)cos(x3) * sin(y) + (- cos(q)cos(w)cos(x3)cos(y) - r3 cos(q)cos(w)cos(x))sin(x) + sin(q)sin(w) + w cos(a)cos(q)cos(w)cos(x)cos(y) + 5cos(q)cos(w) / cos(q)cos(w) Type: Expression(Integer) > > The idea is that the simplifying function I am looking for, > lets call it my_simplify(), be applied to any expression expr > containing trigonometric terms, as follows: > > expr_s := my_simplify(expr); > > Is this possible? Yes, at least theoretically ;) There are some packages that might help: http://fricas.github.io/api/search.html?q=trigonometric Take for example TranscendentalManipulations(R, F): click on the link "manip.spad line 434" and you will see the source code, where you'll get an idea how to start with. I would start by normalizing first: (5) -> normalize(expr) (5) a 2 a 2 x 4 ((tan(-) + 1)tan(q)tan(w) + (- w + 5)tan(-) + w + 5)tan(-) 2 2 2 + many many terms ... Type: Expression(Integer) Then you can apply rules/formulas which transform the tan(*/2) functions to any (valid) expression you like. It's not trivial but feasible if you exactly know how to specify the final form. > > > Thanks very much. > > Regards, > Constantine Frangos. > > > ----- Original Message ----- > From: "Kurt Pagani" <nil...@gmail.com> > To: "FriCAS - computer algebra system" <fricas-devel@googlegroups.com> > Cc: cfran...@telkomsa.net > Sent: Wednesday, January 25, 2017 3:51:54 AM > Subject: Re: fricas: trigonometric simplification. > > > Usually, this kind of task is not a CAS' strength because simplification > mostly relies on a normal form/representation. Even with rewrite rules I > cannot see a general pattern. However, waht you can do is sketched below, > namely using equations, rules and substitutions. Admittedly, it's more the > way theorem prover assistants works than automated simplifaction. If you have > well defined normal form this method may be turned into an algorithm as well, > of course. > > I don't know if you deliberatly used " = " (equations in Fricas) or it simpy > was a typo (:= means assignment), anyway, it was the inspiration for the > lines below: > > rs:=rule cos(x)*sin(y)-sin(x)*cos(y) == sin(y-x) > rc:=rule cos(x)*cos(y)-sin(x)*sin(y) == cos(x+y) > > eq1:= t1 = cos(x)*sin(y)-sin(x)*cos(y) > eq2:= t2 = cos(x)*cos(y)-sin(x)*sin(y) > eq3:= expr = t1*cos(x3) + 5 + tan(q)*tan(w) + t2*w*cos(a)+ t1*t2*r3 > > eq4:=expr = subst(rhs eq3,t1=rs rhs eq1) > eq5:=expr_s = subst(rhs eq4,t2=rc rhs eq2) > > > > > FriCAS Computer Algebra System > Version: FriCAS 1.3.0 > Timestamp: Wed Aug 31 20:31:31 GMT 2016 > ----------------------------------------------------------------------------- > Issue )copyright to view copyright notices. > Issue )summary for a summary of useful system commands. > Issue )quit to leave FriCAS and return to shell. > ----------------------------------------------------------------------------- > > (2) -> rs:=rule cos(x)*sin(y)-sin(x)*cos(y) == sin(y-x) > > (2) cos(x)sin(y) - cos(y)sin(x) + %B == sin(y - x) + %B > Type: RewriteRule(Integer,Integer,Expression(Integer)) > (3) -> rc:=rule cos(x)*cos(y)-sin(x)*sin(y) == cos(x+y) > > (3) - sin(x)sin(y) + cos(x)cos(y) + %C == cos(y + x) + %C > Type: RewriteRule(Integer,Integer,Expression(Integer)) > (4) -> > (4) -> eq1:= t1 = cos(x)*sin(y)-sin(x)*cos(y) > > (4) t1 = cos(x)sin(y) - cos(y)sin(x) > Type: Equation(Expression(Integer)) > (5) -> eq2:= t2 = cos(x)*cos(y)-sin(x)*sin(y) > > (5) t2 = - sin(x)sin(y) + cos(x)cos(y) > Type: Equation(Expression(Integer)) > (6) -> eq3:= expr = t1*cos(x3) + 5 + tan(q)*tan(w) + t2*w*cos(a)+ t1*t2*r3 > > (6) expr = tan(q)tan(w) + t1 cos(x3) + t2 w cos(a) + r3 t1 t2 + 5 > Type: Equation(Expression(Integer)) > (7) -> > (7) -> eq4:=expr = subst(rhs eq3,t1=rs rhs eq1) > > (7) expr = tan(q)tan(w) + (cos(x3) + r3 t2)sin(y - x) + t2 w cos(a) + 5 > Type: Equation(Expression(Integer)) > (8) -> eq5:=expr_s = subst(rhs eq4,t2=rc rhs eq2) > > (8) > expr_s > = > tan(q)tan(w) + (r3 cos(y + x) + cos(x3))sin(y - x) + w cos(a)cos(y + x) + 5 > > Type: Equation(Expression(Integer)) > (9) -> > > > Reagrding "rules", there is an excellent tutorial by Franz Lehner where you > will find more examples (Section 4.5, though it's in German, but that's not a > problem to undersrand the examples): > https://www.math.tugraz.at/mathc/compmath2/Demo/fricas-tutorium-0.6.pdf > > On Tuesday, 24 January 2017 23:38:52 UTC+1, Constantine Frangos wrote: > > > I wanted to ask for some assistance in using fricas to > perform some specific trigonometric simplifications. > > (1) The relevant fricas commands or re-write rules to perform > the following simplifications. > > t1 = cos(x)*sin(y)-sin(x)*cos(y) to sin(y-x), > > t2 = cos(x)*cos(y)-sin(x)*sin(y) to cos(x+y). > > (2) I have expressions which are sums of products of the > above-mentioned terms. For example, > > expr = t1*cos(x3) + 5 + tan(q)*tan(w) + t2*w*cos(a) > + t1*t2*r3 > > How can fricas commands be applied in order to simplify > expr to > > expr_s = sin(y-x)*cos(x3) + 5 + tan(q)*tan(w) + > cos(x+y)*w*cos(a) + sin(y-x)*cos(x+y)*r3 ? > > > Thanks very much. > > Regards, > Constantine Frangos. > -- 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 fricas-devel+unsubscr...@googlegroups.com. To post to this group, send email to fricas-devel@googlegroups.com. Visit this group at https://groups.google.com/group/fricas-devel. For more options, visit https://groups.google.com/d/optout.