[Date Index]
[Thread Index]
[Author Index]
RE: Problem with implementing the following functions
*To*: mathgroup at smc.vnet.net
*Subject*: [mg23944] RE: [mg23874] Problem with implementing the following functions
*From*: "David Park" <djmp at earthlink.net>
*Date*: Fri, 16 Jun 2000 00:57:31 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
> -----Original Message-----
> From: Matt Herman [mailto:Henayni at hotmail.com]
To: mathgroup at smc.vnet.net
>
> Hello,
>
> here are the functions
>
> q[(Sqrt[x_] + (z_))/(y_), 1] := (x - (Floor[(z + Sqrt[x])/y]*y -
> z)^2)/y
>
> q[(Sqrt[x_] + (z_))/(y_), n_] :=
> q[(z + Sqrt[x])/y, n - 2] +
> a[(z + Sqrt[x])/y, n - 1]*(
> m[(z + Sqrt[x])/y, n - 1] - m[(z + Sqrt[x])/y, n])
>
> a[(Sqrt[x_] + (z_))/(y_), 0] := Floor[(z + Sqrt[x])/y]
>
> a[(Sqrt[x_] + (z_))/(y_), n_] :=
> Floor[(m[(z + Sqrt[x])/y, n] + Sqrt[x])/q[(z + Sqrt[x])/y, n]]
>
> m[(Sqrt[x_] + (z_))/(y_), 1] := Floor[(z + Sqrt[x])/y]*y - z
>
> m[(Sqrt[x_] + (z_))/(y_), n_] :=
> a[(z + Sqrt[x])/y, n - 1]*q[(z + Sqrt[x])/y, n - 1] -
> m[(z + Sqrt[x])/y, n - 1]
>
>
>
> For some reason mathematica gives me blank inputs when I do
> a[(9+Sqrt[18])/9,5] (or any n for that matter.
>
> Any ideas?
>
> Thanks,
>
> Matt
>
Matt,
Your basic problem is in pattern matching. Mathematica builds ups its
algebraic expressions from Plus, Times and Power and you have to build up
your patterns the same way.
1/9*(9 + Sqrt[18])
FullForm[%]
1/9*(9 + 3*Sqrt[2])
Times[Rational[1, 9], Plus[9, Times[3, Power[2, Rational[1, 2]]]]]
So Mathematica does not divide by 9; it multiplies by Rational[1,9]. In
general it does not divide by y; it multiplies by Power[y,-1]. But in your
case we can just switch y from division to multiplication and vice versa
everywhere.
Secondly Mathematica has "simplified" Sqrt[18] to 3*Sqrt[2]. This does not
match your pattern. You have to use a pattern w_. Sqrt[x_], where w_. will
have the default value of 1 if it is missing from the expression. With these
changes your routines become:
q[(w_. Sqrt[x_] + (z_))y_, 1] := (x - (Floor[(z + w Sqrt[x])y]/y -
z)^2)y
q[(w_. Sqrt[x_] + (z_))y_, n_] :=
q[(z + w Sqrt[x])y, n - 2] +
a[(z + w Sqrt[x])y, n - 1]*(
m[(z + w Sqrt[x])y, n - 1] - m[(z + w Sqrt[x])y, n])
a[y_(w_. Sqrt[x_] + (z_)), 0] := Floor[(z + w Sqrt[x])y]
a[(w_. Sqrt[x_] + (z_))y_, n_] :=
Floor[(m[(z + w Sqrt[x])y, n] + w Sqrt[x])/q[(z + w Sqrt[x])y, n]]
m[(w Sqrt[x_] + (z_))y_, 1] := Floor[(z + w Sqrt[x])y]/y - z
m[(w Sqrt[x_] + (z_))y_, n_] :=
a[(z + w Sqrt[x])y, n - 1]*q[(z + w Sqrt[x])y, n - 1] -
m[(z + w Sqrt[x])y, n - 1]
However, when I tried to run your case I ran into RecursionLimit problems,
which I will leave to sharper minds to remedy.
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
Prev by Date:
**RE:Working Precision**
Next by Date:
**Re: rounding off numbers**
Previous by thread:
**Re: Problem with implementing the following functions**
Next by thread:
**Monte Carlo in Mathematica ?**
| |