• Aucun résultat trouvé

Attributes, options and values by default for the arguments of the user blocks, functions and modules; additional means of processing of

Dans le document Extension of Mathematica systemfunctionality (Page 192-200)

by them in theMathematicasoftware

6.8. Attributes, options and values by default for the arguments of the user blocks, functions and modules; additional means of processing of

them inMathematica

The Mathematica system provides the possibility of assignment to variable, in particular, to names of blocks, functions or modules of the certain special attributes defining their different properties. So, theListable attribute for a functionW defines, that the functionW will be automatically applied to all elements of the list which acts as its argument. The current tenth version of theMathematica system has19 attributes of various purpose,the work with them is supported by3 functions, namely: Attributes, ClearAttributes and SetAttributes whose formats are discussed, for example, in [30-33]. These3 functions provide such operations as:(1) return of the list of the attributes ascribed to an objectx;(2) deletion of all or separate attributes ascribed to an objectx; (3) a redefinition of the list of the attributes ascribed to an objectx. Meanwhile, in a number of cases of these means it isn’t enough or they are not so effective. Therefore, we offered a number of means in this direction which expand the above standardMathematica means.

Above all,since eventuallynewMathematica versions quite can both change the standard set of attributes and to expand it, the problem of testing of an arbitrary symbol to be qua of an admissible attribute is quite natural. The AttributesQ procedure solves the given

problem whose callAttributesQ[x] returnsTrue, ifx – the list of admissible attributes of the current version of the system, andFalse otherwise. Moreover, the callAttributesQ[x, y] with the2nd optional argumenty –an undefinite variable– returns through it the list of elements of the listx which aren’t attributes. The following fragment represents source code of the procedure with typical examples of its usage.

