Existential conditional on aspects of forall I am trying to describe that given information about the result of $f(x),$ a $y$ exists such that for all $x$ with that result for $f(x),$ we have $g(x) = g(y)$. Only specific information about $x$ (namely the value of $f(x)$) may be used when constructing the $y$. Symbolically:
$$ \forall z: \exists y: \forall x: (z = f(x) \implies g(x) = g(y)). $$
However, from this formula, it is not immediately clear that that is what is meant, so I was wondering if there is a way to state this formula more clearly?

Edit 2:
Removed the previous example in favour of a more conceptual example:
We explain three examples, and the third is an example of our problem:

*

*For every jar there is a lid that fits: $
\forall j \in \text{Jar}: \exists l \in \text{Lid}: \text{fits}(j, l)$.


*There is a lid that fits on every jar: $\exists l \in \text{Lid}: \forall j \in \text{Jar}: \text{fits}(j, l)$.


*For every diameter there exists a lid that fits on every jar of such diameter: $\forall d: \exists l \in \text{Lid}: \forall j \in \text{Jar}: (\text{diam}(j) = d \implies \text{fits}(j, l))$.
The question is: is there a clearer way to describe the last sentence in a logical statement?
 A: *

*

For every diameter there exists a lid that fits on every jar of such diameter.

For every $\boldsymbol d,$ there exists a lid that fits on every jar of diameter $\boldsymbol d.$
For each $\boldsymbol d,$ for some lid $\boldsymbol l,$ for every jar $\boldsymbol j$ of diameter $\boldsymbol d,\, \boldsymbol l$ fits $\boldsymbol j.$
$$\forall d\; \exists l \; \forall j \; \Big(\text{diam}(j,d)
\implies \text{fits}(j, l)\Big).\tag1$$

$$\forall d\; \exists l {\in} L \; \forall j {\in} J\; \Big(\text{diam}(j) = d \implies \text{fits}(j, l)\Big)$$



*

given $\color{red}{\text{information about the result of }f(x)},$ a $y$ exists such that for $\color{green}{\text{all }x}$ with $\color{red}{\text{that result for }f(x)},$ we have $g(\color{green}x) = g(y).$
(Only $\color{red}{\text{specific information about $\color{green}x$ (namely the value of $f(x)$}}$) may be used when constructing the $y.)$

Given $\color{red}{\text{a value }v},$ an input $b$ exists such that for $\color{green}{\text{all inputs }a}$ for which $f(\color{green}a)=\color{red}v,$ we have $g(\color{green}a) = g(b).$ $$\forall v\; \exists b\; \forall a\; \Big(f(a)=v \implies  g(a) = g(b)\Big).\tag2$$

$$\forall z: \exists y: \forall x: (z = f(x) \implies g(x) = g(y))$$



*Observe that the italicised ‘diameter’ is a predicate, whereas the boldfaced ‘diameter’ is a variable, now renamed $\boldsymbol d$ for clarity.
Similarly, the red $\color{red}x$ that occurs before $y$ is a different object from the green $\color{green}x$ that occurs after $y.$ Given your intended meaning, the former is a red herring, now dropped to avert conflict and confusion.


*Another ambiguity worth noting: the statement $$\text{some lid $l$ fits on each jar $j$}$$ contains a hanging quantifier, and might mean either $$\exists l \;\forall j \;\text{fits}(j,l)$$ or $$\forall j \;\exists l \;\text{fits}(j,l).$$


*

I was wondering if there is a way to state this formula more clearly?

Not for formulae $(1)$ and $(2),$ unless you prefer replace $(P{\implies}Q)$ with $(\lnot P \lor Q).$
