# Tag Info

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 ...

10

Regarding the plot issue, I tried using HoldForm[x = Stack[_]] as an axis label to capture the stack at the moment of evaluation inside HoldForm. This revealed a problem in a helper function for dealing with units. The function VisualizationUtilitiesOptionsDump`unitFormStringQ is applied to the axis labels (in a pattern test). The definition is this: ...

9

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]]]}]

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 ...

7

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 ...

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 ...

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 ...

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 ...

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$_] ... 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, ... 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} *) 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. 1 TraditionalForm@FullSimplify@Exp[FullSimplify@PowerExpand[ Log[((Ft Bcr)^(2 p + 4)*Ft^(23 p - 4))/(Bcr^(1/(2.5 p - 4))* Ft^((24 p + 4)/(3 p - 1)))^(3 p - 6)]]]$\text{Ft}^{p+\frac{60}{3 p-1}+36} \text{Bcr}^{-\frac{1.2}{4.\, -2.5 p}+2. p+2.8}\$

1

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 ...

1

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.

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 ...

1

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 ...

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] ...

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 ...

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 ...

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