Questions tagged [programming]

Questions on writing non-trivial programs in Mathematica. Do not use this tag for questions on plotting/graphics or for questions on doing mathematics with Mathematica, where the focus is more on the math than the program.

Questions in this tag are expected to require the implementation of new, general functionality (i.e. new algorithms, constructs, abstractions, data types and data structures, etc.). Questions requiring/asking for good examples of program design, novel use of language constructs usually combined with of a highly abstract level of programming or the philosophical/theoretical aspect of programming in Mathematica belong here (OO-style, linked lists, metaprogramming, etc.). Also, if your question involves an extensive amount of code there is a good chance it belongs to this tag.

Example questions:

Questions about functional programming should use . Questions on linear/nonlinear/mathematical programming (i.e., constrained optimization) should use the tag instead.

Be aware that often it is hard to predict in advance whether or not this tag is appropriate for a given question, because it often only becomes clear once some good / relevant answers to it are posted. A proper thing to do is to review the question and especially answers after the question has been answered satisfactorily, and check if at least some of the good / representative answers contain any of the following:

  • Large (more than, say, 20 lines, and often several functions) amount of Mathematica code, which serves its purpose, in the sense that it can not be easily reduced to fewer lines without missing some of the defining properties of the solution (e.g. efficiency or generality)
  • Implementation of reasonably generic new functionality, which can be used in (many) more situations than the current problem.
  • Implementation of interesting algorithms and / or data structures
  • Good example of program design, where by splitting a problem into right sub-problems and using appropriate tools to "glue" it together, an extensible and modular design is achieved.
  • Interesting new abstractions or instructive use of some known abstractions (e.g. linked lists, OO-style, strong types, etc, etc)
  • Interesting and possibly novel uses of language constructs. In particular, using certain combinations of them to achieve things which are not easy to achieve by other means.

If they do, chances are that this tag is relevant and appropriate.

1585 questions
73
votes
10 answers

Having used Mathematica as a "gateway" language, where to from here?

I have been using Mathematica for about a year. It is the first language that I have attempted to learn. I'm still very much a newbie, but there are moments I feel more like I am waving than drowning. As with many addictions, at first it left an…
geordie
  • 3,693
  • 1
  • 26
  • 33
42
votes
4 answers

Can Mathematica be regarded as a software prototyping environment?

I am an undergraduate student, starting to use Mathematica to model simple physical chemistry problems, as a prelude to a summer internship in a computational/theoretical chemistry group. The solution to a problem I was given (and walked through)…
CHM
  • 3,395
  • 26
  • 46
40
votes
1 answer

What can I use as the second argument to Return in my own functions?

Having found out about the second argument to Return I played a bit with it, and the following tests all resulted in…
celtschk
  • 19,133
  • 1
  • 51
  • 106
39
votes
4 answers

Downloading files without using Import

A quick question, but which I don't believe has been asked here or at SO. Does Mathematica have a simple way to just download a file from the web? i.e. if I have a list of PDF links (~ 2,000), can I use Mathematica to quickly take them and save them…
canadian_scholar
  • 3,754
  • 1
  • 27
  • 45
28
votes
3 answers

Mathematica as a normal programming language

I'm interested in Mathematica's core language for both practical development and as an object of computer science study. Actually, the former is more of a means to the latter. I would like to create complete applications, but mainly to get…
jonvuri
  • 383
  • 3
  • 6
25
votes
4 answers

Continuous evaluation of complex calculations

When having a first look at some system, it's often very useful to just play with the parameters and see how it develops. Therefore, I would like to let a certain evaluation run "until I cancel it". Take a nonlinear differential equation for…
David
  • 14,911
  • 6
  • 51
  • 81
24
votes
6 answers

Mathematica quine

A quine is a computer program which takes no input and produces a copy of its own source code as its only output. There are many trivial quines in Mathematica: In[1]:= "Hello world" Out[1]= "Hello world" In[2]:= 3.14 Out[2]= 3.14 In[3]:=…
a06e
  • 11,327
  • 4
  • 48
  • 108
23
votes
3 answers

Suitability of Mathematica as platform for engineering calculations and programs

I am considering using Mathematica with Wolfram Workbench as a standard platform for calculations and programs in a large engineering department. I am looking for a solution that would provide better validation, documentation and revision control…
David Creech
  • 1,128
  • 10
  • 15
15
votes
2 answers

Is Mathematica a Turing-complete language?

Is Mathematica a Turing-complete language? If so, how can that be proved? If not, why?
Timothy
  • 303
  • 2
  • 8
14
votes
2 answers

Mathematica Application in Real Life

As an 'user'-level in Mathematica, I mainly use built-in Mathematica function and benefit Mathematica as a mathematical tool-box for my specific scientific problem. My level is not yet programmer-level. The magic of Mathematica is that there are…
Nam Nguyen
  • 1,761
  • 13
  • 24
13
votes
1 answer

Solutions for searching over Mathematica notebooks?

I have hundreds of Mathematica notebooks accumulated over the years, and I'd like to search over them. I've been using various versions of text search (grep, SilverSearcher, Spotlight), but there are limitations. For instance, just now I needed to…
Yaroslav Bulatov
  • 7,793
  • 1
  • 19
  • 44
12
votes
3 answers

Emulating Sequence with my own function

I just considered if/how one could implement Sequence in Mathematica if it were not predefined. It turned out that the following simple definition has in all my tests exactly the right behaviour: myseq /: f_[x___, myseq[y___], z___] := f[x, y,…
celtschk
  • 19,133
  • 1
  • 51
  • 106
12
votes
1 answer

Aborting from inside a Dialog

Suppose I got in a Dialog and wanted to not Return but Abort the computation. How could I do that? Using Return[] the computation continues, and sometimes that implies getting inside countless other Dialogs of which it is not easy to go out without…
Rojo
  • 42,601
  • 7
  • 96
  • 188
12
votes
2 answers

Functions with changeable global variables

I'm not sure is the topic title correct, but I mean such a case. I have several functions and "changeable" global variables, e.g.: f1[x_]:=Module[{q}, q=expr1[x, V0]; V0=expr2[V0]; q]; This means that function f1 depends on x explicitly and on…
Alx
  • 3,632
  • 11
  • 15
9
votes
6 answers

Best way to find permutation with specific total

Can anyone suggest a good way to find permutations of 12 digits, 0 to 4, totalling 24. I.e. two such permutations:- {2, 1, 4, 1, 2, 2, 2, 2, 2, 2, 1, 3} // Total 24 {4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0} // Total 24 I am trying this, but it…
Chris Degnen
  • 30,927
  • 2
  • 54
  • 108
1
2 3
13 14