Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [upvalues]

The tag has no usage guidance.

1
vote
1answer
63 views

How to use an up-value assignment when all symbols are “too deep”?

I would like to make an up-value assignment such as a/:Conjugate[a[x]]a[x]+Conjugate[b[x]]b[x] = 1 or ...
5
votes
2answers
98 views

How to prevent arguments UpValues from being used in selective functions

Ok, I know the simple answer is to set some form of Hold attribute to the function but bear with me for a bit while I explain my motivation and why that is not quite what I want. I have a collection ...
1
vote
0answers
33 views

Understanding TagSetDelayed

I was reading What is the distinction between DownValues, UpValues, SubValues, and OwnValues? and I started to be confused with the part "Upvalues" of the first answer. Some of my confusion comes ...
8
votes
2answers
238 views

Overloading functions like Mean for distributions

I'd like to understand how functions like Mean are overloaded to provide the right behavior for the distributions in Mathematica (like NormalDistribution or PoissonDistribution). I originally assumed ...
1
vote
0answers
31 views

Holding evaluation of flat, orderless, function in up value [closed]

I have an operator that is flat and orderless that I want to evaluate only after the expression has been entirely flattened. Essentially, I want an expression of the form ...
8
votes
2answers
175 views

Issue with Upvalues

I want to introduce two variables (I call them EXt and EXtC, where "C" stands for complex conjugate) which would mimic the behavior of a phase of a complex number. For that, I use the following tags: ...
6
votes
2answers
196 views

What makes a pattern more general?

This is a rewording of the question. The original post is below. How come that a pattern for an expression with a specific head is not more specific than a pattern for an expression with a generic ...
9
votes
0answers
81 views

List assigment ({…}={…}) and UpValues

Let's say I want to track any assignment attempt for a variable a: a /: Set[a, x_] := Print@{a, x} This works as intended: <...
5
votes
1answer
87 views

? vs Information - Making UpValues less destructive

I'll first state the main question of this, what follows afterwards are some of my thoughts/attempts at fixing it and additional questions about possible improvements (getting an answer to those would ...
6
votes
1answer
86 views

TagSet for symbol inside NumericQ behaves differently than in other fooQ functions

I am trying to define some symbols as being numeric by using TagSet and encountered the following different behaviors between NumericQ and e.g. ...
2
votes
0answers
106 views

What is the correct usage of HoldFirst?

I encountered a situation where using HoldFirst seems to do the trick for the specific task, but I am uncertain about the proper use of this attribute. Consider ...
0
votes
0answers
57 views

Defining UpValue like replacements confined to exprs with specific Head

I'm not seeing a clean method to redefine builtin functions like Cross, Dot, etc. in such a way they only are only applied to expressions that are using some marker-like Head value. Reduced example, ...
2
votes
3answers
221 views

Define derivatives of symbols

I have a symbol a appearing in my computations, which has a complicated definition in terms of other variables. However, I know that any derivative of ...
1
vote
1answer
90 views

How to find all up-value symbols related its object

Suppose I set a series up-value for a rectangle like: rectangle[long] ^= 10; rectangle[width] ^= 12; rectangle[height] ^= 28; How to find all of the symbol about ...
1
vote
0answers
72 views

How to update a Text Field Widget during evaluation of a function

My problem is rather simple, I need that the TextField widget named Sumfield updates its value during a function evaluation, in ...
2
votes
1answer
204 views

Tag protected error for Grad despite using Unprotect[Grad]? [duplicate]

I've defined an upvalue grade[k,m], where k is an integer and m is a matrix, and have defined a number of overrides for this type in the normal Mathematica namespace (...
1
vote
0answers
57 views

Another question on using UpValues with Derivatives

I want to create an UpValue that will cause a function that is zero for it's second derivative to have a value when the second derivative is integrated. The ...
0
votes
1answer
58 views

Trying to “fix” Simplify, but cannot Up/DownValue it because it is Protected

There is an irksome shortcoming for Simplify that I encountered: Simplify not evaluating completely with Square roots -- still not entirely sure if it's because of AssumptionsMaxNonlinearVariables ...
3
votes
1answer
182 views

Simplify not evaluating completely with Square roots

Here's a simple question. It's no longer high priority that I know this, but it's something that can come in handy later on. ...
1
vote
0answers
60 views

Is there a better way to overload Plus?

I'm writing a function to produce a more readable version of output which consists mainly of Plus[seq__] where seq__ matches-for ...
14
votes
1answer
305 views

How to define homogeneous functions that respect Euler's theorem of homogeneous functions?

A homogeneous function of degree $k$ is defined as a function that observes the following specification rule: $f(a x_1, a x_2, ..., a x_n) = a^k f(x_1, x_2, ..., x_n)$ (see Wikipedia entry, ...
5
votes
2answers
103 views

Local modification of built-in command via UpValue

I have a computationally intense function f that returns a matrix. Sometimes only the diagonal is needed, which is faster to compute, thus there's a syntax for f to ...
1
vote
0answers
468 views

Setting derivative of function equal to 0 at x=0 using UpValues

I'm trying to set the derivative of a function to zero at a specified point. This will act as an initial condition for an algorithm I'm writing: so I'm specifying the value of the function at x=0, and ...
4
votes
1answer
132 views

Upvalues for Missing do not work with Dataset

Consider the following Dataset: d = Dataset[<| 1 -> Missing[], 2 -> 1.0, 3 -> 4.0 |>] And the following Upvalue for Missing: ...
3
votes
0answers
47 views

Custom iterable objects

I understand that to create objects with custom behavior with respect to existing code one uses upvalues. However, I'm at loss when it comes to guess what interface is expected from objects fed to ...
11
votes
4answers
298 views

How to prevent Quantity calculations from converting units

I have an accrual calculation that I would like to preserve the units even though they are of the same dimension (e.g. time). For example, I would like the following ...
10
votes
1answer
260 views

How to deal with bad arguments when a function's UpValues is a pure-function?

In practice, I needs to define the UpValues of a user-defined function. For instance, the operation of function like differential formula , expansion and so on. ...
3
votes
1answer
88 views

Define behavior of an expectation function wrt derivative

I wanted to calculate the expressions for Ursell functions $$u_n(\sigma_1,\ldots,\sigma_n) = \frac{\partial}{\partial a_1}\cdots \frac{\partial}{\partial a_n}\log E(\exp\sum a_i\sigma_i)\big|_{a_i=0}$...
5
votes
2answers
251 views

Why this upvalue doesn't escape from Sum?

Probably a hard question, but I decide to cry out loud :). This is actually another problem I encountered when answering this question. Consider the following transform rule stored as an upvalue: <...
11
votes
1answer
143 views

