From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 2080 invoked from network); 25 Mar 2021 15:53:11 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 25 Mar 2021 15:53:11 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1616687591; b=0I9sGJFnrwEHWKWQysIw5U64Vg3EDsbUEoUgNTmWw6yMoc7JfZ1699Yg+ABK1Pkuq0Ff39maO5 3OJDRDQYSP6sTLu6jEIS0YWvfitXJ/sxBnIIyRUi9MFi6RNP75c9zeMPMNcZoTeZrNWmgkFVzv 2JIaBIVpymQU0u5ILLzQBr/uvEFnWvr1gDd5eWvPNUy2XS3NNdRzSbpfwujLs8bO/CwSh7NLXs HN7E698Pv5HTB+KQxjilSAnFI+qP+js2MKl5YO3ocScIzcEgxUo4WrRi24ve0u+BlzxRua9BNH 5OEby5DZFZv5OeXYyYMK8mo+omWWU+4jkKdCmM0y6V1rCQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mta04.eastlink.ca) smtp.remote-ip=24.224.136.10; dmarc=none header.from=eastlink.ca; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1616687591; bh=Frvxk7ZpKXZ97HI6l1fBbNV/1Qq+oUuLMXKFSldlM78=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:MIME-Version:Date: Message-ID:Subject:From:To:DKIM-Signature; b=jq+1yKP3rHv992gmbYBuzvy9p7Gn77Fdn6/mESS1/p9+exD96WAn6yjJ1WauWDNIgpk4ylsmo0 ij0t81DIT+L6mOaE57h1cV20+gKDZ+ZoPv6hg2dYvZgJ1fckVLk5LFcePHd+agWNrE/Iuy6wWQ t3/CKOiImQt3zlMIVnI9bkDz4Uun2LL6grKX8VlD5NyojF+LzfndVME0gzgurGFStmp6koxFk3 RoCqfYlcGina8gsvNXYOs57vQhCZeaiD0q/9xiUwUYDnP9+PpqlZ/fi4SBV8rLm0j7y/oDpGaF FacFaJX0hy4KvTq1e6OvYs5r+R4Ez2GbXxRXTLliUhGl3A==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-transfer-encoding: Content-type:MIME-version:Date:Message-id:Subject:From:To:Reply-To:Cc: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=1CNyP+cmkc2tmDZJ/WHXBbDTcIasDCnRDUG9+yoIcvQ=; b=zSfV7zxQE+eK5m5uGZLGuyTKbO 8QLiiI5a7RjEMfZT61celJx0ERclt+Xt1qiVzvST865GRRXfHpD6rZTQZK0kTqldDu+CdjOeZ5+5L UkVArWwWD1dXS/vLQCLvlKk2KtWeJFxKvR9w++JOwpd6w8SkDA/TdlxBOGOfe/hPxzzL29VogyiYa s/bzI/EnDnoWOgwuQs0uN7zaHcKxxlMRCxp2SgHCloxmK6RJAtMuKIZO8eq/rEl03quXvSkUJl4Rp 2I0eorEMgn54hkBzSCkwRT/B4MRv8HIBKLSIqXVrGbGbQb1rOyrdVYFCYwBvVE8N60S3+7a5zyrhk QYux5JSQ==; Received: from authenticated user by zero.zsh.org with local id 1lPSIH-000Gas-A1; Thu, 25 Mar 2021 15:53:09 +0000 Authentication-Results: zsh.org; iprev=pass (mta04.eastlink.ca) smtp.remote-ip=24.224.136.10; dmarc=none header.from=eastlink.ca; arc=none Received: from mta04.eastlink.ca ([24.224.136.10]:39884) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) id 1lPSHi-000GDH-Ta; Thu, 25 Mar 2021 15:52:37 +0000 Received: from csp02.eastlink.ca ([71.7.199.167]) by mta04.eastlink.ca (Oracle Communications Messaging Server 8.0.2.2.20180531 64bit (built May 31 2018)) with ESMTPS id <0QQJ009KG7IP70B0@mta04.eastlink.ca> for zsh-users@zsh.org; Thu, 25 Mar 2021 12:52:32 -0300 (ADT) Received: from [192.168.0.3] ([24.207.90.194]) by Eastlink with ESMTP id PSHglGJIG54V7PSHglN5Gu; Thu, 25 Mar 2021 12:52:32 -0300 X-Authority-Analysis: v=2.4 cv=PJ/KRdmC c=1 sm=1 tr=0 ts=605cb1c0 a=zv49KfEsxEDzuN5AGO7r0Q==:117 a=zv49KfEsxEDzuN5AGO7r0Q==:17 a=IkcTkHD0fZMA:10 a=SAN9p1O2MzZhxUbnRNMA:9 a=QEXdDO2ut3YA:10 a=2Sff-5FkbYdzWncB_jrr:22 a=fCgQI5UlmZDRPDxm0A3o:22 X-Vade-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudehtddgkedvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecugfetuffvnffkpffmpdfqfgfvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefvhffukffffgggtgfgsehtkeertddtfeejnecuhfhrohhmpeftrgihucetnhgurhgvfihsuceorhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrqeenucggtffrrghtthgvrhhnpeetvefgtdfgueegveduhfelffegteegheeugfegveehkeeftdehjedugedutddtheenucfkphepvdegrddvtdejrdeltddrudelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvgedrvddtjedrledtrdduleegpdhhvghloheplgduledvrdduieekrddtrdefngdpmhgrihhlfhhrohhmpehrrgihrghnughrvgifshesvggrshhtlhhinhhkrdgtrgdprhgtphhtthhopeiishhhqdhushgvrhhsseiishhhrdhorhhgpdhgvghtqdgkihhprfgrshhsfigupehtrhhuvg X-Vade-Score: -100 X-Vade-State: 0 X-EL-IP-NOAUTH: 24.207.90.194 To: Zsh Users From: Ray Andrews Subject: arithmetic anomaly Message-id: <0227b30d-4f09-2c8b-1248-557859d875ce@eastlink.ca> Date: Thu, 25 Mar 2021 08:52:32 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-version: 1.0 Content-type: text/plain; charset=utf-8; format=flowed Content-transfer-encoding: 8bit Content-language: en-US X-Seq: 26601 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: So my nephew and I came up with different algorithms for working out a probability problem.  Here's both of them in a script and the output: #!/bin/zsh setopt force_float integer level= typeset -F term= typeset -F numerator= typeset -F denominator= for ((level=1; level<23; level++)); do # Ray:     numerator=     for ((term=1; term <= level; term++)); do         (( numerator += (level**(term - 1)) * (level - 1)**(level - term) ))     done     (( denominator = level**level ))     printf "%.0f / %.0f \n" "$(( numerator ))" "$(( denominator ))" # Brett:     numerator=1     for ((term=1; term < level; term++)); do         (( numerator = numerator * (level - 1) + level**term ))     done     (( denominator = level**level ))     printf "%.0f / %.0f \n" "$(( numerator ))" "$(( denominator ))" done ========================================= 1 / 1 1 / 1 3 / 4 3 / 4 19 / 27 19 / 27 175 / 256 175 / 256 2101 / 3125 2101 / 3125 31031 / 46656 31031 / 46656 543607 / 823543 543607 / 823543 11012415 / 16777216 11012415 / 16777216 253202761 / 387420489 253202761 / 387420489 6513215599 / 10000000000 6513215599 / 10000000000 185311670611 / 285311670611 185311670611 / 285311670611 5777672071535 / 8916100448256 5777672071535 / 8916100448256 195881901213181 / 302875106592253 195881901213181 / 302875106592253 7174630439858727 / 11112006825558016 7174630439858727 / 11112006825558016 282325794823047136 / 437893890380859392 282325794823047136 / 437893890380859392 11878335717996660736 / 18446744073709551616 11878335717996660736 / 18446744073709551616 532092356706984001536 / 827240261886336827392 532092356706984001536 / 827240261886336827392 25283323623228810723328 / 39346408075296541507584 25283323623228810723328 / 39346408075296541507584 1270184310304975863414784 / 1978419655660313627328512 1270184310304975863414784 / 1978419655660313627328512 67267626542454044570419200 / 104857600000000000000000000 67267626542454044570419200 / 104857600000000000000000000 3745435018385981790358601728 / 5842587018385982340114415616 3745435018385981790358601728 / 5842587018385982340114415616 218733549978113966650274349056 / 341427877364219559508793360384 218733549978113931465902260224 / 341427877364219559508793360384 #               ^  Ooops! ... both work.  But look at the last pair. The two diverge in the numerator, why is that?  If there was some rounding of fractions or something I'd understand that an error would eventually pop up, but there's no divisions, only whole number integer arithmetic. It's puzzling that the two are perfect until the numbers get big, but it's not close to overflow and even then the denominator is bigger and has no issue.  Obviously no bridges are going to fall down for an error in the 17th digit, but I'm curious.