Differential Privacy of Cross-Attention with Provable Guarantee

## Abstract

Cross-attention has become a fundamental module nowadays in many important artificial intelligence applications, e.g.,
retrieval-augmented generation (RAG), system prompt, guided stable diffusion, and many more.
Ensuring cross-attention privacy is crucial and urgently needed because its key and value matrices may contain sensitive information about model providers and their users.
In this work, we design a novel differential privacy (DP) data structure to address the privacy security of cross-attention with a theoretical guarantee.
In detail, let n 𝑛 n italic_n be the input token length of system prompt/RAG data, d 𝑑 d italic_d be the feature dimension, 0 < α ≤ 1 0 𝛼 1 0<\alpha\leq 1 0 < italic_α ≤ 1 be the relative error parameter, R 𝑅 R italic_R be the maximum value of the query and key matrices, R w subscript 𝑅 𝑤 R_{w} italic_R start_POSTSUBSCRIPT italic_w end_POSTSUBSCRIPT be the maximum value of the value matrix, and r , s , ϵ s 𝑟 𝑠 subscript italic-ϵ 𝑠 r,s,\epsilon_{s} italic_r , italic_s , italic_ϵ start_POSTSUBSCRIPT italic_s end_POSTSUBSCRIPT be parameters of polynomial kernel methods.
Then, our data structure requires O ~ ⁢ ( n ⁢ d ⁢ r 2 ) ~ 𝑂 𝑛 𝑑 superscript 𝑟 2 \widetilde{O}(ndr^{2}) over~ start_ARG italic_O end_ARG ( italic_n italic_d italic_r start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT ) memory consumption with O ~ ⁢ ( n ⁢ r 2 ) ~ 𝑂 𝑛 superscript 𝑟 2 \widetilde{O}(nr^{2}) over~ start_ARG italic_O end_ARG ( italic_n italic_r start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT ) initialization time complexity and O ~ ⁢ ( α − 1 ⁢ r 2 ) ~ 𝑂 superscript 𝛼 1 superscript 𝑟 2 \widetilde{O}(\alpha^{-1}r^{2}) over~ start_ARG italic_O end_ARG ( italic_α start_POSTSUPERSCRIPT - 1 end_POSTSUPERSCRIPT italic_r start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT ) query time complexity for a single token query.
In addition, our data structure can guarantee that the process of answering user query satisfies ( ϵ , δ ) italic-ϵ 𝛿 (\epsilon,\delta) ( italic_ϵ , italic_δ ) -DP with O ~ ⁢ ( n − 1 ⁢ ϵ − 1 ⁢ α − 1 / 2 ⁢ R 2 ⁢ s ⁢ R w ⁢ r 2 ) ~ 𝑂 superscript 𝑛 1 superscript italic-ϵ 1 superscript 𝛼 1 2 superscript 𝑅 2 𝑠 subscript 𝑅 𝑤 superscript 𝑟 2 \widetilde{O}(n^{-1}\epsilon^{-1}\alpha^{-1/2}R^{2s}R_{w}r^{2}) over~ start_ARG italic_O end_ARG ( italic_n start_POSTSUPERSCRIPT - 1 end_POSTSUPERSCRIPT italic_ϵ start_POSTSUPERSCRIPT - 1 end_POSTSUPERSCRIPT italic_α start_POSTSUPERSCRIPT - 1 / 2 end_POSTSUPERSCRIPT italic_R start_POSTSUPERSCRIPT 2 italic_s end_POSTSUPERSCRIPT italic_R start_POSTSUBSCRIPT italic_w end_POSTSUBSCRIPT italic_r start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT ) additive error and n − 1 ⁢ ( α + ϵ s ) superscript 𝑛 1 𝛼 subscript italic-ϵ 𝑠 n^{-1}(\alpha+\epsilon_{s}) italic_n start_POSTSUPERSCRIPT - 1 end_POSTSUPERSCRIPT ( italic_α + italic_ϵ start_POSTSUBSCRIPT italic_s end_POSTSUBSCRIPT ) relative error between our output and the true answer.
Furthermore, our result is robust to adaptive queries in which users can intentionally attack the cross-attention system.
To our knowledge, this is the first work to provide DP for cross-attention and is promising to inspire more privacy algorithm design in large generative models (LGMs).

## 1 Introduction

The development of Artificial Intelligence (AI) has four stages: (1) prediction AI, e.g., ResNet [] in image classification; (2) generation AI, e.g., ChatGPT [] in language generation; (3) autonomous agent AI, Voyager [] autonomously plays Minecraft game []; (4) Artificial Generalization Intelligence (AGI).
Humans have made rapid progress in generative AI, and we are excitingly heading to the third stage, the era of AI agent [].
One prevalent application of AI agents is customized large generative models (LGMs) agents [], e.g., AgentGPT [], SuperAGI [], MetaGPT [, ], GPT Researcher [] and many so on.
In particular, recently, Apple Inc. introduced Apple Intelligence [], signaling the integration of LGMs into physical devices. This innovation allows devices to use personal information for real-life assistance, such as entering passport numbers when booking flights or informing users of their latest meetings.
With increased AI capabilities, privacy concerns become significant, as the more personal information devices handle, the greater the potential privacy risks.

One fundamental technique used in LGMs is cross-attention [], which is an essential module in retrieval-augmented generation (RAG) [], system prompt, guided stable diffusion, and many so on.
In RAG, to be more professional, the LGMs answer user input queries by using a domain-specific database under cross-attention, which may contain specific privacy data and knowledge so that the LGMs gain additional power.
For system prompts, based on cross-attention, some customized long prompts, e.g., user information or concrete rules, are concatenated before user input to follow human instructions better, which are commonly used in ChatGPT [], Claude3 [] and other commercial LGMs.

Consequently, protecting the privacy of domain-specific data in RAG or system prompts is crucial as they contain sensitive information about users and companies. These data and prompts are the core assets of many start-ups.
However, these data and prompts can be easily recovered [], jailbroken [], and released [] by user adversarial attack [], e.g., there are 1700 tokens in ChatGPT system prompts [].
These findings highlight the critical importance of robust privacy protections in LGMs, making privacy not just essential but an urgent issue that demands immediate attention.

To fundamentally preserve cross-attention privacy, we borrow the powerful tools from differential privacy (DP) [], which provides measurable privacy and combines with statistical machine learning seamlessly [].
Thus, in this work, we would like to ask and answer the following question,

How can we use differential privacy to protect the security of cross-attention in LGMs?

Our work demonstrates that the Softmax cross-attention computation is equivalent to computing the weighted distance problem.

###### Definition 1.1 (Softmax cross-attention) .

Let $n$ and $m$ be the token length of the data and input query, respectively.
Let $d$ be the feature dimension.
Given fixed key matrix $K\in[0,R]^{n\times d}$ and fixed value matrix $V\in[-R_{w},R_{w}]^{n\times d}$, for any input query matrix $Q\in[0,R]^{m\times d}$,
the goal of the Softmax Cross-Attention Computation is to get the matrix $\mathrm{Attn}(Q,K,V)\in\mathbb{R}^{m\times d}$, which is

$$ $\displaystyle\mathrm{Attn}(Q,K,V):=D^{-1}AV,$ $$

where $A\in\mathbb{R}^{m\times n}$ satisfies $A_{i,j}:=\exp(\langle Q_{i},K_{j}\rangle/d)$ for any $i\in[m],j\in[n]$ ($Q_{i}$ and $K_{j}$ denote the $i$-th and $j$-th rows of $Q$ and $K$, respectively) and $D:=\mathrm{diag}(A{\bf 1}_{n})\in\mathbb{R}^{m\times m}$ is a diagonal matrix.

Note that $\mathsf{Softmax}(QK^{\top})=D^{-1}A\in\mathbb{R}^{m\times n}$ in Definition 1.1, which is the standard function used in transformers, and usually, we call it as attention matrix. Our main theorem, presented below, provides a robust solution of cross-attention, ensuring privacy and accuracy guarantees.

###### Theorem 1.2 (Main result; Informal version of Theorem 3.1 ) .

Let $Q,K,V,\mathrm{Attn}$ be defined in Definition 1.1.
Let $\alpha\in(0,1)$ be the relative error parameter and $p_{f}$ be the probability of failure parameter.
Let $r,s,\epsilon_{s}$ be the parameters of the polynomial kernel methods (Lemma C.7).
Let $l=\widetilde{O}(r)$.
Then, our Algorithm 1 requires $O(lndr)$ memory with $O(lnr)$ initialization time and $\widetilde{O}(\alpha^{-1}lr)$ query time, such that with probability $1-p_{f}$, the output process of cross-attention satisfies $(\epsilon,\delta)$-DP and is robust to adaptive query with relative error $n^{-1}(\alpha+\epsilon_{s})$ and additive error $\widetilde{O}(n^{-1}\epsilon^{-1}\alpha^{-1/2}lR^{2s}R_{w}r)$.

Our main technique in Theorem 1.2 ensures that cross-attention is differentially private by using the polynomial kernel approximation method and transforming it into a weighted distance problem.
We then solve the problem by summing over weighted distances (depending on the value embedding) between the query embedding and the key embedding.
We build a data structure for weighted Softmax queries in Section 4.3, and we extend this data structure to handle adaptive queries using the $\epsilon_{0}$-net/metric entropy argument in Section 4.4.
Furthermore, our error decreases as the input token length grows, diminishing both the relative and additive errors to zero.

Our contributions are as follows:

- •
We demonstrate that cross-attention computations are equivalent to the weighted distance problem (Section 3).
- •
We design a novel algorithm (Algorithm 3) that privately answers weighted Softmax queries with high probability and a concrete accuracy bound.
- •
Our algorithm (Algorithm 1) handles multiple cross-attention queries and is robust against adaptive query attacks (Theorem 3.1), meaning that potential attackers cannot intentionally extract information of system prompts/RAG data.

To our knowledge, this is the first work to utilize DP to protect prompts in LGMs with theoretically provable guarantees.
While some have explored protecting user/system prompts with DP [, ], they are primarily empirical and lack theoretical guarantees.
Additionally, many others are working on protecting private datasets by applying DP to the fine-tuning stage of LGMs [, , , , , ], which diverges from our work.
The strength of DP lies in its strong, unambiguous, and concrete definition of privacy, enabling algorithm designs with provable privacy and accuracy analysis.
Therefore, we believe that the theoretical aspects of DP applications in LGMs remain a highly impactful direction, and we aim to pave the way for further exploration in this area.

###### Definition 1.1 (Softmax cross-attention) .

###### Theorem 1.2 (Main result; Informal version of Theorem 3.1 ) .

### 1.1 Related Work

Differential Privacy in Data Structure and Attention.
Differential privacy (DP) is a flourishing and powerful technique that has enormous applications in the topic of private machine learning. In the era of Large Generative Models (LGMs), there are three primary approaches to ensuring privacy:
(1) during the pre-training stage: to protect training data [, ],
(2) during the adaptation stage: to protect target data [, , , , , ],
(3) during the inference stage: to protect user/system prompts [] and RAG data [].
To protect training data, DP-SGD [] uses DP optimizer to ensure data privacy, severing as the traditional baseline method.
Recently, numerous works have aimed to improve this method by integrating DP in both the pre-training and fine-tuning stages of LGMs [, , , , , , , , ].
To protect user/system prompts, EW [] provides a survey on both DP and non-DP methods.
In the use of LGMs, prompting methods almost become a standard way for inference [].
Given the billions of prompt interactions daily, ensuring privacy is essential []. We refer readers to Appendix A for more related works.

Roadmap.
In Section 2, we present the preliminary of differential privacy (DP) and cross-attention.
In Section 3, we present the main result of our cross-attention theorem (Theorem 3.1).
In Section 4, we outline the main results of our algorithms.
In Section 5, we discuss DP-related topics and potential extensions.
In Section 6, we conclude our paper.

## 2 Preliminary

In this section, we give the preliminary of differential privacy (DP) and cross-attention.
In Section 2.1, we describe the notations.
In Section 2.2, we give definitions related to DP.

### 2.1 Notations

We use $\Pr[]$ to denote the probability. We use $\operatorname*{{\mathbb{E}}}[]$ to denote the expectation. We use $\operatorname*{\mathrm{Var}}[]$ to denote the variance.
For two vectors $x\in\mathbb{R}^{d}$ and $y\in\mathbb{R}^{d}$, we use $\langle x,y\rangle$ to denote the inner product between $x,y$, i.e., $\langle x,y\rangle=\sum_{i=1}^{d}x_{i}y_{i}$.
We use $X\subset\mathbb{R}^{d}$ and $|X|=n$ to mean the same thing as $X\in\mathbb{R}^{n\times d}$. Also, we denote $x_{i}^{\top}$ as the $i$-th row of $X$.
We use $x_{i,j}$ to denote the $j$-th coordinate of $x_{i}\in\mathbb{R}^{n}$.
We use ${\bf 1}_{n}$ to denote a length-$n$ vector where all the entries are ones.
We use $\|x\|_{p}$ to denote the $\ell_{p}$ norm of a vector $x\in\mathbb{R}^{n}$, i.e., $\|x\|_{1}:=\sum_{i=1}^{n}|x_{i}|$, $\|x\|_{2}:=(\sum_{i=1}^{n}x_{i}^{2})^{1/2}$, and $\|x\|_{\infty}:=\max_{i\in[n]}|x_{i}|$.

### 2.2 Differential Privacy Definitions

In this section, we give several definitions related to differential privacy (DP). We refer the reader to DR [] for more background and details on DP.

###### Definition 2.1 (Neighboring dataset) .

We define the two neighboring datasets as $X,X^{\prime}\in\mathbb{R}^{n}$ such that $\|X-X^{\prime}\|_{1}\leq 1$, i.e., they differ on a single data point.

###### Definition 2.2 (Sensitivity) .

The sensitivity of a function $f:\mathbb{R}^{n}\to\mathbb{R}^{d}$ is defined by:
$\Delta:=\max_{X,X^{\prime}\in\mathbb{R}^{n},\|X-X^{\prime}\|_{1}=1}\|f(X)-f(X^
{\prime})\|_{1}.$

###### Definition 2.3 ( $(\epsilon,\delta)$ -DP) .

For $\epsilon>0,\delta\geq 0$, a randomized algorithm $\mathcal{A}$ is $(\epsilon,\delta)$-DP, if for all $\mathcal{S}\subseteq\mathrm{Range}({\mathcal{A}})$ and for all $X,X^{\prime}$
such that $\|X-X^{\prime}\|_{1}\leq 1$:

$$ $\displaystyle\Pr[{\mathcal{A}}(X)\in\mathcal{S}]\leq\exp(\epsilon)\Pr[{ \mathcal{A}}(X^{\prime})\in{\mathcal{S}}]+\delta.$ $$

When $\delta=0$, the algorithm is said to have pure differential privacy.

We mainly use the truncated Laplace mechanism, which has the following definitions.

###### Definition 2.4 (Truncated Laplace distribution) .

We use $\mathrm{TLap}(\Delta,\epsilon,\delta)$ to denote the Truncated Laplace distribution with pdf proportional to $\exp(-\epsilon|z|/\Delta)$ on the region $[-B,B]$, where $B=\frac{\Delta}{\epsilon}\cdot\log(1+\frac{\exp(\epsilon)-1}{2\delta})$.

###### Fact 2.5 (Theorem 3 in GDGK [ 32 ] ) .

Let $z$ denote a $\mathrm{TLap}(\Delta,\epsilon,\delta)$ random variable.
Then we have
$\operatorname*{{\mathbb{E}}}[z]=0$, and

$$ $\displaystyle\operatorname*{\mathrm{Var}}[z]=\frac{2\Delta^{2}}{\epsilon^{2}}( 1-\delta\cdot\frac{\log^{2}(1+\frac{e^{\epsilon}-1}{2\delta})+2\log(1+\frac{e^ {\epsilon}-1}{2\delta})}{e^{\epsilon}-1}).$ $$

Furthermore, if $\delta=0$, we have $\operatorname*{\mathrm{Var}}[z]=2\Delta^{2}/\epsilon^{2}$, meaning truncated Laplacian mechanism will be reduced to the standard
Laplacian mechanism.

###### Lemma 2.6 (Laplace mechanism, [ 20 , 32 ] , see Lemma 2.2 in AIMN [ 3 ] ) .

Given a numeric function $f$ that takes a dataset $X$ as the input, and has sensitivity $\Delta$, the mechanism that outputs $f(X)+z$ where $z\sim\mathrm{Lap}(\Delta/\epsilon)$ is $(\epsilon,0)$-DP. In addition, if $\epsilon,\delta\in(0,0.5)$, $f(X)+z$, where $z\sim\mathrm{TLap}(\Delta,\epsilon,\delta)$ is $(\epsilon,\delta)$-DP. Moreover, the truncated Laplace mechanism is always accuracy up to error $B$.

Figure: Algorithm 1 Adaptive query data structure

###### Definition 2.1 (Neighboring dataset) .

###### Definition 2.2 (Sensitivity) .

###### Definition 2.3 ( ( ϵ , δ ) italic-ϵ 𝛿 (\epsilon,\delta) ( italic_ϵ , italic_δ ) -DP) .

###### Definition 2.4 (Truncated Laplace distribution) .

###### Fact 2.5 (Theorem 3 in GDGK [ 32 ] ) .

###### Lemma 2.6 (Laplace mechanism, [ 20 , 32 ] , see Lemma 2.2 in AIMN [ 3 ] ) .

## 3 Main Results: Cross-Attention

In this section, we show our main result for cross-attention.
Theorem 3.1 states that we can ensure the entire cross-attention module satisfies DP and is robust to adaptive queries.
Our high-level idea is based on the similarity between weighted distance problem and cross-attention. For a typical weighted distance problem, we define the following:
Let $w\in\mathbb{R}^{n}$ be the weights, $X\in\mathbb{R}^{n\times d}$ be the data matrix, where $x_{i}^{\top}$ is the $i$-th row of $X$ for $i\in[n]$, and let $y\in\mathbb{R}^{d}$ be the query. Suppose we need to answer $\ell_{1}$-distance query. We have

$$ $\displaystyle\sum_{i\in[n]}\underbrace{w_{i}}_{\mathrm{weight}}\|\underbrace{y }_{\mathrm{query}}-\underbrace{x_{i}}_{\mathrm{data}}\|_{1}.$ $$

Now we introduce cross-attention.
Let $Q,K,V,\mathrm{Attn}$ be defined in Definition 1.1.
In a standard cross-attention process, we have access to $K$ and $V$ before inference, but not to the user input $Q$.
For the cross-attention mechanism $\mathrm{Attn}$ (Definition 1.1), we aim to ensure that the matrix $AV$ satisfies DP guarantee.
Let $A_{i,j}=\exp(\langle Q_{i},K_{j}\rangle/d)$ for $i\in[m],j\in[n]$. Let $V_{j,k}\in\mathbb{R}$ be the $(j,k)$-th entry of $V$, for $j\in[n],k\in[d]$.
By post-processing property (Fact B.5), to ensure that the forward output $\mathrm{Attn}(Q,K,V)=D^{-1}AV$ (Definition 1.1) satisfies DP, we only need to ensure the DP of its component $AV$(^1^11$D$ is only a normalization factor and does not have sensitive information.).
The $(i,k)$-th entry of $AV$ for each $i\in[m],k\in[d]$ is computed by

$$ $\displaystyle(AV)_{i,k}=$ $\displaystyle~{}\sum_{j=1}^{n}\underbrace{V_{j,k}}_{\mathrm{weight}}\exp( \langle\underbrace{Q_{i}}_{\mathrm{query}},\underbrace{K_{j}}_{\mathrm{data}} \rangle/d),$ (1) $$

which can be viewed as a weighted Softmax problem, where $V$ provides the weights, $Q$ is the query, and $K$ is the dataset.
Thus, we choose to add noise to $K$ and $V$ based on the similarity between the weighted distance problem and cross-attention. Furthermore, we find that we can only handle one column of $V$, i.e., $V_{*,k}\in\mathbb{R}^{n}$, in a single data structure. Therefore, we need to initialize a total of $d$ different data structures, each with weights $V_{*,k}$ for $k\in[d]$.

Here, we present our main result below.

###### Theorem 3.1 (Softmax cross-attention, informal version of Theorem I.12 ) .

