Buch Cover Buch Cover Buch Cover Buch Cover

Web-Code: - Webcode Help

Boole'sche Ausdrücke (Selektionen)

Die Symbole "|" bzw. "&" stehen hier für die logische ODER- bzw. die logische UND-Verknüpfung. "&" wird prioritär vor "|" ausgeführt. Das Symbol "!" bezeichne die logische Umkehrung (Negation).

  1. Berechnen Sie damit (true | false) & (false | !true).
  2. Berechnen Sie die folgenden Ausdrücke mit der Bedingung, dass a den Wert 5 und x den Wert (-7) hat. Beachte, dass die logischen Operatoren stärker binden (Klammern) als die Gleichheit.
    • 17 < 19
    • -3 < -8
    • (4 > 3) & (3 > 4) 
    • (8 % 3 = 0) | (8 % 2 = 0)
    • (-13 < -8) | (-1 < 0) & (2 > 3)
    • true | false = (5 < 2 * 3) & (false & true)
    • a <  x
    • -x <  -a - 2
  3. Gegeben a = true, b = false, c = true. Berechnen Sie:
    • a  & (b | c)
    • (b & a) | c
    • b  & (a | c)
    • (a & b) | (a & c)
    • (( ! a) | (! b)) & ((! a) | (! c))
  4. Versuchen Sie die folgenden logischen Ausdrücke nur mit den Operatoren AND und NOT darzustellen. Ein ODER (|) darf also nicht mehr vorkommen.
    • ! (a | b)
    • a | (b & c)

0 Kommentare

Bitte melde dich an um einen Kommentar abzugeben

5 Lösung(en)

def test():
    
    a = 5
    x = -7
    print 17 < 19
    print -3 < -8
    print (4 > 3) & (3 > 4) 
    print (8 % 3 == 0) | (8 % 2 == 0)
    print (-13 < -8) | (-1 < 0) & (2 > 3)
    print True | False == (5 < 2 * 3) & (False & True)
    print a <  x
    print -x <  -a - 2

    a = True
    b = False
    c = True

    print a  & (b | c)
    print (b & a) | c
    print b  & (a | c)
    print (a & b) | (a & c)
    print (( not a) | (not b)) & ((not a) | (not c))

test()

                
*process langlvl(saa2);
*process limits(fixeddec(31));
*process aggregate, attributes;
*process flag(W), source, insource, options, xref,nest, number, offset;
*process gonumber, snap;
*process or ('!') not ('^'); /* module specific */

 Boole : proc options(main);
 /* ********************************************************** */
 /* Autor : philipp gressly freimann (@ sanits-training.ch)    */
 /* Datum : 10. Nov. 2011                                      */
 /* Aufgabe 3.2 (Programmieraufgaben.ch: Boolesche Ausdruecke. */
 /* ********************************************************** */

   dcl TRUE  bit(1) value('1'b);
   dcl FALSE bit(1) value('0'b);


   /* Teilaufgabe a) */
   put skip list("Teilaufgabe a)");

   if(TRUE ! FALSE) & (FALSE ! (^TRUE)) then do;
       put skip list("TRUE!");
       end;
   put skip list("Ist (TRUE!) noch nicht erschienen, so hat");
   put skip list(" Teilaufgabe a) FALSE als Loesung.");


   /* Teilaufgabe b) */
   put skip list("Teilaufgabe b)");
   dcl aa fixed(15) init(5);
   dcl ax fixed(15) init(-7);

   put skip list("17 < 19", 17 < 19);
   put skip list("-3 < -8", -3 < -8);
   put skip list("(4>3) & (3 > 4)", ((4 > 3) & (3 > 4)));

   put skip list(" 8 mod 3 = 0  or  8 MOD 2 = 0",
                 (0 = MOD(8, 3)) ! (0 = MOD(8,2)));

   put skip list("(-13 < -8) ! (-1 < 0) & (2 > 3)" ,
                  (-13 < -8) ! (-1 < 0) & (2 > 3));

   put skip list ("TRUE OR FALSE = (5 < 2*3) & (FALSE & TRUE)",
                   ((TRUE  ! FALSE) = ((5 < 2*3) & (FALSE & TRUE))) );
   put skip list ("a < x", aa < ax);
   put skip list ("x < -a-2", ax < -aa - 2);

   /* Teilaufgabe c) */
   put skip list("Teilaufgabe c)");
   DCL a BIT(1), b BIT(1), c BIT(1);
   a = TRUE ;
   b = FALSE;
   c = TRUE ;

   put skip list("a & (b ! c): ",
                 (a & (b ! c))  );
   put skip list("(b & a) ! c: ",
                 ((b & a) ! c));
   put skip list("b & (a ! c): ",
                  b & (a ! c) );
   put skip list("(a & b) ! (a & c): ", (a & b) ! (a & c));
   put skip list("((^a) ! (^b)) & ((^a) ! (^c)): ",
                  ((^a) ! (^b)) & ((^a) ! (^c)) );

 END Boole;
                

