# Tag Info

17

The following seems to work, however I think it's not general enough: At a clean nb, enter: For[i = 0, i < 4, i++, Print[{i, {33, i}}]] For[i = 0, i < 4, i++, Print[Graphics[Circle[], ImageSize -> 20]]] And then retrieve the Print[ ] output as: c = Cases[NotebookRead /@ Cells[GeneratedCell -> True], Cell[___, "Print", ___]]; ToExpression ...

16

Implementation The following implementation is based on expression serialization and SequenceAlignment built-in function. The idea is to break expressions into constituent parts, then align these part sequences, and then determine the positions where the expressions are different. The auxiliary heads we will need are inert heads diff and myHold, the latter ...

14

I assume you have Maple to use. If so, Simply open Maple and type the Mathematica command itself directly into Maple using the FromMma package built-into Maple, like this: restart; with(MmaTranslator); #load the package (*[FromMma, FromMmaNotebook, Mma, MmaToMaple]*) and now can use it FromMma(Integrate[Cos[x],x]); One can also use Maple convert ...

10

Here's one way to count the number of multiplications in an expression (equal to or greater than the number of Times in the expression). It should also work for several other binary operators, Listable or not (although I haven't tested it on them). t[x_, oper_: Times] := Tr @ ((Length[#] - 1) & /@ (Extract[x, {Sequence @@ Drop[#, ...

9

This is a rather simple-minded approach, but maybe it will be useful to you: ClearAll[opCount]; opCount[h_, expr_] := Cases[ Hold[expr], HoldPattern@h[args : _ ~Repeated~ {2, Infinity}] :> Length@Hold[args] - 1, -2 ] // Total; SetAttributes[opCount, HoldRest]; Let's try: opCount[Times, 1*2*3*4*5 + 6*7*8] (* -> 6 *) opCount[Plus, 1*2*3*4*5 + ...

8

Please let me know if this is moving in the right direction: expr = a + b*3*c + d; Replace[expr, h_[x___] :> {x}, {0, -1}] {a, {3, b, c}, d} Given that heads are lost here, perhaps you want something like: Replace[expr, h_[x___] :> {h, x}, {0, -1}] {Plus, a, {Times, 3, b, c}, d} If this is close to what you a related question that you ...

8

For the first puzzle, I can only guess. The idea is that Function with named variables is a true lexical scoping construct, in that it cares about the possible name collisions inside the inner scoping constructs, including another Function-s (this is where it is different from Slot- based functions, which are not like that. The price to pay is that ...

8

You can use Normal, ConditionalExpression is not explicitly mentioned there but documentation says it deals with special forms. p1 = y /. {First[Solve[x^2 + y^2 + x == 1, y, Reals]]} // First ConditionalExpression[-Sqrt[1 - x - x^2], 1/2 (-1 - Sqrt[5]) < x < 1/2 (-1 + Sqrt[5])] Normal @ p1 -Sqrt[1 - x - x^2]

7

As of version 9 this has changed http://reference.wolfram.com/mathematica/Compatibility/tutorial/Utilities/FilterOptions.html So this package needs to use FilterRules. I Downloaded this package, and changed Summa.m according to the above, and now it loads ok. Changed every place it said FilterOptions to Sequence@@FilterRules. Run few tests from the ...

7

Convert Maple expressions to Mathematica: Through latex： Through free form input：

7

You can forcely specify the condition to be True: Solve[x^2 + y^2 + x == 1, y, Reals] /. ConditionalExpression[e_, _] :> ConditionalExpression[e, True] {{y -> -Sqrt[1 - x - x^2]}, {y -> Sqrt[1 - x - x^2]}} But you should always keep it in mind that this is not an identical transformation.

7

E.g. using Cases: Cases[expr, _F, Infinity] {F[0, 0], F[0, 1], F[2, 0]} Note that the 3rd argument is the levelspec. See e.g. expr//FullForm why it's needed EDIT (I wasn't careful!) Note that this does not work for expr = F[0,0] as by default, Cases does not match the whole expression (it starts at level 1). If that could be the case, you can ...

6

One possible compact solution: multCount[expr_] := Total[Length /@ List @@@ Cases[expr, _Times, \[Infinity]] - 1] multCount[a b c + d e] (* 3 *) multCount[a*b*c + (d*e)/(f*g*h - i*j*k*l)] (* 10 *) Notice that since Mathematica represents divisions by multiplications with the multiplicative inverse and subtractions by additions with the number multiplied ...

6

If you can convert expressions to text form, there's a possible answer here. I sometimes use it to compare notebooks: notebook1 = StringJoin[ Import["/tmp/freaky-illusion.nb", "Plaintext"]]; notebook2 = StringJoin[ Import["/tmp/freaky-illusion-1.nb", "Plaintext"]]; SystemDumpshowStringDiff[notebook1, notebook2]

6

Here is another way using Evaluate: ops1 = {Filling -> {1 -> {2}}, PlotStyle -> {Red, Green}, Frame -> True}; Plot[{Sin[x] + x/2, Sin[x] + x}, {x, 0, 10} , Evaluate@ops1 , PlotLabel -> Style["Using Evaluate", 20] ]

6

On Leonid's valued opinion that the Close was inappropriate I have reopened this question. By my interpretation this does what is requested: SetAttributes[setSpec, HoldAllComplete] setSpec[s_Symbol, spec__] := s /: h_[pre__, s, post___] := h[pre, spec, post] The usage is: setSpec[ops1, Filling -> {1 -> {2}}, PlotStyle -> {Red, Green}, Frame ...

6

Maybe we can learn something from what Compile produces. cf = Compile[ {{w, _Real}, {y, _Real}} , w - 4 (w - y) ((w - y)^2 y + 6 (1 + y) ((w - y) y + (1 + y)^2))/((w - y)^2 ((w - y) y + 6 y^2 + 8 y (1 + y)) + (1 + y)^2 (36 (w - y) y + 24 (1 + y)^2)) ] In the compiled code we see that at least the number of ...

6

You can use FullSimplify and play with the ComplexityFunction Option until you obtain a satisfactory result. For example: Let's define our function in terms of LeafCount c[n_][e_] := n Count[e, _Sin | _ArcTan, Infinity] + LeafCount[e] Then: FullSimplify[Sin[1/2 ArcTan[(2 Log[5])/(Log[5]^2 - 2)]], ComplexityFunction -> c[#]] & /@ Range[40, 60, ...

6

The only method I can think of that will use the built-in simplification routines is to snoop on transformations using either TransformationFunctions or ComplexityFunction. Unfortunately neither of these will be restricted to the entire expression therefore what is produced may not be usable. Nevertheless as an example: FullSimplify[Gamma[1 - x] Gamma[x] ...

5

The function you need is TrigToExp, e.g. TrigToExp @ ArcTan[x] 1/2 I Log[1 - I x] - 1/2 I Log[1 + I x] There is an inverse function for TrigToExp, namely ExpToTrig ExpToTrig[ 1/2 I Log[1 - I x] - 1/2 I Log[1 + I x]] ArcTan[x] They both are Listable: Attributes @ {ExpToTrig, TrigToExp} {{Listable, Protected}, {Listable, Protected}} ...

5

The documentation for FullSimplify lists the following transformations in the section Examples → Properties & Relations (I do not think this the list is complete): Expand, TrigExpand, PiecewiseExpand, FunctionExpand, LogicalExpand, Factor, FactorSquareFree, TrigFactor, RootReduce, ToRadicals, Together, Apart. It also mentions that PowerExpand makes ...

5

Analysis It indeed looks like a borderline bug to me. Let us see what is happening. The first observation here is that part assignment does its job all right: sparse = SparseArray[Range[10]]; sparse[[2]] = Sequence[0, 0, 0]; so that ?sparse Global`sparse sparse=SparseArray[Automatic, {10},0,{1,{{0,10},{{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}}}, ...

5

This is only a hack, but maybe it just gives you short way out of this. Lately, we had a similar discussion in chat about NValues where the problem was related. It this cases Rojo wanted to use NValues to prevent some of the arguments to stay untouched by N. There too, the problem was when N was called from very outside and dived into the subexpressions ...

5

In our case a simple and direct approach would be defining a list of rules. Here is an example: rules = { c_ Sum[n a[n] c_^(n-1), {n, 0, Infinity}] :> Sum[n c^n a[n], {n, 0, Infinity}], α_ Sum[a[n] c_^n, {n, 0, Infinity}] + Sum[n a[n] c_^n, {n, 0, Infinity}] :> Sum[(α + n) a[n] c^n, {n, 0, Infinity}]}; Let's define an appropriate ...

5

Maybe TimeConstraint is helpful: y = Gamma[1 - x] Gamma[x] Sin[Pi x] + Gamma[x] Gamma[1 - x] Sin[Pi (1 - x)]; FullSimplify[y, TimeConstraint -> 0.000001] FullSimplify[y, TimeConstraint -> 0.0001] FullSimplify[y, TimeConstraint -> 0.01] Gamma[1 - x] Gamma[x] Sin[π (1 - x)] + Gamma[1 - x] Gamma[x] Sin[π x] 2 Gamma[1 - x] Gamma[x] Sin[π x] 2 π

5

I'm not sure why you don't like your merge function. This is the same pattern matching approach but using ReplaceAll: {e1, e2} /. {Hold[x_], Hold[y_]} :> Hold[x; y] If you would rather avoid patterns here is one (ugly) option: Block[{CompoundExpression}, (e1; e2) ~Thread~ CompoundExpression ~Thread~ Hold]

4

David Carlisle wrote about it back in 2007. The process seems to be rather cumbersome and I have not checked myself if it is reliable working but here are some links that might help you on your specific problem: XHTML and MathML from Office 2007 Going Wordless at the Advanced Mathematica Summer School

4

I once tried doing something like this myself, and ended up with a semi-manual process. Clear[branches, tallyBranches]; branches[b_?AtomQ] := {}; branches[b_?NumberQ] := {}; branches[h_[b___]] := Flatten@Append[branches /@ List[b], h[b]]; tallyBranches[e_, k_Integer: 2] := TableForm[Reverse /@ Cases[Tally[branches[e]], {_, t_ /; t >= k}]] Let's take ...

4

Try this one Sin[1/2 ArcTan[(2 Log[5])/(-2 + Log[5]^2)]] // FunctionExpand Another approach is to apply your own rules. You just need to get rid of the rational between the trig function and the inverse trig function. For example Sin[1/2 ArcTan[(2 Log[5])/(-2 + Log[5]^2)]] /. Sin[1/2 x_] :> Sqrt[1/2 (1 - Cos[x])] // FullSimplify Verification ...

Only top voted, non community-wiki answers of a minimum length are eligible