Questions tagged [attributes]
Questions on attributes of functions.
140
questions
1
vote
1
answer
53
views
Setting PlotRange conditionally
I have several sets of data, and each set of data has a different scale (i.e., a different range of function values). I wish to plot each data set separately. I can do this using ...
0
votes
0
answers
39
views
Can I define relations without explicit transformation rules?
Is there an alternative way to use Mathematica for symbolic algebra, where instead of defining explicit transformation rules into 'canonical form', I can instead 'gently inform' Mathematica about ...
4
votes
2
answers
122
views
Replace vs. ReplaceAll involving Flat
I'm aware that Replace and ReplaceAll behave differently as discussed in this question, but still get confused with the ...
2
votes
0
answers
32
views
Attributes for functions with currying [duplicate]
Is there a way to set attributes for a function which holds for all arguments when currying?
When evaluating, e.g.,
...
11
votes
2
answers
204
views
How to make a function with two patterns listable?
Suppose that I have a function that has two patterns:
disksConstantRadius[radius_][points_] := Disk[#, radius] & /@ points
(noting that this would be better---...
4
votes
1
answer
129
views
How to construct the HoldAll version of Information[]?
When building other functions I need the HoldAll version of Information, and the usual method seems not to work.
Firstly as a ...
4
votes
2
answers
150
views
How to define a function to be numeric when the input is purely symbolic
My goal is to have NumericQ[h[j]]=True for any j regardless of whether j may be symbolic with no defined value.
Setting NumericQ[h[j_]]=True does not work and as I understand the NumericFunction ...
0
votes
1
answer
36
views
index as an attribute for a function containing data frame
Two questions. I have created a sample problem, and would be glad to have your help.
I have 2 functions, fun1 and fun2, and one ...
2
votes
1
answer
71
views
SetAttribute for indicized variables? [duplicate]
Is there a way to SetAttributes to a function defined like this:
fun[t_][x_,y_]
Something like ...
0
votes
2
answers
114
views
How can I remove the attributes "Orderless" from function Times stably and reliably?
Recently I have been doing some algebra of partitioned matrices, where product like below is common:
where $A_{11}, A_{12}, X, Y$ are all partitioned matrix blocks thus all are matrices in essence.
...
1
vote
0
answers
112
views
How to make a function in terms of constants to inherit the attribute of being constant
I have defined two variables a and b:
SetAttributes[a, Constant];
SetAtributes[b, Constant];
I have defined a function c as ...
1
vote
0
answers
46
views
Defining a function expression [duplicate]
I'm sure this has been answered before, but imagine I have the following function
...
2
votes
1
answer
80
views
Construct really identical function (the same as Length)
In[1] Length[Unevaluated[1 + 1 + 1 + 1]]
Out[1] 4
Q1) Can we construct a function named f, such that ...
1
vote
1
answer
51
views
HoldAll doesn't work for List or BlankSequence?
Consider the following function:
f[arg_] := Print[Unevaluated[arg]];
Attributes[f] = HoldAll;
The purpose of the function is to print the arguments unevaluated. In ...
1
vote
1
answer
81
views
Defining a two-variable function with a parity property
I would like to define a function that has the following property $f(-x,y)=f(x,-y)$.
An example is $f(x,y)=x y$. For simple inputs, I can impose this easily enough as:
...
2
votes
1
answer
73
views
Example of when explicitly using MapThread is better than giving a function the Listable Attribute
This answer says that Listable just makes the function automatically apply MapThread to its arguments.
Does anyone have a simple ...
2
votes
0
answers
81
views
Ways to hide a secret token with some code?
I worked out a way to prompt notifications to peopel using my mathematica code that a new version is available. My code is in a private github repository, mathematica can access it using http requests ...
1
vote
2
answers
59
views
How to define a function that acts invidually on a varible number of arguments
I am trying to generate a function that applies to each argument for any number and type of arguments. The function might work like this:
...
1
vote
1
answer
54
views
Extracting name of symbol (variable name) from within a function not working
Abstract: I use a pattern so often that I needed to make a function for constructing it. A function getName[...] for extracting name of variable and value only ...
5
votes
1
answer
132
views
head of a sequence
Why does Head[Sequence[b, c]] return c[Symbol] and not Sequence?
Why does ...
7
votes
2
answers
215
views
Defining a function which is numerical on all vectors of arguments
There is an attribute NumericFunction in Mathematica that can do the following job:
...
1
vote
1
answer
55
views
Attributes for private functions
I am not sure if what I want to do can be done, but I thought to ask anyway.
Note: I already have in hand a workaround, I was just wondering for the power/simplicity that Mathematica may provide.
...
1
vote
1
answer
276
views
Define symmetric function for a subset of variables
I apologize if this question has been asked already. I did some research and found some solutions but none of them was general enough for what I need.
So, I defined the following function:
...
2
votes
2
answers
79
views
Evaluation Control for interpolating functions
I would like to find the root of the third component of an interpolating function, here e.g. a BezierFunction p:
...
1
vote
1
answer
45
views
FilterRules works in DateListPlot but not in Plot
I just experience the following problem (this is a MWE just to illustrate). First DateListPlot
...
0
votes
0
answers
45
views
How to make a Flat function return x when evaluated as f[x]? [duplicate]
With SetAttributes[f, Flat], f[a_] can get matched to f of any number arguments. How can I ...
2
votes
1
answer
53
views
Using the value of OptionValue to clear a list
I'm currently using OptionValue inside a function, the Option I passed to the function should be cleared, then populated with ...
3
votes
2
answers
122
views
When do functions apply on lists and when they do not
I have read in my lecture notes on Mathematica that functions (in the general sense) can be applied to lists of data and that they can return new lists with data. I have tried this and I have got ...
6
votes
1
answer
160
views
Is it possible to make listable Experimental`NumericalFunction?
I have been playing a bit with the undocumented function
Experimental`CreateNumericalFunction
and I wanted to know if somebody found a way to make generated ...
3
votes
2
answers
158
views
Construct a function that maps strings to functions
The main question is the last 5 lines (including codes) of this article.
A[x_, y_] := Evaluate[ToExpression["x^2+y^2"]]
A[3,4]
Then the output becomes
...
2
votes
0
answers
39
views
Mathematica: Remove argument from object with flat attribute
I have an object in mathematica with the attributes Flat and OneIdentity. I also defined the following substitutions:
...
0
votes
1
answer
46
views
Mapping function into elements of Sum
I'm trying to set an attribute that's valid for a generic sum, where n and f are arbitrary.
de[A_ + B_] := de[A] + de[B]
de@Sum[f[i], {i, n}]
Is this possible?
...
2
votes
2
answers
146
views
Returning the argument of a function if the argument is not of the right type
Best to give an example. Let us consider the function AdjacencyMatrix. When we pass, say a matrix to it, we get:
...
0
votes
1
answer
56
views
Preventing an output of a function from being assigned a value
Say I have a function
Example[n_Integer]:=n{x,y,z}
Example@4
{4 x, 4 y, 4 z}
Now, let us assign some values to ...
2
votes
2
answers
75
views
How can one eliminate results in which symbols are assigned constant values?
As an exercise (pertaining to my posting Perform a constrained integration over $[-1,1]^6--yielding a "separability probability"), I issued the command
...
1
vote
2
answers
307
views
Computation with arrays of numbers
My code is
m = RandomVariate[NormalDistribution[], 100];
c = 0.1;
f1 = RandomVariate[NormalDistribution[], 100];
F = Sqrt[c]*m + Sqrt[1 - c]*f1;
I would like to ...
2
votes
1
answer
412
views
Defining an operator with given properties
In symbolic derivations with Mathematica, one often needs to define an operator with some desired properties, which will be used to stand for a general function or transform.
For example, I would ...
1
vote
1
answer
60
views
ScrollPosition Synchronization
Two separate Panes. Pane-1 with vertical scroll bars and Pane-2 no scroll bars. Need to sync the scrolling between them. When scrolling Pane-1 vertically, need to have pane 2 automatically scroll to ...
3
votes
1
answer
227
views
Fast and Listable Piecewise function
I am writing a simulation where I have an array with ten columns and on the order of millions of rows, for which I need to iterate on the order of ten thousand times, making computation time a major ...
3
votes
1
answer
106
views
HoldFirst being overridden by Activate [duplicate]
So here's the problem
a=1;a=2
works because of the HoldFirst attribute of Set, so that it ...
6
votes
2
answers
271
views
Flat attribute : example I don't understand
I am just beginning to learn about attributes of function in mathematica.
I saw the example "Flat". But there is something I don't get :
...
1
vote
1
answer
165
views
Problem displaying Killing equations
What I'm trying to do is to compute the Killing equations and then solve them using DSolve to determine their solutions.
I have a problem understanding where my Mathematica program doesn't work ...
0
votes
1
answer
72
views
How can I get all the order of a list? [closed]
I have a list such as : {1,3,6}, then, I want to get all the orders of it, I do not know which function is easier. I have to try this code, but it is complex.
...
1
vote
1
answer
93
views
Pattern matching on Orderless functions
I'm trying the following pattern matching command:
ReplaceList[Hold[b + a], Hold[x___ + y___] -> {{x}, {y}}]
And Mathematica returns:
...
1
vote
1
answer
196
views
Pick the solutions that satisfy certain conditions
I have a large system of ODEs, and I find a large number of steady-state solutions. But many of them do not satisfy the condition that all the variables must have ...
7
votes
4
answers
567
views
partial numerical evaluation
Context
The following is an issue I have come across many times and still do not have a satisfactory solution for.
The context of it is this. Let's say we have an equation, a linear ODE for the ...
2
votes
0
answers
71
views
non listable plus and times [duplicate]
I am trying to create my own Plus and Times functions, which are identical to the built in ones with the exception that they are ...
5
votes
1
answer
116
views
Subtle order-of-evaluation issues when pattern-matching with attributes
Related question concerning unrolling the tests that are shown below:
Big and Little surprises when unrolling tests of pattern-matching and attributes
Questions researched before posting this one:
...
3
votes
1
answer
105
views
Big and Little surprises when unrolling tests of pattern-matching and attributes
Related question concerning interpretation of the substitutions:
Subtle order-of-evaluation issues when pattern-matching with attributes
Questions researched before posting this one:
Orderless ...
1
vote
0
answers
83
views
Is it possible to modify the behavior of Listable?
Is it possible to achieve Thread-like behavior using the Listable attribute either on a symbol or in a pure function (or ...