mm-779 === Subject: Re: Function argument g[a_,func_, x_Symbol:x] := func/.x->a; g[a,f[x]] f(a) g[a,f[y],y] f(a) g[1,a*x^2+b*x+c] a+b+c g[1,a*z^2+b*z+c,z] a+b+c g[Pi,Sin[x]] 0 or just use Function Function[x,f[x]][a] f(a) f[#]&[a] f(a) Function[x,a*x^2+b*x+c][1] a+b+c a#^2+b#+c&[1] a+b+c Function[x,Sin[x]][Pi] 0 Sin[#]&[Pi] 0 > I would like to define a function g that evaluates another function f at a > given value. That is, > g[a, f[x]] := f[a] > For example, I might want the function f[x]=ax^2+bx+c to be evaluated at x=1 > and get the result a+b+c. That is, > g[1, ax^2+bx+c] should evaluate to a+b+c. > Again, I might want the function f[x]=Sin[x] to be evaluated at x=pi and get > the result 0. That is, > g[pi, Sin[x]] should evaluate to 0. > Is there a way to accomplish this in Mathematica? Any help would be > appreciated. > Bonny. -- hanlonr@cox.net === Subject: Re: Division by Zero (Error Handling) > When dividing (elementwise) two matrices of similar dimension (e.g., A/B), zero-elements in B cause a division by zero error message. In such a case, regardless of numerator, I want the pair's ratio to be zero. > Without building a module that defines modified matrix division, how can I establish that whenever (throughout the notebook) division by zero occurs (regardless of numerator), that the result can be zero? assumedly with a simple 'if...then..else' statement, or am i missing something? > Bruce === Subject: Re: Division by Zero (Error Handling) For the first part: f[x_List,y_List]:= x/(y/.(0->Infinity))/; Dimensions[x]==Dimensions[y]; A=Table[Random[Integer,{1,3}],{3},{3}] {{3, 1, 2}, {1, 3, 2}, {1, 3, 1}} B=Table[Random[Integer,{0,3}],{3},{3}] {{1, 2, 2}, {0, 3, 1}, {3, 1, 3}} f[A,B] {{3, 1/2, 1}, {0, 1, 2}, {1/3, 3, 1/3}} > When dividing (elementwise) two matrices of similar dimension (e.g., A/B), zero-elements in B cause a division by zero error message. In such a case, regardless of numerator, I want the pair's ratio to be zero. > Without building a module that defines modified matrix division, how can I establish that whenever (throughout the notebook) division by zero occurs (regardless of numerator), that the result can be zero? > Bruce -- hanlonr@cox.net === Subject: RE: Function argument Hi Bonny, Maybe I am missing your point, but it not a good idea to have f[x] as the second argument of g[a,f[x]]. Since we have not told which part of the expression f[x] which is the function, and which part is the argument, we will get into trouble if we substitute f1[f2[x]] as second argument to g. Should it evaluate to f1[a], or to f1[f2[a]]? We also will get into trouble in other cases. For instance, should the expression a x^2 + b x + c be seen as a function of x, or of a, b or c? You could define g[a_, f_] := f[a] if you are not satisfied with the usual notation f[a] or f@a. (What is wrong with these notations?) Then g[Pi, Sin] evaluates to 0. If you have set f[x_] := a x^2 + b x + c then g[1, f] will evaluate to a + b + c . Also g[1, Function[{x}, a x^2 + b x + c]] , g[1, (a #^2 + b # + c) &] , a x^2 + b x + c /. x -> 1 and x=1; a x^2 + b x + c will give this result, and there are surely a number of additional ways. -----Original Message----- === Subject: Function argument I would like to define a function g that evaluates another function f at a given value. That is, g[a, f[x]] := f[a] For example, I might want the function f[x]=ax^2+bx+c to be evaluated at x=1 and get the result a+b+c. That is, g[1, ax^2+bx+c] should evaluate to a+b+c. Again, I might want the function f[x]=Sin[x] to be evaluated at x=pi and get the result 0. That is, g[pi, Sin[x]] should evaluate to 0. Is there a way to accomplish this in Mathematica? Any help would be appreciated. Bonny. === Subject: Re: Re: Colored Tick Labels? Unfortunately it seems that AbsoluteOptions[] applies N[] to all its output. Tick labels that were not floating-point numbers will get corrupted. For example try with AbsoluteOptions[Plot[Sin[x], {x, 0, Pi}, Ticks -> {{E}, {1/2}}], Ticks] Any exact numeral in PlotLabel will be affected too. Gianluca Gorni > Not sure I have a complete answer, but here are some possibilities to > examine: > Suppose you have the following plot > plt = Plot[Sin[x], {x, -1, 1}] > You can extract the Ticks from this plot using AbsoluteOptions and > then > modify them. In the following example I make the x tick values Blue > and > the y tick values Red > myTicks = {(Ticks /. AbsoluteOptions[plt, > Ticks])[[1]] /. {x_Real, y_Real, z__} -> {x, StyleForm[y, > FontColor -> Blue], z}, (Ticks /. AbsoluteOptions[plt, > Ticks])[[ > 2]] /. {x_Real, y_Real, z__} -> {x, > StyleForm[y, FontColor -> Red], z}} === Subject: Caret In a text cell, I want to put a caret over a multi-letter variable name, one that spans the variable's full length. The caret box on the Basic Input palette puts a caret in the middle of the variable, and changing size doesn't create a spanning caret. How can I create a spanning caret? Bruce === Subject: <> doesn't work in filename in a batch mode ? When i used : dir = /home/bar/TMP/; lists >> dir <> filename.lst; it works correctly in graphical mode (notebook) When i try use it in batch mode ( math < file.m) i obtained: Syntax::sntxf: lists>>dir cannot be followed by <>filename.lst;. Why ? === Subject: Re: Mathematica Font problems > In the Tutorial, on Page 10, the last equation, if the right arrow is > selected alone, > the Mathematica Format>Font menu shows Courier New. > In the Program Files folder, the Mathematica installation has a Fonts > folder > which has two sub-folders, TrueType and Type1. > The TrueType folder is all Mathematica1.ttf-Mathematica7mb.ttf. > The Type1 folder has four Courier fonts: cour.pfa, courb.pfa, courbi.pfa > and couri.pfa. > There are 48 fonts in the Type1 folder including the Mathematica1.pfa > series. > I looked at the files with WinHex and the beginning of the cour.pfa file > says PS-AdobeFont-1.0 Courier 001.003. > So these are clearly Courier fonts that I believe are used by Mathematica to > have the special characters like the right arrow. I believe these Type1 fonts are only used for PostScript export. Mathematica really does substitute Mathematica1Mono for Courier when it draws this character. You can verify this by evaluating: DisplayString[Graphics[Text[ StyleForm[a[Rule]b, FontFamily -> Courier], {0, 0}]]] Note in the PostScript output that a and b are drawn with Courier, while the [Rule] is drawn with Mathematica1Mono: /Courier-MISO findfont 10.000 scalefont [1 0 0 -1 0 0 ] makefont setfont 0.000 0.000 0.000 setrgbcolor (a) show 69.000 13.000 moveto %%IncludeResource: font Mathematica1Mono %%IncludeFont: Mathematica1Mono /Mathematica1Mono findfont 10.000 scalefont [1 0 0 -1 0 0 ] makefont setfont 0.000 0.000 0.000 setrgbcolor (256) show 76.188 13.000 moveto %%IncludeResource: font Courier-MISO %%IncludeFont: Courier-MISO /Courier-MISO findfont 10.000 scalefont [1 0 0 -1 0 0 ] makefont setfont 0.000 0.000 0.000 setrgbcolor (b) show User Interface Developer Wolfram Research === Subject: How can I use multiple filename ? Hi , When I try : For[i=1,i<10, name=a<>ToString[i]; i>>name; i++]; it doesn'w work Could You help me ? === Subject: Re: How to generate sections, subsections, etc. automatically? Will this do the trick: calc[n_] := Integrate[x^n, x]; mycalculations[i_] := Module[{}, CellPrint[Cell[Calulation Number <> ToString[i], Section, TextAlignment -> Center]]; CellPrint[Cell[The value for parameter i in this calculation is: i = <> ToString[i], Text]]; CellPrint[Cell[BoxData[ToBoxes[calc[i]]], Output]];]Table[mycalculations[i], {i, 1, 4}]; Brian > My code gives multiple output, each of which I wish to put under a > different section. Is it possible to generate a section within a > notebook automatically, without using the toolbar to do so? === Subject: Re: LaTeX and the ConversionRules option I believe the user is asking three distinct questions: 1. How do you write a ConversionRule that handles both inline and top level cells independently? 2. How do you write ConversionRules that will form both syntactically and functionally appropriate TeX environments? 3. How do you write ConversionRules that will preserve cross references? Mathematica's TeXExport can already satisfy questions 1 and 3 in a straightforward manner by using ConversionRules. However, question 2, regarding the handling of environments, may require additional formatting. Both techniques are illustrated below. Note, Publicon is another Wolfram product that can export to TeX. Publicon may be easier to use for TeXExport than Mathematica because Publicon offers templated documents with predefined conversion rules that correspond directly to specific LaTeX Packages. Answers to questions: 1. How do you write a ConversionRule that handles both inline and top level cells independently? First note that the rhs of a TeX ConversionRule must be a List whose contents are either two scalar, three scalar, or two List elements. Examples: a) TeX ConversionRule whose rhs is a List of two scalars: ConversionRules:>{TeX->{macroname{, }}} b) TeX ConversionRule whose rhs is a List of three scalars: ConversionRules:>{TeX->{macroname{, Identity, }}} c) TeX ConversionRule whose rhs is a List of two Lists: ConversionRules:>{TeX->{{lead text, InlineConversionFunction, trail text}, {lead text, TopLevelConversionFunction, trail text}}} The format we need to answer question 1 is found in Example c, where the rhs of the ConversionRule is a List of two Lists. The two inner List elements define a ConversionRule for inline cells and separate one ConversionRule for inline cells is defined as {lead text, InlineConversionFunction, trail text}, where the first and third elements of the list are always strings that are pre- and postpended, respectively, to the inline conversion. The second element is the conversion function itself. The second list is defined as {lead text, TopLevelConversionFunction, trail text} It works in the same manner as the inline ConversionRule, but it only acts on the top level cell as a whole. 2. How do you write ConversionRules that will form both syntactically and functionally appropriate TeX environments? If the content of the environment comes from only on a single cell, like a single paragraph abstract, you could use a ConversionRule that is similar to the following: Example1--Style definition for Abstract: Cell[StyleData[Abstract], . . . ConversionRules:>{TeX->{begin{abstract}n,nend{abstract }}} ] This ConversionRule, TeX->{begin{abstract}n,nend{abstract}}, will produce an abstract environment that looks like: begin{abstract} Contents of the abstract cell end{abstract} However, if you want to produce a TeX environment that contains contents from multiple, contiguous cells, the ConversionRule in Example1 won't work correctly. Example 2: Assume the Abstract style definition from Example 1. Also assume that the notebook we want export to TeX contains the following Abstract Cells: Cell[Paragraph1, Abstract], Cell[Paragraph2, Abstract], Cell[Paragraph3, Abstract], Cell[Paragraph4, Abstract] According to the Abstract style definition from Example 1, the TeX conversion rule prepends begin{abstract}n to each cell's contents and postpends nend{abstract}. Consequently, when we export to TeX, TeXExport produces the following: begin{abstract} Paragraph1 end{abstract} begin{abstract} Paragraph2 end{abstract} begin{abstract} Paragraph3 end{abstract} begin{abstract} Paragraph4 end{abstract} The output above isn't really appropriate. What we really want is the following: begin{abstract} Paragraph1 Paragraph2 Paragraph3 Paragraph4 end{abstract} To achieve the latter without generating an independent environment for each cell, you will need to insert cells that do not contain content and that precede and follow the cells to be included in the environment. We can define these cells as BeginAbstract and EndAbstract where their style definitions are: Cell[StyleData[BeginAbstract], . . . ConversionRules:> TeX->{begin{abstract}n,}} ] and Cell[StyleData[EndAbstract], . . . ConversionRules:> TeX->{,nend{abstract}}} ] and redefine Abstract, without a specific ConversionRule. Cell[StyleData[Abstract], . . . ] Note, a style definition that does not specify a ConversionRule assumes TeXExports default conversion. It doesn't mean there won't be any output when the notebook is exported to TeX. Using the Cells from earlier in the example, but applying the new definition of Abstract and inserting the newly defined BeginAbstract and EndAbstract cells above and below we have: Cell[, BeginAbstract], Cell[Paragraph1, Abstract], Cell[Paragraph2, Abstract], Cell[Paragraph3, Abstract], Cell[Paragraph4, Abstract]. Cell[, EndAbstract] When exported the Abstract environment should look like this. begin{abstract} Paragraph1 Paragraph2 Paragraph3 Paragraph4 end{abstract} I will leave it as an exercise to the user to apply this technique to nesting environments like enumerate or itemize. 3. How do you write ConversionRules that will preserve cross references? In Publicon we use ButtonBoxes to handle cross references. Specifically we use a ButtonBox of style XRef for what becomes ref{} in the TeX Stylesheet of Publicon. Cell[StyleData[XRef], ConversionRules:>{TeX -> {{ref{, ExtractButtonData[ CounterTag], }}, {, Automatic, }}, HTML -> { , XRefToHtmlHyperlink, }}, StyleMenuListing->None] Note, we are using a function, ExtractButtonData[], to extract the CounterTag from the Button Data to set the ref{} macro. Although the ConversionRule does not explicitly set the label{} macro it would be a straightforward Conversion Rule to write. The ConversionRule should work fine in Mathematica, but you will still need to either define ExtractButtonData in a package that you load prior to TeXSaving or write the function code directly in the ConversionRule. -- David Rogers Documentation Programmer Wolfram Research === Subject: Table through zero...strange When i type in Mathematica (version 4) Table[x, {x, -0.1, 0, 0.02}] it gives me {-0.1, -0.08, -0.06, -0.04, -0.02, -3.46945 x 10-18]} but for example Table[x, {x, -0.1, 0, 0.05}] will give a reasonable {-0.1, -0.05, 0.}. Probably a very stupid question but i can't figure out why the zero makes problem. === Subject: .NET/Link and two-dimensional strings The following two lines export a jpeg file containing RED text when executed in a notebook: myText=!(*StyleBox[my text,nFontColor->RGBColor[1, 0, 0]]); Export[C:TempmyText.jpg,Show[Graphics[Text[myText,{0,0}]]]]; If I put these same lines in a file called myText.txt, and then read this file with the following .NET code, the kernel produces a jpeg file containing BLACK text. using System; using System.IO; using Wolfram.NETLink; namespace WriTest { static class Program { static void Main() { MathKernel mathKernel = new MathKernel(); StreamReader streamReader = new StreamReader(@C:TempmyFile.txt); string command1 = streamReader.ReadLine(); string command2 = streamReader.ReadLine(); streamReader.Close(); mathKernel.Compute(command1); string result1 = mathKernel.Result.ToString(); mathKernel.Compute(command2); string result2 = mathKernel.Result.ToString(); } } } Note an examination of command1 within the debugger, just before it is sent to the kernel, produces the following string: myText=!(*StyleBox[my text,nFontColor->RGBColor[1, 0, 0]]); Wrapping ToExpression around this string in a Mathematica notebook results in the desired red text. This problem seems to be related to the need for the StyleBox which can only be found in a two-dimensional string. Other two dimensional string also lead to problems. What is my problem? Colin === Subject: Re: Function argument >I would like to define a function g that evaluates another function >f at a given value. That is, >g[a, f[x]] := f[a] >For example, I might want the function f[x]=ax^2+bx+c to be >evaluated at x=1 and get the result a+b+c. That is, >g[1, ax^2+bx+c] should evaluate to a+b+c. Note in Mathematica ax is distinctly different from a x or a*x. So, unless g is written in an unusual way, g[1,ax^2+bx+c] will not evaluate to a+b+c But it is quite easy to create a function that will return what you want given the arguments 1 and a*x^2+b*x+c. For example, In[1]:= g[a_, f_] := f /. x -> a In[2]:= g[1,a x^2+b x+c] Out[2]= a+b+c >Again, I might want the function f[x]=Sin[x] to be evaluated at x=pi >and get the result 0. That is, >g[pi, Sin[x]] should evaluate to 0. In[3]:= g[Pi,Sin[x]] Out[3]= 0 Note, the definition I've used for g assumes x as the independent variable. Also, I wonder why you want such a function since it as easy (if not easier) to write In[4]:= a x^2 + b x + c /. x -> 1 Out[4]= a+b+c instead of g[1,a x^2+b x+c] -- === Subject: Re: schur decomposition and mathematica > Jeremy, > That is correct. If the eigenvalues are complex, they appear in 2X2 > blocks along the diagonal of T in the decomposition A=Q.T.Q* . In your > case the eigenvalues are complex > mat={{-5.0, 7.0, 6.0, -3.0}, {2.0, -8.0, 3.0, 9.0}, > {7.0, 1.0, 2.0, -7.0}, {3.0, 4.0, 4.0, 4.0}}; > Eigenvalues[mat] > {-9.80269 + 0.336644 I, -9.80269 - 0.336644 I, > 6.30269 + 4.81699 I, 6.30269 - 4.81699 I} > Now consider the Schur decomposition of mat > {Q, T} = SchurDecomposition[mat] > The T matrix is > {{6.30269,-6.10921,1.83689,5.59659},{3.79811,6.30269, > 1.7072,6.28934},{0.,0.,-9.80269,6.03753},{0.,0.,-0.0187708,-9.80269}} > Thus in the first 2x2 block the diagonal values are the real part > (6.30269) and the off-diagonal terms can be used to construct the > imaginary part as follows: > Sqrt[T[[1,2]]*T[[2,1]]] > 0. + 4.8169937117972985*I > Hope this helps, > Brian i thought that that might be the case, but technically i thought T had to be strictly upper triangular, which in this case it is not. i did write my own schur decomposition program recently and went through all sorts of problems trying to 'iron out' these 2x2 buldges (which i did eventually), but maybe now i shouldnt have bothered... who am i to argue with steven wolfram :) > {Q, T} = SchurDecomposition[] > why upon entering :- > SchurDecomposition[{{-5.0, 7.0, 6.0, -3.0}, {2.0, -8.0, 3.0, 9.0}, {7.0, > 1.0, 2.0, -7.0}, {3.0, 4.0, 4.0, 4.0}}] > does mathematica return a 'T matrix' that is not upper triangular? > some the eigenvalues are complex, so is it because these eigenvalues reside > along the diagonal of 'T' in 2x2 blocks? === Subject: Re: Re: schur decomposition and mathematica > Jeremy, > That is correct. If the eigenvalues are complex, they appear in 2X2 > blocks along the diagonal of T in the decomposition A=Q.T.Q* . If all the elements are real or integer valued. The following: SchurDecomposition[{{-5.0 + 0.0 I, 7.0, 6.0, -3.0}, {2.0, -8.0, 3.0, 9.0}, {7.0, 1.0, 2.0, -7.0}, {3.0, 4.0, 4.0, 4.0}}] returns a triangular decomposition, if you'd rather save yourself the work of searching for and computing the eigenvalues of 2x2 blocks. >> why upon entering :- >> SchurDecomposition[{{-5.0, 7.0, 6.0, -3.0}, {2.0, -8.0, 3.0, 9.0}, >> {7.0, >> 1.0, 2.0, -7.0}, {3.0, 4.0, 4.0, 4.0}}] >> does mathematica return a 'T matrix' that is not upper triangular? >> some the eigenvalues are complex, so is it because these >> eigenvalues reside >> along the diagonal of 'T' in 2x2 blocks? === Subject: Re: Animate have you tried clicking on the right-hand bracket enclosing all six plots, thus collapsing them into a single animation? Bye Ben > Hey everyone > Module[{n}, Animate[Plot[Sin[n x], {x, 0, 2 Pi}], {n, 1, 6, 1}]]; > running the above command doesn't yield an animation in one plot, but > much rather six different still plots which appear one beneath the > other. > Any ideas? === Subject: Re: Function argument you almost provided the solution yourself Bye Ben In[6]:= f1[x_]:=Sin[x] f2[x_]:=x^2+43 In[9]:= g[a_,h_]:=h[a] In[14]:= g[[Pi],f1] g[1,f2] Out[14]= 0 Out[15]= 44 > I would like to define a function g that evaluates another function f at a > given value. That is, > g[a, f[x]] := f[a] > For example, I might want the function f[x]=ax^2+bx+c to be evaluated at x=1 > and get the result a+b+c. That is, > g[1, ax^2+bx+c] should evaluate to a+b+c. > Again, I might want the function f[x]=Sin[x] to be evaluated at x=pi and get > the result 0. That is, > g[pi, Sin[x]] should evaluate to 0. > Is there a way to accomplish this in Mathematica? Any help would be > appreciated. > Bonny. === Subject: Re: Function argument > I would like to define a function g that evaluates another function f at a > given value. That is, > g[a, f[x]] := f[a] > For example, I might want the function f[x]=ax^2+bx+c to be evaluated at x=1 > and get the result a+b+c. That is, > g[1, ax^2+bx+c] should evaluate to a+b+c. Presumably you mean a x^2+b x + c, right? (Note the spaces between a and x^2, and between b and x). > Again, I might want the function f[x]=Sin[x] to be evaluated at x=pi and get You mean x=Pi, right? > the result 0. That is, > g[pi, Sin[x]] should evaluate to 0. > Is there a way to accomplish this in Mathematica? Any help would be > appreciated. g[a_,f_]:=f/.{x->a} will do what you want. -- Helen Read University of Vermont === Subject: Re: Function argument > I would like to define a function g that evaluates another function f at a > given value. That is, > g[a, f[x]] := f[a] > For example, I might want the function f[x]=ax^2+bx+c to be evaluated at x=1 > and get the result a+b+c. That is, > g[1, ax^2+bx+c] should evaluate to a+b+c. > Again, I might want the function f[x]=Sin[x] to be evaluated at x=pi and get > the result 0. That is, > g[pi, Sin[x]] should evaluate to 0. > Is there a way to accomplish this in Mathematica? Any help would be > appreciated. > Bonny. g[a_,f_[x_]]:=f[a] ?? === Subject: Re: Function argument g[a_, b_] := Evaluate[b][a] g[Pi, Sin] --> 0 > I would like to define a function g that evaluates another function f at a > given value. That is, > g[a, f[x]] := f[a] > For example, I might want the function f[x]=ax^2+bx+c to be evaluated at x=1 > and get the result a+b+c. That is, > g[1, ax^2+bx+c] should evaluate to a+b+c. > Again, I might want the function f[x]=Sin[x] to be evaluated at x=pi and get > the result 0. That is, > g[pi, Sin[x]] should evaluate to 0. > Is there a way to accomplish this in Mathematica? Any help would be > appreciated. > Bonny. === Subject: Re: Function argument Bonny, Try this: In[23]:= f1[x_] := a*x^2 + b*x + c f2[x_] := Sin[x] g[a_, f_] := f[a] In[31]:=g[1,f1] Out[31]=a+b+c In[32]:=g[Pi,f2] Out[32]=0 Hope this helps, Brian > I would like to define a function g that evaluates another function f at a > given value. That is, > g[a, f[x]] := f[a] > For example, I might want the function f[x]=ax^2+bx+c to be evaluated at x=1 > and get the result a+b+c. That is, > g[1, ax^2+bx+c] should evaluate to a+b+c. > Again, I might want the function f[x]=Sin[x] to be evaluated at x=pi and get > the result 0. That is, > g[pi, Sin[x]] should evaluate to 0. > Is there a way to accomplish this in Mathematica? Any help would be > appreciated. > Bonny. === Subject: Re: Function argument > I would like to define a function g that evaluates another function f at a > given value. That is, > g[a, f[x]] := f[a] Better to just refer to function f by name rather than having to pass the evaluation of f at 'x' every time you call g: g[a_,f_]:=f[a] f[x_]:=a*x^2+b*x+c g[f,1] g[Pi,Sin] -- === Subject: Re: Function argument > I would like to define a function g that evaluates another function f at a > given value. That is, > g[a, f[x]] := f[a] > For example, I might want the function f[x]=ax^2+bx+c to be evaluated at x=1 > and get the result a+b+c. That is, > g[1, ax^2+bx+c] should evaluate to a+b+c. > Again, I might want the function f[x]=Sin[x] to be evaluated at x=pi and get > the result 0. That is, > g[pi, Sin[x]] should evaluate to 0. > Is there a way to accomplish this in Mathematica? Any help would be > appreciated. > Bonny. Hi Bonny, What about the following definition for the function g: In[1]:= g[a_, f_] := f[a] You can test it with different types of expressions: In[2]:= g[0, Sin] Out[2]= 0 In[3]:= g[0, Cos] Out[3]= 1 In[4]:= h[x_] := x^2 In[5]:= g[3, h] Out[5]= 9 In[6]:= g[1/2, 1/#1 & ] Out[6]= 2 HTH, Jean-Marc === Subject: RE: Animate First of all : You don't have to use Module. n is a automatically treated like you wish. Animate is not worth while. Just use Table. You will not have to load any package and it will do exactly the same. After the 6 plots will be created, just double-click on the bracket of the group of plots (so they will be grouped), and then double-click on the graphic. Table[Plot[Sin[n x], {x, 0, 2 Pi}], {n, 1, 6, 1}]; If you really want to have an automatic grouping and creation of the animation, you can proceed like this, but it's not really meant for beginners : (Plot[Sin[#1*x], {x, 0, 2*Pi}, PlotRange -> {-1, 1}, PlotLabel -> ToString[#1]] & ) /@ Range[6]; SelectionMove[EvaluationNotebook[], All, GeneratedCell]; FrontEndTokenExecute[OpenCloseGroup] FrontEndTokenExecute[SelectionAnimate]; F.Jaccard -----Message d'origine----- DeÊ: MR [mailto:marcinrak@gmail.com] Envoy.8eÊ: lundi, 5. juin 2006 09:48 ËÊ: mathgroup@smc.vnet.net ObjetÊ: Animate Hey everyone Module[{n}, Animate[Plot[Sin[n x], {x, 0, 2 Pi}], {n, 1, 6, 1}]]; running the above command doesn't yield an animation in one plot, but much rather six different still plots which appear one beneath the other. Any ideas? === Subject: RE: Animate You have to select the group of 6 graphics cells, close them up, and then double click on the image to start the animation. Or just double click on any image without closing them up. Alternatively, you could attach the following lines of code, which will automatically do this for you. Needs[Graphics`Animation`] Module[{n}, Animate[Plot[Sin[n x], {x, 0, 2 Pi}], {n, 1, 6, 1}]] SelectionMove[EvaluationNotebook[], All, GeneratedCell] FrontEndTokenExecute[OpenCloseGroup]; Pause[0.5]; FrontEndExecute[{FrontEnd`SelectionAnimate[200, AnimationDisplayTime -> 0.1, AnimationDirection -> Forward]}] The 'A' button from the DrawGraphics palette that comes with the DrawGraphics package, for those who have it, will paste in those lines of code. Also, don't forget that you can control the animation with keyboard keys. 1) up/down arrows will advance one frame at a time. 2) left/right arrows will start animation in forward or reverse direction. 3) 'p' will pause or restart the animation. 4) 'c' will put the animation in the ForwardBackward mode. 5) The number keys will control the speed of the animation. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Hey everyone Module[{n}, Animate[Plot[Sin[n x], {x, 0, 2 Pi}], {n, 1, 6, 1}]]; running the above command doesn't yield an animation in one plot, but much rather six different still plots which appear one beneath the other. Any ideas? === Subject: Re: Function argument Bonny, One way this can be done is (which I think you already know) f1[x_] := ax^2+bx+c f2[x_]:=Sin[x] g[a_,f_]:=f[a] Then, g[1,f1]=a+b+c g[pi,f2]=0 Another way is the following. Does not seem the best way, but will work as long as your function f(.) is always in terms of the same variable, say *x.* Define, g[a_,b_]:=b /. x->a Then, g[1,ax^2+bx+c] =a+b+c g[pi,Sin[x]] = 0 Best, Bharat. > I would like to define a function g that evaluates another function f at a > given value. That is, > g[a, f[x]] := f[a] > For example, I might want the function f[x]=ax^2+bx+c to be evaluated at > x=1 > and get the result a+b+c. That is, > g[1, ax^2+bx+c] should evaluate to a+b+c. > Again, I might want the function f[x]=Sin[x] to be evaluated at x=pi and > get > the result 0. That is, > g[pi, Sin[x]] should evaluate to 0. > Is there a way to accomplish this in Mathematica? Any help would be > appreciated. > Bonny. ------=_Part_5942_27787247.1149522588839
Bonny,
 
One way this can be done is (which I think you already know)
f1[x_] := ax^2+bx+c
f2[x_]:=Sin[x]
g[a_,f_]:=f[a]
 
Then,
g[1,f1]=a+b+c
g[pi,f2]=0
 
Another way is the following. Does not seem the best way, but will work as long as your function f(.) is always in terms of the same variable, say x.
Define,
 
g[a_,b_]:=b /. x->a
 
Then,
g[1,ax^2+bx+c] =a+b+c
g[pi,Sin[x]] = 0
 
Best,
Bharat.
 
 
 


 
I would like to define a function g that evaluates another function f at a
given value. That is,

g[a, f[x]] := f[a]

For example, I might want the function f[x]=ax^2+bx+c to be evaluated at x=1
and get the result a+b+c. That is,

g[1, ax^2+bx+c] should evaluate to a+b+c.

Again, I might want the function f[x]=Sin[x] to be evaluated at x=pi and get ------=_Part_5942_27787247.1149522588839-- === Subject: RE: Function argument Bonny, First, write your definition with patterns and with a SetDelayed. g[a_, f_] := f[a] Then you can just supply function names... g[Pi, Sin] 0 g[a, f] f[a] or you can supply pure functions (Look up Function in Help), which act as function names. g[1, a#^2 + b# + c &] a + b + c David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ I would like to define a function g that evaluates another function f at a given value. That is, g[a, f[x]] := f[a] For example, I might want the function f[x]=ax^2+bx+c to be evaluated at x=1 and get the result a+b+c. That is, g[1, ax^2+bx+c] should evaluate to a+b+c. Again, I might want the function f[x]=Sin[x] to be evaluated at x=pi and get the result 0. That is, g[pi, Sin[x]] should evaluate to 0. Is there a way to accomplish this in Mathematica? Any help would be appreciated. Bonny. === Subject: Re: piecewise integration Actually, even I have used the PiecewiseIntegrate package before. Maxim mentioned it in answer to a problem I had with DSolve & a Piecewise forcing function. I have also noticed the problem with DiracDelta functions occurring at the end points of integration. This makes me wonder how they are handled by DSolve and NDSolve. I am not presently at a Mathematica capable computer, so I can't test it. > *This message was transferred with a trial version of CommuniGate(tm) Pro* > The Integrate result seems pretty weak. Is there any way to obtain a > more explicit exact answer besides manually converting the Piecewise > function to two UnitStep functions? Can the same be done if the > final > limit of integration is a variable? in load[x_]=-9*10^3*DiracDelta[x]+Piecewise[{{x*10*(10^3/3), > 0<=x<=3}}]-6*10^3*DiracDelta[x-5]//InputForm out -6000*DiracDelta[-5 + x] - 9000*DiracDelta[x] + > Piecewise[{{(10000*x)/3, 0 <= x <= 3}}, 0] in Integrate[load[x],{x,0,5}]//InputForm out Integrate[InputForm[-6000*DiracDelta[-5 + x] - 9000*DiracDelta[x] + > Piecewise[{{(10000*x)/3, 0 <= x <= 3}}, 0]], {x, 0, 5}] -- > http://chris.chiasson.name/ > I am sure Maxim does not need my help to advertise his package but >> somehow people still keep posting such questions with surprising >> frequency. > It shouldn't surprise you. Such questions will continue to be posted > frequently until Mathematica _itself_ can adequately handle > integration of > Piecewise functions. > No doubt you are right, but I was referring to the fact that I > mentioned the package in a related context only a few days earlier > and Maxim has posted several times in detail on this topic. So I > naturaly felt a little bit like a person trying to help another > person with a Sisyphean task. >> Even if for some reason you do not want to use a third >> party package you can always look at the Mathematica code inside, >> which should answer questions such as these. >> load[x_] = -9*10^3* >> DiracDelta[x] + Piecewise[{{x*10*(10^3/3), 0 <= >> x <= 3}}] - 6*10^3*DiracDelta[x - 5]; >> << piecewise` >> In[3]:= >> PiecewiseIntegrate[load[x],{x,0,5}] >> Out[3]= >> 0 > That might or might not be what Chris wanted. It depends on whether he > wanted integration of DiracDelta to be handled as Mathematica does > or as > PiecewiseIntegrate does. > Using Mathematica, we have, for example, > In[28]:= Integrate[DiracDelta[x],{x,0,2}] > Out[28]= 1/2 > rather than 1, which I infer is what PiecewiseIntegrate would do. > I confess that I never noticed that Integrate and DiracDelta in > Mathematica behaved like this at end points. It seems to me that the > Piecewise approach, which assumes that boundary points are treated > the same as interior points, is the more natural. But Chris obviously > was not interested in the answer to this particular problem but in > more general matters. It is trivial to modify the behaviour of the > package in this respect (by adding ones own rules for handling > DiracDelta) to make it conform with what Mathematica does, if one > really wanted to. But my main point was that the package is > interesting in its own right and it seems to me that anyone seriously > interested in this topic would have already taken a look at it. Why, > even people not seriously interested in it, like myself, have done so > and found interesting and instructive things in it. > Andrzej > If Chris really wanted the integration of the DiracDelta functions > to be > handled as Mathematica does, then I should think he'd want > Integrate[load[x],{x,0,5}] to return 7500, rather than your Out[3]=0. > David >> In[4]:= >> PiecewiseIntegrate[load[x], {x, 0, a}] >> Out[4]= >> If[Inequality[0, Less, a, LessEqual, 3], (5000*a^2)/3, 0] + If[3 < a, >> 15000, 0] + If[a < 0, 9000, 0] + If[0 <= a, -9000, 0] + >> If[5 <= a, -6000, 0] >> Andrzej Kozlowski -- http://chris.chiasson.name/ === Subject: Re: piecewise integration > The Integrate result seems pretty weak. Is there any way to obtain a > more explicit exact answer besides manually converting the Piecewise > function to two UnitStep functions? Can the same be done if the > final > limit of integration is a variable? > in > load[x_]=-9*10^3*DiracDelta[x]+Piecewise[{{x*10*(10^3/3), > 0<=x<=3}}]-6*10^3*DiracDelta[x-5]//InputForm > out > -6000*DiracDelta[-5 + x] - 9000*DiracDelta[x] + > Piecewise[{{(10000*x)/3, 0 <= x <= 3}}, 0] > in > Integrate[load[x],{x,0,5}]//InputForm > out > Integrate[InputForm[-6000*DiracDelta[-5 + x] - 9000*DiracDelta[x] + > Piecewise[{{(10000*x)/3, 0 <= x <= 3}}, 0]], {x, 0, 5}] > -- > http://chris.chiasson.name/ >> I am sure Maxim does not need my help to advertise his package but >> somehow people still keep posting such questions with surprising >> frequency. > It shouldn't surprise you. Such questions will continue to be posted > frequently until Mathematica _itself_ can adequately handle > integration of > Piecewise functions. No doubt you are right, but I was referring to the fact that I mentioned the package in a related context only a few days earlier and Maxim has posted several times in detail on this topic. So I naturaly felt a little bit like a person trying to help another person with a Sisyphean task. >> Even if for some reason you do not want to use a third >> party package you can always look at the Mathematica code inside, >> which should answer questions such as these. >> load[x_] = -9*10^3* >> DiracDelta[x] + Piecewise[{{x*10*(10^3/3), 0 <= >> x <= 3}}] - 6*10^3*DiracDelta[x - 5]; >> << piecewise` >> In[3]:= >> PiecewiseIntegrate[load[x],{x,0,5}] >> Out[3]= >> 0 > That might or might not be what Chris wanted. It depends on whether he > wanted integration of DiracDelta to be handled as Mathematica does > or as > PiecewiseIntegrate does. > Using Mathematica, we have, for example, > In[28]:= Integrate[DiracDelta[x],{x,0,2}] > Out[28]= 1/2 > rather than 1, which I infer is what PiecewiseIntegrate would do. I confess that I never noticed that Integrate and DiracDelta in Mathematica behaved like this at end points. It seems to me that the Piecewise approach, which assumes that boundary points are treated the same as interior points, is the more natural. But Chris obviously was not interested in the answer to this particular problem but in more general matters. It is trivial to modify the behaviour of the package in this respect (by adding ones own rules for handling DiracDelta) to make it conform with what Mathematica does, if one really wanted to. But my main point was that the package is interesting in its own right and it seems to me that anyone seriously interested in this topic would have already taken a look at it. Why, even people not seriously interested in it, like myself, have done so and found interesting and instructive things in it. Andrzej > If Chris really wanted the integration of the DiracDelta functions > to be > handled as Mathematica does, then I should think he'd want > Integrate[load[x],{x,0,5}] to return 7500, rather than your Out[3]=0. > David >> In[4]:= >> PiecewiseIntegrate[load[x], {x, 0, a}] >> Out[4]= >> If[Inequality[0, Less, a, LessEqual, 3], (5000*a^2)/3, 0] + If[3 < a, >> 15000, 0] + If[a < 0, 9000, 0] + If[0 <= a, -9000, 0] + >> If[5 <= a, -6000, 0] >> Andrzej Kozlowski === Subject: Re: piecewise integration > The Integrate result seems pretty weak. Is there any way to obtain a > more explicit exact answer besides manually converting the Piecewise > function to two UnitStep functions? Can the same be done if the final > limit of integration is a variable? > in > load[x_]=-9*10^3*DiracDelta[x]+Piecewise[{{x*10*(10^3/3), > 0<=x<=3}}]-6*10^3*DiracDelta[x-5]//InputForm > out > -6000*DiracDelta[-5 + x] - 9000*DiracDelta[x] + > Piecewise[{{(10000*x)/3, 0 <= x <= 3}}, 0] > in > Integrate[load[x],{x,0,5}]//InputForm > out > Integrate[InputForm[-6000*DiracDelta[-5 + x] - 9000*DiracDelta[x] + > Piecewise[{{(10000*x)/3, 0 <= x <= 3}}, 0]], {x, 0, 5}] > -- > http://chris.chiasson.name/ > I am sure Maxim does not need my help to advertise his package but > somehow people still keep posting such questions with surprising > frequency. It shouldn't surprise you. Such questions will continue to be posted frequently until Mathematica _itself_ can adequately handle integration of Piecewise functions. > Even if for some reason you do not want to use a third > party package you can always look at the Mathematica code inside, > which should answer questions such as these. > load[x_] = -9*10^3* > DiracDelta[x] + Piecewise[{{x*10*(10^3/3), 0 <= > x <= 3}}] - 6*10^3*DiracDelta[x - 5]; > << piecewise` > In[3]:= > PiecewiseIntegrate[load[x],{x,0,5}] > Out[3]= That might or might not be what Chris wanted. It depends on whether he wanted integration of DiracDelta to be handled as Mathematica does or as PiecewiseIntegrate does. Using Mathematica, we have, for example, In[28]:= Integrate[DiracDelta[x],{x,0,2}] Out[28]= 1/2 rather than 1, which I infer is what PiecewiseIntegrate would do. If Chris really wanted the integration of the DiracDelta functions to be handled as Mathematica does, then I should think he'd want Integrate[load[x],{x,0,5}] to return 7500, rather than your Out[3]=0. David > In[4]:= > PiecewiseIntegrate[load[x], {x, 0, a}] > Out[4]= > If[Inequality[0, Less, a, LessEqual, 3], (5000*a^2)/3, 0] + If[3 < a, > 15000, 0] + If[a < 0, 9000, 0] + If[0 <= a, -9000, 0] + > If[5 <= a, -6000, 0] > Andrzej Kozlowski === Subject: RE: Packages--guikit and mathgl3d help! The Problem Is ! that they are not working at the same time such as placing graphics3D[] with MVShow3D[] in a script[] in guikit it does not work. But using standart Show[] function of mathematica instead of MVShow3D[] gives the result exactly. for example: **** Needs[GUIKit`] << Graphics`Graphics` GUIRunModal[Widget[Frame, {title -> Calc with Mathematica, {Widget[ Label, {text -> First argument:}], WidgetAlign[], Widget[TextField, {text -> 10 , columns -> 20, horizontalAlignment -> PropertyValue[ RIGHT]}, Name -> FirstArgumentField]}, {WidgetFill[], Widget[Button, {text -> Compute, BindEvent[action, Script[ { x} = ToExpression /@ PropertyValue[{{FirstArgumentField}, text}]; λ = x; Show[Graphics3D[{Line[{{0, 0, -λ}, {0, 0, λ}}], Line[{{0, -λ, 0}, {0, λ, 0}}], Line[{{-40, 0, 0}, {40, 0, 0}}]}, ViewCenter -> {1, 1, 1}]] Print[Finish λ=, λ]; ]]}]} }]] ***** >>>>this works Needs[GUIKit`] Get[MathGL3d`OpenGLViewer`]; << Graphics`Graphics` GUIRunModal[Widget[Frame, {title -> Calc with Mathematica, {Widget[ Label, {text -> First argument:}], WidgetAlign[], Widget[TextField, {text -> 10 , columns -> 20, horizontalAlignment -> PropertyValue[ RIGHT]}, Name -> FirstArgumentField]}, {WidgetFill[], Widget[Button, {text -> Compute, BindEvent[action, Script[ { x} = ToExpression /@ PropertyValue[{{FirstArgumentField}, text}]; λ = x; MVShow3D[Graphics3D[{Line[{{0, 0, -λ}, {0, 0, λ}}], Line[{{0, -λ, 0}, { 0, λ, 0}}], Line[{{-40, 0, 0}, {40, 0, 0}}]}, ViewCenter -> {1, 1, 1}], MVLineTubeSize -> 1, MVPolygonShading -> MVSmooth, MVTubeSegments -> 8, MVTubeAngle -> 30, MVPointSphereSize -> 0.01, MVNewScene -> True] Print[Finish λ=, λ]; ]]}]} }]] >>>>but this does not work :( thank you for your replies Link to the forum page for this post: http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=Speci al:Forum_ViewTopic&pid=10924#p10924 === Subject: Re: tensors, matrices, and rotation I ordered this book by Malvern after I came home today. http://www.amazon.com/gp/product/0134876032/ I guess I will make a progress post if I am able to do what I set out to do. Gulliet, and Brian for lending your (learning?) experiences. I appreciate them. > A book I can suggest is > Introduction to the mechanics of continuous media by L E. Malvern > Likely out of print but a good library should have it. > Brian, > The exact title is _Introduction to the Mechanics of a Continuous > Medium_ (medium not media) just in case Chris wants to purchase it > online (Amazon as well as Barnes and Noble web sites are unable to find > the book with the misspelled title, even if one adds the author name). > Introduction to the Mechanics of a Continuous Medium > Lawrence E. Malvern > ISBN: 0134876032 > Format: Paperback, 713pp > Publisher: Pearson Education > Edition Number: 1 > Jean-Marc -- http://chris.chiasson.name/ === Subject: Re: New Analytical Functions - Mathematica Verified >>They will change the behavior of its derivatives. Actually I think I did >>not want to use the DiracDelta component in that particular definition >>(or else to use further derivatives thereof in the definition for higher >>derivatives of FractionalPart). >>........................... >>........................... >>Did you try it? > , > Your usage of DiracDelta has made some reable correction for the > result, but on a very high cost of runtime! I have made some > experiments and wanted to publish them. You should remember that my > paper: > http://dabbagh2.fortunecity.com/disc > has proved that the derivative of the fractional part of any function > calculation of fractional part! > This is not exactly new. The function FractionalPart[f[x]] is > differentiable wherever f[x] is differentiable except where it takes on > integer (or, in the complex plane, Gaussian integer) values. > At such points one might regard the derivative as undefined, or as a > generalized function in terms of derivatives of delta functions, > depending on the situation at hand. One often sees FractionalPart used > for e.g. sawtooth waves, and in that setting a generalized function > derivative is often appropriate. > When I used your improvement using Dirac Delta, a very substantial > improvement occurred on the numerical results. HOWEVER, this lead to > some very long delays. To the extent that calculating 5th derivative of > the FractionalPart(x^5) to 1000 places of decimal would take about ONE > HOUR!!!! Here are some results I arranged it in a page prepared for > you: > http://dabbagh2.fortunecity.com/lichtblau/ > You will see how my formulas are A LOT faster. > Mohamed Al-Dabbagh > First let me correct my derivatives (or at least post what I think are > the correct ones). > Derivative[1][FractionalPart][x_] := 1 - DiracDelta[x] > Derivative[n_Integer /; n>1][FractionalPart][x_] := > (-1)^n*Derivative[DiracDelta[x]] > Now we use your function f. > In[3]:= f[x_] := x^5 > In[4]:= gMath[x_] := FractionalPart[f[x]] > In[5]:= InputForm[Timing[gMath''[12.2`400]]] > Out[5]//InputForm= > {0.003999999999999998*Second, > 36316.95999999999999999999999999999999999999999 > 99999999999999999999999999999999999999999999999999999999999999999999999999999 > 99999999999999999999999999999999999999999999999999999999999999999999999999999 > 99999999999999999999999999999999999999999999999999999999999999999999999999999 > 99999999999999999999999999999999999999999999999999999999999999999999999999999 > 99999999999999999999999999999999999999999999999999999999999998868`399.5228787 > 4528037} > So it takes a fraction of a second. Offhand I do not know why it appears > to run so slow for you. > Here is the result for the slightly more complicated example, both for > evaluating second and fifth derivatives. > In[8]:= f[x_] := x^5*Sin[x]^2 > In[10]:= InputForm[Timing[gMath''[12.2`400]]] > Out[10]//InputForm= > {0.*Second, > 258282.7295151941533077499484389228239911198853695416606571789553 > 97340348154747842920564555894547008803556440086166245643590282093764764200190 > 36636044752758309971369144877274629804969160115275382411797649612521530487913 > 14021423969924741654432978075641339718450969747617369938122882505861900120631 > 23291336171292192057571061244505228564074008530150250653359154263365233552077 > In[11]:= InputForm[Timing[Derivative[5][gMath][12.2`400]]] > Out[11]//InputForm= > {0.064004*Second, > -5.08650128579910493665046315290795289078198431826789276935 > 82833885062256473165463289248429898024173337160137072344086983520144149450609 > 25117527136634188560981519715993806959080731375558227844064929448344771904044 > 99542455152362012447722945323920015084363270028976459194249211406113484752274 > 39553483871787782701218811066558362577548299391921139619721479189052606484281 > 5379262528773061529913587801452056996643588005`398.3053093021263*^6} > At the bottom of your note you say: Now you understand how powerful my > formulas are compared to the existing ones you use in Mathematica. > While I am at a loss to understand why the computations are so slow when > you run them, I think you are vastly overstating the case here. > Differentiation in Mathematica by default does but little with > discontinuous functions such as FractionalPart. But as seen above a user > can readily add derivatives to suit ones needs, and evaluations > involving those derivatives seem (to me) to be reasonably fast. > iel Lichtblau > Wolfram Research In this page: http://dabbagh2.fortunecity.com/dirac/ you find the results for symbolic math when using the definition you provided for the derivative of fractional part. The results shows clearly how the matters become complicated as compared to using result of my research when you use the simple derivative which is equal the derivative of fractional part. Mohamed Al-Dabbagh === Subject: Re: New Analytical Functions - Mathematica Verified >>They will change the behavior of its derivatives. Actually I think I did >>not want to use the DiracDelta component in that particular definition >>(or else to use further derivatives thereof in the definition for higher >>derivatives of FractionalPart). >>........................... >>........................... >>Did you try it? > , > Your usage of DiracDelta has made some reable correction for the > result, but on a very high cost of runtime! I have made some > experiments and wanted to publish them. You should remember that my > paper: > http://dabbagh2.fortunecity.com/disc > has proved that the derivative of the fractional part of any function > calculation of fractional part! > This is not exactly new. The function FractionalPart[f[x]] is > differentiable wherever f[x] is differentiable except where it takes on > integer (or, in the complex plane, Gaussian integer) values. > At such points one might regard the derivative as undefined, or as a > generalized function in terms of derivatives of delta functions, > depending on the situation at hand. One often sees FractionalPart used > for e.g. sawtooth waves, and in that setting a generalized function > derivative is often appropriate. > When I used your improvement using Dirac Delta, a very substantial > improvement occurred on the numerical results. HOWEVER, this lead to > some very long delays. To the extent that calculating 5th derivative of > the FractionalPart(x^5) to 1000 places of decimal would take about ONE > HOUR!!!! Here are some results I arranged it in a page prepared for > you: > http://dabbagh2.fortunecity.com/lichtblau/ > You will see how my formulas are A LOT faster. > Mohamed Al-Dabbagh > First let me correct my derivatives (or at least post what I think are > the correct ones). > Derivative[1][FractionalPart][x_] := 1 - DiracDelta[x] > Derivative[n_Integer /; n>1][FractionalPart][x_] := > (-1)^n*Derivative[DiracDelta[x]] > Now we use your function f. > In[3]:= f[x_] := x^5 > In[4]:= gMath[x_] := FractionalPart[f[x]] > In[5]:= InputForm[Timing[gMath''[12.2`400]]] > Out[5]//InputForm= > {0.003999999999999998*Second, > 36316.95999999999999999999999999999999999999999 > 99999999999999999999999999999999999999999999999999999999999999999999999999999 > 99999999999999999999999999999999999999999999999999999999999999999999999999999 > 99999999999999999999999999999999999999999999999999999999999999999999999999999 > 99999999999999999999999999999999999999999999999999999999999999999999999999999 > 99999999999999999999999999999999999999999999999999999999999998868`399.5228787 > 4528037} > So it takes a fraction of a second. Offhand I do not know why it appears > to run so slow for you. > Here is the result for the slightly more complicated example, both for > evaluating second and fifth derivatives. > In[8]:= f[x_] := x^5*Sin[x]^2 > In[10]:= InputForm[Timing[gMath''[12.2`400]]] > Out[10]//InputForm= > {0.*Second, > 258282.7295151941533077499484389228239911198853695416606571789553 > 97340348154747842920564555894547008803556440086166245643590282093764764200190 > 36636044752758309971369144877274629804969160115275382411797649612521530487913 > 14021423969924741654432978075641339718450969747617369938122882505861900120631 > 23291336171292192057571061244505228564074008530150250653359154263365233552077 > In[11]:= InputForm[Timing[Derivative[5][gMath][12.2`400]]] > Out[11]//InputForm= > {0.064004*Second, > -5.08650128579910493665046315290795289078198431826789276935 > 82833885062256473165463289248429898024173337160137072344086983520144149450609 > 25117527136634188560981519715993806959080731375558227844064929448344771904044 > 99542455152362012447722945323920015084363270028976459194249211406113484752274 > 39553483871787782701218811066558362577548299391921139619721479189052606484281 > 5379262528773061529913587801452056996643588005`398.3053093021263*^6} > At the bottom of your note you say: Now you understand how powerful my > formulas are compared to the existing ones you use in Mathematica. > While I am at a loss to understand why the computations are so slow when > you run them, I think you are vastly overstating the case here. > Differentiation in Mathematica by default does but little with > discontinuous functions such as FractionalPart. But as seen above a user > can readily add derivatives to suit ones needs, and evaluations > involving those derivatives seem (to me) to be reasonably fast. > iel Lichtblau > Wolfram Research No need for all this headache. According to my formula: Just define the nth derivative of the FractionalPart of f[x] to be nth derivative of f[x] and voila! This is all what I wanted to say and what the study proved. No need for using generalized functions, thereby, revinventing the wheel everytime we need the calculation of the derivative of fractional part function! Mohamed Al-Dabbagh === Subject: Re: New Analytical Functions - Mathematica Verified > This is not exactly new. The function FractionalPart[f[x]] is > differentiable wherever f[x] is differentiable except where it takes on > integer (or, in the complex plane, Gaussian integer) values. Of course it is not new to say that fractional part is differentiable! The new thing is that to say derivative of fractional part is the same as the derivative in continuity intervals. I don't know what harm in confessing that! However, if it is not new and you have a solution for that then you should consider that instead of the very costly Dirac Delta involvement. > At such points one might regard the derivative as undefined, or as a > generalized function in terms of derivatives of delta functions, Delta function is VERY SLOW in high derivatives. >> To the extent that calculating 5th derivative of > the FractionalPart(x^5) to 1000 places of decimal would take about ONE > HOUR!!!! Try this at your side and post your results with Timing function, please. > At the bottom of your note you say: Now you understand how powerful my > formulas are compared to the existing ones you use in Mathematica. > While I am at a loss to understand why the computations are so slow when > you run them, I think you are vastly overstating the case here. I don't! > Differentiation in Mathematica by default does but little with > discontinuous functions such as FractionalPart. But as seen above a user > can readily add derivatives to suit ones needs, and evaluations > involving those derivatives seem (to me) to be reasonably fast. They are not fast in higher order derivatives. Last word to say that it is all up to you to use my results or not. Mathematica is a great software and I am very proud of using it. It deserves all improvement. I wouldn't spend all this time unless I like to see myself doing some improvement on this great software. When you use it symbolically, it still returns no result for the derivative of fractional part, while it is great to return the correct answer which is the derivative of the function itself. Mohamed Al-Dabbagh === Subject: Re: Simplifying algebraic expressions I suddenly remembered that I have already met a very closely related problem once before and even suggested that the transformation function f be added to Simplify. Moreover, Adams Strzebonski replied promising that he would do so: http://forums.wolfram.com/mathgroup/archive/2005/Jul/msg00717.html So it may have had something to do with the change in the development version. It also shows that my memory is no longer what it used to be :- ( (though I did feel there was something familiar about this problem). Andrzej Kozlowski > Here is, I think, an optimized version of the simplification I > sent earlier: > rule1 = {2x -> u, 3y -> v}; rule2 = Map[Reverse, rule1]; > Simplify[TrigFactor[Simplify[ExpToTrig[ > Simplify[ExpToTrig[(-1)^(2*x + 3*y) /. rule1], > Mod[u, 2] == 0] /. rule2], y .89ÃÃ Integers]], > y .89ÃÃ Integers] > (-1)^y > Optimized means that I can't see any obvious way to make this > simpler. > Unlike other answers to the original post, this works in > Mathematica 5.1 and 5.2, and involves only reversible > operations. In other words, it constitutes a proof. On the other > hand, obviously, it would be ridiculous to use this approach in > practice: there must be a simple transformation rule (or rules) > missing from Simplify, which apparently has already been added > in the development version. >> Andrzej, >> It seems to me that your simplification approach isn't as general >> as the replacement method I advocated (a variant of which is given >> below), as rule1 and rule2 are specific to the input. Also, my >> replacement method is based on the fact that: >> In[30]:= Simplify[((-1)^a)^b == (-1)^(a b), Element[{a, b}, >> Integers]] >> Out[30]= True >> So, I think my approach is generally valid. > You are right, I apologise. I did not look carefully at your code. > But now that I see some challenge ;-) I also see that I can > completley remove rule1 and rule 2 form my code and make it equally > general: > Simplify[TrigFactor[Simplify[ExpToTrig[ > Simplify[ExpToTrig[(-1)^PolynomialMod[2*x + 3*y, > 2]], Mod[u, 2] == 0]], y .89ÃÃ Integers]], > y .89ÃÃ Integers] > (-1)^y > What's more, I can actually produce an even shorter code that will > produce the required simplification: > f[(-1)^(n_)] := (-1)^PolynomialMod[n, 2] > Simplify[f[(-1)^(2*x + 3*y)], TransformationFunctions - {Automatic, f}] > (-1)^y > Of course this ought to be modified so as to be performed only > under the assumption that x and y are integers (not very hard to > do). I suspect that this is close to what has been done in the > development version. > Andrzej Kozlowski > Note also the following problem, which I suspect is related: > Simplify[(-1)^(u + v), (u | v) .89ÃÃ Integers && > Mod[u, 2] == 0 && Mod[v, 2] == 1] > -1 > Simplify[(-1)^(u + v), (u | v) .89ÃÃ Integers && > Mod[u, 2] == 0 && Mod[v, 2] == 0] > 1 > But > Simplify[(-1)^(u + v), (u | v) .89ÃÃ Integers && > Mod[u, 2] == 0] > (-1)^(u + v) > I am sure this also gives (-1)^v in the development version. >> To obtain the desired simplification in 5.2, we can modify my >> previous approach as follows: >> power[e_, a_Plus] := Times @@ (Simplify /@ (power[e, #1]&) /@ List >> @@ a) >> power[e_, a_Integer b_?(Refine[Element[#,Integers]]&)] := (e^a)^b >> power[e_, a_] := e^a >> simp[expr_, assum_] := Block[{$Assumptions = assum}, >> Simplify[expr /. Power -> power] >> ] >> In the above I rely on the following two equivalences, verified by >> Mathematica: >> In[50]:= >> Simplify[e^a e^b == e^(a+b)] >> Out[50]= >> True >> In[51]:= >> Simplify[(e^a)^b == e^(a b), Element[{a,b},Integers]] >> Out[51]= >> True >> The tricky part is that Mathematica automatically converts e^a e^b >> --> e^(a+b), and as you point out above Simplify[(-1)^(u+v),...] >> doesn't work. However, Simplify[(-1)^u, ...] does work, which is >> why the Simplify appears in the definition of power[e_,a_Plus] >> before Times is applied. >> Here are some examples: >> In[56]:= >> simp[(-1)^(u+v),Mod[u,2]==0] >> Out[56]= >> v >> (-1) >> In[57]:= >> simp[(-2)^(u+v),Mod[u,2]==0] >> Out[57]= >> v u + v >> (-1) 2 >> In[58]:= >> simp[(-1)^(2x+3y),Element[{x,y},Integers]] >> Out[58]= >> y >> (-1) >> In[59]:= >> simp[(-2)^(2x+3y),Element[{x,y},Integers]] >> Out[59]= >> y 2 x + 3 y >> (-1) 2 >> Carl Woll >> Wolfram Research > Andrzej Kozlowski >>>> I would like Mathematica to be able to take an expression, say, >>>> (-1)^{2 x + 3 y} and be able to simplify to (-1)^y. >>>> Is there a way one can do this ? >>>> Note that you are using {} instead of (). Different kind of >> brackets >> have completely different meaning in Mathematica. >> I have found it amazingly hard to force Mathematica to perform this >> simplification. The best I could do is this. We need two rules. >> rule1 >> will replace 2x by u and 3y by v. rule 2 does the opposite: it >> replaces u by 2x and v by 2y. >> rule1 = {2x -> u, 3y -> v};rule2 = Map[Reverse, rule1]; >> Now: >> Simplify[TrigFactor[ >> FullSimplify[ExpToTrig[ >> FullSimplify[ >> ComplexExpand[ >> (-1)^(2*x + 3*y) /. >> rule1], Mod[u, 2] == >> 0] /. rule2], >> y .89ÃÃ Integers]], >> y .89ÃÃ Integers] >> (-1)^y >> Uff... Surely, this ought to be easier... >> Andrzej Kozlowski >> Tokyo, Japan >> === Subject: Re: Simplifying algebraic expressions >> Here is, I think, an optimized version of the simplification I >> sent earlier: >> rule1 = {2x -> u, 3y -> v}; rule2 = Map[Reverse, rule1]; >> Simplify[TrigFactor[Simplify[ExpToTrig[ >> Simplify[ExpToTrig[(-1)^(2*x + 3*y) /. rule1], >> Mod[u, 2] == 0] /. rule2], y .89ÃÃ Integers]], >> y .89ÃÃ Integers] >> (-1)^y >> Optimized means that I can't see any obvious way to make this >> simpler. >> Unlike other answers to the original post, this works in >> Mathematica 5.1 and 5.2, and involves only reversible operations. >> In other words, it constitutes a proof. On the other hand, >> obviously, it would be ridiculous to use this approach in >> practice: there must be a simple transformation rule (or rules) >> missing from Simplify, which apparently has already been added in >> the development version. > Andrzej, > It seems to me that your simplification approach isn't as general > as the replacement method I advocated (a variant of which is given > below), as rule1 and rule2 are specific to the input. Also, my > replacement method is based on the fact that: > In[30]:= Simplify[((-1)^a)^b == (-1)^(a b), Element[{a, b}, Integers]] > Out[30]= True > So, I think my approach is generally valid. You are right, I apologise. I did not look carefully at your code. But now that I see some challenge ;-) I also see that I can completley remove rule1 and rule 2 form my code and make it equally general: Simplify[TrigFactor[Simplify[ExpToTrig[ Simplify[ExpToTrig[(-1)^PolynomialMod[2*x + 3*y, 2]], Mod[u, 2] == 0]], y .89ÃÃ Integers]], y .89ÃÃ Integers] (-1)^y What's more, I can actually produce an even shorter code that will produce the required simplification: f[(-1)^(n_)] := (-1)^PolynomialMod[n, 2] Simplify[f[(-1)^(2*x + 3*y)], TransformationFunctions -> {Automatic, f}] (-1)^y Of course this ought to be modified so as to be performed only under the assumption that x and y are integers (not very hard to do). I suspect that this is close to what has been done in the development version. Andrzej Kozlowski >> Note also the following problem, which I suspect is related: >> Simplify[(-1)^(u + v), (u | v) .89ÃÃ Integers && >> Mod[u, 2] == 0 && Mod[v, 2] == 1] >> -1 >> Simplify[(-1)^(u + v), (u | v) .89ÃÃ Integers && >> Mod[u, 2] == 0 && Mod[v, 2] == 0] >> 1 >> But >> Simplify[(-1)^(u + v), (u | v) .89ÃÃ Integers && >> Mod[u, 2] == 0] >> (-1)^(u + v) >> I am sure this also gives (-1)^v in the development version. > To obtain the desired simplification in 5.2, we can modify my > previous approach as follows: > power[e_, a_Plus] := Times @@ (Simplify /@ (power[e, #1]&) /@ List > @@ a) > power[e_, a_Integer b_?(Refine[Element[#,Integers]]&)] := (e^a)^b > power[e_, a_] := e^a > simp[expr_, assum_] := Block[{$Assumptions = assum}, > Simplify[expr /. Power -> power] > In the above I rely on the following two equivalences, verified by > Mathematica: > In[50]:= > Simplify[e^a e^b == e^(a+b)] > Out[50]= > True > In[51]:= > Simplify[(e^a)^b == e^(a b), Element[{a,b},Integers]] > Out[51]= > True > The tricky part is that Mathematica automatically converts e^a e^b > --> e^(a+b), and as you point out above Simplify[(-1)^(u+v),...] > doesn't work. However, Simplify[(-1)^u, ...] does work, which is > why the Simplify appears in the definition of power[e_,a_Plus] > before Times is applied. > Here are some examples: > In[56]:= > simp[(-1)^(u+v),Mod[u,2]==0] > Out[56]= > v > (-1) > In[57]:= > simp[(-2)^(u+v),Mod[u,2]==0] > Out[57]= > v u + v > (-1) 2 > In[58]:= > simp[(-1)^(2x+3y),Element[{x,y},Integers]] > Out[58]= > y > (-1) > In[59]:= > simp[(-2)^(2x+3y),Element[{x,y},Integers]] > Out[59]= > y 2 x + 3 y > (-1) 2 > Carl Woll > Wolfram Research >> Andrzej Kozlowski >> I would like Mathematica to be able to take an expression, say, >> (-1)^{2 x + 3 y} and be able to simplify to (-1)^y. >> Is there a way one can do this ? > Note that you are using {} instead of (). Different kind of brackets > have completely different meaning in Mathematica. > I have found it amazingly hard to force Mathematica to perform this > simplification. The best I could do is this. We need two rules. > rule1 > will replace 2x by u and 3y by v. rule 2 does the opposite: it > replaces u by 2x and v by 2y. > rule1 = {2x -> u, 3y -> v};rule2 = Map[Reverse, rule1]; > Now: > Simplify[TrigFactor[ > FullSimplify[ExpToTrig[ > FullSimplify[ > ComplexExpand[ > (-1)^(2*x + 3*y) /. > rule1], Mod[u, 2] == > 0] /. rule2], > y .89ÃÃ Integers]], > y .89ÃÃ Integers] > (-1)^y > Uff... Surely, this ought to be easier... > Andrzej Kozlowski > Tokyo, Japan === Subject: Re: Simplifying algebraic expressions > I suddenly remembered that I have already met a very closely related > problem once before and even suggested that the transformation function > f be added to Simplify. Moreover, Adams Strzebonski replied promising > that he would do so: > http://forums.wolfram.com/mathgroup/archive/2005/Jul/msg00717.html Yes, this is exactly when the transformation has been added. Here are examples from a code change dated 2005/07/28 15:38:49. In[1]:= Refine[(-1)^(5 m+8 k m+r), Element[k|m, Integers]] m + r Out[1]= (-1) In[2]:= Refine[Cos[3*m*Pi], Assumptions -> Element[m, Integers]] m Out[2]= (-1) These will work since today (the transformation reduced integer coefficients, but didn't try to use Mod assumptions to reduce symbolic subexpressions). In[1]:= Refine[(-1)^(u + v), Element[u|v, Integers] && Mod[u, 2] == 0] v Out[1]= (-1) In[2]:= Refine[(-1)^(5 m+k m+r), Element[k|m, Integers] && Mod[k, 2]==1] r Out[2]= (-1) Adam Strzebonski Wolfram Research > So it may have had something to do with the change in the development > version. > It also shows that my memory is no longer what it used to be :- ( > (though I did feel there was something familiar about this problem). > Andrzej Kozlowski >> Here is, I think, an optimized version of the simplification I >> sent earlier: >> rule1 = {2x -> u, 3y -> v}; rule2 = Map[Reverse, rule1]; >> Simplify[TrigFactor[Simplify[ExpToTrig[ >> Simplify[ExpToTrig[(-1)^(2*x + 3*y) /. rule1], >> Mod[u, 2] == 0] /. rule2], y .89ÃÃ Integers]], >> y .89ÃÃ Integers] >> (-1)^y >> Optimized means that I can't see any obvious way to make this >> simpler. >> Unlike other answers to the original post, this works in >> Mathematica 5.1 and 5.2, and involves only reversible operations. >> In other words, it constitutes a proof. On the other hand, >> obviously, it would be ridiculous to use this approach in >> practice: there must be a simple transformation rule (or rules) >> missing from Simplify, which apparently has already been added in >> the development version. > Andrzej, > It seems to me that your simplification approach isn't as general as > the replacement method I advocated (a variant of which is given > below), as rule1 and rule2 are specific to the input. Also, my > replacement method is based on the fact that: > In[30]:= Simplify[((-1)^a)^b == (-1)^(a b), Element[{a, b}, Integers]] > Out[30]= True > So, I think my approach is generally valid. >> You are right, I apologise. I did not look carefully at your code. >> But now that I see some challenge ;-) I also see that I can >> completley remove rule1 and rule 2 form my code and make it equally >> general: >> Simplify[TrigFactor[Simplify[ExpToTrig[ >> Simplify[ExpToTrig[(-1)^PolynomialMod[2*x + 3*y, >> 2]], Mod[u, 2] == 0]], y .89ÃÃ Integers]], >> y .89ÃÃ Integers] >> (-1)^y >> What's more, I can actually produce an even shorter code that will >> produce the required simplification: >> f[(-1)^(n_)] := (-1)^PolynomialMod[n, 2] >> Simplify[f[(-1)^(2*x + 3*y)], TransformationFunctions -> {Automatic, f}] >> (-1)^y >> Of course this ought to be modified so as to be performed only under >> the assumption that x and y are integers (not very hard to do). I >> suspect that this is close to what has been done in the development >> version. >> Andrzej Kozlowski >> Note also the following problem, which I suspect is related: >> Simplify[(-1)^(u + v), (u | v) .89ÃÃ Integers && >> Mod[u, 2] == 0 && Mod[v, 2] == 1] >> -1 >> Simplify[(-1)^(u + v), (u | v) .89ÃÃ Integers && >> Mod[u, 2] == 0 && Mod[v, 2] == 0] >> 1 >> But >> Simplify[(-1)^(u + v), (u | v) .89ÃÃ Integers && >> Mod[u, 2] == 0] >> (-1)^(u + v) >> I am sure this also gives (-1)^v in the development version. > To obtain the desired simplification in 5.2, we can modify my > previous approach as follows: > power[e_, a_Plus] := Times @@ (Simplify /@ (power[e, #1]&) /@ List > @@ a) > power[e_, a_Integer b_?(Refine[Element[#,Integers]]&)] := (e^a)^b > power[e_, a_] := e^a > simp[expr_, assum_] := Block[{$Assumptions = assum}, > Simplify[expr /. Power -> power] > ] > In the above I rely on the following two equivalences, verified by > Mathematica: > In[50]:= > Simplify[e^a e^b == e^(a+b)] > Out[50]= > True > In[51]:= > Simplify[(e^a)^b == e^(a b), Element[{a,b},Integers]] > Out[51]= > True > The tricky part is that Mathematica automatically converts e^a e^b > --> e^(a+b), and as you point out above Simplify[(-1)^(u+v),...] > doesn't work. However, Simplify[(-1)^u, ...] does work, which is why > the Simplify appears in the definition of power[e_,a_Plus] before > Times is applied. > Here are some examples: > In[56]:= > simp[(-1)^(u+v),Mod[u,2]==0] > Out[56]= > v > (-1) > In[57]:= > simp[(-2)^(u+v),Mod[u,2]==0] > Out[57]= > v u + v > (-1) 2 > In[58]:= > simp[(-1)^(2x+3y),Element[{x,y},Integers]] > Out[58]= > y > (-1) > In[59]:= > simp[(-2)^(2x+3y),Element[{x,y},Integers]] > Out[59]= > y 2 x + 3 y > (-1) 2 > Carl Woll > Wolfram Research >> Andrzej Kozlowski >>>> I would like Mathematica to be able to take an expression, say, >> (-1)^{2 x + 3 y} and be able to simplify to (-1)^y. >> Is there a way one can do this ? >>>> Note that you are using {} instead of (). Different kind of brackets >>> have completely different meaning in Mathematica. >>> I have found it amazingly hard to force Mathematica to perform this >>> simplification. The best I could do is this. We need two rules. rule1 >>> will replace 2x by u and 3y by v. rule 2 does the opposite: it >>> replaces u by 2x and v by 2y. >>>> rule1 = {2x -> u, 3y -> v};rule2 = Map[Reverse, rule1]; >>>> Now: >>>>> Simplify[TrigFactor[ >>> FullSimplify[ExpToTrig[ >>> FullSimplify[ >>> ComplexExpand[ >>> (-1)^(2*x + 3*y) /. >>> rule1], Mod[u, 2] == >>> 0] /. rule2], >>> y .89ÃÃ Integers]], >>> y .89ÃÃ Integers] >>>>> (-1)^y >>>> Uff... Surely, this ought to be easier... >>>> Andrzej Kozlowski >>> Tokyo, Japan >>> === Subject: Re: Simplifying algebraic expressions > Here is, I think, an optimized version of the simplification I sent > earlier: > rule1 = {2x -> u, 3y -> v}; rule2 = Map[Reverse, rule1]; > Simplify[TrigFactor[Simplify[ExpToTrig[ > Simplify[ExpToTrig[(-1)^(2*x + 3*y) /. rule1], > Mod[u, 2] == 0] /. rule2], y .89ÃÃ Integers]], > y .89ÃÃ Integers] > (-1)^y > Optimized means that I can't see any obvious way to make this simpler. > Unlike other answers to the original post, this works in Mathematica > 5.1 and 5.2, and involves only reversible operations. In other words, > it constitutes a proof. On the other hand, obviously, it would be > ridiculous to use this approach in practice: there must be a simple > transformation rule (or rules) missing from Simplify, which > apparently has already been added in the development version. Andrzej, It seems to me that your simplification approach isn't as general as the replacement method I advocated (a variant of which is given below), as rule1 and rule2 are specific to the input. Also, my replacement method is based on the fact that: In[30]:= Simplify[((-1)^a)^b == (-1)^(a b), Element[{a, b}, Integers]] Out[30]= True So, I think my approach is generally valid. > Note also the following problem, which I suspect is related: > Simplify[(-1)^(u + v), (u | v) .89ÃÃ Integers && > Mod[u, 2] == 0 && Mod[v, 2] == 1] > -1 > Simplify[(-1)^(u + v), (u | v) .89ÃÃ Integers && > Mod[u, 2] == 0 && Mod[v, 2] == 0] > But > Simplify[(-1)^(u + v), (u | v) .89ÃÃ Integers && > Mod[u, 2] == 0] > (-1)^(u + v) > I am sure this also gives (-1)^v in the development version. To obtain the desired simplification in 5.2, we can modify my previous approach as follows: power[e_, a_Plus] := Times @@ (Simplify /@ (power[e, #1]&) /@ List @@ a) power[e_, a_Integer b_?(Refine[Element[#,Integers]]&)] := (e^a)^b power[e_, a_] := e^a simp[expr_, assum_] := Block[{$Assumptions = assum}, Simplify[expr /. Power -> power] ] In the above I rely on the following two equivalences, verified by Mathematica: In[50]:= Simplify[e^a e^b == e^(a+b)] Out[50]= True In[51]:= Simplify[(e^a)^b == e^(a b), Element[{a,b},Integers]] Out[51]= True The tricky part is that Mathematica automatically converts e^a e^b --> e^(a+b), and as you point out above Simplify[(-1)^(u+v),...] doesn't work. However, Simplify[(-1)^u, ...] does work, which is why the Simplify appears in the definition of power[e_,a_Plus] before Times is applied. Here are some examples: In[56]:= simp[(-1)^(u+v),Mod[u,2]==0] Out[56]= v (-1) In[57]:= simp[(-2)^(u+v),Mod[u,2]==0] Out[57]= v u + v (-1) 2 In[58]:= simp[(-1)^(2x+3y),Element[{x,y},Integers]] Out[58]= y (-1) In[59]:= simp[(-2)^(2x+3y),Element[{x,y},Integers]] Out[59]= y 2 x + 3 y (-1) 2 Carl Woll Wolfram Research > Andrzej Kozlowski >I would like Mathematica to be able to take an expression, say, >(-1)^{2 x + 3 y} and be able to simplify to (-1)^y. >Is there a way one can do this ? >>Note that you are using {} instead of (). Different kind of brackets >>have completely different meaning in Mathematica. >>I have found it amazingly hard to force Mathematica to perform this >>simplification. The best I could do is this. We need two rules. rule1 >>will replace 2x by u and 3y by v. rule 2 does the opposite: it >>replaces u by 2x and v by 2y. >>rule1 = {2x -> u, 3y -> v};rule2 = Map[Reverse, rule1]; >>Now: >>Simplify[TrigFactor[ >> FullSimplify[ExpToTrig[ >> FullSimplify[ >> ComplexExpand[ >> (-1)^(2*x + 3*y) /. >> rule1], Mod[u, 2] == >> 0] /. rule2], >> y .89ÃÃ Integers]], >> y .89ÃÃ Integers] >>(-1)^y >>Uff... Surely, this ought to be easier... >>Andrzej Kozlowski >>Tokyo, Japan