Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
from: http://rosettacode.org/wiki/Logical_operations
note: Basic Data Operations

View file

@ -0,0 +1,11 @@
{{basic data operation}}
[[Category:Simple]]
;Task:
Write a function that takes two logical (boolean) values, and outputs the result of "and" and "or" on both arguments as well as "not" on the first arguments.
If the programming language doesn't provide a separate type for logical values, use the type most commonly used for that purpose.
If the language supports additional logical operations on booleans such as XOR, list them as well.
<br><br>

View file

@ -0,0 +1,4 @@
F logic(a, b)
print(a and b: (a & b))
print(a or b: (a | b))
print(not a: (!a))

View file

@ -0,0 +1,26 @@
* Logical operations 04/04/2017
LOGICAL CSECT
USING LOGICAL,R15
* -- C=A and B
MVC C,A C=A
NC C,B C=A and B
* -- C=A or B
MVC C,A C=A
OC C,B C=A or B
* -- C=not A
MVC C,A C=A
XI C,X'01' C=not A
* -- if C then goto e
CLI C,X'01' if C
BE E then goto e
XPRNT =C'FALSE',5
*
E BR R14
TRUE DC X'01'
FALSE DC X'00'
A DC X'01'
B DC X'00'
C DS X
PG DC CL80' '
YREGS
END LOGICAL

View file

@ -0,0 +1,7 @@
LDA myBoolean
BNE isTrue
;code that would execute if myBoolean is false, goes here.
RTS
isTrue:
;code that would execute if myBoolean is true, goes here.
RTS

View file

@ -0,0 +1,3 @@
if(myValue == 3 && myOtherValue == 5){
myResult = true;
}

View file

@ -0,0 +1,15 @@
LDA myValue
CMP #3
BNE .skip
;if we got to here, "myValue == 3" evaluated to true.
LDA myOtherValue
CMP #5
BNE .skip
;if we got to here, both "myValue == 3" and "myOtherValue" == 5 evaluated to true.
STA myResult ;any nonzero value is considered TRUE, so we've stored 5 into myResult.
.skip:

View file

@ -0,0 +1,3 @@
if(myValue == 3 || myOtherValue == 5){
myResult = true;
}

View file

@ -0,0 +1,16 @@
LDA myValue
CMP #3
BEQ .doTheThing
;if not equal, check myOtherValue
LDA myOtherValue
CMP #5
BNE .skip
;if we got to here, either "myValue == 3" or "myOtherValue" == 5 evaluated to true.
.doTheThing:
STA myResult ;any nonzero value is considered TRUE, so we've stored 5 into myResult.
.skip:

View file

@ -0,0 +1,9 @@
LDA flags
LSR ;test the rightmost bit.
BCC .skip
LSR ;test the bit just to the left of the one we tested prior.
BCC .skip
;your code for what happens when both of the bottom 2 bits are 1, goes here.
.skip:

View file

@ -0,0 +1,3 @@
BIT myBitFlags
BMI .Bit7Set
BVS .Bit6Set

View file

@ -0,0 +1,4 @@
(defun logical-ops (a b)
(progn$ (cw "(and a b) = ~x0~%" (and a b))
(cw "(or a b) = ~x0~%" (or a b))
(cw "(not a) = ~x0~%" (not a))))

View file

