Questions tagged [downvalues]

Questions about DownValues which specify function definitions for symbols.

Filter by
Sorted by
Tagged with
8
votes
0answers
70 views

Design Patterns for System Functions?

Using PrintDefinitions give one a great view into many system functions. Often the design of these symbols incorporate multiple patterns that I see again and again. ...
0
votes
0answers
29 views

Saving DownValues for a function computed in parallel

Is it possible to save DownValues of a function computed using a parallelization routine? I have a rather costly function f I wish to evaluate at a grid and save ...
14
votes
3answers
208 views

What is the difference between Set and SetDelayed when evaluating the RHS leaves it unchanged?

I thought there was no difference between f[a_] = 2 + a; and f[a_] := 2 + a; because the resulting ...
2
votes
2answers
62 views

Correct way to see domain of function using DownValues?

Here's a simple function g defined for the natural numbers 1 through 10: Table[g[i] = i^2, {i, 1, 10}] I now want to find the ...
0
votes
1answer
40 views

Cannot set DownValues to ValueList while loading package

I have installed a package named HEP from Wolfram Library Archive which contains several .m files by Files -> Install (...
6
votes
2answers
205 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 ...
1
vote
0answers
37 views

Pure OwnValue Functions vs Patterned DownValue Functions [duplicate]

Is it better to use pure Function assigned to symbols as their OwnValues vs function defined by patterns as symbol's ...
2
votes
2answers
44 views

Defining a property of a variable that includes another function (sign)

I have a function that has a lot of sign functions that depend on a variable $\sigma$ and I know the property that $\sigma=1$ with probability $m$ and $-1$ with probability $1-m$. For example we can ...
2
votes
0answers
46 views

How to add sugar for NetEncoder?

I'm tired of the extra level of list in NetEncoder and would like to get rid of it. The obvious thing fails: ...
10
votes
2answers
178 views

Unexpected behavior when directly assigning to DownValues

I'm encountering some unexpected behavior when assigning to DownValues. When I assign two definitions for test[1] as below, ...
4
votes
1answer
140 views

Sorting a list of rules

When we give several definitions for a function f, the DownValues of f are automatically ...
4
votes
2answers
218 views

Wrongly assigning a value to an expression

Sometimes I misstype an equality and I write an assignment instead. For example, if I write f'[x] = 2 instead of an equation, ...
1
vote
1answer
70 views

Changing DownValues of a function when calling

General problem I am looking for a possibility to store information in parallel for a function and change the information when a function is called. Idea It seems possible to solve this problem by ...
8
votes
1answer
199 views

Why can I define N[MySymbol] := …?

As far as I understand, I cannot define the values of built-in functions: Sin[Cat] := Dog will result in error. This is because all built-in symbols have attribute <...
5
votes
1answer
545 views

Optimize DownValues: extract “non-patterns” from Alternatives

Introduction As we know, when we assign DownValues to a symbol, Mathematica creates a dispatch table for "non-pattern" definitions (i.e. expressions that, when ...
4
votes
2answers
98 views

Assigning values to association in DownValues

Compare the following code: Clear[t]; t = <||>; t[2] = 1/2; t[2] with ...
2
votes
2answers
104 views

Memoization and finding already calculated DownValue

The problem of plotting an expensive function discussed in this question caught my attention. As an exercies I tried to solve it using memoization as follows ...
8
votes
0answers
143 views

KeyValuePattern specificity in DownValues

Bug introduced in 10.4.0 and persisting through 11.3.0 CASE:3824590 [...] Developers are discussing this behavior. [...] I will let you know when I have definite information on this. [...] ...
0
votes
1answer
60 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
318 views

How to “clear” the downvalues of a subscripted variable?

I have a function that sets certain subscripts of the symbol aa as in the following example: ...
0
votes
3answers
383 views

How to initialize downvalues from a list?

The For expression below initializes downvalues of a variable a from the values in a list ...
4
votes
1answer
64 views

Using ValueQ to test whether “hash” key exists fails when key is given as variable

Please ignore ^^^ possible duplicate (raised by me). The solution doesn't cover my case. I'm trying to implement a simple hash table according to this top answer at "Is there HashTable structure in ...
1
vote
1answer
85 views

How to extract all necessarily code for a function?

Many times when someone pastes a piece of code into SE there are missing values and symbols that the user left out. To prevent this I'm looking for a function that uproots other functions (extract ...
10
votes
6answers
391 views

Combinations of multiple matching patterns

I wonder if there is any nice way to combine DownValues (or any other suitable rule-/pattern-/function -based Mathematica construct) when multiple patterns match an expression. Let me explain what I ...
4
votes
2answers
1k views

How to take derivative of a interpolated function inside the module

When handling derivatives of a interpolated function, I often use the following function makeDeriv[f_InterpolatingFunction] = D[ f[x], x] Then, I can define ...
14
votes
2answers
388 views

Named patterns in Except

Bug introduced in 8 or earlier and fixed in 10.4.0 Bug isn't present in version 5.2 I don't think I quite understand how Except works. I want to define $f(a,b) = ...
28
votes
5answers
2k views

What are the requirements for a well behaved indexed variable? Subscript, ToExpression, Downvalue?

On writing this answer I needed to call a function, (NonlinearModelFit) with an unknown number of parameters. We have learned that we should not use ...
12
votes
1answer
128 views

Which symbol gets DownValues or OwnValues when using SetDelayed?

I have been looking at various usages of Pattern objects. Here's a number of ways to define the same thing: mod[x_] := {x} ...
0
votes
0answers
36 views

Why is DownValues releasing RuleDelayed's hold for Graphics? [duplicate]

I am trying to understand DownValues in regards to the evaluation of its output. Consider this: ...
5
votes
1answer
206 views

Multiple down-values with exactly the same lefthand side

I was working on an answer to this question, when I was sidetracked by what I bring up here. I wanted a function, which when given a string representing a binary number, would convert the string to a ...
6
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
4answers
444 views

How to do memoization together with evaluation of a complicated function

UPDATE 2: much shorter version Given a list of paired indices {i, j}={{1,2}, {3,4}, …}, I need to first evaluate a rather complicated function test[i,j,x] (because ...
2
votes
1answer
163 views

How do I constrain movement for lists of Locators using 2nd argument of Dynamic?

I need to display edge labels of a graph in a way that allows the edge labels to be moved. Locator seems the simplest and most obvious function to use. My ...
2
votes
0answers
88 views

Function that assigns properties [duplicate]

I want to create a function that creates and assigns properties to a symbol. In theory this would behave similarly to the NonzeroValues property of ...
3
votes
1answer
348 views

String pattern matching in function definition [duplicate]

I have a function f and its downvalues. I want to code an extra downvalue for arguments of the form "part1:part2" I don't understand why f[a__~~":"~~b__] := {a,b} ...
7
votes
1answer
199 views

Graphics Function Definition Style (Using SubValues vs. DownValues)

I am going through some of the items in "Modern Differential Geometry of Curves and Surfaces with Mathematica, Third Edition". An example of the style used by these authors is: ...
6
votes
1answer
318 views

How can I define a ⊕ operator?

What is wrong with the following code? CirclePlus := SparseArray[Band[{1, 1}] -> {##}] & a_ ⊕ b_ := CirclePlus[a, b] SetDelayed::write: Tag Function in (...
2
votes
2answers
343 views

How to unprotect GeneratingFunction

I'm trying to add custom downvalues for GeneratingFunction, and to do so I thought I just had to Unprotect it. However, that ...
4
votes
0answers
176 views

DownValues for Built-in Functions

N.B. I have bitten the bullet, and I am going through Leonid Shifrin's "Mathematica Programming: An Advanced Introduction." (Which needs no introduction in this forum) One question I have: could one ...
4
votes
2answers
558 views

Overloading conjugate operator for a particular function

I trying to modify the behaviour of the built-in Conjugate[] operator on a particular function I have defined, to take into account that some of its variables are ...
1
vote
2answers
206 views

Given a list of date and value pairs, efficiently sum the values by date [duplicate]

I have a list of date & value pairs. There can be multiple entries for each day. Sample data can be generated with the following: ...
9
votes
1answer
268 views

Unset variable by its name given as a string

Unlike the function Clear, the function Unset does not work for string patterns. Given the name of a variable as a string, how can you unset the corresponding variable? Example: Given: ...
5
votes
2answers
461 views

DownValue “associative array” to list? [duplicate]

I have a "sparse array" like this arr[1.5]=0.4, arr[3.5]=0.7, arr[7]=0.3 which is not really a sparse array since the keys are not all integers. This is like a ...
4
votes
1answer
188 views

Downvalues vs. Scoping for Functions

Regarding my recent question on using a default value for a function argument when a pattern was not met yielded some interesting answers, but the general consensus was "Yes this can be done, but ...
5
votes
2answers
178 views

Get DownValues that do not involve patterns?

Say I have a function with a few definitions that also implements memoization: f[x_] := f[x] = x^2 f[x_, y_] := f[x, y] = x^2 + y^2 I then apply the function to ...
9
votes
2answers
1k views

How to get the list of defined values for an indexed variable?

I would like a table with rational indexes - thus it would be practical to use a dictionary, which, in Mathematica are implemented with the indexed variables. I would like to be able to do: ...
50
votes
3answers
2k views

How is pattern specificity decided?

Mathematica has a notion of pattern specificity, which is a partial ordering on patterns. The rules (e.g. DownValues, SubValues,...
2
votes
0answers
155 views

How safe are ReadProtected and Locked symbols? [duplicate]

Possible Duplicate: How to distribute proprietary Mathematica code I suspect that there is a way to expose the down values of such symbols with an attack along these lines: ...
14
votes
1answer
498 views

Selectively clear DownValues

How can I clear a subset of a symbol's DownValues ? For example, suppose I have created some DownValues for $f$ like this: ...
20
votes
5answers
6k views

The difference between 0. and 0

I have a function for which 0 is a special case: f[A___, 0, B___] := 0 But since I am doing numerics, sometimes in the course ...