Initial problem
There is, in my opinion, nothing wrong with "multidependences" in the way I think you mean, but there is a more fundamental problem here (I believe). Consider these definitions:
w[b_, x_] := fixed + b[x]
u[w_, b_, x_] := Sqrt[w[b, x]]
I presume that you expect to call u
with three arguments and have it in turn call w
but this does not happen (in general) because you used the same Symbol name for both a function and a parameter:
u[1, 2, 3]
Sqrt[1[2, 3]]
Please clarify your intent regarding this and if necessary correct this aspect of your example.
Update
Responding now to your updated question I largely agree with seismatica's answer, which I just voted for. However I'll give you an answer in my own words.
First, as described above under most circumstances you should not be passing function names as well, reducing your code to the same form as your declared functions:
b[x_] := 10 x
w[x_] := s + b[x]
c[x_] := x^2
ua[x_] := w[x] - c[x]
ub[x_] := w[x] - c[x]^2
There are two potential issues I see here. The first is that the "namespace" is "poluted" with b
, w
, c
which as I understand are never to be called outside of ua
and ub
. The second is that you introduce a longer than necessary evaluation chain for the functions ua
and ub
. Consider this Trace
:
ub[3] // Trace
{ub[3], w[3] - c[3]^2, {w[3], s + b[3], {b[3], 10 3, 30}, s + 30, 30 + s},
{{{c[3], 3^2, 9}, 9^2, 81}, -81, -81}, (30 + s) - 81,
-81 + (30 + s), -81 + 30 + s, -51 + s}
When the formula is merely:
ub[x]
s + 10 x - x^4
It is a good time to note that ub
is not merely a function of x
but also of s
, and I do recommend making that an explicit parameter rather than relying on a global value. Also, as seismatica showed you can also make these simple expression definitions rather than functions. Combining all this I would instead write:
Block[{s, x, b, w, c},
b = 10 x;
w = s + b;
c = x^2;
ua[s_][x_] = w - c;
ub[s_][x_] = w - c^2;
]
Note the Block
a the use of Set
(=
) rather than SetDelayed
(:=
) in the definitions of ua
and ub
. These work in harmony: the Block
prevents unwanted assignments from interfering with the evaluation that results from Set
. Let's look at the definitions we created:
?ua
?ub
Global`ua
ua[s_][x_] = s + 10 x - x^2
Global`ub
ub[s_][x_] = s + 10 x - x^4
Note that the simplified definitions are used. Despite the fact that these definitions were made using Set
they are now safe from global assignments to s
or x
as arguments will be substituted into the right-hand-side before further evaluation.
Compare this Trace
:
ub[s][3] // Trace
{ub[s][3], s + 10 3 - 3^4, {10 3, 30}, {{3^4, 81}, -81, -81}, s + 30 - 81, -51 + s}
Note that I chose to use SubValues syntax for the definitions. This is not necessary but it allows you to treat ub[s]
as a function that can e.g. be mapped:
ub[3] /@ {2, 4, 6}
{7, -213, -1233}
(For this particular function it would be better to use ub[3][{2, 4, 6}]
-- see Case #4 of this self-Q&A.)
b[x_] := 10 x; w[x_] := s + b[x]; c[x_] := x^2; u[x_] := w[x] - c[x]
$\endgroup$