Aussie AI

Algebraic Identities

  • Book Excerpt from "Generative AI in C++"
  • by David Spuler, Ph.D.

Algebraic Identities

The calculations in some complicated expressions can be reduced by transforming the expression into another equivalent form. The aim when using algebraic identities is to group the operations differently, to reduce the total number of arithmetic operations. Care must be taken to ensure that the new expression has equivalent meaning. For example, the short-circuiting of the logical operators can cause differences. Some useful algebraic identities are:

    2 * x == x + x == x << 1
    a * x + a * y == a * (x + y)
    -x + -y == -(x + y)

There are also Boolean algebraic identities that can be used to perform fewer logical operations:

    (a && b) || (a && c) == a && (b || c)
    (a || b) && (a || c) == a || (b && c)
    !a && !b == !(a || b)
    !a || !b == !(a && b)

 

Next:

Up: Table of Contents

Buy: Generative AI in C++: Coding Transformers and LLMs

Generative AI in C++ The new AI programming book by Aussie AI co-founders:
  • AI coding in C++
  • Transformer engine speedups
  • LLM models
  • Phone and desktop AI
  • Code examples
  • Research citations

Get your copy from Amazon: Generative AI in C++