<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/vDSP/subtract(multiplication:multiplication:)-22a4b",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate4vDSPO8subtract14multiplicationAESaySdGq0_1a_q1_1bt_x1c_q_1dttAA0A6BufferRzAaKR_AaKR0_AaKR1_Sd7ElementRtzSdALRt_SdALRt0_SdALRt1_r2_lFZ"
  },
  "title" : "subtract(multiplication:multiplication:)"
}
-->

# subtract(multiplication:multiplication:)

Returns the double-precision element-wise difference of the products of two pairs of vectors.

```
static func subtract<R, S, T, U>(multiplication multiplicationAB: (a: T, b: U), multiplication multiplicationCD: (c: R, d: S)) -> [Double] where R : AccelerateBuffer, S : AccelerateBuffer, T : AccelerateBuffer, U : AccelerateBuffer, R.Element == Double, S.Element == Double, T.Element == Double, U.Element == Double
```

## Parameters

`multiplicationAB`

A tuple that contains the vectors `A` and `B` in `E = (A * B) - (C * D)`.

`multiplicationCD`

A tuple that contains the vectors `C` and `D` in `E = (A * B) - (C * D)`.

## Return Value

The output vector `E` in `E = (A * B) - (C * D)`.

## Discussion

This function calculates the differences of the first `N` elements of the product of vectors `A` and `B` and the product of vectors `C` and `D`.

```swift
 for (n = 0; n < N; ++n)
    E[n] = A[n]*B[n] - C[n]*D[n]; 
```

![A diagram showing the operation of this function. There are four rows. The top row represents the input vectors, A, B, C, and D, with three boxes of each. The second row represents the operations that multiply vectors A and B, and multiply vectors C and D, with three boxes of each. The third row represents the subtraction operation as three boxes.  The bottom row represents the output vector E as three boxes. The diagram has connecting lines from the input vectors to the operations, and from the operations to the output vectors. ](images/com.apple.accelerate/media-4337031@2x.png)

The following code shows an example of using this function:

```swift
    let a: [Double] = [ 1,  2,  3,  4,  5]
    let b: [Double] = [10, 20, 30, 40, 50]
    let c: [Double] = [ 5,  4,  3,  2,  1]
    let d: [Double] = [50, 40, 30, 20, 10]
    
    let e = vDSP.subtract(multiplication: (a, b),
                          multiplication: (c, d))
    
    // Prints "[-240.0, -120.0, 0.0, 120.0, 240.0]".
    print(e)
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)