Strange behavior of UpSetDelayed together with MakeBoxes

In order to answer this question, I just stumbled into the world of UpValues. Though I managed to find a solution for the problem, I'm confused by my own code now 囧,...
2
votes
1answer
100 views

Writing my own error and warning messages

Question: How is message handling implemented in Mathematica when applying Set to unprotected global variables such as $TimeZone...
4
votes
1answer
239 views

How to tame the wild MMA?

MMA is a free country. But TOO free sometimes. Just as an example: Clear[a] a[x_] == a[y_] ^:= Round[x] == Round[y] {a[3] == a[3.01], a[3] == a[4]} is {True, ...
12
votes
1answer
143 views

$\tt AddTo$ regression in v10

As we know we can assign special addition rules to symbols by using UpValues: ...
2
votes
1answer
71 views

What workarounds are there to TagSetDelayed::tagpos?

My program creates an object based on an Association, with a custom head: g = Gate[<| "key1" -> val1 |>] I have ...
6
votes
1answer
197 views

How to create fast functions based on units?

Using units is a good means for rapidly developing code, since it provides some error control. Hovewer, using Mathamatica functions containing units appears to be copmutationally inefficient. ...
10
votes
2answers
475 views

Using up-values and down-values

I have a problem I'm trying hard to find a solution for, although I don't know if a solution exists. The following rules produce the result e[2].f[] ...
21
votes
2answers
488 views

What does f_[whoCalled]^:=f really mean?

I came across the following post by John Doty in this Google Groups discussion: On Friday, January 11, 2013 8:23:16 PM UTC-7, amzoti wrote: It is clear the Mathematica uses Lisp as one ...
1
vote
0answers
87 views

Upvalues and order of interpretation

I'm trying to use UpValues to improve the usability of some code, but I am running into an issue where the order of the UpValues is important, and I am not sure if it is my understanding or a ...
8
votes
1answer
164 views

How to assign up-values for `Derivative`?

I have defined several custom analytic functions. Here is the simplest example: ln[x_, a_?NumericQ] := Piecewise[{{Log[x], Re[a] > 0}, {-Log[1/x], True}}] ...
1
vote
2answers
73 views

Changing a tag when one function is passed into another using UpValues

I have two complicated functions f[x,y] and g[t]. Before the main evaluation code in g[expr]...
12
votes
2answers
287 views

Why isn't Lookup treated like other symbols?

With Mathematica 10, I wanted to overload Lookup using TagSetDelayed, but it doesn't work. For instance, if I define two objects ...
5
votes
1answer
134 views

Strange behaviour of UpSet [duplicate]

Can anyone explain what is going on here? I want to modify TensorRank for IdentityMatrix, but it fails on its first attempt: <...
5
votes
3answers
3k views

How to force 2+2=5

I was looking at this question (writing a program such that 2 + 2 = 5) and tried to write something in Mathematica, but I couldn't get something to work without completely replacing ...
4
votes
1answer
316 views

Inheritance in Mathematica using pattern matching on UpValues

Edit: I think in my original post, I missed emphasizing the main point. This is mainly a pattern matching question. If you're interested in the 'why' of this question, please read the original post ...
6
votes
2answers
396 views

How to customize derivative behavior via upvalues?

I'm having trouble getting customized derivatives (defined using upvalues) to behave in sane ways. By this I mean that I'd like to define a derivative using an upvalue and then have Mathematica apply ...
5
votes
1answer
142 views

Add options to upvalues

I have some objects that I want to present in TeXForm. Thus, it is easily to do as follows: YoungTableau/:TeXForm[YoungTableau[diagram_]] However, what if I ...
8
votes
3answers
483 views

Make Sinc'[0] return 0 instead of Indeterminate

I want Sinc'[0] to return 0, but instead it returns Indeterminate. I've tried Unprotect[Sinc] Unprotect[Derivative] Derivative[1][Sinc][0] ^= 0 But it doesn't ...
3
votes
1answer
145 views

Experiment with TagSetDelayed involving Part

Reading Associating Definitions With Different Symbols, I was intrigued by this: You can think of upvalues as a way to implement certain aspects of object-oriented programming. A symbol like ...
0
votes
2answers
172 views

How do I use a passed-in symbol as a tag to define UpValues?

ClearAll@foo; foo[tag_] := ( tag /: tag[i_] := tag[[i]] ); a = {7, 8, 9}; foo[a]; a[2] I wanted the above to output 8, ...
3
votes
1answer
149 views

Why is held expression evaluated?

Context: I'm studying non-linear dynamics. As part of a bigger problem, I'd like to generate lists of the form {{deq, ic1}, {deq, ic2}, ...}, where ...