Tag Info

New answers tagged

0

As rm -rf pointed out this is because of the behavior I was addressing in my question: Why doesn't a Composition[] hold its arguments and what can be done about it? Unfortunately as explained there (at least at present) there is no built-in way to make a composite function that respects hold Attributes. For the purpose of performing the action in ...


0

After more thoughts, I think I understood what's going on. Because a composed function SymbolName @* Unevaluated does not exhibit the HoldAllComplete attribute of Unevaluated. So the expression is evaluated before feeding into SymbolName @* Unevaluated. A lesson is that, if we want to keep HoldFirst, HoldAll ... attributes, we have to map the functions one ...


1

Considering work-arounds, Style and Inactivate seem to work well together. Plot[x , {x, 0, 1}, AxesLabel -> {Style["M", Italic], Style[Inactivate[InputForm[E] = M c^2, (Set | Times)], "TraditionalForm"]}] Inactivating Times keeps M c^2 from being rewritten to c^2 M.


5

I'm not sure what's going on with HoldForm[InputForm[ℰ]], but I think I know what's going on with Plot. It appears at some point ReleaseHold is called because wrapping HoldForm twice fixes your problem. Plot[x^2, {x, -2, 2}, AxesLabel -> {x, HoldForm[HoldForm[InputForm[E = 1]]]}]


5

I can't comment on exactly why HoldForm has changed but I believe your examples fall under the purview of the new Active/Inactive functionality. For example: Clear[x]; Plot[Sin[x], {x, 0, 1}, AxesLabel -> {Inactivate[x = 3], Inactive[Set][InputForm[E], 3]}] x Note, however that Inactivate can't be used with InputForm, since you want InputForm to ...


2

For OSX you can do the following. Select Mathematica. Click on "Mathematica" menu then "Services -> Services Preferences..." Select "Shortcuts" tab. In the left side select "App Shortcuts". Click the + button. Fill out the following. Click add after you have set your short cut key and you are good to go.


6

