# How do I interrupt (abort) a computation in Mathematica?

Sometimes I (inadvertently or naively) write a code that would take Mathematica a long time to compute on my laptop or any computer for that matter. For example: Table[Length[Select[Permutations[n], #[[1]] == 1 &]], {n, 1, 10}]. This returns {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880} in about ten seconds. But if I want more terms (even one more) it takes Mathematica much too long to compute.

I usually have to close the program and restart a new session or sometimes I have to unplug my laptop and remove the batteries and restart the computer. Is there an easier way to stop the computation? Is it harmful to my laptop when Mathematica runs a "slow code" for a long period of time (say 10 -15 hours)?

-

## migrated from math.stackexchange.comJun 8 '14 at 22:37

This question came from our site for people studying math at any level and professionals in related fields.

Use Interrupt Evaluation or Abort Evaluation from the Evaluation menu in the main tool bar. you can also Quit Kernel from the same menu. – Algohi Jun 8 '14 at 22:52
It should never be necessary to force-halt a computer by removing the batteries. If all else fails, and the computer is completely unresponsive to any kind of input, you can hold down the power button for a few seconds. That should power-down the computer a safer way than removing the batteries (though as a forced poweroff, it may still cause filesystem corruption). If Mathematica causes your computer to become completely unresponsive (unusual situation), the most likely cause is that the computer ran out of memory and keeps swapping. – Szabolcs Jun 8 '14 at 23:39
Are you sure Permutations[n] (n=1,2,3……) is right codes？ – Apple Jun 10 '14 at 2:00
I know this isn't the point of the question, but... Table[(n - 1)!, {n, 1, 10}] :) – Rahul Jun 10 '14 at 2:08
@Rahul Don't forget Array: Array[#! &, 10, 0] – Mr.Wizard Jun 10 '14 at 2:09

From the Evaluation menu, select Abort Evaluation (or use the shortcut keys for your environment), or Interrupt Evaluation if you want to inspect and continue (using Return[]).

Depending on your system environment, certain CPU-heavy operations can make the above unresponsive. In those cases, Quit Kernel from the same menu can be of use.

In some corner cases, even Quit Kernel may become unresponsive. In those cases, killing the Kernel process via Task Manger (Windows) or the equivalent facilities for your O/S can be used rather than resorting to shutting down/powering down the machine.

In general, there is no "harm" to your hardware running a long conputation: of course, heat/etc. is generated, and at some level there is "wear" on the CPU (e.g. electromigration), but really these are inconsequential for hardware operated normally (as opposed to overclocked/over-voltaged/etc.) - the useful life of the CPU will be far exceeded before these effects matter. So don't fret it.

-
On OS X, there are two additional possibilities: selecting Force Quit... from the Apple menu; launching the Activity Monitor utility and killing the process that is hung. – m_goldberg Jun 9 '14 at 1:17
Even worse case: The task manager becomes unresponsive. Mma can use lots of memory... – LegionMammal978 Nov 6 '15 at 11:44

you can interrupt the evaluation of an expression in Mathematica by pressing

Alt + .

together.

have a nice day

-
I note that on many computers only one of the Alt keys works with this combo. On my current laptop it is left Alt, but if memory serves, I've had computers that used the right Alt key. – Sjoerd C. de Vries Jun 8 '14 at 23:11
Well, I meant the left Alt key. :) – ronald Jun 8 '14 at 23:24
@SjoerdC.deVries: Might be on a system where right alt is alt-gr by default... – ciao Jun 8 '14 at 23:26
It's alt+, on Linux.. :) – Öskå Jun 10 '14 at 0:35

On Linux with standard settings it is:

Alt + .
for aborting the Evaluation

And Alt + ,
for interrupting the evaluation, which shows a pop-up window that gives you several options. Aborting the evaluation is one of them.

-