@ -0,0 +1,22 @@
PROC print_logic = (BOOL a, b)VOID:
(
# for a 6-7 bit/byte compiler #
printf(($"a and b is "gl$, a AND b);
printf(($"a or b is "gl$, a OR b);
printf(($"not a is "gl$, NOT a);
printf(($"a equivalent to b is "gl$, a EQ b);
printf(($"a not equivalent to b is "gl$, a NE b);
# Alternatively ASCII #
printf(($"a and b is "gl$, a & b);
printf(($"a and b is "gl$, a /\ b); <!-- http://web.archive.org/web/20021207211127/http://www.bobbemer.com/BRACES.HTM -->
printf(($"a or b is "gl$, a \/ b);
printf(($"a equivalent to b "gl$, a = b);
printf(($"a not equivalent to b "gl$, a /= b);
¢ for a European 8 bit/byte charcter set eg. ALCOR or GOST ¢
printf(($"a and b is "gl$, a ∧ b);
printf(($"a or b is "gl$, a b);
printf(($"not a is "gl$, ¬ a)
printf(($"a not equivalent to b is "gl$, a ≠ b)
)

View file

@ -0,0 +1,14 @@
procedure booleanOperations( logical value a, b ) ;
begin
% algol W has the usual "and", "or" and "not" operators %
write( a, " and ", b, ": ", a and b );
write( a, " or ", b, ": ", a or b );
write( " not ", a, ": ", not a );
% logical values can be compared with the = and not = operators %
% a not = b can be used for a xor b %
write( a, " xor ", b, ": ", a not = b );
write( a, " equ ", b, ": ", a = b );
end booleanOperations ;

View file

@ -0,0 +1 @@
LOGICALOPS{()()(~)()()()}

View file

@ -0,0 +1,134 @@
/* ARM assembly Raspberry PI */
/* program logicoper.s */
/* Constantes */
.equ STDOUT, 1
.equ WRITE, 4
.equ EXIT, 1
/* Initialized data */
.data
szMessResultAnd: .asciz "Result of And : \n"
szMessResultOr: .asciz "Result of Or : \n"
szMessResultEor: .asciz "Result of Exclusive Or : \n"
szMessResultNot: .asciz "Result of Not : \n"
szMessResultClear: .asciz "Result of Bit Clear : \n"
sMessAffBin: .ascii "Register value : "
sZoneBin: .space 36,' '
.asciz "\n"
/* code section */
.text
.global main
main: /* entry of program */
push {fp,lr} /* save 2 registers */
mov r0,#0b1100 @ binary value 1
mov r1,#0b0110 @ binary value 2
bl logicfunc
100: @ standard end of the program
mov r0,#0 @ return code
pop {fp,lr} @ restore 2 registers
mov r7,#EXIT @ request to exit program
swi 0 @ perform the system call
/******************************************************************/
/* logics functions */
/******************************************************************/
/* r0 contains the first value */
/* r1 contains the second value */
logicfunc:
push {r2,lr} @ save registers
mov r2,r0 @ save value 1 in r2
ldr r0,iAdrszMessResultAnd @ and
bl affichageMess
mov r0,r2 @ load value 1 in r0
and r0,r1
bl affichage2
ldr r0,iAdrszMessResultOr @ or
bl affichageMess
mov r0,r2
orr r0,r1
bl affichage2
ldr r0,iAdrszMessResultEor @ exclusive or
bl affichageMess
mov r0,r2
eor r0,r1
bl affichage2
ldr r0,iAdrszMessResultNot @ not
bl affichageMess
mov r0,r2
mvn r0,r1
bl affichage2
ldr r0,iAdrszMessResultClear @ bit clear
bl affichageMess
mov r0,r2
bic r0,r1
bl affichage2
100:
pop {r2,lr} @ restore registers
bx lr
iAdrszMessResultAnd: .int szMessResultAnd
iAdrszMessResultOr: .int szMessResultOr
iAdrszMessResultEor: .int szMessResultEor
iAdrszMessResultNot: .int szMessResultNot
iAdrszMessResultClear: .int szMessResultClear
/******************************************************************/
/* register display in binary */
/******************************************************************/
/* r0 contains the register */
affichage2:
push {r0,lr} /* save registers */
push {r1-r5} /* save other registers */
mrs r5,cpsr /* saves state register in r5 */
ldr r1,iAdrsZoneBin
mov r2,#0 @ read bit position counter
mov r3,#0 @ position counter of the written character
1: @ loop
lsls r0,#1 @ left shift with flags
movcc r4,#48 @ flag carry off character '0'
movcs r4,#49 @ flag carry on character '1'
strb r4,[r1,r3] @ character -> display zone
add r2,r2,#1 @ + 1 read bit position counter
add r3,r3,#1 @ + 1 position counter of the written character
cmp r2,#8 @ 8 bits read
addeq r3,r3,#1 @ + 1 position counter of the written character
cmp r2,#16 @ etc
addeq r3,r3,#1
cmp r2,#24
addeq r3,r3,#1
cmp r2,#31 @ 32 bits shifted ?
ble 1b @ no -> loop
ldr r0,iAdrsZoneMessBin @ address of message result
bl affichageMess @ display result
100:
msr cpsr,r5 /* restore state register */
pop {r1-r5} /* restore other registers */
pop {r0,lr}
bx lr
iAdrsZoneBin: .int sZoneBin
iAdrsZoneMessBin: .int sMessAffBin
/******************************************************************/
/* display text with size calculation */
/******************************************************************/
/* r0 contains the address of the message */
affichageMess:
push {fp,lr} /* save registers */
push {r0,r1,r2,r7} /* save others registers */
mov r2,#0 /* counter length */
1: /* loop length calculation */
ldrb r1,[r0,r2] /* read byte start position + index */
cmp r1,#0 /* if 0 it's over */
addne r2,r2,#1 /* else add 1 to the length */
bne 1b /* and loop */
/* so here r2 contains the length of the message */
mov r1,r0 /* address message in r1 */
mov r0,#STDOUT /* code to write to the standard output */
mov r7,#WRITE /* "write" system call */
swi #0 /* system call */
pop {r0,r1,r2,r7} /* restore other registers */
pop {fp,lr} /* restore 2 registers */
bx lr /* return */

View file

@ -0,0 +1,9 @@
$ awk '{print "and:"($1&&$2),"or:"($1||$2),"not:"!$1}'
0 0
and:0 or:0 not:1
0 1
and:0 or:1 not:1
1 0
and:0 or:1 not:0
1 1
and:1 or:1 not:0

View file

@ -0,0 +1,24 @@
BYTE FUNC Not(BYTE a)
IF a=0 THEN
RETURN (1)
FI
RETURN (0)
PROC Main()
BYTE a,b,res
FOR a=0 TO 1
DO
FOR b=0 TO 1
DO
res=a AND b
PrintF("%B AND %B=%B",a,b,res)
res=a OR b
PrintF("|%B OR %B=%B",a,b,res)
res=a ! b
PrintF("|%B XOR %B=%B",a,b,res)
res=Not(a)
PrintF("|NOT %B=%B%E",a,res)
OD
OD
RETURN

View file

@ -0,0 +1,7 @@
procedure Print_Logic(A : Boolean; B : Boolean) is
begin
Put_Line("A and B is " & Boolean'Image(A and B));
Put_Line("A or B is " & Boolean'Image(A or B));
Put_Line("A xor B is " & Boolean'Image(A xor B));
Put_Line("not A is " & Boolean'Image(not A));
end Print_Logic;

View file

@ -0,0 +1,7 @@
module AndOrNot where
open import Data.Bool using (Bool ; false ; true ; _∧_ ; __ ; not)
open import Data.Product using (_,_ ; _×_)
test : Bool Bool Bool × Bool × Bool
test a b = a b , a b , not a

View file

@ -0,0 +1,43 @@
module AndOrNot where
-- This part is to compute the values
open import Data.Bool using (Bool ; false ; true ; _∧_ ; __ ; not)
open import Data.Product using (_,_ ; _×_)
test : Bool Bool Bool × Bool × Bool
test a b = a b , a b , not a
-- This part is to print the result
open import Agda.Builtin.IO using (IO)
open import Agda.Builtin.Unit using ()
open import Data.String using (String ; _++_)
open import Data.Bool.Show using (show)
get-and-or-not-str : Bool × Bool × Bool String
get-and-or-not-str (t₁ , t₂ , t₃) =
"a and b: " ++ (show t₁) ++ ", " ++
"a or b: " ++ (show t₂) ++ ", " ++
"not a: " ++ (show t₃)
test-str : Bool Bool String
test-str a b = get-and-or-not-str (test a b)
postulate putStrLn : String IO
{-# FOREIGN GHC import qualified Data.Text as T #-}
{-# COMPILE GHC putStrLn = putStrLn . T.unpack #-}
run : Bool Bool IO
run a b = putStrLn (test-str a b)
main : IO
main = run true false
--
-- This program outputs:
-- a and b: false, a or b: true, not a: false
--

View file

@ -0,0 +1,5 @@
function logic(a,b) {
println("a AND b: " + (a && b))
println("a OR b: " + (a || b))
println("NOT a: " + (!a))
}

View file

@ -0,0 +1,10 @@
void
out(integer a, integer b)
{
o_integer(a && b);
o_byte('\n');
o_integer(a || b);
o_byte('\n');
o_integer(!a);
o_byte('\n');
}

View file

@ -0,0 +1,29 @@
#include <hopper.h>
main:
a=0, b=1 // a and b have some values...
{"values A=",a,", B=",b} println
{"AND : ",a,b} and, println
{"OR : ",a,b} or, println
{"XOR : ",a,b} xor, println
{"NAND: ",a,b} nand, println
{"NOR : ",a,b} nor, println
{"NOT A: ",a}not, println
{"NOT B: ",b}not, println
x=-1,{3,3} rand array(x), mulby(10),ceil,gthan(5),mov(x)
y=-1,{3,3} rand array(y), mulby(10),ceil,gthan(5),mov(y)
{"\nArrays\nX:\n",x,"\nY:\n",y}println
{"AND :\n",x,y} and, println
{"OR :\n",x,y} or, println
{"XOR :\n",x,y} xor, println
{"NAND:\n",x,y} nand, println
{"NOR :\n",x,y} nor, println
{"NOT X :\n",x} not, println
{"NOT Y :\n",y} not, println
exit(0)

View file

@ -0,0 +1,6 @@
boolean a = true;
boolean b = false;
System.Debug('a AND b: ' + (a && b));
System.Debug('a OR b: ' + (a || b));
System.Debug('NOT a: ' + (!a));
System.Debug('a XOR b: ' + (a ^ b));

View file

@ -0,0 +1,7 @@
logic: function [a b][
print ["a AND b =" and? a b]
print ["a OR b =" or? a b]
print ["NOT a = " not? a]
]
logic true false

View file

@ -0,0 +1,9 @@
bool a = true;
bool b = false;
write(a & b);
write(a && b); //(with conditional evaluation of right-hand argument)
write(a | b);
write(a || b); //(with conditional evaluation of right-hand argument)
write(a ^ b);
write(!a);

View file

@ -0,0 +1,5 @@
a = 1
b = 0
msgbox % "a and b is " . (a && b)
msgbox % "a or b is " . (a || b)
msgbox % "not a is " . (!a)

View file

@ -0,0 +1,18 @@
Method "logic ops_,_" is
[
a : boolean;
b : boolean;
|
Print: "not a: " ++ “¬a”;
Print: "not b: " ++ “¬b”;
Print: "a and b: " ++ “a ∧ b”;
Print: "a or b: " ++ “a b”;
Print: "a nand b: " ++ “a ↑ b”;
Print: "a nor b: " ++ “a ↓ b”;
Print: "a implies b: " ++ “a → b”; // = not a OR b
Print: "a is implied b b: " ++ “a ← b”; // = a OR not b
Print: "a does not imply b: " ++ “a ↛ b”; // = a AND not b
Print: "a is not implied by b: " ++ “a ↚ b”; // not a AND b
Print: "a xor b: " ++ “a ⊕ b”; // equivalent to a ≠ b
Print: "a biconditional b: " ++ “a ↔ b”; // equivalent to a = b
];

View file

@ -0,0 +1,7 @@
Lbl LOGIC
r₁→A
r₂→B
Disp "AND:",(A?B)▶Dec,i
Disp "OR:",(A??B)▶Dec,i
Disp "NOT:",(A?0,1)▶Dec,i
Return

View file

@ -0,0 +1,6 @@
a = true
b = false
print a and b
print a or b
print a xor b
print not a

View file

@ -0,0 +1,13 @@
PROClogic(FALSE, FALSE)
PROClogic(FALSE, TRUE)
PROClogic(TRUE, FALSE)
PROClogic(TRUE, TRUE)
END
DEF PROClogic(a%, b%)
LOCAL @% : @% = 2 : REM Column width
PRINT a% " AND " b% " = " a% AND b% TAB(20);
PRINT a% " OR " b% " = " a% OR b% TAB(40);
PRINT a% " EOR " b% " = " a% EOR b% TAB(60);
PRINT " NOT " a% " = " NOT a%
ENDPROC

View file

@ -0,0 +1,4 @@
L¬
¬
0 L 1
0 1 0 1

View file

@ -0,0 +1,25 @@
/* The following three functions assume 0 is false and 1 is true */
/* And */
define a(x, y) {
return(x * y)
}
/* Or */
define o(x, y) {
return(x + y - x * y)
}
/* Not */
define n(x) {
return(1 - x)
}
define f(a, b) {
"a and b: "
a(a, b)
"a or b: "
o(a, b)
"not a: "
n(a)
}

View file

@ -0,0 +1,5 @@
define logic_test(a, b) {
print "a and b: ", a && b, "\n"
print "a or b: ", a || b, "\n"
print "not a: ", !a, "\n"
}

View file

@ -0,0 +1,27 @@
( ( Logic
= x y
. '$arg:(=?x,?y)
& str
$ ( "\n(x,y)="
!arg
( ":\n"
"x and y -> "
( (!x&!y)&true
| false
)
)
( \n
"x or y -> "
( (!x|!y)&true
| false
)
)
"\nnot x -> "
(~!x&true|false)
)
)
& out$(Logic$(,))
& out$(Logic$(~,))
& out$(Logic$(,~))
& out$(Logic$(~,~))
);

View file

@ -0,0 +1,5 @@
logic = { a, b |
p "a and b: #{ a && b }"
p "a or b: #{ a || b }"
p "not a: #{ not a }"
}

View file

@ -0,0 +1,7 @@
void print_logic(bool a, bool b)
{
std::cout << std::boolalpha; // so that bools are written as "true" and "false"
std::cout << "a and b is " << (a && b) << "\n";
std::cout << "a or b is " << (a || b) << "\n";
std::cout << "not a is " << (!a) << "\n";
}

View file

@ -0,0 +1,16 @@
using System;
namespace LogicalOperations
{
class Program
{
static void Main(string[] args)
{
bool a = true, b = false;
Console.WriteLine("a and b is {0}", a && b);
Console.WriteLine("a or b is {0}", a || b);
Console.WriteLine("Not a is {0}", !a);
Console.WriteLine("a exclusive-or b is {0}", a ^ b);
}
}
}

View file

@ -0,0 +1,6 @@
void print_logic(int a, int b)
{
printf("a and b is %d\n", a && b);
printf("a or b is %d\n", a || b);
printf("not a is %d\n", !a);
}

View file

@ -0,0 +1,26 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. print-logic.
DATA DIVISION.
LOCAL-STORAGE SECTION.
01 result PIC 1 USAGE BIT.
LINKAGE SECTION.
01 a PIC 1 USAGE BIT.
01 b PIC 1 USAGE BIT.
PROCEDURE DIVISION USING a, b.
COMPUTE result = a B-AND b
DISPLAY "a and b is " result
COMPUTE result = a B-OR b
DISPLAY "a or b is " result
COMPUTE result = B-NOT a
DISPLAY "Not a is " result
COMPUTE result = a B-XOR b
DISPLAY "a exclusive-or b is " result
GOBACK
.

View file

@ -0,0 +1,6 @@
Function Foo( a, b )
// a and b was defined as .F. (false) or .T. (true)
? a .AND. b
? a .OR. b
? .NOT. a, .NOT. b
Return Nil

View file

@ -0,0 +1,6 @@
(defn logical [a b]
(prn (str "a and b is " (and a b)))
(prn (str "a or b is " (or a b)))
(prn (str "not a is " (not a))))
(logical true false)

View file

@ -0,0 +1,9 @@
<cffunction name = "logic" hint = "Performs basic logical operations">
<cfargument name = "a" required = "yes" type = "boolean" />
<cfargument name = "a" required = "yes" type = "boolean" />
<cfoutput>
'A' AND 'B' is #a AND b#< br />
'A' OR 'B' is #a OR b#< br />
NOT 'A' is #!a#
</cfoutput>
</cffunction>

View file

@ -0,0 +1,6 @@
10 A = -1
20 B = 0
30 PRINT A AND B
40 PRINT A OR B
50 PRINT (A AND (NOT B)) OR ((NOT A) AND B)
60 PRINT NOT A

View file

@ -0,0 +1 @@
70 PRINT XOR(1, 0)

View file

@ -0,0 +1,8 @@
(defun demo-logic (a b)
(mapcar (lambda (op)
(format t "~a ~a ~a is ~a~%" a op b (eval (list op a b))))
'(and or)))
(loop for a in '(nil t) do
(format t "NOT ~a is ~a~%" a (not a))
(loop for b in '(nil t) do (demo-logic a b) (terpri)))

View file

@ -0,0 +1,33 @@
import std.stdio;
void logic(T, U)(T lhs, U rhs) {
writefln("'%s' is of type '%s', '%s' is of type '%s';",
lhs, typeid(typeof(lhs)), rhs,typeid(typeof(rhs)));
writefln("\t'%s' AND '%s' is %s, ", lhs, rhs, lhs && rhs);
writefln("\t'%s' OR '%s' is %s, ", lhs, rhs, lhs || rhs);
writefln("\tNOT '%s' is %s.\n", lhs, !lhs);
}
class C { int value; }
void main() {
bool theTruth = true;
bool theLie = false;
real zeroReal = 0.0L;
real NaN; // D initializes floating point values to NaN
int zeroInt = 0;
real[] nullArr = null;
string emptyStr = "";
string nullStr = null;
C someC = new C;
C nullC = null;
// Note: Struct is value type in D, but composite
// so no default bool equivalent.
logic(theTruth, theLie);
logic(zeroReal, NaN);
logic(zeroInt, nullArr);
logic(nullStr, emptyStr);
logic(someC, nullC);
}

View file

@ -0,0 +1,19 @@
var a := True;
var b := False;
Print('a = ');
PrintLn(a);
Print('b = ');
PrintLn(b);
Print('a AND b: ');
PrintLn(a AND b);
Print('a OR b: ');
PrintLn(a OR b);
Print('NOT a: ');
PrintLn(NOT a);
Print('a XOR b: ');
PrintLn(a XOR b);

View file

@ -0,0 +1,21 @@
[ 1 q ] sT
[ 0=T 0 ] s!
[ l! x S@ l! x L@ + l! x ] s&
[ l! x S@ l! x L@ * l! x ] s|
[ 48 + P ] s.
[ Sb Sa
la l. x [ ] P lb l. x [ ] P
la lb l& x l. x [ ] P
la Lb l| x l. x [ ] P
La l! x l. x
A P
] sF
[a b a&b a|b !a] P A P
0 0 lF x
0 1 lF x
1 0 lF x
1 1 lF x

View file

@ -0,0 +1,2 @@
{ exclusive or }
writeLn(A:5, ' xor', B:6, ' yields', A xor B:7);

View file

@ -0,0 +1,5 @@
var a = true
var b = false
print("a and b is \(a && b)")
print("a or b is \(a || b)")
print("Not a is \(!a)")

View file

@ -0,0 +1,6 @@
def logicalOperations(a :boolean, b :boolean) {
return ["and" => a & b,
"or" => a | b,
"not" => !a,
"xor" => a ^ b]
}

View file

@ -0,0 +1,6 @@
def logicalOperations(a :boolean, b :boolean) {
return ["and" => a.and(b),
"or" => a.or(b),
"not" => a.not(),
"xor" => a.xor(b)]
}

View file

@ -0,0 +1,18 @@
LogicalOperations(BOOLEAN A,BOOLEAN B) := FUNCTION
ANDit := A AND B;
ORit := A OR B;
NOTA := NOT A;
XORit := (A OR B) AND NOT (A AND B);
DS := DATASET([{A,B,'A AND B is:',ANDit},
{A,B,'A OR B is:',ORit},
{A,B,'NOT A is:',NOTA},
{A,B,'A XOR B is:',XORit}],
{BOOLEAN AVal,BOOLEAN BVal,STRING11 valuetype,BOOLEAN val});
RETURN DS;
END;
LogicalOperations(FALSE,FALSE);
LogicalOperations(FALSE,TRUE);
LogicalOperations(TRUE,FALSE);
LogicalOperations(TRUE,TRUE);
LogicalOperations(1>2,1=1); //Boolean expressions are also valid here

View file

@ -0,0 +1,10 @@
fun logicOperations = void by logic a, logic b
writeLine("=== input values are " + a + ", " + b + " ===")
writeLine("a and b: " + (a and b))
writeLine(" a or b: " + (a or b))
writeLine(" not a: " + (not a))
end
logicOperations(false, false)
logicOperations(false, true)
logicOperations(true, false)
logicOperations(true, true)

View file

@ -0,0 +1,16 @@
proc logic a b . .
if a = 1 and b = 1
r1 = 1
.
if a = 1 or b = 1
r2 = 1
.
if a = 0
r3 = 1
.
print r1 & " " & r2 & " " & r3
.
call logic 0 0
call logic 0 1
call logic 1 0
call logic 1 1

View file

@ -0,0 +1,15 @@
compare_bool = fn (A, B) {
io.format("~p and ~p = ~p~n", [A, B, A and B])
io.format("~p or ~p = ~p~n", [A, B, A or B])
io.format("not ~p = ~p~n", [A, not A])
io.format("~p xor ~p = ~p~n", [A, B, A xor B])
io.format("~n")
}
@public
run = fn () {
compare_bool(true, true)
compare_bool(true, false)
compare_bool(false, true)
compare_bool(false, false)
}

View file

@ -0,0 +1,12 @@
import extensions;
public program()
{
bool a := true;
bool b := false;
console.printLine("a and b is ", a && b);
console.printLine("a or b is ", a || b);
console.printLine("Not a is ", a.Inverted);
console.printLine("a xor b is ", a ^^ b)
}

View file

@ -0,0 +1,6 @@
iex(1)> true and false
false
iex(2)> false or true
true
iex(3)> not false
true

View file

@ -0,0 +1,14 @@
(28)> nil || 23
23
iex(29)> [] || false
[]
iex(30)> nil && true
nil
iex(31)> 0 && 15
15
iex(32)> ! true
false
iex(33)> ! nil
true
iex(34)> ! 3.14
false

View file

@ -0,0 +1,16 @@
--Open cmd and elm-repl and directly functions can be created
--Creating Functions
t=True
f=False
opand a b= a && b
opor a b= a || b
opnot a= not a
--Using the created Functions
opand t f
opor t f
opnot f
--Output will be False, True and True of type Boolean!
--end

View file

@ -0,0 +1,10 @@
1> true and false.
false
2> false or true.
true
3> true xor false.
true
4> not false.
true
5> not (true and true).
false

View file

@ -0,0 +1,6 @@
procedure print_logic(integer a, integer b)
printf(1,"a and b is %d\n", a and b)
printf(1,"a or b is %d\n", a or b)
printf(1,"a xor b is %d\n", a xor b)
printf(1,"not a is %d\n", not a)
end procedure

View file

@ -0,0 +1 @@
=CONCATENATE($A1, " AND ", $B1, " is ", AND($A1,$B1))

View file

@ -0,0 +1 @@
=CONCATENATE($A1, " OR ", $B1, " is ", OR($A1,$B1))

View file

@ -0,0 +1 @@
=CONCATENATE(" NOT ", $A1, " is ", NOT($A1))

View file

@ -0,0 +1,6 @@
let printLogic a b =
printfn "a and b is %b" (a && b)
printfn "a or b is %b" (a || b)
printfn "Not a is %b" (not a)
// The not-equals operator has the same effect as XOR on booleans.
printfn "a exclusive-or b is %b" (a <> b)

View file

@ -0,0 +1,4 @@
1 3=~["unequal, "]?
1 1= 1_=["true is -1, "]?
0~["false is 0, "]?
'm$'a>'z@>&["a < m < z"]?

View file

@ -0,0 +1,7 @@
: logical-operators ( a b -- )
{
[ "xor is: " write xor . ]
[ "and is: " write and . ]
[ "or is: " write or . ]
[ "not is: " write drop not . ]
} 2cleave ;

View file

@ -0,0 +1,21 @@
class Main
{
static Void doOps (Bool arg1, Bool arg2)
{
echo ("$arg1 and $arg2 = ${arg1.and(arg2)}")
echo ("$arg1 or $arg2 = ${arg1.or(arg2)}")
echo ("not $arg1 = ${arg1.not}")
echo ("$arg1 xor $arg2 = ${arg1.xor(arg2)}")
}
public static Void main ()
{
[true,false].each |Bool arg1|
{
[true,false].each |Bool arg2|
{
doOps (arg1, arg2)
}
}
}
}

View file

@ -0,0 +1,6 @@
: .bool ( ? -- ) if ." true" else ." false" then ;
: logic ( a b -- ) 0<> swap 0<> swap
cr ." a = " over .bool ." b = " dup .bool
cr ." a and b = " 2dup and .bool
cr ." a or b = " over or .bool
cr ." not a = " 0= .bool ;

View file

@ -0,0 +1,19 @@
SUBROUTINE PRNLOG(A, B)
LOGICAL A, B
PRINT *, 'a and b is ', A .AND. B
PRINT *, 'a or b is ', A .OR. B
PRINT *, 'not a is ', .NOT. A
C You did not ask, but the following logical operators are also standard
C since ANSI FORTRAN 66
C =======================================================================
C This yields the same results as .EQ., but has lower operator precedence
C and only works with LOGICAL operands:
PRINT *, 'a equivalent to b is ', A .EQV. B
C This yields the same results as .NE., but has lower operator precedence
C and only works with LOGICAL operands (this operation is also commonly
C called "exclusive or"):
PRINT *, 'a not equivalent to b is ', A .NEQV. B
END

View file

@ -0,0 +1,27 @@
' FB 1.05.0 Win64
Sub logicalDemo(b1 As Boolean, b2 As Boolean)
Print "b1 = "; b1
Print "b2 = "; b2
Print "b1 And b2 = "; b1 And b2
Print "b1 Or b2 = "; b1 Or b2
Print "b1 XOr b2 = "; b1 Xor b2
Print "b1 Eqv b2 = "; b1 Eqv b2
Print "b1 Imp b2 = "; b1 Imp b2
Print "Not b1 = "; Not b1
Print "b1 AndAlso b2 = "; b1 AndAlso b2
Print "b1 OrElse b2 = "; b1 OrElse b2
Print
End Sub
Dim b1 As Boolean = True
Dim b2 As Boolean = True
logicalDemo b1, b2
b2 = False
logicalDemo b1, b2
b1 = False
logicalDemo b1, b2
b2 = True
logicalDemo b1, b2
Print "Press any key to quit"
Sleep

View file

@ -0,0 +1,9 @@
logical[a,b] :=
{
println["$a and $b is " + (a and b)]
println["$a or $b is " + (a or b)]
println["$a xor $b is " + (a xor b)]
println["$a nand $b is " + (a nand b)]
println["$a nor $b is " + (a nor b)]
println["not $a is " + (not a)]
}

View file

@ -0,0 +1,8 @@
def logical( a, b ) = println( """
a and b = ${a and b}
a or b = ${a or b}
not a = ${not a}
a xor b = ${a xor b}
""" )
for i <- [false, true], j <- [false, true] do logical( i, j )

View file

@ -0,0 +1,30 @@
window 1, @"Logical Operations", (0,0,480,270)
Boolean a, b
text ,,,,, 43
print @"In FB, the Boolean constants _true or YES = 1, _false or NO = 0"
print fn StringByPaddingToLength( @"", 39, @"-", 0 )
print @"a\tb\tand\tor\txor\tnand\tnor"
print fn StringByPaddingToLength( @"", 39, @"-", 0 )
a = NO : b = NO : print a, b, a and b, a or b, a xor b, a nand b, a nor b
a = NO : b = YES : print a, b, a and b, a or b, a xor b, a nand b, a nor b
a = YES : b = NO : print a, b, a and b, a or b, a xor b, a nand b, a nor b
a = YES : b = YES : print a, b, a and b, a or b, a xor b, a nand b, a nor b
print
print "FB also has shorthand operator expressions"
print fn StringByPaddingToLength( @"", 39, @"-", 0 )
print @"a\tb\t&&\t||\t^^\t^&\t^|"
print fn StringByPaddingToLength( @"", 39, @"-", 0 )
a = NO : b = NO : print a, b, a && b, a || b, a ^^ b, a ^& b, a ^| b
a = NO : b = YES : print a, b, a && b, a || b, a ^^ b, a ^& b, a ^| b
a = YES : b = NO : print a, b, a && b, a || b, a ^^ b, a ^& b, a ^| b
a = YES : b = YES : print a, b, a && b, a || b, a ^^ b, a ^& b, a ^| b
HandleEvents

View file

@ -0,0 +1,15 @@
Logical := function(a, b)
return [ a or b, a and b, not a ];
end;
Logical(true, true);
# [ true, true, false ]
Logical(true, false);
# [ true, false, false ]
Logical(false, true);
# [ true, false, true ]
Logical(false, false);
# [ false, false, true ]

View file

@ -0,0 +1 @@
3 4 and

View file

@ -0,0 +1 @@
1 2 or

View file

@ -0,0 +1,16 @@
[indent=4]
/*
Logical operations in Genie
valac logicals.gs
./logicals true false
*/
def logicals(a:bool, b:bool)
print @"$a and $b is $(a and b)"
print @"$a or $b is $(a or b)"
print @"not $a is $(not a)"
init
a:bool = bool.parse(args[1])
b:bool = bool.parse(args[2])
logicals(a, b)

View file

@ -0,0 +1,5 @@
func printLogic(a, b bool) {
fmt.Println("a and b is", a && b)
fmt.Println("a or b is", a || b)
fmt.Println("not a is", !a)
}

View file

@ -0,0 +1,35 @@
package main
// stackoverflow.com/questions/28432398/difference-between-some-operators-golang
import "fmt"
func main() {
// Use bitwise OR | to get the bits that are in 1 OR 2
// 1 = 00000001
// 2 = 00000010
// 1 | 2 = 00000011 = 3
fmt.Println(1 | 2)
// Use bitwise OR | to get the bits that are in 1 OR 5
// 1 = 00000001
// 5 = 00000101
// 1 | 5 = 00000101 = 5
fmt.Println(1 | 5)
// Use bitwise XOR ^ to get the bits that are in 3 OR 6 BUT NOT BOTH
// 3 = 00000011
// 6 = 00000110
// 3 ^ 6 = 00000101 = 5
fmt.Println(3 ^ 6)
// Use bitwise AND & to get the bits that are in 3 AND 6
// 3 = 00000011
// 6 = 00000110
// 3 & 6 = 00000010 = 2
fmt.Println(3 & 6)
// Use bit clear AND NOT &^ to get the bits that are in 3 AND NOT 6 (order matters)
// 3 = 00000011
// 6 = 00000110
// 3 &^ 6 = 00000001 = 1
fmt.Println(3 &^ 6)
}

View file

@ -0,0 +1,9 @@
def logical = { a, b ->
println """
a AND b = ${a} && ${b} = ${a & b}
a OR b = ${a} || ${b} = ${a | b}
NOT a = ! ${a} = ${! a}
a XOR b = ${a} != ${b} = ${a != b}
a EQV b = ${a} == ${b} = ${a == b}
"""
}

View file

@ -0,0 +1 @@
[true, false].each { a -> [true, false].each { b-> logical(a, b) } }

View file

@ -0,0 +1,6 @@
PROCEDURE Foo( a, b )
// a and b was defined as .F. (false) or .T. (true)
? a .AND. b
? a .OR. b
? ! a, ! b
RETURN

View file

@ -0,0 +1,9 @@
a = False
b = True
a_and_b = a && b
a_or_b = a || b
not_a = not a
a_xor_b = a /= b
a_nxor_b = a == b
a_implies_b = a <= b -- sic!

View file

@ -0,0 +1,8 @@
*Main > False && undefined
False
Prelude> undefined && False
*** Exception: Prelude.undefined
Prelude> True || undefined
True
Prelude> undefined || True
*** Exception: Prelude.undefined

View file

@ -0,0 +1,8 @@
Prelude> False <= undefined
*** Exception: Prelude.undefined
Prelude> undefined <= True
*** Exception: Prelude.undefined
Prelude> True < undefined
*** Exception: Prelude.undefined
Prelude> undefined < False
*** Exception: Prelude.undefined

View file

@ -0,0 +1,5 @@
fun logic a b
println "a and b = " + (a && b)
println "a or b = " + (a || b)
println " not a = " + (!a)
endfun

View file

@ -0,0 +1,6 @@
x = value1 /= 0
y = value2 /= 0
NOTx = x == 0
xANDy = x * y
xORy = x + y /= 0
EOR = x /= y

View file

@ -0,0 +1,7 @@
U0 PrintLogic(Bool a, Bool b) {
Print("a and b is %d\n", a && b);
Print("a or b is %d\n", a || b);
Print("not a is %d\n", !a);
}
PrintLogic(TRUE, FALSE);

View file

@ -0,0 +1,4 @@
(defn logic [a b]
(print "a and b:" (and a b))
(print "a or b:" (or a b))
(print "not a:" (not a)))

View file

@ -0,0 +1,9 @@
100 LET A=-1
110 LET B=0
120 PRINT A AND B
130 PRINT A OR B
140 PRINT (A AND(NOT B)) OR((NOT A) AND B)
150 PRINT NOT A
160 PRINT 15 BAND 4
170 PRINT 2 BOR 15
180 PRINT (A BOR B)-(A BAND B) ! xor

View file

@ -0,0 +1,62 @@
invocable all
procedure main() #: sample demonstrating boolean function use
limit := 4
char2 := char(2)||char(0)
every (i := char(1 to limit)|char2) do {
write(iop := "bnot","( ",image(i)," ) = ",image(iop(i)))
every k := 3 | 10 do {
write("bistrue(",image(i),",",k,") - ", if bistrue(i,k) then "returns" else "fails")
write("bisfalse(",image(i),",",k,") - ", if bisfalse(i,k) then "returns" else "fails")
}
every (j := char(1 to limit)) & (iop := "bor"|"band"|"bxor") do
write(iop,"( ",image(i),", ",image(j)," ) = ",image(iop(i,j)))
}
end
procedure bisfalse(b,p) #: test if bit p (numbered right to left from 1) is false; return b or fails
return boolean_testbit(0,b,p)
end
procedure bistrue(b,p) #: test if bit p is true; return b or fails
return boolean_testbit(1,b,p)
end
procedure bnot(b) #: logical complement of b (not is a reserved word)
static cs,sc
initial sc := reverse(cs := string(&cset))
if type(b) ~== "string" then runerr(103,b)
return map(b,cs,sc) # en-mass inversion through remapping ordered cset
end
procedure bor(b1,b2) #: logical or
return boolean_op(ior,b1,b2)
end
procedure band(b1,b2) #: logical or
return boolean_op(iand,b1,b2)
end
procedure bxor(b1,b2) #: logical or
return boolean_op(ixor,b1,b2)
end
procedure boolean_testbit(v,b,p) #: (internal) test if bit p is true/false; return b or fail
if not 0 <= integer(p) = p then runerr(101,p)
if type(b) ~== "string" then runerr(103,b)
if v = ishift(ord(b[-p/8-1]), -(p%8)+1) then return b
end
procedure boolean_op(iop,b1,b2) #: boolean helper
local b3,i
static z
initial z := char(0)
if type(b1) ~== "string" then runerr(103,b1)
if type(b2) ~== "string" then runerr(103,b2)
b3 := ""
every i := -1 to -max(*b1,*b2) by -1 do
b3 := char(iop(ord(b1[i]|z),ord(b2[i]|z))) || b3
return b3
end

View file

@ -0,0 +1,5 @@
printLogic := method(a,b,
writeln("a and b is ", a and b)
writeln("a or b is ", a or b)
writeln("not a is ", a not)
)

View file

@ -0,0 +1 @@
aon=: *.`+.`(-.@[)`:0

View file

@ -0,0 +1,6 @@
a=: 0 0 1 1 NB. Work on vectors to show all possible
b=: 0 1 0 1 NB. 2-bit combos at once.
a aon b
0 0 0 1
0 1 1 1
1 1 0 0

View file

@ -0,0 +1,11 @@
(2b10001 b. table/~i.4);(2b10110 b. table/~i.4);<2b10000 b. table/~i.4
┌───────────────┬───────────────┬───────────────┐
│┌─────┬───────┐│┌─────┬───────┐│┌─────┬───────┐│
││17 b.│0 1 2 3│││22 b.│0 1 2 3│││16 b.│0 1 2 3││
│├─────┼───────┤│├─────┼───────┤│├─────┼───────┤│
││0 │0 0 0 0│││0 │0 1 2 3│││0 │0 0 0 0││
││1 │0 1 0 1│││1 │1 0 3 2│││1 │0 0 0 0││
││2 │0 0 2 2│││2 │2 3 0 1│││2 │0 0 0 0││
││3 │0 1 2 3│││3 │3 2 1 0│││3 │0 0 0 0││
│└─────┴───────┘│└─────┴───────┘│└─────┴───────┘│
└───────────────┴───────────────┴───────────────┘

View file

@ -0,0 +1,15 @@
fn logical_operations(anon a: bool, anon b: bool) {
println("a and b is {}", a and b)
println("a or b is {}", a or b)
println("not a is {}", not a)
}
fn main() {
let a = true
let b = false
logical_operations(a, b)
// Extra operations
println("a equals b is {}", a == b)
println("a xor b is {}", (a ^ b) == true) // == true ensures bool
}

Some files were not shown because too many files have changed in this diff Show more