New answers tagged

7

Introduction I'm not aware of any way to hold evaluation of arguments in expression of form Inactive[f][arguments], which is how inactivated expressions look like. What we can do, to prevent evaluation of arguments, is to use a symbol with appropriate Hold... attribute, instead of Inactive[f] expression. This symbol should have no DownValues that could ...


3

Note that Root is only considered numeric when its argument does NOT contain any non-numerical parameters. For instance: Root[(# - a) &, 1] (* Out: a *) NumericQ@Root[(# - a) &, 1] (* Out: False *) A similar argument applies to RootSum, Rational, and Complex: NumericQ@RootSum[a + # &, Log[#1] &] (* False *) NumericQ@Rational[a, 2] ...


3

I think you are not properly aware of how the kernel is evaluating your expression and how the front-end is printing the result. ClearAll[f] SetAttributes[f, HoldFirst] f[x_] := (x = 42) Now if f were to see 1 + 1 as an argument in either evaluated or unevaluated form, it would complain. f[1 + 1] f[2] but it doesn't complain when Inactive[f][1 + ...


3

This is the answer merged from this more recent question The form in question I meant the form Function[Null, body-using-slots, attrs] as ciao correctly noted. At least at the time when I wrote the book, this form hasn't been documented. I learned about it from Roman Maeder's book "Programming in Mathematica". OTOH, this form is very useful in some ...


4

We can get a long way by directly declaring that the symbols in question are NumericQ. For example, θ is normally treated as non-scalar: CircleDot[a, Times[θ, b]] (* CircleDot[a, Times[b, θ]] *) CircleDot[a, Times[Sin[θ], b]] (* CircleDot[a, Times[b, Sin[θ]]] *) NumericQ is a protected symbol, but its built-in definition still permits direct assignment (...


3

Try adding this to your existing definitions: (x_scalar a_)\[CircleDot]b_ := x (a\[CircleDot]b) This specifies a definition similar to your last one that only applies when the Head of $x$ is scalar, an auxiliary operator we introduce. Now, suppose that you want $t$ to be a scalar and $vec_i$ to be vectors: (scalar[t] vec1) \[CircleDot] vec2 (* Out: ...



Top 50 recent answers are included