Recent

Author Topic: three-way comparison  (Read 741 times)

BobDog

  • Sr. Member
  • ****
  • Posts: 366
Re: three-way comparison
« Reply #15 on: November 29, 2022, 12:51:38 am »

Perhaps >< could be used.
(Simple console program)
Code: Pascal  [Select][+][-]
  1. uses
  2. math;
  3.  
  4. Operator >< (a:int32;b:int32) z : int32;  
  5. begin  
  6. z:=sign(a-b);
  7. exit(z);
  8. end;
  9.  
  10.  function range(f:int32;l:int32):int32 ;
  11. begin
  12.     range:=  random(2147483647) mod (l-f+1) + f ;
  13. end;
  14. var
  15. i,a,b,j:int32;
  16. ar:array[-1..1] of int32=(0,0,0);
  17.  
  18. begin
  19.  
  20. writeln(3><9);
  21. writeln(3><3);
  22. writeln(9><3);
  23. writeln('---- The first few: ---');
  24. for i:=1 to 10000000 do
  25. begin
  26. a:=range(0,2);
  27. b:=range(0,2);
  28. j:=a><b;
  29. if (i<501) then  write(j);
  30. ar[j]:=ar[j]+1;
  31. end;
  32. writeln(chr(10));
  33. writeln('bucket');;
  34. for i:=-1 to 1 do writeln(ar[i]);
  35. writeln('_______');
  36. writeln(ar[-1]+ar[0]+ar[1]);
  37. writeln('Done, press return to end . . .');
  38. readln;
  39. end.
  40.  

Thaddy

  • Hero Member
  • *****
  • Posts: 12566
Re: three-way comparison
« Reply #16 on: November 29, 2022, 09:46:05 am »
But that is already used and what I showed.... See the Rosetta code entry.
{ imp ==>}
  operator >< (const a,b:trit):trit;

Problem with this thread is that there is too much noise.
(And frankly people writings not based on any theory at all. My code is founded in proper theory and complete)
« Last Edit: November 29, 2022, 09:54:13 am by Thaddy »
Writing code in an overly complex way is usually merely a complete misunderstanding of the goal you are trying to achieve.

BobDog

  • Sr. Member
  • ****
  • Posts: 366
Re: three-way comparison
« Reply #17 on: November 29, 2022, 12:53:21 pm »
But that is already used and what I showed.... See the Rosetta code entry.
{ imp ==>}
  operator >< (const a,b:trit):trit;

Problem with this thread is that there is too much noise.
(And frankly people writings not based on any theory at all. My code is founded in proper theory and complete)
What are you trying to say Thaddy, that you and only you have the proper theory?
So we read your thing and immediately stop right there, all is now concluded, no other answers counts any more?
(I now see your rosettacode unit, but your >< operator can return values other than 0,-1,1)
I am only going by the first question in the thread, a simple operator to do a simple task.
I wasn't quite expecting to be rubbished, cast aside, vilified, along with everybody else here.


Thaddy

  • Hero Member
  • *****
  • Posts: 12566
Re: three-way comparison
« Reply #18 on: December 01, 2022, 10:17:12 am »
That operator can ONLY return a trit, which means -1,0,+1
I never villified you, I merely was trying to teach you how it can be done.
(From two different approached, but founded in the Kleene and Priest logic, which is the accepted and current scientific approach to solve the problem at hand)
Writing code in an overly complex way is usually merely a complete misunderstanding of the goal you are trying to achieve.

Zvoni

  • Hero Member
  • *****
  • Posts: 1591
Re: three-way comparison
« Reply #19 on: December 01, 2022, 10:41:36 am »
That operator can ONLY return a trit, which means -1,0,+1
I never villified you, I merely was trying to teach you how it can be done.
(From two different approached, but founded in the Kleene and Priest logic, which is the accepted and current scientific approach to solve the problem at hand)
..... and at a guess, implemented and validated (confirmed to work) a gazillion times all across the world and programming languages
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Thaddy

  • Hero Member
  • *****
  • Posts: 12566
Re: three-way comparison
« Reply #20 on: December 01, 2022, 12:37:10 pm »
Indeed, see Rosetta code.
Also note my remark in the code and the original discussion that the first implementation - however correct - was corrected by me when I saw the Rosetta Code implementations - so not the Pascal ones, they did not exist -and made a second one, also correct but also way more efficient.
« Last Edit: December 01, 2022, 12:54:48 pm by Thaddy »
Writing code in an overly complex way is usually merely a complete misunderstanding of the goal you are trying to achieve.

 

TinyPortal © 2005-2018