Prefix to Infix Converter with Built-in Dynamic Tutorial

Prefix to Infix Converter Sign

This calculator will convert a prefix expression (Polish Notation) to an infix expression and show the step-by-step process used to arrive at the result using stack.

If you're not sure what is meant by the terms infix, prefix, or stack, please visit the Learn section of the Infix to Prefix Converter page.

If you would like to convert a postfix expression back to an infix expression, please visit the Postfix to Infix Converter. Or, if you would like to convert a prefix expression (* 4 3) to postfix (4 3 *), please visit the Prefix to Postfix Converter.

Read more ...

Also on this page:

Prefix to Infix Converter

Convert prefix to infix and see the step-by-step process for completing the conversion.

Special Instructions

Learn More

Selected Data Record:

A Data Record is a set of calculator entries that are stored in your web browser's Local Storage. If a Data Record is currently selected in the "Data" tab, this line will list the name you gave to that data record. If no data record is selected, or you have no entries stored for this calculator, the line will display "None".

DataData recordData recordSelected data record: None
Example notations:

Example prefix expressions:

To see an example of how the Prefix to Infix Converter works, and what types of expressions the calculator is set up to handle, select a prefix expression from the drop-down menu. To clear the expression field to enter your own prefix expression, select "Example Problems" or click the "Reset" button.

Prefix expression:

Prefix expression:

Enter a prefix expression that fits within the following guidelines:

  • Include a single space between numbers or operators.
  • Numbers, single letters, and operators only (no variables or function names).
  • Contains only numbers, decimal points, letters, and these valid characters: ^ * / + - .
  • Numbers with a leading decimal point must be preceded by a zero (enter .5 as 0.5).
#
Result:

Infix:

This line will display the result of the prefix to infix conversion.

If you would like to save the current entries to the secure online database, tap or click on the Data tab, select "New Data Record", give the data record a name, then tap or click the Save button. To save changes to previously saved entries, simply tap the Save button. Please select and "Clear" any data records you no longer need.

Related Calculators

infix to prefix converterprefix to postfix converterprefix evaluator

Help and Tools

Learn

How to convert prefix notation into infix notation.

How to Convert Prefix Notation to Infix Notation Using Stack

Working from right to left, scan each character of the prefix expression, and take one of the following two actions.

If the character is an operand, push it to the stack.

If the character is an operator, pop the top value from the stack for its left operand and pop the next top value from the stack for its right operand. Finally, insert the operator between its operands, place the infix string within a set of parenthesis, and then push the infix string back to the stack.

Repeat the above scanning and subsequent actions until all prefix characters have been handled. If the prefix expression was valid, you should be left with a single element in the stack, which is the infix equivalent of the prefix expression.

Prefix to Infix Conversion Examples

The following are two examples showing how to apply the conversion process detailed in the previous section.

Example #1: * 5 - ^ 6 2 2

Start scanning characters, one at a time, from right to left.


* 5 - ^ 6 2 2

The first character scanned is "2", which is an operand, so push it to the stack.

2
  
StackPostfix String

* 5 - ^ 6 2 2

The next character scanned is "2", which is an operand, so push it to the stack.

2
2
  
StackPostfix String

* 5 - ^ 6 2 2

The next character scanned is "6", which is an operand, so push it to the stack.

6
2
2
  
StackPostfix String

* 5 - ^ 6 2 2

The next character scanned is "^", which is an operator, so pop its two operands from the stack. Pop 6 from the stack for the left operand and then pop 2 from the stack for the right operand. Next, insert the "^" between its two operands to form the infix string 6 ^ 2, and then place that string inside a set of parenthesis.

2
 (6 ^ 2) 
StackPostfix String

Next, push the infix string (6 ^ 2) to the stack.

(6 ^ 2)
2
  
StackPostfix String

* 5 - ^ 6 2 2

The next character scanned is "-", which is an operator, so pop its two operands from the stack. Pop (6 ^ 2) from the stack for the left operand and then pop 2 from the stack for the right operand. Next, insert the "-" between its two operands to form the infix string (6 ^ 2) - 2, and then place that string inside a set of parenthesis.

 
 ((6 ^ 2) - 2) 
StackPostfix String

Next, push the infix string ((6 ^ 2) - 2) to the stack.

((6 ^ 2) - 2)
  
StackPostfix String

* 5 - ^ 6 2 2

The next character scanned is "5", which is an operand, so push it to the stack.

5
((6 ^ 2) - 2)
  
StackPostfix String

* 5 - ^ 6 2 2

The next character scanned is "*", which is an operator, so pop its two operands from the stack. Pop 5 from the stack for the left operand and then pop ((6 ^ 2) - 2) from the stack for the right operand. Next, insert the "*" between its two operands to form the infix string 5 * ((6 ^ 2) - 2), and then place that string inside a set of parenthesis.

 
 (5 * ((6 ^ 2) - 2)) 
StackPostfix String

Next, push the infix string (5 * ((6 ^ 2) - 2)) to the stack.

(5 * ((6 ^ 2) - 2))
  
StackPostfix String

Since we are done scanning characters, the remaining element in the stack (* 5 - ^ 6 2 2) becomes the result of the prefix to infix conversion.

Prefix notation: * 5 - ^ 6 2 2
Infix equivalent: (5 * ((6 ^ 2) - 2))
Example #2: - * ^ 7 2 + 25 / 10 5 13

Start scanning characters, one at a time, from right to left.