Let $Q,K,V,\mathrm{Attn}$ be defined in Definition 1.1.
Let $\alpha\in(0,1)$ be the relative error parameter and $p_{f}$ be the probability of failure parameter.
Let $r,s,\epsilon_{s}$ be the parameters of the polynomial kernel methods (Lemma C.7).
Let $\Gamma_{R,s}:=\max_{j\in[s]}\frac{R^{j}}{\sqrt{j!}}$ (Definition I.3).
Let $l=O(r\log(dR/(\epsilon_{s}p_{f})))$.
There is a data structure DPTreeSoftmaxAdaptive (Algorithm 1) that uses $O(lnrd)$ spaces to ensure cross-attention satisfies DP and supports the following operations:

- •
We initialize $d$ data structures using Init$(K,n,V_{*,k},\epsilon\in(0,1),\delta\in(0,1),\delta^{\prime}\in(0,1),c\in(0,0.
1),\epsilon_{s}\in(0,0.1),p_{f}\in(0,0.01))$ (Algorithm 1), for $k\in[d]$. It takes $O(lnr)$ time to initialize one data structure.
- •
At query time, for user input $Q$, we process one token at a time by passing the $i$-th row of $Q$, denoted $Q_{i}\in\mathbb{R}^{d}$, to DistanceQuery$(Q_{i},\alpha\in(0,1))$ (Algorithm 1) for each $i\in[m]$.
It takes $O(\alpha^{-1}lr\log^{2}n)$ time to output an entry $z$ in $\mathrm{Attn}(Q,K,V)$ such that
–
the process of output $z$ satisfies $(\epsilon,\delta+\delta^{\prime})$-DP,
–
the process of output $z$ has relative error $n^{-1}(\alpha+\epsilon_{s})$,
–
the process of output $z$ has additive error $O(n^{-1}\epsilon^{-1}\alpha^{-1/2}l\Gamma_{R,s}^{2}R_{w}r\sqrt{\log(l/\delta^{
\prime})}\cdot\log^{3/2}n)$,
–
it holds with probability $1-p_{f}$ (where $p_{f}$ is used in $l$),
–
it is robust to adaptive query.

In Theorem 3.1, we use our DPTreeSoftmaxAdaptive (Algorithm 1) and guarantee that, for each query token of cross-attention, the output process satisfies $(\epsilon,\delta)$-DP with $n^{-1}(\alpha+\epsilon_{s})$ relative error and $O(n^{-1}\epsilon^{-1}\alpha^{-1/2}l\Gamma_{R,s}^{2}R_{w}r\sqrt{\log(l/\delta^{
\prime})}\cdot\log^{3/2}n)$ additive error, and $O(\alpha^{-1}lr\log^{2}n)$ running time under adaptive query.
More specifically, the algorithm creates $d$ DPTreeSoftmaxAdaptive data structures, each requiring $O(lnr)$ memory consumption and $O(lnr)$ initialization time.
Notably, our error is inversely proportional to $n$, meaning that as the input token length increases, both the relative and approximate errors approach zero. This is achieved by the normalizing matrix $D$ (Definition 1.1). We refer the reader to Section I for proof details.

Thus, our algorithm theoretically protects system prompts/RAG data in cross-attention as discussed in Section 1.
In Section 4, we provide a detailed technical overview, and in Section 5, we will present self-attention and DP-related discussion.

Figure: Algorithm 2 DPTree initialization and query

###### Theorem 3.1 (Softmax cross-attention, informal version of Theorem I.12 ) .

## 4 Key Data Structure: DPTree

This section provides our key data structures: DPTree (Algorithm 2), DPTreeDistance (Algorithm 5 and 6), DPTreeHighDim (Algorithm 7), DPTreeSoftmax (Algorithm 3), and DPTreeSoftmaxAdaptive (Algorithm 1).

In Section 4.1, we provide our high-level proof insights.
In Section 4.2, we give our basic building block algorithms DPTree, DPTreeDistance and DPTreeHighDim.
In Section 4.3, we present our DPTreeSoftmax algorithm that solves the weighted Softmax problem.
In Section 4.4, we present our DPTreeSoftmaxAdaptive algorithm that enables DPTreeSoftmax to handle adaptive query problem.

### 4.1 Technique Overview

Notice that Eq. (1) is not a typical distance measure like $\ell_{1}$ or $\ell_{2}$, but by using polynomial kernel method techniques, we transform it into a distance measure. AS [] states that the exponential inner product can be approximated by polynomial kernel function $P(\cdot):\mathbb{R}^{d}\to\mathbb{R}^{r}$, i.e., $P(x)^{\top}P(y)\approx\exp(x^{\top}y/d)$ for two vector $x,y\in\mathbb{R}^{d}$, with a relative error. Then, by the Law of Cosines, we transform the inner product of polynomial kernel functions into a distance measure, i.e.,

$$ $\displaystyle 2P(x)^{\top}P(y)=$ $\displaystyle~{}-\|P(x)-P(y)\|_{2}^{2}+\|P(x)\|^{2}_{2}+\|P(y)\|^{2}_{2}.$ (2) $$

After transforming Eq. (1) into a distance measure, we design the DPTree series data structures to provide cross-attention DP guarantee.

In summary, we first design the data structure DPTree (Algorithm 2) that builds a binary segment tree with truncated Laplace noise added in the leaf nodes to ensure DP guarantee.
Then, based on this data structure, we design DPTreeDistance (Algorithm 5 and 6) to answer one dimensional weighted distance queries $\sum_{i=1}^{n}w_{i}\cdot|y-x_{i}|$, which utilizes DPTree to store and return noised weights $w_{i}$ multiplied with the approximated distances between the query $y$ and data $x_{i}$.
We further decompose high dimensional $\ell_{p}^{p}$-distance problem into one dimensional $\ell_{1}$-distance problems using

$$ $\displaystyle\sum_{i=1}^{n}w_{i}\cdot\|y-x_{i}\|_{p}^{p}=$ $\displaystyle~{}\sum_{k=1}^{d}\sum_{i=1}^{n}w_{i}\cdot|y_{k}-x_{i,k}|^{p}.$ (3) $$

Based on this decomposition, we design DPTreeHighDim (Algorithm 7) which is capable of answering high dimension queries.
Then, using Eq. (2) and DPTreeHighDim, we design DPTreeSoftmax (Algorithm 3) to answer Softmax queries. By building multiple copies of this data structure, we boost the success probability such that it can answer any query (including adaptive query) with an additive error, establishing the final data structure DPTreeSoftmaxAdaptive (Algorithm 1).
See Section C for a more detailed outline of algorithms and proof techniques.

### 4.2 DPTree, DPTreeDistance, and DPTreeHighDim

We design a basic data structure DPTree (Algorithm 2) that answers summation queries by a summation segment tree with truncated Laplace noise (Definition 2.4).
The algorithm first builds a binary summation tree in an array and then adds truncated Laplace noises to each node.
In query time, we first trace from bottom nodes to find their lowest common ancestor, then report the summation by using at most $2\log n$ nodes on the path (Algorithm 2).
Based on the parallel composition rule of DP (Fact B.7), we find that if we have multiple disjoint interval queries, the error of the weighted sum of the intervals can be bounded independently of the number of queries (Lemma D.8). See more details in Section D.

We then design DPTreeDistance, a one-dimensional weighted $\ell_{1}$ distance data structure detailed in Algorithm 5 and 6. Initialization involves rounding each data point to the nearest multiple of a small interval and aggregating their weights into an array (illustrated in Figure 1), which is then input into our DPTree. At query time, we retrieve aggregated weights within small intervals and multiply them by their distances to the query point. We introduce a relative error parameter $\alpha$ to reduce the number of iterations to $O(\log(n)/\alpha)$, improving efficiency. Guided by Eq.(3), we design DPTreeHighDim (Algorithm 7), which extends DPTreeDistance to higher dimension by constructing independent data structures for each coordinate. See details in Section F and G.

Figure: Algorithm 3 Softmax query

### 4.3 Softmax Activation

In this section, we present DPTreeSoftmax (Algorithm 3) that answers the weighted Softmax query (Definition 4.1) and is further used to design DP cross-attention.
First, we introduce the definition of weighted Softmax query, an abstraction for the problem described in Eq. (1).

###### Definition 4.1 (Weighted Softmax query (without normalization)) .

For the dataset $X\in[0,R]^{n\times d}$ where $x_{i}^{\top}$ is the $i$-th row of $X$ and query $y\in[0,R]^{d}$, we define the weighted exponential inner product/Softmax query to be:

$$ $\displaystyle\sum_{i\in[n]}w_{i}\exp(\langle x_{i},y\rangle/d)=w^{\top}\exp(Xy /d).$ $$

Building on Definition 4.1, we develop a novel algorithm to answer differentially private weighted Softmax queries using the polynomial kernel method from AS []. Specifically, in Eq.(2), there is a term that computes the weighted $\ell_{2}^{2}$ distance, which we calculate using DPTreeHighDim. We then compute the exact term for the weighted $\ell_{2}^{2}$ norms of the approximation kernel. By summing these terms with a controlled error, we extend DPTreeHighDim to answer the Softmax query efficiently.
More details can be found in Section I.

###### Theorem 4.2 (Softmax query, informal version of Theorem I.8 ) .

Let $R\geq 1$.
Let $r\leq{2s+2d\choose 2s}$ and $s=O(\max\{\frac{\log(1/\epsilon_{s})}{\log(\log(1/\epsilon_{s})/R)},R^{2}\})$.
Let $\Gamma_{R,s}:=\max_{j\in[s]}\frac{R^{j}}{\sqrt{j!}}$ (Definition I.3).
Let the accuracy parameter be $\epsilon_{s}\in(0,0.1)$.
Our data structure DPTreeSoftmax (Algorithm 3) uses $O(nr)$ spaces to solve Softmax query problem for dataset $X\subset[0,R]^{d}$ and support following operations:

- •
Init$(X\subset[0,R]^{d},n\in\mathbb{N}_{+},w\in[-R_{w},R_{w}]^{n},\epsilon\in(0,1),
\delta\in(0,1),\delta^{\prime}\in(0,1),c\in(0,0.1),\epsilon_{s}\in(0,0.1))$. (Algorithm 3)
It takes $O(nr)$ time to initialize the data structure.
- •
DistanceQuery$(y\in[0,R]^{d},\alpha\in(0,1))$. (Algorithm 3)
It takes $O(\alpha^{-1}r\log^{2}n)$ time to output a number $z$ such that
–
the process of output $z$ satisfies $(\epsilon,\delta+\delta^{\prime})$-DP private, which computes $w^{\top}\exp(Xy/d)$,
–
the error bound satisfies $|z-w^{\top}\exp(Xy/d)|\leq(\alpha+\epsilon_{s})\cdot w^{\top}\exp(Xy/d)$
$+~{}O(\epsilon^{-1}\alpha^{-1/2}\Gamma_{R,s}^{2}R_{w}r\sqrt{\log(1/\delta^{
\prime})}\cdot\log^{3/2}n)$,
–
it holds with probability at least $0.99$.

###### Remark 4.3 .

In Theorem 4.2, the parameter $\epsilon_{s}$ is the accuracy parameter for polynomial kernel approximation described in Section C.5.
Besides, note that the error bound in Theorem 4.2 does not depend on $\delta$ but depends on $\delta^{\prime}$.
The role of $\delta$ is to control a hidden constant term in the big $O$ notation, i.e., increasing $\delta$ reduces the error by a small constant (Fact 2.5).
In practice, we set $\delta$ as a small positive constant close to 0 0. Please refer to the Lemma D.6 for more details.

###### Definition 4.1 (Weighted Softmax query (without normalization)) .

###### Theorem 4.2 (Softmax query, informal version of Theorem I.8 ) .

###### Remark 4.3 .

### 4.4 Adaptive Query Data Structure

We adapt our DPTreeSoftmax to DPTreeSoftmaxAdaptive (Algorithm 1) to solve the adaptive query problem. By proving it can handle any query within the query space with a certain error, we ensure it effectively processes adaptive queries. We first boost the constant probability to high probability using the Chernoff bound (Lemma B.2). Employing an $\epsilon_{0}$-net argument and the union bound, we bound all query points within the net. Finally, we use the Lipschitz property of the weighted Softmax distance function with an additive error to bound all points in the query space. The corresponding proofs can be found in Section H and Section I.

###### Theorem 4.4 (Adaptive query Softmax data structure, informal version of Theorem I.11 ) .

Let $R\geq 1$.
Let $r\leq{2s+2d\choose 2s}$ and $s=O(\max\{\frac{\log(1/\epsilon_{s})}{\log(\log(1/\epsilon_{s})/R)},R^{2}\})$.
Let $\Gamma_{R,s}:=\max_{j\in[s]}\frac{R^{j}}{\sqrt{j!}}$ (Definition I.3).
Let the accuracy parameter be $\epsilon_{s}\in(0,0.1)$.
Let $X\in[0,R]^{n\times d}$ be the dataset, $w\in[-R_{w},R_{w}]^{n}$ be weights, $y\in[0,R]^{d}$ be the query, $\alpha\in(0,1)$ be the relative error parameter and $p_{f}$ be the failure probability parameter.
Let $l=O(r\log(dR/(\epsilon_{s}p_{f})))$.
There is a data structure DPTreeSoftmaxAdaptive (Algorithm 1) that uses $O(lnr)$ spaces to solve the weighted Softmax query problem for the dataset $X\subset[0,R]^{d}$ and supports the following operations:

- •
Init$(X\subset[0,R]^{d},n\in\mathbb{N}_{+},w\in[-R_{w},R_{w}]^{n},\epsilon\in(0,1),
\delta\in(0,1),\delta^{\prime}\in(0,1),c\in(0,0.1),\epsilon_{s}\in(0,0.1),p_{f
}\in(0,0.01))$. It takes $O(lnr)$ time to initialize the data structure.
- •
DistanceQuery$(y\in[0,R]^{d},\alpha\in(0,1))$. It takes $O(\alpha^{-1}lr\log^{2}n)$ time to output a number $z$ such that
–
the process of output $z$ satisfies $(\epsilon,\delta+\delta^{\prime})$-DP private, which computes $w^{\top}\exp(Xy/d)$,
–
the error bound satisfies $|z-w^{\top}\exp(Xy/d)|\leq(\alpha+\epsilon_{s})\cdot w^{\top}\exp(Xy/d)$
$+~{}O(\epsilon^{-1}\alpha^{-1/2}l\Gamma_{R,s}^{2}R_{w}r\sqrt{\log(l/\delta^{
\prime})}\cdot\log^{3/2}n)$,
–
it holds with probability at least $1-p_{f}$ (where $p_{f}$ is used in $l$),
–
it is robust to adaptive query.

###### Remark 4.5 .

We describe the parallelization of our algorithms.
In the second for loop of Init and the for loop of DistanceQuery in Algorithm 3, the $r$ DPTreeDistance data structures instantiated for each coordinate are independent of each other.
In addition, the for loops in Algorithm 1 are also parallelizable since the $l=O(r\log(dR/(\epsilon_{s}p_{f})))$ copies are independent.
After parallelization, we have the final time complexity of Init to be $O(nr)$ and DistanceQuery to be $O(\alpha^{-1}\log^{2}n)$ in Algorithm 1 with $O(lr)$ GPU process.

###### Theorem 4.4 (Adaptive query Softmax data structure, informal version of Theorem I.11 ) .

###### Remark 4.5 .

## 5 Discussion

#### How do we extend to self-attention?

As self-attention is a more fundamental module in LGMs, we would like to extend our data structure to this setting. However, the challenge we faced was the dynamic update in tree nodes for each query for self-attention, which our current analysis does not support.
How we can solve this challenge is crucial, and we leave it as our future direction.

#### Why not add noise to some other places?

Where and how to add DP noises is an important problem to ask during the DP algorithm design.
In this paper, we consider the problem of $\sum_{i=1}^{n}w_{i}\exp(\langle x_{i},y\rangle/d)$ where $y,x_{i}\in[0,R]^{d}$ and $w\in[-R_{w},R_{w}]^{n}$ (Definition 4.1).
Notice that the only place where we add noises is in the most basic building block data structure DPTree (Algorihtm 2).
From Lemma C.3 and the way we initialize DPTree in Algorithm 5, we see that the sensitivity $\Delta$ of this problem is $2R_{w}$.

A simple method for adding noise involves adding $n$ noises to a length $n$ array, with each item $w_{i}\exp(\langle x_{i},y\rangle/d)$ for $i\in[n]$. However, this approach increases the error by a factor of $n$ by basic composition (Fact B.6) and also makes the model dependent on the number of queries. Besides, it only supports a single query and requires rebuilding the tree for each new query, rendering it impractical.
In contrast, our current noise-adding technique (Lines 9 and 15 of Algorithm 2) utilizes a summation tree such that the error only increases by a factor of $\operatorname{poly}\log n$.
This method also supports multiple queries, eliminating the need to rebuild the tree each time.

#### How to remove the relative error parameter α 𝛼 \alpha italic_α ?

The relative error parameter $\alpha$ in Theorem 3.1 appears because of the $(1+\alpha)$-approximation introduced in Algorithm 5 (Remark F.3) to reduce the number of required iterations from naive $O(n)$ to $O(\log(n)/\alpha)$.
However, we notice that a recent work [] does not utilize $(1+\alpha)$-approximation and still achieves $O(\log n)$ iteration number. They introduce a new tree node representation where each node stores the sum of distances from one point to multiple points, enabling the answer to be divided into only $\log n$ values, each combining two distance values, two count values, and $y$ itself.
Our DPTree algorithms can be integrated with their method, thus removing parameter $\alpha$.

## 6 Conclusion

To our knowledge, we are the first work to provide differential privacy for cross-attention.
This paper presents the DPTree data structures, which provide a differential privacy guarantee for the cross-attention module in large generative models.
This is achieved by transforming the cross-attention mechanism into a weighted distance problem.
Furthermore, our algorithm is robust to adaptive queries, allowing users to interact with the model arbitrarily without extracting sensitive information from the system prompts or RAG data.
Our results may inspire more privacy algorithm design in large generative models.

## Acknowledgement

Research is partially supported by the National Science Foundation (NSF) Grants 2023239-DMS, CCF-2046710, and Air Force Grant FA9550-18-1-0166.

## Appendix A More Related Work

#### Differential Privacy Guarantee Analysis.

Ever since DMNS [] proposes the notion of differential privacy (DP), it has become one of the most essential standards of privacy protection in both theoretical and empirical ways [, , , , ].
DP provides a powerful, robust, and quantifiable privacy definition, allowing algorithm design with concrete privacy and accuracy guarantee [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ].
Additionally, new mechanisms have been proposed beyond the traditional Laplace, Gaussian, and Exponential mechanisms [].
For example, truncated Laplace mechanism [] is proved to be the current tightest the lower and upper bounds on the minimum noise amplitude and power cross all $(\epsilon,\delta)$-DP distributions.

#### Cross-Attention in System Prompt, RAG, Stable Diffusion and More.

Cross-attention [], first introduced in language translation, is a widely used technique in many advanced AI systems. For example, Stable Diffusion [, , , , ] and SORA [] employ cross-attention as a core module for a text-to-image conditional generation. This technique is also utilized by other multimodal models [], including Imagen [] and Diffusion Transformer [].
In the realm of text-to-image editing, HMT^+ [] analyzes and controls the cross-attention module to enable editing without requiring additional training. Furthermore, YYB^+ [] tackles the issue of inaccurate cross-attention maps, enhancing fine-grained control over edited regions while preventing unintended changes to other areas.
In addition, Retrieval Augmented Generation (RAG) [, , ], a technique that improves model responses by retrieving information from a knowledge base or external documents, extensively uses cross-attention as its core design module.
Cross-attention also has other applications. ORST [] demonstrates that the prompt-tuning [] task can be formulated as cross-attention, while CFP [] uses cross-attention to fuse multi-scale features in vision transformers, thereby reducing computation.
Moreover, attention-based Transformer architecture makes LGMs equipping many emergent ability [], such as spatial reasoning [], mathematical reasoning [], in-context learning ability [], compositional ability [], few-shot adaptation ability [, ], and so on.
There are some other works that used cross attention in Hopfield Models [, , , , , , ].

## Appendix B More Preliminary

In Section B.1, we give the probability tools we use in the paper.
In Section B.2, we provide the algebraic facts we use.
In Section B.3, we give the DP facts we use in the paper.
In Section B.4, we compare between popular DP mechanisms.

