Re: questions about delayed expression.

• To: mathgroup at smc.vnet.net
• Subject: [mg19887] Re: questions about delayed expression.
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Sun, 19 Sep 1999 18:47:35 -0400
• References: <7s1q2l\$9oi@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Wen-Feng Hsiao <d8442803 at student.nsysu.edu.tw> wrote in message
news:7s1q2l\$9oi at smc.vnet.net...
> Hi,
>
>    The following is the process that I run in my notebook.
>
> In[1]:=
> a[x_] := x + 4
> b[x_] := -3 x + 8
>
> In[2]:=
> sola = x /. Solve[{a[x] == c}, x];
> solb = x /. Solve[{b[x] == c}, x];
>
> In[3]:=
> Inter[c_] := Interval[{sola[[1]], solb[[1]]}]
>
> In[4]:=
> Inter[.3]
> Inter[.4]
>
> Out[4]=
> \!\(Interval[{\(-4\) + c, \(8 - c\)\/3}]\)
>
> Out[5]=
> \!\(Interval[{\(-4\) + c, \(8 - c\)\/3}]\)
>
> My questions are:
> 1. Why Inter[.3] and Inter[.4] cannot be evaluated? Their results should
> not be the same. This is not my intention.

Inter[c_] := Interval[{sola[[1]], solb[[1]]}]

is effectively stored as it appears.
When this rule is used in evaluating Inter[.3], Mathematica looks on the right to
find occurrences of c that it must replace with .3; there are none; so it
returns Interval[{sola[[1]], solb[[1]]}]  which then evaluates sola[[1]] and
solb[[1]]} to give the result that you found.

We need to make the c's visible on the right of the soted definition of
Inter.

If we change the definion of Inter to

Inter[c_] = Interval[{sola[[1]], solb[[1]]}]

then the right side is evaluted before the rule is stored.
We now store

Inter[c_] = Interval[{-4 + c, (8-c)/3}]

and get

Inter[.3]
Inter[.4]

Interval[{-3.7, 2.56667}]

Interval[{-3.6, 2.53333}]

> 2. I don't know if there is any better way to extract the 'root(s)' from
> the output of 'Solve' command. The output form is {{x->root1}, {x-
> >root2}, ...{}}. If I use 'ReplaceAll'(/.) command, it will remain a list
> of solutions of x. It seems I can only use element operation to extract
> the root(s) from the solution list? In my case, I use sola[[1]] and
> solb[[1]].

We can  use

sola[[1, 1]]

1-4

Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

```

• Prev by Date: Re: Re: F[f_,x_]:=f[x] ?
• Next by Date: Real roots and other assumptions...
• Previous by thread: Re: questions about delayed expression.
• Next by thread: Relatively prime numbers