- * ^ 7 2 + 25 / 10 5 13

The first character scanned is "13", which is an operand, so push it to the stack.

13
  
StackPostfix String

- * ^ 7 2 + 25 / 10 5 13

The next character scanned is "5", which is an operand, so push it to the stack.

5
13
  
StackPostfix String

- * ^ 7 2 + 25 / 10 5 13

The next character scanned is "10", which is an operand, so push it to the stack.

10
5
13
  
StackPostfix String

- * ^ 7 2 + 25 / 10 5 13

The next character scanned is "/", which is an operator, so pop its two operands from the stack. Pop 10 from the stack for the left operand and then pop 5 from the stack for the right operand. Next, insert the "/" between its two operands to form the infix string 10 / 5, and then place that string inside a set of parenthesis.

13
 (10 / 5) 
StackPostfix String

Next, push the infix string (10 / 5) to the stack.

(10 / 5)
13
  
StackPostfix String

- * ^ 7 2 + 25 / 10 5 13

The next character scanned is "25", which is an operand, so push it to the stack.

25
(10 / 5)
13
  
StackPostfix String

- * ^ 7 2 + 25 / 10 5 13

The next character scanned is "+", which is an operator, so pop its two operands from the stack. Pop 25 from the stack for the left operand and then pop (10 / 5) from the stack for the right operand. Next, insert the "+" between its two operands to form the infix string 25 + (10 / 5), and then place that string inside a set of parenthesis.

13
 (25 + (10 / 5)) 
StackPostfix String

Next, push the infix string (25 + (10 / 5)) to the stack.

(25 + (10 / 5))
13
  
StackPostfix String

- * ^ 7 2 + 25 / 10 5 13

The next character scanned is "2", which is an operand, so push it to the stack.

2
(25 + (10 / 5))
13
  
StackPostfix String

- * ^ 7 2 + 25 / 10 5 13

The next character scanned is "7", which is an operand, so push it to the stack.

7
2
(25 + (10 / 5))
13
  
StackPostfix String

- * ^ 7 2 + 25 / 10 5 13

The next character scanned is "^", which is an operator, so pop its two operands from the stack. Pop 7 from the stack for the left operand and then pop 2 from the stack for the right operand. Next, insert the "^" between its two operands to form the infix string 7 ^ 2, and then place that string inside a set of parenthesis.

(25 + (10 / 5))
13
 (7 ^ 2) 
StackPostfix String

Next, push the infix string (7 ^ 2) to the stack.

(7 ^ 2)
(25 + (10 / 5))
13
  
StackPostfix String

- * ^ 7 2 + 25 / 10 5 13

The next character scanned is "*", which is an operator, so pop its two operands from the stack. Pop (7 ^ 2) from the stack for the left operand and then pop (25 + (10 / 5)) from the stack for the right operand. Next, insert the "*" between its two operands to form the infix string (7 ^ 2) * (25 + (10 / 5)), and then place that string inside a set of parenthesis.

13
 ((7 ^ 2) * (25 + (10 / 5))) 
StackPostfix String

Next, push the infix string ((7 ^ 2) * (25 + (10 / 5))) to the stack.

((7 ^ 2) * (25 + (10 / 5)))
13
  
StackPostfix String

- * ^ 7 2 + 25 / 10 5 13

The next character scanned is "-", which is an operator, so pop its two operands from the stack. Pop ((7 ^ 2) * (25 + (10 / 5))) from the stack for the left operand and then pop 13 from the stack for the right operand. Next, insert the "-" between its two operands to form the infix string ((7 ^ 2) * (25 + (10 / 5))) - 13, and then place that string inside a set of parenthesis.

 
 (((7 ^ 2) * (25 + (10 / 5))) - 13) 
StackPostfix String

Next, push the infix string (((7 ^ 2) * (25 + (10 / 5))) - 13) to the stack.

(((7 ^ 2) * (25 + (10 / 5))) - 13)
  
StackPostfix String

Since we are done scanning characters, the remaining element in the stack (- * ^ 7 2 + 25 / 10 5 13) becomes the result of the prefix to infix conversion.

Prefix notation: - * ^ 7 2 + 25 / 10 5 13
Infix equivalent: (((7 ^ 2) * (25 + (10 / 5))) - 13)

Adjust Calculator Width:

Move the slider to left and right to adjust the calculator width. Note that the Help and Tools panel will be hidden when the calculator is too wide to fit both on the screen. Moving the slider to the left will bring the instructions and tools panel back into view.

Also note that some calculators will reformat to accommodate the screen size as you make the calculator wider or narrower. If the calculator is narrow, columns of entry rows will be converted to a vertical entry form, whereas a wider calculator will display columns of entry rows, and the entry fields will be smaller in size ... since they will not need to be "thumb friendly".

Show/Hide Popup Keypads:

Select Show or Hide to show or hide the popup keypad icons located next to numeric entry fields. These are generally only needed for mobile devices that don't have decimal points in their numeric keypads. So if you are on a desktop, you may find the calculator to be more user-friendly and less cluttered without them.

Stick/Unstick Tools:

Select Stick or Unstick to stick or unstick the help and tools panel. Selecting "Stick" will keep the panel in view while scrolling the calculator vertically. If you find that annoying, select "Unstick" to keep the panel in a stationary position.

If the tools panel becomes "Unstuck" on its own, try clicking "Unstick" and then "Stick" to re-stick the panel.