Skip to main content

Questions tagged [upvalues]

The tag has no usage guidance.

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

Why can't I assign upvalues to NonCommutativeMultiply?

I'm trying to define a non-commutative product with respect to which, certain quantities (e.g. numbers, and some other quantities defined in my code) behave as "scalars" and can be pulled ...
user366202's user avatar
3 votes
1 answer
155 views

Pattern matching vs. condition in a function

I'm trying to learn stuff from pattern matching but I found sometimes pattern matching does not work as I expected. Could anyone explain why the below outputs are not same? Thank you. And could anyone ...
Josh's user avatar
  • 31
3 votes
3 answers
108 views

Can't get TagSetDelayed to match LHS when the latter has a Hold attribute set

I'm following this example here; Code Readability and Object-Oriented Code ...
RobertNathaniel's user avatar
4 votes
1 answer
101 views

Can UpValues (as well as other "*Values") always be converted to DownValues?

As this post has discussed, UpValues are certainly useful, and as this post has discussed, g /: f[g[x_]] := h[x] is not ...
user688486's user avatar
1 vote
0 answers
58 views

Overloading the Normal function

I am currently working on library that keeps functions in unevaluated form, e.g. In: a = RhoVariable[s] Out: RhoVariable[s] RhoVariable has some definition, namely ...
fqrt's user avatar
  • 84
1 vote
1 answer
54 views

How to clear a selection of definitions from UpValues?

I'm trying to set up a bunch of 2D points using UpSet that I am going to use later for building lines and graphs. ...
joka's user avatar
  • 342
17 votes
1 answer
467 views

Broken ValueQ function in Mma12.2?

f[x] ^= 1; ValueQ[g[x]] returns True in Mathematica 12.2. Is it a bug?
Roma Lee's user avatar
  • 926
1 vote
1 answer
85 views

Define a function for symbols with UpValues

Suppose that we define UpValues for different symbols isSpecialFunction[N1]^=True isSpecialFunction[N2]^=True isSpecialFunction[N3]^=True I would like to make the ...
apt45's user avatar
  • 1,688
5 votes
1 answer
34 views

How to duplicate UpValue of one function to another?

Let's say I have defined a function zO for the following up-values ...
LeafGlowPath's user avatar
  • 1,473
3 votes
0 answers
77 views

What are some ways to overload Min in order for it to work with user defined expressions?

I have defined size to work with discrete size labels: ...
yosimitsu kodanuri's user avatar
3 votes
1 answer
151 views

General definitions of deeply nested functions without SetDelayed, "UpUpValues"

I'd like to assign an "UpUpValue" in a way generalized to any nested head surrounding the value for which the UpUpValue would be defined. That is, if a function ...
Ghersic's user avatar
  • 1,177
4 votes
2 answers
330 views

How to set a rule that's too deep for UpValue?

I want to automatically transform Conjugate[a CenterDot[x, y, z]] to Conjugate[a] Conjugate[CenterDot[x, y, z]]. However, the ...
atbug's user avatar
  • 685
0 votes
1 answer
59 views

Modified "Plus" function: how to save just the final result of an addition of multiple objects?

In my version of object-oriented programming in Mathematica, essentially (without going into details) obj[a] is a reference to an object whose actual data is stored ...
user avatar
5 votes
2 answers
283 views

Efficiency of the rule _ * 0 := 0

In the standard evaluation process, innermost parts are evaluated first. For example: In[0]:= (a/a + 1) * 0 The evaluation process gives: ...
BP75's user avatar
  • 51
3 votes
1 answer
86 views

Upvalues of modified system functions

Suppose that someone (e.g. the author of a package I need to use) modifies the upvalues of a system function in the following way ...
vsht's user avatar
  • 3,572
1 vote
1 answer
121 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 ...
Kagaratsch's user avatar
  • 12.1k
5 votes
2 answers
174 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 ...
void life's user avatar
  • 352
1 vote
0 answers
205 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 ...
StarBucK's user avatar
  • 2,184
8 votes
2 answers
295 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 ...
hmode's user avatar
  • 482
1 vote
0 answers
38 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 ...
steven's user avatar
  • 11
8 votes
2 answers
242 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: ...
user43283's user avatar
  • 245
7 votes
2 answers
271 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 ...
Hector's user avatar
  • 6,458
9 votes
0 answers
126 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: <...
Lukas Lang's user avatar
  • 34.4k
5 votes
1 answer
129 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 ...
Lukas Lang's user avatar
  • 34.4k
8 votes
1 answer
118 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. ...
Stalpotaten's user avatar
2 votes
0 answers
210 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 ...
user42582's user avatar
  • 4,225
0 votes
0 answers
64 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, ...
MB Reynolds's user avatar
3 votes
3 answers
663 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 ...
Stan's user avatar
  • 951
1 vote
1 answer
98 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 ...
yode's user avatar
  • 27.2k
1 vote
0 answers
77 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 ...
Paul's user avatar
  • 11
2 votes
1 answer
386 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 (...
Peeter Joot's user avatar
  • 6,488
1 vote
0 answers
74 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 ...
Dave's user avatar
  • 43
0 votes
1 answer
77 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 ...
kozner's user avatar
  • 283
4 votes
1 answer
577 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. ...
kozner's user avatar
  • 283
1 vote
1 answer
197 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 ...
user42582's user avatar
  • 4,225
14 votes
1 answer
628 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, ...
user42582's user avatar
  • 4,225
5 votes
2 answers
121 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 ...
mrupp's user avatar
  • 777
1 vote
0 answers
1k 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 ...
Buddhapus's user avatar
  • 581
4 votes
1 answer
151 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: ...
ecoxlinux's user avatar
  • 979
3 votes
1 answer
86 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 ...
Lorenzo Pistone's user avatar
11 votes
4 answers
378 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 ...
Edmund's user avatar
  • 43.2k
10 votes
1 answer
291 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. ...
xyz's user avatar
  • 655
3 votes
1 answer
128 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}$...
mlainz's user avatar
  • 358
5 votes
2 answers
293 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: <...
xzczd's user avatar
  • 68.4k
12 votes
1 answer
189 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 囧,...
xzczd's user avatar
  • 68.4k
2 votes
1 answer
157 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...
rfrasier's user avatar
  • 602
4 votes
1 answer
246 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, ...
asoldat's user avatar
  • 85
13 votes
1 answer
179 views

AddTo regression in version 10

Bug (of Interval) introduced in 10, persisting through 12.2. As we know we can assign special addition rules to symbols by using ...
jkuczm's user avatar
  • 15.1k
2 votes
1 answer
117 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 ...
Patrick Stevens's user avatar
6 votes
1 answer
253 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. ...
Alexey Bobrick's user avatar