# Questions tagged [upvalues]

The tag has no usage guidance.

62 questions
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 ...
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 ...
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 ...
238 views

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 ...
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 ...
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: ...
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 ...
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: <...
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 ...
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. ...
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 ...
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, ...
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 ...
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 ...
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 ...
204 views

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 (...
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 ...
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 ...
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. ...
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 ...
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, ...
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 ...
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 ...
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: ...
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 ...
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 ...
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. ...
88 views

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, ...
143 views

### $\tt AddTo$ regression in v10

As we know we can assign special addition rules to symbols by using UpValues: ...
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 ...
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. ...
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[] ...
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 ...
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 ...
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}}] ...
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]...
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 ...
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: <...
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 ...
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 ...
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 ...
142 views

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 ...
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 ...
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 ...