Questions tagged [attributes]

Questions on attributes of functions.

Filter by
Sorted by
Tagged with
2 votes
1 answer
61 views

SetAttribute for indicized variables? [duplicate]

Is there a way to SetAttributes to a function defined like this: fun[t_][x_,y_] Something like ...
user avatar
  • 6,104
0 votes
1 answer
68 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. ...
user avatar
  • 289
1 vote
0 answers
54 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 ...
user avatar
  • 340
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 ...
user avatar
  • 4,138
2 votes
1 answer
72 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 ...
user avatar
  • 2,451
1 vote
1 answer
41 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 ...
user avatar
  • 107
1 vote
1 answer
61 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: ...
user avatar
  • 179
0 votes
0 answers
20 views

How to set attributes for f[x_][y_]? [duplicate]

This doesn't hold expr: ...
user avatar
  • 1,055
2 votes
0 answers
36 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 ...
user avatar
2 votes
0 answers
71 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 ...
user avatar
1 vote
2 answers
51 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: ...
user avatar
  • 1,647
1 vote
1 answer
44 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 ...
user avatar
  • 1,647
5 votes
1 answer
107 views

head of a sequence

Why does Head[Sequence[b, c]] return c[Symbol] and not Sequence? Why does ...
user avatar
  • 1,004
7 votes
2 answers
184 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: ...
user avatar
  • 229
1 vote
1 answer
53 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. ...
user avatar
  • 743
1 vote
1 answer
157 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: ...
user avatar
  • 127
2 votes
2 answers
67 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: ...
user avatar
  • 967
1 vote
1 answer
39 views

FilterRules works in DateListPlot but not in Plot

I just experience the following problem (this is a MWE just to illustrate). First DateListPlot ...
user avatar
  • 5,453
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 ...
user avatar
  • 1,760
2 votes
1 answer
46 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 ...
user avatar
3 votes
2 answers
120 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 ...
user avatar
  • 530
6 votes
1 answer
139 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 ...
user avatar
  • 457
3 votes
2 answers
134 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 ...
user avatar
  • 2,451
2 votes
0 answers
36 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: ...
user avatar
1 vote
1 answer
42 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? ...
user avatar
2 votes
2 answers
142 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: ...
user avatar
  • 1,274
0 votes
1 answer
50 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 ...
user avatar
  • 1,274
2 votes
2 answers
73 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 ...
user avatar
1 vote
2 answers
203 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 ...
user avatar
  • 11
2 votes
1 answer
233 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 ...
user avatar
  • 889
1 vote
1 answer
51 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 ...
user avatar
  • 81
2 votes
1 answer
191 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 ...
user avatar
  • 917
3 votes
1 answer
101 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 ...
user avatar
  • 1,941
6 votes
2 answers
218 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 : ...
user avatar
  • 1,973
1 vote
1 answer
116 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 ...
user avatar
  • 13
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. ...
user avatar
  • 121
1 vote
1 answer
90 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: ...
user avatar
1 vote
1 answer
153 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 ...
user avatar
  • 4,391
7 votes
4 answers
544 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 ...
user avatar
  • 1,183
2 votes
0 answers
68 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 ...
user avatar
  • 1,183
4 votes
1 answer
106 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: ...
user avatar
  • 8,561
3 votes
1 answer
95 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 ...
user avatar
  • 8,561
1 vote
0 answers
81 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 ...
user avatar
  • 3,980
0 votes
1 answer
90 views

Modelling non-commutative products, CenterDot problem

I am trying to model certain non-commutative, but associative, structures with Mathematica. As a notation for the product I take CenterDot and add the attribute Flat since the product is associative. ...
user avatar
  • 33
4 votes
1 answer
104 views

Concerning the Attribute Flat

Suppose we have a function f with the Attribute Flat. From my understanding, the following command should return all possible ways of rewriting ...
user avatar
  • 663
4 votes
2 answers
294 views

Make Times non-commutative only for a specific set of expressions

I'm making a small hacky notebook and want to avoid using external libraries. In my notebook, I'd like multiplication to be non-commutative only for a particular family of expressions whilst still ...
user avatar
4 votes
1 answer
186 views

What are Flat Attribute best practices? [duplicate]

I would like, as an example, to build a Times-like function. Take the following example ...
user avatar
  • 889
5 votes
1 answer
482 views

Define a distributive function?

Here is a related question, but not quite what I'm after. I would like to define a function f[x_] that has the distributive attribute, such that: ...
user avatar
  • 11.5k
4 votes
1 answer
83 views

Listable function behaving in an unexpected way

For example, if I define a function like this: SetAttributes[func,Listable]; func@{{1,2},{3,4}} it gives the result like: ...
user avatar
  • 1,941
13 votes
2 answers
467 views

Why is listable not an attribute of the Set function?

The following is a list of attributes for the Set function: Attributes[Set] ...
user avatar
  • 315