### B.1 Probability Tools

In this section, we give several probability lemmas.

###### Lemma B.1 (Markov’s inequality) .

If $x$ is a nonnegative random variable and $t>0$, we have

$$ $\displaystyle\Pr[x\geq t]\leq\frac{\operatorname*{{\mathbb{E}}}[x]}{t}.$ $$

###### Lemma B.2 (Chernoff bound, [ 15 ] ) .

Let $x_{i}$ be a Bernoulli random variable with probability $p_{i}$ of being equal to $1$ and $1-p_{i}$ of being equal to 0 0, and all $x_{i}$ for $i\in[n]$ are independent. Let $x=\sum_{i=1}^{n}x_{i}$. Let $\mu=\operatorname*{{\mathbb{E}}}[x]=\sum_{i=1}^{n}p_{i}$. Then, for all $\delta>0$ we have

$$ $\displaystyle\Pr[x\geq(1+\delta)\mu]\leq\exp(-\delta^{2}\mu/3),$ $$

and for all $0<\delta<1$

$$ $\displaystyle\Pr[x\leq(1-\delta)\mu]\leq\exp(-\delta^{2}\mu/2).$ $$

###### Lemma B.3 (Chebyshev’s inequality) .

Let $x$ (integrable) be a random variable with finite non-zero variance $\sigma^{2}$ (and thus finite expected value $\mu$). Then for any real number $k>0$,

$$ $\displaystyle\Pr[|x-\mu|\geq k\sigma]\leq\frac{1}{k^{2}}.$ $$

###### Lemma B.1 (Markov’s inequality) .

###### Lemma B.2 (Chernoff bound, [ 15 ] ) .

###### Lemma B.3 (Chebyshev’s inequality) .

### B.2 Algebraic Facts

###### Fact B.4 (Upper bound of exponential, Fact C.9 in LSSZ24b [ 73 ] ) .

For $a\in\mathbb{R}$, $b\in\mathbb{R}$, $a,b\leq R$, where $R\geq 0$, we have

$$ $\displaystyle|\exp(a)-\exp(b)|\leq\exp(R)|a-b|.$ $$

###### Fact B.4 (Upper bound of exponential, Fact C.9 in LSSZ24b [ 73 ] ) .

### B.3 DP Facts

In this section, we present several facts about differential privacy (DP).
We first state the post-processing property, which means, in an algorithm, if one step is DP, all the following steps are DP.

###### Fact B.5 (Post-processing, see Fact 2.1 in GKK + [ 37 ] ) .

Let ${\mathcal{A}}_{1}$ be an $(\epsilon,\delta)$-DP algorithm and ${\mathcal{A}}_{2}$ be a (randomized) post-processing algorithm. Then the algorithm ${\mathcal{A}}(X)={\mathcal{A}}_{2}({\mathcal{A}}_{1}(X))$ is still an $(\epsilon,\delta)$-DP algorithm.

If we have many DP algorithms, we need a composition rule. The most straightforward composition is the basic/sequential composition rule.

###### Fact B.6 (Basic composition, see Fact 2.3 in GKK + [ 37 ] ) .

Let ${\mathcal{A}}_{1}$ be an $(\epsilon_{1},\delta_{1})$-DP algorithm and ${\mathcal{A}}_{2}$ be an $(\epsilon_{2},\delta_{2})$-DP algorithm. Then ${\mathcal{A}}(X)=({\mathcal{A}}_{1}(X),{\mathcal{A}}_{2}({\mathcal{A}}_{1}(X),
X))$ is an $(\epsilon_{1}+\epsilon_{2},\delta_{1}+\delta_{2})$-DP algorithm.

We can do much better if we know that the inputs are disjoint.

###### Fact B.7 (Parallel composition, see Fact 2.4 in GKK + [ 37 ] ) .

Let ${\mathcal{A}}_{1}$ be an $(\epsilon_{1},\delta_{1})$-DP algorithm and ${\mathcal{A}}_{2}$ be an $(\epsilon_{2},\delta_{2})$-DP algorithm. Assume ${\mathcal{A}}_{1}$ and ${\mathcal{A}}_{2}$ depend on disjoint subsets of input coordinates. Then the algorithm ${\mathcal{A}}(X)=({\mathcal{A}}_{1}(X),{\mathcal{A}}_{2}({\mathcal{A}}_{1}(X),
X))$ is a $(\max\{\epsilon_{1},\epsilon_{2}\},$
$\max\{\delta_{1},\delta_{2}\})$-DP algorithm.

In addition, we have the advanced composition, which improves the dependence of the number of DP algorithms to square root but compromises the term $\delta^{\prime}$.

###### Theorem B.8 (Advanced composition, see Theorem 3.20 in DR [ 20 ] ) .

For all $\epsilon,\delta,\delta^{\prime}\geq 0$, the class of $(\epsilon,\delta)$-differentially private mechanisms satisfies $(\epsilon^{\prime},k\delta+\delta^{\prime})$-differential privacy under $k$-fold adaptive composition for:

$$ $\displaystyle\epsilon^{\prime}=k\epsilon(e^{\epsilon}-1)+\epsilon\sqrt{2k\log( 1/\delta^{\prime})}.$ $$

###### Fact B.5 (Post-processing, see Fact 2.1 in GKK + [ 37 ] ) .

###### Fact B.6 (Basic composition, see Fact 2.3 in GKK + [ 37 ] ) .

###### Fact B.7 (Parallel composition, see Fact 2.4 in GKK + [ 37 ] ) .

###### Theorem B.8 (Advanced composition, see Theorem 3.20 in DR [ 20 ] ) .

### B.4 Comparison of Truncated Laplace, Gaussian, and Laplace Mechanisms

We first define the Laplace mechanism as below:

###### Definition B.9 (Laplace distribution) .

We use $\mathrm{Lap}(b)$ to denote the pdf:
$p(z)=\frac{1}{2b}\exp(-\frac{|z|}{b}).$

###### Fact B.10 .

For $z\sim\mathrm{Lap}(b)$, $\operatorname*{{\mathbb{E}}}[z]=0$, and $\operatorname*{\mathrm{Var}}[z]=2b^{2}$. Furthermore, if $b=\Delta/\epsilon$, we have $\operatorname*{\mathrm{Var}}[z]=2\Delta^{2}/\epsilon^{2}$.

In this paper, we use the Chebyshev inequality to bound the error, and from GDGK [], we know that the truncated Laplace mechanism has the current minimum variance across all $(\epsilon,\delta)$-DP distributions.

The variance of Gaussian mechanism in Theorem 3.22 in DR []:

$$ $\displaystyle\operatorname*{\mathrm{Var}}=\frac{2\Delta^{2}\log(1.25/\delta)}{ \epsilon^{2}}.$ $$

The variance of Laplace mechanism in Fact B.10:

$$ $\displaystyle\operatorname*{\mathrm{Var}}=\frac{2\Delta^{2}}{\epsilon^{2}}.$ $$

The variance of truncated Laplace mechanism in Fact 2.5, for $c\in(0,1]$:

$$ $\displaystyle\operatorname*{\mathrm{Var}}=\frac{2\Delta^{2}c}{\epsilon^{2}}.$ $$

Thus, since it has the minimum variance, we choose the truncated Laplace mechanism to design our algorithms among these popular mechanisms.

###### Definition B.9 (Laplace distribution) .

###### Fact B.10 .

## Appendix C Proof Outline

This section provides the proof outline of our paper.
In Section C.1, we analyze our DPTree data structure.
In Section C.2, we show the sensitivity of summation problem.
In Section C.3, we explain the high-level idea behind the weighted $\ell_{p}^{p}$ distance query.
In Section C.4, we show how to answer one-dimensional weighted $\ell_{1}$ distance query.
In Section C.5, we show how to answer Softmax distance query using previous algorithms.
In Section C.6, we show how to handle adaptive query.
By combining the results from these sections, we prove the main results in Section 4.

### C.1 Summation Segment Tree

First, in order to solve the weighted distance problem, we need to have a basic DP algorithm (Algorithm 2) that can answer simple summation queries.
After analyzing its DP and error in Section D, we state the data structure theorem.

###### Theorem C.1 ( DPTree data structure, informal version of Theorem D.1 ) .

There is a data structure (see DPTree in Algorithm 2) that uses $O(n)$ spaces to support the following operations:

- •
Init$(a\in\mathbb{R}^{n},n\in\mathbb{N}_{+},\Delta\in\mathbb{N}_{+},\epsilon\in(0,1
),\delta\in(0,1))$. It takes $O(n)$ time to initialize the data structure.
- •
Query$(x\in[n],y\in[n])$. It takes $O(\log n)$ time to output a number $z$ such that
–
the process of output $z$ satisfies $(\epsilon,\delta)$-DP private, which computes $\sum_{i=x}^{y}a_{i}$,
–
$|z-\sum_{i=x}^{y}a_{i}|\leq O(\epsilon^{-1}\Delta\log^{3/2}n)$,
–
it holds with probability $0.99$.

During the design of the data structure, we found an interesting property based on the parallel composition rule of DP Fact B.7.
We will now state the lemma, whose proof is provided in Section D.

###### Lemma C.2 (Weighted sum of disjoint interval queries, informal version of Lemma D.8 ) .

If the following conditions hold that:

- •
Let there be $t$ disjoint intervals, i.e., $S_{j}$ for $j\in[t]$, such that $S_{j}\cap S_{k}=\emptyset$ for all $j\neq k$.
- •
Let $\epsilon\in(0,1)$ and $\delta\in(0,1)$.
- •
Let $a_{j}$ for $j\in[t]$ be a series that square converges to $a$, i.e., $\sum_{j=1}^{t}a_{j}^{2}\leq a$.

Then, we have Alg. 2 is $(\epsilon,\delta)$-DP and output $\sum_{j=1}^{t}a_{j}\textsc{Query}(S_{j})$ with the error upper bounded by

$$ $\displaystyle O(a^{1/2}\epsilon^{-1}\Delta\log^{3/2}n)$ $$

with probability $0.99$.

From Lemma C.2, we can see that if we have multiple disjoint interval queries, the error of the weighted sum of the intervals can be bounded independently of the number of queries, as long as the sum of squared weights is finite.

###### Theorem C.1 ( DPTree data structure, informal version of Theorem D.1 ) .

###### Lemma C.2 (Weighted sum of disjoint interval queries, informal version of Lemma D.8 ) .

### C.2 Sensitivity for Range Summation Problem

Our DP summation tree data structure DPTree (Algorithm 2) requires sensitivity parameter $\Delta$. In this section, we show that for the summation problem, we have the sensitivity $\Delta=2R$ if the input $X\in[-R,R]^{n}$.

###### Lemma C.3 (Sensitivity of summation) .

Let $X\in[-R,R]^{n}$. We have the sensitivity $\Delta=2R$ for DPTree.Init in Algorithm 2.

###### Proof.

Let’s say two neighboring datasets $X$ and $X^{\prime}$ differ in $x_{i}$ and $x^{\prime}_{i}$ for some $i$ in the array $X$. Then for a summation problem, i.e. $f(X):=\sum_{i=1}^{n}x_{i}$, we have

$$ $\displaystyle\Delta=$ $\displaystyle~{}\max_{X,X^{\prime}}|f(X)-f(X^{\prime})|=\max_{X,X^{\prime}}|x_ {i}-x^{\prime}_{i}|=2R.$ $$

where the first step follows from Definition 2.2, the second step follows from $X,X^{\prime}$ differ in $x_{i},x^{\prime}_{i}$, and the last step follows from each coordinate of the dataset is bounded in $[-R,R]$.
∎

###### Lemma C.3 (Sensitivity of summation) .

###### Proof.

### C.3 Weighted ℓ p p superscript subscript ℓ 𝑝 𝑝 \ell_{p}^{p} roman_ℓ start_POSTSUBSCRIPT italic_p end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_p end_POSTSUPERSCRIPT Distance Problem

In this section, we introduce the intuition behind the method for handling the weighted $\ell_{p}^{p}$ distance problem. The formal lemmas and proofs can be found in Section E.

Given a dataset and a query point in $d$ dimensions, we round each coordinate of the data points and the query point to the nearest multiple of a small interval. We then aggregate the weights of data points that have been rounded to the same position. Finally, we compute the sum of these aggregated weights multiplied by the distances between the query point and the data points over the rounded positions. This approach makes the computation more efficient while maintaining sufficient accuracy.

We provide an example of weighted $\ell_{1}$-distance of a one-dimensional dataset consisting of 10 data points, i.e., $X\in[0,1]^{10}$ and a query $y=0$ in Figure 1.

###### Lemma C.4 (Weighted $\ell_{p}^{p}$ -distance high dimension, informal version of Lemma E.2 ) .

If the following conditions hold:

- •
Let data $X\in[0,R]^{n\times d}$ and $x_{i}^{\top}\in[0,R]^{d}$ be the $i$-th row of $x$, weight $w\in\mathbb{R}^{n}$, query $y\in[0,R]^{d}$.
- •
We round each dimension of $X$ and $y$ to an integer multiple of $R/n$.
- •
Let $x_{i,k},y_{k}$ denote the $k$-th coordinates of $x_{i},y$ for $k\in[d]$.
- •
Let $c_{j,k}:=\sum_{j_{0}\in S_{j,k}}w_{j_{0}}$ where the set $S_{j,k}$ is the set of index $i$ such that the corresponding $x_{i,k}$ is rounded to $jR/n$ for $j\in\{0,1,2,\dots,n\}$ for $k\in[d]$.
- •
After rounding, we assume that $y_{k}$ is in the $l_{k}R/n$ position for $l_{k}\in\{0,1,2,\dots,n\}$ for $k\in[d]$.

For the weighted problem, we have

$$ $\displaystyle\sum_{i=1}^{n}w_{i}\cdot\|y-x_{i}\|_{p}^{p}=\sum_{k=1}^{d}\sum_{j =0}^{n}(|l_{k}-j|R/n+O(R/n))^{p}c_{j,k}.$ $$

where $O(R/n)$ is the rounding error for each data point.

###### Remark C.5 .

In Lemma C.4, we first round the dataset. This rounding simplifies the calculation by reducing the number of possible positions to consider, from real values in $[0,R]^{d}$ to the total $O(nd)$ spots. However, it also introduces an error $O(R/n)$ for one data point. Then, for one spot in the rounded dataset, we sum over the weights of that spot and multiply the corresponding distance raised to the power of $p$. Additionally, since we are dealing with $\ell_{p}^{p}$ distance, the rounding error is also raised to the power of $p$.

Figure: Figure 1: The visualization of how to build $c_{j}$ of rounded dataset $X\in[0,1]^{10}$ and compute the weighted $\ell_{1}$ distance. The number above each $x_{i}$ is $w_{i}$. See Algorithm 5 for details. Suppose $y=0$. Then $\sum_{i=1}^{n}w_{i}|y-x_{i}|=0.1\cdot 2.2+0.3\cdot 3.1+0.3\cdot(-2)+0.3\cdot(- 3)+0.4\cdot 2+0.6\cdot 6+0.7\cdot 0.5+0.9\cdot(-1)+0.9\cdot 1=4.4$. And $\sum_{j=0}^{n}|k-j|c_{j}/n=0.1\cdot 2.2+0.3\cdot(-1.9)+0.4\cdot 2+0.6\cdot 6+0 .7\cdot 0.5=4.4$. See details in Lemma E.1.
Refer to caption: x1.png

###### Lemma C.4 (Weighted ℓ p p superscript subscript ℓ 𝑝 𝑝 \ell_{p}^{p} roman_ℓ start_POSTSUBSCRIPT italic_p end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_p end_POSTSUPERSCRIPT -distance high dimension, informal version of Lemma E.2 ) .

###### Remark C.5 .

### C.4 One-Dimensional Weighted ℓ 1 subscript ℓ 1 \ell_{1} roman_ℓ start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT Distance Data Structure

Based on previous discussions in Section C.1 and C.3, we can now describe our one-dimensional weighted $\ell_{1}$ distance data structure, DPTreeDistance, presented in Algorithm 5 and 6, which generalizes the results from BLM^+ [].
Drawing from the intuition in Section C.3, the initialization process is as follows: first, we round each data point in the dataset to the nearest multiple of a small interval and build an array that aggregates the corresponding weights. This array is then fed into our DPTree data structure in Algorithm 2.
At query time, we query the DPTree to obtain the aggregated weights within a small interval and multiply these weights by the distance to the query point. Furthermore, we also introduce a relative error parameter $\alpha$ to reduce the total number of queries to $O(\log(n)/\alpha)$ instead of querying all $n$ positions.
We also analyze the DP and the error bound; see details in Section F.

###### Theorem C.6 ( DPTreeDistance data structure, informal version of Theorem F.6 ) .

There is a data structure DPTreeDistance (Algorithm 5 and 6) that uses $O(n)$ spaces to solve weighted $\ell_{1}$-distance query problem for dataset $X\subset[0,R]$
and support the following operations:

- •
Init$(X\subset[0,R],n\in\mathbb{N}_{+},w\in[-R_{w},R_{w}]^{n},\epsilon\in(0,1),
\delta\in(0,1))$. (Algorithm 5) It takes $O(n)$ time to initialize the data structure.
- •
DistanceQuery$(y\in[0,R],\alpha\in(0,1))$. (Algorithm 6)
It takes $O(\alpha^{-1}\log^{2}n)$ time to output a number $z$ such that
–
the process of output $z$ satisfies $(\epsilon,\delta)$-DP, which computes $\sum_{i\in[n]}w_{i}|y-x_{i}|$,
–
$|z-\sum_{i\in[n]}w_{i}|y-x_{i}||\leq\alpha\sum_{i\in[n]}w_{i}|y-x_{i}|+O(
\epsilon^{-1}\alpha^{-1/2}RR_{w}\log^{3/2}n)$,
–
it holds with probability $0.99$.

###### Theorem C.6 ( DPTreeDistance data structure, informal version of Theorem F.6 ) .

### C.5 Softmax Activation

We then describe how we extend the previous results to Softmax activation, i.e. exponential inner product function (Definition 4.1).
From AS [], we know that Softmax activation can be approximated by polynomial kernel function $P(\cdot)$ with a certain error.
The following lemma shows that we can transform weighted Softmax queries into polynomial kernels. More specifically, we have one term that computes the weighted $\ell_{2}^{2}$ distance, which is the place where we add DP noises. Because of the decomposability of the $\ell_{p}^{p}$ distance, i.e. $\sum_{i\in[n]}w_{i}\|x_{i}-y\|_{p}^{p}=\sum_{j\in[d]}\sum_{i\in[n]}w_{i}|x_{i,
j}-y_{j}|^{p}$, we can easily extend the results of Section C.4 to handle the $\ell_{2}^{2}$ distance query. After that, we compute the term for the weighted $\ell_{2}^{2}$ norms of approximation kernel exactly. Summing all these terms, with a certain error, we can answer the Softmax query. Related proofs can be found in Section I.

###### Lemma C.7 (Weighted Softmax approximation, informal version of Lemma I.6 ) .

Let the accuracy parameter be $\epsilon_{s}\in(0,0.1)$.
Let $R\geq 1$.
Let $r\leq{2s+2d\choose 2s}$ and $s=O(\max\{\frac{\log(1/\epsilon_{s})}{\log(\log(1/\epsilon_{s})/R)},R^{2}\})$.
Let $\Gamma_{R,s}:=\max_{j\in[s]}\frac{R^{j}}{\sqrt{j!}}$ (Definition I.3).
Let $P(x):[0,R]^{d}\to[0,\Gamma_{R,s}]^{r}$ be the $s$-th order polynomial kernel function defined in Lemma I.5.
Then, we can approximate the exponential inner product using the polynomial kernel function:

$$ $\displaystyle w^{\top}\exp(Xy/d)=$ $\displaystyle~{}-\frac{1}{2}\sum_{j\in[r]}\sum_{i\in[n]}w_{i}|P(x_{i})_{j}-P(y )_{j}|^{2}+\frac{1}{2}\sum_{i\in[n]}w_{i}(\|P(x_{i})\|^{2}_{2}+\|P(y)\|^{2}_{2})$ $\displaystyle+~{}O(w^{\top}\exp(Xy/d)\cdot\epsilon_{s}).$ $$

Moreover, the vectors $P(\cdot)$ can be computed in $O(r)$ time.

