rationalize
-- transform an
expression into a rational expressionrationalize(
object)
transforms the
expression object
into an equivalent rational expression
by replacing non-rational subexpressions by newly generated
variables.
rationalize(object, <, inspect <,
stop>>)
object |
- | an arithmetical expression or a set or list of such expressions |
inspect |
- | subexpressions to operate on: a set of types, or a procedure, or NIL . The default is NIL , i.e., all subexpressions
are to be inspected. |
stop |
- | subexpressions to be leaft unchanged: a set of types,
or a procedure, or NIL .
The default is the set { DOM_INT , DOM_RAT , DOM_IDENT } , i.e.,
integers, rational numbers and identifiers are not replaced by
variables. |
a sequence consisting of the rationalized object and a set of substitution equations.
indets
, maprat
, rewrite
, simplify
, subs
rationalize(
object
, inspect
,
stop
)
``walks'' recursively through the
expression tree of object
as long as the types of the
subexpressions are in inspect
. All non-rational
subexpressions of a type not matching stop
are replaced by
variables D1
, D2
, etc.
rationalize
returns a sequence (rat,
subsSet)
. The rationalized object rat
contains new
variables, which are specified by the set of ``substitution equations''
subsSet
. The relation object = subs(rat,
subsSet)
holds.inspect
is NIL
, all subexpressions are inspected.
If inspect
is a set of types, all subexpressions matching
one of these types are inspected. If inspect
is a
procedure, all subexpressions x
, say, with
inspect(x) = TRUE
are inspected.
Any subexpression not matching inspect
is replaced by a
variable.
stop
is NIL
, then all inspected non-rational
subexpressions are replaced by variables. If stop
is a set
of types, any non-rational subexpression matching one of these types is
left untouched. If stop
is a procedure, any non-rational
subexpression x
, say, with stop(x) = TRUE
is
leaft untouched.inspect
and stop
may be
strings as returned by the type
function, or domain types such as
DOM_INT
, DOM_RAT
etc.rationalize
operates on single arithmetical
expressions as well as on lists and sets of expressions:
>> rationalize(2*sqrt(3) + 0.5*x^3)
3 1/2 2 D2 + D1 x , {D1 = 0.5, D2 = 3 }
>> rationalize([(x - sqrt(2))*(x^2 + sqrt(3)), (x - sqrt(2))*(x - sqrt(3))])
2 1/2 1/2 [(x - D3) (D4 + x ), (x - D3) (x - D4)], {D3 = 2 , D4 = 3 }
rationalize
allows to specify which kinds
of subexpressions are to be inspected and which kinds of subexpressions
are to be leaft unchanged. In the following call, the subexpression
x^3
(of type "_power"
) is not inspected and
replaced by a variable:
>> rationalize(2*sqrt(3) + 0.5*x^3, {"_plus", "_mult"})
3 1/2 2 D5 + D6 D7, {D6 = x , D7 = 0.5, D5 = 3 }
In the following call, all subexpressions are inspected. Neither floating point numbers nor integers nor identifiers are replaced:
>> rationalize(2*sqrt(3) + 0.5*x^3, NIL, {DOM_FLOAT, DOM_INT, DOM_IDENT})
3 1/2 2 D8 + 0.5 x , {D8 = 3 }
D1
, D2
etc. instead of X1
, X2
etc.