Bill Allombert on Fri, 16 Feb 2024 12:20:31 +0100
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Numerical instability in extracting base B digits of the fractional part of real
|
- To: pari-dev@pari.math.u-bordeaux.fr
- Subject: Re: Numerical instability in extracting base B digits of the fractional part of real
- From: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
- Date: Fri, 16 Feb 2024 12:16:59 +0100
- Arc-authentication-results: i=1; smail; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1708082424; c=relaxed/relaxed; bh=IKF+WDlgOY/ZvenQeX9xAOA57m8bYKze3TzluurM8Q0=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:Mail-Followup-To: References:MIME-Version:Content-Type:Content-Disposition: In-Reply-To; b=X+KTTijiYG5ltEEXVzD43n+wObtYUmXMnYuP0lVarhLxzvzwlUf+tL8FsXe61IGcPB52Fs/XJuP9tpd+QcNAgO0db1LArlSFMOw2xu1IWgXsEd1IC1EP/4o4ze5NAKMBgn+l11bBpnBWHhW5Jj9GqOQCalWTg0slaFEUTmh7wwpjbVN32UF2qohnc3LUwjlQAje3itTel4lm6A59//TiP0qK+PmDDWHdNb2LNY8mD2MtRQp3wWsOJRGrJfUUy1xUgseS7vwoeP0jGsEtATCWGyHBMr5DeW+A/vD1cjSixM9j+S2hRQIo/gtP2whTFB8XTUgkXBfSJU+exwxa7925Yb7I+7HanJ/SoRi+htrHPQsNeLvMQSTnK+HduJ8PzErHoSqxH/l4kNWFEIeDmAv/F6itbqBz4i0vC0nhEtDAe14LY3zGE+ExkbE4dac4IJa4UZcBUJpo+d+bzPrIyZ4UqRnubpkGNH5rMzxU10bla+qt5/++eTOrT+zckvNMOBqq07Wuj39pwdSIerhV02Cn25NAn9YlvblUSyn0Q2MRka9CWQ+wZBngHjJk3ZwlkUglGwWh/FX7eUZFd+U1WXxHn5MKZRHbslp/OSEsHjL1l+z+9F4JqXaWi9mHjECin3UyWH3W+feCtWXbIVbc5UZUa6cvGAcT1xoLwdTku3N8BSE=
- Arc-seal: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1708082424; cv=none; b=jIqY0k+jD7AxNF165VFLtijHpFS3gdLNyFcTHokMM9M7F0Dtq4hOPlD5kriKAfR9rNVpoIez31usWKI4GSvpE/I5zNUvASX3KK3vEx3EkS8FyQ6clSl1iw9hbh+VcoaZae2cLb244E+SQOfIVXoq26BfH7Xa7/seB7j8z5fRMmumXhi20YiRlNpOBOFDUACW+B419kPVonhZU2K1avKR1Gf0M1bQ+DREdjJOqjIkPXINxWVKlunzz2gUa/YgXQQoBxfWIIlFZf7zOvTeYXXiihsvCXj1X+blclouyuOhd0fNX+IsyHiJ0xrdxnDxfymHAcEHLic5WH5AmX2Bj3baz2IRqc/Iducb1FqVvsc7OtunshXOclDTIaUKNiGUTqexhEOJ1+w6a+BIl0LdwGLyY/FNIlsShSv8zEFFqbVf8OIBlnCci0wb8VO8qiAOgfjeMRWDXwvWFHQkNoHo/TvcLdjsIg0KDAb291/34CZmtP7BBfrQOHzwRJ+2S+fmJxUUNHjj0XD5KL7q5yxxlwuPxw96Gd7/8/zM5DAYgkkj45TNfBUZakPggD2XBiyrLFQ+e/SJU2b3ptizRIMWc9QM05MUXFG5Jw9P7294wgtdYlL7sbRm2UAM28Xum8DxF0XU4z6i6NBt2hxS5s+NYrT+DmlrEgOqrO0F6UUN9V3petw=
- Authentication-results: smail; dmarc=none header.from=math.u-bordeaux.fr
- Authentication-results: smail; arc=none
- Delivery-date: Fri, 16 Feb 2024 12:20:31 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=math.u-bordeaux.fr; s=2022; t=1708082424; bh=IKF+WDlgOY/ZvenQeX9xAOA57m8bYKze3TzluurM8Q0=; h=Date:From:To:Subject:References:In-Reply-To:From; b=sNRi4eiESbgFGao3nSOKbLF/o2k8GGKLuNfJRtSgalvwSBWwW6o+MNZ+0t8GJAlLK pQDA2LKZi3vmVsSqqlZT7MM5Wmga+eOvllUHO6jwjVEwokCxB52Sad5FUkey+TySkh i/prrEQmajLxLFPCyU0Yhiz8p94K0ZsOcxq4GO15IlGYOA94lXyuFqyFBm+utZsI/j bTip8Rjzs1VyK7oBcA7PADFkaQrwOT5E1FYtUxmrxjEXzNT7BzBjbYtA6tKEv6VLTz Iz5L4BRau57VBE0S9i1IdPTtEVYiz4gxkB9GCXGU+1J1C6RZZfJ3tvJoYHvMcdfEGo msTUdP0BCWsjOS5m+wl6EEDPWuJSxZPxjh250Hk08g497872Dvc0ogSg1QttSGIv5K P07MHGhRPN62Uh5HGnFVUHgP73qNiEywtvHKM5y/l2f/5aOQ50z/HST0dgAuXGBUyq olY6g9giCaGGitvjaNh6IvfYSJrEl6mAsoz9ifjsRHRGzM6SholXRzQ5YIZ78DePGV gqJhbJ4xy4d85OjucRHpuKXeElbIB5VBqaoyzlH51F8F8qZq4D3jNCEoEu/vNsMypU 4okfDuftlMoFOzBoBDVeNynd+c9HX8T+AsI1Fv1fNtZwqEX6YXFgSYknq+rQmdXMCH JMuO5q9cbyR03q2d6iSP/+D0=
- In-reply-to: <CAGUWgD9jh04yWKo8gnd=oT8sxt---hQiq65tGc0cM6Mxnk3wdw@mail.gmail.com>
- Mail-followup-to: pari-dev@pari.math.u-bordeaux.fr
- References: <CAGUWgD9jh04yWKo8gnd=oT8sxt---hQiq65tGc0cM6Mxnk3wdw@mail.gmail.com>
On Fri, Feb 16, 2024 at 09:46:17AM +0200, Georgi Guninski wrote:
> I don't claim this is a bug, but it appears very counter intuitive to me.
>
> Give real number $A$ and positive integer $B$, I am trying to get
> the base $B$ digits of frac(A) with given precision (they may be infinite).
>
> So far the only reliable way to do this is to compute C=floor(B^L*A)
> and then write C in base B.
Yes, this the correct solution: digits(floor(B^L*A),B)
> I found another algorithm which agrees with chatGPT solution:
If it agree with chatGPT, it is probably wrong...
Your code do "A=C-d;" which leads to cancellation and accuracy loss.
This is a property of floating point numbers.
? a=.33
%6 = 0.33000000000000000000000000000000000000
? a*10-3
%7 = 0.30000000000000000000000000000000000000
? b=a*10-3
%8 = 0.30000000000000000000000000000000000000
? b*10-3
%9 = -2.350988701644575016E-38
The formula B^L*A does only multiplication, which does not have this problem
Cheers,
Bill