Tag Info

Hot answers tagged

5

This is what I have so far. It's far from complete, but still a good start I think. listableQ[s_Symbol] /; MemberQ[Attributes @ s, Listable] := True listableQ[s_Symbol] := MatchQ[DownValues[s], {__?test2}] listableQ[Verbatim[Function][_, _, attr_]] /; ! FreeQ[{attr}, Listable] := True listableQ[Verbatim[Function][vars_, body_, ___]] := test1[vars, body] ...


5

This function yields True if the expression expr is valid, otherwise it yields False: validExpressionQ[ expr_, allowedList_List] := Union @ Cases[ Variables[expr], f_[x___] :> x, Infinity] == Union @ allowedList now we have, e.g. validExpressionQ[ x f[a, b, d] - 4 f[b, a, d] + z f[] + f[a, b, d] - f[a] f[b, d], {a, b, d}] True ...


5

Assuming[n ∈ Integers && n > 0, PolynomialQ[x^n, x]] won't work because Assuming only works on functions with Assumptions option, such as Simplify, Refine, etc. Unfortunately PolynomialQ doesn't have this option. Still, something like Simplify[PolynomialQ[x^n, x], n ∈ Integers && n > 0] won't work because Mathematica will calculate ...


4

Apparently you know somehow that n is a non-negative integer, but Mathematica has no idea. n could be anything. You need to let Mathematica know. Since PolynomialQ doesn't honor Assuming, you would need to make your own that does. Using Simplify could incorporate the assumptions. Here is my attempt at it (though my pattern-fu is not very strong -- e.g. ...


4

In Version 9, there is a new function DuplicateFreeQ which returns True is there is any duplicate elements in a list. This function is currently not documented, but it is there. Examples: snake = {{0, 1}, {0, 0}, {1, 0}, {2, 0}, {3, 0}} DuplicateFreeQ[snake] (*True*) a = {1, 2, 3, 3}; DuplicateFreeQ[a] (* False *) a = {1, 2, 3}; DuplicateFreeQ[a] (* ...


3

Jump straight down to Update 2 for the final code. I'll leave the previous iterations here as they explain how that solution developed. This is based on the following definition of similarity: Two expressions are similar if they become identical when all variables are replaced by the same generic variable. For example, both $a+b$ and $b+c$ become ...


3

This is not an answer, but some clue which I think might suggest a bug on what is going on. First I'd like to state that the following test is done in Mathematica 9.0.1 only, and I have no idea about the cases in other versions. The inconsistency Now let's start a fresh kernel, evaluate one of the examples in the question: PossibleZeroQ[Re[Root[5 + 20 ...


2

As far as I can tell, in general there is no way to do what you want. One can't generally measure the memory requirements etc. for delayed definitions, because for them the creation of corresponding values happens only at run-time. OTOH, you can't really exclude the delayed definitions, particularly when dealing with the code of others. It is a trade-off. ...


2

A possibility is to define a support function: EDIT: Thanks to Simon Woods' comment: .. instead of __ check[(a | b | d) ..] := 1; check[___] = Indeterminate; The substitution expr /. f-> check contains Indeterminate if f has arguments not allowed. Concluding: If[FreeQ[expr /. f -> check, Indeterminate], "ok", "error"] returns "error" for ...


1

data = {I (a^2 + b^2) (*1*), a (I b + e) (*2*), b (I a + d) (*3*), b (I a + f) (*4*), a b (*5*), a (I b + f) (*6*), I (b^2 + c^2) (*7*)} systemnames = Names["System`*"]; test[expr_] := Select[{Extract[expr, #], #} & /@ Position[expr, _Symbol, Infinity], MemberQ[systemnames , ToString@(#[[1]])] &] Gather[data, test[#1] == test[#2] ...


1

Is this what you want? ClearAll@ExactVarsQ; ExactVarsQ[func_, vars__] := MatchQ[ Sort@DeleteDuplicates@Cases[func, x_ /; (AtomQ[x] && ! NumericQ[x]), {0, Infinity}], Sort@DeleteDuplicates@{vars} ] test1 = (1 - Exp[I*(x - 5.6)*23.4])*Log[Abs[x - 4.3]]/(1.7 + 3.2*I - x^2) test2 = (1 - Exp[I*(x - y)*23.4])*Log[Abs[x - 4.3]]/(1.7 + 3.2*I - ...


1

Since it seems that evaluation of the expression is specifically permitted let's leverage that: check[expr_, f_, pat_] := FreeQ[expr /. f[pat ...] -> 1, _f] check[expr, f, a | b | d] check[expr, f, a | b | c | d] False True I used Alternatives instead of List to make this cleaner, but you can always Apply Alternatives if needed. If for some ...


1

Your updated request makes no sense me unless you mean something much simpler that you appeared to be attempting. Perhaps all you want is this: min = Min[x /. solutions] Min[-Sqrt[b3], Sqrt[b3]] min /. b3 -> 2 -Sqrt[2] I hope this helps. If not I'm at a loss. There are a couple of problems here. First, as Nasser comments your ...



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