[Aimmath-commit] AIM/WEB-INF/maple/aim Util1.mpl,1.2,1.3
Brought to you by:
gustav_delius,
npstrick
|
From: <gr...@us...> - 2004-01-09 08:09:02
|
Update of /cvsroot/aimmath/AIM/WEB-INF/maple/aim
In directory sc8-pr-cvs1:/tmp/cvs-serv12408
Modified Files:
Util1.mpl
Log Message:
Added NiceSqrt, NiceCoeff, NiceCoeffs and improvements to NiceFrac. - GG
Index: Util1.mpl
===================================================================
RCS file: /cvsroot/aimmath/AIM/WEB-INF/maple/aim/Util1.mpl,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Util1.mpl 25 Aug 2003 21:47:19 -0000 1.2
--- Util1.mpl 9 Jan 2004 08:09:00 -0000 1.3
***************
*** 153,156 ****
--- 153,179 ----
`Package/Assign`(
+ NiceSqrt::string,
+ "Returns @x@ in a nice form with respect to square roots,
+ which means ``as is'' if @x@ is not a real constant or
+ its square is not an integer. ",
+ proc(x)
+ local sqrx, x_;
+ if not type([x], [realcons]) then
+ `aim/LaTeX`(x);
+ else
+ sqrx := x^2;
+ x_ := (simplify @ expand @ combine)(x);
+ if not type(sqrx, integer) or type(x_, integer) then
+ `aim/LaTeX`(x_);
+ elif type(x_, `^`) then
+ cat("\\sqrt{ }", `aim/LaTeX`(op(1, x_)));
+ else
+ cat(`aim/LaTeX`(op(1, x_)), " \\sqrt{ }", `aim/LaTeX`(op([2, 1], x_)));
+ fi;
+ fi;
+ end
+ ):
+
+ `Package/Assign`(
NiceFrac::string,
"Return a nicely formatted rendition of the fraction @n@/@d@ as a
***************
*** 160,174 ****
<dd>if present, @n@/@d@ is treated as a term in a larger expression,
i.e. if @n@/@d@ = 0 then an empty string is returned or otherwise
! the operational sign (+ or -) is prepended;</dd>
<dt>@\"coef\"@ (or @\"coeff\"@)</dt>
<dd>if present, @n@/@d@ is treated as the coefficient of a term,
i.e. if @n@/@d@ = 1 or -1 then only an operational sign is returned
(+, in the former case, or - otherwise); in any case, as with
! @\"term\"@ an operational sign is prepended;</dd>
<dt>@\"lcoef\"@ (or @\"lcoeff\"@)</dt>
<dd>if present, @n@/@d@ is treated as the coefficient of a leading term,
i.e. if @n@/@d@ = -1 then only the operational sign - is returned,
! and if @n@/@d@ = 1 a null string is returned; in any case, an
! operational sign is prepended only if @n@/@d@ is negative;</dd>
<dt>@\"nocancel\"@</dt>
<dd>if present, @n@/@d@ is not cancelled to lowest terms;</dd>
--- 183,201 ----
<dd>if present, @n@/@d@ is treated as a term in a larger expression,
i.e. if @n@/@d@ = 0 then an empty string is returned or otherwise
! a binary operational sign (+ or -) is included;</dd>
! <dt>@\"lterm\"@</dt>
! <dd>if present, @n@/@d@ is treated as a term in a larger expression,
! i.e. if @n@/@d@ = 0 then an empty string is returned or if negative
! a unary - is included;</dd>
<dt>@\"coef\"@ (or @\"coeff\"@)</dt>
<dd>if present, @n@/@d@ is treated as the coefficient of a term,
i.e. if @n@/@d@ = 1 or -1 then only an operational sign is returned
(+, in the former case, or - otherwise); in any case, as with
! @\"term\"@ an operational sign is included;</dd>
<dt>@\"lcoef\"@ (or @\"lcoeff\"@)</dt>
<dd>if present, @n@/@d@ is treated as the coefficient of a leading term,
i.e. if @n@/@d@ = -1 then only the operational sign - is returned,
! and if @n@/@d@ = 1 a null string is returned; in any case, a
! operational sign (unary -) is included only if @n@/@d@ is negative;</dd>
<dt>@\"nocancel\"@</dt>
<dd>if present, @n@/@d@ is not cancelled to lowest terms;</dd>
***************
*** 180,184 ****
</dl>",
proc(n, d)
! local x, n_, d_, sign_, term, coef, lcoef, nocancel, textstyle;
if nargs = 1 or type(args[2], string) then
d_ := 1;
--- 207,211 ----
</dl>",
proc(n, d)
! local x, n_, d_, sign_, term, lterm, coef, lcoef, nocancel, textstyle;
if nargs = 1 or type(args[2], string) then
d_ := 1;
***************
*** 187,190 ****
--- 214,218 ----
fi;
term := member("term", [args]);
+ lterm := member("lterm", [args]);
coef := member("coef", [args]) or member("coeff", [args]);
lcoef := member("lcoef", [args]) or member("lcoeff", [args]);
***************
*** 202,211 ****
fi;
! if not nocancel and term and x = 0 then
return "";
elif not nocancel and (coef or lcoef) and x = 1 then
return sign_;
elif not nocancel and denom(x) = 1 then
! return cat(sign_, `aim/LaTeX`(x));
else
if nocancel then
--- 230,239 ----
fi;
! if not nocancel and (term or lterm) and x = 0 then
return "";
elif not nocancel and (coef or lcoef) and x = 1 then
return sign_;
elif not nocancel and denom(x) = 1 then
! return cat(sign_, NiceSqrt(x));
else
if nocancel then
***************
*** 216,227 ****
fi;
if textstyle then
! return cat(sign_, `aim/LaTeX`(n_), "/",
`if`(evalb(nops(d_) = 1), "", "("),
`aim/LaTeX`(d_),
`if`(evalb(nops(d_) = 1), "", ")"));
else
! return cat(sign_, "\\frac{", `aim/LaTeX`(n_), "}{", `aim/LaTeX`(d_), "}");
fi;
fi;
end
):
--- 244,339 ----
fi;
if textstyle then
! return cat(sign_, NiceSqrt(n_), "/",
`if`(evalb(nops(d_) = 1), "", "("),
`aim/LaTeX`(d_),
`if`(evalb(nops(d_) = 1), "", ")"));
else
! return cat(sign_, "\\frac{", NiceSqrt(n_), "}{", `aim/LaTeX`(d_), "}");
fi;
fi;
+ end
+ ):
+
+ `Package/Assign`(
+ NiceCoeff::string,
+ "Returns a nicely formatted rendition of @c x@ as a LaTeX string,
+ where @c@ is rendered using #NiceFrac#. It accepts the following
+ optional arguments
+ <dl>
+ <dt>@\"term\"@</dt>
+ <dd>if present, @c@ is treated as a term in a larger expression,
+ i.e. if @c@ = 0 then an empty string is returned or otherwise
+ a binary operational sign (+ or -) is included;</dd>
+ <dt>@\"lterm\"@</dt>
+ <dd>if present, @c@ is treated as the coefficient of a leading term,
+ i.e. like @\"term\"@ except an operational sign only occurs
+ if @c@ is negative;</dd>
+ <dt>@\"textstyle\"@</dt>
+ <dd>if present, @c@ is formatted in textstyle, i.e. using / between
+ numerator and denominator, and a multiplication . on the line
+ is inserted (by default, @c@ is formatted in displaystyle, i.e. in
+ @\\frac{..}{..}@ form);</dd>
+ <dt>@\"cdot\"@</dt>
+ <dd>if present, a \\cdot is inserted after a non-trivial coefficient.</dd>
+ </dl>",
+ proc(c, x)
+ local term, lterm, textstyle, cdot, fracargs;
+ term := member("term", [args]);
+ lterm := member("lterm", [args]);
+ textstyle := member("textstyle", [args]);
+ cdot := member("cdot", [args]);
+
+ if c = 0 then
+ return `if`(evalb(term or lterm), "", "0");
+ fi;
+
+ fracargs := `if`(term, "coef", NULL), `if`(lterm, "lcoef", NULL);
+ if not textstyle or denom(c) = 1 then
+ return cat(NiceFrac(c, fracargs),
+ `if`(evalb(cdot and abs(c) <> 1)," {\\cdot} ", " "), `aim/LaTeX`(x));
+ else
+ return cat(NiceFrac(c, fracargs, "textstyle"), " . ", `aim/LaTeX`(x));
+ fi;
+ end
+ ):
+
+ `Package/Assign`(
+ NiceCoeffs::string,
+ "For a sequence of arguments @c1, x1, c2, x2, ...@
+ returns a nicely formatted rendition of @c1 x1 + c2 x2 + ...@
+ as a LaTeX string, where the @ci@ are rendered using #NiceFrac#.
+ It accepts the optional argument @\"textstyle\"@ and
+ if present, @c@ is formatted in textstyle, i.e. using / between
+ numerator and denominator, and a multiplication . on the line
+ is inserted (by default, @c@ is formatted in displaystyle, i.e. in
+ @\\frac{..}{..}@ form). It also accepts the optional argument @\"cdot\"@
+ and inserts a \\cdot after a nontrivial coefficient if @\"textstyle\"@
+ is not used. If the number of non-string arguments is odd
+ the last non-string argument is treated as a constant coefficient.",
+ proc()
+ local passargs, args_, nargs_, i, expr;
+ passargs, args_ := selectremove(x -> member(x, {"textstyle", "cdot"}),
+ [args]);
+ nargs_ := nargs - nops(passargs);
+ passargs := op(passargs);
+ i := 1;
+ while i <= nargs_ and args_[i] = 0 do
+ i := i + 2;
+ od;
+ if nargs_ < i then
+ return 0;
+ elif nargs_ = i then
+ return NiceFrac(args_[i], passargs);
+ fi;
+ expr := NiceCoeff(args_[i], args_[i + 1], "lterm", passargs);
+ i := i + 2;
+ while i < nargs_ do
+ expr := expr, " ", NiceCoeff(args_[i], args_[i + 1], "term", passargs);
+ i := i + 2;
+ od;
+ if nargs_ = i then
+ expr := expr, " ", NiceFrac(args_[i], "term", passargs);
+ fi;
+ return cat(expr);
end
):
|