From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Shouran Ma Newsgroups: gmane.emacs.devel Subject: Re: Adding a generic mathematical library Date: Sat, 27 Jul 2024 21:07:33 +0200 Message-ID: <87o76ik616.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33354"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org, "Sergey Kostyaev" , "Philip Kaludercic" To: "Emanuel Berg" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jul 27 21:08:40 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sXmmV-0008Tn-Tz for ged-emacs-devel@m.gmane-mx.org; Sat, 27 Jul 2024 21:08:39 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sXmlZ-00061K-79; Sat, 27 Jul 2024 15:07:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sXmlY-00061A-AN for emacs-devel@gnu.org; Sat, 27 Jul 2024 15:07:40 -0400 Original-Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sXmlW-0001E7-AP for emacs-devel@gnu.org; Sat, 27 Jul 2024 15:07:40 -0400 Original-Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-52f022bd00cso233951e87.1 for ; Sat, 27 Jul 2024 12:07:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722107256; x=1722712056; darn=gnu.org; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=bhzIr2ZU3Of37dXXFg74kiaanu2e80d58JWZIwBC7tg=; b=j+WgL/svUmVzZIA6GiBLgiBKRCJ80QlM+ziRoX2leI1Inh7CHccH60p4x+aLi/lj0V kHNr2dXJ/2DeiWEYYM4axsMd94SZFVjvqORJstHEKljzveSaMz36EasA+JoBzFK3biI1 YSLNOjthNAlF/R+cwsVQAyZsZZsJasc2n9xlPpHd/FhYAiO6SEoo+1N3IKXabxJH+y61 Bstz9XujgtRG53TzVPp7F/3Z6t8brzUHnkarHabIypyWfGixP1rR5R3P0whqu7z5O2g8 rO2otbfjZ+tJYmznUJdkosBn6VYT6KsfNTPh+e+WcCZ/U6TCJo/KC3vC4pWjp6akpShC reqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722107256; x=1722712056; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bhzIr2ZU3Of37dXXFg74kiaanu2e80d58JWZIwBC7tg=; b=cBKgxwTD6i0yPZw9GPyuoezjo0NRGgWgChHN8LSrTyc2F8ca0IJO2+nhVxEcxGq8kM 3JBmsJEKxMoUJ3Un9ZEkNduDAdbE94+fZBB5HIATY5N+mtu1QSucIlBcIzzgvcz82JYI 5Qa3FRd7UY+caaMLfwqjNrnG25mmtvmOx2dHXGJlmOD0CNgPM7Bg9NqSKJ43etsLoadG pzPXgDFyRCGVBEEmFNPtzYiuYodZ+MRalWkb3Mt+/U0MuUSZpXca81hf4Ltap+4/PVca iafns6/iDI9V0S9fpRLBwrerabaLTZAF45HMqS+Gyuj+a0+4FqfuxOML38h3rbjQ0Fb7 o6Aw== X-Gm-Message-State: AOJu0YxIAAHiqadngR1Khwe1G3M4b/EcY+K8YLZehvC5EgvKHkkuwsf8 izjvPTZazJ7lDedSlkDOxklLaQcUq6ycx20f5CHJQ5/ZmtW1mHuu X-Google-Smtp-Source: AGHT+IFIT7JCEjyM1nteOzEMotwoLFVdeHGea6Ye0k+Yavkx70omCjhQ4v6achdWsuDSRCzgad5tCQ== X-Received: by 2002:a05:6512:e91:b0:52e:ccf4:c5e2 with SMTP id 2adb3069b0e04-52fd52e97dfmr3389841e87.8.1722107255646; Sat, 27 Jul 2024 12:07:35 -0700 (PDT) Original-Received: from ThinkPad-T470s (81-235-157-129-no600.tbcn.telia.com. [81.235.157.129]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52fd5c1a001sm834889e87.208.2024.07.27.12.07.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jul 2024 12:07:34 -0700 (PDT) In-Reply-To: 87bk2ig7ir.fsf@dataswamp.org Received-SPF: pass client-ip=2a00:1450:4864:20::129; envelope-from=shouran.ma@gmail.com; helo=mail-lf1-x129.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:322140 Archived-At: > Sent: Saturday, July 27, 2024 at 16:57 +0200 > From: "Shouran Ma" > > However, WE DON'T EVEN HAVE A UNIFIED WAY TO REPRESENTING A VECTOR. I need to elaborate this statement, otherwise it cause confusion to others. Elisp provides "List" and "Vector" as an array of numbers: https://www.gnu.org/software/emacs/manual/html_node/elisp/Sequences-Arrays-Vectors.html To express an array of numbers, a developer would either use two of them - (setq x '(1 2 3 4)) ; (type-of x) => cons - (setq x [1 2 3 4]) ; (type-of x) => vector "cons" (or "list") is the first thing that everybody would choose, for example, in Sergey's elisa: https://github.com/s-kostyaev/elisa/blob/main/elisa.el In the function "elisa--distances", Sergey puts "head" and "(car tail)" as arguments to "elisa-cosine-distance", this means Sergey uses cons/list to organize array of numbers. However, Elisp also has "array" types: https://www.gnu.org/software/emacs/manual/html_node/elisp/Arrays.html > An array object has slots that hold a number of other Lisp objects, > called the elements of the array. Any element of an array MAY BE > ACCESSED IN CONSTANT TIME. In contrast, the time to access an element > of a list is proportional to the position of that element in the list. cons/list is something like "linked list" which is not accessed in const time, but vector support this, e.g. it takes more time to access the last element if we use cons/list, but less time if use vector. However, Elisp provides too few functions on operating the vector type, for example, to slice a vector like the way in python: array[2:4]. So my saying "don't even have a unified way to representing a vector", I mean, to organize/represent a MATHEMATICAL vector - I would prefer to choose the object that support const time access, i.e. the BUILTIN vector type, over the cons/list. - However, the BUILTIN vector type supports quite a few functions, which forces me to change my mind to organize/represent the MATHEMATICAL vectors by cons/list. This is the dilemma during developing my own math libraries. Besides, in the Calc subroutine, the MATHEMATICAL vectors are represented by cons/list in this way (vec 3 5 2 1 0) ; not (3 5 2 1 0) or [3 5 2 1 0] i.e. a symbol "vec" is placed at the beginning of the list, in order to simplify the predication. But this leads to the indexing problem, that elements are indexed since 1, not 0. Such an indexing scheme would cause a nightmare to the developer who want to use our math subroutine to do further development. In summary, if the builtin vector type is preferred way to represent the MATHEMATICAL vector, we should first of all complete the fundamental vector operations, like vector slicing etc. And of course, we should take a look at how sbcl https://git.code.sf.net/p/sbcl/sbcl organize their vector and their vector functions. >From my side, I don't want to touch the vector things so far, but instead the rational number (the bullet 2 & 3 in my previous mail). Finally, > Sent: Saturday, July 27, 2024 at 17:49 +0200 > From: "Emanuel Berg" > > However it used to be even worse, when we didn't even have clocks! If the "clock" you said is the clock to measure how long a function runs, we have, it is "benchmark-run". -- Best Regards, Shouran Ma