[Aimmath-commit] AIM/WEB-INF/maple Random.mpl,1.12,1.13
Brought to you by:
gustav_delius,
npstrick
|
From: <mo...@us...> - 2003-12-20 21:43:00
|
Update of /cvsroot/aimmath/AIM/WEB-INF/maple
In directory sc8-pr-cvs1:/tmp/cvs-serv24342
Modified Files:
Random.mpl
Log Message:
A bug fix in `Nice/Trinomial`()
Index: Random.mpl
===================================================================
RCS file: /cvsroot/aimmath/AIM/WEB-INF/maple/Random.mpl,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** Random.mpl 15 Oct 2003 15:37:22 -0000 1.12
--- Random.mpl 20 Dec 2003 21:42:57 -0000 1.13
***************
*** 466,485 ****
`Package/Assign`(
`Nice/Binomial`::InertExpr,
! "Produces a \"nice\" binomial from its arguments (which is more complicated than it sounds). If one looks through the problems assigned in a typical calculus or precalc book, one will notice that there are certain rules that authors tend to follow when designing \"nice\" questions. This procedure attempts to produce a \"nice\" random binomial in @x@ that is a sum of a monomial in @x@ and a constant term in a random order. The defaults for the degree of the monomial and the two coefficients can be overriden by supplying the appropriate arguments. The argument @x@ is mandatory and can be any algebraic expression or Inert Expression.",
! proc(_x,deg,arange,brange)
! local n,a,b,nr,ar,br,i,x;
- x:=Rand(_x);
# defaults
! nr:=[1,[1..3]];
ar:=[-3..-1,1..3];
br:=[-3..-1,1..3];
# overriden
! if nargs>1 then nr:=deg fi;
if nargs>2 then ar:=arange fi;
if nargs>3 then br:=brange fi;
!
! n:=Rand(nr);
# don't let them both be negative
--- 466,488 ----
`Package/Assign`(
`Nice/Binomial`::InertExpr,
! "Produces a \"nice\" binomial from its arguments (which is more complicated than it sounds). If one looks through the problems assigned in a typical calculus or precalc book, one will notice that there are certain rules that authors tend to follow when designing \"nice\" questions. This procedure attempts to produce a \"nice\" random binomial of the form @a*x^n+b*y^m@ where @a:=Rand(arange)@, @b:=Rand(brange)@, @x:=Rand(_x)@, @y:=Rand(_y)@, @n:=Rand(deg)@, and @m:=Rand(ydeg)@. Only the argument @x@ is mandatory. Both @x@ and @y@ can be any any algebraic expression or Inert Expression.",
! proc(_x,deg,arange,brange,_y,ydeg)
! local n,a,b,ar,br,i,x,y,m;
# defaults
! # x:=x;
! n:=Rand([1,[1..3]]);
ar:=[-3..-1,1..3];
br:=[-3..-1,1..3];
+ y:=1;
+ m:=1;
# overriden
! if nargs>0 then x:=Rand(_x) fi;
! if nargs>1 then n:=Rand(deg) fi;
if nargs>2 then ar:=arange fi;
if nargs>3 then br:=brange fi;
! if nargs>4 then y:=Rand(_y) fi;
! if nargs>5 then m:=Rand(ydeg) fi;
# don't let them both be negative
***************
*** 498,502 ****
if type(b,algebraic) then
b:=abs(b): break
! elif type(b,algebraic) then
a:=abs(a): break
fi
--- 501,505 ----
if type(b,algebraic) then
b:=abs(b): break
! elif type(a,algebraic) then
a:=abs(a): break
fi
***************
*** 507,518 ****
od:
! # if its degree 1 you can use both coefficients
! if n=1 then
if `aim/StartsNegative`(a) then
! return Plus(b,Times(a,x));
elif `aim/StartsNegative`(b) then
! return Plus(Times(a,x),b);
else
! return Plus(Rand(Permute(Times(a,x),b)));
fi;
# otherwise we only use one coefficient unless its overriden
--- 510,521 ----
od:
! # if both are degree 1 you can use both coefficients
! if n=1 and m=1 then
if `aim/StartsNegative`(a) then
! return Plus(Times(b,y),Times(a,x));
elif `aim/StartsNegative`(b) then
! return Plus(Times(a,x),Times(b,y));
else
! return Plus(Rand(Permute(Times(a,x),Times(b,y))));
fi;
# otherwise we only use one coefficient unless its overriden
***************
*** 522,526 ****
# overridden... use b
if nargs>3 then
! return Plus(b,Times(a,ToThe(x,n)));
# default.. don't use b
else
--- 525,529 ----
# overridden... use b
if nargs>3 then
! return Plus(Times(b,ToThe(y,m)),Times(a,ToThe(x,n)));
# default.. don't use b
else
***************
*** 531,535 ****
# overridden... use both
if nargs>3 then
! return Plus(Times(a,ToThe(x,n)),b);
# only a was overidden, so ignore b
elif nargs=3 then
--- 534,538 ----
# overridden... use both
if nargs>3 then
! return Plus(Times(a,ToThe(x,n)),Times(b,ToThe(y,m)));
# only a was overidden, so ignore b
elif nargs=3 then
***************
*** 543,547 ****
# b overridden... use both
if nargs>3 then
! return Plus(Rand(Permute(b,Times(a,ToThe(x,n)))));
# only a was overidden, so ignore b
elif nargs=3 then
--- 546,550 ----
# b overridden... use both
if nargs>3 then
! return Plus(Rand(Permute(Times(b,ToThe(y,m)),Times(a,ToThe(x,n)))));
# only a was overidden, so ignore b
elif nargs=3 then
***************
*** 549,553 ****
# default...use just one in either order
else
! return Rand(Plus(Rand(Permute(b,ToThe(x,n)))),Plus(1,Times(a,ToThe(x,n))));
fi
fi;
--- 552,558 ----
# default...use just one in either order
else
! return Rand(Fn(Plus,Permute(b,ToThe(x,n))),
! Plus(1,Times(a,ToThe(x,n)))
! );
fi
fi;
***************
*** 559,579 ****
`Nice/Trinomial`::InertExpr,
"Produces a \"nice\" trinomial in @x@. See #Nice/Binomial# for more info.",
! proc(_x,deg,arange,brange,crange)
! local n,m,a,b,c,nr,ar,br,cr,i,typ,x;
!
! x:=Rand(_x);
# defaults
! nr:=[1..3];
ar:=[-3..-1,1..3];
br:=[-3..-1,1..3];
cr:=[-3..-1,1..3];
# overriden
! if nargs>1 then nr:=deg fi;
if nargs>2 then ar:=arange fi;
if nargs>3 then br:=brange fi;
if nargs>4 then cr:=crange fi;
- m,n:=op(sort(Rand(List([nr],2))));
b:=Rand(br);
# don't let both a and c be negative
--- 564,591 ----
`Nice/Trinomial`::InertExpr,
"Produces a \"nice\" trinomial in @x@. See #Nice/Binomial# for more info.",
! proc(_x,deg,arange,brange,crange,_y,ydeg,_z,zdeg)
! local m,n,p,a,b,c,nr,ar,br,cr,i,typ,x,y,z,xp,yp,zp;
# defaults
! # x:=x;
! m:=Rand(1..3);
ar:=[-3..-1,1..3];
br:=[-3..-1,1..3];
cr:=[-3..-1,1..3];
+ y:=x;
+ n:=Rand(1..3);
+ z:=1;
+ p:=1;
# overriden
! if nargs>0 then x:=Rand(_x) fi;
! if nargs>1 then m:=Rand(deg) fi;
if nargs>2 then ar:=arange fi;
if nargs>3 then br:=brange fi;
if nargs>4 then cr:=crange fi;
+ if nargs>5 then y:=Rand(_y) fi;
+ if nargs>6 then n:=Rand(ydeg) fi;
+ if nargs>7 then z:=Rand(_z) fi;
+ if nargs>8 then p:=Rand(zdeg) fi;
b:=Rand(br);
# don't let both a and c be negative
***************
*** 603,625 ****
# three types possible
if `aim/StartsNegative`(a) then
! typ=1
elif `aim/StartsNegative`(c) then
! typ=Rand(2,3)
else
typ:=Rand(1..3)
fi;
if typ=1 then
if nargs<=3 then b:=Rand(-1,1) fi;
if nargs<=2 then a:=Rand(-1,1) fi;
! return Plus(c,Times(b,ToThe(x,m)),Times(a,ToThe(x,n)))
elif typ=2 then
if nargs<=2 then a:=1 fi:
if nargs<=4 then c:=Rand(-1,1) fi:
! return Plus(Times(a,ToThe(x,n)),Times(b,ToThe(x,m)),c)
else
if nargs<=2 then a:=1 fi:
if nargs<=3 then b:=Rand(-1,1) fi:
! return Plus(Times(a,ToThe(x,n)),Times(b,ToThe(x,m)),c)
fi:
end
--- 615,641 ----
# three types possible
if `aim/StartsNegative`(a) then
! typ:=1
elif `aim/StartsNegative`(c) then
! typ:=Rand(2,3)
else
typ:=Rand(1..3)
fi;
+ xp:=`if`(m=1,x,ToThe(x,m));
+ yp:=`if`(n=1,y,ToThe(y,n));
+ zp:=`if`(p=1,z,ToThe(z,p));
+
if typ=1 then
if nargs<=3 then b:=Rand(-1,1) fi;
if nargs<=2 then a:=Rand(-1,1) fi;
! return Plus(Times(c,zp),Times(b,yp),Times(a,xp))
elif typ=2 then
if nargs<=2 then a:=1 fi:
if nargs<=4 then c:=Rand(-1,1) fi:
! return Plus(Times(a,xp),Times(b,yp),Times(c,zp))
else
if nargs<=2 then a:=1 fi:
if nargs<=3 then b:=Rand(-1,1) fi:
! return Plus(Times(a,xp),Times(b,yp),Times(c,zp))
fi:
end
|