In Version 10, we can use Inactivate and Activate to achieve this easily: With[{rl = Array[{m -> #} &, 5], s = Inactivate[Sum[i^m, {i, 1, n}], Sum]}, Thread[Equal[s /. rl, Factor[Activate[s] /. rl]]]] // Column // TeXForm \begin{array}{l} \underset{i=1}{\overset{n}{\sum }}i=\frac{1}{2} n (n+1) \\ \underset{i=1}{\overset{n}{\sum ...


1

Szabolcs already answered in detail the question that was asked, but I'd like to comment on an implicit question: how do you keep f[x] in your example from evaluating? First realize that f[x] will be substituted into something which will evaluate, unless it has hold attributes such as these: Hold, HoldForm, Defer. Then you need a way to keep f[x] from ...


1

Question How do I prevent Part[] from trying to decompose symbolic expressions when it is evaluated? Mathematica 10 implements something like your listPart (with additional functionality): Indexed: Indexed can be used to indicate components of symbolic vectors, matrices, tensors, etc. When expr is a list, Indexed[expr,i] gives ...


4

Well that's a hairy one. I like it though, as it forced me to think about aspects of evaluation that I am normally oblivious to. Unfortunately that thinking didn't lead to any great insights. My only idea so far is to interrupt evaluation and mess with the Stack as Leonid did for How do you set attributes on SubValues? I have little experience in this ...


0

UPD: Looks like I accidentally dismissed everything in the post below the horizontal line confusing it to comments, and tried to answered a more general question than needed. Too bad. To clarify: the idea represented below is to have [still immutable] objects with pointers (in the form of symbols) to their properties inside the objects themselves, which ...


4

How about the old Gayley-Villegas trick? Obj /: (lhs_ = Obj[id_]) := Block[{$inSet = True}, lhs /: (lhs["Property"] = value_) := setObjProperty[id, value]; lhs /: Unset[lhs] := ClearAll[lhs]; lhs = Obj[id] ] /; ! TrueQ[$inSet] Then we get the following behaviour: obj = Obj[1]; UpValues[obj] {HoldPattern[obj["Property"] = value$_] ...


0

Dynamic is sometimes too aggressive for some purposes. You need to make sure Dynamic updates only when you are ready for new results. Besides, to ensure that Dynamic will have enough time to process your request it is sometimes a good idea to use SynchronousUpdating option. In the solotuion below you will see that instead of calculating the menu options ...


8

I'm the one inside the company who suggested RightComposition (and pushed for syntax for Composition and RightComposition). I'm sympathetic to your need, and have wanted the same thing once or twice myself. Given that not much /* and @* code has been written yet, I think it is certainly possible we could have /* parse to LeftComposition. I'm not sure what ...


6

Using this site as my rubber duck and attempting to answer my own questions: (1) Reason for existing behavior One may want to be able to do this: heldRow = HoldForm @* Row @* List; (* version 10 syntax *) x = 7; Block[{x}, heldRow[x + x + x, x^2*x^3] ] 3 xx^5 (* proposed behavior would yield: x+x+xx^2 x^3 *) My counterargument: this ...


1

I propose using the step function I presented in: How do I evaluate only one step of an expression? (For the remainder of this answer I will assume you have that function loaded.) I wrote it for the purpose of handling delayed definitions such as: expr := (p == q || p == q + 1) You could use it in the following manner: SetAttributes[f, HoldFirst] ...


3

Eldo's answer only works for a very restricted set of inputs. Here is a much more general solution. validNum = Except[_Complex, _?NumericQ]; eldoDiff[θ1 : validNum, θ2 : validNum] := Plus @@ ({θ1, θ2} /. Rational[a_, b_] :> Rational[1, b]) mgDiff[θ1 : validNum, θ2 : validNum] := (With[{a = Mod[Abs[θ1 - θ2], 2 π]}, Min[a, 2 π - a]] /. Degree -> ...


2

VectorAngle[{Cos[#1], Sin[#1]}, {Cos[#2], Sin[#2]}] & @@ {3 Pi/4, -3 Pi/4} Edit. taking the point mentioned by m_goldberg: data = {{-((3 π)/4), (3 π)/4}, {-135 °, 135 °}, {-2, 1}}; VectorAngle[{Cos[#1], Sin[#1]}, {Cos[#2], Sin[#2]}] & @@@ data//Simplify (* {Pi/2, Pi/2, 3} *)


4

I think your definition of d is not properly generalizable because the list dimensions don't match when doing higher derivatives. So I instead use a simpler definition of the Gateaux derivative from Wikipedia which does exactly the same thing as what you're trying to do. I call it gatD, and it takes the operator, the function u and a List of test functions. ...


3

When you use the syntax f[x_]:= ... in Mathematica, you are not defining a function f. You are defining a pattern-replacement rule. The documentation and the users tend to be vague or misleading or just incorrect about this point. Of course you can define "function" as something quite to your liking and ignore the protestations of mathematicians, ...


1

The OP asks in a comment: One more question. Clear[f, g];f = g;f[x_] = x^4, I can understand the result of ?g. However, why {g,h,j}[[1]]=6 causes error? When using =(Set), MMA first evaluate the first part f and {g,h,j}[[1]] to g and g right?(i.e. always evaluating lhs before assignment) Why is f[x_] = x^4 ok, but not {g,h,j}[[1]]=6? The OP indicates ...


15

I'm guessing you're coming from a programming language where every expression must evaluate to a value, and if it didn't evaluate to something (like 5[Cos+Sin]), it's a syntax error. To me, Mathematica started to make a lot more sense, once I stopped thinking about functions and values, and started to think of every expression as evaluating to an "expression ...


1

@Daniel Lichtblau's comment seems like an answer that is worth putting in an answer: (1) Integrate will not catch conditions that are discrete. (2) As was pointed out already in comments, the result is correct anyway; the singularity is removable (e.g. via Limit). Edit: I might add that GenerateConditions might yield a ConditionalExpression but not a ...


4

Look what you get when you evaluate your first example function: f[2, y, z] (* 1/4 y^2 (-y^2 - z^2) + 1/4 z^2 (-y^2 - z^2) + 1/8 (-y^2 - z^2)^2 *) You get a nice simple polynomial. When you use Evaluate you are effectively replacing f[2, y, z] by that polynomial before Plot3D "sees" it. Plot3D samples that polynomial at various values of $y$ and $z$ to ...


2

bindeaa[e0_] := e0; c[e0_] := 40 e0; bindeab[e0_] := 1.27 e0; (* bindeab is not used and can be eliminated unless used elsewhere in your \ code *) alpha[gamma_, p_, epsilon_] = p (gamma - epsilon); beta[b_, epsilon_, n2_] = b epsilon^2 n2^(3/2); eisl[b_, e0_, g_, gamma_, p_, epsilon_, n2_, x_] = g c[e0] (epsilon)^2 - bindeaa[e0] + e0 ((-2 Log[E^(1/2) ...


5

Define the helper functions and variables like this: F[x_] := {x[[2]] x[[3]], -x[[1]] x[[3]], -0.51 x[[1]] x[[2]]} dt = 0.1; xi = {0, 1, 1}; Do not define xj since you need to use that as a single symbol in FindRoot. Now this equation, xj == xi + dt F[xj] makes sense if we substitute a concrete vector value for xj. If we don't the equation will still ...


1

Maybe this type of visualization will help understand the evaluation order better. Things are printed in InputForm here, but please "think" FullForm when you look at expressions. In[2]:= On[] Plus[3^3,6*9] Off[] During evaluation of In[2]:= On::trace: On[] --> Null. >> During evaluation of In[2]:= Power::trace: 3^3 --> 27. >> During ...



Top 50 recent answers are included