       Re: IsExact

• To: mathgroup at smc.vnet.net
• Subject: [mg80539] Re: IsExact
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Sun, 26 Aug 2007 02:51:47 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <falsi4\$gfh\$1@smc.vnet.net>

```carlos at colorado.edu wrote:

> Let c be a 1D list of scalar coefficients, numeric or symbolic,
> real or complex. No entry is a list. Examples:
>
> ClearAll[n,x,y,a,a1,a2,b,r];
> c1={1,2*I/5,E^(25*n),3/4+I,Cos[n*x*Pi],y*Sqrt[-5]};
> c2={a/b,r+2/5,a1,,,,,a2};
> c3={1.5,0,Sqrt,0,4};
> c4={(r+0.5)/3,3/7,3+Sin[4*x*y]};
> c5={1,2,3,4,5,6}+0.0;
> c6={N[x]};
>
> I need a function IsExact[c] that returns False if
> at least one entry of c is floating, or if it contains one
> floating number; else True.  For example, tests on
> c1 and c2  should return True; the others False.
>
> Any simple way to implement this? It should work on V.5.

I believe you are already aware that any global value for the symbols
used in the lists may affect the result in one way or another (so the
ClearAll).

Nevertheless, you will have to put a hold on
N[some_symbolic_expression], since after evaluation the element becomes
just some_symbolic_expression. Compare the result from c6 and c7.

Below, the function exactQ accepts a one dimensional list and returns
*True* only if none of its elements has head *Real* or *N*.

In:=

exactQ[(lst_List)?VectorQ] := FreeQ[lst, _Real | N]

ClearAll[n, x, y, a, a1, a2, b, r];
c1 = {1, 2*(I/5), E^(25*n), 3/4 + I, Cos[n*x*Pi],
y*Sqrt[-5]};
c2 = {a/b, r + 2/5, a1, Null, Null, Null, Null, a2};
c3 = {1.5, 0, Sqrt, 0, 4};
c4 = {(r + 0.5)/3, 3/7, 3 + Sin[4*x*y]};
c5 = {1, 2, 3, 4, 5, 6} + 0.;
c6 = {N[x]};
c7 = {HoldForm[N[x]]};

exactQ /@ {c1, c2, c3, c4, c5, c6, c7}

{c6, c7}

Out=
{True, True, False, False, False, True, False}

Out=
{{x},{N[x]}}

Implemented and tested on Mathematica 5.2 for Microsoft Windows (June
20, 2005).

--
Jean-Marc

```

• Prev by Date: Re: JLink
• Next by Date: Re: Solving Nonlinear Equations
• Previous by thread: Re: IsExact
• Next by thread: Re: IsExact