Skip to Content
Q# Pocket Guide
book

Q# Pocket Guide

by Mariia Mykhailova
June 2022
Intermediate to advanced
205 pages
3h 53m
English
O'Reilly Media, Inc.
Content preview from Q# Pocket Guide

Chapter 5. Operations and Functions

This chapter dives deeper into defining and using operations and functions—the main units of Q# code.

Operations are the most general type of Q# subroutine—sequences of statements that perform a certain task, packaged as a single logical unit. Functions are a special type of subroutine that perform only deterministic classical computation. Together, operations and functions are called callables.

Since Q# is a quantum programming language, operations are much more common in Q# code—you cannot write a quantum program without using an operation. However, functions are useful in their own right, as I’ll show you in this chapter.

The chapter starts with the basic ways to define functions and operations and use them, including call expressions and statements, and a description of signatures of callables.

After that I’ll show how quantum gates and measurements are represented as operations in Q#, thus finishing the discussion we started in Chapter 2 of how the language expresses central quantum computing concepts. Next, I’ll discuss defining and using adjoint and controlled variants of operations—powerful tools for expressing quantum algorithms more concisely.

I’ll wrap up the chapter with a discussion of the functional elements of Q#, such as passing callables as arguments to other callables and using partial application to construct new callables, and the type-parameterized callables.

Defining and Using Operations and Functions: The Basics

A basic ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Qiskit Pocket Guide

Qiskit Pocket Guide

James L. Weaver, Frank J. Harkins
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer
How to Overcome a Power Deficit

How to Overcome a Power Deficit

Cyril Bouquet, Jean-Louis Barsoux

Publisher Resources

ISBN: 9781098108854Errata Page