cirq.inverse
Returns the inverse val**-1
of the given value, if defined.
cirq.inverse(
val: Any, default: Any = RaiseTypeErrorIfNotProvided
) -> Any
Used in the notebooks
An object can define an inverse by defining a pow(self, exponent) method
that returns something besides NotImplemented when given the exponent -1.
The inverse of iterables is by default defined to be the iterable's items,
each inverted, in reverse order.
Args |
val
|
The value (or iterable of invertible values) to invert.
|
default
|
Determines the fallback behavior when val doesn't have
an inverse defined. If default is not set, a TypeError is raised.
If default is set to a value, that value is returned.
|
Returns |
If val has a pow method that returns something besides
NotImplemented when given an exponent of -1, that result is returned.
Otherwise, if val is iterable, the result is a tuple with the same
items as val but in reverse order and with each item inverted.
Otherwise, if a default argument was specified, it is returned.
|
Raises |
TypeError
|
val doesn't have a pow method, or that method returned
NotImplemented when given -1. Furthermore val isn't an
iterable containing invertible items. Also, no default argument
was specified.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-06-27 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-27 UTC."],[],[]]