# Questions tagged [design-patterns]

The tag has no usage guidance.

32 questions
Filter by
Sorted by
Tagged with
129 views

### Obtaining Pairs of Consecutive Elements with Conditional Adjustment

I've encountered a particular problem and was wondering if anyone has any insights on how to approach it more efficiently or elegantly. To be accurate, given the list: ...
66 views

### Pattern Match "Empty" Term in NonCommutativeMultiply

Not sure if this has been asked before, please point me to the post if it has. Is there a way to treat terms like (b+c), a**(b+c)...
195 views

### How to define the pattern for the sum of some specified terms?

I want to define a function to check whether the expression is the sum of these terms a*x+b*y^n+c*Exp[k*z] (* n can be 1*) These ...
224 views

### Equivalent of Nothing for patterns

Let's say we want a pattern, that matches, when expression contains some terms but it can optionaly contain some other terms. For example: ...
15k views

### What does the construct f[x_] := f[x] = ... mean?

This question mentions "x := x = trickery". What does defining a function as f[x_] := f[x] = ... do and what is it good for?
1 vote
63 views

### How can I collect the sum of any number of gradients without using ReplaceRepeated[]?

Recently, I have run into the problem where I need to collect the the sum of any number of gradients. I have defined a function grad[] to represent the gradient, ...
956 views

### How can a verbal reasoning question be solved with Mathematica?

Could a "verbal reasoning" problem like the following be solved with Mathematica? What comes next in the series. KD XP NG VN QJ TL TM Correct answer is <...
1 vote
159 views

### How to construct a pattern that match the multiple partial differential of any multi-variable functions?

For example,I want to match a multiple partial derivative of a function $f^{(1,0,1)}[x,y,z]$ which is the same as$\frac{\partial^2{f}}{\partial{x}\partial{z}}$.The only information given is the list ...
1 vote
98 views

### Unusual performance of the Cases function [closed]

Recently I was surprised by unusual performance of Cases function. The code ...
807 views

### Art on Mathematica: How can I export 4K resolution png images?

This question is solely based upon $[1]$ and therefore, the reading of $[1]$ could be interesting. How can I export the image created, by the code in the following, with high definition, beautiful, 4K ...
899 views

### Art on mathematica with filled circles and straight paths: how can I reproduce minimalist suns?

I would like to know: how can I construct minimalist images like this one?
18k views

### Struct equivalent in Mathematica?

I really miss having something like a struct in Mathematica. I know of (and regularly use) a couple of programming techniques which feel like a ...
379 views

### Implement settable properties

I am looking for advice on implementing the following. (It is possible that the answer is that it is simply not a good idea to do this.) I would like to have an object similar to ...
9k views

### How can I implement object oriented programming in Mathematica?

Roman Maeder's object oriented programming package is nice, but I'm hoping someone can suggest a sleek and novel implementation that is easy to use.
486 views

### Fourier Transform of a symbolic expression

Hello I would like to do the Fourier Transform of H1'[t - L2[t]/c - L2primo[t]/c] I know that its transform has to be: ...
1k views

### How and why to use monadic programming in Mathematica?

This is a methodological question with two parts: How to use monadic programming in Mathematica? Why use monadic programming in Mathematica? In my opinion the questions are inter-related -- we ...
113 views

### Is there a way to make $g$ changeable independently of $f$ in this code?

My problem is that in the below code, every time I want to change $g$ I also have to change $f$. Let's say we have three functions: $f$, $h$, and $g$ ($h$ is not really relevant for the question, but ...
9k views

### Can one identify the design patterns of Mathematica?

... or are they unnecessary in such a high-level language? I've been thinking about programming style, coding standards and the like quite a bit lately, the result of my current work on a mixed .Net/...
1k views

### Permanently extending the behaviour of functions (like decorators)

Suppose I have a function, e.g. f[x_] := x^2 It works like this: f[5] (* 25 *) I would like to permanently modify it so ...
185 views

### Designing a Manipulate Block

I am trying to create a Manipulate block which contains tabels, graphs and explanations. In the first row I want to add some tables and explanations, but sometimes the tabels are cut. For doing this I ...
772 views

### Draw Graph with upper and lower limit

I am attempting to draw a graph with a slope of 200,000 that becomes "saturated" at $y= \pm 10$. Essentially, the graph is of the form $y=200000x$. However, I have been unsuccessful in getting it to ...
101 views

### Does Mathematica have a method for achieving the same goals that Aspect Oriented Programming does?

I imagine that this question has been asked before, yet I'm not able to find an answer using the form of the question I believe might be asked. Is there a mechanism for duplicating the ...
273 views

### Longest and Shortest won't work in ReplaceList?

I'm trying to make a pattern that's easy to preceive by human but hard to write out by Mathematica when I came across this problem. (Check the original problem here) Let's check this simple case: I'...
918 views

### What's the analogue of UML in Mathematica land?

What's the analogue of Unified Modeling Language (UML) in Mathematica land? Mathematica has elements of object-orientation, but most Mathematica programs or applications aren't of object-oriented ...
716 views

### Opposite of Alternatives

I was looking at this question (here) and I tried to find any thing gives the opposite of Alternatives. In other words, some pattern matching function that gives ...
43 views

### Design problem with an an InterpolatingFunction-like object: bad performance over a remote kernel

I these last times, I found myself using often the following approach. Given some data, I make some preliminary, common, computations and I store these results in an ...
901 views

### How to add texture to a parametric plot?

I need to put some simple textures to some parametric plots. My textures are not complicated, They are like the first example in here. Is there any simple way of doing this? For example, How can I ...
67 views

### How to correctly use PatternTest (?) [duplicate]

This works fine: {3, -5, 2, 7, -6, 3} /. x_ /; x < 0 :> 0 (*{3, 0, 2, 7, 0, 3}*) and this works fine: ...
558 views

### Why does MapIndexed return the index in a list?

MapIndex returns the index in a list instead of as shown in my revised example. I can work with it (or work around it), but what's the design concept? It seems ...
2k views

### How can one define a custom data object?

In Mathematica there are different objects like InterpolatingFunction or SparseArray? How can I define a custom data object with ...