Questions about DownValues which specify function definitions for symbols.

learn more… | top users | synonyms

4
votes
1answer
124 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 ...
2
votes
1answer
82 views

Can a Symbol own OwnValues that don't evaluate when it's the head of an expression?

I believe this a question that most of us have encountered when we were beginners but forgot when we got more familiar with Mathematica. We know the notation $y=y(x)$ for functions, where $y$ here ...
4
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
331 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
92 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
79 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
138 views

String pattern matching in function definition

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 ...
4
votes
1answer
113 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
157 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
150 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 ...
3
votes
0answers
131 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 ...
3
votes
2answers
250 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
1answer
124 views

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

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
154 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
317 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 ...
3
votes
1answer
147 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 ...
3
votes
2answers
137 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 ...
8
votes
2answers
403 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: ...
35
votes
2answers
661 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, ...
1
vote
0answers
86 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: ...
9
votes
1answer
315 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: ...
17
votes
5answers
2k 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 ...
6
votes
3answers
189 views

Organizing similar datasets using DownValues instead of Contexts

In his answer to this question, Leonid helped me find a way to programmatically generate contexts for holding sets of symbols with the same names. Perhaps a simpler way is to use ...