###### Lemma C.7 (Weighted Softmax approximation, informal version of Lemma I.6 ) .

### C.6 Adaptive Query

We introduce how we can modify our algorithm to solve the adaptive query problem using some tools in QRS^+ [].
Our approach is based on proving that our algorithm can handle any query within the query space with a certain error. Since adaptive queries must lie within this space, our algorithm can effectively handle them.
In Section C.5, we demonstrate our algorithm’s capability to answer weighted Softmax distance queries with constant probability. We then use the Chernoff bound to boost the constant probability of our algorithm to a high probability. Next, we apply the notion of an $\epsilon_{0}$-net to bound all query points within the net using the union bound. Finally, we bound all points in the query space by utilizing the Lipschitz property of the weighted Softmax distance function and introducing an additive error. See the proofs in Sections H and I.

###### Lemma C.8 (Adaptive Softmax, informal version of Lemma I.10 ) .

If the following conditions hold:

- •
Let $N$ be the $\ell_{\infty}$ $\epsilon_{0}$-net of ${\mathcal{B}}$, and let $|N|$ be the size of the net $N$.
- •
Let data set $X\in[0,R]^{n\times d}$, weights $w\in[-R_{w},R_{w}]^{n}$, query $y\in[0,R]^{d}$.
- •
Let the relative error parameter $\alpha\in(0,1)$, the failure probability $p_{f}\in(0,0.01)$.
- •
We create $l=O(\log((R/\epsilon_{0})^{r}/p_{f}))$ independent copies of the data structure $\{\textsc{DPTreeSoftmax}_{j}\}_{j=1}^{l}$ (Algorithm 3) and take the median of the outputs with each data structure instantiated with $(\epsilon/l,(\delta+\delta^{\prime})/l)$-DP.
- •
Let $f(y):=\mathrm{Median}(\{\textsc{DPTreeSoftmax}_{j}.\textsc{DistanceQuery}(y,
\alpha)\}_{j=1}^{l})$.
- •
Let $Z(y):=w^{\top}\exp(Xy/d)$.
- •
Let $B=O(\epsilon^{-1}\alpha^{-1/2}l\Gamma_{R,s}^{2}R_{w}r\sqrt{\log(l/\delta^{
\prime})}\cdot\log^{3/2}n)$.

Then with probability $1-p_{f}$, for all query points $q\in{\mathcal{B}}$, there exists a point $y\in N$ which is the closest to $q$, we can have the process of outputting median of $l$ responses is $(\epsilon,\delta+\delta^{\prime})$-DP and the error satisfies

$$ $\displaystyle|f(y)-Z(q)|\leq(\alpha+\epsilon_{s})Z(q)+B+2n\sqrt{d}RR_{w}\exp(R ^{2})\epsilon_{0}.$ $$

###### Lemma C.8 (Adaptive Softmax, informal version of Lemma I.10 ) .

## Appendix D DPTree Algorithm

In this section, we give the analysis of privacy, accuracy and runtime of our DPTree (Algorithm 2).
In Section D.1, we give the theorem (Theorem D.1) of our data structure that can answer summation problem.
In Section D.2, we improve our data structure from constant probability to high probability by applying Chernoff bound.
In Section D.3, we give the analysis.
In Section D.4, we show some results of our data structure if the input queries are disjoint.

### D.1 Single Data Structure

We give the theorem of our DPTree data structure that can answer the summation problem with DP, accuracy, runtime guarantee.

###### Theorem D.1 ( DPTree data structure, formal version of Theorem C.1 ) .

There is a data structure (see DPTree in Algorithm 2) that uses $O(n)$ spaces to support the following operations:

- •
Init$(a\in\mathbb{R}^{n},n\in\mathbb{N}_{+},\Delta\in\mathbb{N}_{+},\epsilon\in(0,1
),\delta\in(0,1))$. It takes $O(n)$ time to initialize the data structure.
- •
Query$(x\in[n],y\in[n])$. It takes $O(\log n)$ time to output a number $z$ such that
–
the process of output $z$ satisfies $(\epsilon,\delta)$-DP private, which computes $\sum_{i=x}^{y}a_{i}$,
–
$|z-\sum_{i=x}^{y}a_{i}|\leq O(\epsilon^{-1}\Delta\log^{3/2}n)$,
–
it holds with probability $0.99$.

###### Proof.

The proofs follow from combining Lemma D.3 (running time of initialization),
Lemma D.4 (running time of query), Lemma D.5 (DP of query), and Lemma D.6 (error of query) together.
∎

###### Theorem D.1 ( DPTree data structure, formal version of Theorem C.1 ) .

###### Proof.

### D.2 Boost the Constant Probability to High Probability

We can use Chernoff bound to boost the high probability by repeating the data structure multiple times.

###### Theorem D.2 (High-probability) .

There is a data structure (see DPTreeHighProb in Algorithm 4) that uses $O(n\log(1/\delta_{\mathrm{fail}}))$ spaces to support the following operations

- •
Init$(a\in\mathbb{R}^{n},n\in\mathbb{N}_{+},\Delta\in\mathbb{N}_{+},\epsilon\in(0,1
),\delta\in(0,1),\delta_{\mathrm{fail}}\in(0,0.01))$.
It takes $O(n\log(1/\delta_{\mathrm{fail}}))$ time to initialize the data structure.
- •
Query$(x\in[n],y\in[n])$. It takes $O(\log(n)\cdot\log(1/\delta_{\mathrm{fail}}))$ time to output a number $z$ such that
–
the process of output $z$ satisfies $(\epsilon,\delta)$-DP private, which computes $\sum_{i=x}^{y}a_{i}$,
–
$|z-\sum_{i=x}^{y}a_{i}|\leq O(\epsilon^{-1}\Delta\log^{3/2}(n)\cdot\log(1/
\delta_{\mathrm{fail}}))$,
–
it holds with probability $1-\delta_{\mathrm{fail}}$ for failure probability $\delta_{\mathrm{fail}}\in(0,0.01)$.

###### Proof.

Note that our data structure (Theorem D.1) succeeds with probability $0.99$.
The success of the algorithm (Theorem D.1) can be viewed as a Bernoulli random variable, to which we apply the Chernoff bound (Lemma B.2). By repeating the data structure $O(\log(1/\delta_{\mathrm{fail}}))$ times and taking the median of the outputs, we boost the success probability.
The details are following.

To boost the success probability, we assume the query is repeated $l$ times. Let $i\in[l]$, and let $z_{i}$ denote the indicator random variable for the success of the $i$-th instance of the data structure for a single query.
Let $z=\sum_{i=1}^{l}z_{i}$ be the total success times.
Since $p=\Pr[z_{i}=1]=0.99$, we can have $\mu=\operatorname*{{\mathbb{E}}}[z]=\sum_{i=1}^{l}p=lp$.
Note that $p=0.99$. By setting $\delta=0.1$ and using Chernoff bound from Lemma B.2, we can show

$$ $\displaystyle\Pr[z\leq l/2]\leq\Pr[z\leq(1-\delta)lp]\leq\exp(-\delta^{2}lp/2).$ $$

Note that we want $z>l/2$ (since we want at least half to succeed so we could take the median),

$$ $\displaystyle\Pr[z>l/2]\geq 1-\exp(-\delta^{2}lp/2).$ $$

To ensure that failure probability is $\delta_{\mathrm{fail}}$, we have

$$ $\displaystyle\exp(-\delta^{2}lp/2)=\delta_{\mathrm{fail}}.$ $$

We can make this hold by choosing $l=O(\log(1/\delta_{\mathrm{fail}}))$.

By the DP basic composition rule (Fact B.6), we need to choose $\epsilon=\epsilon^{\prime}/O(\log(1/\delta_{\mathrm{fail}}))$ and $\delta=\delta^{\prime}/O(\log(1/\delta_{\mathrm{fail}}))$ where $\epsilon^{\prime},\delta^{\prime}$ are the $\epsilon,\delta$ in Theorem D.1.
∎

Figure: Algorithm 4 Boost constant probability

###### Theorem D.2 (High-probability) .

###### Proof.

### D.3 Algorithm of Data Structure

In this section, we analyze the accuracy, DP, and runtime of Algorithm 2.

We first analyze the runtime.

###### Lemma D.3 (Runtime of initialization, Algorithm 2 ) .

For the initialization, we have the time complexity of Algorithm 2 is $O(n)$.

###### Proof.

All the computations are dominated by $O(n)$ time.
∎

###### Lemma D.4 (Runtime of query, Algorithm 2 ) .

For each query, we have the time complexity of Algorithm 2 is $O(\log n)$.

###### Proof.

Due to the property of tree, we will use at most $2\log n$ nodes in the tree, thus the running time is $O(\log n)$.
∎

We now analyze the DP.

###### Lemma D.5 (Privacy of query, Algorithm 2 ) .

The output process of Query (see Algorithm 2) is $(\epsilon,\delta)$-DP.

###### Proof.

Suppose that our dataset is $X\in[-R,R]^{n}$.
Note that we only add noise in the pre-processing stage. There is no noise in the query stage. Since the problem we care about is summation, if we change one leaf node, the sensitivity $\Delta=2R$ (see Lemma C.3). Since we add noise to each node in the tree, and each leaf node count will contribute to $\log n$ nodes, it is equivalent to our output function being in $\log n$ dimension. We will then blow up the DP parameter by $\log n$ factor. Thus, using the basic composition rule (Fact B.6), the DP guarantee for the whole tree data structure is $((\epsilon/\log n)\cdot\log n,(\delta/\log n)\cdot\log n)$ which is $(\epsilon,\delta)$-DP.
∎

We now analyze the accuracy.

###### Lemma D.6 (Accuracy of query, Algorithm 2 ) .

Let $\epsilon\in(0,1)$ and $\delta\in(0,1)$.
Then, using Chebyshev’s inequality and Fact 2.5, we have the error of Query(see Algorithm 2) output is upper bounded by:

$$ $\displaystyle O(\epsilon^{-1}\Delta\log^{3/2}n).$ $$

with probability $0.99$.

###### Proof.

For an interval $S$, we define $\textsc{TrueQuery}(S)$ to be the output of $\textsc{DPTree}.\textsc{TrueQuery}$ in Algorithm 2.
Let $\textsc{Query}(S)$ denote the noised interval query answer returned by DPTree.Query in Algorithm 2.
Let $z:=\textsc{Query}(S)-\textsc{TrueQuery}(S)$, which from Algorithm 2 we can see this is the sum of $O(\log n)$ independent truncated Laplace random variables each with parameter $\mathrm{TLap}(\Delta,\epsilon/\log n,\delta/\log n)$.
Thus,

$$ $\displaystyle z=\sum_{i=1}^{O(\log n)}z_{i}$ $$

where $z_{i}\sim\mathrm{TLap}(\Delta,\epsilon/\log n,\delta/\log n)$, and every $z_{i}$ are independent to each other.

We know $\mu=\operatorname*{{\mathbb{E}}}[z]=0$ since $\operatorname*{{\mathbb{E}}}[z_{i}]=0$.
From Fact 2.5, we know the variance for each $z_{i}$ is $\operatorname*{\mathrm{Var}}[z_{i}]=c\epsilon^{-2}\Delta^{2}\log^{2}n$ where $0<c\leq 2$ and $c=2$ when $\delta=0$.

Therefore, we can show

$$ $\displaystyle\operatorname*{\mathrm{Var}}[z]=$ $\displaystyle~{}\operatorname*{\mathrm{Var}}[\sum_{i=1}^{O(\log n)}z_{i}]$ $\displaystyle=$ $\displaystyle~{}\sum_{i=1}^{O(\log n)}\operatorname*{\mathrm{Var}}[z_{i}]$ $\displaystyle=$ $\displaystyle~{}O(c\epsilon^{-2}\Delta^{2}\log^{3}n)$ (4) $$

where the first step follows from definition of $z$, the second step follows from every $z_{i}$ are independent to each other, and the last step follows from $\operatorname*{\mathrm{Var}}[z_{i}]=O(c\epsilon^{-2}\Delta^{2}\log^{2}n)$.

Note that we wish to bound $|z|=|\textsc{Query}(S)-\textsc{TrueQuery}(S)|$ as our error.

Using Lemma B.3, we can have

$$ $\displaystyle\Pr[|z|\geq k\sigma]\leq\frac{1}{k^{2}}.$ $$

We know that $\sigma=\sqrt{\operatorname*{\mathrm{Var}}[z]}=O(c^{1/2}\epsilon^{-1}\Delta\log
^{3/2}n)$.
Picking $k=10$, we have

$$ $\displaystyle\Pr[|z|<10\sigma]\geq 0.99.$ $$

Thus, we conclude that error is bounded by $O(c^{1/2}\epsilon^{-1}\Delta\log^{3/2}n)=O(\epsilon^{-1}\Delta\log^{3/2}n)$ (since $c\in(0,2]$) with probability $0.99$.
∎

###### Lemma D.3 (Runtime of initialization, Algorithm 2 ) .

###### Proof.

###### Lemma D.4 (Runtime of query, Algorithm 2 ) .

###### Proof.

###### Lemma D.5 (Privacy of query, Algorithm 2 ) .

###### Proof.

###### Lemma D.6 (Accuracy of query, Algorithm 2 ) .

###### Proof.

### D.4 Disjoint Intervals

In this section, we show some interesting results for our DPTree data structure if the input queries are disjoint.

###### Lemma D.7 (Sum of disjoint interval queries) .

If the following conditions hold that:

- •
Let there be $t$ disjoint intervals, i.e., $S_{j}$ for $j\in[t]$, such that $S_{j}\cap S_{k}=\emptyset$ for all $j\neq k$.
- •
Let $\epsilon\in(0,1)$ and $\delta\in(0,1)$.

Then, we have Algorithm 2 is $(\epsilon,\delta)$-DP and outputs $\sum_{j=1}^{t}\textsc{Query}(S_{j})$ with the error upper bounded by

$$ $\displaystyle O(t^{1/2}\epsilon^{-1}\Delta\log^{3/2}n)$ $$

with probability $0.99$.

###### Proof.

From Lemma D.5, we know that $\mathrm{DPTree}$.Query is $(\epsilon,\delta)$-DP. Then, from Fact B.7 and the disjoint intervals in Algorithm 6, we can conclude that the value returned is $(\epsilon,\delta)$-DP.

Let $\textsc{TrueQuery}(S_{j})$ denote the true interval query answer returned by DPTree.TrueQuery in Algorithm 2 for interval $S_{j}$.
Let $\textsc{Query}(S_{j})$ denote the noised interval query answer returned by DPTree.Query in Algorithm 2 for interval $S_{j}$.
Let $z_{j}:=\textsc{Query}(S_{j})-\textsc{TrueQuery}(S_{j})$ and $z=\sum_{j=1}^{t}z_{j}$.
From the proof of Lemma D.6, we know $z_{j}$ is the sum of $O(\log n)$ independent truncated Laplace random variables each with parameter $\mathrm{TLap}(\Delta,\epsilon/\log n,\delta/\log n)$ and the variance is bounded by

$$ $\displaystyle\operatorname*{\mathrm{Var}}[z_{j}]=O(\epsilon^{-2}\Delta^{2}\log ^{3}n)$ $$

Since the intervals $S_{j}$ are disjoint, they are independent to each other.
Then, we have

$$ $\displaystyle\operatorname*{\mathrm{Var}}[z]=$ $\displaystyle~{}\operatorname*{\mathrm{Var}}[\sum_{j=1}^{t}z_{j}]$ $\displaystyle=$ $\displaystyle~{}\sum_{j=1}^{t}\operatorname*{\mathrm{Var}}[z_{j}]$ $\displaystyle=$ $\displaystyle~{}O(t\epsilon^{-2}\Delta^{2}\log^{3}n)$ $$

where the first step follows from definition of $z$, the second step follows from the intervals are disjoint, and the last step follows from $\operatorname*{\mathrm{Var}}[z_{j}]=O(\epsilon^{-2}\Delta^{2}\log^{2}n)$.

Note that we wish to bound $|z|$ as our error.

Using Lemma B.3, we can have error bounded by

$$ $\displaystyle O(t^{1/2}\epsilon^{-1}\Delta\log^{3/2}n)$ $$

with probability $0.99$.
∎

Moreover, this can be generalized to weighted sum of queries.

###### Lemma D.8 (Weighted sum of disjoint interval queries, formal version of Lemma C.2 ) .

If the following conditions hold that:

- •
Let there be $t$ disjoint intervals, i.e., $S_{j}$ for $j\in[t]$, such that $S_{j}\cap S_{k}=\emptyset$ for all $j\neq k$.
- •
Let $\epsilon\in(0,1)$ and $\delta\in(0,1)$.
- •
Let $a_{j}$ for $j\in[t]$ be a series that square converges to $a$, i.e., $\sum_{j=1}^{t}a_{j}^{2}\leq a$.

Then, we have Alg. 2 is $(\epsilon,\delta)$-DP and output $\sum_{j=1}^{t}a_{j}\textsc{Query}(S_{j})$ with the error upper bounded by

$$ $\displaystyle O(a^{1/2}\epsilon^{-1}\Delta\log^{3/2}n)$ $$

with probability $0.99$.

###### Proof.

The DP proof is the same as in the proof of Lemma D.7.

Let $\textsc{TrueQuery}(S_{j})$ and $\textsc{Query}(S_{j})$ be same in the proof of Lemma D.7
Let $z_{j}:=\textsc{Query}(S_{j})-\textsc{TrueQuery}(S_{j})$ and $z=\sum_{j=1}^{t}a_{j}z_{j}$.
From the proof of Lemma D.7, we know the variance of $z_{j}$ is bounded by

$$ $\displaystyle\operatorname*{\mathrm{Var}}[z_{j}]=O(\epsilon^{-2}\Delta^{2}\log ^{3}n)$ $$

Since the intervals $S_{j}$ are disjoint, they are independent to each other.
Then, we have

$$ $\displaystyle\operatorname*{\mathrm{Var}}[z]=$ $\displaystyle~{}\operatorname*{\mathrm{Var}}[\sum_{j=1}^{t}a_{j}z_{j}]$ $\displaystyle=$ $\displaystyle~{}\sum_{j=1}^{t}\operatorname*{\mathrm{Var}}[a_{j}z_{j}]$ $\displaystyle=$ $\displaystyle~{}\sum_{j=1}^{t}a_{j}^{2}\operatorname*{\mathrm{Var}}[z_{j}]$ $\displaystyle=$ $\displaystyle~{}\sum_{j=1}^{t}a_{j}^{2}\cdot O(\epsilon^{-2}\Delta^{2}\log^{3}n)$ $\displaystyle=$ $\displaystyle~{}O(a\epsilon^{-2}\Delta^{2}\log^{3}n)$ $$

where the first step follows from the definition of $z$, the second step follows from the intervals are disjoint, the third step follows from the $\operatorname*{\mathrm{Var}}[az]=a^{2}\operatorname*{\mathrm{Var}}[z]$ for a random variable $z$ and a constant $a$, the fourth step follows from the $\operatorname*{\mathrm{Var}}[z_{j}]=O(\epsilon^{-2}\Delta^{2}\log^{2}n)$, and the last step follows from $\sum_{j=1}^{t}a_{j}^{2}\leq a$.

Note that we wish to bound $|z|$ as our error.

Using Lemma B.3, we can have error bounded by

$$ $\displaystyle O(a^{1/2}\epsilon^{-1}\Delta\log^{3/2}n)$ $$

with probability $0.99$.
∎

###### Lemma D.7 (Sum of disjoint interval queries) .

###### Proof.

###### Lemma D.8 (Weighted sum of disjoint interval queries, formal version of Lemma C.2 ) .

###### Proof.

## Appendix E Weighted ℓ p p superscript subscript ℓ 𝑝 𝑝 \ell_{p}^{p} roman_ℓ start_POSTSUBSCRIPT italic_p end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_p end_POSTSUPERSCRIPT Distance

In this section, we introduce how to handle weighted $\ell_{p}^{p}$ distance problem in the high level idea.
In Section E.1, we show how to solve one dimensional weighted problem.
In Section E.2, we show how to solve high dimensional weighted problem by decomposing each coordinate of the high dimensional dataset.

Suppose we have the original data $X\in[0,R]^{n}$ and weight $w\in\mathbb{R}^{n}$ and query $y\in[0,R]$. We want to compute the weighted $\ell_{1}$-distance, i.e.

