Compare commits
44 Commits
6641946bad
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 60d5231717 | |||
| fa1c091565 | |||
| fd3229410c | |||
| f86c908d45 | |||
| 1b1b781b84 | |||
| 2b44a0c54c | |||
| f278500d27 | |||
| dc6f46777d | |||
| 97a06db946 | |||
| 7433401bf0 | |||
| 950942d07d | |||
| 405808a47d | |||
| 00c4d85bd9 | |||
| 07b0931e97 | |||
| caa24ac777 | |||
| f5d978bd7c | |||
| 9c1941c9d8 | |||
| 2921cc354a | |||
| 466eabeece | |||
| 48529c79e3 | |||
| 5f6820fcec | |||
| 23a8ba3a49 | |||
| 7cc2039050 | |||
| 3d49ab9b7a | |||
| f292d7e5dc | |||
| 2ab9b63a08 | |||
| 4be6896a0f | |||
| c48f703744 | |||
| 0b9378cea1 | |||
| d877f3905c | |||
| 38c4614e3e | |||
| 888728d039 | |||
| 0856bfc0b0 | |||
| b315e666b8 | |||
| 3b1c190543 | |||
| 6d774a6a4c | |||
| 79bfcf57bb | |||
| 9b225b0551 | |||
| 39be87d52f | |||
| 89c8e63f4b | |||
| 73b7817dcd | |||
| d490406892 | |||
| 004204c9e9 | |||
| 3de689d6fc |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
!/docs
|
!/docs
|
||||||
!/notes
|
!/notes
|
||||||
|
!/notes/*.pdf
|
||||||
|
!/notes/*.md
|
||||||
!/protocol
|
!/protocol
|
||||||
!/protocol/*.md
|
!/protocol/*.md
|
||||||
|
|
||||||
|
|||||||
31
README.md
31
README.md
@@ -4,11 +4,13 @@ Diese Repository ist für die Übungsgruppe am Mittwoch.
|
|||||||
|
|
||||||
- Protokolle findet man [hier](./protocol).
|
- Protokolle findet man [hier](./protocol).
|
||||||
- Notizen findet man [hier](./notes).
|
- Notizen findet man [hier](./notes).
|
||||||
|
- Symbolverzeichnis findet man in [notes/glossar.md](./notes/glossar.md).
|
||||||
|
|
||||||
## LaTeX ##
|
## LaTeX ##
|
||||||
|
|
||||||
Folgendes Einführungsvideo hat Emanuel erstellt <https://www.youtube.com/watch?v=HPUGlcZNG2k>.
|
Folgendes Einführungsvideo hat Emanuel erstellt <https://www.youtube.com/watch?v=HPUGlcZNG2k>.
|
||||||
Alternativ kann es auch sinnvoll(er) mit Markdown/Pandocs zu arbeiten.
|
<br>
|
||||||
|
Alternativ zu LaTeX kann es evtl. sinnvoller sein, mit Markdown/Pandocs zu arbeiten.
|
||||||
|
|
||||||
## Wahrheitstabelle-Generator ##
|
## Wahrheitstabelle-Generator ##
|
||||||
|
|
||||||
@@ -23,3 +25,30 @@ Beispiele aus der Übung:
|
|||||||
|
|
||||||
Das Tool ist klug genug, um das Weglassen der äußersten Klammern
|
Das Tool ist klug genug, um das Weglassen der äußersten Klammern
|
||||||
und `A0 && A1 && A2` statt `((A0 && A1) && A2)` u. Ä. zu zulassen.
|
und `A0 && A1 && A2` statt `((A0 && A1) && A2)` u. Ä. zu zulassen.
|
||||||
|
|
||||||
|
## Zur Klausur ##
|
||||||
|
|
||||||
|
- Datum: (siehe VL + Moodle)
|
||||||
|
- Zulassung: TBA
|
||||||
|
|
||||||
|
### Vorbereitung ###
|
||||||
|
|
||||||
|
Empfehlung:
|
||||||
|
|
||||||
|
1. die Definitionen + Resultate im den VL-Folien komplett durchgehen:
|
||||||
|
- prüfen, dass man die Hauptaspekte begreift;
|
||||||
|
- strikt zw. den paar Dingen, die wirklich zur Definition / zum Resultat gehören,
|
||||||
|
<br/>
|
||||||
|
und den Anmerkungen unterscheiden.
|
||||||
|
2. in die assoziierten Übungsaufgaben schauen und sowohl die Lehre als auch die Anwendungen vertiefen;
|
||||||
|
3. Stichpunkte von »häufigen Fehlern« (bspw. die man persönlich macht)
|
||||||
|
sowie »gewöhnlichen Missverständnissen« erstellen.
|
||||||
|
|
||||||
|
Vor der Klausur gut ausschlafen und auf die Ernährung aufpassen.
|
||||||
|
|
||||||
|
Während der Klausur:
|
||||||
|
|
||||||
|
1. Keine Ablenkungen oder Kommunikationsquellen.
|
||||||
|
2. Aufgaben sorgfältig durchlesen und auf Antwortformat achten (insbes. bei „leeren“ Feldern).
|
||||||
|
3. Zeit gut managen. Mal muss man entscheiden _»Soll ich jetzt bei dieser Frage auf Kosten der anderen weitere Zeit verbringen, oder weitermachen und später darauf zurück kommen?«_
|
||||||
|
4. Übersicht über Fortschritt vor Augen halten.
|
||||||
|
|||||||
4
codego/.gitignore
vendored
4
codego/.gitignore
vendored
@@ -18,9 +18,9 @@
|
|||||||
|
|
||||||
## Go Source
|
## Go Source
|
||||||
!/aussagenlogik
|
!/aussagenlogik
|
||||||
!/aussagenlogik/rekursion
|
!/aussagenlogik/recursion
|
||||||
!/aussagenlogik/schema
|
!/aussagenlogik/schema
|
||||||
!/aussagenlogik/syntaxbaum
|
!/aussagenlogik/formulae
|
||||||
!/core
|
!/core
|
||||||
!/core/environment
|
!/core/environment
|
||||||
!/core/utils
|
!/core/utils
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ run_programme;
|
|||||||
|
|
||||||
## Offene Challenges ##
|
## Offene Challenges ##
|
||||||
|
|
||||||
In der Datei `aussagenlogik/rekursion.go` (relativ zu diesem Ordner) findet man mehrere leere Methoden (mit dem Kommentar `// Herausforderung...`). Wer es mag, kann versuchen, an seinem Rechner diese Methoden zu definieren und auszuprobieren.
|
In dem Ordner `aussagenlogik/recursion` (relativ zum aktuellen Ordner) findet man mehrere leere Methoden (mit dem Kommentar `// Herausforderung...`). Wer es mag, kann versuchen, an seinem Rechner diese Methoden zu definieren und auszuprobieren.
|
||||||
|
|
||||||
### Händisch testen ###
|
### Händisch testen ###
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ Diese Tests existieren parallel zu jedem Modul und folgen dem Namensschema `..._
|
|||||||
```bash
|
```bash
|
||||||
chmod +x scripts/test.sh
|
chmod +x scripts/test.sh
|
||||||
```
|
```
|
||||||
- In `aussagenlogik/rekursion/rekursion_test.go` beim relevanten Testteil eine oder mehrere der Zeilen
|
- In `aussagenlogik/recursion/recursion_test.go` beim relevanten Testteil eine oder mehrere der Zeilen
|
||||||
```go
|
```go
|
||||||
test.Skip("Methode noch nicht implementiert")
|
test.Skip("Methode noch nicht implementiert")
|
||||||
```
|
```
|
||||||
|
|||||||
178
codego/aussagenlogik/formulae/formulae_advanced.go
Normal file
178
codego/aussagenlogik/formulae/formulae_advanced.go
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
package formulae
|
||||||
|
|
||||||
|
import "logik/core/utils"
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* METHOD Get Atoms
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func schemeGetAtoms(fml Formula, prevValues [](*[]Formula)) *[]Formula {
|
||||||
|
if fml.IsAtom() {
|
||||||
|
return &[]Formula{fml.Copy()}
|
||||||
|
} else {
|
||||||
|
var results = []Formula{}
|
||||||
|
for _, prevValue := range prevValues {
|
||||||
|
results = append(results, *prevValue...)
|
||||||
|
}
|
||||||
|
return &results
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var fnGetAtoms = CreateFromSchemeFmlsValued(schemeGetAtoms)
|
||||||
|
|
||||||
|
func (fml Formula) GetAtoms() []Formula {
|
||||||
|
return *fnGetAtoms(fml)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* TYPE FormulaPair, FormulaPairs
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
type FormulaPair struct {
|
||||||
|
Pos Formula
|
||||||
|
Neg Formula
|
||||||
|
}
|
||||||
|
|
||||||
|
type FormulaPairs []FormulaPair
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* Methods for FormulaPairs
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func NewFormulaPairs(pairs []FormulaPair) FormulaPairs { return pairs }
|
||||||
|
|
||||||
|
func (pairs FormulaPairs) Pos() []Formula {
|
||||||
|
var fmls = make([]Formula, len(pairs))
|
||||||
|
for i, pair := range pairs {
|
||||||
|
fmls[i] = pair.Pos
|
||||||
|
}
|
||||||
|
return fmls
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pairs FormulaPairs) Neg() []Formula {
|
||||||
|
var fmls = make([]Formula, len(pairs))
|
||||||
|
for i, pair := range pairs {
|
||||||
|
fmls[i] = pair.Neg
|
||||||
|
}
|
||||||
|
return fmls
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* TYPE KNF, DNF, Horn
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
type FormulaConjunct []Formula
|
||||||
|
type FormulaDisjunct []Formula
|
||||||
|
type FormulaKNF []FormulaDisjunct
|
||||||
|
type FormulaDNF []FormulaConjunct
|
||||||
|
type FormulaHornClause struct {
|
||||||
|
Pos FormulaDisjunct
|
||||||
|
Neg FormulaConjunct
|
||||||
|
}
|
||||||
|
type FormulaHorn []FormulaHornClause
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* Methods for KNF, DNF, Horn
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func (fml FormulaDisjunct) ToFormula() Formula {
|
||||||
|
return Disjunction(fml)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml FormulaConjunct) ToFormula() Formula {
|
||||||
|
return Conjunction(fml)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml FormulaKNF) ToFormula() Formula {
|
||||||
|
var termsAsFormulae = make([]Formula, len(fml))
|
||||||
|
for i, term := range fml {
|
||||||
|
termsAsFormulae[i] = term.ToFormula()
|
||||||
|
}
|
||||||
|
return Conjunction(termsAsFormulae)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml FormulaDNF) ToFormula() Formula {
|
||||||
|
var termsAsFormulae = make([]Formula, len(fml))
|
||||||
|
for i, term := range fml {
|
||||||
|
termsAsFormulae[i] = term.ToFormula()
|
||||||
|
}
|
||||||
|
return Disjunction(termsAsFormulae)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml FormulaHornClause) ToFormula() Formula {
|
||||||
|
return Implies(fml.Neg.ToFormula(), fml.Pos.ToFormula())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml FormulaHorn) ToFormula() Formula {
|
||||||
|
var hornclausesAsFormulae = make([]Formula, len(fml))
|
||||||
|
for i, hornclause := range fml {
|
||||||
|
hornclausesAsFormulae[i] = hornclause.ToFormula()
|
||||||
|
}
|
||||||
|
return Conjunction(hornclausesAsFormulae)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAtomsFromArrayOfLiterals(fmls []Formula) []string {
|
||||||
|
var atoms = []string{}
|
||||||
|
var m = map[string]bool{}
|
||||||
|
for _, fml := range fmls {
|
||||||
|
if fml.IsLiteral() {
|
||||||
|
m[fml.GetName()] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for name, _ := range m {
|
||||||
|
atoms = append(atoms, name)
|
||||||
|
}
|
||||||
|
utils.SortStrings(&atoms)
|
||||||
|
return atoms
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAtomsFromArrayOfArraysOfLiterals(fmlArrays [][]Formula) []string {
|
||||||
|
var atoms = []string{}
|
||||||
|
var m = map[string]bool{}
|
||||||
|
for _, fmls := range fmlArrays {
|
||||||
|
for _, atom := range getAtomsFromArrayOfLiterals(fmls) {
|
||||||
|
m[atom] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for name, _ := range m {
|
||||||
|
atoms = append(atoms, name)
|
||||||
|
}
|
||||||
|
utils.SortStrings(&atoms)
|
||||||
|
return atoms
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml FormulaConjunct) GetAtoms() []string {
|
||||||
|
return getAtomsFromArrayOfLiterals(fml)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml FormulaDisjunct) GetAtoms() []string {
|
||||||
|
return getAtomsFromArrayOfLiterals(fml)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml FormulaHornClause) GetAtoms() []string {
|
||||||
|
return getAtomsFromArrayOfArraysOfLiterals([][]Formula{fml.Pos, fml.Neg})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml FormulaKNF) GetAtoms() []string {
|
||||||
|
var fmlArrays = make([][]Formula, len(fml))
|
||||||
|
for i, term := range fml {
|
||||||
|
fmlArrays[i] = term
|
||||||
|
}
|
||||||
|
return getAtomsFromArrayOfArraysOfLiterals(fmlArrays)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml FormulaDNF) GetAtoms() []string {
|
||||||
|
var fmlArrays = make([][]Formula, len(fml))
|
||||||
|
for i, term := range fml {
|
||||||
|
fmlArrays[i] = term
|
||||||
|
}
|
||||||
|
return getAtomsFromArrayOfArraysOfLiterals(fmlArrays)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml FormulaHorn) GetAtoms() []string {
|
||||||
|
var fmlArrays = make([][]Formula, 2*len(fml))
|
||||||
|
for i, hornclause := range fml {
|
||||||
|
fmlArrays[i] = append(hornclause.Neg, hornclause.Pos...)
|
||||||
|
}
|
||||||
|
return getAtomsFromArrayOfArraysOfLiterals(fmlArrays)
|
||||||
|
}
|
||||||
151
codego/aussagenlogik/formulae/formulae_basic.go
Normal file
151
codego/aussagenlogik/formulae/formulae_basic.go
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
package formulae
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* TYPE Formula
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
type Formula struct {
|
||||||
|
kind string
|
||||||
|
name string
|
||||||
|
expr string
|
||||||
|
valence int
|
||||||
|
subformulae [](*Formula)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* METHODS
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func (fml *Formula) SetKind(kind string) { fml.kind = kind }
|
||||||
|
|
||||||
|
func (fml Formula) GetKind() string { return fml.kind }
|
||||||
|
|
||||||
|
func (fml *Formula) SetExpr(expr string) { fml.expr = expr }
|
||||||
|
|
||||||
|
func (fml Formula) GetExpr() string { return fml.expr }
|
||||||
|
|
||||||
|
func (fml Formula) GetName() string { return fml.name }
|
||||||
|
|
||||||
|
func (fml *Formula) SetSubformulae(subFmls [](*Formula)) {
|
||||||
|
fml.subformulae = subFmls
|
||||||
|
fml.valence = len(subFmls)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml Formula) GetSubFormulae() []Formula {
|
||||||
|
var n int = fml.valence
|
||||||
|
var subFmls = make([]Formula, n)
|
||||||
|
for i, subFml := range fml.subformulae {
|
||||||
|
subFmls[i] = *subFml
|
||||||
|
}
|
||||||
|
return subFmls
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml Formula) GetAllSubFormulae() []Formula {
|
||||||
|
var subFml = fml.GetSubFormulae()
|
||||||
|
var result = []Formula{fml.Copy()}
|
||||||
|
for _, child := range subFml {
|
||||||
|
result = append(result, child.GetAllSubFormulae()...)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml Formula) GetAllSubFormulaeStrict() []Formula {
|
||||||
|
var subFml = fml.GetSubFormulae()
|
||||||
|
var result = []Formula{}
|
||||||
|
for _, child := range subFml {
|
||||||
|
result = append(result, child.GetAllSubFormulae()...)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml Formula) GetChild(indexOpt ...int) Formula {
|
||||||
|
var index int = 0
|
||||||
|
if len(indexOpt) > 0 {
|
||||||
|
index = indexOpt[0]
|
||||||
|
}
|
||||||
|
var subFml Formula
|
||||||
|
if 0 <= index && index < fml.valence {
|
||||||
|
subFml = *(fml.subformulae[index])
|
||||||
|
} else {
|
||||||
|
panic(fmt.Sprintf("Instance has no child of index %d !", index))
|
||||||
|
}
|
||||||
|
return subFml
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml Formula) Pretty(preindentOpt ...string) string {
|
||||||
|
var preindent string = ""
|
||||||
|
if len(preindentOpt) > 0 {
|
||||||
|
preindent = preindentOpt[0]
|
||||||
|
}
|
||||||
|
return fml.pretty(preindent, " ", "", 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml Formula) pretty(preindent string, tab string, prepend string, depth int) string {
|
||||||
|
var indent string = preindent + strings.Repeat(tab, depth)
|
||||||
|
switch fml.valence {
|
||||||
|
case 0:
|
||||||
|
switch kind := fml.kind; kind {
|
||||||
|
case "atom", "generic":
|
||||||
|
return indent + prepend + kind + " " + fml.expr
|
||||||
|
default:
|
||||||
|
return indent + prepend + kind
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
var lines string = indent + prepend + fml.kind
|
||||||
|
prepend = "|__ "
|
||||||
|
for _, subFml := range fml.subformulae {
|
||||||
|
lines += "\n" + subFml.pretty(preindent, tab, prepend, depth+1)
|
||||||
|
}
|
||||||
|
return lines
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// shallow copy
|
||||||
|
func (fml Formula) Copy() Formula {
|
||||||
|
return Formula{
|
||||||
|
expr: fml.expr,
|
||||||
|
kind: fml.kind,
|
||||||
|
valence: fml.valence,
|
||||||
|
subformulae: fml.subformulae,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml Formula) Deepcopy() Formula {
|
||||||
|
var subFmls = make([](*Formula), len(fml.subformulae))
|
||||||
|
for i, subFml := range fml.subformulae {
|
||||||
|
subFmlCopy := subFml.Deepcopy()
|
||||||
|
subFmls[i] = &subFmlCopy
|
||||||
|
}
|
||||||
|
return Formula{
|
||||||
|
expr: fml.expr,
|
||||||
|
kind: fml.kind,
|
||||||
|
valence: fml.valence,
|
||||||
|
subformulae: subFmls,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
|
||||||
|
* METHODS: Recognition of Formula-Types
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func (fml Formula) IsIrreducible() bool { return fml.valence == 0 }
|
||||||
|
func (fml Formula) IsAtom() bool { return fml.kind == "atom" }
|
||||||
|
func (fml Formula) IsPositiveLiteral() bool { return fml.IsAtom() }
|
||||||
|
func (fml Formula) IsNegativeLiteral() bool { return fml.IsNegation() && fml.GetChild().IsAtom() }
|
||||||
|
func (fml Formula) IsLiteral() bool { return fml.IsPositiveLiteral() || fml.IsNegativeLiteral() }
|
||||||
|
func (fml Formula) IsGeneric() bool { return fml.kind == "generic" }
|
||||||
|
func (fml Formula) IsTautologySymbol() bool { return fml.kind == "taut" }
|
||||||
|
func (fml Formula) IsContradictionSymbol() bool { return fml.kind == "contradiction" }
|
||||||
|
func (fml Formula) IsConnective() bool { return fml.valence > 0 }
|
||||||
|
func (fml Formula) IsNegation() bool { return fml.kind == "not" }
|
||||||
|
func (fml Formula) IsConjunction2() bool { return fml.kind == "and2" }
|
||||||
|
func (fml Formula) IsConjunction() bool { return fml.kind == "and" || fml.kind == "and2" }
|
||||||
|
func (fml Formula) IsDisjunction2() bool { return fml.kind == "or2" }
|
||||||
|
func (fml Formula) IsDisjunction() bool { return fml.kind == "or" || fml.kind == "or2" }
|
||||||
|
func (fml Formula) IsImplication() bool { return fml.kind == "implies" }
|
||||||
|
func (fml Formula) IsDoubleImplication() bool { return fml.kind == "iff" }
|
||||||
147
codego/aussagenlogik/formulae/formulae_construction.go
Normal file
147
codego/aussagenlogik/formulae/formulae_construction.go
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
package formulae
|
||||||
|
|
||||||
|
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
|
||||||
|
* CONSTANTS
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
var Tautology = Formula{
|
||||||
|
kind: "taut",
|
||||||
|
expr: "1",
|
||||||
|
valence: 0,
|
||||||
|
subformulae: [](*Formula){},
|
||||||
|
}
|
||||||
|
|
||||||
|
var Contradiction = Formula{
|
||||||
|
kind: "contradiction",
|
||||||
|
expr: "0",
|
||||||
|
valence: 0,
|
||||||
|
subformulae: [](*Formula){},
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
|
||||||
|
* METHODS: Constructions
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func Atom(name string) Formula {
|
||||||
|
return Formula{
|
||||||
|
kind: "atom",
|
||||||
|
name: name,
|
||||||
|
expr: name,
|
||||||
|
valence: 0,
|
||||||
|
subformulae: [](*Formula){},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NegatedAtom(name string) Formula {
|
||||||
|
return Negation(Atom(name))
|
||||||
|
}
|
||||||
|
|
||||||
|
func Generic(name string) Formula {
|
||||||
|
return Formula{
|
||||||
|
kind: "generic",
|
||||||
|
name: name,
|
||||||
|
expr: "{" + name + "}",
|
||||||
|
valence: 0,
|
||||||
|
subformulae: [](*Formula){},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Negation(fml Formula) Formula {
|
||||||
|
var name string
|
||||||
|
if fml.IsAtom() {
|
||||||
|
name = fml.GetName()
|
||||||
|
}
|
||||||
|
var expr = fml.expr
|
||||||
|
expr = "!" + expr
|
||||||
|
return Formula{
|
||||||
|
kind: "not",
|
||||||
|
name: name, // preserves name of negated atoms
|
||||||
|
expr: expr,
|
||||||
|
valence: 1,
|
||||||
|
subformulae: [](*Formula){&fml},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Conjunction2(fml1 Formula, fml2 Formula) Formula {
|
||||||
|
return Formula{
|
||||||
|
kind: "and2",
|
||||||
|
expr: "(" + fml1.expr + " && " + fml2.expr + ")",
|
||||||
|
valence: 2,
|
||||||
|
subformulae: [](*Formula){&fml1, &fml2},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Conjunction(fmls []Formula) Formula {
|
||||||
|
switch len(fmls) {
|
||||||
|
case 0:
|
||||||
|
return Tautology
|
||||||
|
case 1:
|
||||||
|
return fmls[0]
|
||||||
|
}
|
||||||
|
var expr string = ""
|
||||||
|
var subFmls = make([](*Formula), len(fmls))
|
||||||
|
for i, fml := range fmls {
|
||||||
|
(func(i int, subFml Formula) { subFmls[i] = &subFml })(i, fml)
|
||||||
|
if i > 0 {
|
||||||
|
expr += " && "
|
||||||
|
}
|
||||||
|
expr += fml.expr
|
||||||
|
}
|
||||||
|
return Formula{
|
||||||
|
kind: "and",
|
||||||
|
expr: "(" + expr + ")",
|
||||||
|
valence: len(subFmls),
|
||||||
|
subformulae: subFmls,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Disjunction2(fml1 Formula, fml2 Formula) Formula {
|
||||||
|
return Formula{
|
||||||
|
kind: "or2",
|
||||||
|
expr: "(" + fml1.expr + " || " + fml2.expr + ")",
|
||||||
|
valence: 2,
|
||||||
|
subformulae: [](*Formula){&fml1, &fml2},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Disjunction(fmls []Formula) Formula {
|
||||||
|
switch len(fmls) {
|
||||||
|
case 0:
|
||||||
|
return Contradiction
|
||||||
|
case 1:
|
||||||
|
return fmls[0]
|
||||||
|
}
|
||||||
|
var expr string = ""
|
||||||
|
var subFmls = make([](*Formula), len(fmls))
|
||||||
|
for i, fml := range fmls {
|
||||||
|
(func(i int, subFml Formula) { subFmls[i] = &subFml })(i, fml)
|
||||||
|
if i > 0 {
|
||||||
|
expr += " || "
|
||||||
|
}
|
||||||
|
expr += fml.expr
|
||||||
|
}
|
||||||
|
return Formula{
|
||||||
|
kind: "or",
|
||||||
|
expr: "(" + expr + ")",
|
||||||
|
valence: len(subFmls),
|
||||||
|
subformulae: subFmls,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Implies(fml1 Formula, fml2 Formula) Formula {
|
||||||
|
return Formula{
|
||||||
|
kind: "implies",
|
||||||
|
expr: "(" + fml1.expr + " -> " + fml2.expr + ")",
|
||||||
|
valence: 2,
|
||||||
|
subformulae: [](*Formula){&fml1, &fml2},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func DoubleImplication(fml1 Formula, fml2 Formula) Formula {
|
||||||
|
return Formula{
|
||||||
|
kind: "iff",
|
||||||
|
expr: "(" + fml1.expr + " <-> " + fml2.expr + ")",
|
||||||
|
valence: 2,
|
||||||
|
subformulae: [](*Formula){&fml1, &fml2},
|
||||||
|
}
|
||||||
|
}
|
||||||
165
codego/aussagenlogik/formulae/formulae_generate.go
Normal file
165
codego/aussagenlogik/formulae/formulae_generate.go
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
package formulae
|
||||||
|
|
||||||
|
// NOTE: GoLang hat noch keine generics. Erst 2022.
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* Generate int-value FN from scheme
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func CreateFromSchemeIntValued(scheme func(fml Formula, prevValues []int) int) func(fml Formula) int {
|
||||||
|
var fn func(fml Formula) int
|
||||||
|
var subFn = func(ch chan int, subFml Formula) { ch <- fn(subFml) }
|
||||||
|
fn = func(fml Formula) int {
|
||||||
|
var subFmls = fml.GetSubFormulae()
|
||||||
|
var n = len(subFmls)
|
||||||
|
var subChan = make([](chan int), n)
|
||||||
|
var prevValues = make([]int, len(subFmls))
|
||||||
|
// start parallel computations on subformulas
|
||||||
|
for i, subFml := range subFmls {
|
||||||
|
subChan[i] = make(chan int) // create Channel, since currently nil
|
||||||
|
go subFn(subChan[i], subFml)
|
||||||
|
}
|
||||||
|
// successively read values
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
prevValues[i] = <-subChan[i]
|
||||||
|
}
|
||||||
|
// apply schema to get value for formula
|
||||||
|
return scheme(fml, prevValues)
|
||||||
|
}
|
||||||
|
return fn
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* Generate string-value FN from scheme
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func CreateFromSchemeStringValued(scheme func(fml Formula, prevValues []string) string) func(fml Formula) string {
|
||||||
|
var fn func(fml Formula) string
|
||||||
|
var subFn = func(ch chan string, subFml Formula) { ch <- fn(subFml) }
|
||||||
|
fn = func(fml Formula) string {
|
||||||
|
var subFmls = fml.GetSubFormulae()
|
||||||
|
var n = len(subFmls)
|
||||||
|
var subChan = make([](chan string), n)
|
||||||
|
var prevValues = make([]string, len(subFmls))
|
||||||
|
// start parallel computations on subformulas
|
||||||
|
for i, subFml := range subFmls {
|
||||||
|
subChan[i] = make(chan string) // create Channel, since currently nil
|
||||||
|
go subFn(subChan[i], subFml)
|
||||||
|
}
|
||||||
|
// successively read values
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
prevValues[i] = <-subChan[i]
|
||||||
|
}
|
||||||
|
// apply schema to get value for formula
|
||||||
|
return scheme(fml, prevValues)
|
||||||
|
}
|
||||||
|
return fn
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* Generate *[]string-value Fn from scheme
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func CreateFromSchemeStringsValued(scheme func(fml Formula, prevValues [][]string) []string) func(fml Formula) []string {
|
||||||
|
var fn func(fml Formula) []string
|
||||||
|
var subFn = func(ch chan []string, subFml Formula) { ch <- fn(subFml) }
|
||||||
|
fn = func(fml Formula) []string {
|
||||||
|
var subFmls = fml.GetSubFormulae()
|
||||||
|
var n = len(subFmls)
|
||||||
|
var subChan = make([](chan []string), n)
|
||||||
|
var prevValues = make([][]string, len(subFmls))
|
||||||
|
// start parallel computations on subformulas
|
||||||
|
for i, subFml := range subFmls {
|
||||||
|
subChan[i] = make(chan []string) // create Channel, since currently nil
|
||||||
|
go subFn(subChan[i], subFml)
|
||||||
|
}
|
||||||
|
// successively read values
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
prevValues[i] = <-subChan[i]
|
||||||
|
}
|
||||||
|
// apply schema to get value for formula
|
||||||
|
return scheme(fml, prevValues)
|
||||||
|
}
|
||||||
|
return fn
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* Generate Formula-value Fn from scheme
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func CreateFromSchemeFmlValued(scheme func(fml Formula, prevValues []Formula) Formula) func(fml Formula) Formula {
|
||||||
|
var fn func(fml Formula) Formula
|
||||||
|
var subFn = func(ch chan Formula, subFml Formula) { ch <- fn(subFml) }
|
||||||
|
fn = func(fml Formula) Formula {
|
||||||
|
var subFmls = fml.GetSubFormulae()
|
||||||
|
var n = len(subFmls)
|
||||||
|
var subChan = make([](chan Formula), n)
|
||||||
|
var prevValues = make([]Formula, len(subFmls))
|
||||||
|
// start parallel computations on subformulas
|
||||||
|
for i, subFml := range subFmls {
|
||||||
|
subChan[i] = make(chan Formula) // create Channel, since currently nil
|
||||||
|
go subFn(subChan[i], subFml)
|
||||||
|
}
|
||||||
|
// successively read values
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
prevValues[i] = <-subChan[i]
|
||||||
|
}
|
||||||
|
// apply schema to get value for formula
|
||||||
|
return scheme(fml, prevValues)
|
||||||
|
}
|
||||||
|
return fn
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* Generate *[]Formula-value Fn from scheme
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func CreateFromSchemeFmlsValued(scheme func(fml Formula, prevValues [](*[]Formula)) *[]Formula) func(fml Formula) *[]Formula {
|
||||||
|
var fn func(fml Formula) *[]Formula
|
||||||
|
var subFn = func(ch chan *[]Formula, subFml Formula) { ch <- fn(subFml) }
|
||||||
|
fn = func(fml Formula) *[]Formula {
|
||||||
|
var subFmls = fml.GetSubFormulae()
|
||||||
|
var n = len(subFmls)
|
||||||
|
var subChan = make([](chan *[]Formula), n)
|
||||||
|
var prevValues = make([](*[]Formula), len(subFmls))
|
||||||
|
// start parallel computations on subformulas
|
||||||
|
for i, subFml := range subFmls {
|
||||||
|
subChan[i] = make(chan *[]Formula) // create Channel, since currently nil
|
||||||
|
go subFn(subChan[i], subFml)
|
||||||
|
}
|
||||||
|
// successively read values
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
prevValues[i] = <-subChan[i]
|
||||||
|
}
|
||||||
|
// apply schema to get value for formula
|
||||||
|
return scheme(fml, prevValues)
|
||||||
|
}
|
||||||
|
return fn
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* Generate {pos: Formula, ne: Formula}-value Fn from scheme
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func CreateFromSchemeFmlPairValued(scheme func(fml Formula, prevValues []FormulaPair) FormulaPair) func(fml Formula) FormulaPair {
|
||||||
|
var fn func(fml Formula) FormulaPair
|
||||||
|
var subFn = func(ch chan FormulaPair, subFml Formula) { ch <- fn(subFml) }
|
||||||
|
fn = func(fml Formula) FormulaPair {
|
||||||
|
var subFmls = fml.GetSubFormulae()
|
||||||
|
var n = len(subFmls)
|
||||||
|
var subChan = make([](chan FormulaPair), n)
|
||||||
|
var prevValues = make([]FormulaPair, len(subFmls))
|
||||||
|
// start parallel computations on subformulas
|
||||||
|
for i, subFml := range subFmls {
|
||||||
|
subChan[i] = make(chan FormulaPair) // create Channel, since currently nil
|
||||||
|
go subFn(subChan[i], subFml)
|
||||||
|
}
|
||||||
|
// successively read values
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
prevValues[i] = <-subChan[i]
|
||||||
|
}
|
||||||
|
// apply schema to get value for formula
|
||||||
|
return scheme(fml, prevValues)
|
||||||
|
}
|
||||||
|
return fn
|
||||||
|
}
|
||||||
151
codego/aussagenlogik/formulae/formulae_normalforms.go
Normal file
151
codego/aussagenlogik/formulae/formulae_normalforms.go
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
package formulae
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* METHODS: get KNF/DNF
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func (fml Formula) GetKNFparts() FormulaKNF {
|
||||||
|
var subFmls []Formula
|
||||||
|
if fml.IsDisjunctOfLiterals() {
|
||||||
|
subFmls = []Formula{fml}
|
||||||
|
} else if fml.IsKNF() {
|
||||||
|
subFmls = fml.GetSubFormulae()
|
||||||
|
} else {
|
||||||
|
panic("Formula not in KNF!")
|
||||||
|
}
|
||||||
|
var terms = make([]FormulaDisjunct, len(subFmls))
|
||||||
|
for i, subFml := range subFmls {
|
||||||
|
if subFml.IsLiteral() {
|
||||||
|
terms[i] = []Formula{subFml}
|
||||||
|
} else {
|
||||||
|
terms[i] = subFml.GetSubFormulae()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return terms
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml Formula) GetDNFparts() FormulaDNF {
|
||||||
|
var subFmls []Formula
|
||||||
|
if fml.IsDisjunctOfLiterals() {
|
||||||
|
subFmls = []Formula{fml}
|
||||||
|
} else if fml.IsKNF() {
|
||||||
|
subFmls = fml.GetSubFormulae()
|
||||||
|
} else {
|
||||||
|
panic("Formula not in DNF!")
|
||||||
|
}
|
||||||
|
var terms = make([]FormulaConjunct, len(subFmls))
|
||||||
|
for i, subFml := range subFmls {
|
||||||
|
if subFml.IsLiteral() {
|
||||||
|
terms[i] = []Formula{subFml}
|
||||||
|
} else {
|
||||||
|
terms[i] = subFml.GetSubFormulae()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return terms
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml Formula) GetHornParts() FormulaHorn {
|
||||||
|
var subFmls []Formula
|
||||||
|
if fml.IsHornClause() {
|
||||||
|
subFmls = []Formula{fml}
|
||||||
|
} else if fml.IsHornFml() {
|
||||||
|
subFmls = fml.GetSubFormulae()
|
||||||
|
} else {
|
||||||
|
panic("Formula not a Horn-Formula!")
|
||||||
|
}
|
||||||
|
var parts = make([]FormulaHornClause, len(subFmls))
|
||||||
|
for i, subFml := range subFmls {
|
||||||
|
Pos := []Formula{}
|
||||||
|
Neg := []Formula{}
|
||||||
|
var subSubFml []Formula
|
||||||
|
if subFml.IsLiteral() {
|
||||||
|
subSubFml = []Formula{subFml}
|
||||||
|
} else {
|
||||||
|
subSubFml = subFml.GetSubFormulae()
|
||||||
|
}
|
||||||
|
for _, L := range subSubFml {
|
||||||
|
if L.IsPositiveLiteral() {
|
||||||
|
Pos = append(Pos, L)
|
||||||
|
} else {
|
||||||
|
Neg = append(Neg, L.GetChild())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parts[i] = FormulaHornClause{Pos, Neg}
|
||||||
|
}
|
||||||
|
return parts
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* METHODS: check if KNF/DNF
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func onlyLiterals(fmls []Formula) bool {
|
||||||
|
for _, fml := range fmls {
|
||||||
|
if !fml.IsLiteral() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func numPositiveLiterals(fmls []Formula) int {
|
||||||
|
var n = 0
|
||||||
|
for _, fml := range fmls {
|
||||||
|
if fml.IsPositiveLiteral() {
|
||||||
|
n++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml Formula) IsConjunctOfLiterals() bool {
|
||||||
|
return fml.IsLiteral() || (fml.IsConjunction() && onlyLiterals(fml.GetSubFormulae()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml Formula) IsDisjunctOfLiterals() bool {
|
||||||
|
return fml.IsLiteral() || (fml.IsDisjunction() && onlyLiterals(fml.GetSubFormulae()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml Formula) IsHornClause() bool {
|
||||||
|
var literals = fml.GetSubFormulae()
|
||||||
|
return fml.IsLiteral() || (fml.IsDisjunction() && onlyLiterals(literals) && (numPositiveLiterals(literals) <= 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml Formula) IsKNF() bool {
|
||||||
|
if fml.IsConjunction() {
|
||||||
|
for _, subFml := range fml.GetSubFormulae() {
|
||||||
|
if !subFml.IsDisjunctOfLiterals() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return fml.IsDisjunctOfLiterals()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml Formula) IsDNF() bool {
|
||||||
|
if fml.IsDisjunction() {
|
||||||
|
for _, subFml := range fml.GetSubFormulae() {
|
||||||
|
if !subFml.IsConjunctOfLiterals() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return fml.IsConjunctOfLiterals()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fml Formula) IsHornFml() bool {
|
||||||
|
if fml.IsConjunction() {
|
||||||
|
for _, subFml := range fml.GetSubFormulae() {
|
||||||
|
if !subFml.IsHornClause() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return fml.IsHornClause()
|
||||||
|
}
|
||||||
|
}
|
||||||
158
codego/aussagenlogik/formulae/formulae_test.go
Normal file
158
codego/aussagenlogik/formulae/formulae_test.go
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
package formulae_test
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* UNIT TESTING
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
import (
|
||||||
|
"logik/aussagenlogik/formulae"
|
||||||
|
"logik/aussagenlogik/schema"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* TESTCASE KNF
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func TestRecogniseKNF(test *testing.T) {
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var fml formulae.Formula
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("A7")
|
||||||
|
assert.True(fml.IsKNF())
|
||||||
|
fml = schema.ParseExpr("! A7")
|
||||||
|
assert.True(fml.IsKNF())
|
||||||
|
fml = schema.ParseExpr("!! A7")
|
||||||
|
assert.False(fml.IsKNF())
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("(A0 || ! A1 || A7)")
|
||||||
|
assert.True(fml.IsKNF())
|
||||||
|
fml = schema.ParseExpr("(A0 && ! A1 && A7)")
|
||||||
|
assert.True(fml.IsKNF())
|
||||||
|
fml = schema.ParseExpr("(A0 && !! A1 && A7)")
|
||||||
|
assert.False(fml.IsKNF())
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("(A0 || ! A1 || A7) && (A4 || ! A5) && A1")
|
||||||
|
assert.True(fml.IsKNF())
|
||||||
|
fml = schema.ParseExpr("(A0 && ! A1 && A7) || (A4 && ! A5) || A1")
|
||||||
|
assert.False(fml.IsKNF())
|
||||||
|
fml = schema.ParseExpr("((A0 || ! A1 || A7) && (A4 || ! A5)) || A8")
|
||||||
|
assert.False(fml.IsKNF())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRecogniseDNF(test *testing.T) {
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var fml formulae.Formula
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("A7")
|
||||||
|
assert.True(fml.IsDNF())
|
||||||
|
fml = schema.ParseExpr("! A7")
|
||||||
|
assert.True(fml.IsDNF())
|
||||||
|
fml = schema.ParseExpr("!! A7")
|
||||||
|
assert.False(fml.IsDNF())
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("(A0 && ! A1 && A7)")
|
||||||
|
assert.True(fml.IsDNF())
|
||||||
|
fml = schema.ParseExpr("(A0 || ! A1 || A7)")
|
||||||
|
assert.True(fml.IsDNF())
|
||||||
|
fml = schema.ParseExpr("(A0 || !! A1 || A7)")
|
||||||
|
assert.False(fml.IsDNF())
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("(A0 && ! A1 && A7) || (A4 && ! A5) || A1")
|
||||||
|
assert.True(fml.IsDNF())
|
||||||
|
fml = schema.ParseExpr("(A0 || ! A1 || A7) && (A4 || ! A5) && A1")
|
||||||
|
assert.False(fml.IsDNF())
|
||||||
|
fml = schema.ParseExpr("((A0 && ! A1 && A7) || (A4 && ! A5)) && A8")
|
||||||
|
assert.False(fml.IsDNF())
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* TESTCASE Horn
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func TestRecogniseHorn(test *testing.T) {
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var fml formulae.Formula
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("A7")
|
||||||
|
assert.True(fml.IsHornFml())
|
||||||
|
fml = schema.ParseExpr("! A7")
|
||||||
|
assert.True(fml.IsHornFml())
|
||||||
|
fml = schema.ParseExpr("!! A7")
|
||||||
|
assert.False(fml.IsHornFml())
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("(! A0 || ! A1 || A7)")
|
||||||
|
assert.True(fml.IsHornFml())
|
||||||
|
fml = schema.ParseExpr("(A0 && ! A1 && A7)")
|
||||||
|
assert.True(fml.IsHornFml())
|
||||||
|
fml = schema.ParseExpr("(A0 && !! A1 && A7)")
|
||||||
|
assert.False(fml.IsHornFml())
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("(A0 && ! A1 && ! A7) || (A4 && ! A5) || (! A1 && ! A8)")
|
||||||
|
assert.False(fml.IsHornFml())
|
||||||
|
fml = schema.ParseExpr("(A0 && ! A1 && ! A7) || (A4 && ! A5) || (! A1 && ! A8)")
|
||||||
|
assert.False(fml.IsHornFml())
|
||||||
|
fml = schema.ParseExpr("(A0 || ! A1 || ! A7) && (A4 || ! A5) && (! A1 || ! A8)")
|
||||||
|
assert.True(fml.IsHornFml())
|
||||||
|
fml = schema.ParseExpr("((A0 || ! A1 || A7) && (A4 || ! A5)) || A8")
|
||||||
|
assert.False(fml.IsHornFml())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTransformHornToFormula(test *testing.T) {
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var fml formulae.Formula
|
||||||
|
var horn formulae.FormulaHorn
|
||||||
|
var hornClauses []formulae.FormulaHornClause
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("A8")
|
||||||
|
assert.True(fml.IsHornFml())
|
||||||
|
horn = fml.GetHornParts()
|
||||||
|
hornClauses = horn
|
||||||
|
assert.Equal(1, len(hornClauses))
|
||||||
|
assert.ElementsMatch([]string{"A8"}, hornClauses[0].Pos.GetAtoms())
|
||||||
|
assert.ElementsMatch([]string{}, hornClauses[0].Neg.GetAtoms())
|
||||||
|
assert.Equal("(1 -> A8)", horn.ToFormula().GetExpr())
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("!A8")
|
||||||
|
assert.True(fml.IsHornFml())
|
||||||
|
horn = fml.GetHornParts()
|
||||||
|
hornClauses = horn
|
||||||
|
assert.Equal(1, len(hornClauses))
|
||||||
|
assert.ElementsMatch([]string{}, hornClauses[0].Pos.GetAtoms())
|
||||||
|
assert.ElementsMatch([]string{"A8"}, hornClauses[0].Neg.GetAtoms())
|
||||||
|
assert.Equal("(A8 -> 0)", horn.ToFormula().GetExpr())
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("!A3 || A2 || !A7 || !A9")
|
||||||
|
assert.True(fml.IsHornFml())
|
||||||
|
horn = fml.GetHornParts()
|
||||||
|
hornClauses = horn
|
||||||
|
assert.Equal(1, len(hornClauses))
|
||||||
|
assert.ElementsMatch([]string{"A2"}, hornClauses[0].Pos.GetAtoms())
|
||||||
|
assert.ElementsMatch([]string{"A3", "A7", "A9"}, hornClauses[0].Neg.GetAtoms())
|
||||||
|
assert.Equal("((A3 && A7 && A9) -> A2)", horn.ToFormula().GetExpr())
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("!A3 || !A2 || !A7 || !A9")
|
||||||
|
assert.True(fml.IsHornFml())
|
||||||
|
horn = fml.GetHornParts()
|
||||||
|
hornClauses = horn
|
||||||
|
assert.Equal(1, len(hornClauses))
|
||||||
|
assert.ElementsMatch([]string{}, hornClauses[0].Pos.GetAtoms())
|
||||||
|
assert.ElementsMatch([]string{"A2", "A3", "A7", "A9"}, hornClauses[0].Neg.GetAtoms())
|
||||||
|
assert.Equal("((A3 && A2 && A7 && A9) -> 0)", horn.ToFormula().GetExpr())
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("!A3 && A2 && !A7 && A9 && A7")
|
||||||
|
assert.True(fml.IsHornFml())
|
||||||
|
horn = fml.GetHornParts()
|
||||||
|
hornClauses = horn
|
||||||
|
assert.Equal(5, len(hornClauses))
|
||||||
|
assert.Equal("((A3 -> 0) && (1 -> A2) && (A7 -> 0) && (1 -> A9) && (1 -> A7))", horn.ToFormula().GetExpr())
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("(A0 || ! A1 || ! A7) && (A4 || ! A5) && (! A1 || ! A8)")
|
||||||
|
assert.True(fml.IsHornFml())
|
||||||
|
horn = fml.GetHornParts()
|
||||||
|
hornClauses = horn
|
||||||
|
assert.Equal(3, len(hornClauses))
|
||||||
|
assert.Equal("(((A1 && A7) -> A0) && (A5 -> A4) && ((A1 && A8) -> 0))", horn.ToFormula().GetExpr())
|
||||||
|
}
|
||||||
35
codego/aussagenlogik/recursion/recursion_atoms.go
Normal file
35
codego/aussagenlogik/recursion/recursion_atoms.go
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package recursion
|
||||||
|
|
||||||
|
import (
|
||||||
|
"logik/aussagenlogik/formulae"
|
||||||
|
)
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* METHOD: Atoms
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func Atoms(fml formulae.Formula) []string {
|
||||||
|
// Definiere Schema:
|
||||||
|
var schema = func(fml formulae.Formula, prevValues [][]string) []string {
|
||||||
|
// Herausforderung: schreibe diese Funktion!
|
||||||
|
return []string{}
|
||||||
|
}
|
||||||
|
// Erzeuge Funktion aus Schema und berechne Wert:
|
||||||
|
fn := formulae.CreateFromSchemeStringsValued(schema)
|
||||||
|
return fn(fml)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* METHOD: Subformulae
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func Subformulae(fml formulae.Formula) []string {
|
||||||
|
// Definiere Schema:
|
||||||
|
var schema = func(fml formulae.Formula, prevValues [][]string) []string {
|
||||||
|
// Herausforderung: schreibe diese Funktion!
|
||||||
|
return []string{}
|
||||||
|
}
|
||||||
|
// Erzeuge Funktion aus Schema und berechne Wert:
|
||||||
|
fn := formulae.CreateFromSchemeStringsValued(schema)
|
||||||
|
return fn(fml)
|
||||||
|
}
|
||||||
49
codego/aussagenlogik/recursion/recursion_count.go
Normal file
49
codego/aussagenlogik/recursion/recursion_count.go
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package recursion
|
||||||
|
|
||||||
|
import (
|
||||||
|
"logik/aussagenlogik/formulae"
|
||||||
|
)
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* METHOD: Formula Depth
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func FmlDepth(fml formulae.Formula) int {
|
||||||
|
// Definiere Schema:
|
||||||
|
var schema = func(fml formulae.Formula, prevValues []int) int {
|
||||||
|
// Herausforderung: schreibe diese Funktion!
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
// Erzeuge Funktion aus Schema und berechne Wert:
|
||||||
|
fn := formulae.CreateFromSchemeIntValued(schema)
|
||||||
|
return fn(fml)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* METHOD: Formula Length
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func FmlLength(fml formulae.Formula) int {
|
||||||
|
// Definiere Schema:
|
||||||
|
var schema = func(fml formulae.Formula, prevValues []int) int {
|
||||||
|
// Herausforderung: schreibe diese Funktion!
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
// Erzeuge Funktion aus Schema und berechne Wert:
|
||||||
|
fn := formulae.CreateFromSchemeIntValued(schema)
|
||||||
|
return fn(fml)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* METHOD: Number of Parentheses
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
func NrParentheses(fml formulae.Formula) int {
|
||||||
|
// Definiere Schema:
|
||||||
|
var schema = func(fml formulae.Formula, prevValues []int) int {
|
||||||
|
// Herausforderung: schreibe diese Funktion!
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
// Erzeuge Funktion aus Schema und berechne Wert:
|
||||||
|
fn := formulae.CreateFromSchemeIntValued(schema)
|
||||||
|
return fn(fml)
|
||||||
|
}
|
||||||
44
codego/aussagenlogik/recursion/recursion_eval.go
Normal file
44
codego/aussagenlogik/recursion/recursion_eval.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package recursion
|
||||||
|
|
||||||
|
import (
|
||||||
|
"logik/aussagenlogik/formulae"
|
||||||
|
"logik/core/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* METHOD: Evaluation of fomulae in models
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func Eval(fml formulae.Formula, I []string) int {
|
||||||
|
// Definiere (parameterisiertes) Schema:
|
||||||
|
var schema = func(_I []string) func(formulae.Formula, []int) int {
|
||||||
|
return func(fml formulae.Formula, prevValues []int) int {
|
||||||
|
if fml.IsAtom() || fml.IsGeneric() {
|
||||||
|
return utils.BoolToInt(utils.StrListContains(_I, fml.GetName()))
|
||||||
|
} else if fml.IsTautologySymbol() {
|
||||||
|
return 1
|
||||||
|
} else if fml.IsContradictionSymbol() {
|
||||||
|
return 0
|
||||||
|
} else if fml.IsNegation() {
|
||||||
|
return 1 - prevValues[0]
|
||||||
|
} else if fml.IsConjunction2() {
|
||||||
|
return utils.Min2(prevValues[0], prevValues[1])
|
||||||
|
} else if fml.IsConjunction() {
|
||||||
|
return utils.MinList(prevValues)
|
||||||
|
} else if fml.IsDisjunction2() {
|
||||||
|
return utils.Max2(prevValues[0], prevValues[1])
|
||||||
|
} else if fml.IsDisjunction() {
|
||||||
|
return utils.MaxList(prevValues)
|
||||||
|
} else if fml.IsImplication() {
|
||||||
|
return utils.BoolToInt(prevValues[0] <= prevValues[1])
|
||||||
|
} else if fml.IsDoubleImplication() {
|
||||||
|
return utils.BoolToInt(prevValues[0] == prevValues[1])
|
||||||
|
} else {
|
||||||
|
panic("Could not evaluate expression!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Erzeuge Funktion aus Schema und berechne Wert:
|
||||||
|
fn := formulae.CreateFromSchemeIntValued(schema(I))
|
||||||
|
return fn(fml)
|
||||||
|
}
|
||||||
88
codego/aussagenlogik/recursion/recursion_nnf.go
Normal file
88
codego/aussagenlogik/recursion/recursion_nnf.go
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
package recursion
|
||||||
|
|
||||||
|
import (
|
||||||
|
"logik/aussagenlogik/formulae"
|
||||||
|
)
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* METHOD: compute NNF
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
// NOTE: diese bedarf einer Art Doppeltrekursion
|
||||||
|
func NNF(fml formulae.Formula) formulae.Formula {
|
||||||
|
// Definiere Schema:
|
||||||
|
var schema = func(fml formulae.Formula, prevValues []formulae.FormulaPair) formulae.FormulaPair {
|
||||||
|
// separate out positive and negative parts:
|
||||||
|
var pairs = formulae.NewFormulaPairs(prevValues)
|
||||||
|
var prevPos = pairs.Pos()
|
||||||
|
var prevNeg = pairs.Neg()
|
||||||
|
// compute value from previous positive/negative parts:
|
||||||
|
if fml.IsPositiveLiteral() {
|
||||||
|
return formulae.FormulaPair{
|
||||||
|
Pos: fml.Deepcopy(),
|
||||||
|
Neg: formulae.Negation(fml),
|
||||||
|
}
|
||||||
|
} else if fml.IsNegativeLiteral() {
|
||||||
|
return formulae.FormulaPair{
|
||||||
|
Pos: fml.Deepcopy(),
|
||||||
|
Neg: prevPos[0],
|
||||||
|
}
|
||||||
|
} else if fml.IsTautologySymbol() {
|
||||||
|
return formulae.FormulaPair{
|
||||||
|
Pos: formulae.Tautology,
|
||||||
|
Neg: formulae.Contradiction,
|
||||||
|
}
|
||||||
|
} else if fml.IsContradictionSymbol() {
|
||||||
|
return formulae.FormulaPair{
|
||||||
|
Pos: formulae.Contradiction,
|
||||||
|
Neg: formulae.Tautology,
|
||||||
|
}
|
||||||
|
} else if fml.IsNegation() {
|
||||||
|
return formulae.FormulaPair{
|
||||||
|
Pos: prevNeg[0],
|
||||||
|
Neg: prevPos[0],
|
||||||
|
}
|
||||||
|
} else if fml.IsConjunction2() {
|
||||||
|
return formulae.FormulaPair{
|
||||||
|
Pos: formulae.Conjunction2(prevPos[0], prevPos[1]),
|
||||||
|
Neg: formulae.Disjunction2(prevNeg[0], prevNeg[1]),
|
||||||
|
}
|
||||||
|
} else if fml.IsConjunction() {
|
||||||
|
return formulae.FormulaPair{
|
||||||
|
Pos: formulae.Conjunction(prevPos),
|
||||||
|
Neg: formulae.Disjunction(prevNeg),
|
||||||
|
}
|
||||||
|
} else if fml.IsDisjunction2() {
|
||||||
|
return formulae.FormulaPair{
|
||||||
|
Pos: formulae.Disjunction2(prevPos[0], prevPos[1]),
|
||||||
|
Neg: formulae.Conjunction2(prevNeg[0], prevNeg[1]),
|
||||||
|
}
|
||||||
|
} else if fml.IsDisjunction() {
|
||||||
|
return formulae.FormulaPair{
|
||||||
|
Pos: formulae.Disjunction(prevPos),
|
||||||
|
Neg: formulae.Conjunction(prevNeg),
|
||||||
|
}
|
||||||
|
} else if fml.IsImplication() {
|
||||||
|
return formulae.FormulaPair{
|
||||||
|
Pos: formulae.Disjunction2(prevNeg[0], prevPos[1]),
|
||||||
|
Neg: formulae.Conjunction2(prevPos[0], prevNeg[1]),
|
||||||
|
}
|
||||||
|
} else if fml.IsDoubleImplication() {
|
||||||
|
return formulae.FormulaPair{
|
||||||
|
Pos: formulae.Conjunction2(
|
||||||
|
formulae.Disjunction2(prevNeg[0], prevPos[1]),
|
||||||
|
formulae.Disjunction2(prevNeg[1], prevPos[0]),
|
||||||
|
),
|
||||||
|
Neg: formulae.Disjunction2(
|
||||||
|
formulae.Conjunction2(prevPos[0], prevNeg[1]),
|
||||||
|
formulae.Conjunction2(prevPos[1], prevNeg[0]),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
panic("Could not evaluate expression!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Erzeuge Funktion aus Schema und berechne Wert:
|
||||||
|
fn := formulae.CreateFromSchemeFmlPairValued(schema)
|
||||||
|
return fn(fml).Pos
|
||||||
|
}
|
||||||
455
codego/aussagenlogik/recursion/recursion_test.go
Normal file
455
codego/aussagenlogik/recursion/recursion_test.go
Normal file
@@ -0,0 +1,455 @@
|
|||||||
|
package recursion_test
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* UNIT TESTING
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
import (
|
||||||
|
"logik/aussagenlogik/formulae"
|
||||||
|
"logik/aussagenlogik/recursion"
|
||||||
|
"logik/aussagenlogik/schema"
|
||||||
|
"logik/core/utils"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* TESTCASE eval(·, ·)
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func TestEvalLiteral(test *testing.T) {
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
var I []string
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("A0")
|
||||||
|
I = []string{"A0"}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(1, val)
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("A0")
|
||||||
|
I = []string{}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(0, val)
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("! A0")
|
||||||
|
I = []string{"A0"}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(0, val)
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("! A0")
|
||||||
|
I = []string{}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(1, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvalNegation(test *testing.T) {
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
var I []string
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("A4 || ! A4")
|
||||||
|
I = []string{}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(1, val)
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("A4 && ! A4")
|
||||||
|
I = []string{}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(0, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvalConjunction(test *testing.T) {
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
var I []string
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("A0 && A1")
|
||||||
|
I = []string{"A0"}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(0, val)
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("A0 && A1")
|
||||||
|
I = []string{"A0", "A1"}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(1, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvalDisjunction(test *testing.T) {
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
var I []string
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("A0 || A1")
|
||||||
|
I = []string{"A0"}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(1, val)
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("A0 || A1")
|
||||||
|
I = []string{"A7"}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(0, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvalImplication(test *testing.T) {
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
var I []string
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("A0 -> A1")
|
||||||
|
I = []string{"A0"}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(0, val)
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("A0 -> A1")
|
||||||
|
I = []string{"A0", "A1"}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(1, val)
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("A0 -> A1")
|
||||||
|
I = []string{"A7"}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(1, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvalIff(test *testing.T) {
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
var I []string
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("A0 <-> A1")
|
||||||
|
I = []string{"A0"}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(0, val)
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("A0 <-> A1")
|
||||||
|
I = []string{"A0", "A1"}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(1, val)
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("A0 <-> A1")
|
||||||
|
I = []string{"A7"}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(1, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvalComplex(test *testing.T) {
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
var I []string
|
||||||
|
fml = schema.ParseExpr("( ! A0 || (( A0 && A3 ) || A2 ))")
|
||||||
|
I = []string{"A0", "A2"}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(1, val)
|
||||||
|
|
||||||
|
I = []string{"A0", "A3"}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(1, val)
|
||||||
|
|
||||||
|
I = []string{"A0"}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(0, val)
|
||||||
|
|
||||||
|
I = []string{"A4", "A8"}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(1, val)
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("( ! A0 || (( A0 && A3 ) || ! A2 ))")
|
||||||
|
I = []string{"A0", "A2"}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(0, val)
|
||||||
|
|
||||||
|
I = []string{"A0", "A3"}
|
||||||
|
val = recursion.Eval(fml, I)
|
||||||
|
assert.Equal(1, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* TESTCASE Atoms(·)
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func TestAtomsNoduplicates(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var fml formulae.Formula
|
||||||
|
var val []string
|
||||||
|
fml = schema.ParseExpr("( A4 && ( A4 || A4 ))")
|
||||||
|
val = recursion.Atoms(fml)
|
||||||
|
var n int = len(utils.FilterStrings(&val, func(x string) bool { return x == "A4" }))
|
||||||
|
assert.Equal(1, n, "Atome dürfen nicht mehrfach vorkommen!")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAtomsNoNonAtoms(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var fml formulae.Formula
|
||||||
|
var val []string
|
||||||
|
fml = schema.ParseExpr("( {F} || A3 )")
|
||||||
|
val = recursion.Atoms(fml)
|
||||||
|
utils.SortStrings(&val)
|
||||||
|
assert.NotContains(val, "F", "Nichtatomare Formeln dürfen nicht vorkommen!")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAtomsCalc1(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var fml formulae.Formula
|
||||||
|
var val []string
|
||||||
|
fml = schema.ParseExpr("A0")
|
||||||
|
val = recursion.Atoms(fml)
|
||||||
|
assert.ElementsMatch([]string{"A0"}, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAtomsCalc2(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var fml formulae.Formula
|
||||||
|
var val []string
|
||||||
|
fml = schema.ParseExpr("((( ! A8 && A3 ) || A4 ) && A0 )")
|
||||||
|
val = recursion.Atoms(fml)
|
||||||
|
assert.ElementsMatch([]string{"A0", "A3", "A4", "A8"}, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* TESTCASE depth(·, ·)
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func TestDepthCalc1(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
fml = schema.ParseExpr("A0")
|
||||||
|
val = recursion.FmlDepth(fml)
|
||||||
|
assert.Equal(0, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDepthCalc2(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
fml = schema.ParseExpr("!! A8")
|
||||||
|
val = recursion.FmlDepth(fml)
|
||||||
|
assert.Equal(2, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDepthCalc3(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
fml = schema.ParseExpr("( ! A0 && A3 )")
|
||||||
|
val = recursion.FmlDepth(fml)
|
||||||
|
assert.Equal(2, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDepthCalc4(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
fml = schema.ParseExpr("((( ! A0 && A3 ) || A4 ) && A8 )")
|
||||||
|
val = recursion.FmlDepth(fml)
|
||||||
|
assert.Equal(4, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDepthCalc5(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
fml = schema.ParseExpr("! ((( ! A0 && A3 ) || A4 ) && A8 )")
|
||||||
|
val = recursion.FmlDepth(fml)
|
||||||
|
assert.Equal(5, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* TESTCASE length(·)
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func TestLengthCalc1(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
fml = schema.ParseExpr("A0")
|
||||||
|
val = recursion.FmlLength(fml)
|
||||||
|
assert.Equal(1, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLengthCalc2(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
fml = schema.ParseExpr("!! A8")
|
||||||
|
val = recursion.FmlLength(fml)
|
||||||
|
assert.Equal(3, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLengthCalc3(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
fml = schema.ParseExpr("( ! A0 && A3 )")
|
||||||
|
val = recursion.FmlLength(fml)
|
||||||
|
assert.Equal(4, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLengthCalc4(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
fml = schema.ParseExpr("((( ! A0 && A3 ) || A4 ) && A8 )")
|
||||||
|
val = recursion.FmlLength(fml)
|
||||||
|
assert.Equal(8, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLengthCalc5(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
fml = schema.ParseExpr("! ((( ! A0 && A3 ) || A4 ) && A8 )")
|
||||||
|
val = recursion.FmlLength(fml)
|
||||||
|
assert.Equal(9, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* TESTCASE #Parentheses(·)
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func TestParenthesesCalc1(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
fml = schema.ParseExpr("A0")
|
||||||
|
val = recursion.NrParentheses(fml)
|
||||||
|
assert.Equal(0, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParenthesesCalc2(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
fml = schema.ParseExpr("!! A8")
|
||||||
|
val = recursion.NrParentheses(fml)
|
||||||
|
assert.Equal(0, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParenthesesCalc3(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
fml = schema.ParseExpr("( ! A0 && A3 )")
|
||||||
|
val = recursion.NrParentheses(fml)
|
||||||
|
assert.Equal(2, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParenthesesCalc4(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
fml = schema.ParseExpr("((( ! A0 && A3 ) || A4 ) && A8 )")
|
||||||
|
val = recursion.NrParentheses(fml)
|
||||||
|
assert.Equal(6, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParenthesesCalc5(test *testing.T) {
|
||||||
|
test.Skip("Methode noch nicht implementiert")
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var val int
|
||||||
|
var fml formulae.Formula
|
||||||
|
fml = schema.ParseExpr("! ((( ! A0 && A3 ) || A4 ) && A8 )")
|
||||||
|
val = recursion.NrParentheses(fml)
|
||||||
|
assert.Equal(6, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* TESTCASE NNF
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func TestNNFatoms(test *testing.T) {
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var fml formulae.Formula
|
||||||
|
var nnf_expected formulae.Formula
|
||||||
|
|
||||||
|
nnf_expected = formulae.Atom("A7")
|
||||||
|
fml = schema.ParseExpr("A7")
|
||||||
|
assert.Equal(nnf_expected.GetExpr(), recursion.NNF(fml).GetExpr())
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("!! A7")
|
||||||
|
assert.Equal(nnf_expected.GetExpr(), recursion.NNF(fml).GetExpr())
|
||||||
|
|
||||||
|
nnf_expected = formulae.NegatedAtom("A7")
|
||||||
|
fml = schema.ParseExpr("! A7")
|
||||||
|
assert.Equal(nnf_expected.GetExpr(), recursion.NNF(fml).GetExpr())
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("!!! A7")
|
||||||
|
assert.Equal(nnf_expected.GetExpr(), recursion.NNF(fml).GetExpr())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNNFconj(test *testing.T) {
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var fml formulae.Formula
|
||||||
|
var nnf_expected formulae.Formula
|
||||||
|
|
||||||
|
nnf_expected = formulae.Disjunction2(formulae.NegatedAtom("A0"), formulae.NegatedAtom("A1"))
|
||||||
|
fml = schema.ParseExpr("! (A0 && A1)")
|
||||||
|
assert.Equal(nnf_expected.GetExpr(), recursion.NNF(fml).GetExpr())
|
||||||
|
|
||||||
|
nnf_expected = formulae.Disjunction2(formulae.Atom("A0"), formulae.Atom("A1"))
|
||||||
|
fml = schema.ParseExpr("! (! A0 && ! A1)")
|
||||||
|
assert.Equal(nnf_expected.GetExpr(), recursion.NNF(fml).GetExpr())
|
||||||
|
|
||||||
|
nnf_expected = formulae.Conjunction2(formulae.Atom("A0"), formulae.NegatedAtom("A1"))
|
||||||
|
fml = schema.ParseExpr("(A0 && ! A1)")
|
||||||
|
assert.Equal(nnf_expected.GetExpr(), recursion.NNF(fml).GetExpr())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNNFdisj(test *testing.T) {
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var fml formulae.Formula
|
||||||
|
var nnf_expected formulae.Formula
|
||||||
|
|
||||||
|
nnf_expected = formulae.Conjunction2(formulae.NegatedAtom("A0"), formulae.NegatedAtom("A1"))
|
||||||
|
fml = schema.ParseExpr("! (A0 || A1)")
|
||||||
|
assert.Equal(nnf_expected.GetExpr(), recursion.NNF(fml).GetExpr())
|
||||||
|
|
||||||
|
nnf_expected = formulae.Conjunction2(formulae.Atom("A0"), formulae.Atom("A1"))
|
||||||
|
fml = schema.ParseExpr("! (! A0 || ! A1)")
|
||||||
|
assert.Equal(nnf_expected.GetExpr(), recursion.NNF(fml).GetExpr())
|
||||||
|
|
||||||
|
nnf_expected = formulae.Disjunction2(formulae.Atom("A0"), formulae.NegatedAtom("A1"))
|
||||||
|
fml = schema.ParseExpr("(A0 || ! A1)")
|
||||||
|
assert.Equal(nnf_expected.GetExpr(), recursion.NNF(fml).GetExpr())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNNFcalcComplex(test *testing.T) {
|
||||||
|
var assert = assert.New(test)
|
||||||
|
var fml formulae.Formula
|
||||||
|
var nnf_expected formulae.Formula
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("! (! (!A0 || A1) || ! ! A8)")
|
||||||
|
nnf_expected = schema.ParseExpr("((!A0 || A1) && ! A8)")
|
||||||
|
assert.Equal(nnf_expected.GetExpr(), recursion.NNF(fml).GetExpr())
|
||||||
|
|
||||||
|
fml = schema.ParseExpr("! (! (!A0 || !(A1 && ! A7)) && ! A8)")
|
||||||
|
nnf_expected = schema.ParseExpr("((!A0 || (! A1 || A7)) || A8)")
|
||||||
|
assert.Equal(nnf_expected.GetExpr(), recursion.NNF(fml).GetExpr())
|
||||||
|
}
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
package rekursion
|
|
||||||
|
|
||||||
import (
|
|
||||||
"logik/aussagenlogik/syntaxbaum"
|
|
||||||
"logik/core/utils"
|
|
||||||
)
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *
|
|
||||||
* EXPORTS
|
|
||||||
* ---------------------------------------------------------------- */
|
|
||||||
|
|
||||||
type RekursiveChannelInt struct {
|
|
||||||
channel chan int
|
|
||||||
}
|
|
||||||
|
|
||||||
func RekursivEval(ch chan int, tree syntaxbaum.SyntaxBaum, I []string) {
|
|
||||||
// Werte für Teilformeln rekursiv berechnen
|
|
||||||
fn := func(_ch chan int, _tree syntaxbaum.SyntaxBaum) { RekursivEval(_ch, _tree, I) }
|
|
||||||
var values = RekursiveCallInt(fn, tree.GetChildren())
|
|
||||||
// Aus Werten für Teilformeln Wert für Formeln berechnen
|
|
||||||
if tree.IsAtom() || tree.IsGeneric() {
|
|
||||||
ch <- utils.BoolToInt(utils.StrListContains(I, tree.GetExpr()))
|
|
||||||
} else if tree.IsTautologySymbol() {
|
|
||||||
ch <- 1
|
|
||||||
} else if tree.IsContradictionSymbol() {
|
|
||||||
ch <- 0
|
|
||||||
} else if tree.IsNegation() {
|
|
||||||
ch <- 1 - values[0]
|
|
||||||
} else if tree.IsConjunction2() {
|
|
||||||
ch <- utils.Min2(values[0], values[1])
|
|
||||||
} else if tree.IsConjunction() {
|
|
||||||
ch <- utils.MinList(values)
|
|
||||||
} else if tree.IsDisjunction2() {
|
|
||||||
ch <- utils.Max2(values[0], values[1])
|
|
||||||
} else if tree.IsDisjunction() {
|
|
||||||
ch <- utils.MaxList(values)
|
|
||||||
} else if tree.IsImplication() {
|
|
||||||
ch <- utils.BoolToInt(values[0] <= values[1])
|
|
||||||
} else {
|
|
||||||
panic("Could not evaluate expression!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func RekursivAtoms(ch chan []string, tree syntaxbaum.SyntaxBaum) {
|
|
||||||
// // Werte für Teilformeln rekursiv berechnen
|
|
||||||
// var values = RekursiveCallStringList(RekursivAtoms, tree.GetChildren())
|
|
||||||
// Herausforderung: schreibe diese Funktion!
|
|
||||||
ch <- []string{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func RekursivDepth(ch chan int, tree syntaxbaum.SyntaxBaum) {
|
|
||||||
// // Werte für Teilformeln rekursiv berechnen
|
|
||||||
// var values = RekursiveCallInt(RekursivDepth, tree.GetChildren())
|
|
||||||
// Herausforderung: schreibe diese Funktion!
|
|
||||||
ch <- 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func RekursivLength(ch chan int, tree syntaxbaum.SyntaxBaum) {
|
|
||||||
// // Werte für Teilformeln rekursiv berechnen
|
|
||||||
// var values = RekursiveCallInt(RekursivLength, tree.GetChildren())
|
|
||||||
// Herausforderung: schreibe diese Funktion!
|
|
||||||
ch <- 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func RekursivParentheses(ch chan int, tree syntaxbaum.SyntaxBaum) {
|
|
||||||
// // Werte für Teilformeln rekursiv berechnen
|
|
||||||
// var values = RekursiveCallInt(RekursivParentheses, tree.GetChildren())
|
|
||||||
// Herausforderung: schreibe diese Funktion!
|
|
||||||
ch <- 0
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package rekursion
|
|
||||||
|
|
||||||
import (
|
|
||||||
"logik/aussagenlogik/syntaxbaum"
|
|
||||||
)
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *
|
|
||||||
* EXPORTS
|
|
||||||
* ---------------------------------------------------------------- */
|
|
||||||
|
|
||||||
func RekursiveCallInt(fn func(ch chan int, tree syntaxbaum.SyntaxBaum), children []syntaxbaum.SyntaxBaum) []int {
|
|
||||||
subChannel := make(chan int)
|
|
||||||
values := make([]int, len(children))
|
|
||||||
// start parallel computations on subformulae
|
|
||||||
for _, subtree := range children {
|
|
||||||
go fn(subChannel, subtree)
|
|
||||||
}
|
|
||||||
// successively read values
|
|
||||||
for i := 0; i < len(children); i++ {
|
|
||||||
values[i] = <-subChannel
|
|
||||||
}
|
|
||||||
return values
|
|
||||||
}
|
|
||||||
|
|
||||||
func RekursiveCallString(fn func(ch chan string, tree syntaxbaum.SyntaxBaum), children []syntaxbaum.SyntaxBaum) []string {
|
|
||||||
subChannel := make(chan string)
|
|
||||||
values := make([]string, len(children))
|
|
||||||
// start parallel computations
|
|
||||||
for _, subtree := range children {
|
|
||||||
go fn(subChannel, subtree)
|
|
||||||
}
|
|
||||||
// successively read values
|
|
||||||
for i := 0; i < len(children); i++ {
|
|
||||||
values[i] = <-subChannel
|
|
||||||
}
|
|
||||||
return values
|
|
||||||
}
|
|
||||||
|
|
||||||
func RekursiveCallStringList(fn func(ch chan []string, tree syntaxbaum.SyntaxBaum), children []syntaxbaum.SyntaxBaum) [][]string {
|
|
||||||
subChannel := make(chan []string)
|
|
||||||
values := make([][]string, len(children))
|
|
||||||
// start parallel computations
|
|
||||||
for _, subtree := range children {
|
|
||||||
go fn(subChannel, subtree)
|
|
||||||
}
|
|
||||||
// successively read values
|
|
||||||
for i := 0; i < len(children); i++ {
|
|
||||||
values[i] = <-subChannel
|
|
||||||
}
|
|
||||||
return values
|
|
||||||
}
|
|
||||||
@@ -1,295 +0,0 @@
|
|||||||
package rekursion_test
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *
|
|
||||||
* UNIT TESTING
|
|
||||||
* ---------------------------------------------------------------- */
|
|
||||||
|
|
||||||
import (
|
|
||||||
"logik/aussagenlogik/rekursion"
|
|
||||||
"logik/aussagenlogik/schema"
|
|
||||||
"logik/aussagenlogik/syntaxbaum"
|
|
||||||
"logik/core/utils"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *
|
|
||||||
* TESTCASE eval(·, ·)
|
|
||||||
* ---------------------------------------------------------------- */
|
|
||||||
|
|
||||||
func TestRekursivEvalLiteral(test *testing.T) {
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan int)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
var I []string
|
|
||||||
tree = schema.ParseExpr("A0")
|
|
||||||
I = []string{"A0"}
|
|
||||||
go rekursion.RekursivEval(ch, tree, I)
|
|
||||||
assert.Equal(1, <-ch)
|
|
||||||
tree = schema.ParseExpr("A0")
|
|
||||||
I = []string{}
|
|
||||||
go rekursion.RekursivEval(ch, tree, I)
|
|
||||||
assert.Equal(0, <-ch)
|
|
||||||
tree = schema.ParseExpr("! A0")
|
|
||||||
I = []string{"A0"}
|
|
||||||
go rekursion.RekursivEval(ch, tree, I)
|
|
||||||
assert.Equal(0, <-ch)
|
|
||||||
tree = schema.ParseExpr("! A0")
|
|
||||||
I = []string{}
|
|
||||||
go rekursion.RekursivEval(ch, tree, I)
|
|
||||||
assert.Equal(1, <-ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRekursivEvalComplex1(test *testing.T) {
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan int)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
var I []string
|
|
||||||
tree = schema.ParseExpr("( ! A0 || (( A0 && A3 ) || A2 ))")
|
|
||||||
I = []string{"A0", "A2"}
|
|
||||||
go rekursion.RekursivEval(ch, tree, I)
|
|
||||||
assert.Equal(1, <-ch)
|
|
||||||
I = []string{"A0", "A3"}
|
|
||||||
go rekursion.RekursivEval(ch, tree, I)
|
|
||||||
assert.Equal(1, <-ch)
|
|
||||||
I = []string{"A0"}
|
|
||||||
go rekursion.RekursivEval(ch, tree, I)
|
|
||||||
assert.Equal(0, <-ch)
|
|
||||||
I = []string{"A4", "A8"}
|
|
||||||
go rekursion.RekursivEval(ch, tree, I)
|
|
||||||
assert.Equal(1, <-ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRekursivEvalComplex2(test *testing.T) {
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan int)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
var I []string
|
|
||||||
tree = schema.ParseExpr("( ! A0 || (( A0 && A3 ) || ! A2 ))")
|
|
||||||
I = []string{"A0", "A2"}
|
|
||||||
go rekursion.RekursivEval(ch, tree, I)
|
|
||||||
assert.Equal(0, <-ch)
|
|
||||||
I = []string{"A0", "A3"}
|
|
||||||
go rekursion.RekursivEval(ch, tree, I)
|
|
||||||
assert.Equal(1, <-ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *
|
|
||||||
* TESTCASE Atoms(·)
|
|
||||||
* ---------------------------------------------------------------- */
|
|
||||||
|
|
||||||
func TestRekursivAtomsNoduplicates(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan []string)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
var val []string
|
|
||||||
tree = schema.ParseExpr("( A4 && ( A4 || A4 ))")
|
|
||||||
go rekursion.RekursivAtoms(ch, tree)
|
|
||||||
val = <-ch
|
|
||||||
var n int = len(utils.FilterStrings(&val, func(x string) bool { return x == "A4" }))
|
|
||||||
assert.Equal(1, n, "Atome dürfen nicht mehrfach vorkommen!")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRekursivAtomsNononatoms(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
test.Skip("Syntax for generic expressions in ANTLR4 g4 needs to be implemented.")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan []string)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
var val []string
|
|
||||||
tree = schema.ParseExpr("( {F} || A3 )")
|
|
||||||
go rekursion.RekursivAtoms(ch, tree)
|
|
||||||
val = <-ch
|
|
||||||
utils.SortStrings(&val)
|
|
||||||
assert.NotContains(val, "F", "Nichtatomare Formeln dürfen nicht vorkommen!")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRekursivAtomsCalc1(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan []string)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
var val []string
|
|
||||||
tree = schema.ParseExpr("A0")
|
|
||||||
go rekursion.RekursivAtoms(ch, tree)
|
|
||||||
val = <-ch
|
|
||||||
utils.SortStrings(&val)
|
|
||||||
assert.Equal([]string{"A0"}, val)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRekursivAtomsCalc2(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan []string)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
var val []string
|
|
||||||
tree = schema.ParseExpr("((( ! A8 && A3 ) || A4 ) && A0 )")
|
|
||||||
go rekursion.RekursivAtoms(ch, tree)
|
|
||||||
val = <-ch
|
|
||||||
utils.SortStrings(&val)
|
|
||||||
assert.Equal([]string{"A0", "A3", "A4", "A8"}, val)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *
|
|
||||||
* TESTCASE depth(·, ·)
|
|
||||||
* ---------------------------------------------------------------- */
|
|
||||||
|
|
||||||
func TestRekursivDepthCalc1(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan int)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
tree = schema.ParseExpr("A0")
|
|
||||||
go rekursion.RekursivDepth(ch, tree)
|
|
||||||
assert.Equal(0, <-ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRekursivDepthCalc2(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan int)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
tree = schema.ParseExpr("!! A8")
|
|
||||||
go rekursion.RekursivDepth(ch, tree)
|
|
||||||
assert.Equal(2, <-ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRekursivDepthCalc3(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan int)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
tree = schema.ParseExpr("( ! A0 && A3 )")
|
|
||||||
go rekursion.RekursivDepth(ch, tree)
|
|
||||||
assert.Equal(2, <-ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRekursivDepthCalc4(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan int)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
tree = schema.ParseExpr("((( ! A0 && A3 ) || A4 ) && A8 )")
|
|
||||||
go rekursion.RekursivDepth(ch, tree)
|
|
||||||
assert.Equal(4, <-ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRekursivDepthCalc5(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan int)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
tree = schema.ParseExpr("! ((( ! A0 && A3 ) || A4 ) && A8 )")
|
|
||||||
go rekursion.RekursivDepth(ch, tree)
|
|
||||||
assert.Equal(5, <-ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *
|
|
||||||
* TESTCASE length(·)
|
|
||||||
* ---------------------------------------------------------------- */
|
|
||||||
|
|
||||||
func TestRekursivLengthCalc1(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan int)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
tree = schema.ParseExpr("A0")
|
|
||||||
go rekursion.RekursivLength(ch, tree)
|
|
||||||
assert.Equal(1, <-ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRekursivLengthCalc2(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan int)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
tree = schema.ParseExpr("!! A8")
|
|
||||||
go rekursion.RekursivLength(ch, tree)
|
|
||||||
assert.Equal(3, <-ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRekursivLengthCalc3(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan int)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
tree = schema.ParseExpr("( ! A0 && A3 )")
|
|
||||||
go rekursion.RekursivLength(ch, tree)
|
|
||||||
assert.Equal(4, <-ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRekursivLengthCalc4(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan int)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
tree = schema.ParseExpr("((( ! A0 && A3 ) || A4 ) && A8 )")
|
|
||||||
go rekursion.RekursivLength(ch, tree)
|
|
||||||
assert.Equal(8, <-ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRekursivLengthCalc5(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan int)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
tree = schema.ParseExpr("! ((( ! A0 && A3 ) || A4 ) && A8 )")
|
|
||||||
go rekursion.RekursivLength(ch, tree)
|
|
||||||
assert.Equal(9, <-ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *
|
|
||||||
* TESTCASE #Parentheses(·)
|
|
||||||
* ---------------------------------------------------------------- */
|
|
||||||
|
|
||||||
func TestRekursivParenthesesCalc1(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan int)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
tree = schema.ParseExpr("A0")
|
|
||||||
go rekursion.RekursivParentheses(ch, tree)
|
|
||||||
assert.Equal(0, <-ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRekursivParenthesesCalc2(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan int)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
tree = schema.ParseExpr("!! A8")
|
|
||||||
go rekursion.RekursivParentheses(ch, tree)
|
|
||||||
assert.Equal(0, <-ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRekursivParenthesesCalc3(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan int)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
tree = schema.ParseExpr("( ! A0 && A3 )")
|
|
||||||
go rekursion.RekursivParentheses(ch, tree)
|
|
||||||
assert.Equal(2, <-ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRekursivParenthesesCalc4(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan int)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
tree = schema.ParseExpr("((( ! A0 && A3 ) || A4 ) && A8 )")
|
|
||||||
go rekursion.RekursivParentheses(ch, tree)
|
|
||||||
assert.Equal(6, <-ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRekursivParenthesesCalc5(test *testing.T) {
|
|
||||||
test.Skip("Methode noch nicht implementiert")
|
|
||||||
var assert = assert.New(test)
|
|
||||||
var ch = make(chan int)
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
tree = schema.ParseExpr("! ((( ! A0 && A3 ) || A4 ) && A8 )")
|
|
||||||
go rekursion.RekursivParentheses(ch, tree)
|
|
||||||
assert.Equal(6, <-ch)
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package schema
|
package schema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"logik/aussagenlogik/syntaxbaum"
|
"logik/aussagenlogik/formulae"
|
||||||
parser "logik/grammars/aussagenlogik"
|
parser "logik/grammars/aussagenlogik"
|
||||||
"strings"
|
"regexp"
|
||||||
|
|
||||||
"github.com/antlr/antlr4/runtime/Go/antlr"
|
"github.com/antlr/antlr4/runtime/Go/antlr"
|
||||||
)
|
)
|
||||||
@@ -12,12 +12,12 @@ import (
|
|||||||
* EXPORTS
|
* EXPORTS
|
||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
func ParseExpr(u string) syntaxbaum.SyntaxBaum {
|
func ParseExpr(u string) formulae.Formula {
|
||||||
var lexer = createLexer(u)
|
var lexer = createLexer(u)
|
||||||
var tokenStream = lexerToTokenStream(lexer)
|
var tokenStream = lexerToTokenStream(lexer)
|
||||||
var prs = parser.NewaussagenlogikParser(tokenStream)
|
var prs = parser.NewaussagenlogikParser(tokenStream)
|
||||||
var t = prs.Start()
|
var t = prs.Start()
|
||||||
tree := createSyntaxBaum(t, prs)
|
tree := createFormula(t, prs)
|
||||||
return tree
|
return tree
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,9 +38,9 @@ func createLexer(u string) antlr.Lexer {
|
|||||||
return parser.NewaussagenlogikLexer(stream)
|
return parser.NewaussagenlogikLexer(stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSyntaxBaum(tree antlr.Tree, parser antlr.Parser) syntaxbaum.SyntaxBaum {
|
func createFormula(tree antlr.Tree, parser antlr.Parser) formulae.Formula {
|
||||||
var ant = antlrTree{tree: tree, parser: &parser}
|
var ant = antlrTree{tree: tree, parser: &parser}
|
||||||
return ant.toSyntaxBaum()
|
return ant.toFormula()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *
|
/* ---------------------------------------------------------------- *
|
||||||
@@ -66,28 +66,18 @@ func (ant antlrTree) getLabel() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ant antlrTree) getTextContent() string {
|
func (ant antlrTree) getTextContent() string {
|
||||||
var expr string = ant.getLabel()
|
var expr string = ""
|
||||||
for _, subant := range ant.getChildren() {
|
var subants = ant.getChildren()
|
||||||
|
if len(subants) == 0 {
|
||||||
|
return ant.getLabel()
|
||||||
|
}
|
||||||
|
for _, subant := range subants {
|
||||||
expr += subant.getTextContent()
|
expr += subant.getTextContent()
|
||||||
}
|
}
|
||||||
return expr
|
return expr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ant antlrTree) getTextContentLeaves() string {
|
func (ant antlrTree) toFormula() formulae.Formula {
|
||||||
var expr string = ""
|
|
||||||
var subants = ant.getChildren()
|
|
||||||
if len(subants) == 0 {
|
|
||||||
expr = ant.getLabel()
|
|
||||||
} else {
|
|
||||||
for _, subant := range subants {
|
|
||||||
expr += subant.getTextContent()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return expr
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ant antlrTree) toSyntaxBaum() syntaxbaum.SyntaxBaum {
|
|
||||||
var tree syntaxbaum.SyntaxBaum
|
|
||||||
var label string = ant.getLabel()
|
var label string = ant.getLabel()
|
||||||
var subants = ant.getChildren()
|
var subants = ant.getChildren()
|
||||||
var nChildren = len(subants)
|
var nChildren = len(subants)
|
||||||
@@ -95,65 +85,81 @@ func (ant antlrTree) toSyntaxBaum() syntaxbaum.SyntaxBaum {
|
|||||||
switch label {
|
switch label {
|
||||||
case "start":
|
case "start":
|
||||||
if nChildren == 1 {
|
if nChildren == 1 {
|
||||||
return subants[0].toSyntaxBaum()
|
return subants[0].toFormula()
|
||||||
}
|
}
|
||||||
case "open":
|
case "open":
|
||||||
if nChildren == 1 {
|
if nChildren == 1 {
|
||||||
return subants[0].toSyntaxBaum()
|
return subants[0].toFormula()
|
||||||
}
|
}
|
||||||
case "closed":
|
case "closed":
|
||||||
switch nChildren {
|
switch nChildren {
|
||||||
case 1:
|
case 1:
|
||||||
return subants[0].toSyntaxBaum()
|
return subants[0].toFormula()
|
||||||
|
// expr = ( expr )
|
||||||
case 3:
|
case 3:
|
||||||
return subants[1].toSyntaxBaum()
|
return subants[1].toFormula()
|
||||||
}
|
}
|
||||||
case "atomic":
|
case "atomic":
|
||||||
if nChildren == 1 {
|
if nChildren == 1 {
|
||||||
subant := subants[0]
|
return subants[0].toFormula()
|
||||||
tree = syntaxbaum.SyntaxBaum{}
|
|
||||||
tree.SetKind(subant.getLabel())
|
|
||||||
tree.SetExpr(subant.getTextContentLeaves())
|
|
||||||
tree.SetChildren([](*syntaxbaum.SyntaxBaum){})
|
|
||||||
return tree
|
|
||||||
}
|
}
|
||||||
|
case "taut":
|
||||||
|
return formulae.Tautology
|
||||||
|
case "contradiction":
|
||||||
|
return formulae.Contradiction
|
||||||
|
case "atom":
|
||||||
|
name := ant.getTextContent()
|
||||||
|
return formulae.Atom(name)
|
||||||
|
case "generic":
|
||||||
|
re := regexp.MustCompile(`^{|}$`)
|
||||||
|
name := string(re.ReplaceAll([]byte(ant.getTextContent()), []byte("")))
|
||||||
|
return formulae.Generic(name)
|
||||||
case "not":
|
case "not":
|
||||||
|
// NOTE: expr = ! expr
|
||||||
if nChildren == 2 {
|
if nChildren == 2 {
|
||||||
// NOTE: Children = [NotSymbol, Teilformel]
|
return formulae.Negation(subants[1].toFormula())
|
||||||
subtree := subants[1].toSyntaxBaum()
|
|
||||||
tree = syntaxbaum.SyntaxBaum{}
|
|
||||||
tree.SetKind(label)
|
|
||||||
tree.SetExpr(subants[0].getTextContent() + " " + subtree.GetExpr())
|
|
||||||
tree.SetChildren([](*syntaxbaum.SyntaxBaum){&subtree})
|
|
||||||
return tree
|
|
||||||
}
|
}
|
||||||
case "and2", "and", "or2", "or", "implies":
|
case "and2":
|
||||||
|
// NOTE: expr = expr && expr
|
||||||
|
if nChildren == 3 {
|
||||||
|
return formulae.Conjunction2(subants[0].toFormula(), subants[2].toFormula())
|
||||||
|
}
|
||||||
|
case "or2":
|
||||||
|
// NOTE: expr = expr || expr
|
||||||
|
if nChildren == 3 {
|
||||||
|
return formulae.Disjunction2(subants[0].toFormula(), subants[2].toFormula())
|
||||||
|
}
|
||||||
|
case "implies":
|
||||||
|
// NOTE: expr = expr -> expr
|
||||||
|
if nChildren == 3 {
|
||||||
|
return formulae.Implies(subants[0].toFormula(), subants[2].toFormula())
|
||||||
|
}
|
||||||
|
case "iff":
|
||||||
|
// NOTE: expr = expr <=> expr
|
||||||
|
if nChildren == 3 {
|
||||||
|
return formulae.DoubleImplication(subants[0].toFormula(), subants[2].toFormula())
|
||||||
|
}
|
||||||
|
case "and", "or":
|
||||||
|
// NOTE: expr = expr op expr op ... op expr
|
||||||
var n int = int((len(subants) + 1) / 2)
|
var n int = int((len(subants) + 1) / 2)
|
||||||
if nChildren == 2*n-1 && n >= 2 {
|
if nChildren == 2*n-1 && n >= 2 {
|
||||||
var isSymb bool = false
|
var subtrees = make([]formulae.Formula, n)
|
||||||
var subtrees = make([](*syntaxbaum.SyntaxBaum), n)
|
var isSymb bool = true
|
||||||
var i int = 0
|
var i int = 0
|
||||||
var expr string = ""
|
|
||||||
for _, subant := range subants {
|
for _, subant := range subants {
|
||||||
if isSymb {
|
if isSymb {
|
||||||
expr += " " + subant.getTextContent()
|
subtrees[i] = subant.toFormula()
|
||||||
} else {
|
|
||||||
subtree := subant.toSyntaxBaum()
|
|
||||||
subtrees[i] = &subtree
|
|
||||||
expr += " " + subtree.GetExpr()
|
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
// NOTE: infix notation: alternatives between expression and symbol
|
// NOTE: infix notation: alternatives between expression and symbol
|
||||||
isSymb = !isSymb
|
isSymb = !isSymb
|
||||||
}
|
}
|
||||||
expr = strings.Trim(expr, " ")
|
switch label {
|
||||||
var lbrace string = "("
|
case "and":
|
||||||
var rbrace string = ")"
|
return formulae.Conjunction(subtrees)
|
||||||
tree = syntaxbaum.SyntaxBaum{}
|
case "or":
|
||||||
tree.SetKind(label)
|
return formulae.Disjunction(subtrees)
|
||||||
tree.SetExpr(lbrace + expr + rbrace)
|
}
|
||||||
tree.SetChildren(subtrees)
|
|
||||||
return tree
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ package schema_test
|
|||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"logik/aussagenlogik/formulae"
|
||||||
"logik/aussagenlogik/schema"
|
"logik/aussagenlogik/schema"
|
||||||
"logik/aussagenlogik/syntaxbaum"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@@ -18,25 +18,30 @@ import (
|
|||||||
|
|
||||||
func TestParseExpr(test *testing.T) {
|
func TestParseExpr(test *testing.T) {
|
||||||
var assert = assert.New(test)
|
var assert = assert.New(test)
|
||||||
var tree syntaxbaum.SyntaxBaum
|
var tree formulae.Formula
|
||||||
|
|
||||||
tree = schema.ParseExpr("A8712")
|
tree = schema.ParseExpr("A8712")
|
||||||
assert.Equal("A8712", tree.GetExpr())
|
assert.Equal("A8712", tree.GetExpr())
|
||||||
assert.Equal("atom", tree.GetKind())
|
assert.Equal("atom", tree.GetKind())
|
||||||
assert.Equal(0, len(tree.GetChildren()))
|
assert.Equal(0, len(tree.GetSubFormulae()))
|
||||||
|
|
||||||
|
tree = schema.ParseExpr("A12")
|
||||||
|
assert.Equal("A12", tree.GetExpr())
|
||||||
|
assert.Equal("atom", tree.GetKind())
|
||||||
|
assert.Equal(0, len(tree.GetSubFormulae()))
|
||||||
|
|
||||||
tree = schema.ParseExpr(" ! A5 ")
|
tree = schema.ParseExpr(" ! A5 ")
|
||||||
assert.Equal("! A5", tree.GetExpr())
|
assert.Equal("!A5", tree.GetExpr())
|
||||||
assert.Equal("not", tree.GetKind())
|
assert.Equal("not", tree.GetKind())
|
||||||
assert.Equal(1, len(tree.GetChildren()))
|
assert.Equal(1, len(tree.GetSubFormulae()))
|
||||||
|
|
||||||
tree = schema.ParseExpr("A0 -> A1")
|
tree = schema.ParseExpr("A0 -> A1")
|
||||||
assert.Equal("(A0 -> A1)", tree.GetExpr())
|
assert.Equal("(A0 -> A1)", tree.GetExpr())
|
||||||
assert.Equal("implies", tree.GetKind())
|
assert.Equal("implies", tree.GetKind())
|
||||||
assert.Equal(2, len(tree.GetChildren()))
|
assert.Equal(2, len(tree.GetSubFormulae()))
|
||||||
|
|
||||||
tree = schema.ParseExpr("( A0 && A1) || A2")
|
tree = schema.ParseExpr("( A0 && ! ! A1) || A2")
|
||||||
assert.Equal("((A0 && A1) || A2)", tree.GetExpr())
|
assert.Equal("((A0 && !!A1) || A2)", tree.GetExpr())
|
||||||
assert.Equal("or2", tree.GetKind())
|
assert.Equal("or2", tree.GetKind())
|
||||||
assert.Equal(2, len(tree.GetChildren()))
|
assert.Equal(2, len(tree.GetSubFormulae()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,154 +0,0 @@
|
|||||||
package syntaxbaum
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type SyntaxBaum struct {
|
|
||||||
kind string
|
|
||||||
expr string
|
|
||||||
valence int
|
|
||||||
children [](*SyntaxBaum)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *
|
|
||||||
* METHODS
|
|
||||||
* ---------------------------------------------------------------- */
|
|
||||||
func (tree *SyntaxBaum) SetKind(kind string) {
|
|
||||||
tree.kind = kind
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) GetKind() string {
|
|
||||||
return tree.kind
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree *SyntaxBaum) SetExpr(expr string) {
|
|
||||||
tree.expr = expr
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) GetExpr() string {
|
|
||||||
return tree.expr
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree *SyntaxBaum) SetChildren(children [](*SyntaxBaum)) {
|
|
||||||
tree.children = children
|
|
||||||
tree.valence = len(children)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) GetChildren() []SyntaxBaum {
|
|
||||||
var n int = tree.valence
|
|
||||||
var children = make([]SyntaxBaum, n)
|
|
||||||
for i, subtreePtr := range tree.children {
|
|
||||||
children[i] = *subtreePtr
|
|
||||||
}
|
|
||||||
return children
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) GetChild(indexOpt ...int) (SyntaxBaum, error) {
|
|
||||||
var index int = 0
|
|
||||||
if len(indexOpt) > 0 {
|
|
||||||
index = indexOpt[0]
|
|
||||||
}
|
|
||||||
var subtree SyntaxBaum
|
|
||||||
var err error
|
|
||||||
if 0 <= index && index < tree.valence {
|
|
||||||
subtree = *(tree.children[index])
|
|
||||||
} else {
|
|
||||||
err = errors.New(fmt.Sprintf("Instance has no child of index %d !", index))
|
|
||||||
}
|
|
||||||
return subtree, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) Pretty(preindentOpt ...string) string {
|
|
||||||
var preindent string = ""
|
|
||||||
if len(preindentOpt) > 0 {
|
|
||||||
preindent = preindentOpt[0]
|
|
||||||
}
|
|
||||||
return tree.pretty(preindent, " ", "", 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) pretty(preindent string, tab string, prepend string, depth int) string {
|
|
||||||
var indent string = preindent + strings.Repeat(tab, depth)
|
|
||||||
switch tree.valence {
|
|
||||||
case 0:
|
|
||||||
switch kind := tree.kind; kind {
|
|
||||||
case "atom", "generic":
|
|
||||||
return indent + prepend + kind + " " + tree.expr
|
|
||||||
default:
|
|
||||||
return indent + prepend + kind
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
var lines string = indent + prepend + tree.kind
|
|
||||||
prepend = "|__ "
|
|
||||||
for _, subtree := range tree.children {
|
|
||||||
lines += "\n" + subtree.pretty(preindent, tab, prepend, depth+1)
|
|
||||||
}
|
|
||||||
return lines
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
// METHODS: Recognitong of Formula-Types
|
|
||||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) IsIrreducible() bool {
|
|
||||||
return tree.valence == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) IsAtom() bool {
|
|
||||||
return tree.kind == "atom"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) IsLiteral() bool {
|
|
||||||
if tree.IsAtom() {
|
|
||||||
return true
|
|
||||||
} else if tree.IsNegation() {
|
|
||||||
subtree, err := tree.GetChild()
|
|
||||||
if err == nil {
|
|
||||||
return subtree.IsAtom()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) IsGeneric() bool {
|
|
||||||
return tree.kind == "generic"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) IsTautologySymbol() bool {
|
|
||||||
return tree.kind == "taut"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) IsContradictionSymbol() bool {
|
|
||||||
return tree.kind == "contradiction"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) IsConnective() bool {
|
|
||||||
return tree.valence > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) IsNegation() bool {
|
|
||||||
return tree.kind == "not"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) IsConjunction2() bool {
|
|
||||||
return tree.kind == "and2"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) IsConjunction() bool {
|
|
||||||
return tree.kind == "and" || tree.kind == "and2"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) IsDisjunction2() bool {
|
|
||||||
return tree.kind == "or2"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) IsDisjunction() bool {
|
|
||||||
return tree.kind == "or" || tree.kind == "or2"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tree SyntaxBaum) IsImplication() bool {
|
|
||||||
return tree.kind == "implies"
|
|
||||||
}
|
|
||||||
@@ -85,6 +85,14 @@ func SumList(x []int) int {
|
|||||||
* METHODS: for string lists
|
* METHODS: for string lists
|
||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func CopyStringList(list []string) []string {
|
||||||
|
var listCopy = make([]string, len(list))
|
||||||
|
for i, value := range list {
|
||||||
|
listCopy[i] = value
|
||||||
|
}
|
||||||
|
return listCopy
|
||||||
|
}
|
||||||
|
|
||||||
func StrListContains(list []string, x string) bool {
|
func StrListContains(list []string, x string) bool {
|
||||||
for _, obj := range list {
|
for _, obj := range list {
|
||||||
if obj == x {
|
if obj == x {
|
||||||
@@ -131,7 +139,7 @@ func UnionStrings2(list1 []string, list2 []string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// assumes that listTo contains no duplicates
|
// assumes that listTo contains no duplicates
|
||||||
func UnionStringsTo(listTo *[]string, listFrom []string) {
|
func UnionStringsInPlace(listTo *[]string, listFrom []string) {
|
||||||
var mark = make(map[string]bool)
|
var mark = make(map[string]bool)
|
||||||
for _, item := range listFrom {
|
for _, item := range listFrom {
|
||||||
mark[item] = true
|
mark[item] = true
|
||||||
@@ -149,7 +157,19 @@ func UnionStringsTo(listTo *[]string, listFrom []string) {
|
|||||||
func UnionStringsList(lists [][]string) []string {
|
func UnionStringsList(lists [][]string) []string {
|
||||||
var list = []string{}
|
var list = []string{}
|
||||||
for _, list_ := range lists {
|
for _, list_ := range lists {
|
||||||
UnionStringsTo(&list, list_)
|
UnionStringsInPlace(&list, list_)
|
||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* METHODS: for maps
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func CopyMapStringBool(m map[string]bool) map[string]bool {
|
||||||
|
var mCopy = map[string]bool{}
|
||||||
|
for key, value := range m {
|
||||||
|
mCopy[key] = value
|
||||||
|
}
|
||||||
|
return mCopy
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ func TestJsonToArrayOfStrings(test *testing.T) {
|
|||||||
var assert = assert.New(test)
|
var assert = assert.New(test)
|
||||||
var result []string
|
var result []string
|
||||||
utils.JsonToArrayOfStrings("[]", &result)
|
utils.JsonToArrayOfStrings("[]", &result)
|
||||||
assert.Equal([]string{}, result)
|
assert.ElementsMatch([]string{}, result)
|
||||||
utils.JsonToArrayOfStrings("[ \"ganymed\" ]", &result)
|
utils.JsonToArrayOfStrings("[ \"ganymed\" ]", &result)
|
||||||
assert.Equal([]string{"ganymed"}, result)
|
assert.ElementsMatch([]string{"ganymed"}, result)
|
||||||
utils.JsonToArrayOfStrings("[ \"ganymed\", \"io\" ]", &result)
|
utils.JsonToArrayOfStrings("[ \"ganymed\", \"io\" ]", &result)
|
||||||
assert.Equal([]string{"ganymed", "io"}, result)
|
assert.ElementsMatch([]string{"ganymed", "io"}, result)
|
||||||
assert.Panics(func() { utils.JsonToArrayOfStrings("[ 178 ]", &result) }, "Should panic if converting not a JSON-encoded array of strings!")
|
assert.Panics(func() { utils.JsonToArrayOfStrings("[ 178 ]", &result) }, "Should panic if converting not a JSON-encoded array of strings!")
|
||||||
assert.Panics(func() { utils.JsonToArrayOfStrings("true", &result) }, "Should panic if converting not a JSON-encoded array of strings!")
|
assert.Panics(func() { utils.JsonToArrayOfStrings("true", &result) }, "Should panic if converting not a JSON-encoded array of strings!")
|
||||||
assert.Panics(func() { utils.JsonToArrayOfStrings("", &result) }, "Should panic if converting not a JSON-encoded array of strings!")
|
assert.Panics(func() { utils.JsonToArrayOfStrings("", &result) }, "Should panic if converting not a JSON-encoded array of strings!")
|
||||||
@@ -73,6 +73,7 @@ func TestSumList(test *testing.T) {
|
|||||||
func TestSortStrings(test *testing.T) {
|
func TestSortStrings(test *testing.T) {
|
||||||
var assert = assert.New(test)
|
var assert = assert.New(test)
|
||||||
var list = []string{"katze", "Hund", "baby", "Pluto", "Saturn", "Mond"}
|
var list = []string{"katze", "Hund", "baby", "Pluto", "Saturn", "Mond"}
|
||||||
|
// NOTE: here use .Equal and not .ElementsMatch, since order important.
|
||||||
utils.SortStrings(&list)
|
utils.SortStrings(&list)
|
||||||
assert.Equal([]string{"baby", "Hund", "katze", "Mond", "Pluto", "Saturn"}, list)
|
assert.Equal([]string{"baby", "Hund", "katze", "Mond", "Pluto", "Saturn"}, list)
|
||||||
}
|
}
|
||||||
@@ -85,11 +86,11 @@ func TestFilterStrings(test *testing.T) {
|
|||||||
var assert = assert.New(test)
|
var assert = assert.New(test)
|
||||||
var list = []string{"abram", "aaron", "aardvark", "aarhus", "alaska", "eel", "aal"}
|
var list = []string{"abram", "aaron", "aardvark", "aarhus", "alaska", "eel", "aal"}
|
||||||
var list2 = utils.FilterStrings(&list, func(x string) bool { return strings.HasPrefix(x, "aa") })
|
var list2 = utils.FilterStrings(&list, func(x string) bool { return strings.HasPrefix(x, "aa") })
|
||||||
assert.Equal([]string{"aaron", "aardvark", "aarhus", "aal"}, list2)
|
assert.ElementsMatch([]string{"aaron", "aardvark", "aarhus", "aal"}, list2)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *
|
/* ---------------------------------------------------------------- *
|
||||||
* TESTCASE UnionStrings2, UnionStringsTo, UnionStringsList
|
* TESTCASE UnionStrings2, UnionStringsInPlace, UnionStringsList
|
||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
func TestUnionStrings2(test *testing.T) {
|
func TestUnionStrings2(test *testing.T) {
|
||||||
@@ -97,17 +98,15 @@ func TestUnionStrings2(test *testing.T) {
|
|||||||
var list1 = []string{"red", "blue", "blue", "green", "blue", "grey", "black", "green"}
|
var list1 = []string{"red", "blue", "blue", "green", "blue", "grey", "black", "green"}
|
||||||
var list2 = []string{"yellow", "orange", "lila", "red"}
|
var list2 = []string{"yellow", "orange", "lila", "red"}
|
||||||
var list = utils.UnionStrings2(list1, list2)
|
var list = utils.UnionStrings2(list1, list2)
|
||||||
utils.SortStrings(&list)
|
assert.ElementsMatch([]string{"black", "blue", "green", "grey", "lila", "orange", "red", "yellow"}, list)
|
||||||
assert.Equal([]string{"black", "blue", "green", "grey", "lila", "orange", "red", "yellow"}, list)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnionStringsTo(test *testing.T) {
|
func TestUnionStringsInPlace(test *testing.T) {
|
||||||
var assert = assert.New(test)
|
var assert = assert.New(test)
|
||||||
var list1 = []string{"red", "blue", "green"}
|
var list1 = []string{"red", "blue", "green"}
|
||||||
var list2 = []string{"yellow", "red", "blue", "red", "black"}
|
var list2 = []string{"yellow", "red", "blue", "red", "black"}
|
||||||
utils.UnionStringsTo(&list1, list2)
|
utils.UnionStringsInPlace(&list1, list2)
|
||||||
utils.SortStrings(&list1)
|
assert.ElementsMatch([]string{"black", "blue", "green", "red", "yellow"}, list1)
|
||||||
assert.Equal([]string{"black", "blue", "green", "red", "yellow"}, list1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnionStringsList(test *testing.T) {
|
func TestUnionStringsList(test *testing.T) {
|
||||||
@@ -116,6 +115,5 @@ func TestUnionStringsList(test *testing.T) {
|
|||||||
var lists [][]string
|
var lists [][]string
|
||||||
lists = [][]string{{"red", "blue", "blue", "green"}, {"yellow", "red", "black"}}
|
lists = [][]string{{"red", "blue", "blue", "green"}, {"yellow", "red", "black"}}
|
||||||
list = utils.UnionStringsList(lists)
|
list = utils.UnionStringsList(lists)
|
||||||
utils.SortStrings(&list)
|
assert.ElementsMatch([]string{"black", "blue", "green", "red", "yellow"}, list)
|
||||||
assert.Equal([]string{"black", "blue", "green", "red", "yellow"}, list)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +1,37 @@
|
|||||||
grammar aussagenlogik;
|
grammar aussagenlogik;
|
||||||
|
|
||||||
// Standardtokens:
|
// Standardtokens:
|
||||||
NUMBER: [0-9]+;
|
NUMBER: [0-9];
|
||||||
|
ZERO: ~[a-zA-Z0-9][0]; // negatives Look-Behind nötig, um konfliktierendes Lexing zu vermeiden
|
||||||
|
ONE: ~[a-zA-Z0-9][1]; // ""
|
||||||
WHITESPACE: [ \r\n\t]+ -> skip;
|
WHITESPACE: [ \r\n\t]+ -> skip;
|
||||||
LBRACE: '(';
|
LBRACE: '(';
|
||||||
RBRACE: ')';
|
RBRACE: ')';
|
||||||
LCURLYBRACE: '{';
|
LCURLYBRACE: '{';
|
||||||
RCURLYBRACE: '}';
|
RCURLYBRACE: '}';
|
||||||
|
TEXT: [a-zA-Z0-9\\_];
|
||||||
|
|
||||||
// Symbole (erlaube mehrere Varianten)
|
// Symbole (erlaube mehrere Varianten)
|
||||||
SYMB_NOT: ('!'|'~'|'not');
|
SYMB_NOT: ('!'|'~'|'not');
|
||||||
SYMB_AND: ('&'+|'^'|'and');
|
SYMB_AND: ('&'+|'^'|'and');
|
||||||
SYMB_OR: ('|'+|'v'|'or');
|
SYMB_OR: ('|'+|'v'|'or');
|
||||||
SYMB_IMPL: ('->'|'=>');
|
SYMB_IFF: ([<][-]+[>]|[<][=]+[>]|'iff');
|
||||||
|
SYMB_IMPL: (~[<][-]+[>]|~[<][=]+[>]);
|
||||||
|
|
||||||
// Rules
|
// Rules
|
||||||
start: open <EOF> | closed <EOF>;
|
start: open <EOF> | closed <EOF>;
|
||||||
|
|
||||||
closed: atomic | not | LBRACE open RBRACE;
|
closed: atomic | not | LBRACE open RBRACE;
|
||||||
open: and2 | and | or2 | or | implies;
|
open: and2 | and | or2 | or | implies | iff;
|
||||||
|
|
||||||
// Schemata für atomische Ausdrücke
|
// Schemata für atomische Ausdrücke
|
||||||
atomic: taut | contradiction | atom; //| generic;
|
atomic: taut | contradiction | atom | generic;
|
||||||
taut: ('1'|'true');
|
taut: (ONE|'true');
|
||||||
contradiction: ('0'|'false');
|
contradiction: (ZERO|'false');
|
||||||
atom: 'A0' | 'A1' | 'A' NUMBER; // muss A0, A1 wegen falsum/verum extra auflisten
|
atom: 'A' NUMBER+;
|
||||||
// // als 'generische' Formeln schreibe bspw. {F}, {G}, {F1}, usw.
|
// als 'generische' Formeln schreibe bspw. {F}, {G}, usw.
|
||||||
// // generic: LCURLYBRACE (.*?) RCURLYBRACE;
|
generic: LCURLYBRACE TEXT+ RCURLYBRACE | LCURLYBRACE TEXT* ( generic TEXT* )+ RCURLYBRACE;
|
||||||
// FIXME: dieses Schema führt zu Konflikten
|
// FIXME: liest Zahlen schlecht ein
|
||||||
|
|
||||||
// Schema für Negation: ¬ F
|
// Schema für Negation: ¬ F
|
||||||
not: symb=SYMB_NOT closed;
|
not: symb=SYMB_NOT closed;
|
||||||
@@ -39,3 +43,5 @@ or2: closed symb=SYMB_OR closed;
|
|||||||
or: ( closed ( symb=SYMB_OR closed )+ );
|
or: ( closed ( symb=SYMB_OR closed )+ );
|
||||||
// Schema für Implikation: F1 ⟶ F2
|
// Schema für Implikation: F1 ⟶ F2
|
||||||
implies: closed symb=SYMB_IMPL closed;
|
implies: closed symb=SYMB_IMPL closed;
|
||||||
|
// Schema für Implikation: F1 ⟷ F2
|
||||||
|
iff: closed symb=SYMB_IFF closed;
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"logik/aussagenlogik/rekursion"
|
"logik/aussagenlogik/formulae"
|
||||||
|
"logik/aussagenlogik/recursion"
|
||||||
"logik/aussagenlogik/schema"
|
"logik/aussagenlogik/schema"
|
||||||
"logik/aussagenlogik/syntaxbaum"
|
|
||||||
env "logik/core/environment"
|
env "logik/core/environment"
|
||||||
"logik/core/utils"
|
"logik/core/utils"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -21,6 +21,7 @@ type dataType struct {
|
|||||||
|
|
||||||
type resultsType struct {
|
type resultsType struct {
|
||||||
eval int
|
eval int
|
||||||
|
nnf formulae.Formula
|
||||||
atoms []string
|
atoms []string
|
||||||
depth int
|
depth int
|
||||||
length int
|
length int
|
||||||
@@ -50,28 +51,18 @@ func getData() {
|
|||||||
utils.JsonToArrayOfStrings(s, &data.interpretation)
|
utils.JsonToArrayOfStrings(s, &data.interpretation)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getResults(tree syntaxbaum.SyntaxBaum) resultsType {
|
func getResults(tree formulae.Formula) resultsType {
|
||||||
ch1 := make(chan int)
|
|
||||||
ch2 := make(chan []string)
|
|
||||||
ch3 := make(chan int)
|
|
||||||
ch4 := make(chan int)
|
|
||||||
ch5 := make(chan int)
|
|
||||||
go rekursion.RekursivEval(ch1, tree, data.interpretation)
|
|
||||||
go rekursion.RekursivAtoms(ch2, tree)
|
|
||||||
go rekursion.RekursivDepth(ch3, tree)
|
|
||||||
go rekursion.RekursivLength(ch4, tree)
|
|
||||||
go rekursion.RekursivParentheses(ch5, tree)
|
|
||||||
// Methoden ausführen:
|
|
||||||
return resultsType{
|
return resultsType{
|
||||||
eval: <-ch1,
|
eval: recursion.Eval(tree, data.interpretation),
|
||||||
atoms: <-ch2,
|
nnf: recursion.NNF(tree),
|
||||||
depth: <-ch3,
|
atoms: recursion.Atoms(tree),
|
||||||
length: <-ch4,
|
depth: recursion.FmlDepth(tree),
|
||||||
nParentheses: <-ch5,
|
length: recursion.FmlLength(tree),
|
||||||
|
nParentheses: recursion.NrParentheses(tree),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func displayResults(tree syntaxbaum.SyntaxBaum, results resultsType) {
|
func displayResults(tree formulae.Formula, results resultsType) {
|
||||||
fmt.Println(fmt.Sprintf(
|
fmt.Println(fmt.Sprintf(
|
||||||
dedent.Dedent(`
|
dedent.Dedent(`
|
||||||
Syntaxbaum von
|
Syntaxbaum von
|
||||||
@@ -81,10 +72,11 @@ func displayResults(tree syntaxbaum.SyntaxBaum, results resultsType) {
|
|||||||
|
|
||||||
Für I = {%[3]s} und F wie oben gilt
|
Für I = {%[3]s} und F wie oben gilt
|
||||||
eval(F, I) = %[4]d;
|
eval(F, I) = %[4]d;
|
||||||
atoms(F) = {%[5]s}; <- *
|
F^NNF = %[5]s;
|
||||||
depth(F) = %[6]d; <- *
|
atoms(F) = {%[6]s}; <- *
|
||||||
length(F) = %[7]d; <- *
|
depth(F) = %[7]d; <- *
|
||||||
#parentheses(F) = %[8]d; <- *
|
length(F) = %[8]d; <- *
|
||||||
|
#parentheses(F) = %[9]d; <- *
|
||||||
|
|
||||||
* noch nicht implementiert!
|
* noch nicht implementiert!
|
||||||
Challenge: schreibe diese Methoden! (siehe README.md)
|
Challenge: schreibe diese Methoden! (siehe README.md)
|
||||||
@@ -93,6 +85,7 @@ func displayResults(tree syntaxbaum.SyntaxBaum, results resultsType) {
|
|||||||
tree.Pretty(" "),
|
tree.Pretty(" "),
|
||||||
strings.Join(data.interpretation, ", "),
|
strings.Join(data.interpretation, ", "),
|
||||||
results.eval,
|
results.eval,
|
||||||
|
results.nnf.GetExpr(),
|
||||||
// string(results.atoms),
|
// string(results.atoms),
|
||||||
strings.Join(results.atoms, ", "),
|
strings.Join(results.atoms, ", "),
|
||||||
results.depth,
|
results.depth,
|
||||||
|
|||||||
@@ -47,12 +47,10 @@ function precompile_grammars() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function compile_programme() {
|
function compile_programme() {
|
||||||
[ -f "main" ] && rm "main";
|
[ -f "dist/main" ] && rm "dist/main";
|
||||||
echo -e "\033[92;1mGO\033[0m kompiliert \033[1mmain.go\033[0m";
|
echo -e "\033[92;1mGO\033[0m kompiliert \033[1mmain.go\033[0m";
|
||||||
call_go build "main.go";
|
call_go build -o dist/main "main.go";
|
||||||
! [ -f "main" ] && exit 1;
|
! [ -f "dist/main" ] && exit 1;
|
||||||
! [ -d "dist" ] && mkdir "dist";
|
|
||||||
mv "main" "dist";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function run_programme() {
|
function run_programme() {
|
||||||
|
|||||||
@@ -9,14 +9,13 @@
|
|||||||
################################
|
################################
|
||||||
|
|
||||||
export TEST_VERBOSE=false # <- true: unittest mit verbose output
|
export TEST_VERBOSE=false # <- true: unittest mit verbose output
|
||||||
export TEST_TIMEOUT="60s"
|
export TEST_TIMEOUT="10s"
|
||||||
|
|
||||||
function call_go() {
|
function call_go() {
|
||||||
go $@;
|
go $@;
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_requirements() {
|
function check_requirements() {
|
||||||
[ -f "go.sum" ] && rm "go.sum";
|
|
||||||
call_go get "$( cat scripts/requirements )";
|
call_go get "$( cat scripts/requirements )";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
notes/.gitignore
vendored
4
notes/.gitignore
vendored
@@ -1,4 +0,0 @@
|
|||||||
*
|
|
||||||
!/.gitignore
|
|
||||||
|
|
||||||
!/*.pdf
|
|
||||||
69
notes/glossar.md
Normal file
69
notes/glossar.md
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<style>
|
||||||
|
table tbody tr td {
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
table tbody tr td:nth-child(1) {
|
||||||
|
font-size: 10pt;
|
||||||
|
}
|
||||||
|
table tbody tr td:nth-child(2), table tbody tr td:nth-child(3) {
|
||||||
|
font-size: 8pt;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
# Glossar #
|
||||||
|
|
||||||
|
| Symbol | Referenz (im Skript) | Kurze Beschreibung |
|
||||||
|
| :----- | :------------------- | :----------------- |
|
||||||
|
| `¬` | §8 Definition, VL2, Seite 8 | Negationsjunktor („nicht“) |
|
||||||
|
| `⋀` | §8 Definition, VL2, Seite 8 | Konjunktionsjunktor („und“) |
|
||||||
|
| `⋁` | §8 Definition, VL2, Seite 8 | Disunktionsjunktor („oder“) |
|
||||||
|
| `⟶` | VL2, Seite 47 | **Abkürzung** für Implikation |
|
||||||
|
| `⟷` | VL2, Seite 47 | **Abkürzung** für Doppeltimplikation |
|
||||||
|
| `⊨` | §9 Definition, VL2, Seite 34 | Erfüllbarkeitsbeziehung: `I ⊨ F` gdw. `I` erf. `F` |
|
||||||
|
| `=` | — | `F = G` gdw. `F` und `G` _dieselbe_ Formel sind |
|
||||||
|
| `≡` | §13 Definition, VL3, Seite 11 | `F ≡ G` gdw. `F`, `G` **semantisch** äquivalent |
|
||||||
|
| `{...}_⋀` | §39 Definition, VL5, Seite 108 | Mengendarstellung von Disjunktionsglied |
|
||||||
|
| ~~-`𝒜`-~~ | — | (**Eintrag ignorieren**: kommt in VL nicht vor!) |
|
||||||
|
| AL | (VL2–VL6) | Aussagenlogik |
|
||||||
|
| `Aᵢ` | §8 Definition, VL2, Seite 8 | das _i_-te Atom in der AL-Sprache |
|
||||||
|
| `Atome(·)` | §5 Definition, V2, Seite 14 | `Atome(F) =` Menge aller Atome in `F` |
|
||||||
|
| bereinigt | §76 Definition, VL10, Seite 21 | äqv. Formel, Variablensubstitution, so dass jede Var nur gebunden od. frei vorkommt |
|
||||||
|
| `𝔠` | §88+§89 Definition, VL11, Seiten 9+14 | (Fraktur c) die Herbrand-Konstante („out of bounds“) |
|
||||||
|
| DNF | §22 Definition, VL3, Seite 55 | disjunktive Normalform für AL und PL |
|
||||||
|
| erfüllbar | §10 Definition, VL2, Seite 68 | Die „klassischen“ Probleme |
|
||||||
|
| `eval(·,·)` | §16 Algorithmus, VL3, Seite 30 | Evaluation: `eval(F,I)=1` gdw. `I ⊨ F` |
|
||||||
|
| `ℱ` | §8 Definition, VL2, Seite 8 | Die „AL-Sprache“, Menge aller AL-Formeln |
|
||||||
|
| `Fun(t)` | §63 Definition, VL9, Seite 18 | alle Variablen, Konstanten, Fktsymbole in Term `t` |
|
||||||
|
| `FV(F)` | §57 Definition, VL8, Seite 27 | Menge freier Variablen in `F` (für Terme siehe `var(t)`) |
|
||||||
|
| `g`, `g´`, `g´´`, ... | | Skolemisierung: ∃-Eliminierung mittels Funktionen, die Abhängigkeiten ausdrücken |
|
||||||
|
| `GV(F)` | §75 Definition, VL10, Seite 17 | Menge gebundener Variablen in `F`|
|
||||||
|
| `H,H(F)` | §88 Definition, VL11, Seite 9 | Herbrand-Symbole, Herbrand-Universum |
|
||||||
|
| Herbrand-Interpretation | §89 Definition, VL11, Seite 14 | Interpretation für ein Herbrand-Modell. Alle H-M haben die gleiche Interpretationen von Termen. Nur Relationen können anders interpretiert werden. |
|
||||||
|
| KNF | §22 Definition (AL), VL3, Seite 55; §85 Definition (PL), VL10, Seite 89 | konjunktive Normalform für AL und PL |
|
||||||
|
| `ℒ` | §8 Definition, VL2, Seite 8 | Die Menge der Literale |
|
||||||
|
| PL | (ab VL7) | Prädikatenlogik |
|
||||||
|
| NNF | §18 Definition (AL), VL3, Seite 39; §73 Definition (PL), VL10, Seite 8 | Negationsnormalform - Negation nur bei Literalen |
|
||||||
|
| PNF | §78 Definition, VL10, Seite 37 | Pränexnormalform - Kette von Quantoren um einen Q-freien Teil |
|
||||||
|
| `ℛ,ℛ⁽ᵏ⁾`| §52 Definition, VL7, Seite 72 | Menge der (`k`-stelligen) Relationssymbole, `k≥0`. |
|
||||||
|
| `res(·)` | §41–43 Definition, VL6, Seiten 37–43 | `res(F) =` Menge aller Resolventen aus Disjunktionsgliedern aus `F` |
|
||||||
|
| `Res(·)` | §43 Definition, VL6, Seite 43 | `Res(F) = F ∪ res(F)` |
|
||||||
|
| `Res⁽ⁿ⁾(·)` | §43 Definition, VL6, Seite 43 | `Res(Res(···Res(F)···))`, _n_ Mal |
|
||||||
|
| `Res*(·)` | §43 Definition, VL6, Seite 43 | Resolutionshülle |
|
||||||
|
| `𝒮,𝒮⁽ᵏ⁾`| §52 Definition, VL7, Seite 72 | Menge der (`k`-stelligen) Funktionssymbole, `k≥0`. **Beachte:** für `k=0` sind dies die Konstanten! |
|
||||||
|
| Skolemform | §81, VL10, Seite 62 | äqv. Formel, in der alle Existenzquantoren eliminiert wurden |
|
||||||
|
| strukturelle Ind | §6 Theorem, VL2, Seite 24 | allgemeine Induktion über die Teilformelbeziehung |
|
||||||
|
| strukturelle Rek | §4 Theorem, VL2, Seite 12 | rekursive Konstruktionschemata über die Teilformelbeziehung |
|
||||||
|
| `Sym(F)` | §64 Definition, VL9, Seite 20 | alle „relevanten“ Symbole in `F`: alle **freien** Vars, alle Konstanten, Fktsymbole, Relnsymbole |
|
||||||
|
| `𝒯` | §53 Definition, VL7, Seite 74 | Menge der Terme in PL |
|
||||||
|
| tautologisch | §10 Definition, VL2, Seite 68 | Die „klassischen“ Probleme |
|
||||||
|
| `TF(·)` | §35 Definition, VL5, Seite 56 | `TF(F) =` Menge aller Teilformeln in `F` (inkl. `F` selbst) |
|
||||||
|
| `tᵥ` | §37 Definition, VL5, Seite 64 | Abbildung, die Teilformeln auf Literale abbildet |
|
||||||
|
| `tseiᵥ` | §37 Definition, VL5, Seite 64 | Tseitin-Transformation |
|
||||||
|
| unerfüllbar | §10 Definition, VL2, Seite 68 | Die „klassischen“ Probleme |
|
||||||
|
| `𝒱` | §52 Definition, VL7, Seite 72 | Menge der Variablen in PL |
|
||||||
|
| `var(t)` | §55 Definition, VL8, Seite 20 | Menge der Variablen in `t` (für Fml siehe `FV(F)`) |
|
||||||
|
| widerlegbar | §10 Definition, VL2, Seite 68 | Die „klassischen“ Probleme |
|
||||||
|
|
||||||
|
... (wird fortgesetzt)
|
||||||
|
|
||||||
|
**ACHTUNG:** Seitennr können abweichen.
|
||||||
BIN
notes/woche10.pdf
Normal file
BIN
notes/woche10.pdf
Normal file
Binary file not shown.
BIN
notes/woche12.pdf
Normal file
BIN
notes/woche12.pdf
Normal file
Binary file not shown.
BIN
notes/woche14.pdf
Normal file
BIN
notes/woche14.pdf
Normal file
Binary file not shown.
BIN
notes/woche5.pdf
BIN
notes/woche5.pdf
Binary file not shown.
BIN
notes/woche8.pdf
Normal file
BIN
notes/woche8.pdf
Normal file
Binary file not shown.
@@ -2,9 +2,30 @@
|
|||||||
|
|
||||||
Inhaltsverzeichnis
|
Inhaltsverzeichnis
|
||||||
|
|
||||||
- [Vorlesungswoche 1](./woche1.md)
|
- [Vorlesungswoche 1](./woche1.md) (_keine Übung_)
|
||||||
- [Vorlesungswoche 2](./woche2.md) Erste Übung: Organisatorisches
|
- [Vorlesungswoche 2](./woche2.md) Erste Übung: Organisatorisches.
|
||||||
- [Vorlesungswoche 3](./woche3.md) Seminaraufgaben aus Blatt 1
|
- [Vorlesungswoche 3](./woche3.md) Semaufg Blatt 1; [BBB Aufzeichnung](https://t1p.de/tjiu).
|
||||||
- [Vorlesungswoche 4](./woche4.md) ~~Hausaufgaben aus Blatt ??~~ Spezielle Themen
|
- [Vorlesungswoche 4](./woche4.md) Spezielle Themen; [Zoom Aufzeichnung](https://t1p.de/91vz).
|
||||||
- [Vorlesungswoche 5](./woche5.md) Seminaraufgaben aus Blatt 2
|
- [Vorlesungswoche 5](./woche5.md) Semaufg Blatt 2; [Zoom Aufzeichnung](https://t1p.de/ny7n).
|
||||||
- [Vorlesungswoche 6](./woche6.md) Hausaufgaben aus Blatt 1
|
- [Vorlesungswoche 6](./woche6.md) HA Blatt 1; [Zoom Aufzeichnung](https://t1p.de/m431).
|
||||||
|
- [Vorlesungswoche 7](./woche7.md) (_keine Übung: ...Pfingsten..._)
|
||||||
|
- [Vorlesungswoche 8](./woche8.md) Semaufg Blatt 3; [Zoom Aufzeichnung](https://t1p.de/fmok).
|
||||||
|
- [Vorlesungswoche 9](./woche9.md) HA Blatt 2; [Zoom Aufzeichnung](https://t1p.de/8vmh).
|
||||||
|
- [Vorlesungswoche 10](./woche10.md) Semaufg Blatt 4; [Zoom Aufzeichnung](https://t1p.de/fpv5).
|
||||||
|
- [Vorlesungswoche 11](./woche11.md) HA Blatt 3; [Zoom Aufzeichnung](https://t1p.de/626y).
|
||||||
|
- [Vorlesungswoche 12](./woche12.md) Semaufg Blatt 5; [Zoom Aufzeichnung](https://t1p.de/n4bt).
|
||||||
|
- (Zusatz) Seminaraufgabe 5.5 [Zoom Aufzeichnung](https://t1p.de/bnlj).
|
||||||
|
- [Vorlesungswoche 13](./woche13.md) HA Blatt 4; [Zoom Aufzeichnung](https://t1p.de/76qo).
|
||||||
|
- [Vorlesungswoche 14](./woche14.md) Semaufg Blatt 6; [Zoom Aufzeichnung](https://t1p.de/slya).
|
||||||
|
- [Vorlesungswoche 15](./woche15.md) HA Blatt 5; [Zoom Aufzeichnung](https://t1p.de/3xsm).
|
||||||
|
|
||||||
|
**Notizen**
|
||||||
|
|
||||||
|
- Für den BBB-Raum bzw. die Zoom-Aufzeichnungen braucht man einen **Code** (siehe Moodle).
|
||||||
|
- Klausurdatum wird noch angekündigt.
|
||||||
|
Je nachdem können wir ggf. 1–2 Stunden für Vorklausurfragen organisieren.
|
||||||
|
- In [**Vorlesungswoche 16**](./woche16.md) wird eine zusätzliche Übung angeboten:
|
||||||
|
<br/>
|
||||||
|
allgemeine Fragestellung von Studierenden.
|
||||||
|
- Zoom-Raum mit dem üblichen Code.
|
||||||
|
- Dies wird _nicht_ aufgezeichnet werden!
|
||||||
|
|||||||
23
protocol/woche10.md
Normal file
23
protocol/woche10.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Vorlesungswoche 10 (14.–20. Juni) #
|
||||||
|
|
||||||
|
Handnotizen findet man unter [notes/woche10.pdf](./../notes/woche10.pdf).
|
||||||
|
|
||||||
|
## Agenda ##
|
||||||
|
|
||||||
|
- [x] 2–5 min Organisatorisches
|
||||||
|
- [x] Serie 4, Seminaraufgaben besprechen
|
||||||
|
- [x] SemA 4.1
|
||||||
|
- [x] SemA 4.2
|
||||||
|
- [x] SemA 4.3
|
||||||
|
- [x] SemA 4.4
|
||||||
|
- [x] SemA 4.5
|
||||||
|
- Anmerkungen zu HA
|
||||||
|
- [x] restliche Zeit für allg. Fragen
|
||||||
|
|
||||||
|
## Nächste Woche ##
|
||||||
|
|
||||||
|
- HA aus Blatt 3.
|
||||||
|
|
||||||
|
### TODOs (Studierende) ###
|
||||||
|
|
||||||
|
- am ÜB 4 weiter arbeiten.
|
||||||
20
protocol/woche11.md
Normal file
20
protocol/woche11.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Vorlesungswoche 11 (21.–27. Juni) #
|
||||||
|
|
||||||
|
## Agenda ##
|
||||||
|
|
||||||
|
- [x] 2–5 min Organisatorisches
|
||||||
|
- [x] Serie 3, Hausaufgaben besprechen
|
||||||
|
- [x] allgemeines Feedback
|
||||||
|
- [x] HA 3.1
|
||||||
|
- [x] HA 3.2
|
||||||
|
- [x] HA 3.3
|
||||||
|
- [x] restliche Zeit für allg. Fragen
|
||||||
|
- Frage über VPN Zugang bis nächste Woche zu klären.
|
||||||
|
|
||||||
|
## Nächste Woche ##
|
||||||
|
|
||||||
|
- Seminaraufgaben aus Blatt 5.
|
||||||
|
|
||||||
|
### TODOs (Studierende) ###
|
||||||
|
|
||||||
|
- ÜB 4 bis **Do 24.06.** um 22:00 abgeben!
|
||||||
43
protocol/woche12.md
Normal file
43
protocol/woche12.md
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
# Vorlesungswoche 12 (28. Juni – 4. Juli) #
|
||||||
|
|
||||||
|
## Agenda ##
|
||||||
|
|
||||||
|
- [x] 2–5 min Organisatorisches
|
||||||
|
- [x] Serie 5, Seminaraufgaben besprechen
|
||||||
|
- [x] SemA 5.1
|
||||||
|
- [x] SemA 5.2
|
||||||
|
- [x] SemA 5.3
|
||||||
|
- [x] SemA 5.4
|
||||||
|
- ~~[ ] (Zusatz) SemA 5.5~~ ---> siehe Aufzeichnung
|
||||||
|
- [x] restliche Zeit für allg. Fragen
|
||||||
|
- Alternativer Beweis von (d) durch Argument:
|
||||||
|
|
||||||
|
```
|
||||||
|
»Sonst wären F und F^skol sem. äquivalent,
|
||||||
|
aber das ist nicht i. A. der Fall.«
|
||||||
|
```
|
||||||
|
|
||||||
|
Da wir aber uns aber auf einer Instanz beschränken,
|
||||||
|
passt dieser Ansatz nicht.
|
||||||
|
Wir müssen im Einzelfall prüfen.
|
||||||
|
Vgl. Unterschied zw.
|
||||||
|
|
||||||
|
```
|
||||||
|
1. Es ist nicht so, dass (F ≡ F^skol) für alle F
|
||||||
|
```
|
||||||
|
und
|
||||||
|
|
||||||
|
```
|
||||||
|
2. Für alle F, es ist nicht so dass (F ≡ F^skol).
|
||||||
|
```
|
||||||
|
|
||||||
|
Wir haben nur 1 und damit kann es durchaus sein,
|
||||||
|
dass für einzelne Fälle F, F^skol schon sem. äqv. sind.
|
||||||
|
|
||||||
|
## Nächste Woche ##
|
||||||
|
|
||||||
|
- HA aus Blatt 4.
|
||||||
|
|
||||||
|
### TODOs (Studierende) ###
|
||||||
|
|
||||||
|
- am ÜB 5 weiter arbeiten.
|
||||||
21
protocol/woche13.md
Normal file
21
protocol/woche13.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Vorlesungswoche 13 (5.–11. Juli) #
|
||||||
|
|
||||||
|
## Agenda ##
|
||||||
|
|
||||||
|
- [x] 2–5 min Organisatorisches
|
||||||
|
- [x] Serie 4, Hausaufgaben besprechen
|
||||||
|
- [x] allgemeines Feedback
|
||||||
|
- [x] HA 4.1
|
||||||
|
- [x] HA 4.2
|
||||||
|
- [x] HA 4.3
|
||||||
|
- [x] HA 4.4
|
||||||
|
- [x] HA 4.5
|
||||||
|
- [x] restliche Zeit für allg. Fragen
|
||||||
|
|
||||||
|
## Nächste Woche ##
|
||||||
|
|
||||||
|
- Seminaraufgaben aus Blatt 6.
|
||||||
|
|
||||||
|
### TODOs (Studierende) ###
|
||||||
|
|
||||||
|
- ÜB 5 bis **Do 08.07.** um 22:00 abgeben!
|
||||||
23
protocol/woche14.md
Normal file
23
protocol/woche14.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Vorlesungswoche 14 (12.–18. Juli) #
|
||||||
|
|
||||||
|
## Agenda ##
|
||||||
|
|
||||||
|
- [x] 2–5 min Organisatorisches
|
||||||
|
- **Beachte:** HA zu Serie 6 werden leider nicht besprochen!
|
||||||
|
- Notenstand in Moodle, Schwellwert 59 Pkt
|
||||||
|
- Zusatzübung
|
||||||
|
- [x] Serie 6, Seminaraufgaben besprechen
|
||||||
|
- [x] SemA 6.1
|
||||||
|
- [x] SemA 6.2
|
||||||
|
- [x] SemA 6.3
|
||||||
|
- [x] SemA 6.4
|
||||||
|
- ~~[ ] (Zusatz) SemA 6.5~~ ---> siehe Aufzeichnung in Moodle
|
||||||
|
- [x] restliche Zeit für allg. Fragen
|
||||||
|
|
||||||
|
## Nächste Woche ##
|
||||||
|
|
||||||
|
- HA aus Blatt 5.
|
||||||
|
|
||||||
|
### TODOs (Studierende) ###
|
||||||
|
|
||||||
|
- am ÜB 6 weiter arbeiten.
|
||||||
23
protocol/woche15.md
Normal file
23
protocol/woche15.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Vorlesungswoche 15 (19.–25. Juli) #
|
||||||
|
|
||||||
|
## Agenda ##
|
||||||
|
|
||||||
|
- [x] 2–5 min Organisatorisches
|
||||||
|
- [x] Anfragen, ob Vorklausurübung erwünscht wird.
|
||||||
|
- [x] Serie 5, Hausaufgaben besprechen
|
||||||
|
- ~~[ ] allgemeines Feedback~~
|
||||||
|
- [x] HA 5.1
|
||||||
|
- [x] HA 5.2
|
||||||
|
- [x] HA 5.3
|
||||||
|
- [x] HA 5.4
|
||||||
|
- [x] HA 5.5
|
||||||
|
- ~~[ ] restliche Zeit für allg. Fragen~~
|
||||||
|
|
||||||
|
## Nächste Woche ##
|
||||||
|
|
||||||
|
- Studierende bringen **eigene Fragen** mit und wir diskutieren diese.
|
||||||
|
|
||||||
|
### TODOs (Studierende) ###
|
||||||
|
|
||||||
|
- ÜB 6 bis **Do 22.07.** um 22:00 abgeben!
|
||||||
|
- Klausurvorbereitung!
|
||||||
15
protocol/woche16.md
Normal file
15
protocol/woche16.md
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# Woche 16 (26. Juli – 1. Aug) #
|
||||||
|
|
||||||
|
Diese Woche wird nicht aufgezeichnet.
|
||||||
|
|
||||||
|
## Agenda ##
|
||||||
|
|
||||||
|
[x] allgemeine ganzen Stoff betreffende Fragen von Studierenden
|
||||||
|
|
||||||
|
## Nächste Woche ##
|
||||||
|
|
||||||
|
- Klausur.
|
||||||
|
|
||||||
|
### TODOs (Studierende) ###
|
||||||
|
|
||||||
|
- Klausurvorbereitung!
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
# Vorlesungswoche 3 (26. April – 2. Mai) #
|
# Vorlesungswoche 3 (26. April – 2. Mai) #
|
||||||
|
|
||||||
|
## Agenda ##
|
||||||
|
|
||||||
- [x] Organisatorisches (max. 5 min)
|
- [x] Organisatorisches (max. 5 min)
|
||||||
- Erinnerung über Abgabe: Matrikelnr., 1 PDF.
|
- Erinnerung über Abgabe: Matrikelnr., 1 PDF.
|
||||||
- [x] Serie 1, Seminaraufgaben
|
- [x] Serie 1, Seminaraufgaben
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
# Vorlesungswoche 4 (3. April – 9. Mai) #
|
# Vorlesungswoche 4 (3. Mai – 9. Mai) #
|
||||||
|
|
||||||
|
Handnotizen findet man unter [notes/woche4.pdf](./../notes/woche4.pdf).
|
||||||
|
|
||||||
|
## Agenda ##
|
||||||
|
|
||||||
- [x] Organisatorisches (max. 5 min)
|
- [x] Organisatorisches (max. 5 min)
|
||||||
- Hochladen = Abgeben
|
- Hochladen = Abgeben
|
||||||
@@ -43,7 +47,6 @@
|
|||||||
-> „gelöst“ durch wohlfundiert/Wohlordnung
|
-> „gelöst“ durch wohlfundiert/Wohlordnung
|
||||||
-> R keine Menge
|
-> R keine Menge
|
||||||
|
|
||||||
|
|
||||||
## Nächste Woche ##
|
## Nächste Woche ##
|
||||||
|
|
||||||
- Seminaraufgaben für Serie 2:
|
- Seminaraufgaben für Serie 2:
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
# Vorlesungswoche 5 (10.–16. Mai) #
|
# Vorlesungswoche 5 (10.–16. Mai) #
|
||||||
|
|
||||||
|
Handnotizen findet man unter [notes/woche5.pdf](./../notes/woche5.pdf).
|
||||||
|
|
||||||
## Agenda ##
|
## Agenda ##
|
||||||
|
|
||||||
- [x] 2–5 min Organisatorisches (max. 5 min)
|
- [x] 2–5 min Organisatorisches (max. 5 min)
|
||||||
- [x] Serie 2, Seminaraufgaben
|
- [x] Serie 2, Seminaraufgaben
|
||||||
- [x] 7,5 min SA 2.1 Modelle
|
- [x] 7,5 min SA 2.1 Modelle
|
||||||
|
|||||||
20
protocol/woche6.md
Normal file
20
protocol/woche6.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Vorlesungswoche 6 (17.–23. Mai) #
|
||||||
|
|
||||||
|
## Agenda ##
|
||||||
|
|
||||||
|
- [x] 2–5 min Organisatorisches
|
||||||
|
- [x] Serie 1, Hausaufgaben besprechen (inkl. Feedbacknotizen von SHK)
|
||||||
|
- [x] HA 1.1
|
||||||
|
- [x] HA 1.2
|
||||||
|
- [x] HA 1.3
|
||||||
|
- [x] HA 1.4
|
||||||
|
- [x] restliche Zeit für allg. Fragen
|
||||||
|
- Fragen zu strukturelle Induktion
|
||||||
|
|
||||||
|
## Nächste Woche ##
|
||||||
|
|
||||||
|
- nach Anfrage kann ggf. etwas aufgezeichnet werden
|
||||||
|
|
||||||
|
### TODOs (Studierende) ###
|
||||||
|
|
||||||
|
- ÜB 2 bis **Do 20.05.** um 22:00 abgeben!
|
||||||
3
protocol/woche7.md
Normal file
3
protocol/woche7.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Vorlesungswoche 7 (24.–30. Mai) #
|
||||||
|
|
||||||
|
(keine VL od. ÜG diese Woche)
|
||||||
23
protocol/woche8.md
Normal file
23
protocol/woche8.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Vorlesungswoche 8 (31. Mai – 6. Juni) #
|
||||||
|
|
||||||
|
Handnotizen findet man unter [notes/woche8.pdf](./../notes/woche8.pdf).
|
||||||
|
|
||||||
|
## Agenda ##
|
||||||
|
|
||||||
|
- [x] 2–5 min Organisatorisches
|
||||||
|
- Feedback zu HA 1
|
||||||
|
- Symbolverzeichnis findet man in [notes/glossar.md](./../notes/glossar.md).
|
||||||
|
- [x] Serie 3, Seminaraufgaben besprechen
|
||||||
|
- [x] SemA 3.1
|
||||||
|
- [x] SemA 3.2
|
||||||
|
- [x] SemA 3.3
|
||||||
|
- [ ] restliche Zeit für allg. Fragen
|
||||||
|
|
||||||
|
## Nächste Woche ##
|
||||||
|
|
||||||
|
- HA aus Blatt 2.
|
||||||
|
|
||||||
|
### TODOs (Studierende) ###
|
||||||
|
|
||||||
|
– VL Wochen 5+6 wieder durchlesen, VL Woche 7 für Vorlesung durchlesen.
|
||||||
|
- am ÜB 3 weiter arbeiten.
|
||||||
24
protocol/woche9.md
Normal file
24
protocol/woche9.md
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Vorlesungswoche 9 (7.–13. Juni) #
|
||||||
|
|
||||||
|
## Agenda ##
|
||||||
|
|
||||||
|
- [x] 2–5 min Organisatorisches
|
||||||
|
- [x] Serie 2, Hausaufgaben besprechen
|
||||||
|
- [x] allgemeines Feedback
|
||||||
|
- [x] SemA 2.1
|
||||||
|
- [x] SemA 2.2
|
||||||
|
- [x] SemA 2.3
|
||||||
|
- [x] SemA 2.4
|
||||||
|
- [x] SemA 2.5
|
||||||
|
- [x] restliche Zeit für allg. Fragen
|
||||||
|
|
||||||
|
## Nächste Woche ##
|
||||||
|
|
||||||
|
- Seminaraufgaben aus Blatt 4.
|
||||||
|
- Allg.: bitte überlegen, was vor der Klausur erwünscht wäre, bspw. interaktive Sprechstunden/Fragerunde,
|
||||||
|
oder ob ihr (selbstverständlich Pandemie-Maßnahmen beachtend) unter euch euch treffen wollt,
|
||||||
|
durch den Stoff + die Übungen gemeinsam geht.
|
||||||
|
|
||||||
|
### TODOs (Studierende) ###
|
||||||
|
|
||||||
|
- ÜB 3 bis **Do 10.06.** um 22:00 abgeben!
|
||||||
Reference in New Issue
Block a user