In[2550]:= AttributesQ[x_List, y___] := Module[{a, b = {}},

Map[If[Quiet[Check[SetAttributes[a, #], $Failed]] === $Failed, AppendTo[b, #]] &, x]; If[b != {}, If[{y}!= {}&& ! HowAct[y], y = b]; False, True]] In[2551]:=

{AttributesQ[{Listable, Agn, Protected, Kr, Art}, h], h} Out[2551]= {False, {Agn, Kr, Art}}

In[2552]:= {AttributesQ[{Protected, Listable, HoldAll}, g], g} Out[2552]= {True, g}

The given means is quite useful in a number of system appendices, at that, expanding the testing means of theMathematica system.

Definitions of the user blocks, functions and modules in the Mathematica system allow qua of conditions and initial values for formal arguments, and initial values for local variables to use rather complex constructions as the following simple fragment illustrates, namely:

In[4173]:= G[x_Integer, y_ /; {v[t_] := Module[{}, t^2], If[v[y] > 2015, True, False]}

[[2]]] := Module[{a = {g[z_] := Module[{}, z^3], If[g[x] < 2015, 73, 90]}[[2]]}, Clear[v, g]; x*y + a]

In[4174] := {a, b}= {500, 90}; {G[42, 73], G[42, 500], G[0, 0]}

Out[4174]= {3156, 21090, G[0, 0]}

In[4175]:= Map[PureDefinition, {v, g}]

Out[2565]= {”v[t_]:= Module[{}, t^2]“, $Failed}

In[4176]:= G[x_Integer, y_ /; {v[t_] := Module[{}, t^2], If[v[a] > 2015, True, False]}

[[2]]] := Module[{a = {g[z_] := Module[{}, z^3],

If[g[b] < 2015, 71, 90] }[[2]]}, x*y + a] In[4177]:= {a, b}= {460, 71}; {G[42, 71], G[42, 460], G[0, 0]}

Out[4177]= {3072, 19410, 90}

In[4178]:= Map[PureDefinition, {v, g}]

Out[4178]= {”v[t_]:= Module[{}, t^2]“, “g[z_]:= Module[{}, z^3]”} For possibility of use of sequence of offers, including as well definitions of procedures, as a condition for a formal argumenty and initial value for the local variablea the reception that is based on the list has been used in the previous fragment. The sequences of offers were defined as

elements of lists with value of their last element ascondition andinitial value respectively.

At that, if in body of the main procedureG a cleaning of symbolsv andg from their definitions wasn’t done, the proceduresv andg will be available in the

current session, otherwise not. The given question is solved depending on an objective, the previous fragment illustrates the told. The above reception can be applied rather

effectively for programming of means of the different purpose what illustrates a number of the procedures represented in [28-33]. The mechanisms of typification of formal

arguments of the user functions, blocks and modules enough in details are considered in [30-33]. Meanwhile, along with the mechanism of typification of formal arguments, the system Mathematica has definition mechanisms for formal arguments of values by

default, i.e. values that receive the corresponding factual arguments at their absence at the calls. However, the system mechanism of setting of values by default assumes definition of such values before evaluation of definitions of blocks,functions and modules on the basis of the standardDefault function whose format supports installation of various values by default serially for separate formal arguments or of the same value for all arguments.

The next fragment represents the procedureDefaults1[F, y] that provides the setting of expressions as values by default for the corresponding formal arguments of any subtuple of a tuple of formal arguments of the user block, function, moduleF that is defined by the2–element listy(the first element–number of position of an argument,the second element is an expression). For several values by default the listy hasListListtype whose sublists have the above format. The procedure successfully works with the user block, function or module F of the same name, processing only the first subobject from the list of the

subobjects which are returned at the callDefinition[F]. The procedure call returns$Failed, or is returned unevaluated in special situations. The next fragment represents source code of theDefaults procedure with examples of its typical usage.

In[2640]:= Defaults[x_ /; BlockFuncModQ[x], y_ /; ListQ[y] && Length[y] == 2 ||

ListListQ[y] &&

DeleteDuplicates[Map[IntegerQ[#[[1]]] &, y]] == {True}] := Module[{a =

Flatten[{Definition2[x]}], atr = Attributes[x], q, t, u, b = Flatten[{HeadPF[x]}][[1]], c

= Args[x], d, p, h = {}, k = 1, g = If[ListListQ[y], y, {y}]}, If[Max[Map[#[[1]]&, y]]

<= Length[c]&& Min[Map[#[[1]]&, y]] >= 1, c = Map[ToString, If[NestListQ[c], c[[1]], c]]; q = Map[#[[1]] &, y]; d = StringReplace[a[[1]], b–> ””, 1]; While[k <=

Length[q], p = c[[q[[k]]]]; t = StringSplit[p, “_”]; If[MemberQ[q, q[[k]]]], u = If[Length[t] == 2, t[[2]] = StringReplace[t[[2]], ” /; “–> ””];

If[Quiet[ToExpression[“{” <> t[[1]] <> “=” <> ToString[y[[k]][[2]]] <> “,” <> t[[2]]

<> “}“]][[2]] || Quiet[Head[y[[k]][[2]]] === Symbol[t[[2]]]], True, False], True]; If[u, c[[q[[k]]]] = StringTake[p,

{1, Flatten[StringPosition[p, “_”]][[2]]}] <> “.”]]; k++];

ClearAllAttributes[x]; ClearAll[x]; k = 1; While[k <= Length[q],

ToExpression[“Default[” <> ToString[x] <> “, ” <> ToString[q[[k]]] <> “]” <> ” = ”

<>

ToString1[y[[k]][[2]]]]; k++]; ToExpression[ToString[x] <> “[” <>

StringTake[ToString[c], {2,–2}] <> “]” <> d]; Map[ToExpression, MinusList[a, {a[[1]]}]]; SetAttributes[x, atr], $Failed]]

In[2641] := G[x_, y_ /; IntegerQ[y]] := x+y; G[x_, y_, z_] := x*y*z; G[x_, y_, z_, h_]

:= x*y*z*h

In[2642]:= SetAttributes[G, {Listable, Protected, Flat}]

In[2643]:= Defaults[G, {{2, 500}, {1, 90}}]

In[2644]:= Definition[G]

Out[2644]= Attributes[G]= {Flat, Listable, Protected}

G[x_., y_.]:= x+ y G[x_, y_, z_]:= x y z G[x_, y_, z_, h_]:= x y z h G /: Default[G, 1]= 90 G /: Default[G, 2]= 500

In[2645]:= {G[42, 47], G[73], G[]}

Out[2645]= {89, 573, 590}

In[2646]:= ClearAllAttributes[G]; ClearAll[G];

G[x_, y_ /; IntegerQ[y]] := x + y; G[x_, y_, z_] := x*y*z; G[x_, y_, z_, h_] := x*y*z*h In[2647]:= SetAttributes[G, {Listable, Protected, Flat}]

In[2648]:= Defaults[G, {2, 90}]

In[2649]:= Definition[G]

Out[2649]= Attributes[G]= {Flat, Listable, Protected}

G[x_, y_.]:= x+ y G[x_, y_, z_]:= x y z G[x_, y_, z_, h_]:= x y z h G /: Default[G, 2]= 90

In[2650]:= Defaults[G, {1, 500}]

In[2651]:= Definition[G]

Out[2651]= Attributes[G]= {Flat, Listable, Protected}

G[x_., y_.]:= x+ y G[x_, y_, z_]:= x y z G[x_, y_, z_, h_]:= x y z h G /: Default[G, 1]= 500 G /: Default[G, 2]= 90

In[2652]:= {G[], G[72, 67], G[500]}

Out[2652]= {590, 139, 1000}

The successful call Defaults[G, y] returnsNull, i.e. nothing, carrying out all settingsy of values by default for formal arguments of a block, function or moduleG. It is necessary to emphasize once again that in case of an object G of the same name the callDefaults[G,y]

processes only the first subobject from the list of subobjects which is returned on the

callDefinition[G]. And this is a rather essential remark since the assignment mechanism to formal arguments ofG of values by default for case of an object of the same name, using

theDefault function, is other than ascribing for objects of such type, in particular, of the attributes. In the latter case the attributes are ascribed to all subobjects of an objectG of the same name whereas for values by default the mechanism is valid only concerning thefirst subobject from the list of the subobjects returned on the callDefinition[G].This

mechanism is realized as by the standard reception with use of the callDefault[G,n]

=default with template definition fornth formal argument of an objectG in the form“_.”

and by the callDefaults[G, {n, default}] as it rather visually illustrates the following fragment, namely:

In[2673] := Clear[V]; Default[V, 2] = 90; V[x_, y_.] := {x, y};

V[x_, y_., z_, h_] := {x, y, z, h}

In[2674]:= Definition[V]

Out[2674]= V[x_, y_.]:= {x, y}

V[x_, y_., z_, h_]:= {x, y, z, h}

V /: Default[V, 2]= 90

In[2675]:= {V[500], V[42, 47, 67]}

Out[2675]= {{500, 90}, {42, 90, 47, 67}}

In[2676]:= Clear[V]; Default[V, 2] = 90; V[x_, y_.] := {x, y};

V[x_, y_, z_, h_] := {x, y, z, h} In[2677]:= Definition[V]

Out[2677]= V[x_, y_.]:= {x, y}

V[x_, y_, z_, h_]:= {x, y, z, h}

V /: Default[V, 2]= 90

In[2678]:= {V[500], V[42, 47, 67]}

Out[2678]= {{500, 90}, V[42, 47, 67]}

In[2679]:= Clear[V]; V[x_, y_] := {x, y}; V[x_, y_, z_, h_] := {x, y, z, h}; Defaults[V, {2, 90}] In[2680]:= Definition[V]

Out[2680]= V[x_, y_.]:= {x, y}

V[x_, y_, z_, h_]:= {x, y, z, h}

V /: Default[V, 2]= 90

In[2681]:= {V[500], V[42, 47, 67]}

Out[2681]= {{500, 90}, V[42, 47, 67]}

While the DefaultsM procedure expands the previousDefaults procedure onto case of the objects of the same name of type {Block, Function, Module}. The successful procedure callDefaultsM[G, y] returnsNull, i.e. nothing, at that, carrying out all settings of values by defaulty for formal arguments of a block, function or moduleG. At that, for an object of the same nameG of the specified types the settings of values by defaulty for formal arguments of all subobjects of the objectG are carried out. The next fragment represents source code of theDefaultsM procedure with typical examples of its usage.

In[2556]:= DefaultsM[x_ /; BlockFuncModQ[x], y_ /; ListQ[y] && Length[y] == 2 ||

ListListQ[y] &&

DeleteDuplicates[Map[IntegerQ[#[[1]]] &, y]] == {True}] := Module[{ArtKr, atr = Attributes[x], q, k = 1,

a = Flatten[{PureDefinition[x]}], g = If[ListListQ[y], y, {y}]}, ClearAllAttributes[x];

ClearAll[x]; q = Map[#[[1]] &, g]; While[k <= Length[g], ToExpression[“Default[”

<> ToString[x] <> “, ” <> ToString[g[[k]][[1]]] <> “]” <> ” = ” <> ToString1[g[[k]]

[[2]]]]; k++]; ArtKr[s_String, def_List] := Module[{n = Unique[AVZ], b, c, d, t, j= 1, h}, h = ToString[n] <> ToString[x]; ToExpression[ToString[n] <> s]; b = HeadPF[h];

d = StringReplace[PureDefinition[h], b–> ””]; c = Select[Map[ToString, Args[h]], #

!= “$Failed” &]; While[j <= Length[c], If[MemberQ[q, j], t = c[[j]]; c[[j]] = StringTake[t, {1, Flatten[StringPosition[t, “_”]][[2]]}] <> “.”]; j++];

ToExpression[ToString[x] <> “[” <> StringTake[ToString[c], {2,–2}] <> “]” <> d];

ClearAll[h, n]]; k = 1; While[k <= Length[a], ArtKr[a[[k]], g]; k++]; SetAttributes[x, atr]] In[2557]:= G[x_, y_, z_Integer] := x + y + z; G[x_, y_] := x + y; G[x_] :=

Block[{}, x]; G[x_, y_, z_, h_] := Module[{}, x*y*z*h]; SetAttributes[G, {Flat, Protected, Listable}];

In[2558]:= DefaultsM[G, {{2, 90}, {3, 500}}]

In[2559]:= Definition[G]

Out[2559]= Attributes[G]= {Flat, Listable, Protected}

G[x_]:= Block[{}, x]

G[x_, y_.]:= x+ y

G[x_, y_., z_.]:= x+ y+ z

G[x_, y_., z_., h_]:= Module[{}, x y z h]

G /: Default[G, 2]= 90 G /: Default[G, 3]= 500

In[2550]:= {G[56], G[42, 47], G[47, 18, 25]}

Out[2550]= {56, 89, 90}

TheDefaultsM procedure provides a rather useful expansion of standard means of this type, supporting as the single objects of type {Block, Function, Module}, and the objects of the same name as evidently illustrate examples of the previous fragment.

It is necessary to focus attention on one rather important point once again. As it was already noted earlier, the procedures can be defined on the basis of constructions of the types {Module, Block}. However, proceeding from certain considerations, it is generally recommended to give preference to the constructions of theModule type because in a number of cases(this question has been considered slightly above and in [30-33]in details) the constructions of theBlock type are carried out incorrectly, without output of any

diagnostic messages. As an illustration we will give an example of realization of the Default1 procedure which concerns the theme of values by default, on the basis of two types of constructions– on the basis ofModule andBlock. The procedure callDefault1[x, y, z] returnsNull, i.e. nothing, providing settings of the values by default determined by a listz for arguments of an objectx, whose positions are given by a listy ofPosIntListтипа for ablock/function/ modulex. The next fragment from the standpoint of formalization

represents almost identical realizations of definition of theDefault1 procedure on the basis of constructions andModule, andBlock. And if the first realization is carried out quite correctly regardless of names of local variables, then the correctness of the second,

generally speaking, depends on crossing of a list of names of local variables with a list of values by default for arguments, in particular, of a function as quite visually illustrates the following fragment in case when the local variablea exists in addition and in the list of values by default for simple functionG. The following fragment represents source codes along with corresponding typical examples.

In[3792]:= Default1[x_Symbol, y_ /; PosIntListQ[y], z_List] := Module[{k = 1, a = Min[Map[Length, {y, z}]]}, While[k <= a, Default[x, y[[k]]] = z[[k]]; k++]; ]

In[3793]:= Default1[G, {1, 2}, {a, b}]; G[x_., y_.] := {x, y};

Clear[Default1]; DefaultValues[G]

Out[3793]= {HoldPattern[Default[G, 1]]:>a, HoldPattern[Default[G, 2]]:> b} In[3794]:=

Default1[x_Symbol, y_ /; PosIntListQ[y], z_List] := Block[{k = 1, a =

Min[Map[Length, {y, z}]]}, While[k <= a, Default[x, y[[k]]] = z[[k]]; k++]; ] In[3795]:= ClearAll[G]; Default1[G, {1, 2}, {a, b}]; G[x_., y_.] := {x, y};

DefaultValues[G]

Out[3795]= {HoldPattern[Default[G, 1]]:>2, HoldPattern[Default[G, 2]]:> b} In[3796]:=

Default1[x_Symbol, y_ /; PosIntListQ[y], z_List] := Module[{k = 1, h = Min[Map[Length, {y, z}]]}, While[k <= h, Default[x, y[[k]]] = z[[k]]; k++]; ] In[3797]:= Default1[G, {1, 2}, {a, b}]; G[x_., y_.] := {x, y};

Clear[Default1]; DefaultValues[G]

Out[3797] = {HoldPattern[Default[G, 1]]:>a, HoldPattern[Default[G, 2]]:> b} In[3798]:=

Default1[x_Symbol, y_ /; PosIntListQ[y], z_List] := Block[{k = 1, h =

Min[Map[Length, {y, z}]]}, While[k <= h, Default[x, y[[k]]] = z[[k]]; k++]; ] In[3799]:= ClearAll[G]; Default1[G, {1, 2}, {a, b}]; G[x_., y_.] := {x, y};

DefaultValues[G]

Out[3799]= {HoldPattern[Default[G, 1]]:>a, HoldPattern[Default[G, 2]]:> b}

Thus, the mechanisms of local variables used by procedures on the basis of Module andBlock, generally, aren’t identical. Consequently, in general it is necessary to give

preference to definition of the procedures on the basis of a Module construction, however, taking into account the aforesaid there are very many cases when both types of the

organization of the procedures are equivalent, demanding the preliminary analysis concerning the existence of such equivalence. The given question rather in details is considered in [33]. In general, for definition of the procedures we recommend to use structures on the basis ofModule in order to avoid need of carrying out the additional analysis on procedurality and universality in all cases of appendices.

For determination of values by default for formal arguments of a function/ block/module it is possible to use both the meansDefaults, DefaultsM and Default, and directly in their headings on the basis of constructions of the format“x_:expression”, or by combining both specified methods. However, the systemDefaultValues function returns the settings of values by default, executed only by means of the standardDefault function, for

example:

In[2269] := Default[G5, 2] = 90; G5[x_, y_: 500, z_: 42] := {x, y, z};

DefaultValues[G5]

Out[2269]= {HoldPattern[Default[G5, 2]]:> 90}

In[2270]:= G5[Agn]

Out[2270]= {Agn, 500, 42}

In[2271]:= Default[S4, 2] = 90; S4[x_, y_., z_: 42] := {x, y, z};

DefaultValues[S4]

Out[2271]= {HoldPattern[Default[S4, 2]]:> 90}

In[2272]:= S4[Avz]

Out[2272]= {Avz, 90, 42}

At that, if for argument a value by default has been defined and viaDefault, and directly in heading by a construction“_:”, then the second way has the maximum priority as it very visually illustrates the previous example with theG5 function. Meanwhile, the

standardDefaultValues function possesses serious enough shortcomings. First of all, the given function doesn’t reflect the values by default defined in a block/function/module heading, and only set through theDefault function. However generally it is incorrect

because for arguments the assignment of values by default as through theDefault function, and directly in headings is admissible; at that, the priority belongs exactly to the second method what often can contradict result of a call of the DefaultValues function as it is illustrated with the previous examples.

For elimination of similar shortcomings the DefaultValues1 procedure has been

programmed, whose the callDefaultValues1[x] returns the list of the format {{N1}:>V1,

…, {Np}:>Vp}, whereNj andVj(j=1..p) define numbers of positions of formal arguments in the heading of a block/function/module, and values by default ascribed to them

respectively, regardless of method of their definition, taking into account the priority(the setting of values by default in headings of blocks/functions/modules has the highest

priority). The following fragment represents source code of theDefaultValues1 procedure with the most typical examples of its usage.

In[3079] := DefaultValues1[x_ /; BlockFuncModQ[x]]:= Module[{d ={}, h, k, a = {SetAttributes[String, Listable]}, b = Map[ToString, Args[x]], c = Map[ToString, DefaultValues[x]]}, ClearAttributes[ToString, Listable]; If[b != {}, For[a = 1, a <=

Length[b], a++, h = b[[a]]; If[! StringFreeQ[h, “_:”],

AppendTo[d, ToExpression[“ {” <> ToString[a] <> “}:> ” <> StringTake[h, {Flatten[StringPosition[h, “_:”]][[2]] + 1,–1}]]]]]]; If[c != {}, If[c != {}, c = ToExpression[Mapp[StringReplace, Mapp[StringReplace, c,

{“HoldPattern[Default[” <> ToString[x]–> “{“, “]]”–> “}”}], {”{, “–> “{“, “{}”–>

“{2015}”}]]]; h = c[[1]][[1]]; If[Op[h] == {2015}, a = {}; For[k = 1, k <= Length[b], k++, AppendTo[a, ToExpression[ToString[{k}] <> ” :> ” <> ToString[c[[1]][[2]]]]]]; c

= a]; If[PosIntListQ[h] && Length[h] > 1, a = {}; b = h; For[k = 1, k <= Length[b], k++, AppendTo[a, ToExpression[ToString[{k}] <> ” :> ” <> ToString[c[[1]][[2]]]]]]; c

= a]]; If[d == {}&& c == {}, Return[{}],

c = Sort[Join[d, c], Op[#1][[1]][[1]] <= Op[#2][[1]][[1]] &]]; {k, h}= {1, {}}; While[k

<= Length[c]–1, AppendTo[h, If[Op[c[[k]]][[1]] == Op[c[[k + 1]]][[1]], k + 1]]; k++];

Select[ReplacePart[c, Mapp[Rule, Select[h, # != “Null” &], Null]], ! SameQ[#, Null]

&]]

In[3080] := Default[G] = 500; G[x_, y_., z_: 90] := {x, y, z};

DefaultValues1[G]

Out[3080]= {{1}:> 500, {2}:> 500, {3}:> 90}

In[3081]:= Default[S2, 2, 3] = 90; S2[x_, y_., z_] := {x, y, z};

DefaultValues1[S2]

Out[3081]= {{1}:> 90, {2}:> 90}

In[3082]:= Default1[S3, {1, 2, 3}, {42, 47, 25}]; S3[x_: 500, y_., z_.] := {x, y, z};

DefaultValues1[S3]

Out[3082]= {{1}:> 500, {2}:> 47, {3}:> 25}

In[3083]:= Default[S4, 2] = 2015; S4[x_: 500, y_: 47, z_: 42] := {x, y, z};

DefaultValues1[S4]

Out[3083]= {{1}:> 500, {2}:> 47, {3}:> 42}

In[3084]:= Default[S5, 2] = 90; S5[x_, y_: 500, z_: 42] := {x, y, z}; DefaultValues1[S5]

Out[3084]= {{2}:> 500, {3}:> 42}

In[3085]:= Default1[V3, {1,2,3,4}, {a, b, c, d}]; V3[x_., y_., z_., t_.] := {x,y,z,t};

DefaultValues1[V3]

Out[3085]= {{1}:> a, {2}:> b, {3}:> c, {4}:> d}

In[3086]:= Default1[V4, {1, 2, 3, 4}, {a, b, c, d}]; V4[x_., y_: 90, z_., t_: 500] := {x, y, z, t}; DefaultValues1[V4]

Out[3086]= {{1}:> a, {2}:> 90, {3}:> c, {4}:> 500}

Definition of theDefaultValues1 procedure along with the standard means uses our means such asArgs, BlockFuncModQ, Mapp, PosIntListQ andOp that are considered in the present book and in [28-33]. Thus, our procedure DefaultValues1 rather significantly expands the possibilities of the standard DefaultValues function,and quite it replaces on condition of existence of the packageAVZ_Package [48] uploaded into the

currentMathematica session.

Considering existence of 2 admissible mechanisms of assignment of values by default to formal arguments of the blocks, functions and modules, the problem of definition of this kind of values for objects of the specified type represents quite certain interest. In this connexion theDefaultsQ procedure solves the given problem whose callDefaultsQ[x]

returnsTrue if definitions of blocks, functions or modulesx contain values by default for their formal arguments, andFalse otherwise. Whereas the procedure callDefaultsQ[x,y]

where the second argumenty –an undefinite variable– in addition throughy returns the list of the used types of values by default {“_.”, “_:”}. The next fragment represents source code of theDefaultsQ procedure along with the most typical examples of its usage.

In[2776]:= DefaultsQ[x_ /; BlockFuncModQ[x], y___] := Module[{c = {}, d, a = Args[x], b = {“_.”, “_:”}, k = 1}, a = Map[ToString, If[NestListQ[a], a[[1]], a]];

While[k <= Length[a], d = a[[k]]; If[! StringFreeQ[d, b[[1]]], AppendTo[c, b[[1]]], If[! StringFreeQ[d, b[[2]]], AppendTo[c, b[[2]]]]]; k++]; If[c == {}, False, If[{y}!=

{}&& ! HowAct[y], y = DeleteDuplicates[Flatten[c]]]; True]] In[2777]:=

PureDefinition[G]

Out[2777] = {”G[x_., y_.]:= x+ y“, “G[x_, y_, z_]:= x*y*z“,

“G[x_, y_, z_, h_]:= x*y*z*h”}

In[2778]:= {DefaultsQ[G, t], t}

Out[2778]= {True, {“_.”}}

In[2779]:= Default[S, 1] = 90; S[x_., y_: 500, z_] := x + y + z;

Kr[x_, y_, z_] := Block[{}, x*y*z]

In[2780]:= {Map9[DefaultsQ, {S, Kr}, {v1, v2}], {v1, v2}}

Out[2780]= {{True, False}, {{“_.”, “_:”}, v2}}

Along with attributes and values by default for formal arguments of a block, function or module, these objects can use the mechanism ofoptions. First of all, the mechanism ofoptions is rather widely used by the system means. So, for a number of functions in theMathematica system(in particular, thePlot function), the options available both for

Dans le document Extension of Mathematica systemfunctionality (Page 192-200)