$$ $\displaystyle\sum_{i=1}^{n}w_{i}\cdot|y-x_{i}|.$ $$

For data in $d$-dimension, due to the decomposability of $\ell_{p}^{p}$ distance, our problem will be:
given $x_{i}\in[0,R]^{d}$ and $w_{i}\in\mathbb{R}$ for $i\in[n]$, and $y\in[0,R]^{d}$, we can compute

$$ $\displaystyle\sum_{i=1}^{n}w_{i}\cdot\|y-x_{i}\|_{p}^{p}=$ $\displaystyle~{}\sum_{j=1}^{d}\sum_{i=1}^{n}w_{i}\cdot|y_{j}-x_{i,j}|^{p}$ $$

where $x_{i,j},y_{j}$ means the $j$-th coordinates of $x_{i},y$ for $j\in[d]$.

Therefore, we can solve one dimension problem first, and then the high dimension case can be solved automatically.

### E.1 One Dimensional Weighted Distance

Now we can give the lemma for weighted distance of dataset.

###### Lemma E.1 (Weighted distance one dimension) .

If the following conditions hold:

- •
Let data $X\in[0,R]^{n}$, weight $w\in\mathbb{R}^{n}$, query $y\in[0,R]$.
- •
We round $X$ and $y$ to an integer multiple of $R/n$.
- •
Let $c_{j}=\sum_{j_{0}\in S_{j}}w_{j_{0}}$ where set $S_{j}$ is the set of index $i$ such that the corresponding $x_{i}$ is rounded to $jR/n$ for $j\in\{0,1,2,\dots,n\}$.
- •
After rounding, we assume $y$ is in the $kR/n$ position for $k\in\{0,1,2,\dots,n\}$.

For the weighted problem, we have

$$ $\displaystyle\sum_{i=1}^{n}w_{i}\cdot|y-x_{i}|=\sum_{j=0}^{n}(|k-j|R/n+O(R/n)) c_{j}.$ $$

Moreover, we have

$$ $\displaystyle\sum_{i=1}^{n}w_{i}\cdot|y-x_{i}|^{p}=\sum_{j=0}^{n}(|k-j|R/n+O(R /n))^{p}c_{j}$ $$

where $O(R/n)$ is the rounding error for each data point.

###### Proof.

For each $i$, we have:

$$ $\displaystyle w_{i}\cdot|y-x_{i}|=w_{i}\cdot(\frac{|k-j|R}{n}+O(\frac{R}{n})).$ $$

where $O(R/n)$ is the rounding error introduced by each data point, since each data point will be at most $O(R/n)$ away from its true position.

We can construct $c_{j}$ by

$$ $\displaystyle c_{j}=\sum_{j_{0}\in S_{j}}w_{j_{0}}$ $$

set $S_{j}$ is the set of index $i$ such that the corresponding $x_{i}$ is rounded to $jR/n$.
Moreover, $c_{j}$ can be negative.

Summing over all $i$ and grouping by $j$, we get:

$$ $\displaystyle\sum_{i=1}^{n}w_{i}\cdot|y-x_{i}|=\sum_{j=0}^{n}(\frac{|k-j|R}{n} +O(\frac{R}{n}))c_{j}.$ $$

The total rounding error will be $O(R)$ because we have $n$ data points, each with an error of at most $O(R/n)$.

Moreover, we have

$$ $\displaystyle\sum_{i=1}^{n}w_{i}\cdot|y-x_{i}|^{p}=\sum_{j=0}^{n}(\frac{|k-j|R }{n}+O(\frac{R}{n}))^{p}c_{j}.$ $$

∎

###### Lemma E.1 (Weighted distance one dimension) .

###### Proof.

### E.2 High Dimensional Weighted Distance

Finally, we can solve the problem of weighted distance for $d$-dimensional dataset.

###### Lemma E.2 (Weighted $\ell_{p}^{p}$ -distance high dimension, formal version of Lemma C.4 ) .

If the following conditions hold:

- •
Let data $X\in[0,R]^{n\times d}$ and $x_{i}^{\top}\in[0,R]^{d}$ be the $i$-th row of $x$, weight $w\in\mathbb{R}^{n}$, query $y\in[0,R]^{d}$.
- •
We round each dimension of $X$ and $y$ to an integer multiple of $R/n$.
- •
Let $x_{i,k},y_{k}$ denote the $k$-th coordinates of $x_{i},y$ for $k\in[d]$.
- •
Let $c_{j,k}:=\sum_{j_{0}\in S_{j,k}}w_{j_{0}}$ where set $S_{j,k}$ is the set of index $i$ such that the corresponding $x_{i,k}$ is rounded to $jR/n$ for $j\in\{0,1,2,\dots,n\}$ for $k\in[d]$.
- •
After rounding, we assume $y_{k}$ is in the $l_{k}R/n$ position for $l_{k}\in\{0,1,2,\dots,n\}$ for $k\in[d]$.

For the weighted problem, we have

$$ $\displaystyle\sum_{i=1}^{n}w_{i}\cdot\|y-x_{i}\|_{p}^{p}=\sum_{k=1}^{d}\sum_{j =0}^{n}(|l_{k}-j|R/n+O(R/n))^{p}c_{j,k}$ $$

where $O(R/n)$ is the rounding error for each data point.

###### Proof.

We can show

$$ $\displaystyle\sum_{i=1}^{n}w_{i}\cdot\|y-x_{i}\|_{p}^{p}=$ $\displaystyle~{}\sum_{k=1}^{d}\sum_{i=1}^{n}w_{i}\cdot|y_{k}-x_{i,k}|^{p}$ $\displaystyle=$ $\displaystyle~{}\sum_{k=1}^{d}\sum_{j=0}^{n}(|l_{k}-j|R/n+O(R/n))^{p}c_{j,k}$ $$

where the first step follows from decomposability of $\ell_{p}^{p}$-distance by dimension, the second step follows from Lemma E.1.

∎

###### Lemma E.2 (Weighted ℓ p p superscript subscript ℓ 𝑝 𝑝 \ell_{p}^{p} roman_ℓ start_POSTSUBSCRIPT italic_p end_POSTSUBSCRIPT start_POSTSUPERSCRIPT italic_p end_POSTSUPERSCRIPT -distance high dimension, formal version of Lemma C.4 ) .

###### Proof.

## Appendix F One-Dimensional Weighted ℓ 1 subscript ℓ 1 \ell_{1} roman_ℓ start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT Distance Query

In this section, we generalize the algorithms in BLM^+ [] to weighted distance.
Here, we compute the problem of one-dimensional weighted $\ell_{1}$ distance query i.e. $\sum_{i\in[n]}w_{i}|y-x_{i}|$ for a given query $y\in[0,R]$, weights $w\in[-R_{w},R_{w}]^{n}$ and dataset $X\subset[0,R]$ and $n=|X|$.
In Section F.1, we analyze the runtime of our algorithm.
In Section F.2, we analyze the DP and accuracy of our algorithm.
In Section F.3, we give the theorem for our DPTreeDistance data structure.

Figure: Algorithm 5 Pre-processing data structure

Figure: Algorithm 6 One dimensional weighted $\ell_{1}$ distance query

### F.1 Runtime Analysis

We first analyze the runtime.

###### Lemma F.1 (Runtime of initialization, Algorithm 5 ) .

For the initialization, we have the time complexity of Init in Algorithm 5 is $O(n)$.

###### Proof.

In the initialization of Init, the computations need $O(n)$ time to compute the count and $O(\log n)$ time to build the tree. Thus, total time is $O(n)$.
∎

###### Lemma F.2 (Runtime of DistanceQuery , Algorithm 6 ) .

For the $\ell_{1}$ distance query, we have the time complexity of DistanceQuery in Algorithm 6 is $O(\alpha^{-1}\log^{2}n)$.

###### Proof.

In DistanceQuery, the computations need $O(\log n)$ time to compute one value from DPTree.Query and this process need to be repeated $O(\alpha^{-1}\log n)$ times.
∎

###### Remark F.3 .

In Line 8 and 13 of Algorithm 6, we use $R/(1+\alpha)^{j}$ to approximate the distance of each data point to the query in Lemma E.1, i.e. $|k-j|R/n$.
This will introduce $\alpha$ relative error but also reduce the numbers of iteration from $O(n)$ to $O(\log(n)/\alpha)$.

###### Lemma F.1 (Runtime of initialization, Algorithm 5 ) .

###### Proof.

###### Lemma F.2 (Runtime of DistanceQuery , Algorithm 6 ) .

###### Proof.

###### Remark F.3 .

### F.2 Privacy and Accuracy Analysis

We show the DP.

###### Lemma F.4 (Privacy of DistanceQuery , Algorithm 6 ) .

The output process of DistanceQuery (Algorithm 6) is $(\epsilon,\delta)$-DP.

###### Proof.

From Lemma D.5, we know that $\mathrm{DPTree}$.Query is $(\epsilon,\delta)$-DP output.
We observe that intervals in Algorithm 6 are disjoint.
Then, following the same logic in the proof of Lemma D.8, we can conclude that the value returned is $(\epsilon,\delta)$-DP.
∎

We now analyze the accuracy of the algorithm.

###### Lemma F.5 (Accuracy of DistanceQuery , Algorithm 6 ) .

If the following conditions are satisfied:

- •
Let $X\in[0,R]^{n}$ be a dataset consisting of $n$ one-dimensional numbers, with weights $w\in[-R_{w},R_{w}]^{n}$.
- •
Let $\alpha\in(0,1)$ represent the relative error parameter utilized in Algorithm 6.
- •
Let $\widetilde{A}$ denote the output of the DistanceQuery in Algorithm 6.
- •
Let $A_{*}:=\sum_{i\in[n]}w_{i}|y-x_{i}|$ represent the true distance query value for a specific query $y$.

Then with probability $0.99$, we have

$$ $\displaystyle|\widetilde{A}-A_{*}|\leq\alpha A_{*}+O(\epsilon^{-1}\alpha^{-1/2 }RR_{w}\log^{3/2}n).$ $$

###### Proof.

To simplify the explanation, we consider only the distance query for the points in $X$ located to the right of $y$. The proof can be symmetrically applied to the case of points to the left of $y$.
For an interval $S_{j}:=(l_{j},r_{j})$ where $l_{j},r_{j}$ are defined in Algorithm 6, we define $\textsc{TrueQuery}(S_{j})$ to be the output of $\textsc{DPTree}.\textsc{TrueQuery}$ in Algorithm 2.
Let

$$ $\displaystyle\widehat{A}:=$ $\displaystyle~{}\sum_{j=0}^{O(\log(n)/\alpha)}\frac{R}{(1+\alpha)^{j}}\cdot \textsc{TrueQuery}(S_{j}).$ $$

Since TrueQuery returns the sum of the corresponding weights, it aligns with the true answer $A_{*}:=\sum_{i\in[n]}w_{i}|y-x_{i}|$.
Thus, we have

$$ $\displaystyle|\widehat{A}-A_{*}|\leq\alpha\cdot A_{*},$ $$

because for all $j$, the distances between $y$ and different points in $X$ vary only by a multiplicative factor of $(1+\alpha)$.

Next we show the additive error.
Let $\textsc{Query}(S_{j})$ denote the noised interval query answer returned by DPTree.Query in Algorithm 2. Algorithm 6 outputs
$\widetilde{A}=\sum_{j=0}^{O(\log(n)/\alpha)}\frac{R}{(1+\alpha)^{j}}\cdot
\textsc{Query}(S_{j})$. We wish to bound

$$ $\displaystyle|\widehat{A}-\widetilde{A}|\leq$ $\displaystyle~{}|\sum_{j=0}^{O(\log(n)/\alpha)}\frac{R}{(1+\alpha)^{j}}\cdot( \textsc{TrueQuery}(S_{j})-\textsc{Query}(S_{j}))|.$ $$

Let $z_{j}:=\textsc{Query}(S_{j})-\textsc{TrueQuery}(S_{j})$, which from Algorithm 2 we can see this is the sum of $O(\log n)$ independent truncated Laplace random variables.

From Lemma D.8, we only need to show that the series $\frac{1}{(1+\alpha)^{j}}$ for $j\in\{0,1,\dots,O(\log(n)/\alpha)\}$ square converges to $1/\alpha$, since $R$ is a constant.

We can show

$$ $\displaystyle\sum_{j=0}^{O(\log(n)/\alpha)}\frac{1}{(1+\alpha)^{2j}}\leq$ $\displaystyle~{}\sum_{j=0}^{\infty}\frac{1}{(1+\alpha)^{2j}}$ $\displaystyle\leq$ $\displaystyle~{}\sum_{j=0}^{\infty}\frac{1}{(1+\alpha)^{j}}$ $\displaystyle=$ $\displaystyle~{}\frac{1}{1-\frac{1}{1+\alpha}}$ $\displaystyle=$ $\displaystyle~{}1+\frac{1}{\alpha}$ $\displaystyle=$ $\displaystyle~{}O(1/\alpha)$ $$

where the first step follows from we extend the finite sum to infinite sum, the second step follows from $\frac{1}{(1+\alpha)^{2j}}\leq\frac{1}{(1+\alpha)^{j}}$, the third step follows from the closed form of geometric sum, the fourth step follows from simple algebra, and the last step follows from $\alpha\in(0,1)$.

Then from the proof of Lemma D.8, we can know that the variance is given by

$$ $\displaystyle O(\frac{R^{2}R_{w}^{2}\log^{3}n}{\alpha\epsilon^{2}})$ (5) $$

since the sensitivity $\Delta=2R_{w}$ from Lemma C.3.

Using Lemma B.3, we can have additive error bounded by

$$ $\displaystyle O(\frac{R\cdot R_{w}\log^{3/2}n}{\epsilon\sqrt{\alpha}}).$ $$

with probability $0.99$.
∎

###### Lemma F.4 (Privacy of DistanceQuery , Algorithm 6 ) .

###### Proof.

###### Lemma F.5 (Accuracy of DistanceQuery , Algorithm 6 ) .

###### Proof.

### F.3 One Dimension Single Data Structure

We therefore have the data structure that can solve weighted $\ell_{1}$-distance problem.

###### Theorem F.6 ( DPTreeDistance data structure, formal version of Theorem C.6 ) .

There is a data structure DPTreeDistance (Algorithm 5,6) that uses $O(n)$ spaces to solve weighted $\ell_{1}$-distance query problem for dataset $X\subset[0,R]$
and support the following operations:

- •
Init$(X\subset[0,R],n\in\mathbb{N}_{+},w\in[-R_{w},R_{w}]^{n},\epsilon\in(0,1),
\delta\in(0,1))$. (Algorithm 5) It takes $O(n)$ time to initialize the data structure.
- •
DistanceQuery$(y\in[0,R],\alpha\in(0,1))$. (Algorithm 6)
It takes $O(\alpha^{-1}\log^{2}n)$ time to output a number $z$ such that
–
the process of output $z$ satisfies $(\epsilon,\delta)$-DP private, which computes $\sum_{i\in[n]}w_{i}|y-x_{i}|$,
–
$|z-\sum_{i\in[n]}w_{i}|y-x_{i}||\leq\alpha\sum_{i\in[n]}w_{i}|y-x_{i}|+O(
\epsilon^{-1}\alpha^{-1/2}RR_{w}\log^{3/2}n)$,
–
it holds with probability $0.99$.

###### Proof.

The proofs follow from combining Lemma F.1 (running time of initialization), Lemma F.2 (running time of query), Lemma F.4 (DP of query), and Lemma F.5 (error of query) together.
∎

###### Theorem F.6 ( DPTreeDistance data structure, formal version of Theorem C.6 ) .

###### Proof.

## Appendix G High-Dimensional Weighted ℓ 1 subscript ℓ 1 \ell_{1} roman_ℓ start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT Query

In this section, we show how we can solve the high dimensional weighted $\ell_{1}$ distance problem, generalizing results from BLM^+ [].
In Section G.1, we give the analysis of Algorithm 7.
In Section G.2, we give the theorem of our DPTreeHighDim data structure.

Algorithm 5,6 can be naturally extended to higher dimensions because of the decomposability of the $\ell_{1}$ distance function.
We construct $d$ separate one-dimensional distance query data structures, each corresponding to a coordinate projection of the dataset.

### G.1 Privacy and Accuracy Analysis for High Dimensional Weighted Distance

We now give the analysis of our Algorithm 7 for high dimensional weighted $\ell_{1}$-distance query.

Figure: Algorithm 7 High-dimensional weighted $\ell_{1}$ distance query

###### Lemma G.1 (Privacy of DistanceQuery , Algorithm 7 ) .

If the following conditions hold

- •
Let data set $X\in[0,R]^{n\times d}$, weights $w\in[-R_{w},R_{w}]^{n}$, query $y\in[0,R]^{d}$.
- •
Let $\epsilon\in(0,1)$, $\delta\in(0,1)$, $\delta^{\prime}\in(0,1)$.
- •
Let $c\in(0,0.1)$ be a small constant and $A$ be the output of DistanceQuery in Algorithm 7, where each one-dimensional algorithm is configured to be $(c\epsilon/\sqrt{d\log(1/\delta^{\prime})},\delta/d)$-DP (see Line 11).
- •
Let $A_{*}=\sum_{i\in[n]}w_{i}\|y-x_{i}\|_{1}$ represent the true distance query value.
- •
Let $\epsilon=O(\log(1/\delta^{\prime}))$.

Then, we have the output process of DistanceQuery (Algorithm 7) is $(\epsilon,\delta+\delta^{\prime})$-DP.

###### Proof.

The $(\epsilon,\delta+\delta^{\prime})$-DP guarantee follows from the approximate DP advanced composition result Theorem B.8.
Our algorithm instantiate each one-dimensional data structure with $(c\epsilon/\sqrt{d\log(1/\delta^{\prime})},\delta/d)$-DP total $d$ times.

From advanced composition in Theorem B.8, for a sufficient small parameter $\epsilon$ and constant $c$, we have the final privacy loss parameter be:

$$ $\displaystyle O(c\epsilon\sqrt{2d\log(1/\delta^{\prime})}/\sqrt{d\log(1/\delta ^{\prime})})=O(\epsilon)$ $$

and the final failure probability parameter be:

$$ $\displaystyle d\delta/d+\delta^{\prime}=\delta+\delta^{\prime}.$ $$

∎

###### Lemma G.2 (Accuracy of DistanceQuery , Algorithm 7 ) .

If the following conditions hold

- •
Let data set $X\in[0,R]^{n\times d}$, weights $w\in[-R_{w},R_{w}]^{n}$, query $y\in[0,R]^{d}$.
- •
Let $\epsilon\in(0,1)$, $\delta\in(0,1)$, $\delta^{\prime}\in(0,1)$.
- •
Let $c\in(0,0.1)$ be a small constant and $A$ be the output of DistanceQuery in Algorithm 7, where each one-dimensional algorithm is configured to be $(c\epsilon/\sqrt{d\log(1/\delta^{\prime})},\delta/d)$-DP (see Line 11).
- •
Let $A_{*}=\sum_{i\in[n]}w_{i}\|y-x_{i}\|_{1}$ represent the true distance query value.

With probability $0.99$, we have

$$ $\displaystyle|A-A_{*}|\leq\alpha A_{*}+O(\epsilon^{-1}\alpha^{-1/2}RR_{w}d \sqrt{\log(1/\delta^{\prime})}\cdot\log^{3/2}n).$ $$

###### Proof.

Let $A_{i}$ be the $i$-th dimension output returned by $\mathcal{D}_{i}$ in Algorithm 7.
Let $A_{*,i}$ be the true distance query value in the $i$-th dimension.
Observe that $A_{*}=\sum_{i=1}^{d}A_{*,i}$ and $A=\sum_{i=1}^{d}A_{i}$.

We follow the similar idea in the proof of Lemma F.5.
Let $z_{j,i}$ be the random variables that represent $z_{j}$ (used in the proof of Lemma F.5) for the $i$-th coordinate.
We can observe that the overall error across $d$ coordinates can be upper bounded by

$$ $\displaystyle|\sum_{i=1}^{d}\sum_{j=0}^{O(\log(n)/\alpha)}\frac{Rz_{j,i}}{(1+ \alpha)^{j}}|$ $$

