total differential (thermodynamic relations) Assume that:


*

*there are four quantities $S,T,P,V$; any two of them can be varied independently, but the other two are then determined ---(1)

*$dU=TdS-PdV$ ---(2)

*$F=U-ST$ ---(3)


then, according to my book:
$$dF=d(U-ST)=dU-TdS-SdT$$
but I can't get the above result. Here is my reasoning:
Choose $S$ and $T$ as independent variables
According to the definition of total differential:
$$dF=\frac{\partial (U-ST)}{\partial U}dU+\frac{\partial (U-ST)}{\partial S}dS+\frac{\partial (U-ST)}{\partial T}dT$$
By (2), we know that the value of $U$ depends on $S$ and $T$, so:
$$dF=\left(\frac{\partial U}{\partial U}-\frac{\partial (ST)}{\partial U}\right)dU+\left(\frac{\partial U}{\partial S}-T\frac{\partial S}{\partial S}\right)dS+\left(\frac{\partial U}{\partial T}-S\frac{\partial T}{\partial T}\right)dT \\
=\left(1-\frac{\partial (ST)}{\partial U}\right)dU+\left(\frac{\partial U}{\partial S}-T\right)dS+\left(\frac{\partial U}{\partial T}-S\right)dT $$
It seems that the author of my book assumed $U$ to be indepedent of $S$ and $T$ to get $\frac{\partial (ST)}{\partial U}=0$, $\frac{\partial U}{\partial S}=0$ and $\frac{\partial U}{\partial T}=0$, but doesn't it contradict assumption (2)?
Would you explain to me how can the author obtain his result?

Oh! I finally got it! 
There is no contradiction with assumption (2). I thought there was, just because I didn't pay attention to an important fact: when doing partial differentiation with respect to one variable, the other variables are regarded as constants! Also, as Hurkyl said below, the number of variables doesn't matter at all! Let me try to explain it:


*

*Case 1: we treat $F$ as a function of three variables, i.e. $F(U,S,T)$, then we got the following result as I did in my original post:
$$dF=\left(1-\frac{\partial (ST)}{\partial U}\right)dU+\left(\frac{\partial U}{\partial S}-T\right)dS+\left(\frac{\partial U}{\partial T}-S\right)dT$$
but when we are doing partial differentiation of $F(U,S,T)$ with respect to $U$, the other variables, $S$ and $T$, are regarded as constants, so $\frac{\partial (ST)}{\partial U}=0$, similarly, $\frac{\partial U}{\partial T}=0$ ($U$ and $S$ kept constant) and $\frac{\partial U}{\partial S}=0$ ($U$ and $T$ kept constant), so $$dF=(1-0)dU+(0-T)dS+(0-S)dT=dU-TdS-SdT$$
notice that it does not contradict with assumption (2), because the variables are regarded as unrelated just because we are doing partial differentiation, whereas in assumption (2), we are defining $dU$, not doing partial differentiation.

*Case 2: we treat $F$ as a function of any two variables, not necessarily $S$ and $T$. For example, we treat $F$ as $F(U,S)$, then
$$dF=\left(\frac{\partial (U-ST)}{\partial U}\right)_S dU+\left(\frac{\partial (U-ST)}{\partial S}\right)_U dS$$
notice that in this case, $T$ can not be regarded as constant, because it is not a variable of $F$, but a function of $U$ and $S$, so:
$$dF=\left(1-S\frac{\partial T}{\partial U}\right)dU+\left(-S\frac{\partial T}{\partial S}-T\right)dS \\ 
=dU-S\left(\frac{\partial T}{\partial U}dU+\frac{\partial T}{\partial S}dS\right)-TdS \\
=dU-SdT-TdS$$
we can get the same result if we choose any two variables.

*Case 3: we treat $F$ as a function of one variable, $F(t)$, where $U=U(t)$, $S=S(t)$, $T=T(t)$, in this case we can just use single variable differentiation:
$$\frac{dF}{dt}=\frac{d(U-ST)}{dt}=\frac{dU}{dt}-\left(T\frac{dS}{dt}+S\frac{dT}{dt}\right)$$
multiply the above equation by $dt$, we can get $dF=dU-TdS-SdT$
So, we can get the same result no matter how we choose variables. And it doesn't matter whether the variables are independent or not! We can still have good approximation from the total differential $dF$ (please refer to Mary Boas's Mathematical Methods in the Physical Sciences, 3rd Edition, p.200 and p.201 problem #8 for an explanation of this).
Anyway, thank all of you for sharing your ideas here.
 A: Edit: as has been pointed out, it is not strictly necessary to use only two coordinates here.  Given that it is explicit that of the four state quantities two are redundant, I feel it is clearest to do so.  The original text remains below.

