Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127021 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id DEF651A00BC for ; Tue, 1 Apr 2025 21:33:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1743543070; bh=/DY4ey1du+8D58G3JJfzXicGwRg41bC9q9Xbb4hfxfo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Oh1hThEQD1S7l7QsTcxiVF6hW1bFg8Tf4GNQj8HendgWNlcZDI2TndeFb/9EWAije sXHDQan1vHPhU1VJfh0M2eoCinH5NxXHVwaDeBnSI3VunUoFinT/6CbbCdfTCpoGdE UAWpqdul29HbLg/M9JjXOlTp7CM366Rrg/6/5T7dH0UHu3Bp44tiPkqw9fAvich3Pj BhY4cmapVF9/cVZ/ooxt6H9lE/KioEefnkjArCVU+pgbnOmAK04Gos3hCQwl62uarM 2A1y51W+PD7KbJDm+PrejTN+Myq25ZolFzZshtCmvY3tvkE4nYqBFlgwZT8JKvn2wI btbqUehRL796Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0488C180081 for ; Tue, 1 Apr 2025 21:31:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 1 Apr 2025 21:31:09 +0000 (UTC) Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5efe8d9eb12so3718296a12.1 for ; Tue, 01 Apr 2025 14:33:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743543215; x=1744148015; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=7T0XHQCmfmpPGCklCT0CEszwzSDlYGl3BZ+XcVirBHE=; b=atoibMEkl4rn/TkFmoT3bH1R2OkjsZAD5JPYDkB3GjIL/2NAp9CNoPe4BPH25BbtOP bxVohoshBJXcQ7PURkK8QpqN5hdBoDBVpzSgpwD7viCMekoXn6O1Vs3OE9JL0CE51nS4 HTSpE22R1aTtdMhi6M8FpouYqWKdHa3cOj0c6lmY4GdfUmNPVKds/G75tujIsXvNJmc3 rWwJ8RQ6CSsosKrAH+jUQCgksJbgxIR90ZIJGeJsfEnnZXcZUoU32u2Y1W5P30Qi8wQt Qh0CXLhledieC/EyBw71XTrUSeydqcvrT8l6P5mA2KeVN5q43Byi8hkViaDFYIDpB5OQ ifOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743543215; x=1744148015; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7T0XHQCmfmpPGCklCT0CEszwzSDlYGl3BZ+XcVirBHE=; b=GYVJMHDi5JkFHoI50M1OqnBzdEuTYa+//ShgLmI44P8LGQRNbDcE/FZj1XqRM6smoD bqXfWr8bZ2YEzRJnzGG05eJzF39W+0fChIJxsob7hMrxd/c4gCEJLrhK2F92JXNiY1li MjoEeDQuKaTGmgik5J6D9/Un2PtwlRyZzjJ7EGSnfDBkq3OzLWquiubpHR1x++5RY7QW /mzHEykxblPdFz27SfOwPZF+ZbwQzMe/iMDsiVD7+MXwUd+a9TFx+lo7EQ9SIR9XuEtJ J4YZ9g08UGdOvoKA2Y7+qgjLf2uzklxYLBrzpzl94lHEv7X9vhOfPCaKJNizdQorpnH4 SMtA== X-Forwarded-Encrypted: i=1; AJvYcCXEJZ8SNKY+X87S2/ofJVwCwLVBVCarMV97l/4uSzWponZOZFDdRVxPbWrlJEwAcuYcYS7o5xmtDKU=@lists.php.net X-Gm-Message-State: AOJu0Yw+4TBC79ZkxTTopx9hRGiZKOUpGjFHuckUxSdS8Cyqstq3QXKe GB9liZ8s9XS6PFerQ33tmxTakZB2YFba3CFneb6B9/F3moUrqZfX273giClDJu7mwVyvcqe0NWN rlwNJquVYSI4rA3wDZrGKirnyB5qXsqAZTLo= X-Gm-Gg: ASbGncuMNfn4ay2MZeE5pdpr1jJU7tC/hA6hcB7cJ8ckluxaHWfQolFXwazxk9+LoGM Jg2STgYVL7WYQmJRidsd2WYKRSRIX2rs2/ZZMsS2KLYsiFXyugzraIiX5oXV2JND5aZ7bnmzaE+ 0aRUIMq9DHOux+mn1GBNpuHoyZnw== X-Google-Smtp-Source: AGHT+IGfjkNtBJ7ul80/zgHwvDwsDxChtxD+OdaI/aHYd1zCrCtqZlEGQpjFXh/A//wWZ+Z7SE5jVeqa7MRXlLQe5XI= X-Received: by 2002:a17:907:7ba1:b0:ac2:7cf9:71a0 with SMTP id a640c23a62f3a-ac738c59c7dmr1186149366b.48.1743543214847; Tue, 01 Apr 2025 14:33:34 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <4a3c6ce7-102d-4cfe-a7a8-35630715b870@gmail.com> <799bd54a-2136-4410-823a-9233ccbeb16a@app.fastmail.com> <89495A22-BCBD-4779-835D-56B90257FF51@php.net> <371df6b7-2c4b-4bb6-b711-162e512ce145@app.fastmail.com> In-Reply-To: <371df6b7-2c4b-4bb6-b711-162e512ce145@app.fastmail.com> Date: Wed, 2 Apr 2025 00:33:23 +0300 X-Gm-Features: AQ5f1JrVRnBQdAIrDil9sCkb-D5CS_XAtrhL7safXrvRrT3mi4ZeuKmOra_Am00 Message-ID: Subject: Re: [PHP-DEV] [RFC brainstorm] Approximately equals operator To: Rob Landers Cc: Derick Rethans , internals@lists.php.net, Larry Garfield Content-Type: multipart/alternative; boundary="000000000000f8c28f0631be4987" From: i.miroslavov@gmail.com (Iliya Miroslavov Iliev) --000000000000f8c28f0631be4987 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Apr 1, 2025 at 11:29=E2=80=AFPM Rob Landers wro= te: > On Tue, Apr 1, 2025, at 22:17, Derick Rethans wrote: > > On 1 April 2025 20:52:32 BST, Larry Garfield > wrote: > >On Mon, Mar 31, 2025, at 5:03 PM, Niels Dossche wrote: > >> Hi internals! > >> > >> I'm excited to share what I've been working on! > >> I had an epiphany. I realized what we truly need to revolutionize PHP: > >> a new operator. > >> > >> Hear me out. > >> We live in an imperfect world, and we often approximate data, but > >> neither `=3D=3D` nor `=3D=3D=3D` are ideal comparison operators to dea= l with > >> these kinds of data. > >> > >> Introducing: the "approximately equal" (or "approx-equal") operator > >> `~=3D` (to immitate the maths symbol =E2=89=83). > >> This combines the power of type coercion with approximating equality. > >> Who cares if things are actually equal, close enough amirite? > >> > >> First of all, if `$a =3D=3D $b` holds, then `$a ~=3D $b` obviously. > >> The true power lies where the data is not exactly the same, but "close > enough"! > >> > >> Here are some examples: > >> > >> We all had situations where we wanted to compare two floating point > >> numbers and it turns out that due to the non-exact representation, > >> seemingly-equal numbers don't match! Gone are those days because the > >> `~=3D` operator nicely rounds the numbers for you before comparing the= m. > >> This also means that the "Fundamental Theorem of Engineering" now hold= s! > >> i.e. 2.7 ~=3D 3 and 3.14 ~=3D 3. Of course also 2.7 ~=3D 3.14. But thi= s is > >> false obviously: 2 ~=3D 1. > >> > >> Ever had trouble with users mistyping something? Say no more! > >> "This is a tpyo" ~=3D "This is a typo". It's typo-resistant! > >> However, if the strings are too different, then they're not > >> approx-equal. > >> For example: "vanilla" ~=3D "strawberry" gives false. > >> How does this work? > >> * The strings are equal if their levenshtein ratio is <=3D 50%, so it'= s > >> adaptive to the length. > >> * If the ratio is > 50%, then the shortest string comes first in the > >> comparison, such that if we ever get a `~<` operator, then "vanilla" ~= < > >> "strawberry". > >> > >> There is of course a PoC implementation available at: > >> https://github.com/php/php-src/pull/18214 > >> You can see more examples on GitHub in the tests, here is a copy: > >> ```php > >> // Number compares > >> var_dump(2 ~=3D 1); // false > >> var_dump(1.4 ~=3D 1); // true > >> var_dump(-1.4 ~=3D -1); // true > >> var_dump(-1.5 ~=3D -1.8); // true > >> var_dump(random_int(1, 1) ~=3D 1.1); // true > >> > >> // Array compares (just compares the lengths) > >> var_dump([1, 2, 3] ~=3D [2, 3, 4]); // true > >> var_dump([1, 2, 3] ~=3D [2, 3, 4, 5]); // false > >> > >> // String / string compares > >> var_dump("This is a tpyo" ~=3D "This is a typo"); // true > >> var_dump("something" ~=3D "different"); // false > >> var_dump("Wtf bro" ~=3D "Wtf sis"); // true > >> > >> // String / different type compares > >> var_dump(-1.5 ~=3D "-1.a"); // true > >> var_dump(-1.5 ~=3D "-1.aaaaaaa"); // false > >> var_dump(NULL ~=3D "blablabla"); // false > >> ``` > >> > >> Note that this does not support all possible Opcache optimizations > >> _yet_, nor does it support the JIT yet. > >> However, there are no real blockers to add support for that. > >> > >> I look forward to hearing you! > >> > >> Have a nice first day of the month ;) > >> Kind regards > >> Niels > > > >Naturally, the degree of closeness for strings or for floats should be > controlled by an ini setting. Maximum flexibility! > > > >--Larry Garfield > > You got to be joking! Everybody knows ini settings make things unportable= . > I suggest we introduce AI to determine the closeness instead. > > cheers > Derick > > > We have to be careful not to tie ourselves to a specific AI model. But we > can use ini settings to allow the user to specify which model to use. > > =E2=80=94 Rob > Rob, I don't trust users. This must be hardcoded inside PHP and we can build and support 100 different versions just to be sure no user makes mistakes. No hassle here --=20 Iliya Miroslavov Iliev i.miroslavov@gmail.com --000000000000f8c28f0631be4987 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Tue, Apr 1, = 2025 at 11:29=E2=80=AFPM Rob Landers <rob@bottled.codes> wrote:
On Tue, Apr 1, 2025, at 22:17, Derick Re= thans wrote:
On 1 April 2025 20:52:32 BST, Larry Garfield <larry@garfieldtech.com> = wrote:
>On Mon, Mar 31, 2025, at 5:03 PM, Niels Dossche wr= ote:
>> Hi internals!
>>
<= div>>> I'm excited to share what I've been working on!
>> I had an epiphany. I realized what we truly need to revolu= tionize PHP:=C2=A0
>> a new operator.
>= ;>
>> Hear me out.
>> We live in= an imperfect world, and we often approximate data, but=C2=A0
>> neither `=3D=3D` nor `=3D=3D=3D` are ideal comparison operators t= o deal with=C2=A0
>> these kinds of data.
>>
>> Introducing: the "approximately equal= " (or "approx-equal") operator=C2=A0
>> = `~=3D` (to immitate the maths symbol =E2=89=83).
>> Thi= s combines the power of type coercion with approximating equality.
>> Who cares if things are actually equal, close enough amirite= ?
>>
>> First of all, if `$a =3D=3D= $b` holds, then `$a ~=3D $b` obviously.
>> The true po= wer lies where the data is not exactly the same, but "close enough&quo= t;!
>>
>> Here are some examples:
>>
>> We all had situations where we= wanted to compare two floating point=C2=A0
>> numbers = and it turns out that due to the non-exact representation,=C2=A0
<= div>>> seemingly-equal numbers don't match! Gone are those days b= ecause the=C2=A0
>> `~=3D` operator nicely rounds the n= umbers for you before comparing them.
>> This also mean= s that the "Fundamental Theorem of Engineering" now holds!
>> i.e. 2.7 ~=3D 3 and 3.14 ~=3D 3. Of course also 2.7 ~=3D 3= .14. But this is=C2=A0
>> false obviously: 2 ~=3D 1.
>>
>> Ever had trouble with users mis= typing something? Say no more!
>> "This is a tpyo&= quot; ~=3D "This is a typo". It's typo-resistant!
>> However, if the strings are too different, then they're not= =C2=A0
>> approx-equal.
>> For exam= ple: "vanilla" ~=3D "strawberry" gives false.
=
>> How does this work?
>> * The strings are = equal if their levenshtein ratio is <=3D 50%, so it's=C2=A0
>> adaptive to the length.
>> * If the rati= o is > 50%, then the shortest string comes first in the=C2=A0
<= div>>> comparison, such that if we ever get a `~<` operator, then = "vanilla" ~<=C2=A0
>> "strawberry&quo= t;.
>>
>> There is of course a PoC = implementation available at:=C2=A0
>> You can see more exam= ples on GitHub in the tests, here is a copy:
>> ```php<= br>
>> // Number compares
>> var_dump(2= ~=3D 1); // false
>> var_dump(1.4 ~=3D 1); // true
=
>> var_dump(-1.4 ~=3D -1); // true
>> = var_dump(-1.5 ~=3D -1.8); // true
>> var_dump(random_in= t(1, 1) ~=3D 1.1); // true
>>
>> //= Array compares (just compares the lengths)
>> var_dump= ([1, 2, 3] ~=3D [2, 3, 4]); // true
>> var_dump([1, 2, = 3] ~=3D [2, 3, 4, 5]); // false
>>
>&g= t; // String / string compares
>> var_dump("This i= s a tpyo" ~=3D "This is a typo"); // true
>= > var_dump("something" ~=3D "different"); // false
>> var_dump("Wtf bro" ~=3D "Wtf sis"= ); // true
>>
>> // String / differ= ent type compares
>> var_dump(-1.5 ~=3D "-1.a"= ;); // true
>> var_dump(-1.5 ~=3D "-1.aaaaaaa"= ;); // false
>> var_dump(NULL ~=3D "blablabla"= ;); // false
>> ```
>>
>> Note that this does not support all possible Opcache optimizatio= ns=C2=A0
>> _yet_, nor does it support the JIT yet.
=
>> However, there are no real blockers to add support for = that.
>>
>> I look forward to heari= ng you!
>>
>> Have a nice first day= of the month ;)
>> Kind regards
>>= Niels
>
>Naturally, the degree of closen= ess for strings or for floats should be controlled by an ini setting.=C2=A0= Maximum flexibility!
>
>--Larry Garfield=

You got to be joking! Everybody knows ini set= tings make things unportable. I suggest we introduce AI to determine the cl= oseness instead.

cheers
Derick


We have to be caref= ul not to tie ourselves to a specific AI model. But we can use ini settings= to allow the user to specify which model to use.

<= div id=3D"m_-6019868526527811441sig121229152">=E2=80=94 Rob
=

Rob, I don't= trust users. This must be hardcoded inside PHP and we can build and suppor= t 100 different versions just to be sure no user makes mistakes. No hassle = here
--
Iliya Miroslavov Iliev
--000000000000f8c28f0631be4987--