where each $z_{j,i}$ is the sum of $O(\log n)$ truncated Laplace random variables independent to others.
With $\epsilon$ scaled down by $c\epsilon/\sqrt{d\log(1/\delta^{\prime})}$ and $\delta$ scaled down by $\delta/d$, the variance of each individual dimension is given by (see Eq. (5))

$$ $\displaystyle O(\alpha^{-1}\epsilon^{-2}dR^{2}R_{w}^{2}\log(1/\delta^{\prime}) \log^{3}n).$ $$

Thus, the total variance for $d$ instantiated data structures is then

$$ $\displaystyle O(\alpha^{-1}\epsilon^{-2}d^{2}R^{2}R_{w}^{2}\log(1/\delta^{ \prime})\log^{3}n).$ $$

Finally, from Lemma B.3, we have the additive error given by

$$ $\displaystyle O(\alpha^{-1/2}\epsilon^{-1}dRR_{w}\sqrt{\log(1/\delta^{\prime}) }\cdot\log^{3/2}n).$ $$

∎

###### Lemma G.1 (Privacy of DistanceQuery , Algorithm 7 ) .

###### Proof.

###### Lemma G.2 (Accuracy of DistanceQuery , Algorithm 7 ) .

###### Proof.

### G.2 High Dimension Single Data Structure

We have the data structure that can solve weighted $\ell_{1}$-distance problem in $d$-dimensional data.

###### Theorem G.3 ( DPTreeHighDim data structure) .

There is a data structure DPTreeHighDim (Algorithm 7) that uses $O(nd)$ spaces to solve weighted $\ell_{1}$-distance query problem for dataset $X\subset[0,R]^{d}$ and support the following operations:

- •
Init$(X\subset[0,R]^{d},n\in\mathbb{N}_{+},w\in[-R_{w},R_{w}]^{n},\epsilon\in(0,1),
\delta\in(0,1),\delta^{\prime}\in(0,1),c\in(0,0.1))$. (Algorithm 7) It takes $O(nd)$ time to initialize the data structure.
- •
DistanceQuery$(y\in[0,R]^{d},\alpha\in(0,1))$. (Algorithm 7)
It takes $O(\alpha^{-1}d\log^{2}n)$ time to output a number $z$ such that
–
the process of output $z$ satisfies is $(\epsilon,\delta+\delta^{\prime})$-DP private, which computes $\sum_{i\in[n]}w_{i}\|y-x_{i}\|_{1}$,
–
$|z-\sum_{i\in[n]}w_{i}\|y-x_{i}\|_{1}|\leq\alpha\sum_{i\in[n]}w_{i}\|y-x_{i}\|
_{1}+O(\epsilon^{-1}\alpha^{-1/2}RR_{w}d\sqrt{\log(1/\delta^{\prime})}\cdot
\log^{3/2}n)$,
–
it holds with probability $0.99$.

###### Proof.

For the runtime analysis, since we loop data structure DPTreeDistance $d$ times, an additional $d$ factor will appear for both initialization and query time complexity.
The DP is proved by Lemma G.1.
The accuracy is proved by Lemma G.2.
∎

###### Theorem G.3 ( DPTreeHighDim data structure) .

###### Proof.

## Appendix H Adaptive Query

In this section, we introduce how we can solve the adaptive query problem by our algorithm, using some tools from QRS^+ [].
Our idea is that, if we can prove that our algorithm can solve any query in the query space with certain error. Then, since adaptive query must lie in this space, we can handle adaptive query.
In Section H.1, we show how we can boost the constant probability of our algorithm to high probability.
In Section H.2, we show how we can apply the notion of $\epsilon_{0}$-net and bound all query points in net.
In Section H.3, we show how we can bound all points in the query space by introducing an additive error.
In Section H.4, we examine the effects of different norms on our adaptive query proof.

First, from Theorem G.3, given query $y\in[0,R]^{d},\alpha\in(0,1)$ we have DistanceQuery$(y,\alpha)$ that can solve $d$-dimension weighted $\ell_{1}$-distance problem with constant probability $0.99$. Now we show how to improve it to solve adaptive query problem.

### H.1 Boost the Constant Probability to High Probability

We can repeat the data structure multiple times and take the median to boost the constant probability using Chernoff bound from Lemma B.2.

###### Lemma H.1 (Using Chernoff bound to boost the probability) .

If the following conditions hold:

- •
Let data set $X\in[0,R]^{n\times d}$, weights $w\in[-R_{w},R_{w}]^{n}$, query $y\in[0,R]^{d}$.
- •
Let relative error parameter $\alpha\in(0,1)$, the failure probability $p_{f}\in(0,0.01)$.
- •
We create $l=O(\log(1/p_{f}))$ independent copies of data structure DPTreeHighDim and take the median of the outputs with each data structure instantiated with $(\epsilon/l,(\delta+\delta^{\prime})/l)$-DP.
- •
Let $A_{*}=\sum_{i\in[n]}w_{i}\|y-x_{i}\|_{1}$ be the true answer.
- •
Let $B=O(\epsilon^{-1}\alpha^{-1/2}lRR_{w}d\sqrt{\log(l/\delta^{\prime})}\cdot\log^
{3/2}n)$.

Then for each fixed query point $y$, we can have the process of outputting the median of $l$ responses is $(\epsilon,\delta+\delta^{\prime})$-DP and the error is upper bounded by $\alpha A_{*}+B$ with probability $1-p_{f}$.

###### Proof.

By basic composition Fact B.6, we prove the DP. Similar to the proof of Theorem D.2, we prove the error by Chernoff bound (Lemma B.2).
∎

###### Lemma H.1 (Using Chernoff bound to boost the probability) .

###### Proof.

### H.2 From Each Fixed Query Point to All On-net Points

In this section, we build $\epsilon_{0}$-net and generalize from each fixed query point to all on-net points.

###### Definition H.2 ( $\ell_{p}$ $\epsilon_{0}$ -net, see Definition 4.2.1 in Ver [ 96 ] ) .

We define $N$ be $\ell_{p}$ $\epsilon_{0}$-net of ${\mathcal{B}}:=\{q\in[0,R]^{d}\}$ such that, for every point $q$ in ${\mathcal{B}}$, there exists $y\in N$ satisfying $\|y-q\|_{p}\leq\epsilon_{0}$.

###### Fact H.3 ( $\ell_{\infty}$ $\epsilon_{0}$ -net) .

Let $N$ be the $\ell_{\infty}$ $\epsilon_{0}$-net of ${\mathcal{B}}$, and $|N|$ be the size of net $N$. We have $|N|\leq(5R/\epsilon_{0})^{d}$.

###### Fact H.4 ( $\ell_{2}$ $\epsilon_{0}$ -net, see Lemma 5 in Woo [ 102 ] ) .

Let $N$ be the $\ell_{2}$ $\epsilon_{0}$-net of ${\mathcal{B}}$, and $|N|$ be the size of net $N$. We have $|N|\leq(5R/\epsilon_{0})^{d}$.

###### Fact H.5 ( $\ell_{1}$ $\epsilon_{0}$ -net, see Theorem 2 in GS [ 41 ] ) .

Let $N$ be the $\ell_{1}$ $\epsilon_{0}$-net of ${\mathcal{B}}$, and $|N|$ be the size of net $N$. We have $|N|\leq(5R\sqrt{d}/\epsilon_{0})^{d}$.

###### Lemma H.6 (From for each query point to for all points in net) .

If the following conditions hold:

- •
Let $N$ be the $\ell_{\infty}$ $\epsilon_{0}$-net of ${\mathcal{B}}$, and $|N|$ be the size of net $N$.
- •
Let data set $X\in[0,R]^{n\times d}$, weights $w\in[-R_{w},R_{w}]^{n}$, query $y\in[0,R]^{d}$.
- •
Let relative error parameter $\alpha\in(0,1)$, the failure probability $p_{f}\in(0,0.01)$.
- •
We create $l=O(\log(|N|/p_{f}))$ independent copies of data structure DPTreeHighDim and take the median of the outputs with each data structure instantiated with $(\epsilon/l,(\delta+\delta^{\prime})/l)$-DP.
- •
Let $A_{*}=\sum_{i\in[n]}w_{i}\|y-x_{i}\|_{1}$ be the true answer.
- •
Let $B=O(\epsilon^{-1}\alpha^{-1/2}lRR_{w}d\sqrt{\log(l/\delta^{\prime})}\cdot\log^
{3/2}n)$.

Then with probability $1-p_{f}$, for all query points $y\in N$, we can have the process of outputting the median of $l$ responses is $(\epsilon,\delta+\delta^{\prime})$-DP and the error is upper bounded by $\alpha A_{*}+B$.

###### Proof.

By basic composition Fact B.6, we prove the DP. From Lemma H.1, we know for each $y\in N$, the error is upper bounded by $\alpha A_{*}+B$ with probability $1-p_{f}/|N|$.

Then, by union bound, with probability $1-p_{f}$, the error of all $|N|$ query points in the net $y\in N$ is upper bounded by $\alpha A_{*}+B$.
∎

###### Definition H.2 ( ℓ p subscript ℓ 𝑝 \ell_{p} roman_ℓ start_POSTSUBSCRIPT italic_p end_POSTSUBSCRIPT ϵ 0 subscript italic-ϵ 0 \epsilon_{0} italic_ϵ start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT -net, see Definition 4.2.1 in Ver [ 96 ] ) .

###### Fact H.3 ( ℓ ∞ subscript ℓ \ell_{\infty} roman_ℓ start_POSTSUBSCRIPT ∞ end_POSTSUBSCRIPT ϵ 0 subscript italic-ϵ 0 \epsilon_{0} italic_ϵ start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT -net) .

###### Fact H.4 ( ℓ 2 subscript ℓ 2 \ell_{2} roman_ℓ start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT ϵ 0 subscript italic-ϵ 0 \epsilon_{0} italic_ϵ start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT -net, see Lemma 5 in Woo [ 102 ] ) .

###### Fact H.5 ( ℓ 1 subscript ℓ 1 \ell_{1} roman_ℓ start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ϵ 0 subscript italic-ϵ 0 \epsilon_{0} italic_ϵ start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT -net, see Theorem 2 in GS [ 41 ] ) .

###### Lemma H.6 (From for each query point to for all points in net) .

###### Proof.

### H.3 From Net Points to All Points

In this section, we show how to generalize points from net to all points in the query space. Since adaptive query must lie in this space, we complete the proof of adaptive query.

###### Lemma H.7 (Lipschitz of query function) .

If the following conditions hold:

- •
Let data set $X\in[0,R]^{n\times d}$, weights $w\in[-R_{w},R_{w}]^{n}$, query $y\in[0,R]^{d}$.
- •
Let $Z(y):=\sum_{i\in[n]}w_{i}\|y-x_{i}\|_{1}$.
- •
Let $L=nR_{w}$.

Then, we have $Z(y)$ is $L$-Lipschitz (note that we have $\ell_{1}$ Lipschitz here).

###### Proof.

We can show

$$ $\displaystyle|Z(y)-Z(\widetilde{y})|=$ $\displaystyle~{}|\sum_{i\in[n]}w_{i}\|y-x_{i}\|_{1}-\sum_{i\in[n]}w_{i}\| \widetilde{y}-x_{i}\|_{1}|$ $\displaystyle\leq$ $\displaystyle~{}\sum_{i\in[n]}|w_{i}|\cdot|\|y-x_{i}\|_{1}-\|\widetilde{y}-x_{ i}\|_{1}|$ $\displaystyle\leq$ $\displaystyle~{}\sum_{i\in[n]}|w_{i}|\cdot\|y-\widetilde{y}\|_{1}$ $\displaystyle=$ $\displaystyle~{}nR_{w}\cdot\|y-\widetilde{y}\|_{1}$ $$

where the first step follows from definition of $Z(y)$, the second step follows from triangular inequality, the third step follows from reverse triangular inequality, the fourth step follows from $w\in[-R_{w},R_{w}]^{n}$.
∎

###### Lemma H.8 (From points in net to all points in query space) .

If the following conditions hold:

- •
Let $N$ be the $\ell_{\infty}$ $\epsilon_{0}$-net of ${\mathcal{B}}$, and $|N|$ be the size of net $N$.
- •
Let data set $X\in[0,R]^{n\times d}$, weights $w\in[-R_{w},R_{w}]^{n}$, query $y\in[0,R]^{d}$.
- •
Let relative error parameter $\alpha\in(0,1)$, the failure probability $p_{f}\in(0,0.01)$.
- •
We create $l=O(\log((R/\epsilon_{0})^{d}/p_{f}))$ independent copies of data structure $\{\textsc{DPTreeHighDim}_{j}\}_{j=1}^{l}$ and take the median of the outputs with each data structure instantiated with $(\epsilon/l,(\delta+\delta^{\prime})/l)$-DP.
- •
Let $f(y):=\mathrm{Median}(\{\textsc{DPTreeHighDim}_{j}.\textsc{DistanceQuery}(y,
\alpha)\}_{j=1}^{l})$.
- •
Let $Z(y):=\sum_{i\in[n]}w_{i}\|y-x_{i}\|_{1}$, where $Z(y)$ is $L$-Lipschitz with $L=nR_{w}$.
- •
Let $B=O(\epsilon^{-1}\alpha^{-1/2}lRR_{w}d\sqrt{\log(l/\delta^{\prime})}\cdot\log^
{3/2}n)$.

Then with probability $1-p_{f}$, for all query points $q\in{\mathcal{B}}$, there exists a point $y\in N$ which is the closest to $q$, we can have the process of outputting the median of $l$ responses is $(\epsilon,\delta+\delta^{\prime})$-DP and the error satisfy

$$ $\displaystyle|f(y)-Z(q)|\leq\alpha Z(q)+B+2Ld\epsilon_{0}.$ $$

###### Proof.

By basic composition Fact B.6, we prove the DP.

We define an event $E$ such that:

$$ $\displaystyle~{}\forall y\in N$ $\displaystyle~{}|f(y)-Z(y)|\leq\alpha Z(y)+B.$ $$

From Lemma H.1, with $l=O(\log(|N|/p_{f}))$ we know

$$ $\displaystyle\Pr[\mathrm{event}~{}E~{}\mathrm{holds}]\geq 1-p_{f}$ $$

We can show