Unfortunately, all the $d$'s and $\partial$'s running around can make these thermodynamics problems really confusing.  I would look at it as follows:
You have some 2d state space.  $P, S, V, T$ are "coordinates" describing this space, hence their inherent redundancy.
$U$ and $F$ are scalar fields on this space.  Framed this way, you can think about the problem in terms of something you might be more familiar with: multivaraible calculus, like what you use in electromagnetism problems.
Phrased this way, the differential of $U$ is instead written as
$$\nabla U = T \nabla S - P \nabla V$$
This is a vector in the state space.
Similarly, we have
$$\nabla F = \nabla (U - TS) = \nabla U - T \nabla S - S \nabla T$$
Now, multivariable calculus tells us that you can always decompose the gradient $\nabla$ into partial derivatives and vectors, like so:  let $X$ and $Y$ be coordinates.  $\nabla$ can be decomposed as
$$\nabla = (\nabla X) \partial_X + (\nabla Y) \partial_Y$$
The key is that there are only two coordinates in this 2d state space involved.  The choice of coordinates is arbitrary, but there can only be two.  Your mistake is that you try to write $\nabla F$ in terms of $\partial_U, \partial_S, \partial_T$.  That's three variables.  You can't do that.
The proper decomposition is
$$\nabla F = [(\nabla S) \partial_S + (\nabla T) \partial_T][U - TS]$$
which yields
$$\nabla F = (\nabla S) \left[ \frac{\partial U}{\partial S} - T - S \frac{\partial T}{\partial S} \right ] + (\nabla T) \left[ \frac{\partial U}{\partial T} - S - T \frac{\partial S}{\partial T}\right]$$
But for the decomposition of $\nabla$ I wrote to hold, $S, T$ must be a truly independent pair of coordinate functions, so their partial derivatives with respect to one another are zero, and you get the same result as if you applied the product rule from the start.
So I think some of the issues here have to do with some lack of rigor in the usual presentation of the calculus used in thermodynamics problems.

Edit: Answers to questions posed by the OP in response.
(1) Abuse of notation. $z = z(x,y)$.  They should (but "they" often don't) distinguish between $z$ as a function of two inputs and (let's call it) $Z = Z(\lambda)$, a function of one input.  Let $x = x(\lambda) = \lambda$ and $y = y(\lambda)$, and you get
$$\frac{dZ}{d\lambda} = \frac{\partial z}{\partial x} \frac{dx}{d \lambda} + \frac{\partial z}{\partial y} \frac{d y}{d\lambda}$$
Geometrically, you should see this as working in a 2d space where you're constraining yourself to some curve.
(2) Gradients and linear approximations are intimately related.  Look at a Taylor expansion for a scalar field in the direction of some vector $a$:
$$\phi(r + a t) - \phi(r)  = t a \cdot \nabla \phi|_r + \ldots$$
The first linear approximation to the change in a function is indeed the gradient.  That this is not emphasized in thermo texts is something I attribute to an unwillingness to consider multivariable calculus outside of 3d (which happens a lot in very large state spaces).
(3) The vectors comprising a gradient are often not unit.  Consider polar coordinates:
$$\nabla = \hat r \partial_r + \frac{\hat \theta}{r} \partial_\theta$$
A: Partial derivatives are making this problem too complicated -- (IMO) generally speaking, differentials are more straightforward and explicit, and should be preferred when possible.
The expression you are having difficulty with 
$$d(U−ST)=dU−TdS−SdT$$
is just applying the familiar derivative rules and is no more complicated than implicit differentiation. In particular, we need


*

*$d(f-g) = df - dg$

*$d(fg) = f dg + g df$


and so we have
$$ dF = d(U-ST) = dU - d(ST) = dU - (S dT + T dS) = dU - S dT - T dS $$
If and how U, S, and T are related are completely irrelevant to this calculation. However, if we are aware of the dependence
$$ dU = TdS - PdV $$
then we can substitute above to get, for example,
$$ dF = (TdS - PdV) - S dT - T dS = -PdV - SdT $$
A: Assume that of the four quantities $S,T,P,V$ we choose $S,T$ as independent variables. Then, this forces $P = P(S,T)$ and $V=V(S,T)$. These functions are subject the conditions:


*

*$dU=TdS-PdV$

*$F=U-ST$


