1 /* %wc_tols lists all tol[n] contained in the list, nested list
2 or equation it gets as its argument. */
4 %wc_tols(wc_x):=block([vars,retval:[]],
5 /* A list of all variables contained in wc_x */
8 if not(freeof('tol,i)) then
13 /* %wc_tolrenumber renumbers all tol[n] contained in wc_x to start
16 %wc_tolrenumber(wc_x,startnum):=block(
18 oldtols:%wc_tols(wc_x)
23 i=tol[startnum:startnum+1],
32 /* wc_tolappend appends a list of element values to another renumbering all tol[] found in both lists
33 so they won't conflict. */
35 wc_tolappend([wc_args]):=block([wc_retval:[],wc_numberoftols:1],
36 for wc_i in wc_args do
38 wc_retval:append(wc_retval,%wc_tolrenumber(wc_i,wc_numberoftols)),
39 wc_numberoftols:wc_numberoftols+length(%wc_tols(wc_i))
44 /* wc_systematic returns a list of the results of all combinations one can get by assigning every tol[n] wc_valuespertol
45 values between -1 and 1. */
47 wc_systematic(wc_x,[wc_valuespertol]):=block(
49 %wc_tols:%wc_tols(wc_x),
50 /* The index x of the tol[x] being currently assigned a value to */
54 wc_numoftols:length(%wc_tols),
56 /* Default the number of values per tolerance parameter to 3 */
57 if wc_valuespertol=[] then wc_valuespertol:3 else wc_valuespertol:first(wc_valuespertol),
65 wc_tolnum:wc_tolnum+1,
66 wc_tol=((floor(mod(wc_num/(wc_valuespertol^wc_tolnum),wc_valuespertol)))/
67 (wc_valuespertol-1)*2-1)
75 wc_num,0,wc_valuespertol^wc_numoftols-1
80 wc_montecarlo(wc_x,wc_samples):=block(
82 %wc_tols:%wc_tols(wc_x),
85 wc_numoftols:length(%wc_tols),
104 /* Calculates the typical values of wc_x */
106 wc_typicalvalues(wc_x):=
108 makelist(i=0,i,%wc_tols(wc_x)),
112 /* Convenience function: Get the minimum, the typical and the maximal value */
114 wc_mintypmax(wc_x,[wc_params]):=block([wc_allvalues,wc_param1,min,wc_typ,max],
115 if length(wc_params) < 1 then
118 wc_param1:inpart(wc_params,1),
120 if wc_param1 > 0 then
121 wc_allvalues:wc_systematic(wc_x,wc_param1)
124 wc_allvalues:wc_montecarlo(wc_x,-wc_param1)
126 min:apply('min,wc_allvalues),
127 wc_typ:wc_typicalvalues(wc_x),
128 max:apply('max,wc_allvalues),
129 ['min=min,'typ=wc_typ,'max=max]
131 /* Make this function map over equations */
132 ?putprop('mintypmax, ?cdr([?mlist,?mequal]), '?distribute_over)$
134 /* A function that pretty-prints the value ranges the input values are in */
135 wc_inputvalueranges(wc_x):=apply('matrix,
137 append([lhs(wc_i)],wc_mintypmax(rhs(wc_i))),
142 /* A function that generates an equation out of the min, typ and maximum value for an element */
144 wc_mintypmax2tol(wc_tol,wc_min,wc_typ,wc_max):=
145 ((-2*wc_typ+wc_min+wc_max)*wc_tol^2)/2-((wc_min-wc_max)*wc_tol)/2+wc_typ;