$$ $\displaystyle l=$ $\displaystyle~{}O(\log(|N|/p_{f})$ $\displaystyle=$ $\displaystyle~{}O(\log((R/\epsilon_{0})^{d}/p_{f})$ $$

where the first step follows from definition of $l$, the second step follows from Fact H.3.

We condition on event $E$ to be held. Then, by definition of $\ell_{\infty}$ $\epsilon_{0}$-net (see Definition H.2), for each $q\notin N$, there exists $y\in N$ such that

$$ $\displaystyle\|y-q\|_{\infty}\leq\epsilon_{0}$ (6) $$

We know

$$ $\displaystyle|Z(y)-Z(q)|\leq$ $\displaystyle~{}L\cdot\|y-q\|_{1}$ $\displaystyle\leq$ $\displaystyle~{}L\cdot d\|y-q\|_{\infty}$ $\displaystyle\leq$ $\displaystyle~{}L\cdot d\epsilon_{0}$ (7) $$

where the first step follows from Lemma H.7, the second step follows from $\|x\|_{1}\leq d\|x\|_{\infty}$ for $x\in\mathbb{R}^{d}$, and the last step follows from Eq. (6).

Using the on-net query $y$ to answer the off-net query $q$, for any $q\notin N$, we have

$$ $\displaystyle|f(y)-Z(q)|\leq$ $\displaystyle~{}|f(y)-Z(y)|+|Z(q)-Z(y)|$ $\displaystyle\leq$ $\displaystyle~{}|f(y)-Z(y)|+L\cdot d\cdot\epsilon_{0}$ $\displaystyle\leq$ $\displaystyle~{}\alpha Z(y)+B+L\cdot d\cdot\epsilon_{0}$ $\displaystyle\leq$ $\displaystyle~{}\alpha Z(q)+B+2L\cdot d\cdot\epsilon_{0}$ (8) $$

where the first step follows from triangular inequality, the second step follows from Eq. (H.3), the third step follows from Lemma H.6, and the last step follows from Eq. (H.3).

Thus, we complete the proof.
∎

Therefore, even adaptive queries can be answered
accurately, since any adaptive query can be assumed in ${\mathcal{B}}$.

###### Lemma H.7 (Lipschitz of query function) .

###### Proof.

###### Lemma H.8 (From points in net to all points in query space) .

###### Proof.

### H.4 Effect of Different Norms on the Result

In the above proof, we have two different measure spaces, i.e. $\ell_{\infty}$ distance of $\epsilon_{0}$-net (Definition H.2) and $\ell_{1}$ Lipschitz (Lemma H.7).

One might ask, will the norm we choose in two spaces have an impact on the final result?
We can show that the norm we choose currently is sufficient to use.

For different norms, the only differences in the proofs will be Lipschitz smoothness in Eq. (H.3) and the cardinality of $\epsilon_{0}$-net, i.e. $|N|$ in Fact H.3.

###### Lemma H.9 .

If we use $\ell_{\infty}$ $\epsilon_{0}$-net and use $\ell_{1}$ Lipschitz in Lemma H.8, we have copies of data structure $l=O(d\log(nR/p_{f}))$.

###### Proof.

If we use $\ell_{\infty}$ to bound the distance to net, Eq. (H.3) is:

$$ $\displaystyle|Z(y)-Z(q)|\leq$ $\displaystyle~{}nR_{w}\cdot\|y-q\|_{1}$ $\displaystyle\leq$ $\displaystyle~{}nR_{w}\cdot d\|y-q\|_{\infty}$ $\displaystyle\leq$ $\displaystyle~{}nR_{w}\cdot d\epsilon_{0}$ $$

where the first step follows from Lemma H.7, the second step follows from $\|x\|_{1}\leq d\|x\|_{\infty}$ for $x\in\mathbb{R}^{d}$, and the last step follows from $\ell_{\infty}$ $\epsilon_{0}$-net.

Then, Eq. (H.3) is

$$ $\displaystyle|f(y)-Z(q)|\leq$ $\displaystyle~{}\alpha Z(q)+B+2nR_{w}\cdot d\cdot\epsilon_{0}$ $$

For $\ell_{\infty}$ distance, we have $|N|\leq(5R/\epsilon_{0})^{d}$ in Fact H.3.

We can choose $\epsilon_{0}=\Theta(1/n)$ to hide $nR_{w}\cdot d\cdot\epsilon_{0}$ term in $B$ in Lemma H.8.
Thus,

$$ $\displaystyle l=$ $\displaystyle~{}O(\log(|N|/p_{f})$ $\displaystyle=$ $\displaystyle~{}O(\log((R/\epsilon_{0})^{d}/p_{f})$ $\displaystyle=$ $\displaystyle~{}O(\log((nR)^{d}/p_{f}))$ $\displaystyle=$ $\displaystyle~{}O(d\log(nR/p_{f}))$ $$

where the last step follows from $\log(a^{d}/b)=O(d\log(a/b))$ for any $a>1,0<b<1,d>1$.
∎

###### Lemma H.10 .

If we use $\ell_{2}$ $\epsilon_{0}$-net and use $\ell_{1}$ Lipschitz in Lemma H.8, we have copies of data structure $l=O(d\log(nR/p_{f}))$.

###### Proof.

If we use $\ell_{2}$ to bound the distance to net, Eq. (H.3) changes to be:

$$ $\displaystyle|Z(y)-Z(q)|\leq$ $\displaystyle~{}nR_{w}\cdot\|y-q\|_{1}$ $\displaystyle\leq$ $\displaystyle~{}nR_{w}\cdot\sqrt{d}\cdot\|y-q\|_{2}$ $\displaystyle\leq$ $\displaystyle~{}nR_{w}\cdot\epsilon_{0}\sqrt{d}$ $$

where the first step follows from Lemma H.7, the second step follows from $\|x\|_{1}\leq\sqrt{d}\cdot\|x\|_{2}$ for $x\in\mathbb{R}^{d}$, and the last step follows from $\ell_{2}$ $\epsilon_{0}$-net.

Then, Eq. (H.3) changes to be

$$ $\displaystyle|f(y)-Z(q)|\leq$ $\displaystyle~{}\alpha Z(q)+B+2nR_{w}\cdot\epsilon_{0}\sqrt{d}$ $$

For $\ell_{2}$ distance, we also have $|N|\leq(5R/\epsilon_{0})^{d}$ in Fact H.4.

We can choose $\epsilon_{0}=\Theta(1/n)$ to hide $nR_{w}\cdot\sqrt{d}\cdot\epsilon_{0}$ term in $B$ in Lemma H.8.
Thus,

$$ $\displaystyle l=$ $\displaystyle~{}O(\log(|N|/p_{f})$ $\displaystyle=$ $\displaystyle~{}O(\log((R/\epsilon_{0})^{d}/p_{f})$ $\displaystyle=$ $\displaystyle~{}O(\log((nR)^{d}/p_{f}))$ $\displaystyle=$ $\displaystyle~{}O(d\log(nR/p_{f}))$ $$

where the last step follows from $\log(a^{d}/b)=O(d\log(a/b))$ for any $a>1,0<b<1,d>1$.
∎

###### Lemma H.11 .

If we use $\ell_{1}$ $\epsilon_{0}$-net and use $\ell_{1}$ Lipschitz in Lemma H.8, we have copies of data structure $l=O(d\log(ndR/p_{f}))$.

###### Proof.

If we use $\ell_{1}$ to bound the distance to net, Eq. (H.3) changes to be:

$$ $\displaystyle|Z(y)-Z(q)|\leq$ $\displaystyle~{}nR_{w}\cdot\|y-q\|_{1}$ $\displaystyle\leq$ $\displaystyle~{}nR_{w}\cdot\epsilon_{0}$ $$

where the first step follows from Lemma H.7, and the last step follows from $\ell_{1}$ $\epsilon_{0}$-net.

Then, Eq. (H.3) changes to be

$$ $\displaystyle|f(y)-Z(q)|\leq$ $\displaystyle~{}\alpha Z(q)+B+2nR_{w}\cdot\epsilon_{0}$ $$

For $\ell_{1}$ distance, we have $|N|\leq(5R\sqrt{d}/\epsilon_{0})^{d}$.

We can choose $\epsilon_{0}=\Theta(1/n)$ to hide $nR_{w}\cdot\epsilon_{0}$ term in $B$ in Lemma H.8.
Thus,

$$ $\displaystyle l=$ $\displaystyle~{}O(\log(|N|/p_{f})$ $\displaystyle=$ $\displaystyle~{}O(\log((R\sqrt{d}/\epsilon_{0})^{d}/p_{f})$ $\displaystyle=$ $\displaystyle~{}O(\log((nR\sqrt{d})^{d}/p_{f}))$ $\displaystyle=$ $\displaystyle~{}O(d\log(nRd/p_{f}))$ $$

where the last step follows from $\log(a^{d}/b)=O(d\log(a/b))$ for any $a>1,0<b<1,d>1$.
∎

From the above analysis, we can show that $\ell_{\infty}$ or $\ell_{2}$ $\epsilon_{0}$-net is slightly better than $\ell_{1}$ $\epsilon_{0}$-net.

- •
$\ell_{\infty}$ $\epsilon_{0}$-net, Lemma H.9: we have $l=O(d\log(nR/p_{f}))$.
- •
$\ell_{2}$ $\epsilon_{0}$-net, Lemma H.10: we have $l=O(d\log(nR/p_{f}))$.
- •
$\ell_{1}$ $\epsilon_{0}$-net, Lemma H.11: we have $l=O(d\log(nRd/p_{f}))$.

Thus, the norm we choose for $\epsilon_{0}$-net is sufficient good.

###### Lemma H.9 .

###### Proof.

###### Lemma H.10 .

###### Proof.

###### Lemma H.11 .

###### Proof.

## Appendix I Softmax Activation

In this section, we introduce how we extend previous $\ell_{1}$ distance results to the Softmax activation function, which is the most widely used distance measure in attention mechanism based models.

In Section I.1, we show how to extend to the Softmax distance function in Lemma I.6.
In Section I.2, we show how to adjust our algorithms.
In Section I.3, we extend our algorithm to be robust to adaptive query.
In Section I.4, we give the proof of our main result Theorem 3.1.

### I.1 Exponential Inner Product

In this section, we show how we obtain the Softmax distance using $\ell_{2}^{2}$ distance query.
First, we provide some helpful results from AS [].

###### Definition I.1 (Definition 3.1 in AS [ 6 ] ) .

Let $r\geq 1$ denote a positive integer. Let $\epsilon\in(0,0.1)$ denote an accuracy parameter.
Given a matrix $A\in\mathbb{R}^{n\times n}_{\geq 0}$, we say $\widetilde{A}\in\mathbb{R}^{n\times n}_{\geq 0}$ is an $(\epsilon,r)$-approximation of $A$ if

- •
$\widetilde{A}=U_{1}\cdot U_{2}^{\top}$ for some matrices $U_{1},U_{2}\in\mathbb{R}^{n\times r}$ (i.e., $\widetilde{A}$ has rank at most $r$), and
- •
$|\widetilde{A}_{i,j}-A_{i,j}|\leq\epsilon\cdot A_{i,j}$ for all $(i,j)\in[n]^{2}$.

###### Lemma I.2 (Lemma 3.4 in AS [ 6 ] ) .

Suppose $Q,K\in\mathbb{R}^{n\times d}$, with $\|Q\|_{\infty}\leq R$, and $\|K\|_{\infty}\leq R$. Let $A:=\exp(QK^{\top}/d)\in\mathbb{R}^{n\times n}$. For accuracy parameter $\epsilon\in(0,0.1)$, there is a positive integer $s$ bounded above by

$$ $\displaystyle s=O\Big{(}\max\Big{\{}\frac{\log(1/\epsilon)}{\log(\log(1/ \epsilon)/R)},R^{2}\Big{\}}\Big{)},$ (9) $$

and a positive integer $r$ bounded above by

$$ $\displaystyle r\leq{2s+2d\choose 2s}$ (10) $$

such that:
There is a matrix $\widetilde{A}\in\mathbb{R}^{n\times n}$ that is an $(\epsilon,r)$-approximation (Definition I.1) of $A\in\mathbb{R}^{n\times n}$.
Furthermore, the matrices $U_{1}$ and $U_{2}$ defining $\widetilde{A}$ can be computed in $O(n\cdot r)$ time.

Here we consider the vector version of Lemma I.2.

###### Definition I.3 .

We define $\Gamma_{R,s}:=\max_{j\in[s]}\frac{R^{j}}{\sqrt{j!}}$.

Then, we have $P(x):[0,R]^{d}\to[0,\Gamma_{R,s}]^{r}$ where $P(\cdot)$ is polynomial kernel function defined in AS [].

###### Remark I.4 .

We use $\Gamma_{R,s}$ to denote the value range of our polynomial kernel methods function, i.e., $P(x):[0,R]^{d}\to[0,\Gamma_{R,s}]^{r}$. The factorial term in $\Gamma_{R,s}$ comes from Taylor approximation coefficients.
We take the maximum overall $s$ order approximation terms to get the upper bound of our value range.

We use the polynomial approximation method, which has been applied to accelerate Transformer model extensively [, , , , ].

###### Lemma I.5 (Polynomial approximation) .

For any accuracy parameter $\epsilon_{s}\in(0,0.1)$, let $R\geq 1$, and let $P(x):[0,R]^{d}\to[0,\Gamma_{R,s}]^{r}$ be the $s$-th order polynomial kernel function defined in AS [] where $r\leq{2s+2d\choose 2s}$ and $s=O(\max\{\frac{\log(1/\epsilon_{s})}{\log(\log(1/\epsilon_{s})/R)},R^{2}\})$.
Then, for any $x,y\in[0,R]^{d}$, we have

$$ $\displaystyle|P(x)^{\top}P(y)-\exp(x^{\top}y/d)|\leq\epsilon_{s}\cdot\min\{ \exp(x^{\top}y/d),P(x)^{\top}P(y)\}$ $$

Furthermore, the vectors $P(x)$ and $P(y)$ can be computed in $O(r)$ time.

###### Proof.

Let $n=1$. The proof follows from directly applying Lemma I.2.
∎

Using the results from AS [] above, we can extend our results to Softmax activation.

###### Lemma I.6 (Weighted Softmax approximation, formal version of Lemma C.7 ) .

Let accuracy parameter be $\epsilon_{s}\in(0,0.1)$.
Let $R\geq 1$.
Let $r\leq{2s+2d\choose 2s}$ and $s=O(\max\{\frac{\log(1/\epsilon_{s})}{\log(\log(1/\epsilon_{s})/R)},R^{2}\})$.
Let $P(x):[0,R]^{d}\to[0,\Gamma_{R,s}]^{r}$ be the $s$-th order polynomial kernel function defined in Lemma I.5.
Then we can approximate exponential inner product using polynomial kernel function:

$$ $\displaystyle w^{\top}\exp(Xy/d)=$ $\displaystyle~{}-\frac{1}{2}\sum_{j\in[r]}\sum_{i\in[n]}w_{i}|P(x_{i})_{j}-P(y )_{j}|^{2}+\frac{1}{2}\sum_{i\in[n]}w_{i}(\|P(x_{i})\|^{2}_{2}+\|P(y)\|^{2}_{2})$ $\displaystyle+~{}O(w^{\top}\exp(Xy/d)\cdot\epsilon_{s})$ $$

Moreover, the vectors $P(\cdot)$ can be computed in $O(r)$ time.

###### Proof.

From Lemma I.5, we can use polynomial kernel to approximate the Softmax function:

$$ $\displaystyle w^{\top}\exp(Xy/d)=$ $\displaystyle~{}\sum_{i\in[n]}w_{i}P(x_{i})^{\top}P(y)+O(w^{\top}\exp(Xy/d) \cdot\epsilon_{s}).$ $$

The proof of approximation error and time complexity of constructing $P(\cdot)$ follows from Lemma I.5.

Then, we can show

$$ $\displaystyle 2\sum_{i\in[n]}w_{i}P(x_{i})^{\top}P(y)=$ $\displaystyle~{}-\sum_{i\in[n]}w_{i}\|P(x_{i})-P(y)\|_{2}^{2}+\sum_{i\in[n]}w_ {i}(\|P(x_{i})\|^{2}_{2}+\|P(y)\|^{2}_{2})$ $\displaystyle=$ $\displaystyle~{}-\sum_{j\in[r]}\sum_{i\in[n]}w_{i}|P(x_{i})_{j}-P(y)_{j}|^{2}+ \sum_{i\in[n]}w_{i}(\|P(x_{i})\|^{2}_{2}+\|P(y)\|^{2}_{2})$ $$

where the first step follows from $\|x-y\|_{2}^{2}=\|x\|_{2}^{2}+\|y\|_{2}^{2}-2\langle x,y\rangle$, and the second step follows $\|x\|_{2}^{2}=\sum_{j=1}^{d}|x_{j}|^{2}$ for $x\in\mathbb{R}^{d}$.
∎

###### Definition I.1 (Definition 3.1 in AS [ 6 ] ) .

###### Lemma I.2 (Lemma 3.4 in AS [ 6 ] ) .

###### Definition I.3 .

###### Remark I.4 .

###### Lemma I.5 (Polynomial approximation) .

###### Proof.

###### Lemma I.6 (Weighted Softmax approximation, formal version of Lemma C.7 ) .

###### Proof.

### I.2 Algorithm Modifications

Based on Lemma I.6, we can now extend our DP algorithms to handle Softmax activation. First, we need to construct $P(y)$ and $P(x_{i})$ for $i\in[n]$, each costing $O(r)$ time.
Then, for the second term in Lemma I.6, i.e. $\frac{1}{2}\sum_{i\in[n]}w_{i}(\|P(x_{i})\|^{2}_{2}+\|P(y)\|^{2}_{2})$, we don’t need to add DP noises in it; instead, we calculate this term exactly, preprocess it, and store the results in the algorithm.
For the first term, $-\frac{1}{2}\sum_{j\in[r]}\sum_{i\in[n]}w_{i}|P(x_{i})_{j}-P(y)_{j}|^{2}$, we can adjust our high dimensional DP distance query algorithm to solve it.

Due to the decomposability of $\ell_{p}^{p}$ norm, i.e.

$$ $\displaystyle\sum_{i\in[n]}w_{i}\|x_{i}-y\|_{p}^{p}=\sum_{j\in[d]}\sum_{i\in[n ]}w_{i}|x_{i,j}-y_{j}|^{p},$ $$

we can compute $\ell_{2}^{2}$ norm easily (see details in Lemma E.2).
We then show how to extend our one dimensional $\ell_{1}$ distance algorithm (Algorithm 5 and 6) to $\ell_{2}^{2}$ distance with minor modifications.

###### Theorem I.7 ( DPTreeDistance $\ell_{2}^{2}$ distance) .

With $\alpha$ scaled down by a factor of $2$ and all Query instead multiplied by $R^{2}/(1+\alpha/2)^{2j}$ in Lines 8 and 13 of Algorithm 6, i.e., from

- •
Lines 8 and 13: Value $\leftarrow$ Value + ${\mathcal{D}}$.Query($l_{j},r_{j}$) $\cdot\frac{R}{(1+\alpha)^{j}}$

to

- •
Lines 8 and 13: Value $\leftarrow$ Value + ${\mathcal{D}}$.Query($l_{j},r_{j}$) $\cdot\frac{R^{2}}{(1+\alpha/2)^{2j}}$.

The data structure DPTreeDistance (Algorithm 5,6) uses $O(n)$ spaces to solve weighted $\ell_{2}^{2}$-distance query problem for dataset $X\subset[0,R]$ and support the following operations:

- •
Init$(X\subset[0,R],n\in\mathbb{N}_{+},w\in[-R_{w},R_{w}]^{n},\epsilon\in(0,1),
\delta\in(0,1))$. (Algorithm 5) It takes $O(n)$ time to initialize the data structure.
- •
DistanceQuery$(y\in[0,R],\alpha\in(0,1))$. (Algorithm 6)
It takes $O(\alpha^{-1}\log^{2}n)$ time to output a number $z$ such that
–
the process of output $z$ satisfies $(\epsilon,\delta)$-DP private, which computes $\sum_{i\in[n]}w_{i}|y-x_{i}|^{2}$,
–
$|z-\sum_{i\in[n]}w_{i}|y-x_{i}|^{2}|\leq\alpha\sum_{i\in[n]}w_{i}|y-x_{i}|^{2}
+O(\epsilon^{-1}\alpha^{-1/2}R^{2}R_{w}\log^{3/2}n)$,
–
it holds with probability $0.99$.

###### Proof.

The proof is similar to that of Theorem F.6, except that now our additive error includes $R$ increased by a power of $2$, i.e., from $O(\epsilon^{-1}\alpha^{-1/2}RR_{w}\log^{3/2}n)$ to $O(\epsilon^{-1}\alpha^{-1/2}R^{2}R_{w}\log^{3/2}n)$.
∎

Now we can give our result that can answer Softmax query.

###### Theorem I.8 (Softmax query, formal version of Theorem 4.2 ) .

Let $R\geq 1$.
Let $r\leq{2s+2d\choose 2s}$ and $s=O(\max\{\frac{\log(1/\epsilon_{s})}{\log(\log(1/\epsilon_{s})/R)},R^{2}\})$.
Let $\Gamma_{R,s}$ be defined in Definition I.3.
Let accuracy parameter be $\epsilon_{s}\in(0,0.1)$.
There is a data structure DPTreeSoftmax (Algorithm 3) that uses $O(nr)$ spaces to solve Softmax query problem for dataset $X\subset[0,R]^{d}$ and support the following operations:

- •
Init$(X\subset[0,R]^{d},n\in\mathbb{N}_{+},w\in[-R_{w},R_{w}]^{n},\epsilon\in(0,1),
\delta\in(0,1),\delta^{\prime}\in(0,1),c\in(0,0.1),\epsilon_{s}\in(0,0.1))$. (Algorithm 3)
It takes $O(nr)$ time to initialize the data structure.
- •
DistanceQuery$(y\in[0,R]^{d},\alpha\in(0,1))$. (Algorithm 3)
It takes $O(\alpha^{-1}r\log^{2}n)$ time to output a number $z$ such that
–
the process of output $z$ satisfies $(\epsilon,\delta+\delta^{\prime})$-DP private, which computes $w^{\top}\exp(Xy/d)$,
–
$|z-w^{\top}\exp(Xy/d)|\leq(\alpha+\epsilon_{s})\cdot w^{\top}\exp(Xy/d)$
$~{}~{}~{}~{}~{}~{}~{}~{}+~{}O(\epsilon^{-1}\alpha^{-1/2}\Gamma_{R,s}^{2}R_{w}r
\sqrt{\log(1/\delta^{\prime})}\cdot\log^{3/2}n)$,
–
it holds with probability $0.99$.

###### Proof.

The DP proof is the same as the proof of Lemma G.1.

We then show the time complexity. From Lemma I.6, we know that constructing $P(\cdot)$ requires $O(r)$ time.
In the first for loop of Init, the dominating time consumption is $O(nr)$. The second for loop also has a time complexity of $O(nr)$. Therefore, the total time complexity for Init is $O(nr)$.
In the DistanceQuery function, constructing $P(y)$ takes $O(r)$ time. Within the for loop, it requires $O(\alpha^{-1}r\log^{2}n)$. Thus, the total time complexity for DistanceQuery is $O(\alpha^{-1}r\log^{2}n)$.

The space complexity is $O(nr)$, since storing the $n\times r$ matrix $P$ is the dominating factor.

The proof of the error follows from the triangle inequality by combining the errors in Lemma I.6 and Theorem I.7.
∎

###### Theorem I.7 ( DPTreeDistance ℓ 2 2 superscript subscript ℓ 2 2 \ell_{2}^{2} roman_ℓ start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT distance) .

###### Proof.

###### Theorem I.8 (Softmax query, formal version of Theorem 4.2 ) .

###### Proof.

### I.3 Adaptive Softmax

In this section, we show how to make Algorithm 3 robust to adaptive query.
We follow the same idea from Section H.
We notice that, in the Softmax activation, we have query function $Z(y):=w^{\top}\exp(Xy/d)$ different from the $\ell_{1}$-distance in Section H.
Therefore, we need to recalculate Lipschitz constant first.

###### Lemma I.9 (Lipschitz of weighted Softmax) .

If the following conditions hold:

- •
Let data set $X\in[0,R]^{n\times d}$, weights $w\in[-R_{w},R_{w}]^{n}$, query $y\in[0,R]^{d}$.
- •
Let $Z(y):=w^{\top}\exp(Xy/d)$.
- •
Let $L=nd^{-1/2}RR_{w}\exp(R^{2})$.

Then, we have $Z(y)$ is $L$-Lipschitz (note that we have $\ell_{1}$ Lipschitz here).

###### Proof.

We can show

$$ $\displaystyle|Z(y)-Z(\widetilde{y})|=$ $\displaystyle~{}|\sum_{i\in[n]}w_{i}\exp(x_{i}^{\top}y/d)-\sum_{i\in[n]}w_{i} \exp(x_{i}^{\top}\widetilde{y}/d)|$ $\displaystyle\leq$ $\displaystyle~{}\sum_{i\in[n]}|w_{i}|\cdot|\exp(x_{i}^{\top}y/d)-\exp(x_{i}^{ \top}\widetilde{y}/d)|$ $\displaystyle\leq$ $\displaystyle~{}\sum_{i\in[n]}|w_{i}|\exp(R^{2})|x_{i}^{\top}y/d-x_{i}^{\top} \widetilde{y}/d|$ $\displaystyle\leq$ $\displaystyle~{}\sum_{i\in[n]}|w_{i}|\exp(R^{2})\|x_{i}\|_{2}\cdot\|y- \widetilde{y}\|_{2}/d$ $\displaystyle\leq$ $\displaystyle~{}nR_{w}\exp(R^{2})\sqrt{d}R\cdot\|y-\widetilde{y}\|_{2}/d$ $\displaystyle\leq$ $\displaystyle~{}nd^{-1/2}RR_{w}\exp(R^{2})\|y-\widetilde{y}\|_{1}$ $$

where the first step follows from definition of $Z(y),Z(\widetilde{y})$, the second step follows from triangular inequality, the third step follows from Fact B.4, the fourth step follows from Cauchy–Schwarz inequality $|u^{\top}v|\leq\|u\|_{2}\cdot\|v\|_{2}$ for $u,v\in\mathbb{R}^{d}$, the fifth step follows from $w_{i}\in[-R_{w},R_{w}]$ and $x_{i}\in[0,R]^{d}$, and the last step follows from $\|u\|_{2}\leq\|u\|_{1}$ for $u\in\mathbb{R}^{d}$.
∎

Then we can show how to extend our algorithm to be robust to adaptive query.

###### Lemma I.10 (Adaptive Softmax, formal version of Lemma C.8 ) .

If the following conditions hold:

- •
Let $N$ be the $\ell_{\infty}$ $\epsilon_{0}$-net of ${\mathcal{B}}$, and $|N|$ be the size of net $N$.
- •
Let data set $X\in[0,R]^{n\times d}$, weights $w\in[-R_{w},R_{w}]^{n}$, query $y\in[0,R]^{d}$.
- •
Let relative error parameter $\alpha\in(0,1)$, the failure probability $p_{f}\in(0,0.01)$.
- •
We create $l=O(\log((R/\epsilon_{0})^{r}/p_{f}))$ independent copies of data structure $\{\textsc{DPTreeSoftmax}_{j}\}_{j=1}^{l}$ (Algorithm 3) and take the median of the outputs with each data structure instantiated with $(\epsilon/l,(\delta+\delta^{\prime})/l)$-DP.
- •
Let $f(y):=\mathrm{Median}(\{\textsc{DPTreeSoftmax}_{j}.\textsc{DistanceQuery}(y,
\alpha)\}_{j=1}^{l})$.
- •
Let $Z(y):=w^{\top}\exp(Xy/d)$, where $Z(y)$ is $L$-Lipschitz with $L=nd^{-1/2}RR_{w}\exp(R^{2})$.
- •
Let $B=O(\epsilon^{-1}\alpha^{-1/2}l\Gamma_{R,s}^{2}R_{w}r\sqrt{\log(l/\delta^{
\prime})}\cdot\log^{3/2}n)$.

Then with probability $1-p_{f}$, for all query points $q\in{\mathcal{B}}$, there exists a point $y\in N$ which is the closest to $q$, we can have the process of outputting the median of $l$ responses is $(\epsilon,\delta+\delta^{\prime})$-DP and the error satisfies

$$ $\displaystyle|f(y)-Z(q)|\leq(\alpha+\epsilon_{s})Z(q)+B+2n\sqrt{d}RR_{w}\exp(R ^{2})\epsilon_{0}.$ $$

###### Proof.

The proof follows from the same idea as the proof of Lemma H.8, except that we use Theorem I.8 and the Lipschitz in Lemma I.9.
∎

###### Theorem I.11 (Adaptive query Softmax data structure, formal version of Theorem 4.4 ) .

Let $R\geq 1$.
Let $r\leq{2s+2d\choose 2s}$ and $s=O(\max\{\frac{\log(1/\epsilon_{s})}{\log(\log(1/\epsilon_{s})/R)},R^{2}\})$.
Let $\Gamma_{R,s}$ be defined in Definition I.3.
Let accuracy parameter be $\epsilon_{s}\in(0,0.1)$.
Let $X\in[0,R]^{n\times d}$ be the dataset, $w\in[-R_{w},R_{w}]^{n}$ be weights, $y\in[0,R]^{d}$ be the query, $\alpha\in(0,1)$ be the relative error parameter, and $p_{f}$ be the failure probability parameter.
Let $l=O(r\log(dR/(\epsilon_{s}p_{f})))$.
There is a data structure DPTreeSoftmaxAdaptive (Algorithm 1) that uses $O(lnr)$ spaces to solve weighted Softmax query problem for dataset $X\subset[0,R]^{d}$ and support the following operations:

- •
Init$(X\subset[0,R]^{d},n\in\mathbb{N}_{+},w\in[-R_{w},R_{w}]^{n},\epsilon\in(0,1),
\delta\in(0,1),\delta^{\prime}\in(0,1),c\in(0,0.1),\epsilon_{s}\in(0,0.1),p_{f
}\in(0,0.01))$. (Algorithm 1) It takes $O(lnd)$ time to initialize the data structure.
- •
DistanceQuery$(y\in[0,R]^{d},\alpha\in(0,1))$. (Algorithm 1)
It takes $O(\alpha^{-1}ld\log^{2}n)$ time to output a number $z$ such that
–
the process of output $z$ satisfies $(\epsilon,\delta+\delta^{\prime})$-DP private, which computes $w^{\top}\exp(Xy/d)$,
–
$|z-w^{\top}\exp(Xy/d)|\leq(\alpha+\epsilon_{s})\cdot w^{\top}\exp(Xy/d)$
$~{}~{}~{}~{}~{}~{}~{}~{}+~{}O(\epsilon^{-1}\alpha^{-1/2}l\Gamma_{R,s}^{2}R_{w}
r\sqrt{\log(l/\delta^{\prime})}\cdot\log^{3/2}n)$,
–
it holds with probability $1-p_{f}$ (where $p_{f}$ is used in $l$),
–
it is robust to adaptive query.

###### Proof.

We only need to show how to pick $\epsilon_{0}$ in the parameter $l$, because everything else is the same as Lemma I.10.
We know the additive error introduced by adaptive query is $E_{a}:=O(n\sqrt{d}RR_{w}\exp(R^{2})\epsilon_{0})$ and the relative error introduced by polynomial kernel approximation is $E_{p}:=w^{\top}\exp(Xy/d)\cdot\epsilon_{s}$.
It can be shown that:

$$ $\displaystyle E_{p}:=$ $\displaystyle~{}w^{\top}\exp(Xy/d)\cdot\epsilon_{s}$ $\displaystyle\leq$ $\displaystyle~{}\epsilon_{s}\|w\|_{2}\cdot\|\exp(Xy/d)\|_{2}$ $\displaystyle=$ $\displaystyle~{}O(nR_{w}\epsilon_{s}\exp(R^{2}))$ $$

where the first step follows from definition of $E_{p}$, the second step follows from Cauchy–Schwarz inequality, and the last step follows from $w\in[-R_{w},R_{w}]^{n}$, $X\in[0,R]^{n\times d}$, and $y\in[0,R]^{d}$.

Picking $\epsilon_{0}=\Theta(\frac{\epsilon_{s}}{\sqrt{d}R})$, we can hide the error of adaptive query $E_{a}$ in $E_{p}$.
Thus, we have

$$ $\displaystyle l=$ $\displaystyle~{}O(\log((R/\epsilon_{0})^{r}/p_{f}))$ $\displaystyle=$ $\displaystyle~{}O(\log((\sqrt{d}R^{2}/\epsilon_{s})^{r}/p_{f}))$ $\displaystyle=$ $\displaystyle~{}O(r\log(dR/(\epsilon_{s}p_{f})))$ $$

where the first step comes from the definition of $l$, the second step comes from picking $\epsilon_{0}=\Theta(\frac{\epsilon_{s}}{\sqrt{d}R})$, and the last step follows from $\log(a^{d}/b)=O(d\log(a/b))$ for any $a>1,0<b<1,d>1$.
∎

###### Lemma I.9 (Lipschitz of weighted Softmax) .

###### Proof.

###### Lemma I.10 (Adaptive Softmax, formal version of Lemma C.8 ) .

###### Proof.

###### Theorem I.11 (Adaptive query Softmax data structure, formal version of Theorem 4.4 ) .

###### Proof.

### I.4 Proof of Main Result

In this section, we give the proof of our main result of Theorem 3.1.

###### Theorem I.12 (Softmax cross-attention, formal version of Theorem 3.1 ) .

Let $Q,K,V,\mathrm{Attn}$ be defined in Definition 1.1.
Let $\alpha\in(0,1)$ be the relative error parameter and $p_{f}$ be the probability of failure parameter.
Let $r,s,\epsilon_{s}$ be parameters of polynomial kernel methods (Lemma C.7).
Let $\Gamma_{R,s}:=\max_{j\in[s]}\frac{R^{j}}{\sqrt{j!}}$ (Definition I.3).
Let $l=O(r\log(dR/(\epsilon_{s}p_{f})))$.
There is a data structure DPTreeSoftmaxAdaptive (Algorithm 1) that uses $O(lnrd)$ spaces to make cross-attention DP and supports the following operations:

- •
We initialize $d$ data structures using Init$(K,n,V_{*,k},\epsilon\in(0,1),\delta\in(0,1),\delta^{\prime}\in(0,1),c\in(0,0.
1),\epsilon_{s}\in(0,0.1),p_{f}\in(0,0.01))$ (Algorithm 1), for $k\in[d]$. It takes $O(lnr)$ time to initialize one data structure.
- •
At query time, for user input $Q$, we process one token at a time by passing the $i$-th row of $Q$, denoted $Q_{i}\in\mathbb{R}^{d}$, to DistanceQuery$(Q_{i},\alpha\in(0,1))$ (Algorithm 1) for each $i\in[m]$.
It takes $O(\alpha^{-1}lr\log^{2}n)$ time to output an entry $z$ in $\mathrm{Attn}(Q,K,V)$ such that
–
the process of output $z$ satisfies $(\epsilon,\delta+\delta^{\prime})$-DP,
–
the process of output $z$ has relative error $n^{-1}(\alpha+\epsilon_{s})$,
–
the process of output $z$ has additive error $O(n^{-1}\epsilon^{-1}\alpha^{-1/2}l\Gamma_{R,s}^{2}R_{w}r\sqrt{\log(l/\delta^{
\prime})}\cdot\log^{3/2}n)$,
–
it holds with probability $1-p_{f}$ (where $p_{f}$ is used in $l$),
–
it is robust to adaptive query.

###### Proof.

From Section 3, we know that we can ensure matrix $AV$ in cross-attention computation satisfies DP.
Next, from Theorem 4.4, for $i\in[m],j\in[n],k\in[d]$, we have $(AV)_{i,k}$ is $(\epsilon,\delta+\delta^{\prime})$-DP and also robust to adaptive query.
For $D$, we compute the exact true value.
By the post-processing property of DP (Fact B.5), our cross-attention process is DP.

Let $(AV)_{i,k}$ be the true value and $\widetilde{(AV)}_{i,k}$ be the noisy value. Then, from Theorem 4.4, we have

$$ $\displaystyle|(AV)_{i,k}-\widetilde{(AV)}_{i,k}|\leq(\alpha+\epsilon_{s})\cdot (AV)_{i,k}+O(\epsilon^{-1}\alpha^{-1/2}l\Gamma_{R,s}^{2}R_{w}r\sqrt{\log(l/ \delta^{\prime})}\cdot\log^{3/2}n).$ (11) $$

For $D_{i,i}$, we can show

$$ $\displaystyle D_{i,i}=(A\cdot{\bf 1}_{n})_{i}=\sum_{j=1}^{n}\exp(\langle Q_{i} ,K_{j}\rangle/d)\geq n$ (12) $$

because $\langle Q_{i},K_{j}\rangle\geq 0$ for bounded $Q,K$.

Finally, we can show the error of one entry is bounded by

$$ $\displaystyle|(D^{-1}AV)_{i,k}-(D^{-1}\widetilde{AV})_{i,k}|=$ $\displaystyle~{}|D_{i,i}^{-1}((AV)_{i,k}-\widetilde{(AV)}_{i,k})|$ $\displaystyle=$ $\displaystyle~{}|D_{i,i}^{-1}|\cdot|((AV)_{i,k}-\widetilde{(AV)}_{i,k})|$ $\displaystyle\leq$ $\displaystyle~{}n^{-1}(\alpha+\epsilon_{s})\cdot(AV)_{i,k}$ $\displaystyle~{}+O(n^{-1}\epsilon^{-1}\alpha^{-1/2}l\Gamma_{R,s}^{2}R_{w}r \sqrt{\log(l/\delta^{\prime})}\cdot\log^{3/2}(n))$ $$

where the first step follows from definition, the second step follows from simple algebra, and the last step follows from Eq.(11) and (12).
∎

###### Theorem I.12 (Softmax cross-attention, formal version of Theorem 3.1 ) .

###### Proof.

## Peer Reviews

confidence: 3
contribution: 3
initial_rating: 5
presentation: 3
questions: 1.Given the DPTREE's reliance on polynomial kernel approximations and its focus on cross-attention, how well does it generalize to other attention mechanisms or model architectures, especially in high-dimensional or heterogeneous data scenarios?
2.What strategies does the DPTREE mechanism have in place to manage potential approximation errors that may accumulate during adaptive querying?
3.Are there specific types of datasets or applications where DPTREE demonstrates significantly better or worse performance?
soundness: 3
strengths: 1.Novel Application of DP in Cross-Attention: The paper proposes the first DP solution specifically for cross-attention, a fundamental mechanism in LGMs, which is innovative and addresses privacy in an underexplored area.
2.heoretical Rigor: The paper is backed by solid theoretical proofs of privacy and accuracy guarantees, adding depth and credibility to the approach.
3.Adaptive Query Handling: The mechanism is robust against adaptive queries, making it suitable for real-world applications where inputs can vary significantly.
4.Memory and Computation Efficiency: Through the DPTREE structure, the proposed method optimizes memory usage and computational complexity, enhancing scalability.
summary: This paper introduces a novel differential privacy (DP) mechanism, DPTREE, for preserving privacy in cross-attention mechanisms in large generative models (LGMs). The structure provides privacy guarantees while supporting adaptive queries with theoretically bounded errors and optimized memory and computation costs.
weaknesses: 1.Lack of Innovation in Core Techniques: The DPTREE mechanism heavily relies on polynomial kernel approximations and basic DP noise mechanisms, which are established techniques in DP literature. The limited novelty in these technical foundations weakens the originality of the proposed approach.
2.Limited Generalization and Practicality: DPTREE is specifically tailored to cross-attention, and its reliance on polynomial kernel approximations may not generalize well across other types of attention mechanisms or data structures in LGMs. This specificity reduces the model's adaptability, which could hinder broader applicability and limit its impact in the field.
3.Computational and Initialization Costs: Although optimized for memory during inference, the initialization and computational costs for high-dimensional data remain high. This could make the solution impractical for larger LGMs or applications requiring frequent real-time updates.

---

confidence: 2
contribution: 3
initial_rating: 6
presentation: 2
questions: - How do you guarantee that $K_{i,j} \in [0,R]$ and $V_{i,j} \in [-R,R]$? Is this done by clipping? If so, what effect does that have on the performance of the algorithm?
- What is the scope of the adjacency relation? Is it leaving out individual tokens? If so, in practice secrets may reach across many tokens and the DP guarantees would not provide meaningful privacy.
soundness: 3
strengths: - Given that cross-attention modules are fundamental in numerous applications involving sensitive data such as RAG, this work addresses an important gap. The transformation of cross-attention computations into a "weighted distance problem" is a creative solution, making it amenable to DP techniques in a novel way.
- The paper does a good job of grounding its methodology in formal mathematical guarantees. By presenting detailed proofs of differential privacy for the cross-attention mechanism as well as an error and complexity analysis, the authors provide a robust theoretical backing.
summary: This paper introduces a modified cross attention algorithm with differential privacy guarantees. The authors modify the cross-attention algorithm by approximating the exponential inner product which allows them to cast the modified algorithm into a weighted distance problem. The paper introduces a several novel tree based data structures to efficiently compute a private the private weighted distance. They produce detailed proofs of privacy guarantees as well as error analysis.
weaknesses: - The appeal of cross attention is its superior empirical performance. The paper adapts the algorithm in several ways without evidence how the algorithm's performance is changed.
- While I understand that the contributions of this paper are of theoretical nature, the motivation of the paper is the popularity of the cross-attention mechanism which is due to its practicality. As such, an empirical evaluation of the utility-privacy trade-off would strengthen the paper especially considering the main audience of this conference. However, the paper is already in the current state fairly dense and I'm not sure whether adding even more content will help the readability in its current format.

---

confidence: 3
contribution: 3
initial_rating: 6
presentation: 2
questions: In Theorem 1.2, you mentioned that with probability 1 - $p_f$, the mechanism is $(\epsilon, \delta)$-DP. It gives me a feeling that the mechanism is $(\epsilon, \delta + p_f) $- DP. What's the value of $p_f$ in practice? Given a fixed $\epsilon$, the larger is $ \delta + p_f$ , the less private is the mechanism.
soundness: 3
strengths: 1. The novel idea of reformulating Cross Attention as a weighted distance problem allows the use of classic differential privacy algorithms, such as the binary tree mechanism, as building blocks to ensure the privacy of Cross Attention.

2. A comprehensive analysis of the algorithm is provided, covering aspects such as utility, computational complexity, and privacy properties. I believe this work provides a solid foundation for developing differentially private mechanisms for core components in large language models.

3. Figure 1 in the appendix is very helpful for understanding the connection between cross attention and the dp binary tree.
summary: This paper proposes a differentially private algorithm for implementing Cross Attention. It reformulates Cross Attention as a private summation problem and employs a classic binary tree algorithm to ensure privacy. The paper provides a comprehensive analysis of the proposed algorithm, though it lacks empirical evaluation.
weaknesses: 1. The comparison with DP-SGD is limited. Currently, DP-SGD is widely used in various fine-tuning tasks and can be relatively easily integrated into existing systems. In contrast, the proposed DP Cross-Attention requires complex algorithmic design, making adaptation to existing systems challenging. It requires significant modifications, which reduces its accessibility.

2. For linear queries, the matrix mechanism [1] generally outperforms the binary tree. I would be interested in hearing more discussion on the matrix mechanism. Could you also provide an estimate of the width of the binary tree (i.e., the number of leaves) in your algorithm?

[1] Li, Chao, Gerome Miklau, Michael Hay, Andrew McGregor, and Vibhor Rastogi. "The matrix mechanism: optimizing linear counting queries under differential privacy." The VLDB journal 24 (2015): 757-781.

---

confidence: 3
contribution: 2
initial_rating: 6
presentation: 3
questions: 1. The definition of differential privacy in the article is unclear. It is defined for datasets represented by vectors in $\mathbb{R}^n$. However, in cross-attention, the key and value matrices have dimensions of $n\times d$. I recommend clarifying the definition so that it fits the cross-attention setting.
2. In line 269, it is stated that "D is only a normalization factor and does not contain sensitive information". However, the normalization factors depend on $A$, which is calculated from $K$ and $V$. Thus, $D$ contains private information and should be protected. I do not understand why we can directly discard $D$ in this context.
3. In Algorithm 3, the variables $P_{wx}$ and $s_{wx}$ are used without adding any noise. Can you explain why the resulting algorithm still preserves differential privacy?
4. Has the problem of private distance queries been studied in the literature? If so, it would be helpful to include some related work.
5. The initialization time complexity and query time complexity in the abstract do not include $d$. Is this a typo?
soundness: 3
strengths: The paper is the first to propose a DP algorithm for cross-attention computation. The algorithm is both time- and space-efficient for initialization and can quickly answer adaptive user queries. The idea of approximating the exponential inner product by a polynomial kernel function (Lemma I.5) and the distance query algorithms (Algorithms 5 and 6) are interesting.
summary: This paper studies the problem of privately computing cross-attention. The authors propose a data structure that can answer cross-attention queries within certain relative and absolute errors while satisfying $(\varepsilon,\delta)$-DP. The main idea is to approximate the exponential inner product using a polynomial kernel function, which converts the original problem into one of answering distance queries.
weaknesses: 1. It is unclear what information is protected in this paper.  It is necessary to clearly state which parts of the input are private ($K$ and $V$?) and which parts of the output are public ($Q$?). Moreover, since each row of $K$ is derived from one word in the input, the proposed algorithm seems to only protect word-level privacy.
2. The paper does not contain any experiments, making it difficult to evaluate whether the obtained errors fall within a reasonable range. Since the problem arises from a real-world application, it is strongly recommended to provide some illustrative experiments, such as standard NLP tasks on real-world datasets.
3. The proposed algorithm has a relative error, which could be unsatisfactory. In Section 5, it is mentioned that the parameter $\alpha$ can be removed. Does this imply that the algorithm can be modified to involve only additive errors, or does the $n^{-1}\varepsilon_{S}$ term still exist?

Meta-review: There were a lot of discussion on the paper. However, there were not many folks strongly supporting the work. Few of the concerns that lingered are:

a) Lack for experiments for a completely applied problem. It is unclear what the theorems convey without having real numbers on benchmark tasks.

b) The comparison to DP-SGD or standard DP training algorithms is limited. I think the only way to handle this issue is via having experiments with an end to end training task.

We would like to revise the paper focussing on these two aspects.

Decision: Reject