Flag on the play, what is $U$? What is $F$? 
Maybe, we should say $S,T,P,V,U,F$ are six quantities held in place by relations 2. and 3. above. In that view, there would be four independent variables. Apparently, $S,T,U,P$ are independent. Thus $V,F$ are dependent. We should rewrite condition (2.) to reflect this choice better:
$$dV = \frac{T}{P}dS-\frac{1}{P}dU$$
Next, as $U,S,T$ are independent,
$$ dF = dU-SdT-TdS $$
I have my dependent variable differentials standing alone so now we can read whatever partial derivatives in the variables $S,T,U,P$ we wish. For example,
$$ \left( \frac{\partial F}{\partial U} \right)_{S,T,P}=1 $$
or
$$ \left( \frac{\partial F}{\partial T}\right)_{U,T,P}=-S $$
the notations given above explicitly recognize $S,T,U,P$ as independent. By definition, this supposes that all partial derivatives amongst $S,T,U,P$ are zero. To be careful, I'd want to consider a function on six dimensional space and check that the proposed set of independent variables are supported by the implicit function theorem. However, I may be over-stepping here since your condition (2.) is a differential relation. So, a different theorem is required, let me continue with formal reasoning.
You asked:
"$\frac{\partial U}{\partial S}=0$ and $\frac{\partial U}{\partial T}=0$, but doesn't it contradict assumption (2)?"
I think the answer here is just that you have to look at (2.) as I did. Namely,
$$dV = \frac{T}{P}dS-\frac{1}{P}dU$$
This doesn't reveal a dependence between $S$ and $U$. Rather, it shows how $V$ varies in response to changes in $S$ and $U$.
Honestly, somebody else might come along and give you a different answer. It's all about what is dependent and what is independent. I find the notation which indicates explicitly which variables are taken as independent is helpful to sort things out.
A: To Muphrid:
Thanks for your reply. If we must write the total differential with respect to only the two independent variables, then may be I can do it this way: 
\begin{equation*}
\begin{split}
dF &= \frac{\partial (U-TS)}{\partial S}dS+\frac{\partial (U-TS)}{\partial T}dT \\
&= \left(\frac{\partial U}{\partial S}-T\right)dS+\left(\frac{\partial U}{\partial T}-S\right)dT  \\
&= (\frac{\partial U}{\partial S}dS+\frac{\partial U}{\partial T}dT)-TdS-SdT \\
&= dU-TdS-SdT
\end{split}
\end{equation*}
But there are somethings I don't understand: 
(1) if we must write only in terms of the independent variables, how about total derivatives? for example, if $y=g(x)$, then for $z=f(x,y)$, we have $$\frac{dz}{dx}=\frac{\partial z}{\partial x}+\frac{\partial z}{\partial y}\frac{dy}{dx}$$
in this case, why are we allowed to write the partial derivatives with respect to both $x$ and $y$? (where the value of $y$ depends on $x$, so there is just one independent variable $x$).
(2) why can the total differential be written as gradient instead? From what I have learnt, total differential is a linear approximation of the change of a function, whereas gradient is a vector field that points in the direction of the greatest rate of increase with its magnitude equals to that rate, so it seems to me that they are two different things.
(3) For this decomposition: $$\nabla = (\nabla X) \partial_X + (\nabla Y) \partial_Y$$ I haven't seen this before, but isn't that $\nabla X$ and $\nabla Y$ need to be normalized to form unit vectors, just like the $\mathbf{i}$ and $\mathbf{j}$ in $$\nabla = \mathbf{i}\frac{\partial}{\partial x}+\mathbf{j}\frac{\partial}{\partial y} \quad?$$
To James:
Thanks for your reply, but I think there are only two independent variables, $S$ and $T$ (if we choose them to be), and the values of other variables depend on them.
Also, the meanings of these variables are: $P$=pressure, $V$=volume, $S$=entropy, $T$=temperature, $U$=internal energy, $F$=Helmholtz potential.
A: This is a chemistry/physics question.  The Gibbs Phase Rule given the number of independent variables for a given number of components and phases present.  Part of the confusion here is that some information is implicit.  The simplest possible case is one component and one phase.  Such a system would have THREE independent variables.  But here, since it is not mentioned, the amount of material $n$ is clearly being held constant.  This leaves two independent variables.
There are a large number of thermodynamic functions running from entropy through heat capacity to free energies.  ALL such functions in the system described above are functions of two independent variables.  The original poster seems to have chosen $S$ and $V$ as independent variables.
Now the First Law of thermodynamics gives us $U$, the internal energy.  We can construct new functions from $U$ using a Legendre transformation.  For example we can define $A$ as $A = U -TS$ ($T$ is temperature).  Then $$dA = dU - d(TS)$$ and we are off and running.
I'm not going to work out the details.  The point is that one must (I feel strange saying this in THIS group) pick one's independent variables once and for all at the start and stick to them.  For example the standard definition for $A = U - TS$ is $A$, the Helmholtz free energy.  It is customary in chemical thermodynamics to define the energy $U$ in terms of entropy $S$ and volume $V$, thus $$U = U(S,V)$$ (assuming amount of material constant).