Lösung von: Philipp G. Freimann (BBW (Berufsbildungsschule Winterthur) https://www.bbw.ch)

package ch.programmieraufgaben.selektion;

/**
 * Aufgabe 3.2 aus Programmieren lernen
 * @author Philipp Gressly (phi AT gressly DOT ch)
 */
public class BoolescheAusdruecke {
  public static void main(String[] args) {
    new BoolescheAusdruecke().top();
  }
  
  void top() {
    aufgabeA();
    aufgabeB();
    aufgabeC();
    aufgabeD();
  }
  
  void aufgabeA() {
    System.out.println("Aufgabe a)");
    System.out.println((true | false) & (false | !true));
  }
  
  void aufgabeB() {
     System.out.println("Aufgabe b)");
     int a =   5;
     int x = - 7;
     System.out.println(17 < 19);
     System.out.println(-3 < -8);
     System.out.println((4>3) & (3 > 4));
     System.out.println((8%3 == 0) | (8%2 == 0));
     System.out.println((-13 < -8) | (-1 < 0) & (2 > 3));
     System.out.println((true | false) == ((5<2*3) & (false & true)));
     System.out.println(a < x);
     System.out.println(-x < -a - 2);
  }
  
  void aufgabeC() {
      System.out.println("Aufgabe c)");
      boolean a = true, b = false, c = true;
      System.out.println(a & (b | c));
      System.out.println((b&a) | c);
      System.out.println(b & (a|c));
      System.out.println((a&b) | (a&c));
      System.out.println(((!a) | (!b)) & ((!a) | (!c)));
  }
  
  void aufgabeD() {
      boolean a = true, b = false, c = true; // nur ein Beispiel
      System.out.println("Aufgabe d)");
      System.out.println("(!a) & (!b) : " + ((!a) & (!b)));
      System.out.println("!(!(a) & !(b & c)): " + (!(!(a) & !(b & c))));
  }
  
}  // end of class BoolescheAusdruecke
                

Lösung von: Philipp G. Freimann (BBW (Berufsbildungsschule Winterthur) https://www.bbw.ch)

package ch.santis_basis_modul_755.selection_fork;

/**
 * @author   Gilda.Thode
 * @version  1.0
 *           2018/02/28
 */
public class Exercise_3_2 {

    public Exercise_3_2() {
        // TODO Auto-generated constructor stub
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new Exercise_3_2().exercises();
    }
    
    void exercises() {
        
        exercise_a();
        exercise_b();
        exercise_c();
        exercise_d();   
    }

    private void exercise_a() {
        // TODO Auto-generated method stub
        print ("exercise_a\n");
        print (true | false & false | !true);
        print ("");
    }
    
    @SuppressWarnings({ "unused" })
    private void exercise_b() {
        // TODO Auto-generated method stub
        int a = 5;
        int x = -7;
        
        print ("exercise_b\n");
        
        if (17 < 19 ) {
            print ("1. condition ", true);
        } 
        if (-3 < -8) {
            print ("2. condition ", true);
        } 
        if (4 > 3 & 3 > 4) {
            print ("3. condition ", true);
        } 
        if ((8 % 3 == 0) || (8 % 2 == 0)) {
            print ("4. condition ", true);
        } 
        if ((-13 < -8) || (-1 < 0) && (2 > 3)) {
            print ("5. condition ", true);
        }
        if ((true || false) == ((5 < 2 * 3) && (false && true))) {
            print ("6. condition ", true);
        }
        if (a < x) {
            print ("7. condition ", true);
        }
        if (- x < -a - 2) {
            print ("8. condition ", true);
        } 
        print ("");
    }

    private void exercise_c() {
        // TODO Auto-generated method stub
        boolean a = true, c = true;
        boolean b = false;
        
        print ("exercise_c\n");
        
        if (a && (b || c)) {
            print ("1. condition ", true);
        } 
        if ((b && a) || c) {
            print ("2. condition ", true);
        } 
        if (b && (a || c)) {
            print ("3. condition ", true);
        } 
        if ((a && b) || (a && c)) {
            print ("4. condition ", true);
        } 
        if (((! a) || (!b)) && ((! a) || (! c))) {
            print ("5. condition ", true);
        }
        print ("");
    }
    
    //exercise d is the secondary part of exercise c --> see the assignments of the booleans
    //ATTENTION: the terms are only value for this assignments
    private void exercise_d() {
        // TODO Auto-generated method stub
        boolean a = true, c = true;
        boolean b = false;
        
        print ("exercise_d\n");
        
        if (!a & !b) {
            print ("1. condition ", true);
        } 
        if (!(!(a) & !((b) && !!(c)))) {
            print ("2. condition ", true);
        }
        print ("");
        
        //the different possibilities for the terms
        testab (true, true);
        testab (true, false);
        testab (false, true);
        testab (false, false);
        
        testabc (true, true, true);
        testabc (true, true, false);
        testabc (true, false, true);
        testabc (true, false, false);
        testabc (false, true, true);
        testabc (false, true, false);
        testabc (false, false, true);
        testabc (false, false, false);
    }
    
    //test methods for both terms
    private void testab(boolean a, boolean b) {
        // TODO Auto-generated method stub
        if ((!(a | b)) == (!a & !b)) {
            print ("Okay nice, first term is correct!");
        } else {
            print ("Error");
        }
        print ("");
    }
    
    private void testabc(boolean a, boolean b, boolean c) {
        // TODO Auto-generated method stub
        if ((a | (b & c) == !(!(a) & !((b) && !!(c))))) {
            print ("Okay nice, second term is correct!");
        } else {
            print ("Error");
        }
        print ("");
    }
    
    //three print methods
    private void print(boolean truefalse) {
        // TODO Auto-generated method stub
        System.out.println(truefalse);
    }
    
    private void print(String string) {
        // TODO Auto-generated method stub
        System.out.println(string);
    }
    
    private void print(String string, boolean b) {
        // TODO Auto-generated method stub
        System.out.println(string + b);
    }
}//end of class
                

Lösung von: Gilda Thode (SANTIS Training AG)

/*  (true | false) & (false | !true)
                              \----/
<=> (true | false) & (false | false)
    \------------/   \-------------/
<=>      true      &      false
         \--------------------/
<=>              false                                */
console.log( (true || false) && (false || !true) );   // false


let a = 5, x = -7;

console.log( 17 < 19 );   // true
console.log( -3 < -8 );   // false


/*  (4 > 3) & (3 > 4)
    \-----/   \-----/
<=>  true   &  false
     \-------------/
<=>       false                     */
console.log( (4 > 3) && (3 > 4) );  // false


/*  (8 % 3 = 0) | (8 % 2 = 0)
    \---------/   \---------/
<=>    false    |    true
       \----------------/
<=>            true                            */
console.log( (8 % 3 == 0) || (8 % 2 == 0) );   // true


/*  (-13 < -8) | (-1 < 0) & (2 > 3)
    \--------/   \------/   \-----/
<=>    true    |   true   &  false
                   \-------------/   (& vor |)
<=>    true    |        false
       \--------------------/
<=>             true                                */
console.log( (-13 < -8) || (-1 < 0) && (2 > 3) );   // true


/*  true | false = (5 < 2 * 3) & (false & true)
    \----------/        \----/   \------------/
<=>     true     = (5 <   6  ) &      false
                   \---------/
<=>     true     =    true     &      false
                      \-------------------/
<=>     true     =           false
        \------------------------/
<=>               false                                            */
console.log( true || false == (5 < 2 * 3) && (false && true) );    // true (!)
// hier muss noch eine klammer gesetzt werden:
console.log( (true || false) == (5 < 2 * 3) && (false && true) );  // false


/*   a < x
     \---/
<=> 5 < -7  <=> false   */
console.log( a < x );   // false


/*  -x < -a - 2
    \/   \----/
<=> +7 < -5 - 2
         \----/
<=> 7  <   -7    <=> false    */
console.log( -x < -a - 2 );   // false


a = true;
let b = false, c = true;

/*   a   & (b      |     c)
     |     \--------------/
<=> true &  (false | true)
            \------------/
<=> true &       true
     \--------------/
           true                 */
console.log( a && (b || c) );   // true


/*  (b     & a   ) |  c
    \------------/    |
<=> (false & true) | true
    \------------/
<=>      false     | true
         \--------------/
<=>            true             */
console.log( (b && a) || c );   // true


/*    b   & (a    |    c)
      |     \-----------/
<=> false & (true | true)
            \-----------/
<=> false &     true
    \--------------/
         false                  */
console.log( b && (a || c) );   // false


/*  (  a  &   b  ) | (  a  &   c )
       |      |         |      |
<=> (true & false) | (true & true)
    \------------/   \-----------/
<=>      false     |      true
         \-------------------/
<=>               true                 */
console.log( (a && b) || (a && c) );   // true


/*   ((!a)   |   (!b))   &  ((!a)    |   (!c))
        |          |           |          |
<=> ((!true) | (!false)) & ((!true)  | (!true))
     \-----/   \------/     \-----/    \------/
<=>  (false  |   true)   &  (false   |  false)
     \---------------/      \----------------/
<=>         true         &         false
            \--------------------------/
<=>                     false                      */
console.log( ((!a) || (!b)) && ((!a) || (!c)) );   // false


// anwendung des gesetzes nach de Morgan
// https://de.wikipedia.org/wiki/De-morgansche_Gesetze
// in kürze: diskunktion kann man durch negation und konjunktion ersetzen
/*
              I.
a b
0 0:  !(a | b) <=> !a & !b
       \-----/     \/   \/
         !0    <=> 1  & 1
         \/        \----/
         1     <=>    1        (1)

0 1:  !(a | b) <=> !a & !b
       \-----/     \/   \/
         !1    <=> 1  & 0
         \/        \----/
         0     <=>    0        (1)


1 0:  !(a | b) <=> !a & !b
       \-----/     \/   \/
         !1    <=> 0  & 1
         \/        \----/
         0     <=>    0        (1)

1 1:  !(a | b) <=> !a & !b
       \-----/     \/   \/
         !1    <=> 0  & 0
         \/        \----/
         0     <=>    0        (1)    */
console.log( !(a || b) == !a && !b );

/*

               II.

a b c
0 0 0:   a | (b & c) <=> !(!a & !(b & c)
         |   \-----/       |     \-----/
         0 |    0    <=> !(1  & !   0)
         \-------/              \----/
             0       <=> !(1  &    1)
                          \---------/
             0       <=> !     1
                         \-----/
             0       <=>    0                (1)

0 0 1:   a | (b & c) <=> !(!a & !(b & c)
         |   \-----/       |     \-----/
         0 |    0    <=> !(1  & !   0)
         \-------/              \----/
             0       <=> !(1  &    1)
                          \---------/
             0       <=> !     1
                         \-----/
             0       <=>    0                (1)

0 1 0:   a | (b & c) <=> !(!a & !(b & c)
         |   \-----/       |     \-----/
         0 |    0    <=> !(1  & !   0)
         \-------/              \----/
             0       <=> !(1  &    1)
                          \---------/
             0       <=> !     1
                         \-----/
             0       <=>    0                (1)

0 1 1:   a | (b & c) <=> !(!a & !(b & c)
         |   \-----/        |    \-----/
         0 |    1    <=>  !(1  & !  1)
         \-------/               \----/
             1       <=>  !(1  &   0)
                           \--------/
             1       <=>  !    0
                          \----/
             1       <=>    1                (1)

1 0 0:   a | (b & c) <=> !(!a & !(b & c)
         |   \-----/        |    \-----/
         1 |    0    <=>  !(0  & !  0)
         \-------/               \----/
             1       <=>  !(0  &   1)
                           \--------/
             1       <=>  !    0
                          \----/
             1       <=>    1                (1)

1 0 1:   a | (b & c) <=> !(!a & !(b & c)
         |   \-----/        |    \-----/
         1 |    0    <=>  !(0  & !  0)
         \------/                \----/
             1       <=>  !(0  &   1)
                           \--------/
             1       <=>  !    0
                          \----/
             1       <=>    1                (1)

1 1 0:   a | (b & c) <=> !(!a & !(b & c)
         |   \-----/        |    \-----/
         1 |    0    <=>  !(0  & !  0)
         \------/                \----/
             1       <=>  !(0  &   1)
                           \--------/
             1       <=>  !    0
                          \----/
             1       <=>    1                (1)

1 1 1:   a | (b & c) <=> !(!a & !(b & c)
         |   \-----/        |    \-----/
         1 |    1    <=>  !(0  & !  1)
         \------/                \---/
             1       <=>  !(0  &   0)
                          \--------/
             1       <=>  !    0
                          \----/
             1       <=>    1                (1) */
console.log( a || (b && c) == !(!a && !(b && c)) );          // lissalanda@gamx.at            

                

Lösung von: Lisa Salander (Heidi-Klum-Gymnasium Bottrop)

Verifikation/Checksumme:

  1. false
  2. Antworten:
    • 17 < 19 -> true
    • -3 < -8 -> false
    • (4 > 3) & (3 > 4) -> false
    • (8 % 3 = 0) | (8 % 2 = 0) -> true
    • (-13 < -8) | (-1 < 0) & (2 > 3) -> true
    • true | false = (5 < 2*3) & (false & true) -> false
    • a < x     ->    false
    • -x < -a - 2    ->    false
  3. true, true, false, true, false
    • (! a) & (! b)
    • !(!(a)  & !(b & c))

Aktionen

Bewertung

Durchschnittliche Bewertung:

Eigene Bewertung:
Bitte zuerst anmelden

Meta

Zeit: 0.5
Schwierigkeit: Mittel
Webcode: tby9-5gzh
Autor: Philipp G. Freimann (BBW (Berufsbildungsschule Winterthur) https://www.bbw.ch)

Zu Aufgabenblatt hinzufügen