├── .gitignore
├── LICENSE
├── README
├── aufgaben
├── 1
│ ├── 10000008
│ │ ├── README
│ │ └── meme.png
│ ├── 10000001.tex
│ ├── 10000002.tex
│ ├── 10000003.tex
│ ├── 10000004.tex
│ ├── 10000005.tex
│ ├── 10000006.tex
│ ├── 10000007.tex
│ ├── 10000008.tex
│ ├── 10000009.tex
│ ├── 10000010.tex
│ ├── 10000011.tex
│ ├── 10000012.tex
│ ├── 10000013.tex
│ ├── 10000014.tex
│ └── 10000017.tex
├── 2
│ ├── 20000001.tex
│ ├── 20000002.tex
│ ├── 20000003.tex
│ ├── 20000005.tex
│ └── 20000006.tex
├── 3
│ ├── 30000013
│ │ └── beispiel.csv
│ ├── 30000015
│ │ ├── aufg1a.lsg
│ │ └── aufg1b.lsg
│ ├── 30000044
│ │ ├── Makefile
│ │ ├── part.c
│ │ └── testdata
│ ├── 30000064
│ │ ├── 30000064.java
│ │ └── ausdruck.txt
│ ├── 30000068
│ │ ├── date.regex
│ │ └── fileext.regex
│ ├── 30000070
│ │ └── air.txt
│ ├── 30000076
│ │ ├── Makefile
│ │ ├── wordle.pdf
│ │ └── wordle.tex
│ ├── 30000077
│ │ └── Mastermind.jpeg
│ ├── 30000096
│ │ ├── ungerade.pdf
│ │ └── ungerade_minimized.pdf
│ ├── 30000001.tex
│ ├── 30000002.tex
│ ├── 30000003.tex
│ ├── 30000004.tex
│ ├── 30000005.tex
│ ├── 30000006.tex
│ ├── 30000007.tex
│ ├── 30000008.tex
│ ├── 30000009.tex
│ ├── 30000010.tex
│ ├── 30000011.tex
│ ├── 30000012.tex
│ ├── 30000013.tex
│ ├── 30000014.tex
│ ├── 30000015.tex
│ ├── 30000016.tex
│ ├── 30000017.tex
│ ├── 30000018.tex
│ ├── 30000019.tex
│ ├── 30000020.tex
│ ├── 30000021.tex
│ ├── 30000022.tex
│ ├── 30000023.tex
│ ├── 30000024.tex
│ ├── 30000025.tex
│ ├── 30000026.tex
│ ├── 30000027.tex
│ ├── 30000028.tex
│ ├── 30000029.tex
│ ├── 30000030.tex
│ ├── 30000031.tex
│ ├── 30000032.tex
│ ├── 30000033.tex
│ ├── 30000034.tex
│ ├── 30000035.tex
│ ├── 30000036.tex
│ ├── 30000037.tex
│ ├── 30000038.tex
│ ├── 30000039.tex
│ ├── 30000040.tex
│ ├── 30000041.tex
│ ├── 30000042.tex
│ ├── 30000043.tex
│ ├── 30000044.tex
│ ├── 30000045.tex
│ ├── 30000046.tex
│ ├── 30000047.tex
│ ├── 30000048.tex
│ ├── 30000049.tex
│ ├── 30000050.tex
│ ├── 30000051.tex
│ ├── 30000052.tex
│ ├── 30000053.tex
│ ├── 30000054.tex
│ ├── 30000055.tex
│ ├── 30000056.tex
│ ├── 30000057.tex
│ ├── 30000058.tex
│ ├── 30000059.tex
│ ├── 30000060.tex
│ ├── 30000061.tex
│ ├── 30000062.tex
│ ├── 30000063.tex
│ ├── 30000064.tex
│ ├── 30000065.tex
│ ├── 30000066.tex
│ ├── 30000067.tex
│ ├── 30000068.tex
│ ├── 30000069.tex
│ ├── 30000070.tex
│ ├── 30000071.tex
│ ├── 30000072.tex
│ ├── 30000073.tex
│ ├── 30000074.tex
│ ├── 30000075.tex
│ ├── 30000076.tex
│ ├── 30000077.tex
│ ├── 30000078.tex
│ ├── 30000079.tex
│ ├── 30000080.tex
│ ├── 30000081.tex
│ ├── 30000082.tex
│ ├── 30000083.tex
│ ├── 30000084.tex
│ ├── 30000085.tex
│ ├── 30000086.tex
│ ├── 30000087.tex
│ ├── 30000088.tex
│ ├── 30000089.tex
│ ├── 30000090.tex
│ ├── 30000091.tex
│ ├── 30000092.tex
│ ├── 30000093.tex
│ ├── 30000094.tex
│ ├── 30000095.tex
│ ├── 30000096.tex
│ ├── 30000097.tex
│ └── 30000098.tex
├── 4
│ ├── 40000042
│ │ ├── block.c
│ │ ├── block.pas
│ │ └── leer.c
│ ├── 40000043
│ │ └── feld.txt
│ ├── 40000001.tex
│ ├── 40000002.tex
│ ├── 40000003.tex
│ ├── 40000004.tex
│ ├── 40000005.tex
│ ├── 40000006.tex
│ ├── 40000007.tex
│ ├── 40000008.tex
│ ├── 40000009.tex
│ ├── 40000010.tex
│ ├── 40000012.tex
│ ├── 40000013.tex
│ ├── 40000014.tex
│ ├── 40000015.tex
│ ├── 40000016.tex
│ ├── 40000017.tex
│ ├── 40000018.tex
│ ├── 40000019.tex
│ ├── 40000020.tex
│ ├── 40000021.tex
│ ├── 40000022.tex
│ ├── 40000023.tex
│ ├── 40000024.tex
│ ├── 40000025.tex
│ ├── 40000026.tex
│ ├── 40000027.tex
│ ├── 40000028.tex
│ ├── 40000029.tex
│ ├── 40000030.tex
│ ├── 40000031.tex
│ ├── 40000032.tex
│ ├── 40000033.tex
│ ├── 40000034.tex
│ ├── 40000035.tex
│ ├── 40000036.tex
│ ├── 40000037.tex
│ ├── 40000038.tex
│ ├── 40000039.tex
│ ├── 40000040.tex
│ ├── 40000041.tex
│ ├── 40000042.tex
│ ├── 40000043.tex
│ ├── 40000044.tex
│ ├── 40000045.tex
│ ├── 40000046.tex
│ ├── 40000047.tex
│ ├── 40000048.tex
│ ├── 40000049.tex
│ ├── 40000050.tex
│ ├── 40000051.tex
│ ├── 40000052.tex
│ ├── 40000053.tex
│ ├── 40000054.tex
│ ├── 40000055.tex
│ ├── 40000056.tex
│ ├── 40000057.tex
│ ├── 40000058.tex
│ ├── 40000059.tex
│ ├── 40000060.tex
│ ├── 40000061.tex
│ ├── 40000062.tex
│ ├── 40000063.tex
│ ├── 40000064.tex
│ ├── 40000065.tex
│ ├── 40000066.tex
│ ├── 40000067.tex
│ ├── 40000068.tex
│ ├── 40000069.tex
│ ├── 40000070.tex
│ ├── 40000071.tex
│ ├── 40000072.tex
│ ├── 40000073.tex
│ ├── 40000074.tex
│ ├── 40000075.tex
│ ├── 40000076.tex
│ ├── 40000077.tex
│ ├── 40000078.tex
│ ├── 40000079.tex
│ ├── 40000080.tex
│ ├── 40000081.tex
│ ├── 40000082.tex
│ ├── 40000083.tex
│ ├── 40000084.tex
│ ├── 40000085.tex
│ ├── 40000086.tex
│ ├── 40000087.tex
│ ├── 40000088.tex
│ ├── 40000089.tex
│ ├── 40000090.tex
│ ├── 40000091.tex
│ ├── 40000092.tex
│ └── 40000093.tex
├── 5
│ ├── 50000001.tex
│ ├── 50000002.tex
│ ├── 50000003.tex
│ ├── 50000004.tex
│ ├── 50000005.tex
│ ├── 50000006.tex
│ ├── 50000007.tex
│ ├── 50000008.tex
│ ├── 50000009.tex
│ ├── 50000010.tex
│ ├── 50000011.tex
│ ├── 50000012.tex
│ ├── 50000013.tex
│ ├── 50000014.tex
│ ├── 50000015.tex
│ ├── 50000016.tex
│ ├── 50000017.tex
│ ├── 50000018.tex
│ ├── 50000019.tex
│ ├── 50000020.tex
│ ├── 50000021.tex
│ ├── 50000022.tex
│ ├── 50000023.tex
│ ├── 50000024.tex
│ ├── 50000025.tex
│ ├── 50000026.tex
│ ├── 50000027.tex
│ ├── 50000028.tex
│ ├── 50000029.tex
│ ├── 50000030.tex
│ ├── 50000031.tex
│ ├── 50000032.tex
│ ├── 50000033.tex
│ ├── 50000034.tex
│ ├── 50000035.tex
│ ├── 50000036.tex
│ ├── 50000037.tex
│ ├── 50000038.tex
│ ├── 50000039.tex
│ ├── 50000040.tex
│ ├── 50000041.tex
│ └── 50000042.tex
├── 6
│ ├── 60000005
│ │ ├── a.java
│ │ ├── b.java
│ │ ├── c.java
│ │ ├── d.java
│ │ └── e.java
│ ├── 60000041
│ │ ├── DSC_0559.jpg
│ │ ├── Makefile
│ │ └── biber2.jpg
│ ├── 60000001.tex
│ ├── 60000002.tex
│ ├── 60000003.tex
│ ├── 60000004.tex
│ ├── 60000005.tex
│ ├── 60000008.tex
│ ├── 60000009.tex
│ ├── 60000010.tex
│ ├── 60000011.tex
│ ├── 60000012.tex
│ ├── 60000013.tex
│ ├── 60000014.tex
│ ├── 60000015.tex
│ ├── 60000016.tex
│ ├── 60000017.tex
│ ├── 60000018.tex
│ ├── 60000019.tex
│ ├── 60000020.tex
│ ├── 60000022.tex
│ ├── 60000023.tex
│ ├── 60000025.tex
│ ├── 60000026.tex
│ ├── 60000027.tex
│ ├── 60000028.tex
│ ├── 60000029.tex
│ ├── 60000030.tex
│ ├── 60000031.tex
│ ├── 60000032.tex
│ ├── 60000033.tex
│ ├── 60000034.tex
│ ├── 60000035.tex
│ ├── 60000036.tex
│ ├── 60000037.tex
│ ├── 60000038.tex
│ ├── 60000039.tex
│ ├── 60000040.tex
│ ├── 60000041.tex
│ ├── 60000042.tex
│ ├── 60000043.tex
│ ├── 60000044.tex
│ ├── 60000045.tex
│ ├── 60000046.tex
│ ├── 60000047.tex
│ ├── 60000048.tex
│ ├── 60000049.tex
│ ├── 60000050.tex
│ ├── 60000051.tex
│ ├── 60000052.tex
│ └── 60000053.tex
├── 7
│ ├── 70000014
│ │ └── kakuro.pdf
│ ├── 70000015
│ │ └── nurikabe.png
│ ├── 70000020
│ │ ├── calcudoku-problem.png
│ │ └── calcudoku-solved.png
│ ├── 70000022
│ │ ├── HashiwokakeroBeispiel.pdf
│ │ └── HashiwokakeroLoesung.pdf
│ ├── 70000024
│ │ ├── fill1.png
│ │ └── fill8.png
│ ├── 70000027
│ │ ├── answer.png
│ │ └── example.png
│ ├── 70000030
│ │ ├── Hitori.png
│ │ └── Hitoricompleted.png
│ ├── 70000032
│ │ ├── example-big.png
│ │ └── solution-big.png
│ ├── 70000034
│ │ ├── lightup-solution.png
│ │ └── lightup.png
│ ├── 70000037
│ │ ├── Flow-aufgabe.png
│ │ ├── Flow-loesung.png
│ │ └── Makefile
│ ├── 70000048
│ │ ├── Makefile
│ │ ├── nurimaze.pdf
│ │ └── nurimaze.tex
│ ├── 70000050
│ │ ├── Makefile
│ │ ├── graph-common.tex
│ │ ├── graph-loesung.pdf
│ │ ├── graph-loesung.tex
│ │ ├── graph.pdf
│ │ └── graph.tex
│ ├── 70000065
│ │ ├── license.txt
│ │ ├── puzzle-mit-fehlendem-stueck-fehlende-puzzleteile.jpg
│ │ └── puzzle.jpg
│ ├── 70000001.tex
│ ├── 70000002.tex
│ ├── 70000003.tex
│ ├── 70000004.tex
│ ├── 70000005.tex
│ ├── 70000006.tex
│ ├── 70000007.tex
│ ├── 70000008.tex
│ ├── 70000009.tex
│ ├── 70000010.tex
│ ├── 70000011.tex
│ ├── 70000012.tex
│ ├── 70000013.tex
│ ├── 70000014.tex
│ ├── 70000015.tex
│ ├── 70000016.tex
│ ├── 70000017.tex
│ ├── 70000018.tex
│ ├── 70000019.tex
│ ├── 70000020.tex
│ ├── 70000021.tex
│ ├── 70000022.tex
│ ├── 70000023.tex
│ ├── 70000024.tex
│ ├── 70000025.tex
│ ├── 70000026.tex
│ ├── 70000027.tex
│ ├── 70000028.tex
│ ├── 70000029.tex
│ ├── 70000030.tex
│ ├── 70000031.tex
│ ├── 70000032.tex
│ ├── 70000033.tex
│ ├── 70000034.tex
│ ├── 70000035.tex
│ ├── 70000036.tex
│ ├── 70000037.tex
│ ├── 70000038.tex
│ ├── 70000039.tex
│ ├── 70000040.tex
│ ├── 70000041.tex
│ ├── 70000042.tex
│ ├── 70000043.tex
│ ├── 70000044.tex
│ ├── 70000045.tex
│ ├── 70000046.tex
│ ├── 70000047.tex
│ ├── 70000048.tex
│ ├── 70000049.tex
│ ├── 70000050.tex
│ ├── 70000051.tex
│ ├── 70000052.tex
│ ├── 70000053.tex
│ ├── 70000054.tex
│ ├── 70000055.tex
│ ├── 70000056.tex
│ ├── 70000057.tex
│ ├── 70000058.tex
│ ├── 70000059.tex
│ ├── 70000060.tex
│ ├── 70000061.tex
│ ├── 70000062.tex
│ ├── 70000063.tex
│ ├── 70000064.tex
│ ├── 70000065.tex
│ ├── 70000066.tex
│ ├── 70000067.tex
│ ├── 70000068.tex
│ ├── 70000069.tex
│ ├── 70000070.tex
│ ├── 70000071.tex
│ ├── 70000072.tex
│ ├── 70000073.tex
│ ├── 70000074.tex
│ ├── 70000075.tex
│ ├── 70000076.tex
│ ├── 70000077.tex
│ └── 70000082.tex
├── 8
│ ├── 80000001.tex
│ ├── 80000002.tex
│ ├── 80000003.tex
│ └── 80000004.tex
├── .gitignore
├── Makefile
├── Makefile.include
├── README
├── aufgabensammlung.tex
├── buildchapter.sh
├── macros-uebungen.tex
├── macros
│ ├── content.tex
│ ├── front.tex
│ ├── packages.tex
│ ├── uebungen.tex
│ └── vorwort.tex
├── mkinclude
├── mkthemaidx.cpp
├── mkvkf.sh
├── ohnethema.sh
├── test.tex
├── testaufgabe.tex
├── themaliste.sh
├── vkf.csv
├── vkf.template
├── vkf
│ └── README
├── woche01.tex
├── woche02.tex
├── woche03.tex
├── woche04.tex
├── woche05.tex
├── woche06.tex
├── woche07.tex
├── woche08.tex
├── woche09.tex
├── woche10.tex
├── woche11.tex
└── woche12.tex
└── code
├── README
├── calculator
├── Makefile
├── README
├── phase1
│ ├── Makefile
│ ├── README
│ ├── calculator.c
│ ├── grammar.y
│ └── tokens.l
├── phase10
│ ├── Makefile
│ ├── README
│ ├── calculator.c
│ ├── constants.c
│ ├── constants.h
│ ├── grammar.y
│ └── tokens.l
├── phase11
│ ├── Makefile
│ ├── README
│ ├── calculator.c
│ ├── constants.c
│ ├── constants.h
│ ├── functions.c
│ ├── functions.h
│ ├── grammar.y
│ ├── help.c
│ ├── help.h
│ ├── tokens.l
│ ├── tree.c
│ └── tree.h
├── phase2
│ ├── Makefile
│ ├── README
│ ├── calculator.c
│ ├── grammar.y
│ └── tokens.l
├── phase3
│ ├── Makefile
│ ├── README
│ ├── calculator.c
│ ├── grammar.y
│ └── tokens.l
├── phase4
│ ├── Makefile
│ ├── README
│ ├── calculator.c
│ ├── grammar.y
│ └── tokens.l
├── phase5
│ ├── Makefile
│ ├── README
│ ├── calculator.c
│ ├── grammar.y
│ └── tokens.l
├── phase6
│ ├── Makefile
│ ├── README
│ ├── calculator.c
│ ├── grammar.y
│ └── tokens.l
├── phase7
│ ├── Makefile
│ ├── README
│ ├── calculator.c
│ ├── grammar.y
│ └── tokens.l
├── phase8
│ ├── Makefile
│ ├── README
│ ├── calculator.c
│ ├── constants.c
│ ├── constants.h
│ ├── grammar.y
│ └── tokens.l
└── phase9
│ ├── Makefile
│ ├── README
│ ├── calculator.c
│ ├── constants.c
│ ├── constants.h
│ ├── grammar.y
│ └── tokens.l
├── divisible
├── Makefile
├── count
├── d3.c
└── divisible.l
├── gvm
├── AUTHORS
├── ChangeLog
├── Makefile.am
├── NEWS
├── README
├── common
│ ├── Makefile.am
│ └── includes.h
├── configure.ac
├── configureit
├── doc
│ ├── Makefile.am
│ ├── assign.h
│ ├── beispiel.goto
│ ├── condgoto.h
│ ├── engine.h
│ ├── goto.h
│ ├── gvm.1
│ ├── gvm.tex
│ ├── node.h
│ ├── nodes.h
│ ├── parser.y
│ ├── parsergoto.y
│ ├── print.goto
│ ├── steuerung.goto
│ ├── tm.h
│ ├── tmc-beaver.tm
│ ├── tmc-command.goto
│ ├── tmc-initial.goto
│ ├── tmc-isolate.goto
│ ├── tmc-move.goto
│ ├── tmc-printtm.goto
│ ├── tmc-splice.goto
│ ├── tmc-state.goto
│ ├── tmc.1
│ └── vm.h
├── tmc
│ ├── Makefile.am
│ ├── data
│ │ ├── Makefile.am
│ │ ├── addtape
│ │ ├── addtape1
│ │ ├── addtape2
│ │ └── addtape3
│ ├── pgm
│ │ ├── Makefile.am
│ │ ├── add
│ │ ├── beaver3
│ │ ├── beaver4
│ │ └── beaver5
│ ├── tmc-grammar.y
│ ├── tmc-tokens.l
│ ├── tmc.c
│ └── tmc.h
└── vm
│ ├── Makefile.am
│ ├── grammar.y
│ ├── gvm.c
│ ├── gvm.h
│ ├── test.goto
│ ├── tokens.l
│ ├── utils.c
│ └── utils.h
├── manualpda
├── README
└── mpda.ps
├── minedemo
├── README
├── build.xml
├── ch
│ └── hsr
│ │ └── autospr
│ │ └── minesweeper
│ │ ├── BombActionListener.java
│ │ ├── IllegalStateException.java
│ │ ├── InconsistentConfigurationException.java
│ │ ├── Mine.java
│ │ ├── MineButton.java
│ │ ├── MineComponent.java
│ │ ├── MineFactory.java
│ │ ├── MineField.java
│ │ ├── MineLabel.java
│ │ ├── MineReader.java
│ │ ├── Mines.java
│ │ ├── Position.java
│ │ ├── ResetActionListener.java
│ │ └── Solver.java
├── resources
│ ├── marker.png
│ └── smBomb.png
├── runall
└── samples
│ ├── and.mines
│ ├── crossover.mines
│ ├── or.mines
│ ├── splitter.mines
│ ├── test.mines
│ ├── wire.mines
│ └── xor.mines
├── ragel
├── Makefile
├── teilbar.c
├── teilbar.dot
├── teilbar.pdf
├── teilbar.rl
├── teilbar_fsm.c
├── ungerade.c
├── ungerade.dot
├── ungerade.pdf
├── ungerade_minimized.dot
└── ungerade_minimized.pdf
├── regex
├── bash
│ └── regex.bash
├── c
│ ├── Makefile
│ └── regex.c
├── cpp
│ ├── Makefile
│ ├── main.cpp
│ ├── regex.cpp
│ └── regex.h
├── csharp
│ ├── Program.cs
│ ├── README
│ └── csharp.csproj
├── go
│ ├── README
│ └── regex.go
├── java
│ ├── README
│ ├── build.xml
│ └── ch
│ │ └── ost
│ │ └── autospr
│ │ ├── RegexMatcher.java
│ │ ├── StringMatcher.java
│ │ ├── matcher.java
│ │ ├── matcherfactory.java
│ │ └── regex.java
├── javascript
│ ├── regex.js
│ ├── regextest.html
│ └── regextest.js
├── mysql
│ └── regex_matcher.sql
├── perl
│ └── regex.pl
├── powershell
│ └── regex.ps1
├── python
│ ├── README.md
│ ├── regex_pypi.py
│ └── regex_stdlib.py
├── re2
│ ├── Makefile
│ └── regex.cpp
├── rust
│ ├── .gitignore
│ ├── Cargo.toml
│ ├── readme.md
│ └── src
│ │ └── main.rs
└── sh
│ └── regex.sh
└── turing
├── Makefile
├── README
├── data
├── addtape
├── addtape1
├── addtape2
├── addtape3
└── subtracttape
├── pgm
├── add
├── beaver3
├── beaver4
├── beaver5
└── subtract
└── turing.c
/.gitignore:
--------------------------------------------------------------------------------
1 | *.acn
2 | *.acr
3 | *.alg
4 | *.aux
5 | *.bbl
6 | *.blg
7 | *.dvi
8 | *.fdb_latexmk
9 | *.glg
10 | *.glo
11 | *.gls
12 | *.idx
13 | *.ilg
14 | *.ind
15 | *.ist
16 | *.lof
17 | *.log
18 | *.lot
19 | *.maf
20 | *.mtc
21 | *.mtc0
22 | *.nav
23 | *.nlo
24 | *.out
25 | *.pdf
26 | *.pdfsync
27 | *.ps
28 | *.snm
29 | *.synctex.gz
30 | *.toc
31 | *.vrb
32 | *.xdy
33 | *.tdo
34 | *.swp
35 | *.swo
36 | *.o
37 | Makefile.in
38 | skript/images/*.mpx
39 | skript/images/*.[0-9]
40 | skript/images/timestamp
41 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Creative Commons
2 |
3 | - by attribution: darf weiterverwendet werden, wenn urspruengliche
4 | Quelle genannt wird.
5 |
6 | - noncommercial: Kommerzielle Nutzung untersagt.
7 |
8 | Details:
9 |
10 | http://creativecommons.org/licenses/by-nc/3.0/legalcode
11 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | Materialien zur Vorlesung Automaten und Sprachen
2 | an der OST Ostscheizer Fachhochschule, Campus Rapperswil
3 |
4 | Die Unterverzeichnisse enthalten die folgenden, von einander unabhaengigen
5 | Teile:
6 |
7 | aufgaben Eine Sammlung von Aufgaben, entstanden aus Uebungsaufgaben und
8 | Pruefungen frueherer Jahre
9 |
10 | code Beispiele von Anwendungen der Theorie. Dieser Code findet sich
11 | auch auf https://autospr.ch/code
12 |
13 | Vor dem Erscheinen des Buches "Automaten und Sprachen: Theoretische
14 | Informatik für die Praxis" enthielt dieses Modul auch das Skript zur
15 | Vorlesung.
16 |
17 | Aufgabensammlung
18 | ----------------
19 |
20 | Im Verzeichnis "aufgaben" wurde eine Aufgabensammlung aufgebaut. Die
21 | Aufgaben sind nach Kapiteln geordnet und so organisiert, dass die Aufgaben
22 | zusammen mit den Musterloesungen leicht aus anderen Projekten referenziert
23 | werden koennen. Falls eine Aufgabe oder ihre Loesung zusaetzliche Files
24 | benoetig, sind diese Files in einem Verzeichnis mit der gleichen Nummer
25 | abgelegt.
26 |
27 | Code
28 | ----
29 |
30 | Im Unterverzeichnis "code" befindet sich ein Reihe kleiner
31 | Beispielprojekte, welche die Anwendung der Theorie des Skriptes
32 | illustrieren. Eine kurze Beschreibung der Projekte findet man in
33 | code/README.
34 |
35 |
--------------------------------------------------------------------------------
/aufgaben/.gitignore:
--------------------------------------------------------------------------------
1 | vkf.tex
2 | thema.tex
3 | work
4 | mkthemaidx
5 |
--------------------------------------------------------------------------------
/aufgaben/1/10000001.tex:
--------------------------------------------------------------------------------
1 | Übersetzen Sie die folgenden Aussagen soweit möglich in
2 | logische Formeln (Sie müssen die Aussagen selbst nicht beweisen).
3 | \begin{teilaufgaben}
4 | \item Eine Aussage (nennen Sie diese $P$) ist entweder wahr oder falsch.
5 | \item Jede reelle Zahl ist entweder positiv, negativ oder $0$.
6 | \item Negative (reelle) Zahlen haben keine reellen Wurzeln.
7 | \end{teilaufgaben}
8 |
9 | \thema{Logik}
10 |
11 | \begin{loesung}
12 | \begin{teilaufgaben}
13 | \item Wenn die Aussage $P$ heisst: $P\vee\neg P$.
14 | Man könnte argumentieren, dass damit noch nicht ausgedrückt ist,
15 | dass mit ``entweder\dots oder'' ein ausschliessendes Oder formuliert
16 | worden ist. Dazu müsse man mit einer Und-Verknüfpung den Termen
17 | $\neg(P\wedge \neg P)$
18 | hinzufügen. Aber
19 | $\neg(P\wedge \neg P)=\neg P\vee \neg\neg P=\neg P\vee P=P\vee\neg P$,
20 | dieser Zusatzterm ist also genau dann wahr, wenn der ursprüngliche
21 | auch wahr war, bereits $P\vee \neg P$ beinhaltet also ein ausschliessendes
22 | Oder.
23 | \item $\forall x\in\mathbb R(x > 0\vee x<0\vee x=0)$
24 | \item $x\in\mathbb R\wedge x < 0\Rightarrow
25 | \neg\exists w\in\mathbb R(x=w^2)$
26 | oder mit einem All-Quantor: $\forall x\in\mathbb R(x<0\Rightarrow
27 | \neg\exists w\in\mathbb R(x=w^2))$
28 | \qedhere
29 | \end{teilaufgaben}
30 | \end{loesung}
31 |
32 |
--------------------------------------------------------------------------------
/aufgaben/1/10000002.tex:
--------------------------------------------------------------------------------
1 | Übersetzen Sie die folgenden logischen Formeln in deutsche Sätze:
2 | \begin{teilaufgaben}
3 | \item $\exists m\in\mathbb N (n=2m)$
4 | \item $\exists m\in\mathbb N (n=2m)\Rightarrow (-1)^n > 0$
5 | \item $\neg(x\in\mathbb R_{>0})\vee \exists w\in\mathbb R(x=w^2)$
6 | \end{teilaufgaben}
7 |
8 | \thema{Logik}
9 |
10 | \begin{loesung}
11 | \begin{teilaufgaben}
12 | \item $n$ ist eine gerade Zahl.
13 | \item Eine gerade Potenz von $-1$ ist positiv.
14 | \item $\neg (x\in\mathbb R_{>0})\vee \exists w\in\mathbb R(x=w^2)$ wird zunächst
15 | übersetzt in
16 | $x\in\mathbb R_{>0}\Rightarrow \exists w\in\mathbb R(x=w^2)$, was man lesen
17 | kann als: wenn $x$ eine positive reelle Zahl ist, dann hat $x$ eine
18 | Quadratwurzel.
19 | \qedhere
20 | \end{teilaufgaben}
21 | \end{loesung}
22 |
23 |
--------------------------------------------------------------------------------
/aufgaben/1/10000003.tex:
--------------------------------------------------------------------------------
1 | Was ist falsch am folgenden Beweis für $2=1$?
2 |
3 | Betrachte die Gleichung $a=b$. Multipliziere beide Seiten mit
4 | $a$ um $a^2=ab$ zu erhalten. Subtrahiere $b^2$ auf beiden
5 | Seiten, was $a^2-b^2=ab-b^2$ ergibt. Beide Seiten kann man
6 | faktorisieren und bekommt $(a+b)(a-b)=b(a-b)$. Teile beide
7 | Seiten durch $a-b$, dies ergibt $a+b=b$. Jetzt setzt man
8 | $a=1$ und $b=1$, und es ergibt sich $2=1$.
9 |
10 | \thema{Beweis}
11 |
12 | \begin{loesung}
13 | Im Laufe des Beweises wird durch $(a-b)$ geteilt, ohne dass man
14 | sicherstellt, dass dies auch tatsächlich möglich ist.
15 | Tatsächlich wurde sogar davon ausgegangen, dass $a=b$, dass
16 | also in jedem Fall $a-b=0$ ist, die Division ist also unabhängig davon,
17 | was man später einsetzt, nicht zulässig.
18 | Für die
19 | gewählten Werte $a=1$ und $b=1$ ist erst recht $a-b=0$.
20 | \end{loesung}
21 |
22 |
--------------------------------------------------------------------------------
/aufgaben/1/10000005.tex:
--------------------------------------------------------------------------------
1 | Der Grad eines Vertex ist die Zahl der Kanten, die im Vertex enden.
2 | Zeigen Sie, dass die Summe der Grade aller Vertices eines Graphen
3 | eine gerade Zahl ist.
4 |
5 | \thema{Grad eines Vertex}
6 | \thema{Graph}
7 |
8 | \begin{loesung}
9 | Entfernt man aus dem Graphen Kante für Kante, dann wird die
10 | Summe der Grade in jedem Schritt um zwei kleiner. Sie ändert
11 | dabei also ihren Rest bei Teilung durch zwei nicht. Wenn alle
12 | Kanten entfernt sind, sind auch alle Grade 0, die Summe der
13 | Grade ist also gerade. Daher muss die ursprüngliche Summe der
14 | Grade auch gerade gewesen sein.
15 |
16 | Wir können diesen konstruktiven Beweis auch induktiv formulieren.
17 | Dazu zeigen wir, dass die Summe der Grade aller Vertices eines Graphen
18 | mit $n$ Kanten $2n$ ist. Für einen Graphen ohne Kanten ist dies
19 | sicher richtig, dies ist die Induktionsverankerung. Nehmen wir
20 | jetzt an, dass die Behauptung für einen Graphen mit $n$ Kanten
21 | richtig ist. Sei jetzt $G$ ein Graph mit $n+1$ Kanten. Wir können
22 | eine Kante entfernen und erhalten einen Graphen $G_1$ mit $n$
23 | Kanten, für den natürlich die Induktionsannahme gilt. Die Summe
24 | der Grade ist also $2n$. Fügen wir jetzt die Kante wieder hinzu,
25 | wird der Grad von Anfangs- und Endpunkt der Kante um genau $1$
26 | zunehmen, die Summe der Grade von $G$ ist also $2n+2=2(n+1)$,
27 | was die Behauptung für $n+1$ beweist.
28 | \end{loesung}
29 |
30 |
--------------------------------------------------------------------------------
/aufgaben/1/10000006.tex:
--------------------------------------------------------------------------------
1 | Betrachten Sie die Behauptung:
2 | \begin{quote}
3 | In einem Graphen mit mindestens zwei Knoten gibt es zwei verschiedene Knoten
4 | mit dem gleichen Grade (der gleichen Anzahl Kanten, die von diesem
5 | Knoten ausgehen).
6 | \end{quote}
7 | Ist die Behauptung wahr oder falsch? Warum (Beweis
8 | oder Gegenbeispiel)?
9 |
10 | \begin{hinweis}
11 | Gehen Sie von einem zusammenhängenden Graphen
12 | aus, und überlegen sie sich, welche Grade möglich sind.
13 | \end{hinweis}
14 |
15 | \thema{Graph}
16 | \thema{Grad eines Vertex}
17 |
18 | \begin{loesung}
19 | Die Behauptung ist wahr.
20 |
21 | In einem zusammenhängenden Graphen mit $n$
22 | Ecken kann der Grad einer Ecke nicht grösser als $n-1$ sein.
23 | Möglich sind also nur die $n-1$ verschiedenen Grade
24 | $1,2,\dots,n-1$. Daher müssen zwei Ecken den gleichen Grad
25 | haben.
26 |
27 | Falls der Graph nicht zusammenhängend ist, nimmt man eine
28 | Zusammenhangskomponente mit mindestens zwei Ecken, nach dem
29 | eben bewiesenen muss diese zwei Ecken mit dem gleichen
30 | Grad haben.
31 |
32 | Falls es keine Zusammenhangskomponente mit mit mindestens
33 | zwei Ecken gibt, besteht der Graph nur aus Vertices und hat
34 | kein Kanten, also haben alle Vertices den Grad $0$, auch
35 | in diesem Fall ist die Aussage also richtig.
36 | \end{loesung}
37 |
--------------------------------------------------------------------------------
/aufgaben/1/10000008/README:
--------------------------------------------------------------------------------
1 | https://mathematicsart.com/solved-exercises/derivative-of-x-squared-and-derivative-of-sumx-x-times/
2 |
--------------------------------------------------------------------------------
/aufgaben/1/10000008/meme.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/1/10000008/meme.png
--------------------------------------------------------------------------------
/aufgaben/1/10000009.tex:
--------------------------------------------------------------------------------
1 | Beweisen Sie mit vollständiger Induktion
2 | \[
3 | \sum_{k=1}^n k^2
4 | =
5 | \frac{n(n+1)(2n+1)}{6}.
6 | \]
7 |
8 | \begin{loesung}
9 | {\bf Induktionsverankerung:} n=0, klar.
10 | \\
11 | {\bf Induktionsannahme:} Formel gilt für $n$.
12 | \\
13 | {\bf Induktionsschritt:} Nachweis für $\color{red}n+1$:
14 | \begin{align*}
15 | \sum_{k=1}^{{\color{red}n+1}} k^2
16 | &=
17 | \sum_{k=1}^n k^2
18 | +
19 | (n+1)^2
20 | =
21 | \frac{n({\color{red}n+1})(2n+1)}{6}+\frac{{\color{red}n+1}}{6}(6n+6)
22 | \\
23 | &
24 | =
25 | \frac{{\color{red}n+1}}{6}\bigl(
26 | 2n^2+n+6n+6
27 | \bigr)
28 | =
29 | \frac{{\color{red}n+1}}{6}\bigl(
30 | 2n^2+7n+6
31 | \bigr)
32 | \\
33 | &=
34 | \frac{{\color{red}n+1}}{6}
35 | (2n+3)(n+2)
36 | =
37 | \frac{{\color{red}n+1}}{6}(2({\color{red}n+1})+1)({\color{red}n+1}+1).
38 | \end{align*}
39 | Dies ist die Formel für die Summe mit $n$ ersetzt durch $\color{red}n+1$.
40 | \end{loesung}
41 |
--------------------------------------------------------------------------------
/aufgaben/1/10000011.tex:
--------------------------------------------------------------------------------
1 | Zeichnen Sie den Graphen
2 | \begin{align*}
3 | V &= \{ A, B, C, D, E \}
4 | \\
5 | E &= \{
6 | \{A,B\},
7 | \{A,C\},
8 | \{B,C\},
9 | \{B,D\},
10 | \{C,E\},
11 | \{D,E\}
12 | \}.
13 | \end{align*}
14 |
15 | \begin{loesung}
16 | Da die Kanten Mengen sind, ist dies ein ungerichteter Graph:
17 | \begin{center}
18 | \begin{tikzpicture}[>=latex,thick]
19 | \coordinate (A) at (0,{sqrt(3)});
20 | \coordinate (B) at (-1,0);
21 | \coordinate (C) at (1,0);
22 | \coordinate (D) at (-1,-2);
23 | \coordinate (E) at (1,-2);
24 | \draw[shorten >= 0.3cm,shorten <= 0.3cm] (A) -- (B);
25 | \draw[shorten >= 0.3cm,shorten <= 0.3cm] (A) -- (C);
26 | \draw[shorten >= 0.3cm,shorten <= 0.3cm] (B) -- (C);
27 | \draw[shorten >= 0.3cm,shorten <= 0.3cm] (B) -- (D);
28 | \draw[shorten >= 0.3cm,shorten <= 0.3cm] (C) -- (E);
29 | \draw[shorten >= 0.3cm,shorten <= 0.3cm] (D) -- (E);
30 | \draw (A) circle[radius=0.3];
31 | \draw (B) circle[radius=0.3];
32 | \draw (C) circle[radius=0.3];
33 | \draw (D) circle[radius=0.3];
34 | \draw (E) circle[radius=0.3];
35 | \node at (A) {$A\mathstrut$};
36 | \node at (B) {$B\mathstrut$};
37 | \node at (C) {$C\mathstrut$};
38 | \node at (D) {$D\mathstrut$};
39 | \node at (E) {$E\mathstrut$};
40 | \end{tikzpicture}
41 | \end{center}
42 | \end{loesung}
43 |
--------------------------------------------------------------------------------
/aufgaben/1/10000013.tex:
--------------------------------------------------------------------------------
1 | Bringen Sie die Formel
2 | \[
3 | \varphi
4 | =
5 | ((x\wedge y) \vee z) \wedge t
6 | \]
7 | in a) konjunktive und b) disjunktive Normalform.
8 |
9 | \begin{loesung}
10 | \begin{teilaufgaben}
11 | \item Konjunktive Normalform: UND von ODER-Termen
12 | \begin{align*}
13 | \varphi
14 | &=
15 | ((x\vee z)\wedge (y\vee z)) \wedge t
16 | =
17 | (x\vee z) \wedge (y\vee z) \wedge t.
18 | \end{align*}
19 | \item Disjunktive Normalform: ODER von UND-Termen
20 | \begin{align*}
21 | \varphi
22 | &=
23 | ((x\wedge y)\wedge t)\vee(z\wedge t)
24 | =
25 | (x\wedge y \wedge t) \vee (z\wedge t).
26 | \qedhere
27 | \end{align*}
28 | \end{teilaufgaben}
29 | \end{loesung}
30 |
--------------------------------------------------------------------------------
/aufgaben/1/10000014.tex:
--------------------------------------------------------------------------------
1 | Schreiben Sie die folgenden, in aufzählender Form gegebenen Mengen mit
2 | Hilfe eines Prädikates.
3 | \begin{teilaufgaben}
4 | \item
5 | $A=\{1,3,5,7,9,\dots\}$
6 | \item
7 | $B=\{1,4,7,10,13,16,\dots\}$
8 | \item
9 | $C=\{10,11,\dots,99,1000,1001,\dots,9999,100000,100001,\dots\}$
10 | \end{teilaufgaben}
11 |
12 | \begin{loesung}
13 | \begin{teilaufgaben}
14 | \item
15 | $A=\{2n+1\mid n\in\mathbb{N}\}.$
16 | \item
17 | $B=\{ n\in\mathbb{N}\mid n\equiv 1\mod 3\}.$
18 | \item
19 | $C=\{n\in\mathbb{N}\mid \text{$n$ hat eine gerade Anzahl Stellen}\}.$
20 | \qedhere
21 | \end{teilaufgaben}
22 | \end{loesung}
23 |
--------------------------------------------------------------------------------
/aufgaben/1/10000017.tex:
--------------------------------------------------------------------------------
1 | Beweisen Sie die folgende Behauptung mit Hilfe eines Widerspruchsbeweises:
2 | \begin{quote}
3 | Wenn für eine natürliche Zahl $n$ die Zahl $n^3+5$ ungerade ist, dann ist
4 | $n$ gerade.
5 | \end{quote}
6 |
7 | \begin{loesung}
8 | Die zu beweisende Aussage $A$ ist ``$n$ ist gerade''.
9 | Wir nehmen daher das logische Gegenteil an, also
10 | dass $n$ ungerade ist.
11 | Dann ist auch $n^3$ ungerade.
12 | Weil $5$ ungerade ist, ist $n^3+5$ gerade, im Widerspruch zur Annahme
13 | der Behauptung.
14 | Damit ist die Behauptung bewiesen.
15 | \end{loesung}
16 |
--------------------------------------------------------------------------------
/aufgaben/2/20000001.tex:
--------------------------------------------------------------------------------
1 | Wieviele Sprachen mit leerem Alphabet gibt es?
2 |
3 | \thema{Sprache}
4 |
5 | \begin{loesung}
6 | Nirgends in der Definition einer Sprache wird verlangt, dass das
7 | Alphabet einer Sprache nicht leer sein darf. Eine Sprache mit leerem
8 | Alphabet kann aber natürlich nur leer sein oder nur das leere Wort
9 | enthalten. Die einzigen Sprachen mit leerem Alphabet $\Sigma=\emptyset$
10 | sind also
11 | \begin{align*}
12 | L_0&=\emptyset& L_1=\Sigma^0=\{\varepsilon\}.
13 | \end{align*}
14 | Es gibt genau zwei Sprachen mit leerem Alphabet, die leere Sprache ohne
15 | ein Wort, und die Sprache mit nur einem, nämlich dem leeren Wort.
16 | \end{loesung}
17 |
--------------------------------------------------------------------------------
/aufgaben/2/20000005.tex:
--------------------------------------------------------------------------------
1 | Sei $\Sigma = \{\texttt{0},\texttt{1}\}$ das Alphabet, schreiben
2 | Sie $\Sigma^*$ in aufzählender Form.
3 |
4 | \thema{Sprache}
5 |
6 | \begin{loesung}
7 | \begin{align*}
8 | \Sigma^*
9 | &=
10 | \{\varepsilon, \texttt{0}, \texttt{1},
11 | \texttt{00}, \texttt{01}, \texttt{10}, \texttt{11},
12 | \texttt{000},
13 | \texttt{001},
14 | \texttt{010},
15 | \texttt{011},
16 | \texttt{100},
17 | \texttt{101},
18 | \texttt{110},
19 | \texttt{111},
20 | \texttt{0000},
21 | \dots
22 | \}
23 | \end{align*}
24 | \end{loesung}
25 |
--------------------------------------------------------------------------------
/aufgaben/2/20000006.tex:
--------------------------------------------------------------------------------
1 | Sei $\Sigma=\{\texttt{0},\texttt{1}\}$, schreiben Sie die Menge
2 | \[
3 | L
4 | =
5 | \{w\in\Sigma^*\mid |w|_{\texttt{0}} = 2\}
6 | \]
7 | in aufzählender Form.
8 |
9 | \thema{Sprache}
10 |
11 | \begin{loesung}
12 | $L$ besteht aus Wörtern, die genau zwei Nullen enthalten:
13 | \begin{align*}
14 | L
15 | &=\{
16 | \texttt{00},\\
17 | &\phantom{=\{}
18 | \texttt{100},
19 | \texttt{010},
20 | \texttt{001},\\
21 | &\phantom{=\{}
22 | \texttt{1100},
23 | \texttt{1010},
24 | \texttt{1001},
25 | \texttt{0110},
26 | \texttt{0101},
27 | \texttt{0011},\\
28 | &\qquad\dots\}
29 | \end{align*}
30 | \end{loesung}
31 |
--------------------------------------------------------------------------------
/aufgaben/3/30000005.tex:
--------------------------------------------------------------------------------
1 | Gegeben sei ein deterministischer endlicher Automat $A=(Q,\Sigma, \delta,
2 | z_0, F)$ mit $|Q|=|F|$. Wieviele Zustände enthält der minimale Automat?
3 |
4 | \thema{DEA}
5 | \thema{minimaler Automat}
6 |
7 | \begin{loesung}
8 | Da $Q$ and $F$ endliche Mengen sind folgt aus $|Q|=|F|$, dass $Q=F$.
9 | Alle Zustände sind also Akzeptierzustände. Im Algorithmus zur Bestimmung
10 | des Minimalautomaten können daher schon im ersten Schritt überhaupt
11 | keine Zustände als äquivalent markiert werden, also erst recht nicht
12 | in späteren Schritten.
13 |
14 | Alternativ kann man auch argumentieren, dass von jedem Zustand $z$ aus
15 | $$L(z)=\Sigma^*,$$
16 | also
17 | $$L(z)=L(z'),$$
18 | d.~h.~die Zustände sind äquivalent.
19 |
20 | Oder man kann sagen, dass dieser Automat, da er nur Akzeptierzustände
21 | besitzt, notwendigerweise alle Wörter akzeptieren muss. $L(A)=\Sigma^*$,
22 | der minimale Automat, der $\Sigma^*$ akzeptiert, ist aber
23 | \[
24 | \entrymodifiers={++[o][F]}
25 | \xymatrix @-1mm {
26 | *+\txt{} \ar[r]
27 | &*++[o][F=]{}\ar@(ur,dr)^{\Sigma}
28 | }
29 | \]
30 | Dieser Automat hat offensichtlich nur einen Zustand.
31 | \end{loesung}
32 |
33 |
--------------------------------------------------------------------------------
/aufgaben/3/30000010.tex:
--------------------------------------------------------------------------------
1 | Sei $L$ eine reguläre Sprache über dem Alphabet $\Sigma$.
2 | Zeigen Sie, dass die folgenden Sprachen auch regulär sind:
3 | \begin{teilaufgaben}
4 | \item $\operatorname{Rest}(L)=\{v \in\Sigma^*\mid v=ax, a\in\Sigma, x\in L\}$
5 | \item $\operatorname{First}(L)=\{v \in\Sigma^*\mid v=xa, a\in\Sigma, x\in L\}$
6 | \end{teilaufgaben}
7 |
8 | \themaL{regulare Ausdrucke}{reguläre Ausdrücke}
9 | \themaL{regulare Sprache}{reguläre Sprache}
10 |
11 | \begin{loesung}
12 | \begin{teilaufgaben}
13 | \item Da $L$ regulär ist, gibt es einen regulären Ausdruck $r$ mit
14 | $L(r)=L$. Dann ist $.r$ ein regulärer Ausdruck, der
15 | $\operatorname{Rest}(L)=L(.r)$ akzeptiert.
16 | Also ist
17 | $\operatorname{Rest}(L)$ regulär.
18 | \item Da $L$ regulär ist, gibt es einen regulären Ausdruck $r$ mit
19 | $L(r)=L$. Dann ist $r.$ ein regulärer Ausdruck, der
20 | $\operatorname{First}(L)=L(r.)$ akzeptiert. Also ist
21 | $\operatorname{First}(L)$ regulär.
22 | \qedhere
23 | \end{teilaufgaben}
24 | \end{loesung}
25 |
26 |
--------------------------------------------------------------------------------
/aufgaben/3/30000012.tex:
--------------------------------------------------------------------------------
1 | Das Pumping Lemma liefert zu jeder regulären Sprache die Pumping length.
2 | Bestimmen Sie die kleinstmögliche Pumping length für die folgenden
3 | durch reguläre Ausdrücke definierten Sprachen.
4 | \begin{teilaufgaben}
5 | \item ${\tt 0001}^*$
6 | \item $({\tt 01})^*$
7 | \item ${\tt 1011}$
8 | \item ${\tt 1}^*{\tt 01}^*{\tt 01}^*$
9 | \end{teilaufgaben}
10 |
11 | \themaL{Pumping Lemma fur regulare Sprachen}{Pumping Lemma für reguläre Sprachen}
12 | \thema{Pumping length}
13 |
14 | \begin{loesung}
15 | \begin{teilaufgaben}
16 | \item Wörter mit mindestens vier Zeichen können aufgepumpt werden,
17 | $N=4$.
18 | \item Wörter mit mindestens zwei Zeichen können aufgepumpt werden,
19 | $N=2$.
20 | \item Da nur ein einziges Wort vorhanden ist, muss die Pumping length
21 | so gross sein, dass dieses Wort nicht unter die Anwendbarkeit des
22 | Pumping Lemmas fällt, also $N=5$.
23 | \item Damit ein Wort aufgepumpt werden kann, muss es mindestens eine
24 | {\tt 1} enthalten. Dies ist erst garantiert, wenn das Wort mindestens
25 | drei Zeichen hat. Also $N=3$
26 | \qedhere
27 | \end{teilaufgaben}
28 | \end{loesung}
29 |
--------------------------------------------------------------------------------
/aufgaben/3/30000013/beispiel.csv:
--------------------------------------------------------------------------------
1 | "Name","Vorname","Jahrgang","Geburtsort"
2 | "Kirk","James T.","2233","Riverside, Iowa"
3 | "Spock",,,"Vulcan"
4 | "Scott","Montgomery ""Scotty""","2222","Linlithgow"
5 |
--------------------------------------------------------------------------------
/aufgaben/3/30000015/aufg1a.lsg:
--------------------------------------------------------------------------------
1 | ( *[a-zA-Z0-9._]* *, *[a-zA-Z0-9._]* *, *[a-zA-Z0-9._] *)
2 |
--------------------------------------------------------------------------------
/aufgaben/3/30000015/aufg1b.lsg:
--------------------------------------------------------------------------------
1 | ( *, *, *)
2 |
--------------------------------------------------------------------------------
/aufgaben/3/30000016.tex:
--------------------------------------------------------------------------------
1 | Sei $\Sigma=\{0,1\}$.
2 | Wir sagen, ein Wort in $\Sigma^*$ sei ``wachsend'',
3 | wenn auf jede Folge von Nullen eine mindestens
4 | so lange Folge von Einsen folgt.
5 | Betrachten Sie die Sprache
6 | \[
7 | L=\{
8 | w\in \Sigma^*\,|\, \text{$w$ ist wachsend}
9 | \}
10 | \]
11 | Ist $L$ regulär?
12 |
13 | \themaL{regular}{regulär}
14 | \themaL{Pumping Lemma fur regulare Sprachen}{Pumping Lemma für reguläre Sprachen}
15 |
16 | \begin{loesung}
17 | $L$ ist nicht regulär, wie man mit dem Pumping-Lemma beweisen kann.
18 | Dazu nimmt man an, $L$ sei regulär. Das Pumping-Lemma garantiert, dass
19 | es eine Zahl $N$ gibt, die Pumping-Length, so dass Wörter mit grösserer
20 | Länge aufgepumpt werden können. Das Wort $0^N1^N$ ist wachsend, denn
21 | auf die Folge von $N$ Nullen folgen $N\ge N$ Einsen. Nach dem Pumping-Lemma
22 | kann $w=xyz$ geschrieben werden, mit $|xy|\le N$ und $|y|>0$. Insbesondere bestehen
23 | $x$ und $y$ ausschliesslich aus Nullen. Das aufgepumpte Wort
24 | $xy^kz$ besteht also aus $N+|y|(k-1)$ Nullen, gefolgt von $N$ Einsen.
25 | Da $N+|y|(k-1) > N$ für $k>1$, ist das aufgepumpte Wort nicht nicht
26 | mehr wachsend, im Widerspruch zur Behauptung des Pumping-Lemmas. Der
27 | Widersprucht zeigt, dass die Voraussetzung nicht zutreffen kann, $L$
28 | ist also nicht regulär.
29 | \end{loesung}
30 |
--------------------------------------------------------------------------------
/aufgaben/3/30000017.tex:
--------------------------------------------------------------------------------
1 | Ein Wort über dem Alphabet $\Sigma=\{0,1\}$ heisst
2 | 3-periodisch, wenn es nur aus Wiederholungen der ersten drei Zeichen besteht,
3 | also zum Beispiel
4 | \[
5 | \text{\tt 011011011},\quad
6 | \text{\tt 100100100},\quad
7 | \text{\tt 101101},\quad
8 | \text{\tt 111},
9 | \]
10 | nicht aber
11 | \[
12 | \text{\tt 00},\quad
13 | \text{\tt 1001},\quad
14 | \text{\tt 101100},\quad
15 | \text{\tt 111000}.
16 | \]
17 | Ist die Sprache $L$ der 3-periodischen Wörter regulär?
18 |
19 | \themaL{regular}{regulär}
20 | \themaL{regulare Ausdrucke}{reguläre Ausdrücke}
21 |
22 | \begin{loesung}
23 | Ja, denn der reguläre Ausdruck
24 | \[
25 | r=(000)^*|
26 | (001)^*|
27 | (010)^*|
28 | (011)^*|
29 | (100)^*|
30 | (101)^*|
31 | (110)^*|
32 | (111)^*
33 | \]
34 | akzeptiert die Sprache: $L=L(r)$.
35 | \end{loesung}
36 |
--------------------------------------------------------------------------------
/aufgaben/3/30000030.tex:
--------------------------------------------------------------------------------
1 | Verwenden Sie das Pumping Lemma um zu zeigen, dass die folgenden
2 | Sprachen nicht regulär sind:
3 | \begin{teilaufgaben}
4 | \item $\Sigma=\{{\tt 0},{\tt 1},{\tt 2}\}$ und $L=\{ 0^n1^n2^n |n\ge 0\}$.
5 | \item $\Sigma=\{{\tt a},{\tt b}\}$ und $L=\{ww|w\in \Sigma^*\}$.
6 | \item $\Sigma=\{{\tt a}\}$, und $L=\{{\tt a}^{2^n}|n\ge 0\}$.
7 | \end{teilaufgaben}
8 |
9 | \themaL{regular}{regulär}
10 | \themaL{Pumping Lemma fur regulare Sprachen}{Pumping Lemma für reguläre Sprachen}
11 |
12 | \begin{loesung}
13 | In allen Teilaufgaben ist der entscheidende Schritt, zur Pumping Length
14 | $N$ ein passendes Wort zu wählen, welches nicht aufgepumpt werden kann.
15 | \begin{teilaufgaben}
16 | \item $0^N1^N2^N$ kann nicht aufgepumpt werden, Argument analog zur
17 | $0^n1^n$ (in der Vorlesung behandelt).
18 | \item ${\tt a}^N{\tt ba}^N{\tt b}\in L$ kann nicht aufgepumpt werden,
19 | weil dadurch die Zahl der {\tt a} vor dem ersten {\tt b}, zunimmt,
20 | nicht aber die Zahl der {\tt a} nach dem ersten {\tt b}.
21 | \item
22 | Sei $n$ die kleinste Zahl, für die $2^n\ge N$. Wähle $w=0^{2^n}$.
23 | Beim Aufpumpen wird das aufgepumpte Wort $ux^kv$ Länge $2^n+k|x|$
24 | haben. Gemäss Pumping Lemma müssten dies alles Zweierpotenzen sein,
25 | was offensichtlich nicht sein kann.
26 | \qedhere
27 | \end{teilaufgaben}
28 | \end{loesung}
29 |
30 |
--------------------------------------------------------------------------------
/aufgaben/3/30000033.tex:
--------------------------------------------------------------------------------
1 | Zeigen Sie: Das Komplement einer nicht regulären Sprache ist nicht
2 | regulär.
3 |
4 | \themaL{Mengenoperationen fur regulare Sprachen}{Mengenoperationen für reguläre Sprachen}
5 | \themaL{regular}{regulär}
6 |
7 | \begin{loesung}
8 | Die Sprache $L$ sei nicht regulär. Dann kann $\bar L$ nur
9 | entweder regulär sein, oder nicht regulär. Wenn $\bar L$
10 | regulär wäre, dann müsste das das Komplement davon
11 | auch regulär sein, also $\bar{\bar L}=L$ müsste regulär sein.
12 | Dies kann also nicht sein, es bleibt also nur noch die Alternative,
13 | dass $\bar L$ nicht regulär ist.
14 | \end{loesung}
15 |
--------------------------------------------------------------------------------
/aufgaben/3/30000044/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile -- example program to illustrate how to build good regex
3 | #
4 | # (c) 2015 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | #
6 | all: part part.c.expanded
7 |
8 | part: part.c
9 | gcc -o part -Wall -g -O2 part.c
10 |
11 | part.c.expanded: part.c
12 | expand part.c > part.c.expanded
13 |
14 | test: part
15 | ./part < testdata
16 |
--------------------------------------------------------------------------------
/aufgaben/3/30000044/testdata:
--------------------------------------------------------------------------------
1 | 42
2 | x43
3 | xxx
4 | 34x
5 |
--------------------------------------------------------------------------------
/aufgaben/3/30000050.tex:
--------------------------------------------------------------------------------
1 | Ist die Sprache
2 | \[
3 | L=\{w\in\{\texttt{1}\}^*\mid\text{$|w|$ ist prim}\}
4 | \]
5 | regulär?
6 |
7 | \themaL{Pumping Lemma fur regulare Sprachen}{Pumping Lemma für reguläre Sprachen}
8 | \themaL{regular}{regulär}
9 |
10 | \begin{loesung}
11 | Nein, wie wir mit dem Pumping Lemma zeigen können.
12 | Dazu nehmen wir an, die Sprache $L$ sei regulär.
13 | Nach dem Pumping Lemma gibt es daher die Pumping Length $N$, Wörter
14 | mit Länge mindestens $N$ haben die Pump-Eigenschaft.
15 | Sei also
16 | \[
17 | w=\texttt{1}^p\qquad\text{mit einer Primzahl $p\ge N$},
18 | \]
19 | so eine Primzahl $p$ gibt es, weil es unendlich viele Primzahlen gibt.
20 | Nach dem Pumping Lemma gibt es jetzt eine Unterteilung $w=xyz$, wobei
21 | $|y|>0$, mit der Eigenschaft, dass auch alle aufgepumpten Wörter
22 | $xy^kz$ in $L$ sind, d.~h.~prime Länge haben.
23 | Wenn man aber genau mit $k=p+1$ pumpt, erhält man als Länge
24 | \[
25 | |xy^kz|
26 | =
27 | |x| + k|y| + |z|
28 | =
29 | |x| + (p+1)|y| + |z|
30 | =
31 | p|y| + \underbrace{|x|+|y|+|z|}_{\textstyle=p}
32 | =
33 | p(|y|+1)
34 | \]
35 | Die Länge von $xy^{(p+1)}z$ ist daher durch $p$ und $|y|+1$ teilbar, kann also
36 | keine Primzahl sein, $xy^{(p+1)}z\not\in L$.
37 | Dieser Widerspruch zeigt, dass die Annahme, $L$ sei regulär, nicht
38 | aufrecht erhalten werden kann.
39 | \end{loesung}
40 |
41 |
42 |
--------------------------------------------------------------------------------
/aufgaben/3/30000059.tex:
--------------------------------------------------------------------------------
1 | Sei $\Sigma=\{\texttt{1}\}$ und die Sprache $L$ über dem Alphabet $\Sigma$
2 | bestehe aus Wörtern, deren Länge eine Fakultät ist:
3 | \[
4 | L=\{
5 | a^{k!}\,|\, k\in \mathbb N
6 | \}.
7 | \]
8 | Ist $L$ regulär?
9 |
10 | \themaL{regular}{regulär}
11 | \themaL{Pumping Lemma fur regulare Sprachen}{Pumping Lemma für reguläre Sprachen}
12 |
13 | \begin{loesung}
14 | Nein, wie man mit dem Pumping-Lemma beweisen kann.
15 | Dazu nehmen wir an, dass $L$ regulär ist.
16 | Sei $N$ die Pumping length von $L$ und $k$ die kleinste ganze Zahl
17 | derart, dass $k!>N$ ist.
18 | Dann ist das Wort
19 | \[
20 | w=\texttt{1}^{k!} \in L.
21 | \]
22 | Nach dem Pumping Lemma lässt sich $w$ in drei Teile $w=xyz$ aufteilen
23 | derart, dass $|y|>0$ und $xy^rz\in L$ für jedes $r$.
24 | Nun ist aber $|y|\le k!$ und damit $|xy^2z|\le k!\cdot 2 < k!\cdot (k+1) = (k+1)!$,
25 | das Wort $xy^2z$ ist also nicht das Wort $\texttt{1}^{k!}$ und ausserdem
26 | ist es zu kurz,
27 | um $\texttt{1}^{(k+1)!}$ zu sein, es kann daher nicht in $L$ sein,
28 | im Widerspruch zur Aussage des Pumping-Lemmas.
29 | Dieser Widerspruch zeigt, dass $L$ nicht regulär sein kann.
30 | \end{loesung}
31 |
32 | \begin{bewertung}
33 | Pumping Lemma ({\bf PL}) 1 Punkt,
34 | Pumping Length ({\bf N}) 1 Punkt,
35 | Beispielwort ({\bf W}) 1 Punkt,
36 | Aufteilung ({\bf A}) 1 Punkt,
37 | Pumpeigenschaft ({\bf P}) 1 Punkt,
38 | Widerspruch und Schlussfolgerung ({\bf R}) 1 Punkt.
39 | \end{bewertung}
40 |
41 |
--------------------------------------------------------------------------------
/aufgaben/3/30000064/30000064.java:
--------------------------------------------------------------------------------
1 | private Pattern htmltag, link;
2 | public LinkGetter() {
3 | htmltag = Pattern.compile("]*href=\"[^>]*>(.*?)");
4 | link = Pattern.compile("href=\"[^>]*\">");
5 | }
6 |
--------------------------------------------------------------------------------
/aufgaben/3/30000064/ausdruck.txt:
--------------------------------------------------------------------------------
1 | [^0-9]*[12]?[0-9]{1,2}[^0-9]*
2 |
--------------------------------------------------------------------------------
/aufgaben/3/30000068/date.regex:
--------------------------------------------------------------------------------
1 | ([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})
2 |
--------------------------------------------------------------------------------
/aufgaben/3/30000068/fileext.regex:
--------------------------------------------------------------------------------
1 | (.*\.)[^.]+
2 |
--------------------------------------------------------------------------------
/aufgaben/3/30000070/air.txt:
--------------------------------------------------------------------------------
1 | [A-Za-z][A-Za-z ]+ ([A-Z]{3}) *[A-Za-z][A-Za-z ]*
2 |
--------------------------------------------------------------------------------
/aufgaben/3/30000076/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile -- build image for 30000076
3 | #
4 | # (c) 2022 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
5 | #
6 |
7 | wordle.pdf: wordle.tex
8 | pdflatex wordle.tex
9 |
--------------------------------------------------------------------------------
/aufgaben/3/30000076/wordle.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/3/30000076/wordle.pdf
--------------------------------------------------------------------------------
/aufgaben/3/30000077/Mastermind.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/3/30000077/Mastermind.jpeg
--------------------------------------------------------------------------------
/aufgaben/3/30000083.tex:
--------------------------------------------------------------------------------
1 | Sei $\Sigma=\{\texttt{0},\texttt{1}\}$.
2 | Ist die Sprache
3 | \[
4 | L
5 | =
6 | \{
7 | w\in \Sigma^*
8 | \mid
9 | \text{das Wort \texttt{11} kommt nicht als Teilwort in $w$ vor}
10 | \}
11 | \]
12 | regulär?
13 |
14 | \themaL{regular}{regulär}
15 | \thema{DEA}
16 |
17 | \begin{loesung}
18 | Die Bedingung bedeutet, dass Einsen immer allein stehen müssen,
19 | dies ist also die Bedingung der letzten Aufgabe.
20 | Da dafür ein deterministischer endlicher Automat gefunden werden
21 | konnte, ist $L$ regulär.
22 | \end{loesung}
23 |
--------------------------------------------------------------------------------
/aufgaben/3/30000096/ungerade.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/3/30000096/ungerade.pdf
--------------------------------------------------------------------------------
/aufgaben/3/30000096/ungerade_minimized.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/3/30000096/ungerade_minimized.pdf
--------------------------------------------------------------------------------
/aufgaben/3/30000098.tex:
--------------------------------------------------------------------------------
1 | Finden Sie reguläre Ausdrücke für die folgenden Sprachen:
2 | \begin{teilaufgaben}
3 | \item
4 | $L=\{w\in\{\texttt{0},\texttt{1}\}^*\mid |w|_{\texttt{0}}=1\}$
5 | \item
6 | $L=\{w\in\{\texttt{0},\texttt{1}\}^*\mid |w|_{\texttt{0}}=1\vee |w|_{\texttt{1}}=1\}$
7 | \item
8 | $L=\{w\in\{\texttt{0},\texttt{1}\}^*\mid \text{$w$ endet mit zwei Nullen}\}$
9 | \end{teilaufgaben}
10 |
11 | \themaL{regulare Ausdrucke}{reguläre Ausdrücke}
12 |
13 | \begin{loesung}
14 | \begin{teilaufgaben}
15 | \item $\texttt{1}{*}\texttt{0}\texttt{1}*$
16 | \item $
17 | (\texttt{0}{*}\texttt{1}\texttt{0}*)|(\texttt{1}{*}\texttt{0}\texttt{1}*)
18 | $
19 | \item $(\texttt{0}|\texttt{1}){*}\texttt{00}$
20 | \qedhere
21 | \end{teilaufgaben}
22 | \end{loesung}
23 |
--------------------------------------------------------------------------------
/aufgaben/4/40000005.tex:
--------------------------------------------------------------------------------
1 | Zeigen Sie, dass die Sprache $L=\{x{\tt\#}y|x,y\in\{{\tt 0},{\tt 1}\}^*\}$
2 | über dem Alphabet $\Sigma = \{{\tt 0},{\tt 1},{\tt \#}\}$
3 | kontextfrei ist.
4 |
5 | \thema{kontextfrei}
6 | \thema{Grammatik}
7 |
8 | \begin{loesung}
9 | Die folgende Grammatik erzeugt $L$:
10 | \begin{align*}
11 | S&\to W {\tt \#} W\\
12 | W&\to W{\tt 0}\\
13 | &\to W{\tt 1}\\
14 | &\to\varepsilon
15 | \end{align*}
16 |
17 | Noch einfacher hätte man argumentieren können, dass $L$
18 | vom regulären Ausdruck {\tt .*\#.*} akzeptiert wird, also
19 | regulär und damit erst recht kontextfrei sein muss.
20 | \end{loesung}
21 |
--------------------------------------------------------------------------------
/aufgaben/4/40000016.tex:
--------------------------------------------------------------------------------
1 | Die Grammatik
2 | \begin{align*}
3 | S&\to A\\
4 | &\to B{\tt c}\\
5 | A&\to AB\\
6 | &\to ABC\\
7 | &\to {\tt a}\\
8 | B&\to {\tt b}\\
9 | C&\to {\tt cc}
10 | \end{align*}
11 | hat nicht Chomsky-Normalform. Finden Sie eine äquivalente Grammatik
12 | in Chomsky-Normalform.
13 |
14 | \thema{Chomsky-Normalform}
15 |
16 | \begin{loesung}
17 | Die Ausgangsgrammatik ist
18 | \begin{align*}
19 | S&\to A\mid B{\tt c}\\
20 | A&\to AB\mid ABC\mid {\tt a}\\
21 | B&\to {\tt b}\\
22 | C&\to {\tt cc}
23 | \end{align*}
24 | Elimination der Unit rule $S\to A$:
25 | \begin{align*}
26 | S&\to B{\tt c}\mid AB\mid ABC\mid {\tt a}\\
27 | A&\to AB\mid ABC\mid {\tt a}\\
28 | B&\to {\tt b}\\
29 | C&\to {\tt cc}
30 | \end{align*}
31 | Ersetzung der $ABC$-Regeln mit Hilfe einer zusätzlichen
32 | Variablen $U$:
33 | \begin{align*}
34 | S&\to B{\tt c}\mid AB\mid AU\mid {\tt a}\\
35 | A&\to AB\mid AU\mid {\tt a}\\
36 | U&\to BC\\
37 | B&\to {\tt b}\\
38 | C&\to {\tt cc}
39 | \end{align*}
40 | Elimination der Terminal-Symbole
41 | \begin{align*}
42 | S&\to BC'\mid AB\mid AU\mid {\tt a}\\
43 | A&\to AB\mid AU\mid {\tt a}\\
44 | U&\to BC\\
45 | B&\to {\tt b}\\
46 | C&\to C'C'\\
47 | C'&\to {\tt c}
48 | \end{align*}
49 | Diese Grammatik hat offenbar Chomsky-Normalform.
50 | \end{loesung}
51 |
--------------------------------------------------------------------------------
/aufgaben/4/40000027.tex:
--------------------------------------------------------------------------------
1 | Sei $\Sigma=\{\texttt{a},\texttt{b},\texttt{c},\texttt{d}\}$.
2 | Zeigen Sie, dass die Sprache
3 | \[
4 | L=\{w\in\Sigma^*|\;\text{$|w|_\texttt{a}=|w|_\texttt{b}$ und $|w|_\texttt{c}=|w|_\texttt{d}$}\}
5 | \]
6 | nicht kontextfrei ist.
7 |
8 | \thema{kontextfrei}
9 | \themaL{Pumping Lemma fur kontextfreie Sprachen}{Pumping Lemma für kontextfreie Sprachen}
10 |
11 | \begin{loesung}
12 | Man verwendet das Pumping Lemma.
13 | \ding{182}
14 | Wäre die Sprache kontextfrei,
15 | \ding{183}
16 | gäbe
17 | es ein Wortlänge $N$ derart, dass ein Wort länger als $N$ sich
18 | aufpumpen lässt.
19 | \ding{184}
20 | Wir wählen das Wort $w=a^Nc^Nb^Nd^N\in L$.
21 | \ding{185}
22 | Nach dem Pumping
23 | Lemma lässt sich $w$ aufteilen in
24 | $w = uvxyz$, wobei $|vy|>0$ und $|vxy|\le N$.
25 | \ding{186}
26 | Wo genau der Teil
27 | $vxy$ liegt wissen wir nicht, aber wegen $|vxy|\le N$ können
28 | höchstens zwei der Buchstaben betroffen sein, und
29 | zwar nur die Paare $(a,c)$, $(c,b)$ oder $(b,d)$.
30 | Nur die Anzahl
31 | der betroffenen Buchstaben ändert sich, die Anzahl der übrigen
32 | Buchstaben bleibt gleich.
33 | In allen drei Fällen werden die
34 | Beziehungen $|w|_a=|w|_b$ und $|w|_c=|w|_d$ durch das Aufpumpen verletzt.
35 | \ding{187}
36 | Das aufgepumpte Wort ist also nicht mehr in der Sprache, dieser Widerspruch
37 | zeigt, dass die Annahme, die Sprache sei kontextfrei, nicht zu halten ist.
38 | \end{loesung}
39 |
--------------------------------------------------------------------------------
/aufgaben/4/40000034.tex:
--------------------------------------------------------------------------------
1 | In einer SQL INSERT Query müssen Spalten der Datenbank und Wert
2 | in gleicher Zahl angegeben werden:
3 | \begin{verbatim}
4 | INSERT INTO blubb(a1, b2, c3) VALUES('wert1', 'wert2', 1291);
5 | \end{verbatim}
6 | Es stellt sich die Frage, ob man dies durch die Grammatik bereits
7 | sicherstellen kann.
8 | Betrachten Sie dazu die Sprache über dem Alphabet
9 | $\Sigma= \{ {\tt (}, {\tt )}, {\tt ,}\}$, bestehend aus Wörter der
10 | Form
11 | \[
12 | w=
13 | \text{\tt (}\underbrace{\text{\tt ,,}\dots\text{\tt ,}}_{n}
14 | \text{\tt)(}\underbrace{\text{\tt,,}\dots\text{\tt ,}}_{n}\text{\tt )}
15 | \]
16 | wobei sich zwischen den beiden Klammern gleich viele Kommata befinden.
17 | Ist diese Sprache kontextfrei?
18 |
19 | \thema{Grammatik}
20 | \thema{kontextfrei}
21 |
22 | \begin{loesung}
23 | Diese Sprache ist kontextfrei, denn man kann diese Wörter mit folgender
24 | Grammatik erzeugen
25 | \begin{align*}
26 | S&\rightarrow \text{`{\tt (}'}\; V \; \text{`{\tt )}'}\\
27 | V&\rightarrow \text{`{\tt ,}'}\; V \; \text{`{\tt ,}'}\\
28 | &\rightarrow \text{`{\tt )(}'}
29 | \qedhere
30 | \end{align*}
31 | \end{loesung}
32 |
33 |
--------------------------------------------------------------------------------
/aufgaben/4/40000042/block.c:
--------------------------------------------------------------------------------
1 | for (i = 1; i < 47; i++)
2 | {
3 | powers[i] = 2 * powers[i - 1];
4 | sum = sum + c[i] * powers[i];
5 | }
6 |
--------------------------------------------------------------------------------
/aufgaben/4/40000042/block.pas:
--------------------------------------------------------------------------------
1 | for i := 1 to 46 do
2 | begin
3 | powers[i] := 2 * powers[i - 1];
4 | sum := sum + c[i] * powers[i]
5 | end
6 |
--------------------------------------------------------------------------------
/aufgaben/4/40000042/leer.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(int argc, char *argv[]) {
5 | ;
6 | printf("Hello, world!\n");
7 | ;
8 | return EXIT_SUCCESS;
9 | }
10 |
--------------------------------------------------------------------------------
/aufgaben/4/40000043/feld.txt:
--------------------------------------------------------------------------------
1 | . .|0 .|1 .|. . . .
2 | - - - - - -
3 | 1 .|. .|. .|3 . . .
4 | - - - -
5 | . .|4 . . .|. . . .
6 | - - - -
7 | . .|. . . .|3 . .|.
8 | - - - - - -
9 | . . . .|2 .|. . .|.
10 |
11 | . . . .|. .|. . .|.
12 | - - - - - - - - - -
13 | . . . .|. .|. . . .
14 |
15 | . . . .|. .|. . . .
16 | - - - - - - - - - -
17 | 2 . .|3 . .|. . . .
18 | - - - -
19 | . . .|. . .|. . . .
20 |
--------------------------------------------------------------------------------
/aufgaben/4/40000075.tex:
--------------------------------------------------------------------------------
1 | Gegeben sind die Regeln
2 | \begin{align*}
3 | S&\to SS
4 | &
5 | S&\to \texttt{a}
6 | &
7 | S&\to \texttt{bb}
8 | &
9 | S&\to \texttt{ccc}
10 | \end{align*}
11 | Leiten Sie damit die folgenden Wörter aus der Variablen $S$ ab.
12 | \begin{teilaufgaben}
13 | \item \texttt{abbaccc}
14 | \item \texttt{cccabba}
15 | \end{teilaufgaben}
16 |
17 | \thema{Grammatik}
18 |
19 | \begin{loesung}
20 | \begin{teilaufgaben}
21 | \item
22 | \(
23 | S
24 | \to
25 | SS
26 | \to
27 | \texttt{a}S
28 | \to
29 | \texttt{a}SS
30 | \to
31 | \texttt{abb}S
32 | \to
33 | \texttt{abb}SS
34 | \to
35 | \texttt{abba}S
36 | \to
37 | \texttt{abbaccc}
38 | \)
39 | \item
40 | \(
41 | S\to SS \to SSS \to SSSS
42 | \to
43 | SSS\texttt{a}
44 | \to
45 | SS\texttt{bba}
46 | \to
47 | S\texttt{abba}
48 | \to
49 | \texttt{cccabba}
50 | \)
51 | \qedhere
52 | \end{teilaufgaben}
53 | \end{loesung}
54 |
--------------------------------------------------------------------------------
/aufgaben/4/40000076.tex:
--------------------------------------------------------------------------------
1 | Geben Sie eine Grammatik für eine Sprache über dem Alphabet
2 | $\Sigma=\{\texttt{a},\texttt{b},\texttt{c}\}$ an, die Wörter gerader
3 | Länge produziert.
4 |
5 | \thema{Grammatik}
6 |
7 | \begin{loesung}
8 | Solche Wörter entstehen, indem man Paare von Zeichen miteinander
9 | verknüpft.
10 | Die Variable $P$ steht daher für ein Paar, die Variable $Z$ für ein
11 | einzelnes Zeichen.
12 | Das leere Wort entspricht auch den Forderungen, was durch die Regel
13 | $S\to\varepsilon$ ausgedrückt werden kann.
14 | Die Grammatik ist daher:
15 | \begin{align*}
16 | S&\to \varepsilon \\
17 | S&\to SP \\
18 | P&\to ZZ \\
19 | Z&\to \texttt{a} \mid \texttt{b} \mid \texttt{c}
20 | \qedhere
21 | \end{align*}
22 | \end{loesung}
23 |
--------------------------------------------------------------------------------
/aufgaben/5/50000003.tex:
--------------------------------------------------------------------------------
1 | Betrachten Sie folgende Variante einer Turing-Maschine. In dieser
2 | Variante ist die Bewegung des Kopfes nach links nicht möglich,
3 | der Kopf kann nur nach rechts bewegt werden oder stehenbleiben. Die
4 | Übergangsfunktion ist also von der Form
5 | $$\delta:Q\times \Gamma\to Q\times\Gamma\times \{S,R\}$$
6 | ($S$ für Stillstand). Welche Art von Sprachen kann mit diesem
7 | Typ Maschine erkannt werden?
8 |
9 | \thema{Turing-Maschine}
10 |
11 | \begin{loesung}
12 | Wenn sich die Maschine entschliesst, stehen zu bleiben (``Bewegung'' $S$),
13 | ändert sie
14 | nur ihren Zustand und den Inhalt des Feldes, auf dem der Schreib-/Lesekopf
15 | gerade steht. Indem man die Zustandsmenge erweitert, kann man solche
16 | Übergänge, durch Zustandsübergänge betrachten, und all solchen Übergänge
17 | bis zur nächsten Rechtsbewegung in einen einzigen Übergang zusammenfassen.
18 | Damit bleibt nur noch eine Zustandsänderung mit jedem Input-Zeichen
19 | übrig, d.~h.~die Maschine liest den Bandinhalt von links nach rechts und
20 | ändert den Zustand bei jedem Zeichen. Damit verhält sie sich genau
21 | wie ein endlicher Automat, die mit dieser Maschine erkennbaren Sprachen
22 | sind also die regulären Sprachen.
23 | \end{loesung}
24 |
--------------------------------------------------------------------------------
/aufgaben/5/50000006.tex:
--------------------------------------------------------------------------------
1 | Beschreiben Sie eine Turing-Maschine, welche entscheidet, ob die
2 | Anzahl der $1$ in einem Wort $w\in\Sigma^*$ ($\Sigma=\{0,1\}$)
3 | mindestens so gross ist wie die Anzahl der $0$.
4 | Sie soll also im Zustand $q_{\text{accept}}$
5 | genau dann anhalten, wenn $|w|_1\ge |w|_0$.
6 |
7 | \thema{Turing-Maschine}
8 |
9 | \begin{loesung}
10 | Der Turing-Maschinen-Algorithmus muss folgendes implementieren
11 | \begin{enumerate}
12 | \item Fahre nach rechts bis zur ersten {\tt 0}, falls keine {\tt 0}
13 | gefunden $\to q_{\text{accept}}$
14 | \item Ersetze die {\tt 0} durch ein {\tt x}
15 | \item Fahre nach Rechts ans Ende des Bandes
16 | \item Fahre nach Links bis zur ersten {\tt 1}
17 | \item Ersetze die {\tt 1} durch {\tt x}, falls keine {\tt 1}
18 | gefunden: $\to q_{\text{reject}}$.
19 | \item Fahre nach links bis zum Anfang des Bandes
20 | \item Weiter bei 1.
21 | \qedhere
22 | \end{enumerate}
23 | \end{loesung}
24 |
--------------------------------------------------------------------------------
/aufgaben/5/50000011.tex:
--------------------------------------------------------------------------------
1 | Sei $\Sigma=\{{\tt 0},{\tt 1}\}$. In der Vorlesung wurde gezeigt, dass
2 | die Menge aller Wörter $\Sigma^*$ abzählbar ist, die Menge $P(\Sigma^*)$
3 | aller Sprachen aber nicht. Zeigen Sie, dass die Menge aller endlichen
4 | Sprachen abzählbar ist.
5 |
6 | \themaL{abzahlbar}{abzählbar}
7 |
8 | \begin{loesung}
9 | Man kann eine Aufzählung der endlichen Teilmengen von $\Sigma^*$ wie
10 | folgt konstruieren.
11 | \begin{compactenum}
12 | \item Die Menge der Sprachen mit genau einem Wort ist abzählbar, da die
13 | Menge $\Sigma^*$ der Wörter abzählbar ist.
14 | \item Die Menge der Sprachen mit genau zwei Wörtern ist abzählbar,
15 | sie ist eine Menge von Paaren von Wörtern, aber $\Sigma^*\times \Sigma^*$
16 | ist abzählbar.
17 | \item Die Menge der Sprachen mit genau drei Wörtern ist abzählbar,
18 | sie besteht aus Paaren bestehend aus einer Sprache aus dem ersten
19 | Schritt und einer Sprache aus dem zweiten Schritt, es gibt also
20 | abzählbar viele davon.
21 | \item Auf die gleiche Art sieht man, dass die Menge der Sprachen mit
22 | genau $n$ Wörtern abzählbar ist.
23 | \end{compactenum}
24 | Die Sprachen mit $n$ Wörtern bilden also jeweils eine abzählbare Menge,
25 | sie lassen sich also mit zwei Zahlen eindeutig identifizieren: der Anzahl
26 | Wörter $n$ und der Nummer $m$ innerhalb Sprachen mit $n$ Wörtern.
27 | Die Menge aller Paare ist aber wieder abzählbar.
28 | \end{loesung}
29 |
30 |
--------------------------------------------------------------------------------
/aufgaben/5/50000014.tex:
--------------------------------------------------------------------------------
1 | Sei $\Sigma=\{{\tt 1}\}$.
2 | Zeigen Sie: es gibt eine nicht entscheidbare
3 | Sprache $L$ über $\Sigma$.
4 | D.~h.~es gibt eine Teilmenge $L\subset \Sigma^*$, die nicht
5 | von einer Turing-Maschine erkannt werden kann\footnote{Da in $L$
6 | nur die Länge eines Wortes wesentlich ist, sagt dieses Resultat
7 | aus, dass es eine Zahlenmenge gibt, die nicht von einer Turing-Maschine
8 | berechnet werden kann.}.
9 |
10 | \begin{hinweis}
11 | Hilbert Hotel.
12 | \end{hinweis}
13 |
14 | \themaL{abzahlbar}{abzählbar}
15 | \thema{Entscheidbarkeit}
16 |
17 | \begin{loesung}
18 | Die Menge der entscheidbaren Sprachen ist abzählbar, wie bereits in
19 | der Vorlesung gezeigt wurde. Sie stehen ja
20 | in eins-zu-eins Beziehung zu den Turing-Maschinen. Die Beschreibungen
21 | der Turing-Maschinen kann man ja der Grösse nach und bei gleicher Grösse
22 | lexikographisch anordnen, und so eine Auf\-zählung aller Turing-Maschinen
23 | erhalten.
24 |
25 | Jeder Teilmenge von $\Sigma^*$ entspricht eindeutig eine Teilmenge
26 | von $\mathbb N$, zu einer Teilmenge $L\subset\Sigma^*$
27 | bildet man einfach die Menge der in $L$ vorkommenden Wortlängen.
28 |
29 | Die Menge der Teilmengen von $\mathbb N$, die Potenzmenge $P(\mathbb N)$,
30 | ist aber überabzählbar.
31 | Es gibt also wesentlich mehr Sprachen als Turing-Maschinen, es
32 | muss also auch Sprachen geben, die nicht von einer Turing-Maschine
33 | erkannt werden können.
34 | \end{loesung}
35 |
--------------------------------------------------------------------------------
/aufgaben/5/50000037.tex:
--------------------------------------------------------------------------------
1 | Beschreiben Sie den Pseudocode, mit dem nach den vereinbarten
2 | Spielregeln ein Wort auf dem Band als Palindrom erkannt werden kann.
3 |
4 | \thema{Turing-Maschine}
5 |
6 | \begin{loesung}
7 | \begin{enumerate}
8 | \item
9 | Falls das Zeichen unter dem Schreib-/Lesekopf ein Leerzeichen ist,
10 | akzeptiere (das leere Wort ist ein Palindrom).
11 | \item
12 | Merke Dir das Zeichen unter dem Schreib-/Lesekopf, überschreibe es mit
13 | einem Leerzeichen und fahre nach rechts, bis wieder ein Leer-Zeichen
14 | unter dem Schreib-/Lesekopf steht, dann fahre nach links.
15 | \item
16 | Wenn das Zeichen unter dem Schreib-/Lesekopf dasselbe ist, wie das
17 | im Schritt 2 gemerkte Zeichen, überschreibe es mit einem Leerzeichen
18 | und fahre nach links.
19 | Falls das Zeichen ein Leerzeichen ist, akzeptiere (dies ist der Fall
20 | eines einzelnen Zeichens in der Mitte des Palindroms).
21 | Falls das Zeichen ein anderes Zeichen ist, verwerfe, das Wort auf
22 | dem Band war kein Palindrom.
23 | \item
24 | Fahre nach links bis zum nächsten Leerzeichen, dann ein Zeichen nach rechts.
25 | Weiter beim Schritt 1.
26 | \qedhere
27 | \end{enumerate}
28 | \end{loesung}
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/aufgaben/6/60000002.tex:
--------------------------------------------------------------------------------
1 | Zeigen Sie, dass eine reguläre Sprache $L$ Turing-entscheidbar ist.
2 |
3 | \thema{DEA}
4 | \thema{Turing-entscheidbar}
5 |
6 | \begin{loesung}
7 | Da $L$ regulär ist, gibt es einen DEA $A$, der $L$ akzeptiert.
8 | Aus diesem DEA konstruieren wir jetzt eine Turing-Maschine.
9 | Wir ersetzen dazu jeden Übergang
10 | \[
11 | \entrymodifiers={++[o][F]}
12 | \xymatrix{
13 | p\ar[r]^a
14 | &q
15 | }
16 | \]
17 | des DEA durch einen Turing-Maschinen-Übergang
18 | \[
19 | \entrymodifiers={++[o][F]}
20 | \xymatrix{
21 | p\ar[r]^{a\to a,R}
22 | &q
23 | }
24 | \]
25 | Ausserdem fügen wir zwei neue Akzeptierzuständge $q_{\text{accept}}$ und
26 | $q_{\text{reject}}$ hinzu, zusammen mit Übergängen
27 | \[
28 | \entrymodifiers={++[o][F]}
29 | \xymatrix{
30 | *++[o][F=]{p}\ar[r]^{\blank\to\blank, R}
31 | &q_{\text{accept}}
32 | &{p}\ar[r]^{\blank\to\blank, R}
33 | &q_{\text{reject}}
34 | }
35 | \]
36 | Diese Turing-Maschine verarbeitet den Input auf dem Band mit dem
37 | DEA, und erkennt am Ende des Wortes genau diejenigen Wörter, die
38 | vom DEA akzpetiert werden. Also ist $L(M)=L(A)$. Die TM hält genau
39 | nach $|w|+1$ Schritten an, also ist $M$ ein Entscheider.
40 | \end{loesung}
41 |
--------------------------------------------------------------------------------
/aufgaben/6/60000003.tex:
--------------------------------------------------------------------------------
1 | Zeigen Sie, dass eine endliche Sprache $L$ entscheidbar ist.
2 |
3 | \thema{Turing-entscheidbar}
4 |
5 | \begin{loesung}
6 | Da die Sprache endlich ist, gibt es einen regulären Ausdruck,
7 | der genau auf die Wörter von $L$ passt. Der zugehörige deterministische
8 | endliche Automat kann auf einer Turing-Maschine simuliert werden,
9 | die somit ein Entscheider für die Sprache ist.
10 | \end{loesung}
11 |
--------------------------------------------------------------------------------
/aufgaben/6/60000005/a.java:
--------------------------------------------------------------------------------
1 | boolean l(String w) {
2 | return l1(w) || l2(w);
3 | }
4 |
--------------------------------------------------------------------------------
/aufgaben/6/60000005/b.java:
--------------------------------------------------------------------------------
1 | boolean l(String w) {
2 | for (int i = 0; i <= w.length(); i++) {
3 | String w1 = w.substring(0, i);
4 | String w2 = w.substring(i);
5 | if (l1(w1) && l2(w2)) {
6 | return true;
7 | }
8 | }
9 | return false;
10 | }
11 |
--------------------------------------------------------------------------------
/aufgaben/6/60000005/c.java:
--------------------------------------------------------------------------------
1 | boolean l(String w) {
2 | // leeres Wort, kein Test in L1 notwendig
3 | if (w.length() == 0) {
4 | return true;
5 | }
6 | // Beendigung der Rekursion wenn das Wort in L1 ist
7 | if (l1(w)) {
8 | return true;
9 | }
10 | // Rekursion erforderlich, untersuche alle Unterteilungen
11 | // (fuer w.length() == 1 wird hier nichts ausgefuehrt)
12 | for (int i = 1; i < w.length(); i++) {
13 | String w1 = w.substring(0, i);
14 | String w2 = w.substring(i);
15 | if (l1(w1) && l(w2)) {
16 | return true;
17 | }
18 | }
19 | return false;
20 | }
21 |
--------------------------------------------------------------------------------
/aufgaben/6/60000005/d.java:
--------------------------------------------------------------------------------
1 | boolean l(String w) {
2 | return !l1(w);
3 | }
4 |
--------------------------------------------------------------------------------
/aufgaben/6/60000005/e.java:
--------------------------------------------------------------------------------
1 | boolean l(String w) {
2 | return l1(w) && l2(w);
3 | }
4 |
--------------------------------------------------------------------------------
/aufgaben/6/60000009.tex:
--------------------------------------------------------------------------------
1 | Sei
2 | \[
3 | A\varepsilon_{CFG}=\{
4 | \,\langle G\rangle\,|\,\text{$G$ ist eine kontextfreie Grammatik und $\varepsilon\in L(G)$}
5 | \}
6 | \]
7 | Zeigen Sie: $A\varepsilon_{\text{CFG}}$ ist entscheidbar.
8 |
9 | \thema{Entscheidbarkeit}
10 |
11 | \begin{loesung}
12 | Zwei mögliche Lösungen:
13 | \begin{enumerate}
14 | \item
15 | Der folgende Algorithmus entscheidet: bilde die Chomsky-Normalform von $G$
16 | und akzeptiere, falls die Regel $S\to\varepsilon$ vorkommt.
17 | \item
18 | Man verwendet den Enscheider für $A_{\text{CFG}}$, dessen
19 | Existenz in der Vorlesung bewiesen wurde (dabei wurde auch die CNF
20 | verwendet), und wendet ihn auf das Paar $(G,\varepsilon)$ an.
21 | \qedhere
22 | \end{enumerate}
23 | \end{loesung}
24 |
--------------------------------------------------------------------------------
/aufgaben/6/60000010.tex:
--------------------------------------------------------------------------------
1 | Sei
2 | \[
3 | \text{\it INFINITE}_{\text{DEA}}
4 | =
5 | \{
6 | \langle A\rangle\,|\,\text{$A$ ein DEA und $L(A)$ unendlich}
7 | \}.
8 | \]
9 | Zeigen Sie, dass $\text{\it INFINITE}_{\text{DEA}}$
10 | entscheidbar ist.
11 |
12 | \thema{Entscheidbarkeit}
13 |
14 | \begin{loesung}
15 | Der folgende Algorithmus entscheidet: bilde den minimalen Automaten und
16 | wandle ihn in einem regulären Ausdruck um. Falls der reguläre
17 | Audruck einen $*$-Operator enthält, der auf einen nichtleeren
18 | Teilstring angewandt wird, akzeptiere, andernfalls verwerfe.
19 | \end{loesung}
20 |
--------------------------------------------------------------------------------
/aufgaben/6/60000011.tex:
--------------------------------------------------------------------------------
1 | $\text{\it EQ}_{\text{DEA}}$ wurde in der Vorlesung als entscheidbar
2 | erkannt. Man kann die Gleichheit von $L(A)$ und $L(B)$ für
3 | zwei endliche Automaten $A$ und $B$ auch dadurch entscheiden,
4 | dass man alle Strings bis zu einer gewissen Länge $N$ mit
5 | beiden Automaten testet. Falls beide Automaten genau die
6 | gleichen Strings akzeptieren, sind die Sprachen gleich.
7 | Wie gross muss $N$ sein, damit dies funktioniert?
8 |
9 | \thema{Entscheidbarkeit}
10 |
11 | \begin{loesung}
12 | Man muss $N$ so gross machen, dass man das kürzeste Wort erkennen
13 | könnte, bei dem die beiden Automaten verschieden entscheiden
14 | würden. Wenn die beiden Automaten bei allen Wörtern gleich entscheiden,
15 | die höchstens so lange sind, wie der zugehörige minimale Automat Zustände
16 | hat, dann werden sie immer gleich entscheiden. $N$ ist also die grössere
17 | der beiden Anzahlen der Zustände der Minimalautomaten von $A$ und $B$.
18 | \end{loesung}
19 |
--------------------------------------------------------------------------------
/aufgaben/6/60000012.tex:
--------------------------------------------------------------------------------
1 | Sei $L$ eine reguläre Sprache. Zeigen Sie, dass dann auch die Sprache
2 | der gespiegelten Wörter regulär ist:
3 | \[
4 | L^t
5 | =
6 | \{
7 | w^t\mid w\in L
8 | \}
9 | \]
10 | wobei $w^t=a_na_{n-1}\dots a_2a_1$ ist, falls
11 | $w=a_1a_2\dots a_{n-1}a_n\in\Sigma^*$. Insbesondere gibt es zu jedem DEA $A$
12 | einen DEA $A^t$ mit $L(A^t)=L(A)^t$.
13 |
14 | \themaL{regular}{regulär}
15 | \thema{Entscheidbarkeit}
16 |
17 | \begin{loesung}
18 | Falls $L$ regulär ist, gibt es einen regulären Ausdruck $r$
19 | mit $L=L(r)$. In diesem Ausdruck vertauscht man die Reihenfolge aller
20 | verketteten Elemente, und erhält einen neuen regulären Ausdruck
21 | $r^t$, auf den genau die gespiegelten Wörter passen.
22 | Also ist $L(A)^t$ regulär.
23 | \end{loesung}
24 |
--------------------------------------------------------------------------------
/aufgaben/6/60000013.tex:
--------------------------------------------------------------------------------
1 | Sei
2 | \[
3 | \text{\it MIRROR}_{\text{DEA}}
4 | = \{\langle A\rangle\,|\,
5 | \text{der DEA $A$ akzeptiert $w$ genau dann, wenn er $w^t$ akzeptiert}\}.
6 | \]
7 | Zeigen Sie: $\text{\it MIRROR}_\text{DEA}$ ist entscheidbar.
8 |
9 | \thema{Entscheidbarkeit}
10 |
11 | \begin{hinweis}
12 | Verwenden Sie Aufgabe~\ref{60000012}
13 | \end{hinweis}
14 |
15 | \begin{loesung}
16 | Die Bedingung bedeutet $L(A)=L(A)^t$, man muss also entscheiden,
17 | ob $L(A)=L(A)^t$. Dazu wendet man den Entscheider für
18 | $\text{\it EQ}_{\text{DEA}}$ auf das Paar $(A,A^t)$ an.
19 | \end{loesung}
20 |
--------------------------------------------------------------------------------
/aufgaben/6/60000015.tex:
--------------------------------------------------------------------------------
1 | Zeigen Sie, dass die folgende Sprache nicht entscheidbar ist
2 | \[
3 | \text{\textsl{USES-STATE}}_{\text{TM}}=
4 | \left\{
5 | \,
6 | \langle M,q,w\rangle \,\left|\,
7 | \begin{minipage}{3truein}Die TM $M$ verwendet bei der Berechnung mit
8 | dem Input $w$ den Zustand $q$.
9 | \end{minipage}\right.
10 | \right\}
11 | \]
12 |
13 | \begin{hinweis}
14 | Dies ist eine Implementationseigenschaft, lässt sich
15 | also nicht mit dem Satz von Rice behandeln.
16 | \end{hinweis}
17 |
18 | \thema{Entscheidbarkeit}
19 | \thema{Reduktion}
20 |
21 | \begin{loesung}
22 | Wir konstruieren eine Reduktion
23 | $A_{\text{TM}}\le \text{\textsl{USES-STATE}}_{\text{TM}}$.
24 | Dazu bilden wir
25 | $\langle M,w\rangle$
26 | auf
27 | \[
28 | f(\langle M,w\rangle)=
29 | \langle M,q_{\text{accept}},w\rangle
30 | \]
31 | ab. Es ist genau dann
32 | $\langle M,w\rangle\in A_{\text{TM}}$, wenn $M$ auf Input $w$ im
33 | Zustand $q_{\text{accept}}$ anhält.
34 | Andererseits ist
35 | $\langle M,q_{\text{accept}},w\rangle\in
36 | \text{\textsl{USES-STATE}}_{\text{TM}}$,
37 | wenn $M$ bei der Verarbeitung
38 | des Input $w$ den Zustand $q_{\text{accept}}$ verwendet, also
39 | $\langle M,w\rangle\in A_{\text{TM}}$.
40 | Damit ist die Reduktion konstruiert, und somit gezeigt, dass
41 | $\text{\textsl{USES-STATE}}_{\text{TM}}$ nicht entscheidbar ist.
42 | \end{loesung}
43 |
--------------------------------------------------------------------------------
/aufgaben/6/60000017.tex:
--------------------------------------------------------------------------------
1 | Können Sie einen Algorithmus angeben, der bei einer beliebigen
2 | turing-erkennbaren
3 | Sprache herausfinden kann, ob alle in der Sprache enthaltenen Wörter
4 | ``wachsend'' sind (im Sinne von Aufgabe~\ref{30000016})
5 |
6 | \thema{Satz von Rice}
7 | \thema{Entscheidbarkeit}
8 |
9 | \begin{loesung}
10 | Die Eigenschaft, dass eine Sprache nur wachsende Wörter
11 | enthält, ist nicht trivial: Die Sprache der wachsenden
12 | Wörter, hat sie, die Sprache $\Sigma^*$ nicht. Nach dem
13 | Satz von Rice ist diese Eigenschaft also nicht entscheidbar,
14 | einen Algorithmus der verlangten Art kann es also nicht geben.
15 | \end{loesung}
16 |
--------------------------------------------------------------------------------
/aufgaben/6/60000018.tex:
--------------------------------------------------------------------------------
1 | Können Sie einen Algorithmus angeben, der zu einer rekursiven
2 | Sprache herausfindet, ob sie ausschliesslich periodische Wörter (siehe
3 | Aufgabe~\ref{30000018})
4 | enthält?
5 |
6 | \thema{Entscheidbarkeit}
7 | \thema{Satz von Rice}
8 |
9 | \begin{loesung}
10 | Nein. Sei
11 | $P$ die Eigenschaft der Sprache $L$ ``Sprache $L$ enthält
12 | nur periodische Wörter''. Die leere Sprache $\emptyset$
13 | hat diese Eigenschaft, die Sprache $\{{\tt 01}\}$ jedoch nicht,
14 | {\tt 01} ist nicht periodisch.
15 | Damit sind die Voraussetzungen des Satzes von Rice erfüllt, also
16 | ist die Eigenschaft $P$ nicht entscheidbar.
17 | \end{loesung}
18 |
--------------------------------------------------------------------------------
/aufgaben/6/60000022.tex:
--------------------------------------------------------------------------------
1 | Betrachten Sie die Frage, ob ein vorgegebener endlicher Automat $A$ über dem
2 | Alphabet $\{{\tt 0},{\tt 1}\}$ keine Zeichenkette akzeptiert,
3 | die eine ungerade Anzahl {\tt 1} enthält. Ist dieses Problem
4 | entscheidbar?
5 |
6 | \thema{Entscheidbarkeit}
7 |
8 | \begin{loesung}
9 | Der folgende Algorithmus entscheidet das Problem.
10 | \begin{enumerate}
11 | \item
12 | Man konstruiert einen endlichen Automaten $B$, der nur Wörter
13 | akzeptiert, die eine ungerade Anzahl von {\tt 1} enthält.
14 | Das Zustandsdiagramm
15 | \[
16 | \entrymodifiers={++[o][F]}
17 | \xymatrix @-1mm {
18 | *++\txt{}\ar[r]
19 | &z_0\ar@/^/[r]^{1} \ar@(dr,dl)^{0}
20 | &*++[o][F=]{z_1} \ar@/^/[l]^{1}
21 | \ar@(dr,ur)_{0}
22 | }
23 | \]
24 | beschreibt einen solchen Automaten.
25 | \item
26 | Man kann einen endlichen Automaten $R$ konstruieren, welcher
27 | die Sprache $L(R)=L(A)\cap L(B)$ akzeptiert.
28 | \item
29 | Der Automat $A$ akzeptiert genau dann kein Wort mit einer ungeraden
30 | Anzahl {\tt 1}, wenn $L(A)\cap L(B)$ leer ist. Das Leerheitsproblem
31 | ist aber entscheidebar, es gibt also einen Entscheider, der
32 | entscheidet, ob $L(R)=\emptyset$.
33 | \qedhere
34 | \end{enumerate}
35 | \end{loesung}
36 |
--------------------------------------------------------------------------------
/aufgaben/6/60000023.tex:
--------------------------------------------------------------------------------
1 | Betrachten Sie das Problem, ob ein deterministischer endlicher Automat
2 | und ein regulärer Ausdruck äquivalent sind (d.h.~sie akzeptieren die
3 | selbe Sprache). Ist dieses Problem entscheidbar?
4 |
5 | \thema{Entscheidbarkeit}
6 | \themaL{regular}{regulär}
7 |
8 | \begin{loesung}
9 | Der folgende Algorithmus entscheidet das Problem.
10 | \begin{enumerate}
11 | \item Wandle den regulären Automaten in einen äquivalenten deterministischen
12 | Automaten um.
13 | \item Finde für beide Automaten den minimalen Automaten
14 | \item Falls die Automaten übereinstimmen sind der ursprüngliche
15 | deterministische endliche Automat und der reguläre Ausdruck
16 | äquivalent.
17 | \qedhere
18 | \end{enumerate}
19 | \end{loesung}
20 |
--------------------------------------------------------------------------------
/aufgaben/6/60000027.tex:
--------------------------------------------------------------------------------
1 | Ein Programmierer ärgert sich darüber, dass Webanwendungen manchmal
2 | einfrieren, weil Javascript-Programme nicht fertig werden.
3 | Er beschliesst daher, einen Scanner zu implementieren, der alle
4 | Java\-scripts inspiziert und nur noch solche Javascripts zur Ausführung
5 | freigibt, die garantiert fertig werden. Wie schätzen Sie seine
6 | Erfolgsaussichten ein?
7 |
8 | \thema{Entscheidbarkeit}
9 | \thema{Halteproblem}
10 |
11 | \begin{loesung}
12 | Dieses Problem ist nicht lösbar denn die Frage, ob ein Programm
13 | anhalten wird, ist nicht entscheidbar, wie das Haltetheorem besagt.
14 | \end{loesung}
15 |
16 | \begin{bewertung}
17 | Verweis auf Haltetheorem 6 Punkte.
18 | \end{bewertung}
19 |
--------------------------------------------------------------------------------
/aufgaben/6/60000035.tex:
--------------------------------------------------------------------------------
1 | Für die Vorlesung AutoSpr soll ein Webservice bereitgestellt werden, mit
2 | welchem Studenten ihre Programme in verschiedenen vereinfachten
3 | Programmiersprachen testen können.
4 | Natürlich möchte man sicherstellen, dass ein solches Programm den
5 | Service nicht monopolisieren kann.
6 | Man möchte also vermeiden, dass ein Programm nicht anhält,
7 | indem man den Code analysiert, bevor er ausgeführt wird.
8 | Wie kann man dies für die Sprachen LOOP, WHILE und GOTO sicherstellen?
9 |
10 | \themaL{Turing-vollstandig}{Turing-vollständig}
11 | \thema{Halteproblem}
12 | \thema{Reduktion}
13 |
14 | \begin{loesung}
15 | Die Sprache LOOP ist nicht Turing-vollständig, wir wissen sogar,
16 | dass jedes LOOP-Pro\-gramm terminiert, für die Sprache LOOP ist so ein
17 | Webservice also kein Problem.
18 |
19 | Die Sprachen WHILE und GOTO sind dagegen Turing-vollständig und damit
20 | ist das Halteproblem für Programme in diesen Sprachen nicht lösbar.
21 | Insbesondere gibt es keine Möglichkeit zu verhindern, dass ein diesem
22 | Webservice aufgegebenes Programm nicht anhalten wird.
23 | \end{loesung}
24 |
25 | \begin{bewertung}
26 | Turing-Vollständigkeit von WHILE und GOTO ({\bf T}) 2 Punkte,
27 | Haltetheorem ({\bf H}) 2 Punkte,
28 | Kein Problem für LOOP ({\bf L}), da LOOP-Programme immer terminieren, 2 Punkte.
29 | \end{bewertung}
30 |
31 |
32 |
--------------------------------------------------------------------------------
/aufgaben/6/60000038.tex:
--------------------------------------------------------------------------------
1 | In der Aufgabe \ref{40000056} wird eine kontextfreie Grammatik für eine
2 | Sprache verlangt.
3 | Gibt es eine Möglichkeit, die Lösungen dieser Aufgabe maschinell zu
4 | korrigieren, also ein Programm zu schreiben, welches genau diejenigen
5 | Grammatiken erkennt, welche die Sprache erzeugen, und alle anderen verwirft?
6 |
7 | \thema{Entscheidbarkeit}
8 | \thema{Reduktion}
9 |
10 | \begin{loesung}
11 | In der Musterlösung von Aufgabe \ref{4000056} wird eine kontextfreie
12 | Grammatik $G$ angegeben, welche die genannte Sprache erzeugt.
13 | Gesucht wird also ein Programm, welches herausfindet, ob eine andere
14 | vorgeschlagene Grammatik $G_1$ die gleiche Sprache erzeugt.
15 | Dies ist dass Problem $\textit{EQ}_{\text{CFG}}$, von welchem im Satz~6.20
16 | im Skript gezeigt wurde, dass es nicht entscheidbar ist.
17 | Die Aufgabe \ref{40000056} ist daher nicht maschinell korrigierbar.
18 | \end{loesung}
19 |
20 | \begin{bewertung}
21 | Reduktion auf Gleichheit von akzeptierten Sprachen ({\bf R}) 2 Punkte,
22 | $\textit{EQ}_{\text{CFG}}$ ist nicht entscheidbar ({\bf E}) 2 Punkte,
23 | Schlussfolgerung ({\bf S}) 2 Punkte.
24 | \end{bewertung}
25 |
26 |
--------------------------------------------------------------------------------
/aufgaben/6/60000040.tex:
--------------------------------------------------------------------------------
1 | In einer verteilten Anwendung sollen Log-Meldungen zentral gesammelt
2 | und ausgewertet werden.
3 | Die Meldungen könnten leicht mit etwa einem Dutzend ziemlich
4 | komplexer regulärer Ausdrücke klassifiziert werden.
5 | Die zugehörigen endlichen Automaten sind jedoch komplex genug, dass
6 | sich bereits Performance-Engpässe abzeichnen.
7 | Daher sollen jetzt alternative Algorithmen untersucht werden.
8 | Um sicherzustellen, dass durch diesen Umbau nicht neue Fehler
9 | eingeführt werden, wird verlangt, dass ein Testprogramm geschrieben
10 | wird, welches vorgeschlagene Algorithmen darauf hin prüfen soll,
11 | ob sie genau die Log-Messages akzeptieren, die auch die genannten
12 | regulären Ausdrücke akzeptieren würden.
13 | Ist so etwas möglich?
14 |
15 | \thema{Reduktion}
16 | \thema{Satz von Rice}
17 |
18 | \begin{loesung}
19 | Nein.
20 | Die Algorithmen müssen eine Sprache akzeptieren, die die Eigenschaft
21 | \begin{center}
22 | P = \text{``besteht nur aus Wörtern, die von den regulären Ausdrücken akzeptiert werden''}
23 | \end{center}
24 | haben.
25 | Sofern die regulären Ausdrücke nicht alle Wörter akzeptieren, was man
26 | hier annehmen darf, ist dies eine nichttriviale Eigenschaft.
27 | Nach dem Satz von Rice kann es daher kein Programm geben, welches
28 | entscheiden kann, ob eine Maschine eine Sprache mit der Eigenschaft
29 | $P$ akzeptiert.
30 | \end{loesung}
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/aufgaben/6/60000041/DSC_0559.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/6/60000041/DSC_0559.jpg
--------------------------------------------------------------------------------
/aufgaben/6/60000041/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile
3 | #
4 | # (c) 2020 Prof Dr Andreas Müller, Hochschule Rapperswil
5 | #
6 | #biber.jpg: DSC_0559.jpg
7 | # convert DSC_0559.jpg -scale 50% \
8 | # -density 300 -units PixelsPerInch biber.jpg
9 |
10 | biber2.jpg: biber.jpg
11 | convert biber.jpg -scale 50% \
12 | -density 300 -units PixelsPerInch biber2.jpg
13 |
--------------------------------------------------------------------------------
/aufgaben/6/60000041/biber2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/6/60000041/biber2.jpg
--------------------------------------------------------------------------------
/aufgaben/6/60000042.tex:
--------------------------------------------------------------------------------
1 | Sei $L$ eine Turing-erkennbare Sprache.
2 | Man sagt, die Sprache sei links-kürzbar, wenn man von einem Wort ein beliebiges
3 | Anfangsstück entfernen kann und das verkürzte Wort immer noch ein Wort
4 | der Sprache ist.
5 | Also zum Beispiel
6 | \[
7 | \texttt{BIBER}\in L
8 | \quad\Rightarrow\quad
9 | \texttt{IBER},
10 | \texttt{BER},
11 | \texttt{ER},
12 | \texttt{R},
13 | \varepsilon \in L.
14 | \]
15 | Wie könnte man ein Programm aufbauen, welches immer anhält und mit
16 | welchem man andere Programme analysieren kann, ob deren akzeptierte Sprache
17 | links-kürzbar ist?
18 |
19 | \thema{Reduktion}
20 | \thema{Satz von Rice}
21 |
22 | \begin{loesung}
23 | Die Eigenschaft einer Sprache, links-kürzbar zu sein, ist eine nichttriviale
24 | Eigenschaft.
25 | Die Liste der Wörter in der Aufgabenstellung bildet eine links-kürzbare
26 | Sprache, die Sprache bestehend nur aus dem Wort \texttt{BIBER} hat diese
27 | Eigenschaft nicht.
28 | Der Satz von Rice besagt jetzt, dass man kein Programm schreiben kann, welches
29 | entscheiden könnte, ob die akzeptierte Sprache die Eigenschaft hat,
30 | links-kürzbar zu sein.
31 | \end{loesung}
32 |
33 | \begin{bewertung}
34 | Satz von Rice ({\bf R}) 1 Punkt,
35 | Eigenschaft ({\bf E}) 1 Punkt,
36 | zwei Sprachen ({\bf Z}) 1 Punkt,
37 | Eigenschaft ist nicht trivial ({\bf T}) 1 Punkt,
38 | Schlussfolgerung nicht entscheidbar ({\bf N}) 2 Punkt.
39 | \end{bewertung}
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/aufgaben/6/60000043.tex:
--------------------------------------------------------------------------------
1 | Endlosschleifen gehören zu den immer wieder vorkommenden Programmierfehlern.
2 | Da ein Java-Compiler den vollständigen Überblick darüber hat, was in einem
3 | Java-Programm passiert, könnte man versuchen, die Änderungen, die der Code
4 | an den Variablen vornimmt, zu verfolgen.
5 | Dadurch könnte man dem Compiler ein Feature hinzufügen, mit dem der
6 | Compiler mögliche Endlosschleifen erkennen kann.
7 | Ist dies möglich?
8 |
9 | \themaL{Turing-vollstandig}{Turing-vollständig}
10 | \thema{Halteproblem}
11 | \thema{Reduktion}
12 |
13 | \begin{loesung}
14 | Ein solcher Compiler wäre in der Lage, das Halteproblem für alle
15 | Programme zu lösen, die in dieser Sprache verfasst sind.
16 | Da Java Turing-vollständig ist, wäre damit das Halteproblem gelöst.
17 | Dies ist ein Widerspruch zum Haltetheorem.
18 | \end{loesung}
19 |
20 | \begin{bewertung}
21 | Bezug zum Halteproblem ({\bf H}) 2 Punkte,
22 | Nichtentscheidbarkeit des Halteproblems ({\bf E}) 2 Punkte,
23 | Turing-Vollständigkeit von Java ({\bf T}) 2 Punkte.
24 | \end{bewertung}
25 |
26 |
--------------------------------------------------------------------------------
/aufgaben/6/60000047.tex:
--------------------------------------------------------------------------------
1 | Formulieren Sie die folgende Fragestellung als Sprachproblem:
2 | {\em
3 | Gegeben ein endlicher Automat $A$, ist er minimal?
4 | }
5 |
6 | \thema{Sprachproblem}
7 |
8 | \begin{loesung}
9 | Es muss eine Sprache konstruiert werden, welche genau die
10 | Beschreibungen/Stringformen
11 | minimaler Automaten enthält, also
12 | \[
13 | L
14 | =
15 | \{
16 | \langle A\rangle
17 | \mid
18 | \text{$A$ ist ein endlicher Automat, der minimal ist}
19 | \}.
20 | \]
21 | \end{loesung}
22 |
--------------------------------------------------------------------------------
/aufgaben/6/60000048.tex:
--------------------------------------------------------------------------------
1 | Ist die Sprache
2 | \[
3 | \{
4 | \langle A\rangle
5 | \mid
6 | \text{$A$ ist ein minimaler, deterministischer endlicher Automat}
7 | \}
8 | \]
9 | entscheidbar?
10 |
11 | \thema{Entscheidbarkeit}
12 | \thema{Entscheider}
13 |
14 | \begin{loesung}
15 | Entscheidbar heisst, dass es einen Algorithmus zur Entscheidung des
16 | Problems gibt.
17 | Der im Kapitel 3 studierte ``Kreuzchenalgorithmus'', mit dem man den
18 | Minimalautomaten eines deterministischen endlichen Automaten finden
19 | kann, kann dazu verwendet werden, die Frage zu entscheiden.
20 | Der folgende Algorithmus mit Input $w$ löst das Problem:
21 | \begin{enumerate}
22 | \item
23 | Wenn $w$ keine Beschreibung eines endlichen Automaten ist, vewerfe $w$.
24 | \item
25 | Finde den Automaten $A$, der $w$ als Beschreibung hat: $w=\langle A\rangle$.
26 | \item
27 | Wende den Minimalalgorithmus auf $A$ an, dies liefert den
28 | Minimalautomaten
29 | $A_\text{min}$
30 | \item
31 | Wenn $A=A_{\text{min}}$ ist, war auch $A$ schon minimal, akzeptiere
32 | $\langle A\rangle$.
33 | \item
34 | Andernfalls verwerfe $\langle A\rangle $.
35 | \end{enumerate}
36 | Jeder Schritt dieses Algorithmus wird in endlicher Zeit fertig.
37 | Auch enthält der Algorithmus keine Schleifen, somit wird er immer
38 | anhalten und ist damit ein Entscheider.
39 | \end{loesung}
40 |
--------------------------------------------------------------------------------
/aufgaben/6/60000051.tex:
--------------------------------------------------------------------------------
1 | Zeigen Sie mit Hilfe des Satzes von Rice, dass die Frage, ob eine
2 | Turing-Maschine eine kontextfreie Sprache akzeptiert, nicht entscheidbar
3 | ist.
4 |
5 | \thema{Satz von Rice}
6 | \thema{Entscheidbarkeit}
7 |
8 | \begin{loesung}
9 | Ob eine Sprache kontextfrei ist oder nicht ist eine nichttriviale
10 | Eigenschaft.
11 | Um dies zu zeigen, muss man zwei Sprachen angeben, von denen die eine
12 | Kontextfrei ist und die andere nicht.
13 | Zwei mögliche Sprachen sind
14 | \begin{align*}
15 | L_1
16 | &=
17 | \Sigma^*&&\text{alle Wörter, kontextfrei dank der Grammatik}
18 | \qquad
19 | \left\{
20 | \;
21 | \begin{aligned}
22 | S&\to SZ\mid \varepsilon\\
23 | Z&\to \Sigma
24 | \end{aligned}
25 | \right.
26 | \\
27 | L_2
28 | &=
29 | \{\texttt{a}^n\texttt{b}^n\texttt{c}^n
30 | \mid
31 | n\ge 0
32 | \}
33 | &&\text{nicht kontextfrei, Standardbeispiel}
34 | \end{align*}
35 | Da die Spracheigenschaft, kontextfrei zu sein, eine nichttriviale
36 | Eigenschaft ist, folgt nach dem Satz von Rice, dass nicht entscheidbar
37 | ist, ob eine Turing-Maschine eine kontextfreie Sprache akzeptiert.
38 | \end{loesung}
39 |
--------------------------------------------------------------------------------
/aufgaben/6/60000053.tex:
--------------------------------------------------------------------------------
1 | Ein häufig wiederkehrende Aufgabe in der Softwareentwicklung ist die
2 | Beurteilung, ob eine Zeichenkette ein gültiges Datum ist.
3 | Daher könnte es nützlich sein, ein Tool zur Verfügung zu haben,
4 | welches ein Programm analysieren kann und eine Aussage liefern kann,
5 | ob das Programm nur korrekte Daten akzeptiert.
6 | Gibt es ein solches Tool?
7 |
8 | \thema{Entscheidbarkeit}
9 | \thema{Satz von Rice}
10 |
11 | \begin{loesung}
12 | Nein.
13 | Dies ist das Entscheidungsproblem für die Eigenschaft
14 | $\textit{DATES}_{\text{TM}}$, wobei die Eigenschaft \textit{DATES}
15 | besagt, dass die Sprache nur aus korrekten Daten besteht.
16 | Diese Eigenschaft ist nicht trivial, denn
17 | \[
18 | \begin{aligned}
19 | L_1&=\{\texttt{2024-07-19}\}&&\text{hat die Eigenschaft \textit{DATES},}\\
20 | L_2&=\{\texttt{blubb}\}&&\text{hat die Eigenschaft nicht.}
21 | \end{aligned}
22 | \]
23 | Beide Sprachen können von einer Turing-Maschine erkannt werden.
24 | Nach dem Satz von Rice ist $\textit{DATES}_{\text{TM}}$ nicht
25 | entscheidbar.
26 | \end{loesung}
27 |
28 | \begin{bewertung}
29 | Eigenschaft \textit{DATES} ({\bf P}) 1 Punkt,
30 | zwei Sprachen ({\bf L}) 1 Punkt,
31 | Eigenschaft ist nicht trivial ({\bf T}) 1 Punkt,
32 | Anwendung des Satzes von Rice ({\bf R}) 2 Punkte.
33 | \end{bewertung}
34 |
35 |
36 |
--------------------------------------------------------------------------------
/aufgaben/7/70000001.tex:
--------------------------------------------------------------------------------
1 | Konstruieren Sie ein binäres Additionsprogramm für eine geeignet
2 | ausgebaute Turing-Maschine, welches Laufzeit
3 | $O(n)$ hat, wobei $n$ die Anzahl Stellen der Summanden ist.
4 | Warum ist Ihre Maschine so viel schneller als die in der Vorlesung
5 | im Video gezeigte Maschine?
6 |
7 | \themaL{Komplexitat}{Komplexität}
8 |
9 | \begin{loesung}
10 | Wir verwenden eine Maschine mit drei Bändern. Zunächst schreiben
11 | wir den zweiten Summanden auf das zweite Band, was in $O(n)$
12 | Schritten durchgeführt werden kann.
13 | Dann beginnt die
14 | eigentliche Addition, wir lesen den ersten Summanden vom ersten Band,
15 | beginnend beim niederwertigsten Bit, und den zweiten Summanden
16 | vom zweiten Band, ebenfalls beginnend beim niederwertigsten Bit.
17 | Die Summe wird jeweils auf Band 3 geschrieben. Nach $O(n)$
18 | solchen Operationen steht das Resultat auf Band 3.
19 |
20 | Nach einem in der Vorlesung bewiesenen Satz benötigt
21 | die Simulation dieser Maschine mit drei Bändern auf einer Standardmaschine
22 | die Laufzeit $O(n^2)$, was sich mit der Laufzeit der Maschine
23 | aus der Vorlesung deckt.
24 | \end{loesung}
25 |
26 |
27 |
--------------------------------------------------------------------------------
/aufgaben/7/70000002.tex:
--------------------------------------------------------------------------------
1 | Zwei Graphen $G$ und $H$ heissen isomorph, wenn die Knoten von $G$ so
2 | umgeordnet werden können, dass die beiden Graphen übereinstimmen.
3 | Zeigen sie dass,
4 | \[
5 | \text{\it ISO} = \{(G,H)\; |\;\text{$G$ und $H$ sind isomorph}\}
6 | \]
7 | in NP ist.
8 |
9 | \thema{polynomieller Verifizierer}
10 | \thema{NP}
11 |
12 | \begin{loesung}
13 | Als Lösungszertifikat $c$ brauchen wir die Zuordnung der Knoten
14 | von $G$ zu den Knoten von $H$. Dann müssen wir nur noch überprüfen,
15 | ob zu jeder Kante von $G$ auch eine Kante von $H$ gehört und
16 | umgekehrt, was in $O(n^4)$ möglich ist ($n$ ist die Anzahl der Ecken).
17 | Also hat {\it ISO} einen polynomiellen Verifizierer, und ist damit
18 | in NP.
19 | \end{loesung}
20 |
--------------------------------------------------------------------------------
/aufgaben/7/70000004.tex:
--------------------------------------------------------------------------------
1 | Seien $A_1$ und $A_2$ Sprachen, die von einer nichtdeterministischen
2 | Turing-Maschine in polynomieller Zeit entscheidbar sind. Zeigen Sie:
3 | \begin{teilaufgaben}
4 | \item $A_1\cap A_2$ ist in NP
5 | \item $A_1A_2$ ist in NP
6 | \end{teilaufgaben}
7 |
8 | \thema{NP}
9 | \thema{polynomieller Verifizierer}
10 |
11 | \begin{loesung}
12 | Man muss nur nachweisen, dass es einen Verifizierer gibt, der polynomielle
13 | Laufzeit hat. Dabei kann man davon ausgehen, dass $V_1$ in polynomieller
14 | Zeit $p_1(n)$ $w_1\in A_1$ verifiziert, und analog für $V_2$.
15 | \begin{teilaufgaben}
16 | \item
17 | Um $w\in A_1\cap A_2$ zu verifizieren, verlangt man als Zertifikat
18 | die beiden Zertifikate, die zertifizieren, dass $w\in A_1$
19 | ist und $w\in A_2$. Dann lässt man beide Verifizierer
20 | $V_1$ und $V_2$ laufen, wozu Laufzeit $p_1(n)+p_2(n)$ notwendig ist,
21 | also polynomielle Laufzeit.
22 | \item
23 | Um $w\in A_1A_2$ zu verifizieren verlangt man als Zertifikat
24 | die Zerlegung $w=w_1w_2$ und die beiden Zertifikate, die
25 | $w_1\in A_1$ bzw.~$w_2\in A_2$ zertifizieren. Dann kontrolliert
26 | man, ob tatsächlich $w=w_1w_2$ ist, und lässt
27 | die Verifizierer auf den beiden Teilwörtern mit den
28 | jeweiligen Zertifikaten laufen.
29 | Dazu ist die Laufzeit
30 | $O(n + p_1(n) + p_2(n))$, also in polynomieller Zeit nötig.
31 | \qedhere
32 | \end{teilaufgaben}
33 | \end{loesung}
34 |
--------------------------------------------------------------------------------
/aufgaben/7/70000010.tex:
--------------------------------------------------------------------------------
1 | Ein Verkehrsnetz soll regelmässig durch Mitarbeiter
2 | kontrolliert werden, die ihre Basis an einzelnen Knotenpunkten
3 | des Netzes haben.
4 | Kann man auf effiziente Art und Weise herausfinden, an welchen
5 | Knotenpunkten man Kontrolleure stationieren muss, damit jede
6 | Strecke in einem Knoten mit Kontrolleur endet?
7 |
8 | \themaL{NP-vollstandig}{NP-vollständig}
9 | \thema{polynomielle Reduktion}
10 |
11 | \begin{loesung}
12 | Dieses Problem is äquivalent zu \textsl{VERTEX-COVER},
13 | und damit NP-vollständig, also nach aktuellem Wissen für
14 | grosse Probleme nicht effizient lösbar. Die Reduktionsabbildung
15 | bildet die Objekte wie folgt ab
16 | \begin{align*}
17 | \text{Knoten}&\mapsto \text{Knoten}\\
18 | \text{Strecke}&\mapsto \text{Kante}\\
19 | \text{Anzahl Kontrolleure}&\mapsto k\\
20 | \text{Knoten mit Kontrolleur}&\mapsto\text{Knoten aus dem Vertex-Cover}
21 | \qedhere
22 | \end{align*}
23 | \end{loesung}
24 |
--------------------------------------------------------------------------------
/aufgaben/7/70000011.tex:
--------------------------------------------------------------------------------
1 | Für eine Gruppenarbeit sollen $k$ Gruppen gebildet werden.
2 | Um die Zeit für das gegenseitige Kennenlernen möglichst
3 | kurz zu halten, sollen sich die Leute einer Gruppe bereits
4 | gegenseitig kennen. Alle Leute sollen beschäftigt sein.
5 | Können Sie einen effizienten Algorithmus
6 | formulieren, mit dem eine solche Gruppeneinteilung auch bei
7 | einer grossen Teilnehmerzahl gefunden werden kann?
8 |
9 | \themaL{NP-vollstandig}{NP-vollständig}
10 | \thema{polynomielle Reduktion}
11 |
12 | \begin{loesung}
13 | Das Problem ist äquivalent zu \textsl{CLIQUE-COVER}, also
14 | NP-vollständig. Nach aktuellem Wissen gibt es also keine
15 | effizienten Algorithmus, der das Problem lösen würde. Die
16 | Äquivalenz wird durch folgende Abbildung vermittelt
17 | \begin{align*}
18 | \text{Teilnehmer}&\mapsto\text{Knoten}\\
19 | \text{kennen sich}&\mapsto\text{Kante}\\
20 | \text{Anzahl Gruppen}&\mapsto k\\
21 | \text{Gruppe}&\mapsto\text{Clique}
22 | \qedhere
23 | \end{align*}
24 | \end{loesung}
25 |
--------------------------------------------------------------------------------
/aufgaben/7/70000012.tex:
--------------------------------------------------------------------------------
1 | Aus einer Menge von Fachleuten, die zum Teil in mehreren Gebieten
2 | $i=1,\dots,n$ tätig sind, soll eine Expertenkommission gebildet werden.
3 | Da zwei Experten für das gleiche Fachgebiet sich erfahrungsgemäss
4 | immer streiten, will man in der Expertenkommission jedes Fachgebiet
5 | durch genau einen Experten vertreten haben. Können Sie einen effizienten
6 | Algorithmus zur Auswahl der Mitglieder der Kommission angeben?
7 |
8 | \themaL{NP-vollstandig}{NP-vollständig}
9 | \thema{polynomielle Reduktion}
10 |
11 | \begin{loesung}
12 | Das Problem ist Äquivalent zu \textsl{HITTING-SET}, ist also
13 | NP-vollständig. Nach aktuellem Wissen gibt es also keine
14 | effizienten Algorithmus, der das Problem lösen würde. Die
15 | Äquivalenz zu \textsl{HITTING-SET} wird durch die Abbildung
16 | \begin{align*}
17 | \text{Experte}&\mapsto \text{Punkt in $S$}\\
18 | \text{Fachgebiet $i$}&\mapsto \text{Teilmenge $U_i$ aller Experten für dieses Gebiet}\\
19 | \text{Expertenkommission}&\mapsto \text{Hitting Set $H$}
20 | \end{align*}
21 | vermittelt.
22 | \end{loesung}
23 |
--------------------------------------------------------------------------------
/aufgaben/7/70000014/kakuro.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000014/kakuro.pdf
--------------------------------------------------------------------------------
/aufgaben/7/70000015/nurikabe.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000015/nurikabe.png
--------------------------------------------------------------------------------
/aufgaben/7/70000018.tex:
--------------------------------------------------------------------------------
1 | In einem
2 | $n$-Sudoku müssen die Zahlen $1$ bis $n^2$ auf die Felder eines
3 | Spielfeld verteilt werden, welches sich aus $n\times n$ quadratisch
4 | angeordneten Quadraten von je $n\times n$ Feldern besteht.
5 | In keiner Zeile und Spalte und in keinem $n\times n$ Teilfeld
6 | darf eine Zahl mehr als einmal vorkommen. Die bekannten Sudokus
7 | sind 3-Sudokus.
8 |
9 | Zeigen sie: wenn $\text{P}=\text{NP}$, dann gibt es einen Algorithmus,
10 | der auch grosse Sudokus in polynomieller Zeit lösen kann.
11 |
12 | \thema{NP}
13 | \thema{polynomieller Verifizierer}
14 |
15 | \begin{loesung}
16 | Wir müssen zunächst zeigen, dass Sudoko ein NP-Problem ist.
17 |
18 | Als Zertifikat verlangen wir das vollständig ausgefüllte Sudoku-Feld.
19 |
20 | Das Sudoku-Feld hat $n^4$ Felder. Für jedes Feld müssen die
21 | folgenden Tests durchgeführt werden. Zunächst muss getestet
22 | werden, ob die Zahl in dem Feld zwisch $1$ und $n^2$ liegt.
23 | Dann muss die Zahl mit den $n^2$ Feldern der Zeile, der Spalte
24 | und des gleichen Teilfeldes verglichen werden. Insgesamt sind
25 | also $O(n^2)$ Vergleichsoperationen notwendig.
26 | Insgesamt braucht es also $O(n^6)$
27 | Operationen. Damit ist gezeigt, dass das Sudoku-Problem einen polynomiellen
28 | Verifizierer hat, also in NP ist.
29 |
30 | Wenn $\text{P}=\text{NP}$ ist, dann muss es auch einen polynomiellen
31 | Algorithmus geben, der Sudokus löst.
32 | \end{loesung}
33 |
--------------------------------------------------------------------------------
/aufgaben/7/70000020/calcudoku-problem.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000020/calcudoku-problem.png
--------------------------------------------------------------------------------
/aufgaben/7/70000020/calcudoku-solved.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000020/calcudoku-solved.png
--------------------------------------------------------------------------------
/aufgaben/7/70000022/HashiwokakeroBeispiel.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000022/HashiwokakeroBeispiel.pdf
--------------------------------------------------------------------------------
/aufgaben/7/70000022/HashiwokakeroLoesung.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000022/HashiwokakeroLoesung.pdf
--------------------------------------------------------------------------------
/aufgaben/7/70000024/fill1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000024/fill1.png
--------------------------------------------------------------------------------
/aufgaben/7/70000024/fill8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000024/fill8.png
--------------------------------------------------------------------------------
/aufgaben/7/70000027/answer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000027/answer.png
--------------------------------------------------------------------------------
/aufgaben/7/70000027/example.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000027/example.png
--------------------------------------------------------------------------------
/aufgaben/7/70000030/Hitori.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000030/Hitori.png
--------------------------------------------------------------------------------
/aufgaben/7/70000030/Hitoricompleted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000030/Hitoricompleted.png
--------------------------------------------------------------------------------
/aufgaben/7/70000032/example-big.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000032/example-big.png
--------------------------------------------------------------------------------
/aufgaben/7/70000032/solution-big.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000032/solution-big.png
--------------------------------------------------------------------------------
/aufgaben/7/70000034/lightup-solution.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000034/lightup-solution.png
--------------------------------------------------------------------------------
/aufgaben/7/70000034/lightup.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000034/lightup.png
--------------------------------------------------------------------------------
/aufgaben/7/70000037/Flow-aufgabe.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000037/Flow-aufgabe.png
--------------------------------------------------------------------------------
/aufgaben/7/70000037/Flow-loesung.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000037/Flow-loesung.png
--------------------------------------------------------------------------------
/aufgaben/7/70000037/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile -- build images for problem 70000037
3 | #
4 | # (c) 2016 Prof Dr Andreas Müller
5 | #
6 | spielname=Flow
7 | all: $(spielname)-aufgabe.png $(spielname)-loesung.png
8 |
9 | geometry = 749x749+0+314
10 |
11 | $(spielname)-aufgabe.png: links-aufgabe.png Makefile
12 | convert -extract $(geometry) links-aufgabe.png $(spielname)-aufgabe.png
13 |
14 | $(spielname)-loesung.png: links-loesung.png Makefile
15 | convert -extract $(geometry) links-loesung.png $(spielname)-loesung.png
16 |
--------------------------------------------------------------------------------
/aufgaben/7/70000048/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile -- Nurimaze-Beispiel
3 | #
4 | # (c) 2018 Prof Dr Andreas Müller
5 | #
6 | nurimaze.pdf: nurimaze.tex
7 | pdflatex nurimaze.tex
8 |
--------------------------------------------------------------------------------
/aufgaben/7/70000048/nurimaze.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000048/nurimaze.pdf
--------------------------------------------------------------------------------
/aufgaben/7/70000050/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile -- build
3 | #
4 | # (c) 2019 Prof Dr Andreas Müller, Hochschule Rapperswil
5 | #
6 | all: graph.pdf graph-loesung.pdf
7 |
8 | graph.pdf: graph.tex graph-common.tex
9 | pdflatex graph.tex
10 |
11 | graph-loesung.pdf: graph-loesung.tex graph-common.tex
12 | pdflatex graph-loesung.tex
13 |
14 |
15 |
--------------------------------------------------------------------------------
/aufgaben/7/70000050/graph-loesung.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000050/graph-loesung.pdf
--------------------------------------------------------------------------------
/aufgaben/7/70000050/graph.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000050/graph.pdf
--------------------------------------------------------------------------------
/aufgaben/7/70000065/license.txt:
--------------------------------------------------------------------------------
1 | Bild von jcomp auf Freepik
2 |
--------------------------------------------------------------------------------
/aufgaben/7/70000065/puzzle-mit-fehlendem-stueck-fehlende-puzzleteile.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000065/puzzle-mit-fehlendem-stueck-fehlende-puzzleteile.jpg
--------------------------------------------------------------------------------
/aufgaben/7/70000065/puzzle.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/aufgaben/7/70000065/puzzle.jpg
--------------------------------------------------------------------------------
/aufgaben/7/70000069.tex:
--------------------------------------------------------------------------------
1 | Formulieren Sie das $n$-Damenproblem als $k$-\textit{CLIQUE}-Problem.
2 |
3 | \thema{polyomielle Reduktion}
4 |
5 | \begin{loesung}
6 | In einem $k$-\textit{CLIQUE}-Problem müssen Knoten eines Graphen
7 | ausgewählt werden, die alle miteinander verbunden sind.
8 | Für das Problem \textit{QUEENS} kann man für jedes Feld des Spielfeldes
9 | einen Knoten des Graphen anlegen.
10 | Zwei Knoten werden miteinander verbunden, wenn Damen auf den zugehörigen
11 | Feldern sich nicht gegenseitig schlagen können.
12 | So entsteht ein Graph mit $n^2$ Knoten.
13 | Eine Lösung des $n$-Damenproblems ist eine Auswahl von $n$ Feldern,
14 | auf denen Damen platziert werden können, die sich gegenseitig
15 | nicht schlagen können.
16 | Dies entspricht der Auswahl von $n$ Knoten des Graphen, die sich
17 | gegenseitig nicht schlagen können.
18 | Letzteres ist gleichbedeutend damit, dass die ausgewählten Knoten
19 | alle miteinander verbunden sind.
20 |
21 | Dem $n$-Damenproblem entspricht daher eine Instanz des
22 | $n$-\textit{CLIQUE}-Problems.
23 | \end{loesung}
24 |
--------------------------------------------------------------------------------
/aufgaben/8/80000003.tex:
--------------------------------------------------------------------------------
1 | Beschreiben Sie die Grammatik der Sprache RISC-GOTO, die analog zu
2 | RISC-WHILE gebildet wird.
3 |
4 | \thema{GOTO}
5 |
6 | \begin{loesung}
7 | In der folgenden Grammatik steht $P$ für ein Programm, $L$ für
8 | eine Programmzeile, $M$ für eine Zeilennummer, $A$ für eine
9 | Anweisung, $N$ für eine natürliche Zahl, $C$ für eine Konstante,
10 | $D$ für eine Ziffer:
11 | \begin{align*}
12 | P&\rightarrow P\; L\\
13 | &\rightarrow L\\
14 | L&\rightarrow M\colon \; A\\
15 | M&\rightarrow N\\
16 | A&\rightarrow r := x_i\\
17 | &\rightarrow x_i := r\\
18 | &\rightarrow r := r + C\\
19 | &\rightarrow r := r - C\\
20 | &\rightarrow \text{\tt IF } r = C \text{ \tt THEN GOTO } M\\
21 | &\rightarrow \texttt{INCR}\\
22 | &\rightarrow \texttt{DECR}\\
23 | C&\rightarrow N\\
24 | N&\rightarrow D\\
25 | &\rightarrow ND\\
26 | D&\rightarrow
27 | \text{'0'}\mid
28 | \text{'1'}\mid
29 | \text{'2'}\mid
30 | \text{'3'}\mid
31 | \text{'4'}\mid
32 | \text{'5'}\mid
33 | \text{'6'}\mid
34 | \text{'7'}\mid
35 | \text{'8'}\mid
36 | \text{'9'}
37 | \end{align*}
38 | \end{loesung}
39 |
--------------------------------------------------------------------------------
/aufgaben/README:
--------------------------------------------------------------------------------
1 | Die Aufgaben in diesem Verzeichnis verwenden folgende systematische
2 | Numerierung, mit der sie einem Kapitel des Skriptes zugeordnet werden
3 | k"onnen:
4 |
5 | CSSSPPPP.tex
6 |
7 | C = Kapitelnummer
8 | SSS = drei Stellen fuer eine Unterstrukturierung des Kaptels, sofern
9 | notwendig und sinnvoll
10 | PPPP = Laufnummer der Aufgabe
11 |
12 | Kapitelnummern
13 |
14 | C Kapitel
15 | 1 Grundlagen
16 | 2 Sprachen
17 | 3 Regulaere Sprachen
18 | 4 Stackautomaten und kontextfreie Sprachen
19 | 5 Turing Maschinen
20 | 6 Entscheidbarkeit
21 | 7 Komplexitaetstheorie
22 | 8 Turing-Vollstaendigkeit
23 |
--------------------------------------------------------------------------------
/aufgaben/aufgabensammlung.tex:
--------------------------------------------------------------------------------
1 | %
2 | % aufgabensammlung.tex -- Skript zur Vorlesung Automaten und Sprachen
3 | % an der Hochschule Rapperswil
4 | %
5 | % (c) 2009-2017 Prof. Dr. Andreas Mueller, HSR
6 | %
7 | \documentclass[a4paper,12pt]{book}
8 | \input{macros/packages.tex}
9 | \makeindex
10 | \begin{document}
11 | \input{macros/front.tex}
12 | \mainmatter
13 | \input{macros/uebungen.tex}
14 | \setboolean{showthema}{true}
15 | \allowdisplaybreaks
16 | \openthemaindex
17 | \setboolean{showthema}{true}
18 | \setboolean{loesungen}{true}
19 | \aufgabetoplevel{./}
20 | \input{macros/vorwort.tex}
21 | \input{macros/content.tex}
22 | \end{document}
23 |
--------------------------------------------------------------------------------
/aufgaben/buildchapter.sh:
--------------------------------------------------------------------------------
1 | #! /bin/sh
2 | #
3 | # build a chapter include file
4 | #
5 | # (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
6 | #
7 | if [ ! -d "${1}" ]
8 | then
9 | echo "must specify directory"
10 | exit 1
11 | fi
12 | dir="${1}"
13 | cd ${dir}
14 | ls *.tex | awk '{
15 | file = substr($1, 1, length($1) - 4)
16 | printf("\\aufgabe{%s}\n", file)
17 | }'
18 |
--------------------------------------------------------------------------------
/aufgaben/macros/content.tex:
--------------------------------------------------------------------------------
1 | %
2 | % content.tex
3 | %
4 | % (c) 2023 Prof Dr Andreas Müller
5 | %
6 | \chapter{Grundlagen}
7 | \lhead{Kapitel~\thechapter}
8 | \rhead{Grundlagen}
9 | \input{work/1.tex}
10 | \chapter{Sprachen}
11 | \lhead{Kapitel~\thechapter}
12 | \rhead{Sprachen}
13 | \input{work/2.tex}
14 | \chapter{Endliche Automaten und reguläre Sprachen}
15 | \lhead{Kapitel~\thechapter}
16 | \rhead{Endliche Automaten und reguläre Sprachen}
17 | \input{work/3.tex}
18 | \chapter{Stackautomaten und kontextfreie Sprachen}
19 | \lhead{Kapitel~\thechapter}
20 | \rhead{Stackautomaten und kontextfreie Sprachen}
21 | \input{work/4.tex}
22 | \chapter{Turing Maschinen}
23 | \lhead{Kapitel~\thechapter}
24 | \rhead{Turing Maschinen}
25 | \input{work/5.tex}
26 | \chapter{Entscheidbarkeit}
27 | \lhead{Kapitel~\thechapter}
28 | \rhead{Entscheidbarkeit}
29 | \input{work/6.tex}
30 | \chapter{Komplexitätstheorie}
31 | \lhead{Kapitel~\thechapter}
32 | \rhead{Komplexitätstheorie}
33 | \input{work/7.tex}
34 | \chapter{Turing-Vollständigkeit}
35 | \lhead{Kapitel~\thechapter}
36 | \rhead{Turing-Vollständigkeit}
37 | \input{work/8.tex}
38 | \closethemaindex
39 |
40 | \printthemata
41 | \input{work/aufgabensammlung.ind}
42 |
--------------------------------------------------------------------------------
/aufgaben/macros/front.tex:
--------------------------------------------------------------------------------
1 | %
2 | % front.tex
3 | %
4 | % (c) 2023 Prof Dr Andreas Müller
5 | %
6 | \pagestyle{fancy}
7 | \lhead{Aufgabensammlung}
8 | \rhead{}
9 | \frontmatter
10 | \newcommand\HRule{\noindent\rule{\linewidth}{1.5pt}}
11 | \begin{titlepage}
12 | \vspace*{\stretch{1}}
13 | \HRule
14 | \vspace*{2pt}
15 | \begin{flushright}
16 | {\Huge
17 | Automaten und Sprachen:\\
18 | \bigskip
19 | Aufgabensammlung}
20 | \end{flushright}
21 | \HRule
22 | \begin{flushright}
23 | \vspace{30pt}
24 | \LARGE
25 | Andreas Müller
26 | \end{flushright}
27 | \vspace*{\stretch{2}}
28 | \begin{center}
29 | Hochschule für Technik, Rapperswil, 2011--2020\\
30 | OST Ostschweizer Fachhochschule, Rapperswil, 2020--2025
31 | \end{center}
32 | \end{titlepage}
33 | \hypersetup{
34 | colorlinks=true,
35 | linktoc=all,
36 | linkcolor=blue
37 | }
38 | \rhead{Inhaltsverzeichnis}
39 | \tableofcontents
40 |
--------------------------------------------------------------------------------
/aufgaben/macros/packages.tex:
--------------------------------------------------------------------------------
1 | %
2 | % packages.tex
3 | %
4 | % (c) 2023 Prof Dr Andreas Müller
5 | %
6 | \usepackage[utf8]{inputenc}
7 | \usepackage[T1]{fontenc}
8 | \usepackage{CJKutf8}
9 | \usepackage{german}
10 | \usepackage{times}
11 | \usepackage{geometry}
12 | \geometry{papersize={210mm,297mm},total={160mm,240mm},top=31mm,bindingoffset=15mm,marginparwidth=9mm}
13 | \usepackage{alltt}
14 | \usepackage{verbatim}
15 | \usepackage{fancyhdr}
16 | \usepackage{amsmath}
17 | \usepackage{amssymb}
18 | \usepackage{amsfonts}
19 | \usepackage{amsthm}
20 | \usepackage{textcomp}
21 | \usepackage{graphicx}
22 | \usepackage{array}
23 | %\usepackage{picins}
24 | \usepackage{ifthen}
25 | \usepackage{multirow}
26 | \usepackage{multicol}
27 | \usepackage{txfonts}
28 | %\usepackage[basic]{circ}
29 | \usepackage[all]{xy}
30 | \usepackage{algorithm}
31 | \usepackage{algorithmic}
32 | \usepackage{makeidx}
33 | \usepackage{paralist}
34 | \usepackage{color}
35 | \usepackage[colorlinks=true]{hyperref}
36 | \usepackage{environ}
37 | \usepackage{menukeys}
38 | \usepackage{pifont}
39 | \usepackage{etoolbox}
40 | \usepackage{bm}
41 | \usepackage{xr}
42 | \usetikzlibrary{arrows,scopes,calc,shapes.geometric}
43 | \usetikzlibrary{decorations.pathreplacing}
44 | \usetikzlibrary{calligraphy}
45 |
--------------------------------------------------------------------------------
/aufgaben/mkinclude:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | #
3 | # mkinclude -- create the Makefile.include
4 | #
5 | # (c) 2023 Prof Dr Andreas Müller
6 | #
7 | ls ?/????????.tex | awk 'BEGIN {
8 | printf("#\n")
9 | printf("# Makefile.include -- dependencies\n")
10 | printf("#\n")
11 | printf("# do not edit, created by mkinlcude\n");
12 | printf("# (c) 2023 Prof Dr Andreas Müller\n")
13 | printf("#\n")
14 | printf("aufgabenfiles = \\\n")
15 | }
16 | {
17 | printf("\t%s \\\n", $1)
18 | }
19 | END {
20 | printf("\t\n");
21 | }' > Makefile.include
22 |
--------------------------------------------------------------------------------
/aufgaben/mkvkf.sh:
--------------------------------------------------------------------------------
1 | #
2 | # mkvkf.sh -- create solutions for lecture problems
3 | #
4 | # (c) 2023 Prof Dr Andreas Müller
5 | #
6 |
7 | buildchapter () {
8 | echo argument: $1
9 | awk -F, 'BEGIN {
10 | woche = '"${1}"'
11 | }
12 | /^%/ {
13 | next
14 | }
15 | {
16 | if ((woche == 0) || (woche == $1)) {
17 | printf("%d %d %d %d\n", $1, $2, $3, $4)
18 | }
19 | }
20 | END {
21 | }' vkf.csv | while read woche kapitel nummer aufgabe
22 | do
23 | echo Woche: ${woche}
24 | echo Kapitel: ${kapitel}
25 | echo Nummer: ${nummer}
26 | echo Aufgabe: ${aufgabe}
27 | nummer1=`expr ${nummer} - 1`
28 | pdf=vkf/${woche}.${kapitel}.`expr ${nummer}`.pdf
29 | sed -e 's/KAPITEL/'"${kapitel}"'/g' \
30 | -e 's/NUMMER/'"${nummer1}"'/g' \
31 | -e 's/AUFGABE/'"${aufgabe}"'/g' vkf.template > vkf.tex
32 | pdflatex --output-directory=work vkf.tex >/dev/null 2>&1
33 | if [ -r work/vkf.pdf ]
34 | then
35 | mv work/vkf.pdf ${pdf}
36 | else
37 | echo failed to produce ${pdf}
38 | echo see vkf/vkf.log for details
39 | exit 1
40 | fi
41 | done
42 | }
43 |
44 | if [ $# -gt 0 ]
45 | then
46 | while [ $# -gt 0 ]
47 | do
48 | chapter=$1
49 | echo "working on chapter ${chapter}"
50 | buildchapter ${chapter}
51 | shift
52 | done
53 | else
54 | buildchapter 0
55 | fi
56 |
57 | exit 0
58 |
--------------------------------------------------------------------------------
/aufgaben/ohnethema.sh:
--------------------------------------------------------------------------------
1 | #
2 | # ohnethema.sh -- Aufgaben ohne Thema-Zuordnung auflisten
3 | #
4 | # (c) 2021 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
5 | #
6 | for f in ?/*.tex
7 | do
8 | if egrep -q '\\themaL?{' $f
9 | then
10 | :
11 | else
12 | echo $f
13 | fi
14 | done
15 |
--------------------------------------------------------------------------------
/aufgaben/test.tex:
--------------------------------------------------------------------------------
1 | %
2 | % test.tex -- Skript zur Vorlesung Automaten und Sprachen
3 | % an der Hochschule Rapperswil
4 | %
5 | % (c) 2009-2017 Prof. Dr. Andreas Mueller, HSR
6 | %
7 | \documentclass[a4paper,12pt]{book}
8 | \input{macros/packages.tex}
9 | \makeindex
10 | \begin{document}
11 | \pagestyle{fancy}
12 | \input{macros/uebungen.tex}
13 | \definecolor{darkgreen}{rgb}{0,0.6,0}
14 | \setboolean{loesungen}{true}
15 | \setboolean{showthema}{false}
16 | \aufgabetoplevel{./}
17 | \setcounter{chapter}{7}
18 | \lhead{Kapitel~\thechapter}
19 | \rhead{Formattiertest}
20 | \openthemaindex
21 | \noindent
22 | \bigskip
23 |
24 | \input{testaufgabe.tex}
25 | \closethemaindex
26 | \end{document}
27 |
--------------------------------------------------------------------------------
/aufgaben/testaufgabe.tex:
--------------------------------------------------------------------------------
1 | %
2 | % testaufgabe.tex
3 | %
4 | % (c) 2023 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
5 | %
6 | %\aufgabe{70000041}
7 | \aufgabe{40000072}
8 | %\aufgabe{60000035}
9 |
--------------------------------------------------------------------------------
/aufgaben/themaliste.sh:
--------------------------------------------------------------------------------
1 | #
2 | # themaliste.sh -- list all topics
3 | #
4 | # (c) 2021 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
5 | #
6 | egrep -h -e '\\themaL?{' ?/*.tex | awk 'BEGIN {
7 | counter = 0;
8 | }
9 | /thema{/ {
10 | printf("%s\n", substr($0, 7));
11 | }
12 | /themaL{/ {
13 | printf("%s\n", substr($0, 8));
14 | }
15 | ' | sort | uniq -c
16 |
--------------------------------------------------------------------------------
/aufgaben/vkf.template:
--------------------------------------------------------------------------------
1 | %
2 | % vkf.template
3 | %
4 | % (c) 2023 Prof. Dr. Andreas Mueller, OST
5 | %
6 | \documentclass[a4paper,12pt]{book}
7 | \input{macros/packages.tex}
8 | \externaldocument{work/aufgabensammlung}
9 | \makeindex
10 | \begin{document}
11 | \let\thechapter=KAPITEL
12 | \input{macros/uebungen.tex}
13 | \openthemaindex
14 | \setboolean{loesungen}{true}
15 | \allowdisplaybreaks
16 | \aufgabetoplevel{./}
17 | \setcounter{problemcounter}{NUMMER}
18 | \aufgabe{AUFGABE}
19 | \end{document}
20 |
--------------------------------------------------------------------------------
/aufgaben/vkf/README:
--------------------------------------------------------------------------------
1 | Verzeichnis für Verständnis-Kontroll-Fragen
2 |
--------------------------------------------------------------------------------
/aufgaben/woche01.tex:
--------------------------------------------------------------------------------
1 | %
2 | % woche01.tex --
3 | %
4 | % (c) 2023 Prof. Dr. Andreas Mueller, OST
5 | %
6 | \documentclass[a4paper,12pt]{book}
7 | \input{macros/packages.tex}
8 | \externaldocument{work/aufgabensammlung}
9 | \makeindex
10 | \begin{document}
11 | \pagestyle{fancy}
12 | \let\thechapter=1
13 | \lhead{Kapitel~\thechapter, Woche 1}
14 | \rhead{Grundlagen}
15 | \input{macros/uebungen.tex}
16 | \setboolean{loesungen}{true}
17 | \aufgabetoplevel{./}
18 | \setcounter{problemcounter}{8}
19 | \aufgabe{10000009}
20 | \aufgabe{10000010}
21 | \setcounter{problemcounter}{12}
22 | \aufgabe{10000013}
23 | \aufgabe{10000014}
24 | \setcounter{problemcounter}{14}
25 | \aufgabe{10000017}
26 | \let\thechapter=2
27 | \rhead{Sprachen}
28 | \setcounter{problemcounter}{3}
29 | \aufgabe{20000005}
30 | \aufgabe{20000006}
31 | \end{document}
32 |
33 |
--------------------------------------------------------------------------------
/aufgaben/woche02.tex:
--------------------------------------------------------------------------------
1 | %
2 | % woche02.tex --
3 | %
4 | % (c) 2023 Prof. Dr. Andreas Mueller, OST
5 | %
6 | \documentclass[a4paper,12pt]{book}
7 | \input{macros/packages.tex}
8 | \externaldocument{work/aufgabensammlung}
9 | \makeindex
10 | \begin{document}
11 | \pagestyle{fancy}
12 | \let\thechapter=3
13 | \lhead{Kapitel~\thechapter, Woche 2}
14 | \rhead{Endliche Automaten und reguläre Sprachen}
15 | \input{macros/uebungen.tex}
16 | \setboolean{loesungen}{true}
17 | \aufgabetoplevel{./}
18 | \setcounter{problemcounter}{79}
19 | \aufgabe{30000082}
20 | \aufgabe{30000083}
21 | \aufgabe{30000084}
22 | \aufgabe{30000085}
23 | \aufgabe{30000086}
24 | \end{document}
25 |
--------------------------------------------------------------------------------
/aufgaben/woche03.tex:
--------------------------------------------------------------------------------
1 | %
2 | % woche03.tex --
3 | %
4 | % (c) 2023 Prof. Dr. Andreas Mueller, OST
5 | %
6 | \documentclass[a4paper,12pt]{book}
7 | \input{macros/packages.tex}
8 | \externaldocument{work/aufgabensammlung}
9 | \makeindex
10 | \begin{document}
11 | \pagestyle{fancy}
12 | \let\thechapter=3
13 | \lhead{Kapitel~\thechapter, Woche 3}
14 | \rhead{Endliche Automaten und reguläre Sprachen}
15 | \input{macros/uebungen.tex}
16 | \setboolean{loesungen}{true}
17 | \aufgabetoplevel{./}
18 | \setcounter{problemcounter}{84}
19 | \aufgabe{30000087}
20 | \aufgabe{30000088}
21 | \aufgabe{30000089}
22 | \aufgabe{30000090}
23 | \aufgabe{30000091}
24 | \aufgabe{30000092}
25 | \end{document}
26 |
27 |
--------------------------------------------------------------------------------
/aufgaben/woche04.tex:
--------------------------------------------------------------------------------
1 | %
2 | % woche04.tex --
3 | %
4 | % (c) 2023 Prof. Dr. Andreas Mueller, OST
5 | %
6 | \documentclass[a4paper,12pt]{book}
7 | \input{macros/packages.tex}
8 | \externaldocument{work/aufgabensammlung}
9 | \makeindex
10 | \begin{document}
11 | \pagestyle{fancy}
12 | \let\thechapter=3
13 | \lhead{Kapitel~\thechapter, Woche 4}
14 | \rhead{Endliche Automaten und reguläre Sprachen}
15 | \input{macros/uebungen.tex}
16 | \setboolean{loesungen}{true}
17 | \aufgabetoplevel{./}
18 | \setcounter{problemcounter}{90}
19 | \aufgabe{30000093}
20 | \aufgabe{30000094}
21 | \aufgabe{30000095}
22 | \setcounter{problemcounter}{94}
23 | \aufgabe{30000097}
24 | \aufgabe{30000098}
25 | \end{document}
26 |
27 |
--------------------------------------------------------------------------------
/aufgaben/woche05.tex:
--------------------------------------------------------------------------------
1 | %
2 | % woche05.tex --
3 | %
4 | % (c) 2023 Prof. Dr. Andreas Mueller, OST
5 | %
6 | \documentclass[a4paper,12pt]{book}
7 | \input{macros/packages.tex}
8 | \externaldocument{work/aufgabensammlung}
9 | \makeindex
10 | \begin{document}
11 | \pagestyle{fancy}
12 | \let\thechapter=4
13 | \lhead{Kapitel~\thechapter, Woche 5}
14 | \rhead{Kontextfreie Grammatiken}
15 | \input{macros/uebungen.tex}
16 | \openthemaindex
17 | \setboolean{loesungen}{true}
18 | \allowdisplaybreaks
19 | \aufgabetoplevel{./}
20 | \setcounter{problemcounter}{73}
21 | \aufgabe{40000075}
22 | \aufgabe{40000076}
23 | \aufgabe{40000077}
24 | \aufgabe{40000078}
25 | \aufgabe{40000079}
26 | \aufgabe{40000080}
27 | \aufgabe{40000081}
28 | \end{document}
29 |
--------------------------------------------------------------------------------
/aufgaben/woche06.tex:
--------------------------------------------------------------------------------
1 | %
2 | % woche06.tex --
3 | %
4 | % (c) 2023 Prof. Dr. Andreas Mueller, OST
5 | %
6 | \documentclass[a4paper,12pt]{book}
7 | \input{macros/packages.tex}
8 | \externaldocument{work/aufgabensammlung}
9 | \makeindex
10 | \begin{document}
11 | \pagestyle{fancy}
12 | \let\thechapter=4
13 | \lhead{Kapitel~\thechapter, Woche 6}
14 | \rhead{Parsing und Stackautomaten}
15 | \input{macros/uebungen.tex}
16 | \openthemaindex
17 | \setboolean{loesungen}{true}
18 | \allowdisplaybreaks
19 | \aufgabetoplevel{./}
20 | \setcounter{problemcounter}{80}
21 | \aufgabe{40000082}
22 | \setcounter{problemcounter}{83}
23 | \aufgabe{40000085}
24 | \setcounter{problemcounter}{81}
25 | \aufgabe{40000083}
26 | \aufgabe{40000084}
27 | \end{document}
28 |
--------------------------------------------------------------------------------
/aufgaben/woche07.tex:
--------------------------------------------------------------------------------
1 | %
2 | % woche07.tex --
3 | %
4 | % (c) 2023 Prof. Dr. Andreas Mueller, OST
5 | %
6 | \documentclass[a4paper,12pt]{book}
7 | \input{macros/packages.tex}
8 | \externaldocument{work/aufgabensammlung}
9 | \makeindex
10 | \begin{document}
11 | \pagestyle{fancy}
12 | \let\thechapter=4
13 | \lhead{Kapitel~\thechapter, Woche 7}
14 | \rhead{Nicht kontextfreie Sprachen}
15 | \input{macros/uebungen.tex}
16 | \openthemaindex
17 | \setboolean{loesungen}{true}
18 | \allowdisplaybreaks
19 | \aufgabetoplevel{./}
20 | \setcounter{problemcounter}{84}
21 | \aufgabe{40000086}
22 | \aufgabe{40000087}
23 | \aufgabe{40000088}
24 | \aufgabe{40000089}
25 | \aufgabe{40000090}
26 | \end{document}
27 |
--------------------------------------------------------------------------------
/aufgaben/woche08.tex:
--------------------------------------------------------------------------------
1 | %
2 | % woche08.tex --
3 | %
4 | % (c) 2023 Prof. Dr. Andreas Mueller, OST
5 | %
6 | \documentclass[a4paper,12pt]{book}
7 | \input{macros/packages.tex}
8 | \externaldocument{work/aufgabensammlung}
9 | \makeindex
10 | \begin{document}
11 | \pagestyle{fancy}
12 | \let\thechapter=5
13 | \lhead{Kapitel~\thechapter, Woche 8}
14 | \rhead{Turing-Maschinen}
15 | \input{macros/uebungen.tex}
16 | \openthemaindex
17 | \setboolean{loesungen}{true}
18 | \allowdisplaybreaks
19 | \aufgabetoplevel{./}
20 | \setcounter{problemcounter}{40}
21 | \aufgabe{50000041}
22 | \setcounter{problemcounter}{36}
23 | \aufgabe{50000037}
24 | \aufgabe{50000038}
25 | \aufgabe{50000039}
26 | \aufgabe{50000040}
27 | \end{document}
28 |
--------------------------------------------------------------------------------
/aufgaben/woche09.tex:
--------------------------------------------------------------------------------
1 | %
2 | % woche08.tex --
3 | %
4 | % (c) 2023 Prof. Dr. Andreas Mueller, OST
5 | %
6 | \documentclass[a4paper,12pt]{book}
7 | \input{macros/packages.tex}
8 | \externaldocument{work/aufgabensammlung}
9 | \makeindex
10 | \begin{document}
11 | \pagestyle{fancy}
12 | \let\thechapter=6
13 | \lhead{Kapitel~\thechapter, Woche 9}
14 | \rhead{Entscheidbarkeit}
15 | \input{macros/uebungen.tex}
16 | \openthemaindex
17 | \setboolean{loesungen}{true}
18 | \allowdisplaybreaks
19 | \aufgabetoplevel{./}
20 | \setcounter{problemcounter}{42}
21 | \aufgabe{60000047}
22 | \aufgabe{60000048}
23 | \aufgabe{60000049}
24 | \aufgabe{60000050}
25 | \aufgabe{60000051}
26 | \end{document}
27 |
--------------------------------------------------------------------------------
/aufgaben/woche10.tex:
--------------------------------------------------------------------------------
1 | %
2 | % woche10.tex --
3 | %
4 | % (c) 2023 Prof. Dr. Andreas Mueller, OST
5 | %
6 | \documentclass[a4paper,12pt]{book}
7 | \input{macros/packages.tex}
8 | \externaldocument{work/aufgabensammlung}
9 | \makeindex
10 | \begin{document}
11 | \pagestyle{fancy}
12 | \let\thechapter=7
13 | \lhead{Kapitel~\thechapter, Woche 10}
14 | \rhead{Komplexität, P und NP}
15 | \input{macros/uebungen.tex}
16 | \openthemaindex
17 | \setboolean{loesungen}{true}
18 | \allowdisplaybreaks
19 | \aufgabetoplevel{./}
20 | \setcounter{problemcounter}{65}
21 | \aufgabe{70000067}
22 | \aufgabe{70000068}
23 | \aufgabe{70000069}
24 | \aufgabe{70000070}
25 | \aufgabe{70000071}
26 | \end{document}
27 |
--------------------------------------------------------------------------------
/aufgaben/woche11.tex:
--------------------------------------------------------------------------------
1 | %
2 | % woche11.tex --
3 | %
4 | % (c) 2023 Prof. Dr. Andreas Mueller, OST
5 | %
6 | \documentclass[a4paper,12pt]{book}
7 | \input{macros/packages.tex}
8 | \externaldocument{work/aufgabensammlung}
9 | \makeindex
10 | \begin{document}
11 | \pagestyle{fancy}
12 | \let\thechapter=7
13 | \lhead{Kapitel~\thechapter, Woche 11}
14 | \rhead{NP-Vollständigkeit}
15 | \input{macros/uebungen.tex}
16 | \openthemaindex
17 | \setboolean{loesungen}{true}
18 | \allowdisplaybreaks
19 | \aufgabetoplevel{./}
20 | \setcounter{problemcounter}{70}
21 | \aufgabe{70000072}
22 | \aufgabe{70000073}
23 | \aufgabe{70000074}
24 | \aufgabe{70000075}
25 | \end{document}
26 |
--------------------------------------------------------------------------------
/aufgaben/woche12.tex:
--------------------------------------------------------------------------------
1 | %
2 | % woche12.tex --
3 | %
4 | % (c) 2023 Prof. Dr. Andreas Mueller, OST
5 | %
6 | \documentclass[a4paper,12pt]{book}
7 | \input{macros/packages.tex}
8 | \externaldocument{work/aufgabensammlung}
9 | \makeindex
10 | \begin{document}
11 | \pagestyle{fancy}
12 | \let\thechapter=8
13 | \lhead{Kapitel~\thechapter, Woche 12}
14 | \rhead{Karp-Katalog, Sprachen}
15 | \input{macros/uebungen.tex}
16 | \openthemaindex
17 | \setboolean{loesungen}{true}
18 | \allowdisplaybreaks
19 | \aufgabetoplevel{./}
20 | \setcounter{problemcounter}{3}
21 | \aufgabe{80000004}
22 | \end{document}
23 |
--------------------------------------------------------------------------------
/code/README:
--------------------------------------------------------------------------------
1 | Code-Beispiel als Anwendungen der Theorie
2 |
3 | regex Programme zur Demonstration der Leistungsfaehigkeit der
4 | regular expression matcher in verschiedenen Programmiersprachen
5 |
6 | calculator Einfaches Taschenrechner-Programm, welches aus einer
7 | kontextfreien Grammatik mit Hilfe eines Scanner-Generators
8 | (flex) und Parser-Generators (bison) aufgebaut wurde.
9 |
10 | minedemo Java-Programm zur Illustration des MINESWEEPER-CONSISTENCY
11 | Problems.
12 |
13 | turing Ein einfacher Turing-Maschinen-Simulator in C mit Beispielen,
14 | welche auch in der Vorlesung gezeigt wurden.
15 |
16 | gvm GOTO Virtual Machine. Zum Nachweis, dass GOTO eine Turing-
17 | vollstaendige Sprache ist, enthaelt dieses Verzeichnis den
18 | Source Code fuer eine virtuelle Maschine, die GOTO-Code
19 | ausfuehren kann, und eine Compiler, der beliebige Turing
20 | Maschinen-Beschreibungen (wie aus dem Verzeichnis turing/pgm)
21 | in GOTO code uebersetzen kann. Damit kann man eine universelle
22 | Turingmaschine auf einer GOTO Maschine simulieren.
23 |
24 |
--------------------------------------------------------------------------------
/code/calculator/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile to build the calculator project
3 | #
4 | # Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | #
6 | subdirs = \
7 | phase1 \
8 | phase2 \
9 | phase3 \
10 | phase4 \
11 | phase5 \
12 | phase6 \
13 | phase7 \
14 | phase8 \
15 | phase9 \
16 | phase10
17 |
18 | build:
19 | for p in 1 2 3 4 5 6 7 8 9 10; \
20 | do \
21 | (cd phase$${p} && make); \
22 | done
23 |
24 | clean:
25 | for p in 1 2 3 4 5 6 7 8 9 10; \
26 | do \
27 | (cd phase$${p}; make clean); \
28 | done
29 |
30 | diff:
31 | for p in 1 2 3 4 5 6 7 8 9 10; \
32 | do \
33 | q=`expr $${p} + 1`; \
34 | diff -ru phase$${p} phase$${q} > phase$${p}-phase$${q}.diff; \
35 | done; \
36 | exit 0
37 |
38 | diffps: diff
39 | for p in 1 2 3 4 5 6 7 8; \
40 | do \
41 | q=`expr $${p} + 1`; \
42 | name=phase$${p}-phase$${q}; \
43 | enscript -2rGE -p $${name}.ps $${name}.diff; \
44 | done
45 |
46 |
--------------------------------------------------------------------------------
/code/calculator/phase1/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile for the calculator project
3 | #
4 | CFLAGS = -g -O2 -Wall
5 |
6 | main: calculator
7 |
8 | tokens.c: tokens.l
9 |
10 | tokens.o: tokens.c
11 |
12 | grammar.h grammar.c: grammar.y
13 | bison -td grammar.y \
14 | && mv grammar.tab.h grammar.h \
15 | && mv grammar.tab.c grammar.c
16 |
17 | grammar.o: grammar.c
18 |
19 | calculator.o: calculator.c
20 |
21 | calculator: calculator.o tokens.o grammar.o
22 |
23 | clean:
24 | rm -f tokens.c grammar.c grammar.h *.o calculator
25 |
--------------------------------------------------------------------------------
/code/calculator/phase1/README:
--------------------------------------------------------------------------------
1 | Skelett bestehend aus
2 | - Tokenizer
3 | - Grammatik
4 | beide ohne irgendwelche Aktionen
5 |
--------------------------------------------------------------------------------
/code/calculator/phase1/calculator.c:
--------------------------------------------------------------------------------
1 | /*
2 | * calculator.c
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | */
6 | #include
7 | #include
8 |
9 | extern int yydebug;
10 | extern int yyparse();
11 |
12 | void yyerror(char *errmsg) {
13 | }
14 |
15 | int yywrap() {
16 | return 1;
17 | }
18 |
19 | int main(int argc, char *argv[]) {
20 | yydebug = 1;
21 | while (!feof(stdin)) {
22 | yyparse();
23 | }
24 | return 0;
25 | }
26 |
--------------------------------------------------------------------------------
/code/calculator/phase1/grammar.y:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * expression parser example
4 | *
5 | * (c) 2009 Prof Dr Andreas Mueller
6 | */
7 | extern void yyerror(char *errmsg);
8 | extern int yylex(void);
9 | %}
10 | %token NUMBER
11 | %%
12 | exprline: expr '\n'
13 | | expr ';'
14 | ;
15 | expr: term
16 | | expr '+' term
17 | | expr '-' term
18 | ;
19 | term: term '*' factor
20 | | term '/' factor
21 | | factor
22 | ;
23 | factor: '(' expr ')'
24 | | NUMBER
25 | ;
26 |
27 | %%
28 |
29 |
--------------------------------------------------------------------------------
/code/calculator/phase1/tokens.l:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * lexer for the calculator
4 | */
5 | %}
6 | %%
7 | [0-9]+(\.[0-9]*)?([eE]-?[0-9]+)?
8 | [+/\-*]
9 | \(|\)
10 | " "
11 | ;
12 | \n
13 | %%
14 |
--------------------------------------------------------------------------------
/code/calculator/phase10/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile for the calculator project
3 | #
4 | CFLAGS = -g -O2 -Wall
5 | LDFLAGS = -lm
6 |
7 | main: calculator
8 |
9 | tokens.c: tokens.l
10 |
11 | tokens.o: tokens.c grammar.h
12 |
13 | grammar.h grammar.c: grammar.y
14 | bison -td grammar.y \
15 | && mv grammar.tab.h grammar.h \
16 | && mv grammar.tab.c grammar.c
17 |
18 | grammar.o: grammar.c grammar.h constants.h
19 |
20 | constants.o: constants.c constants.h
21 |
22 | calculator.o: calculator.c
23 |
24 | calculator: calculator.o tokens.o grammar.o constants.o
25 | gcc calculator.o tokens.o grammar.o constants.o -lm -o calculator
26 |
27 | clean:
28 | rm -f tokens.c grammar.c grammar.h *.o calculator
29 |
--------------------------------------------------------------------------------
/code/calculator/phase10/README:
--------------------------------------------------------------------------------
1 | - monadisches Minus
2 | - implizites *: 6/2(1+2)
3 |
--------------------------------------------------------------------------------
/code/calculator/phase10/calculator.c:
--------------------------------------------------------------------------------
1 | /*
2 | * calculator.c
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | */
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | extern int yydebug;
12 | extern int yyparse();
13 |
14 | void yyerror(char *errmsg) {
15 | fprintf(stderr, "error: %s\n", errmsg);
16 | }
17 |
18 | int yywrap() {
19 | return 1;
20 | }
21 |
22 | int main(int argc, char *argv[]) {
23 | yydebug = 0;
24 | int c;
25 | while (EOF != (c = getopt(argc, argv, "d")))
26 | switch (c) {
27 | case 'd': yydebug = 1;
28 | break;
29 | }
30 | while (!feof(stdin)) {
31 | yyparse();
32 | }
33 | return 0;
34 | }
35 |
--------------------------------------------------------------------------------
/code/calculator/phase10/constants.c:
--------------------------------------------------------------------------------
1 | /*
2 | * constants.c -- constant lookup
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | */
6 | #include "constants.h"
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | double constant(const char *name) {
13 | if (0 == strcmp(name, "pi")) {
14 | return M_PI;
15 | }
16 | if (0 == strcmp(name, "e")) {
17 | return exp(1);
18 | }
19 | if (0 == strcmp(name, "gamma")) {
20 | return 0.57721566490153286060651;
21 | }
22 | if (0 == strcmp(name, "phi")) {
23 | return (1+sqrt(5))/2;
24 | }
25 | fprintf(stderr, "unknown constant %s\n", name);
26 | exit(EXIT_FAILURE);
27 | }
28 |
--------------------------------------------------------------------------------
/code/calculator/phase10/constants.h:
--------------------------------------------------------------------------------
1 | /*
2 | * constants.h
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | * $Id$
6 | */
7 | #ifndef _constants_h
8 | #define _constants_h
9 |
10 | extern double constant(const char *name);
11 |
12 | #endif /* _constants_h */
13 |
14 |
--------------------------------------------------------------------------------
/code/calculator/phase10/tokens.l:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * lexer for the calculator
4 | */
5 | #include "grammar.h"
6 | %}
7 | %%
8 | abs { return ABS; }
9 | asinh { return ASINH; }
10 | acosh { return ACOSH; }
11 | atanh { return ATANH; }
12 | sinh { return SINH; }
13 | cosh { return COSH; }
14 | tanh { return TANH; }
15 | asin { return ASIN; }
16 | acos { return ACOS; }
17 | atan2 { return ATAN2; }
18 | atan { return ATAN; }
19 | sin { return SIN; }
20 | cos { return COS; }
21 | tan { return TAN; }
22 | hypot { return HYPOT; }
23 | cbrt { return CBRT; }
24 | sqrt { return SQRT; }
25 | log { return LOG; }
26 | log10 { return LOG10; }
27 | log2 { return LOG2; }
28 | exp { return EXP; }
29 | j0 { return J0; }
30 | j1 { return J1; }
31 | jn { return JN; }
32 | y0 { return Y0; }
33 | y1 { return Y1; }
34 | yn { return YN; }
35 | gamma { return GAMMA; }
36 | erf { return ERF; }
37 | \%\% { return PREVIOUS; }
38 | \%[a-z]+ {
39 | strncpy(yylval.name, yytext + 1, 9);
40 | return CONSTANT;
41 | }
42 | r[0-9][0-9]? {
43 | yylval.reg = atoi(yytext + 1);
44 | return REGISTER;
45 | }
46 | [0-9]+(\.[0-9]*)?([eE]-?[0-9]+)? {
47 | yylval.value = atof(yytext);
48 | printf("value = %f\n", yylval.value);
49 | return NUMBER;
50 | }
51 | [+/\-*^=] { return yytext[0]; }
52 | \(|\) { return yytext[0]; }
53 | " " { }
54 | ; { return ';'; }
55 | , { return ','; }
56 | \n { return '\n'; }
57 | %%
58 |
--------------------------------------------------------------------------------
/code/calculator/phase11/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile for the calculator project
3 | #
4 | CFLAGS = -g -O2 -Wall
5 | LDFLAGS = -lm
6 |
7 | main: calculator
8 |
9 | tokens.c: tokens.l
10 |
11 | tokens.o: tokens.c grammar.h
12 |
13 | grammar.h grammar.c: grammar.y
14 | bison -td grammar.y \
15 | && mv grammar.tab.h grammar.h \
16 | && mv grammar.tab.c grammar.c
17 |
18 | grammar.o: grammar.c grammar.h constants.h tree.h help.h
19 |
20 | constants.o: constants.c constants.h
21 |
22 | tree.o: tree.c tree.h constants.h functions.h grammar.h
23 |
24 | functions.o: functions.c functions.h
25 |
26 | help.o: help.c help.h
27 |
28 | libcalc.a: tokens.o grammar.o constants.o tree.o functions.o help.o
29 | ar r libcalc.a tokens.o grammar.o constants.o tree.o functions.o help.o
30 |
31 | calculator.o: calculator.c
32 |
33 | calculator: calculator.o libcalc.a
34 | gcc calculator.o -L. -lcalc -lm -o calculator
35 |
36 | clean:
37 | rm -f tokens.c grammar.c grammar.h *.o calculator
38 |
--------------------------------------------------------------------------------
/code/calculator/phase11/README:
--------------------------------------------------------------------------------
1 | - parse tree
2 | - Evaluation und Anzeige des Parse Tree
3 | - History von parse trees
4 | - Registerzuweisungen sind Faktoren, haben damit einen Wert und
5 | können auch im Inneren eines Ausdrucks vorkommen
6 | - neue Funktion: Fakultät, binom, div, mod, trunc, floor
7 | - Zufallszahlen mit rand()
8 |
9 |
--------------------------------------------------------------------------------
/code/calculator/phase11/calculator.c:
--------------------------------------------------------------------------------
1 | /*
2 | * calculator.c
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | */
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | extern int yydebug;
12 | extern int yyparse();
13 |
14 | void yyerror(char *errmsg) {
15 | fprintf(stderr, "error: %s\n", errmsg);
16 | }
17 |
18 | int yywrap() {
19 | return 1;
20 | }
21 |
22 | int main(int argc, char *argv[]) {
23 | yydebug = 0;
24 | int c;
25 | while (EOF != (c = getopt(argc, argv, "d")))
26 | switch (c) {
27 | case 'd': yydebug = 1;
28 | break;
29 | }
30 | fprintf(stdout, "i1> ");
31 | fflush(stdout);
32 | while (!feof(stdin)) {
33 | yyparse();
34 | }
35 | return 0;
36 | }
37 |
--------------------------------------------------------------------------------
/code/calculator/phase11/constants.c:
--------------------------------------------------------------------------------
1 | /*
2 | * constants.c -- constant lookup
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | */
6 | #include "constants.h"
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | double constant(const char *name) {
13 | if (0 == strcmp(name, "pi")) {
14 | return M_PI;
15 | }
16 | if (0 == strcmp(name, "e")) {
17 | return exp(1);
18 | }
19 | if (0 == strcmp(name, "gamma")) {
20 | return 0.57721566490153286060651;
21 | }
22 | if (0 == strcmp(name, "phi")) {
23 | return (1+sqrt(5))/2;
24 | }
25 | fprintf(stderr, "unknown constant %s\n", name);
26 | exit(EXIT_FAILURE);
27 | }
28 |
--------------------------------------------------------------------------------
/code/calculator/phase11/constants.h:
--------------------------------------------------------------------------------
1 | /*
2 | * constants.h
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | * $Id$
6 | */
7 | #ifndef _constants_h
8 | #define _constants_h
9 |
10 | extern double constant(const char *name);
11 |
12 | #endif /* _constants_h */
13 |
14 |
--------------------------------------------------------------------------------
/code/calculator/phase11/functions.c:
--------------------------------------------------------------------------------
1 | /*
2 | * functions.c -- more functions for the calculator
3 | *
4 | * (c) 2023 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
5 | */
6 | #include "functions.h"
7 | #include
8 |
9 | double binom(double n, double k) {
10 | int _k = 1;
11 | double result = 1;
12 | while (_k <= k) {
13 | result = result * n / _k;
14 | n = n - 1;
15 | _k = _k + 1;
16 | }
17 | return result;
18 | }
19 |
20 | double mod(double n, double k) {
21 | int result = (int)n % (int)k;
22 | return result;
23 | }
24 |
25 | double idiv(double n, double k) {
26 | int result = (int)n / (int)k;
27 | return result;
28 | }
29 |
--------------------------------------------------------------------------------
/code/calculator/phase11/functions.h:
--------------------------------------------------------------------------------
1 | /*
2 | * functions.h -- more functions for the calculator
3 | *
4 | * (c) 2023 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
5 | */
6 | #ifndef _functions_h
7 | #define _functions_h
8 |
9 | double binom(double n, double k);
10 | double mod(double n, double k);
11 | double idiv(double n, double k);
12 |
13 | #endif /* _functions_h */
14 |
--------------------------------------------------------------------------------
/code/calculator/phase11/help.h:
--------------------------------------------------------------------------------
1 | /*
2 | * help.h -- help functions
3 | *
4 | * (c) 2023 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
5 | */
6 | #ifndef _help_h
7 | #define _help_h
8 |
9 | void help();
10 |
11 | #endif /* _help_h */
12 |
--------------------------------------------------------------------------------
/code/calculator/phase11/tree.h:
--------------------------------------------------------------------------------
1 | /*
2 | * tree.h -- parse tree structure
3 | *
4 | * (c) 2023 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
5 | */
6 | #ifndef _tree_h
7 | #define _tree_h
8 |
9 | #include
10 | #include
11 |
12 | #define TERMINAL 400
13 | #define EXPR 401
14 | #define TERM 402
15 | #define FACTOR 403
16 |
17 | struct treenode_s;
18 | typedef struct treenode_s {
19 | char *nodename;
20 | int nodetype;
21 | double value;
22 | struct treenode_s **children;
23 | } treenode_t;
24 | typedef treenode_t *treenode_p;
25 |
26 | treenode_p treenode_new(char *name, int nodetype,
27 | treenode_p children, ...);
28 | treenode_p treenode_terminal(char *t);
29 | void treenode_free(treenode_p treenode);
30 | void treenode_add(treenode_p treenode, treenode_p child);
31 | extern int treewide;
32 | extern int tree_precision;
33 | extern int tree_format;
34 | #define TREE_FORMAT_FIXED 0
35 | #define TREE_FORMAT_FLOAT 1
36 | #define TREE_FORMAT_DEFAULT 2
37 |
38 | void treenode_format_number(FILE *out, double value);
39 | int treenode_children(treenode_p treenode);
40 | treenode_p treenode_child(treenode_p treenode, int i);
41 |
42 | double tree_value(treenode_p treenode);
43 | void tree_show(FILE *out, char *prefix, treenode_p treenode);
44 | void tree_print(FILE *out, treenode_p treenode);
45 | treenode_p tree_copy(treenode_p treenode);
46 |
47 | #endif /* _tree_h */
48 |
49 |
--------------------------------------------------------------------------------
/code/calculator/phase2/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile for the calculator project
3 | #
4 | CFLAGS = -g -O2 -Wall
5 |
6 | main: calculator
7 |
8 | tokens.c: tokens.l
9 |
10 | tokens.o: tokens.c grammar.h
11 |
12 | grammar.h grammar.c: grammar.y
13 | bison -td grammar.y \
14 | && mv grammar.tab.h grammar.h \
15 | && mv grammar.tab.c grammar.c
16 |
17 | grammar.o: grammar.c grammar.h
18 |
19 | calculator.o: calculator.c
20 |
21 | calculator: calculator.o tokens.o grammar.o
22 |
23 | clean:
24 | rm -f tokens.c grammar.c grammar.h *.o calculator
25 |
--------------------------------------------------------------------------------
/code/calculator/phase2/README:
--------------------------------------------------------------------------------
1 | - Rueckgabewerte des Lexers mit strukturierten Werten versehen
2 | - Zahlen werden vom Lexer erkannt und in double Werte umgewandelt
3 |
--------------------------------------------------------------------------------
/code/calculator/phase2/calculator.c:
--------------------------------------------------------------------------------
1 | /*
2 | * calculator.c
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | */
6 | #include
7 | #include
8 |
9 | extern int yydebug;
10 | extern int yyparse();
11 |
12 | void yyerror(char *errmsg) {
13 | }
14 |
15 | int yywrap() {
16 | return 1;
17 | }
18 |
19 | int main(int argc, char *argv[]) {
20 | yydebug = 1;
21 | while (!feof(stdin)) {
22 | yyparse();
23 | }
24 | return 0;
25 | }
26 |
--------------------------------------------------------------------------------
/code/calculator/phase2/grammar.y:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * expression parser example
4 | *
5 | * (c) 2009 Prof Dr Andreas Mueller
6 | */
7 | extern void yyerror(char *errmsg);
8 | extern int yylex(void);
9 |
10 | %}
11 | %union {
12 | double value;
13 | }
14 | %token NUMBER
15 | %%
16 | exprline: expr '\n'
17 | | expr ';'
18 | ;
19 | expr: term
20 | | expr '+' term
21 | | expr '-' term
22 | ;
23 | term: term '*' factor
24 | | term '/' factor
25 | | factor
26 | ;
27 | factor: '(' expr ')'
28 | | NUMBER
29 | ;
30 |
31 | %%
32 |
33 |
--------------------------------------------------------------------------------
/code/calculator/phase2/tokens.l:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * lexer for the calculator
4 | */
5 | #include "grammar.h"
6 | %}
7 | %%
8 | [0-9]+(\.[0-9]*)?([eE]-?[0-9]+)? {
9 | yylval.value = atof(yytext);
10 | printf("Zahlenwert: %f\n", yylval.value);
11 | return NUMBER;
12 | }
13 | [+/\-*] { return yytext[0]; }
14 | \(|\) { return yytext[0]; }
15 | " " { }
16 | ; { return ';'; }
17 | \n { return '\n'; }
18 | %%
19 |
--------------------------------------------------------------------------------
/code/calculator/phase3/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile for the calculator project
3 | #
4 | CFLAGS = -g -O2 -Wall
5 |
6 | main: calculator
7 |
8 | tokens.c: tokens.l
9 |
10 | tokens.o: tokens.c grammar.h
11 |
12 | grammar.h grammar.c: grammar.y
13 | bison -td grammar.y \
14 | && mv grammar.tab.h grammar.h \
15 | && mv grammar.tab.c grammar.c
16 |
17 | grammar.o: grammar.c grammar.h
18 |
19 | calculator.o: calculator.c
20 |
21 | calculator: calculator.o tokens.o grammar.o
22 |
23 | clean:
24 | rm -f tokens.c grammar.c grammar.h *.o calculator
25 |
26 | log: calculator
27 | echo '(1+3)*7' | ./calculator -d 2>&1 | egrep -ie 'shift|reduc'
28 |
--------------------------------------------------------------------------------
/code/calculator/phase3/README:
--------------------------------------------------------------------------------
1 | - Grammatik kann rechnen
2 |
--------------------------------------------------------------------------------
/code/calculator/phase3/calculator.c:
--------------------------------------------------------------------------------
1 | /*
2 | * calculator.c
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | */
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | extern int yydebug;
12 | extern int yyparse();
13 |
14 | void yyerror(char *errmsg) {
15 | }
16 |
17 | int yywrap() {
18 | return 1;
19 | }
20 |
21 | int main(int argc, char *argv[]) {
22 | yydebug = 0;
23 | int c;
24 | while (EOF != (c = getopt(argc, argv, "d")))
25 | switch (c) {
26 | case 'd': yydebug = 1;
27 | break;
28 | }
29 | while (!feof(stdin)) {
30 | yyparse();
31 | }
32 | return 0;
33 | }
34 |
--------------------------------------------------------------------------------
/code/calculator/phase3/grammar.y:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * expression parser example
4 | *
5 | * (c) 2012 Prof Dr Andreas Mueller
6 | */
7 | extern void yyerror(char *errmsg);
8 | extern int yylex(void);
9 |
10 | %}
11 | %union {
12 | double value;
13 | }
14 | %token NUMBER
15 | %type expr term factor
16 | %%
17 | exprline: expr '\n' { printf("%f\n", $1); }
18 | | expr ';' { printf("%f;\n", $1); }
19 | ;
20 | expr: term { $$ = $1; }
21 | | expr '+' term { $$ = $1 + $3; }
22 | | expr '-' term { $$ = $1 - $3; }
23 | ;
24 | term: term '*' factor { $$ = $1 * $3; }
25 | | term '/' factor { $$ = $1 / $3; }
26 | | factor { $$ = $1; }
27 | ;
28 | factor: '(' expr ')' { $$ = $2; }
29 | | NUMBER { $$ = $1; }
30 | ;
31 | %%
32 |
33 |
--------------------------------------------------------------------------------
/code/calculator/phase3/tokens.l:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * lexer for the calculator
4 | */
5 | #include "grammar.h"
6 | %}
7 | %%
8 | [0-9]+(\.[0-9]*)?([eE]-?[0-9]+)? {
9 | yylval.value = atof(yytext);
10 | return NUMBER;
11 | }
12 | [+/\-*] { return yytext[0]; }
13 | \(|\) { return yytext[0]; }
14 | " " { }
15 | ; { return ';'; }
16 | \n { return '\n'; }
17 | %%
18 |
--------------------------------------------------------------------------------
/code/calculator/phase4/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile for the calculator project
3 | #
4 | CFLAGS = -g -O2 -Wall
5 |
6 | main: calculator
7 |
8 | tokens.c: tokens.l
9 |
10 | tokens.o: tokens.c grammar.h
11 |
12 | grammar.h grammar.c: grammar.y
13 | bison -td grammar.y \
14 | && mv grammar.tab.h grammar.h \
15 | && mv grammar.tab.c grammar.c
16 |
17 | grammar.o: grammar.c grammar.h
18 |
19 | calculator.o: calculator.c
20 |
21 | calculator: calculator.o tokens.o grammar.o
22 |
23 | clean:
24 | rm -f tokens.c grammar.c grammar.h *.o calculator
25 |
--------------------------------------------------------------------------------
/code/calculator/phase4/README:
--------------------------------------------------------------------------------
1 | - Erweiterung der Grammatik: Listen von Ausdruecken
2 |
--------------------------------------------------------------------------------
/code/calculator/phase4/calculator.c:
--------------------------------------------------------------------------------
1 | /*
2 | * calculator.c
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | */
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | extern int yydebug;
12 | extern int yyparse();
13 |
14 | void yyerror(char *errmsg) {
15 | fprintf(stderr, "error: %s\n", errmsg);
16 | }
17 |
18 | int yywrap() {
19 | return 1;
20 | }
21 |
22 | int main(int argc, char *argv[]) {
23 | yydebug = 0;
24 | int c;
25 | while (EOF != (c = getopt(argc, argv, "d")))
26 | switch (c) {
27 | case 'd': yydebug = 1;
28 | break;
29 | }
30 | while (!feof(stdin)) {
31 | yyparse();
32 | }
33 | return 0;
34 | }
35 |
--------------------------------------------------------------------------------
/code/calculator/phase4/grammar.y:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * expression parser example
4 | *
5 | * (c) 2012 Prof Dr Andreas Mueller
6 | */
7 | extern void yyerror(char *errmsg);
8 | extern int yylex(void);
9 |
10 | %}
11 | %union {
12 | double value;
13 | }
14 | %token NUMBER
15 | %type expr term factor
16 | %%
17 | calculator:
18 | | exprline
19 | | calculator exprline
20 | ;
21 | exprline: expr '\n' { printf("result = %f\n", $1); }
22 | | expr ';' { printf("result = %f;\n", $1); }
23 | ;
24 | expr: term { $$ = $1; }
25 | | expr '+' term { $$ = $1 + $3; }
26 | | expr '-' term { $$ = $1 - $3; }
27 | ;
28 | term: term '*' factor { $$ = $1 * $3; }
29 | | term '/' factor { $$ = $1 / $3; }
30 | | factor { $$ = $1; }
31 | ;
32 | factor: '(' expr ')' { $$ = $2; }
33 | | NUMBER { $$ = $1; }
34 | ;
35 | %%
36 |
37 |
--------------------------------------------------------------------------------
/code/calculator/phase4/tokens.l:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * lexer for the calculator
4 | */
5 | #include "grammar.h"
6 | %}
7 | %%
8 | [0-9]+(\.[0-9]*)?([eE]-?[0-9]+)? {
9 | yylval.value = atof(yytext);
10 | printf("value = %f\n", yylval.value);
11 | return NUMBER;
12 | }
13 | [+/\-*] { return yytext[0]; }
14 | \(|\) { return yytext[0]; }
15 | " " { }
16 | ; { return ';'; }
17 | \n { return '\n'; }
18 | %%
19 |
--------------------------------------------------------------------------------
/code/calculator/phase5/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile for the calculator project
3 | #
4 | CFLAGS = -g -O2 -Wall
5 | LDFLAGS = -lm
6 |
7 | main: calculator
8 |
9 | tokens.c: tokens.l
10 |
11 | tokens.o: tokens.c grammar.h
12 |
13 | grammar.h grammar.c: grammar.y
14 | bison -td grammar.y \
15 | && mv grammar.tab.h grammar.h \
16 | && mv grammar.tab.c grammar.c
17 |
18 | grammar.o: grammar.c grammar.h
19 |
20 | calculator.o: calculator.c
21 |
22 | calculator: calculator.o tokens.o grammar.o
23 | gcc calculator.o tokens.o grammar.o -lm -o calculator
24 |
25 | clean:
26 | rm -f tokens.c grammar.c grammar.h *.o calculator
27 |
28 |
--------------------------------------------------------------------------------
/code/calculator/phase5/README:
--------------------------------------------------------------------------------
1 | - Funktionen
2 |
--------------------------------------------------------------------------------
/code/calculator/phase5/calculator.c:
--------------------------------------------------------------------------------
1 | /*
2 | * calculator.c
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | */
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | extern int yydebug;
12 | extern int yyparse();
13 |
14 | void yyerror(char *errmsg) {
15 | fprintf(stderr, "error: %s\n", errmsg);
16 | }
17 |
18 | int yywrap() {
19 | return 1;
20 | }
21 |
22 | int main(int argc, char *argv[]) {
23 | yydebug = 0;
24 | int c;
25 | while (EOF != (c = getopt(argc, argv, "d")))
26 | switch (c) {
27 | case 'd': yydebug = 1;
28 | break;
29 | }
30 | while (!feof(stdin)) {
31 | yyparse();
32 | }
33 | return 0;
34 | }
35 |
--------------------------------------------------------------------------------
/code/calculator/phase5/tokens.l:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * lexer for the calculator
4 | */
5 | #include "grammar.h"
6 | %}
7 | %%
8 | abs { return ABS; }
9 | asinh { return ASINH; }
10 | acosh { return ACOSH; }
11 | atanh { return ATANH; }
12 | sinh { return SINH; }
13 | cosh { return COSH; }
14 | tanh { return TANH; }
15 | asin { return ASIN; }
16 | acos { return ACOS; }
17 | atan2 { return ATAN2; }
18 | atan { return ATAN; }
19 | sin { return SIN; }
20 | cos { return COS; }
21 | tan { return TAN; }
22 | hypot { return HYPOT; }
23 | cbrt { return CBRT; }
24 | sqrt { return SQRT; }
25 | log { return LOG; }
26 | log10 { return LOG10; }
27 | log2 { return LOG2; }
28 | exp { return EXP; }
29 | j0 { return J0; }
30 | j1 { return J1; }
31 | jn { return JN; }
32 | y0 { return Y0; }
33 | y1 { return Y1; }
34 | yn { return YN; }
35 | gamma { return GAMMA; }
36 | erf { return ERF; }
37 | [0-9]+(\.[0-9]*)?([eE]-?[0-9]+)? {
38 | yylval.value = atof(yytext);
39 | printf("value = %f\n", yylval.value);
40 | return NUMBER;
41 | }
42 | [+/\-*] { return yytext[0]; }
43 | \(|\) { return yytext[0]; }
44 | " " { }
45 | , { return ','; }
46 | ; { return ';'; }
47 | \n { return '\n'; }
48 | %%
49 |
--------------------------------------------------------------------------------
/code/calculator/phase6/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile for the calculator project
3 | #
4 | CFLAGS = -g -O2 -Wall
5 | LDFLAGS = -lm
6 |
7 | main: calculator
8 |
9 | tokens.c: tokens.l
10 |
11 | tokens.o: tokens.c grammar.h
12 |
13 | grammar.h grammar.c: grammar.y
14 | bison -td grammar.y \
15 | && mv grammar.tab.h grammar.h \
16 | && mv grammar.tab.c grammar.c
17 |
18 | grammar.o: grammar.c grammar.h
19 |
20 | calculator.o: calculator.c
21 |
22 | calculator: calculator.o tokens.o grammar.o
23 | gcc calculator.o tokens.o grammar.o -lm -o calculator
24 |
25 | clean:
26 | rm -f tokens.c grammar.c grammar.h *.o calculator
27 |
28 |
--------------------------------------------------------------------------------
/code/calculator/phase6/README:
--------------------------------------------------------------------------------
1 | - Syntax for Potenzfunktion
2 |
--------------------------------------------------------------------------------
/code/calculator/phase6/calculator.c:
--------------------------------------------------------------------------------
1 | /*
2 | * calculator.c
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | */
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | extern int yydebug;
12 | extern int yyparse();
13 |
14 | void yyerror(char *errmsg) {
15 | fprintf(stderr, "error: %s\n", errmsg);
16 | }
17 |
18 | int yywrap() {
19 | return 1;
20 | }
21 |
22 | int main(int argc, char *argv[]) {
23 | yydebug = 0;
24 | int c;
25 | while (EOF != (c = getopt(argc, argv, "d")))
26 | switch (c) {
27 | case 'd': yydebug = 1;
28 | break;
29 | }
30 | while (!feof(stdin)) {
31 | yyparse();
32 | }
33 | return 0;
34 | }
35 |
--------------------------------------------------------------------------------
/code/calculator/phase6/tokens.l:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * lexer for the calculator
4 | */
5 | #include "grammar.h"
6 | %}
7 | %%
8 | abs { return ABS; }
9 | asinh { return ASINH; }
10 | acosh { return ACOSH; }
11 | atanh { return ATANH; }
12 | sinh { return SINH; }
13 | cosh { return COSH; }
14 | tanh { return TANH; }
15 | asin { return ASIN; }
16 | acos { return ACOS; }
17 | atan2 { return ATAN2; }
18 | atan { return ATAN; }
19 | sin { return SIN; }
20 | cos { return COS; }
21 | tan { return TAN; }
22 | hypot { return HYPOT; }
23 | cbrt { return CBRT; }
24 | sqrt { return SQRT; }
25 | log { return LOG; }
26 | log10 { return LOG10; }
27 | log2 { return LOG2; }
28 | exp { return EXP; }
29 | j0 { return J0; }
30 | j1 { return J1; }
31 | jn { return JN; }
32 | y0 { return Y0; }
33 | y1 { return Y1; }
34 | yn { return YN; }
35 | gamma { return GAMMA; }
36 | erf { return ERF; }
37 | [0-9]+(\.[0-9]*)?([eE]-?[0-9]+)? {
38 | yylval.value = atof(yytext);
39 | printf("value = %f\n", yylval.value);
40 | return NUMBER;
41 | }
42 | [+/\-*^] { return yytext[0]; }
43 | \(|\) { return yytext[0]; }
44 | " " { }
45 | ; { return ';'; }
46 | , { return ','; }
47 | \n { return '\n'; }
48 | %%
49 |
--------------------------------------------------------------------------------
/code/calculator/phase7/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile for the calculator project
3 | #
4 | CFLAGS = -g -O2 -Wall
5 | LDFLAGS = -lm
6 |
7 | main: calculator
8 |
9 | tokens.c: tokens.l
10 |
11 | tokens.o: tokens.c grammar.h
12 |
13 | grammar.h grammar.c: grammar.y
14 | bison -td grammar.y \
15 | && mv grammar.tab.h grammar.h \
16 | && mv grammar.tab.c grammar.c
17 |
18 | grammar.o: grammar.c grammar.h
19 |
20 | calculator.o: calculator.c
21 |
22 | calculator: calculator.o tokens.o grammar.o
23 | gcc calculator.o tokens.o grammar.o -lm -o calculator
24 |
25 | clean:
26 | rm -f tokens.c grammar.c grammar.h *.o calculator
27 |
28 |
--------------------------------------------------------------------------------
/code/calculator/phase7/README:
--------------------------------------------------------------------------------
1 | - Register zum Zwischenspeichern von Resultaten
2 |
--------------------------------------------------------------------------------
/code/calculator/phase7/calculator.c:
--------------------------------------------------------------------------------
1 | /*
2 | * calculator.c
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | */
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | extern int yydebug;
12 | extern int yyparse();
13 |
14 | void yyerror(char *errmsg) {
15 | fprintf(stderr, "error: %s\n", errmsg);
16 | }
17 |
18 | int yywrap() {
19 | return 1;
20 | }
21 |
22 | int main(int argc, char *argv[]) {
23 | yydebug = 0;
24 | int c;
25 | while (EOF != (c = getopt(argc, argv, "d")))
26 | switch (c) {
27 | case 'd': yydebug = 1;
28 | break;
29 | }
30 | while (!feof(stdin)) {
31 | yyparse();
32 | }
33 | return 0;
34 | }
35 |
--------------------------------------------------------------------------------
/code/calculator/phase7/tokens.l:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * lexer for the calculator
4 | */
5 | #include "grammar.h"
6 | %}
7 | %%
8 | abs { return ABS; }
9 | asinh { return ASINH; }
10 | acosh { return ACOSH; }
11 | atanh { return ATANH; }
12 | sinh { return SINH; }
13 | cosh { return COSH; }
14 | tanh { return TANH; }
15 | asin { return ASIN; }
16 | acos { return ACOS; }
17 | atan2 { return ATAN2; }
18 | atan { return ATAN; }
19 | sin { return SIN; }
20 | cos { return COS; }
21 | tan { return TAN; }
22 | hypot { return HYPOT; }
23 | cbrt { return CBRT; }
24 | sqrt { return SQRT; }
25 | log { return LOG; }
26 | log10 { return LOG10; }
27 | log2 { return LOG2; }
28 | exp { return EXP; }
29 | j0 { return J0; }
30 | j1 { return J1; }
31 | jn { return JN; }
32 | y0 { return Y0; }
33 | y1 { return Y1; }
34 | yn { return YN; }
35 | gamma { return GAMMA; }
36 | erf { return ERF; }
37 | r[0-9][0-9]? {
38 | yylval.reg = atoi(yytext + 1);
39 | return REGISTER;
40 | }
41 | [0-9]+(\.[0-9]*)?([eE]-?[0-9]+)? {
42 | yylval.value = atof(yytext);
43 | printf("value = %f\n", yylval.value);
44 | return NUMBER;
45 | }
46 | [+/\-*^=] { return yytext[0]; }
47 | \(|\) { return yytext[0]; }
48 | " " { }
49 | ; { return ';'; }
50 | , { return ','; }
51 | \n { return '\n'; }
52 | %%
53 |
54 |
55 |
--------------------------------------------------------------------------------
/code/calculator/phase8/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile for the calculator project
3 | #
4 | CFLAGS = -g -O2 -Wall
5 | LDFLAGS = -lm
6 |
7 | main: calculator
8 |
9 | tokens.c: tokens.l
10 |
11 | tokens.o: tokens.c grammar.h
12 |
13 | grammar.h grammar.c: grammar.y
14 | bison -td grammar.y \
15 | && mv grammar.tab.h grammar.h \
16 | && mv grammar.tab.c grammar.c
17 |
18 | grammar.o: grammar.c grammar.h constants.h
19 |
20 | constants.o: constants.c constants.h
21 |
22 | calculator.o: calculator.c
23 |
24 | calculator: calculator.o tokens.o grammar.o constants.o
25 | gcc calculator.o tokens.o grammar.o constants.o -lm -o calculator
26 |
27 | clean:
28 | rm -f tokens.c grammar.c grammar.h *.o calculator
29 |
--------------------------------------------------------------------------------
/code/calculator/phase8/README:
--------------------------------------------------------------------------------
1 | - Syntax fuer Konstanten
2 |
--------------------------------------------------------------------------------
/code/calculator/phase8/calculator.c:
--------------------------------------------------------------------------------
1 | /*
2 | * calculator.c
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | */
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | extern int yydebug;
12 | extern int yyparse();
13 |
14 | void yyerror(char *errmsg) {
15 | fprintf(stderr, "error: %s\n", errmsg);
16 | }
17 |
18 | int yywrap() {
19 | return 1;
20 | }
21 |
22 | int main(int argc, char *argv[]) {
23 | yydebug = 0;
24 | int c;
25 | while (EOF != (c = getopt(argc, argv, "d")))
26 | switch (c) {
27 | case 'd': yydebug = 1;
28 | break;
29 | }
30 | while (!feof(stdin)) {
31 | yyparse();
32 | }
33 | return 0;
34 | }
35 |
--------------------------------------------------------------------------------
/code/calculator/phase8/constants.c:
--------------------------------------------------------------------------------
1 | /*
2 | * constants.c -- constant lookup
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | */
6 | #include "constants.h"
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | double constant(const char *name) {
13 | if (0 == strcmp(name, "pi")) {
14 | return M_PI;
15 | }
16 | if (0 == strcmp(name, "e")) {
17 | return exp(1);
18 | }
19 | if (0 == strcmp(name, "gamma")) {
20 | return 0.57721566490153286060651;
21 | }
22 | if (0 == strcmp(name, "phi")) {
23 | return (1+sqrt(5))/2;
24 | }
25 | fprintf(stderr, "unknown constant %s\n", name);
26 | exit(EXIT_FAILURE);
27 | }
28 |
--------------------------------------------------------------------------------
/code/calculator/phase8/constants.h:
--------------------------------------------------------------------------------
1 | /*
2 | * constants.h
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | * $Id$
6 | */
7 | #ifndef _constants_h
8 | #define _constants_h
9 |
10 | extern double constant(const char *name);
11 |
12 | #endif /* _constants_h */
13 |
14 |
--------------------------------------------------------------------------------
/code/calculator/phase8/tokens.l:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * lexer for the calculator
4 | */
5 | #include "grammar.h"
6 | %}
7 | %%
8 | abs { return ABS; }
9 | asinh { return ASINH; }
10 | acosh { return ACOSH; }
11 | atanh { return ATANH; }
12 | sinh { return SINH; }
13 | cosh { return COSH; }
14 | tanh { return TANH; }
15 | asin { return ASIN; }
16 | acos { return ACOS; }
17 | atan2 { return ATAN2; }
18 | atan { return ATAN; }
19 | sin { return SIN; }
20 | cos { return COS; }
21 | tan { return TAN; }
22 | hypot { return HYPOT; }
23 | cbrt { return CBRT; }
24 | sqrt { return SQRT; }
25 | log { return LOG; }
26 | log10 { return LOG10; }
27 | log2 { return LOG2; }
28 | exp { return EXP; }
29 | j0 { return J0; }
30 | j1 { return J1; }
31 | jn { return JN; }
32 | y0 { return Y0; }
33 | y1 { return Y1; }
34 | yn { return YN; }
35 | gamma { return GAMMA; }
36 | erf { return ERF; }
37 | \%[a-z]+ {
38 | strncpy(yylval.name, yytext + 1, 9);
39 | return CONSTANT;
40 | }
41 | r[0-9][0-9]? {
42 | yylval.reg = atoi(yytext + 1);
43 | return REGISTER;
44 | }
45 | [0-9]+(\.[0-9]*)?([eE]-?[0-9]+)? {
46 | yylval.value = atof(yytext);
47 | printf("value = %f\n", yylval.value);
48 | return NUMBER;
49 | }
50 | [+/\-*^=] { return yytext[0]; }
51 | \(|\) { return yytext[0]; }
52 | " " { }
53 | ; { return ';'; }
54 | , { return ','; }
55 | \n { return '\n'; }
56 | %%
57 |
--------------------------------------------------------------------------------
/code/calculator/phase9/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile for the calculator project
3 | #
4 | CFLAGS = -g -O2 -Wall
5 | LDFLAGS = -lm
6 |
7 | main: calculator
8 |
9 | tokens.c: tokens.l
10 |
11 | tokens.o: tokens.c grammar.h
12 |
13 | grammar.h grammar.c: grammar.y
14 | bison -td grammar.y \
15 | && mv grammar.tab.h grammar.h \
16 | && mv grammar.tab.c grammar.c
17 |
18 | grammar.o: grammar.c grammar.h constants.h
19 |
20 | constants.o: constants.c constants.h
21 |
22 | calculator.o: calculator.c
23 |
24 | calculator: calculator.o tokens.o grammar.o constants.o
25 | gcc calculator.o tokens.o grammar.o constants.o -lm -o calculator
26 |
27 | clean:
28 | rm -f tokens.c grammar.c grammar.h *.o calculator
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/code/calculator/phase9/README:
--------------------------------------------------------------------------------
1 | - Letzter Rueckgabewert
2 |
--------------------------------------------------------------------------------
/code/calculator/phase9/calculator.c:
--------------------------------------------------------------------------------
1 | /*
2 | * calculator.c
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | */
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | extern int yydebug;
12 | extern int yyparse();
13 |
14 | void yyerror(char *errmsg) {
15 | fprintf(stderr, "error: %s\n", errmsg);
16 | }
17 |
18 | int yywrap() {
19 | return 1;
20 | }
21 |
22 | int main(int argc, char *argv[]) {
23 | yydebug = 0;
24 | int c;
25 | while (EOF != (c = getopt(argc, argv, "d")))
26 | switch (c) {
27 | case 'd': yydebug = 1;
28 | break;
29 | }
30 | while (!feof(stdin)) {
31 | yyparse();
32 | }
33 | return 0;
34 | }
35 |
--------------------------------------------------------------------------------
/code/calculator/phase9/constants.c:
--------------------------------------------------------------------------------
1 | /*
2 | * constants.c -- constant lookup
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | */
6 | #include "constants.h"
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | double constant(const char *name) {
13 | if (0 == strcmp(name, "pi")) {
14 | return M_PI;
15 | }
16 | if (0 == strcmp(name, "e")) {
17 | return exp(1);
18 | }
19 | if (0 == strcmp(name, "gamma")) {
20 | return 0.57721566490153286060651;
21 | }
22 | if (0 == strcmp(name, "phi")) {
23 | return (1+sqrt(5))/2;
24 | }
25 | fprintf(stderr, "unknown constant %s\n", name);
26 | exit(EXIT_FAILURE);
27 | }
28 |
--------------------------------------------------------------------------------
/code/calculator/phase9/constants.h:
--------------------------------------------------------------------------------
1 | /*
2 | * constants.h
3 | *
4 | * (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | * $Id$
6 | */
7 | #ifndef _constants_h
8 | #define _constants_h
9 |
10 | extern double constant(const char *name);
11 |
12 | #endif /* _constants_h */
13 |
14 |
--------------------------------------------------------------------------------
/code/calculator/phase9/tokens.l:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * lexer for the calculator
4 | */
5 | #include "grammar.h"
6 | %}
7 | %%
8 | abs { return ABS; }
9 | asinh { return ASINH; }
10 | acosh { return ACOSH; }
11 | atanh { return ATANH; }
12 | sinh { return SINH; }
13 | cosh { return COSH; }
14 | tanh { return TANH; }
15 | asin { return ASIN; }
16 | acos { return ACOS; }
17 | atan2 { return ATAN2; }
18 | atan { return ATAN; }
19 | sin { return SIN; }
20 | cos { return COS; }
21 | tan { return TAN; }
22 | hypot { return HYPOT; }
23 | cbrt { return CBRT; }
24 | sqrt { return SQRT; }
25 | log { return LOG; }
26 | log10 { return LOG10; }
27 | log2 { return LOG2; }
28 | exp { return EXP; }
29 | j0 { return J0; }
30 | j1 { return J1; }
31 | jn { return JN; }
32 | y0 { return Y0; }
33 | y1 { return Y1; }
34 | yn { return YN; }
35 | gamma { return GAMMA; }
36 | erf { return ERF; }
37 | \%\% { return PREVIOUS; }
38 | \%[a-z]+ {
39 | strncpy(yylval.name, yytext + 1, 9);
40 | return CONSTANT;
41 | }
42 | r[0-9][0-9]? {
43 | yylval.reg = atoi(yytext + 1);
44 | return REGISTER;
45 | }
46 | [0-9]+(\.[0-9]*)?([eE]-?[0-9]+)? {
47 | yylval.value = atof(yytext);
48 | printf("value = %f\n", yylval.value);
49 | return NUMBER;
50 | }
51 | [+/\-*^=] { return yytext[0]; }
52 | \(|\) { return yytext[0]; }
53 | " " { }
54 | ; { return ';'; }
55 | , { return ','; }
56 | \n { return '\n'; }
57 | %%
58 |
--------------------------------------------------------------------------------
/code/divisible/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile -- build divisible by 3 demo program
3 | #
4 | # (c) 2016 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | #
6 | all: divisible
7 |
8 | divisible.c: divisible.l Makefile
9 | flex -o divisible.c --verbose --interactive --trace divisible.l 2>divisible.trace
10 |
11 | divisible: divisible.c d3.c
12 | gcc -o divisible -Wall -g -O2 divisible.c d3.c
13 |
14 | test: divisible
15 | ./count | ./divisible
16 |
--------------------------------------------------------------------------------
/code/divisible/count:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | #
3 | # count -- count up in binary
4 | #
5 | # (c) 2016 Prof Dr Andreas Mueller, Hochschule Rapperswil
6 | #
7 | (
8 | echo obase=2
9 | counter=0
10 | while [ ${counter} -lt 200 ]
11 | do
12 | echo $counter
13 | counter=`expr ${counter} + 1`
14 | done
15 | ) | bc -l
16 |
17 |
--------------------------------------------------------------------------------
/code/divisible/d3.c:
--------------------------------------------------------------------------------
1 | /*
2 | * d3.c -- test for divisibility by 3
3 | *
4 | * (c) 2016 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | */
6 | #include
7 | #include
8 |
9 | int yylex();
10 |
11 | int yywrap() {
12 | exit(EXIT_SUCCESS);
13 | }
14 |
15 | int main(int argc, char *argv[]) {
16 | while (!feof(stdin)) {
17 | yylex();
18 | }
19 | return EXIT_SUCCESS;
20 | }
21 |
--------------------------------------------------------------------------------
/code/divisible/divisible.l:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * lexer definition to recognize binary numbers divisible by 3
4 | *
5 | * (c) 2016 Prof Dr Andreas Mueller, Hochschule Rapperswil
6 | */
7 | #include
8 | long value(const char *s) {
9 | char *end;
10 | return strtol(s, &end, 2);
11 | }
12 | %}
13 | %%
14 | (0|1(01*0)*1)* { printf("%s = %ld: divisible\n", yytext, value(yytext)); }
15 | (0|(1(01*0)*1))*1(01*0)* { printf("%s = %ld: remainder 1\n", yytext, value(yytext)); }
16 | 0*1(01*0|10*1)*01* { printf("%s = %ld: remainder 2\n", yytext, value(yytext)); }
17 | .* { printf("?\n"); }
18 | \n { }
19 | %%
20 |
--------------------------------------------------------------------------------
/code/gvm/AUTHORS:
--------------------------------------------------------------------------------
1 | Prof Dr Andreas Mueller
2 | Hochschule Rapperswil
3 |
--------------------------------------------------------------------------------
/code/gvm/ChangeLog:
--------------------------------------------------------------------------------
1 | ChangeLog for gvm
2 |
3 | 20250527:
4 | * work around a segmentation fault in gmp_fprintf
5 |
6 | 20220517:
7 | * add some more statistics output
8 |
9 | 20130121:
10 | * Integration in das MathI2 Skript
11 |
12 | 20120525:
13 | * create project
14 |
15 |
16 |
--------------------------------------------------------------------------------
/code/gvm/Makefile.am:
--------------------------------------------------------------------------------
1 | #
2 | # top level makefile for the goto vm and tm compiler project
3 | #
4 | # (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | # $Id$
6 | #
7 | SUBDIRS = common vm tmc doc
8 | EXTRA_DIST = configureit
9 |
--------------------------------------------------------------------------------
/code/gvm/NEWS:
--------------------------------------------------------------------------------
1 | Release 1.1 works around a bug in GMP 6.3 on Macos (as installed using
2 | the brew package manager). The function gmp_fprintf causes a segmentation
3 | fault. By writing the output string to a local buffer first, and only then
4 | sending it to the output FILE, the segmentation fault is avoided.
5 |
6 |
--------------------------------------------------------------------------------
/code/gvm/common/Makefile.am:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile for the common directory
3 | #
4 | # (c) 2012-2024 Prof Dr Andreas Mueller
5 | #
6 | EXTRA_DIST = includes.h
7 |
--------------------------------------------------------------------------------
/code/gvm/common/includes.h:
--------------------------------------------------------------------------------
1 | /*
2 | * includes.h -- common includes
3 | *
4 | * (c) 2012-2024 Prof Dr Andreas Mueller
5 | */
6 | /*
7 | #define _POSIX_C_SOURCE 199309L
8 | */
9 |
10 | #ifdef HAVE_CONFIG_H
11 | #include
12 | #endif /* HAVE_CONFIG_H */
13 |
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
--------------------------------------------------------------------------------
/code/gvm/configure.ac:
--------------------------------------------------------------------------------
1 | #
2 | # configure.ac -- create the configure script for the gvm project
3 | #
4 | # (c) 2012-2024 Prof Dr Andreas Mueller
5 | #
6 | AC_PREREQ([2.72])
7 | AC_REVISION([1.0])dnl
8 | AC_INIT([gvm],[1.1],[andreas.mueller@othello.ch])
9 | AC_CONFIG_SRCDIR([vm/gvm.c])
10 | AC_CANONICAL_TARGET([])
11 | AM_INIT_AUTOMAKE
12 | AC_CONFIG_HEADERS(common/config.h)
13 |
14 | # Programs
15 | AC_PROG_CC
16 | AC_PROG_LEX(noyywrap)
17 | AC_PROG_YACC
18 |
19 | AC_CHECK_FUNC(nanosleep, AC_DEFINE(HAVE_NANOSLEEP, [], [Define if nanosleep(2) function is present]), )
20 |
21 | AC_CHECK_HEADERS([gmp.h])
22 | AC_CHECK_LIB(gmp, __gmpz_init)
23 |
24 | AC_C_CONST
25 |
26 | case `uname` in
27 | Linux) CFLAGS="-D_DEFAULT_SOURCE ${CFLAGS}"
28 | ;;
29 | *)
30 | ;;
31 | esac
32 |
33 | # substitutions
34 | AC_CONFIG_FILES([Makefile
35 | common/Makefile
36 | vm/Makefile
37 | tmc/Makefile tmc/pgm/Makefile tmc/data/Makefile
38 | doc/Makefile])
39 | AC_OUTPUT
40 |
--------------------------------------------------------------------------------
/code/gvm/configureit:
--------------------------------------------------------------------------------
1 | #
2 | # setting the right configure flags per plattform
3 | #
4 | # (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | #
6 | case `uname` in
7 | Darwin)
8 | # on Mac OS X, if you have the GNU MP under /usr/local/lib
9 | LDFLAGS="$(pkg-config --libs gmp)"
10 | CFLAGS="-g -Wall -O -std=c99 -Wno-implicit-function-declaration -Wno-unused-function $(pkg-config --cflags gmp)"
11 | export CFLAGS LDFLAGS
12 | ;;
13 | Linux)
14 | # on Linux, GMP is usually included and installed under /usr/lib
15 | # no special linker flags are needed to find it
16 | CFLAGS="-g -Wall -O -std=c99"
17 | export CFLAGS
18 | esac
19 |
20 | # now run configure with these flags
21 | ./configure
22 |
--------------------------------------------------------------------------------
/code/gvm/doc/Makefile.am:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile.am -- makefile to include the documentation in the package
3 | #
4 | # (c) 2012-2024 Prof Dr Andreas Mueller
5 | #
6 | EXTRA_DIST = \
7 | gvm.tex \
8 | assign.h condgoto.h engine.h goto.h node.h nodes.h vm.h tm.h \
9 | parser.y parsergoto.y \
10 | tmc-beaver.tm \
11 | print.goto steuerung.goto beispiel.goto tmc-command.goto \
12 | tmc-initial.goto tmc-isolate.goto tmc-move.goto tmc-printtm.goto \
13 | tmc-splice.goto tmc-state.goto \
14 | gvm.1 tmc.1
15 |
16 | gvm.pdf: gvm.tex
17 | pdflatex gvm.tex
18 | pdflatex gvm.tex
19 |
20 | man_MANS = gvm.1 tmc.1
21 |
--------------------------------------------------------------------------------
/code/gvm/doc/assign.h:
--------------------------------------------------------------------------------
1 | case GVM_NODE_ASSIGN_OPERATOR:
2 | op1 = &gvmp->vars[gvmp->nodes[pc].u.a.source_varno];
3 | op2 = &gvmp->vars[gvmp->nodes[pc].u.a.source2_varno];
4 | switch (gvmp->nodes[pc].u.a.operator) {
5 | case '+': mpz_add(result, *op1, *op2);
6 | break;
7 | case '-': mpz_sub(result, *op1, *op2);
8 | break;
9 | ...
10 | }
11 | mpz_set(gvmp->vars[gvmp->nodes[pc].u.a.target_varno],
12 | result);
13 | pc += 1;
14 | break;
15 |
--------------------------------------------------------------------------------
/code/gvm/doc/beispiel.goto:
--------------------------------------------------------------------------------
1 | 1: v1 := 7
2 | 2: v2 := 5
3 | 3: v0 := v1
4 | 4: v3 := v2
5 | 5: IF v0 = 0 GOTO 9
6 | 6: v3 := v3 + 1
7 | 7: v0 := v0 - 1
8 | 8: GOTO 5
9 | 9: ...
10 |
--------------------------------------------------------------------------------
/code/gvm/doc/condgoto.h:
--------------------------------------------------------------------------------
1 | case GVM_NODE_CONDITIONAL_GOTO:
2 | if (0 == mpz_cmp_ui(
3 | gvmp->vars[gvmp->nodes[pc].u.g.condition_varno],
4 | gvmp->nodes[pc].u.g.condition_constant)) {
5 | pc = gvmp->nodes[pc].u.g.target;
6 | } else {
7 | pc += 1;
8 | }
9 | break;
10 |
--------------------------------------------------------------------------------
/code/gvm/doc/engine.h:
--------------------------------------------------------------------------------
1 | int pc = 0;
2 | while (pc < gvmp->nnodes) {
3 | switch (gvmp->nodes[pc].type) {
4 | case GVM_NODE_ASSIGN_CONSTANT:
5 | ...
6 | pc += 1;
7 | break;
8 | case GVM_NODE_ASSIGN_VARIABLE:
9 | ...
10 | pc += 1;
11 | break;
12 | case GVM_NODE_ASSIGN_OPERATOR_CONST:
13 | ...
14 | pc += 1;
15 | break;
16 | ...
17 | }
18 |
--------------------------------------------------------------------------------
/code/gvm/doc/goto.h:
--------------------------------------------------------------------------------
1 | case GVM_NODE_GOTO:
2 | pc = gvmp->nodes[pc].u.g.target;
3 | break;
4 |
--------------------------------------------------------------------------------
/code/gvm/doc/node.h:
--------------------------------------------------------------------------------
1 | typedef struct gvm_node_s {
2 | int type;
3 | union gvm_node_payload_u {
4 | gvm_assign_t a;
5 | gvm_goto_t g;
6 | gvm_print_t p;
7 | } u;
8 | } gvm_node_t;
9 |
--------------------------------------------------------------------------------
/code/gvm/doc/nodes.h:
--------------------------------------------------------------------------------
1 | typedef struct gvm_assign_s {
2 | int target_varno;
3 | int source_varno;
4 | char operator;
5 | int source2_varno;
6 | mpz_t constant;
7 | } gvm_assign_t;
8 |
9 | typedef struct gvm_goto_s {
10 | int condition_varno;
11 | int condition_constant;
12 | int target;
13 | } gvm_goto_t;
14 |
--------------------------------------------------------------------------------
/code/gvm/doc/parser.y:
--------------------------------------------------------------------------------
1 | expression: VARIABLE ASSIGN CONSTANT {
2 | $$.type = GVM_NODE_ASSIGN_CONSTANT;
3 | $$.u.a.target_varno = $1;
4 | mpz_init_set($$.u.a.constant, $3);
5 | }
6 | ...
7 | | VARIABLE ASSIGN VARIABLE OPERATOR VARIABLE {
8 | $$.type = GVM_NODE_ASSIGN_OPERATOR;
9 | $$.u.a.target_varno = $1;
10 | $$.u.a.source_varno = $3;
11 | $$.u.a.operator = $4;
12 | $$.u.a.source2_varno = $5;
13 | }
14 |
--------------------------------------------------------------------------------
/code/gvm/doc/parsergoto.y:
--------------------------------------------------------------------------------
1 | expression:
2 | ...
3 | | IF VARIABLE '=' CONSTANT GOTO CONSTANT {
4 | $$.type = GVM_NODE_CONDITIONAL_GOTO;
5 | $$.u.g.condition_varno = $2;
6 | $$.u.g.condition_constant
7 | = mpz_get_ui($4);
8 | $$.u.g.target = mpz_get_ui($6) - 1;
9 | }
10 |
--------------------------------------------------------------------------------
/code/gvm/doc/print.goto:
--------------------------------------------------------------------------------
1 | 22: PRINTSTRING "1234 \"abc\""
2 | 23: PRINTVAR v7
3 | 24: PRINTTM
4 |
--------------------------------------------------------------------------------
/code/gvm/doc/steuerung.goto:
--------------------------------------------------------------------------------
1 | 5: IF v0 = 0 GOTO 9
2 | ...
3 | 8: GOTO 5
4 | ...
5 | 11: HALT
6 |
--------------------------------------------------------------------------------
/code/gvm/doc/tm.h:
--------------------------------------------------------------------------------
1 | typedef struct tm_node_s {
2 | int from_state;
3 | int from_tapechar;
4 | int to_state;
5 | int to_tapechar;
6 | int movement;
7 | } tm_node_t;
8 |
9 | typedef struct tm_s {
10 | int nnodes;
11 | tm_node_t *nodes;
12 | int initialstate;
13 | int initialposition;
14 | char *initialtape;
15 | } tm_t;
16 |
--------------------------------------------------------------------------------
/code/gvm/doc/tmc-beaver.tm:
--------------------------------------------------------------------------------
1 | ...
2 | [ 1111 ]
3 | ^1
4 | [ 11110 ]
5 | ^2
6 | [ 111101 ]
7 | ^2
8 | ...
9 |
--------------------------------------------------------------------------------
/code/gvm/doc/tmc-command.goto:
--------------------------------------------------------------------------------
1 | 40: IF v1 = 1 GOTO 42
2 | 41: GOTO 47
3 | 42: IF v3 = 2 GOTO 44
4 | 43: GOTO 47
5 | 44: v7 := 1
6 | 45: v6 := 2
7 | 46: v5 := 2
8 |
--------------------------------------------------------------------------------
/code/gvm/doc/tmc-initial.goto:
--------------------------------------------------------------------------------
1 | 1: v0 := 46826303100262
2 | 2: v1 := 0
3 | 3: v2 := 0
4 |
--------------------------------------------------------------------------------
/code/gvm/doc/tmc-isolate.goto:
--------------------------------------------------------------------------------
1 | 5: v3 := v0
2 | 6: v4 := v2
3 | 7: IF v4 = 0 GOTO 11
4 | 8: v4 := v4 - 1
5 | 9: v3 := v3 / 4
6 | 10: GOTO 7
7 | 11: v3 := v3 % 4
8 |
--------------------------------------------------------------------------------
/code/gvm/doc/tmc-move.goto:
--------------------------------------------------------------------------------
1 | 89: IF v5 = 1 GOTO 91
2 | 90: GOTO 92
3 | 91: v2 := v2 - 1
4 | 92: IF v5 = 2 GOTO 94
5 | 93: GOTO 95
6 | 94: v2 := v2 + 1
7 | 95: IF v5 = 3 GOTO 97
8 | 96: GOTO 98
9 | 97: GOTO 100
10 | ...
11 | 100: HALT
12 |
13 |
--------------------------------------------------------------------------------
/code/gvm/doc/tmc-printtm.goto:
--------------------------------------------------------------------------------
1 | 4: PRINTTM
2 |
--------------------------------------------------------------------------------
/code/gvm/doc/tmc-splice.goto:
--------------------------------------------------------------------------------
1 | 747: v8 := v2
2 | 748: v9 := 1
3 | 749: IF v8 = 0 GOTO 753
4 | 750: v9 := v9 * 4
5 | 751: v8 := v8 - 1
6 | 752: GOTO 749
7 | 753: v10 := v0 % v9
8 | 754: v11 := v0 / v9
9 | 755: v11 := v11 / 4
10 | 756: v11 := v11 * 4
11 | 757: v11 := v11 + v6
12 | 758: v11 := v11 * v9
13 | 759: v11 := v11 + v10
14 | 760: v0 := v11
15 |
--------------------------------------------------------------------------------
/code/gvm/doc/tmc-state.goto:
--------------------------------------------------------------------------------
1 | 98: v1 := v7
2 | 99: GOTO 4
3 | 100: HALT
4 |
--------------------------------------------------------------------------------
/code/gvm/doc/vm.h:
--------------------------------------------------------------------------------
1 | typedef struct gvm_s {
2 | int nnodes;
3 | gvm_node_t *nodes;
4 | int nvars;
5 | mpz_t *vars;
6 | ...
7 | } gvm_t;
8 |
--------------------------------------------------------------------------------
/code/gvm/tmc/data/Makefile.am:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile for the samples directory
3 | #
4 | # (c) 2012 Prof Dr Andreas Mueller, Hochschule Rappersswil
5 | # $Id$
6 | #
7 | EXTRA_DIST = addtape addtape1 addtape2 addtape3
8 |
--------------------------------------------------------------------------------
/code/gvm/tmc/data/addtape:
--------------------------------------------------------------------------------
1 | 10100001011 01011001111
2 |
--------------------------------------------------------------------------------
/code/gvm/tmc/data/addtape1:
--------------------------------------------------------------------------------
1 | 011100111000 010100001011
2 |
--------------------------------------------------------------------------------
/code/gvm/tmc/data/addtape2:
--------------------------------------------------------------------------------
1 | 010111 010111
2 |
--------------------------------------------------------------------------------
/code/gvm/tmc/data/addtape3:
--------------------------------------------------------------------------------
1 | 0111010110111100110100010110001 0000111010110111100110100010110
2 |
--------------------------------------------------------------------------------
/code/gvm/tmc/pgm/Makefile.am:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile for the samples directory
3 | #
4 | # (c) 2012 Prof Dr Andreas Mueller, Hochschule Rappersswil
5 | # $Id$
6 | #
7 | EXTRA_DIST = add beaver3 beaver4 beaver5
8 |
--------------------------------------------------------------------------------
/code/gvm/tmc/pgm/beaver3:
--------------------------------------------------------------------------------
1 | (0,0) -> (1,1) Right
2 | (0,1) -> (0,1) Halt
3 | (0,B) -> (1,1) Right
4 |
5 | (1,0) -> (2,0) Right
6 | (1,1) -> (1,1) Right
7 | (1,B) -> (2,0) Right
8 |
9 | (2,0) -> (2,1) Left
10 | (2,1) -> (0,1) Left
11 | (2,B) -> (2,1) Left
12 |
--------------------------------------------------------------------------------
/code/gvm/tmc/pgm/beaver4:
--------------------------------------------------------------------------------
1 | (0,0) -> (1,1) Right
2 | (0,1) -> (1,1) Left
3 | (0,B) -> (1,1) Right
4 |
5 | (1,0) -> (0,1) Left
6 | (1,1) -> (2,0) Left
7 | (1,B) -> (0,1) Left
8 |
9 | (2,0) -> (2,1) Halt
10 | (2,1) -> (3,1) Left
11 | (2,B) -> (2,1) Halt
12 |
13 | (3,0) -> (3,1) Right
14 | (3,1) -> (0,0) Right
15 | (3,B) -> (3,1) Right
16 |
--------------------------------------------------------------------------------
/code/gvm/tmc/pgm/beaver5:
--------------------------------------------------------------------------------
1 | (0,0) -> (1,1) Left
2 | (0,1) -> (2,1) Right
3 | (0,B) -> (1,1) Left
4 |
5 | (1,0) -> (2,1) Left
6 | (1,1) -> (1,1) Left
7 | (1,B) -> (2,1) Left
8 |
9 | (2,0) -> (3,1) Left
10 | (2,1) -> (4,0) Right
11 | (2,B) -> (3,1) Left
12 |
13 | (3,0) -> (0,1) Right
14 | (3,1) -> (3,1) Right
15 | (3,B) -> (0,1) Right
16 |
17 | (4,0) -> (4,1) Halt
18 | (4,1) -> (0,0) Right
19 | (4,B) -> (4,1) Halt
20 |
--------------------------------------------------------------------------------
/code/gvm/tmc/tmc-grammar.y:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * tmc-grammar.y -- parser for TM compiler
4 | *
5 | * (c) 2012-2024 Prof Dr Andreas Mueller
6 | */
7 | #include
8 | #include "tmc.h"
9 | extern void yyerror(char *errmsg);
10 | extern int yylex (void);
11 | %}
12 | %union {
13 | int state;
14 | int tapechar;
15 | int movement;
16 | }
17 | %token STATE
18 | %token TAPECHAR
19 | %type movement
20 | %token ARROW LEFT RIGHT HALT
21 | %%
22 | program: command
23 | | program command
24 | ;
25 |
26 | command: '(' STATE ',' TAPECHAR ')' ARROW '(' STATE ',' TAPECHAR ')' movement {
27 | int nnodes = tm.nnodes + 1;
28 | tm.nodes = (tm_node_t *)realloc(tm.nodes, nnodes * sizeof(tm_node_t));
29 | tm.nodes[tm.nnodes].from_state = $2;
30 | tm.nodes[tm.nnodes].from_tapechar = $4;
31 | tm.nodes[tm.nnodes].to_state = $8;
32 | tm.nodes[tm.nnodes].to_tapechar = $10;
33 | tm.nodes[tm.nnodes].movement = $12;
34 | tm.nnodes = nnodes;
35 | }
36 |
37 | movement: LEFT { $$ = MOVEMENT_LEFT; }
38 | | RIGHT { $$ = MOVEMENT_RIGHT; }
39 | | HALT { $$ = MOVEMENT_HALT; }
40 | ;
41 | %%
42 |
--------------------------------------------------------------------------------
/code/gvm/tmc/tmc-tokens.l:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * tmc-tokens.l -- lexer definition for the Turing machine compiler
4 | *
5 | * (c) 2012-2024 Prof Dr Andreas Mueller
6 | */
7 | #include "tmc.h"
8 | #include
9 | #include
10 | #undef YY_INPUT
11 | #define YY_INPUT(b, r, ms) ( r = tmc_read(b, ms))
12 | #undef yywrap
13 | %}
14 | %x tapealphabet
15 | %%
16 |
17 | "//"[^\n]*\n
18 | -> { return ARROW; }
19 | [0-9]+ {
20 | yylval.state = atoi(yytext);
21 | return STATE;
22 | }
23 | [()] {
24 | return yytext[0];
25 | }
26 | Left { return LEFT; }
27 | Right { return RIGHT; }
28 | Halt { return HALT; }
29 |
30 | , {
31 | BEGIN(tapealphabet);
32 | return yytext[0];
33 | }
34 | . {
35 | yylval.tapechar = yytext[0];
36 | BEGIN(INITIAL);
37 | return TAPECHAR;
38 | }
39 |
40 | . { }
41 | \n { }
42 | %%
43 |
--------------------------------------------------------------------------------
/code/gvm/tmc/tmc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * tmc.h -- global declarations for the turing machine compiler
3 | *
4 | * (c) 2012-2024 Prof Dr Andraes Mueller
5 | */
6 | #ifndef _tmc_h
7 | #define _tmc_h
8 |
9 | #define MOVEMENT_LEFT 1
10 | #define MOVEMENT_RIGHT 2
11 | #define MOVEMENT_HALT 0
12 |
13 | extern int tmc_read(char *buf, int ms);
14 |
15 | typedef struct tm_node_s {
16 | int from_state;
17 | int from_tapechar;
18 | int to_state;
19 | int to_tapechar;
20 | int movement;
21 | } tm_node_t;
22 |
23 | typedef struct tm_s {
24 | int nnodes;
25 | tm_node_t *nodes;
26 | int initialstate;
27 | int initialposition;
28 | char *initialtape;
29 | } tm_t;
30 |
31 | extern tm_t tm;
32 |
33 | extern int tmc_read(char *buffer, int ms);
34 |
35 | extern void tmc_display(tm_t *tm);
36 |
37 | #endif /* _tmc_h */
38 |
--------------------------------------------------------------------------------
/code/gvm/vm/Makefile.am:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile.am -- build the Makefile for the gvm project
3 | #
4 | # (c) 2012-2024 Prof Dr Andreas Mueller
5 | #
6 | EXTRA_DIST = test.goto gvm.h utils.h tokens.l grammar.y
7 |
8 | bin_PROGRAMS = gvm
9 |
10 | gvm_SOURCES = gvm.c tokens.c grammar.c utils.c
11 |
12 | tokens.c: tokens.l grammar.h
13 | $(LEX) $< && mv lex.yy.c tokens.c
14 |
15 | grammar.h grammar.c: grammar.y
16 | $(YACC) -td $< && mv y.tab.h grammar.h && mv y.tab.c grammar.c
17 |
18 |
19 | test: gvm test.goto
20 | ./gvm -d test.goto
21 |
22 | add: gvm ../tmc/tmp/add1.goto
23 | ./gvm -s 50 ../tmc/add.goto
24 |
25 | add1: gvm ../tmc/tmp/add1.goto
26 | ./gvm ../tmc/tmp/add1.goto
27 |
28 | add3: gvm ../tmc/tmp/add3.goto
29 | ./gvm ../tmc/tmp/add3.goto
30 |
--------------------------------------------------------------------------------
/code/gvm/vm/gvm.h:
--------------------------------------------------------------------------------
1 | /*
2 | * gvm.h -- goto virtual machine declarations
3 | *
4 | * (c) 2012-2024 Prof Dr Andreas Mueller
5 | */
6 | #ifndef _gvm_h
7 | #define _gvm_h
8 |
9 | #include
10 |
11 | #define GVM_NODE_NONE 0
12 | #define GVM_NODE_ASSIGN_CONSTANT 1
13 | #define GVM_NODE_ASSIGN_VARIABLE 2
14 | #define GVM_NODE_ASSIGN_OPERATOR_CONST 3
15 | #define GVM_NODE_ASSIGN_OPERATOR 4
16 | #define GVM_NODE_CONDITIONAL_GOTO 5
17 | #define GVM_NODE_GOTO 6
18 | #define GVM_NODE_HALT 7
19 | #define GVM_NODE_PRINTSTRING 8
20 | #define GVM_NODE_PRINTVAR 9
21 | #define GVM_NODE_PRINTTM 10
22 | #define GVM_NODE_PRINTSTEPS 11
23 |
24 | typedef struct gvm_assign_s {
25 | int target_varno;
26 | int source_varno;
27 | char operator;
28 | int source2_varno;
29 | mpz_t constant;
30 | } gvm_assign_t;
31 |
32 | typedef struct gvm_goto_s {
33 | int condition_varno;
34 | int condition_constant;
35 | int target;
36 | } gvm_goto_t;
37 |
38 | typedef union gvm_print_u {
39 | char *string;
40 | int varno;
41 | } gvm_print_t;
42 |
43 | typedef struct gvm_node_s {
44 | int type;
45 | union gvm_node_payload_u {
46 | gvm_assign_t a;
47 | gvm_goto_t g;
48 | gvm_print_t p;
49 | } u;
50 | } gvm_node_t;
51 |
52 | typedef struct gvm_s {
53 | int nnodes;
54 | gvm_node_t *nodes;
55 | int nvars;
56 | mpz_t *vars;
57 | int sleep;
58 | int steps;
59 | } gvm_t;
60 |
61 | extern gvm_t gvm;
62 |
63 | #endif /* _gvm_h */
64 |
65 |
--------------------------------------------------------------------------------
/code/gvm/vm/test.goto:
--------------------------------------------------------------------------------
1 | 1: v1 := 7
2 | 2: v2 := 5
3 | 3: v0 := v1
4 | 4: v3 := v2
5 | 5: IF v0 = 0 GOTO 9
6 | 6: v3 := v3 + 1
7 | 7: v0 := v0 - 1
8 | 8: GOTO 5
9 | 9: v4 := 0
10 | 10: v0 := v1
11 | 11: IF v0 = 0 GOTO 15
12 | 12: v4 := v4 + v3
13 | 13: v0 := v0 - 1
14 | 14: GOTO 11
15 | 15: v5 := v1 * v3
16 | 16: v6 := 1024
17 | 17: v7 := 10
18 | 18: IF v7 = 0 GOTO 22
19 | 19: v6 := v6 * v6
20 | 20: v7 := v7 - 1
21 | 21: GOTO 18
22 | 22: PRINTSTRING "1234 \"abc\""
23 | 23: PRINTVAR v7
24 | 24: PRINTVAR v6
25 | 25: PRINTTM
26 | 26: PRINTSTRING "steps: "
27 | 27: PRINTSTEPS
28 | 28: HALT
29 |
--------------------------------------------------------------------------------
/code/gvm/vm/utils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * utils.h -- the goto virtual machine
3 | *
4 | * (c) 2012-2024 Prof Dr Andreas Mueller
5 | */
6 | #ifndef _utils_h
7 | #define _utils_h
8 |
9 | #include
10 |
11 | extern int gvm_file;
12 | extern int gvm_trace;
13 |
14 | extern int gvm_read(char *buf, int ms);
15 | extern void gvm_display(gvm_t *gvmp);
16 | extern void gvm_run(gvm_t *gvmp);
17 | extern void gvm_initvar(gvm_t *gvmp, char *v);
18 |
19 | #endif /* _utils_h */
20 |
--------------------------------------------------------------------------------
/code/manualpda/README:
--------------------------------------------------------------------------------
1 | Manuelle Pushdown Automat
2 | -------------------------
3 |
4 | Das Postscript File mpda.ps enthaelt einen manuellen Pushdown
5 | Automaten. Die Symbol-Karten auf Seite 2 enthalten Terminalsymbole
6 | und Variablen, sowie das $-Zeichen zur Markierung des Stackanfangs.
7 | Ausgedruckt auf Folien und ausgeschnitten koennen sie dazu verwendet
8 | werden, die Arbeit eines Stackautomaten zu visualisieren.
9 |
10 |
--------------------------------------------------------------------------------
/code/manualpda/mpda.ps:
--------------------------------------------------------------------------------
1 | %!PS-Adobe-2.0
2 | %
3 | % manualpda.ps -- Folien fuer "manuellen" Stackautomaten
4 | %
5 | % (c) 2013 Prof Dr Andreas Mueller, Hochschule Rapperswil
6 | %
7 | %%Title: Manueller Stackautomat
8 | %%Creator: Prof Dr Andreas Mueller
9 | %%Orientation: Landscape
10 | %%DocumentPaperSizes: A4
11 | %%Pages: 2
12 | %%EndComments
13 |
14 | %%Page: 1
15 | % Titel
16 | /Helvetica findfont 20 scalefont setfont
17 |
18 | 50 730 moveto
19 | (Input:)
20 | show
21 |
22 | 50 60 580 {
23 | dup
24 | 650 moveto
25 | 55 0 rlineto stroke
26 | } for
27 |
28 | 475 600 moveto
29 | (Stack:) dup stringwidth exch -0.5 mul exch rmoveto
30 | show
31 |
32 | 400 590 moveto
33 | 400 50 lineto
34 | 550 50 lineto
35 | 550 590 lineto stroke
36 |
37 | showpage
38 |
39 | /Helvetica findfont 60 scalefont setfont
40 | %%Page: 2
41 | /deltax 60 def
42 | /deltay 80 def
43 | /y 780 def
44 | /karten {
45 | /zeichen exch def
46 | /y y deltay sub def
47 | 40 deltax 500 {
48 | /x exch def
49 | x y moveto
50 | deltax 0 rlineto
51 | 0 deltay rlineto
52 | deltax -1 mul 0 rlineto
53 | 0 deltay -1 mul rlineto
54 | stroke
55 | x deltax 2 div add y deltay 2 div add moveto
56 | zeichen stringwidth pop -0.5 mul -20 rmoveto
57 | zeichen show
58 | } for
59 | } def
60 |
61 | (w) karten
62 | (S) karten
63 | ($) karten
64 | (\() karten
65 | (\)) karten
66 | (0) karten
67 | (1) karten
68 | (a) karten
69 | (b) karten
70 |
71 | showpage
72 |
73 | %%Trailer
74 |
--------------------------------------------------------------------------------
/code/minedemo/README:
--------------------------------------------------------------------------------
1 | Demo-Programm zum Problem MINESWEEPER-CONSISTENCY
2 |
3 | Mehr Information zum bauen und ausfuehren des Programmes findet sich
4 | im File build.xml. Beispiel-Minenfelder sind in den Files im
5 | Verzeichnis samples enthalten.
6 |
7 | wire.mines einfacher "Draht"
8 |
9 | crossover.mines Ueberkreuzung von zwei "Draehten"
10 |
11 | splitter.mines Splitter, Verzweigung von "Draehten"
12 |
13 | and.mines UND Verknuepfung
14 |
15 | or.mines ODER Verknuepfung
16 |
17 | xor.mines XOR Verknuepfung
18 |
19 | test.mines kleines Testbeispiel
20 |
21 |
--------------------------------------------------------------------------------
/code/minedemo/ch/hsr/autospr/minesweeper/IllegalStateException.java:
--------------------------------------------------------------------------------
1 | //
2 | // IllegalStateException.java -- exception thrown when a bad state is set
3 | //
4 | // (c) 2008 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | // $Id: IllegalStateException.java,v 1.1 2008/03/12 14:53:20 afm Exp $
6 | //
7 | package ch.hsr.autospr.minesweeper;
8 |
9 | public class IllegalStateException extends Exception {
10 | public IllegalStateException() { }
11 | public IllegalStateException(String message) { super(message); }
12 | public IllegalStateException(Throwable cause) { super(cause); }
13 | public IllegalStateException(String message, Throwable cause) {
14 | super(message, cause);
15 | }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/code/minedemo/ch/hsr/autospr/minesweeper/InconsistentConfigurationException.java:
--------------------------------------------------------------------------------
1 | //
2 | // InconsistentConfigurationException.java -- exception thrown when an
3 | // inconsistent configuration is
4 | // encountered
5 | //
6 | // (c) 2008 Prof Dr Andreas Mueller, Hochschule Rapperswil
7 | // $Id: InconsistentConfigurationException.java,v 1.1 2008/03/12 14:53:20 afm Exp $
8 | //
9 | package ch.hsr.autospr.minesweeper;
10 |
11 | public class InconsistentConfigurationException extends Exception {
12 | public InconsistentConfigurationException() { }
13 | public InconsistentConfigurationException(String message) {
14 | super(message);
15 | }
16 | public InconsistentConfigurationException(Throwable cause) {
17 | super(cause);
18 | }
19 | public InconsistentConfigurationException(String message,
20 | Throwable cause) {
21 | super(message, cause);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/code/minedemo/ch/hsr/autospr/minesweeper/Mine.java:
--------------------------------------------------------------------------------
1 | //
2 | // Mine.java -- class to hold common constants for buttons and labels
3 | //
4 | // (c) 2008 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | // $Id: Mine.java,v 1.1 2008/03/12 14:53:20 afm Exp $
6 | //
7 | package ch.hsr.autospr.minesweeper;
8 |
9 | /**
10 | * holder class for mine field states.
11 | *
12 | * @author Andreas Mueller
13 | */
14 | public class Mine {
15 | public final static int UNKNOWN = -3;
16 | public final static int BOMB = -2;
17 | public final static int MARKED = -1;
18 |
19 | public final static int OPEN = 0;
20 | public final static int BOMBS_0 = 0;
21 | public final static int BOMBS_1 = 1;
22 | public final static int BOMBS_2 = 2;
23 | public final static int BOMBS_3 = 3;
24 | public final static int BOMBS_4 = 4;
25 | public final static int BOMBS_5 = 5;
26 | public final static int BOMBS_6 = 6;
27 | public final static int BOMBS_7 = 7;
28 | public final static int BOMBS_8 = 8;
29 |
30 | public final static int WIDTH = 20;
31 | public final static int HEIGHT = 20;
32 |
33 | public static boolean isButtonState(int state) {
34 | return (state == UNKNOWN) || (state == BOMB);
35 | }
36 |
37 | public static boolean isLabelState(int state) {
38 | return ((state >= -1) && (state <= BOMBS_8));
39 | }
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/code/minedemo/ch/hsr/autospr/minesweeper/MineComponent.java:
--------------------------------------------------------------------------------
1 | //
2 | // MineComponent.java -- common methods for
3 | //
4 | // (c) 2008 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | // $Id: MineComponent.java,v 1.1 2008/03/12 14:53:20 afm Exp $
6 | //
7 | package ch.hsr.autospr.minesweeper;
8 |
9 | public interface MineComponent {
10 | public void setPosition(Position where);
11 | public Position getPosition();
12 | public void reset();
13 | public void clear();
14 | public boolean isBomb();
15 | public boolean isUnknown();
16 | public boolean hasBombcount();
17 | }
18 |
--------------------------------------------------------------------------------
/code/minedemo/ch/hsr/autospr/minesweeper/MineFactory.java:
--------------------------------------------------------------------------------
1 | //
2 | // MineFactory.java -- build mine buttons
3 | //
4 | // (c) 2008 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | // $Id: MineFactory.java,v 1.1 2008/03/12 14:53:20 afm Exp $
6 | //
7 | package ch.hsr.autospr.minesweeper;
8 |
9 | import javax.swing.*;
10 |
11 | /**
12 | * Build Mine components (Labels are buttons).
13 | *
14 | * @author Andreas Mueller
15 | */
16 | public class MineFactory {
17 | JComponent get(int state) throws IllegalStateException {
18 | if (Mine.isButtonState(state)) {
19 | MineButton b = new MineButton(state);
20 | b.addActionListener(new BombActionListener(b));
21 | return b;
22 | }
23 | if (Mine.isLabelState(state)) {
24 | return new MineLabel(state);
25 | }
26 | return null;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/code/minedemo/ch/hsr/autospr/minesweeper/ResetActionListener.java:
--------------------------------------------------------------------------------
1 | //
2 | // ResetActionListener.java
3 | //
4 | // (c) 2008 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | // $Id: ResetActionListener.java,v 1.1 2008/03/12 14:53:20 afm Exp $
6 | //
7 | package ch.hsr.autospr.minesweeper;
8 |
9 | import java.awt.event.*;
10 |
11 | public class ResetActionListener implements ActionListener {
12 | MineField field;
13 | public ResetActionListener(MineField field) {
14 | this.field = field;
15 | }
16 | public void actionPerformed(ActionEvent ev) {
17 | System.out.println("clearing field");
18 | field.clear();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/code/minedemo/ch/hsr/autospr/minesweeper/Solver.java:
--------------------------------------------------------------------------------
1 | //
2 | // Solver.java -- find as many bombs as possible
3 | //
4 | // (c) 2008 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | // $Id: Solver.java,v 1.1 2008/03/12 14:53:20 afm Exp $
6 | //
7 | package ch.hsr.autospr.minesweeper;
8 |
9 | import java.util.Vector;
10 |
11 | /**
12 | * Global solver algorithm.
13 | *
14 | * @author Andreas Mueller
15 | */
16 | public class Solver {
17 | MineField minefield;
18 |
19 | public Solver(MineField minefield) {
20 | this.minefield = minefield;
21 | }
22 |
23 | public void solve() throws InconsistentConfigurationException {
24 | minefield.reset();
25 | // convert the
26 | MineButton[] fields = minefield.getModifiable();
27 |
28 | // go through the fields and try to determine the state
29 | // based on the information you find in the neighbor
30 | int changes = 0;
31 | do {
32 | changes = 0;
33 | for (int i = 0; i < fields.length; i++) {
34 | changes += fields[i].solve();
35 | }
36 | System.out.println("changes: " + changes);
37 | } while (changes > 0);
38 |
39 | }
40 |
41 | }
42 |
43 |
--------------------------------------------------------------------------------
/code/minedemo/resources/marker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/code/minedemo/resources/marker.png
--------------------------------------------------------------------------------
/code/minedemo/resources/smBomb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/code/minedemo/resources/smBomb.png
--------------------------------------------------------------------------------
/code/minedemo/runall:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | #
3 | # start all apps
4 | #
5 | # (c) 2021 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
6 | #
7 | nohup ant wire &
8 | nohup ant cross &
9 | nohup ant splitter &
10 | nohup ant and &
11 |
--------------------------------------------------------------------------------
/code/minedemo/samples/and.mines:
--------------------------------------------------------------------------------
1 | U01U10UUUUUUUUUUUUUUUUUUUUUUUUUU
2 | U01U10UUUUUUUUUUUUUUUUUUUUUUUUUU
3 | U01110UUUUUUUUUUUUUUUUUUUUUUUUUU
4 | U01U10UUUUUUUUUUUUUUUUUUUUUUUUUU
5 | U01U10UUUUUUUUUUUUUUUUUUUUUUUUUU
6 | U01110UUUUUUUUUUUUUUUUUUUUUUUUUU
7 | U01U10UUUUUUUUUUUUUUUUUUUUUUUUUU
8 | U01U1000000000000000UUUUUUUUUUUU
9 | U011100122101110111000UUUUUUUUUU
10 | U01U1002MM323M212M3210UUUUUUUUUU
11 | 001U1124MUUUUU3UU3MM20UUUUUUUUUU
12 | 012211MM4M323M2112UM20UUUUUUUUUU
13 | 02MU224U31101110012210000UUUUUUU
14 | 02MM3UUU2111111111U111111111111U
15 | 0245M4M4UU1UU1UU1U2U1UU1UU1UU1UU
16 | 02MM3UUU2111111111U111111111111U
17 | 02MU224U31101110012210000000000U
18 | 012211MM4M323M2112UM20UUUUUUUUUU
19 | 001U1124MUUUUU3UU3MM20UUUUUUUUUU
20 | U01U1002MM323M212M3210UUUUUUUUUU
21 | U011100122101110111000UUUUUUUUUU
22 | U01U1000000000000000UUUUUUUUUUUU
23 | U01U10UUUUUUUUUUUUUUUUUUUUUUUUUU
24 | U01110UUUUUUUUUUUUUUUUUUUUUUUUUU
25 | U01U10UUUUUUUUUUUUUUUUUUUUUUUUUU
26 | U01U10UUUUUUUUUUUUUUUUUUUUUUUUUU
27 | U01110UUUUUUUUUUUUUUUUUUUUUUUUUU
28 | U01U10UUUUUUUUUUUUUUUUUUUUUUUUUU
29 | U01U10UUUUUUUUUUUUUUUUUUUUUUUUUU
30 |
--------------------------------------------------------------------------------
/code/minedemo/samples/crossover.mines:
--------------------------------------------------------------------------------
1 | UUUUUUUUUUUUUUUUUUUUUUU
2 | UUUUUUUUU01U10UUUUUUUUU
3 | UUUUUUUUU01110UUUUUUUUU
4 | UUUUUUUUU01U10UUUUUUUUU
5 | UUUUUUUUU01U10UUUUUUUUU
6 | UUUUUUUUU01110UUUUUUUUU
7 | UUUUUUUUU01U10UUUUUUUUU
8 | UUUUUUUUU01U10UUUUUUUUU
9 | U000000000111000000000U
10 | U1111111112U2111111111U
11 | UU1UU1UU1UUUUU1UU1UU1UU
12 | U111111111222111111111U
13 | U0000000001U1000000000U
14 | UUUUUUUUU01U10UUUUUUUUU
15 | UUUUUUUUU01110UUUUUUUUU
16 | UUUUUUUUU01U10UUUUUUUUU
17 | UUUUUUUUU01U10UUUUUUUUU
18 | UUUUUUUUU01110UUUUUUUUU
19 | UUUUUUUUU01U10UUUUUUUUU
20 | UUUUUUUUU01U10UUUUUUUUU
21 | UUUUUUUUU01110UUUUUUUUU
22 | UUUUUUUUUUUUUUUUUUUUUUU
23 |
--------------------------------------------------------------------------------
/code/minedemo/samples/or.mines:
--------------------------------------------------------------------------------
1 | UUUUUUUU01U10UUUUUUUUUUUUUUUU
2 | UUUUUUUU01U10UUUUUUUUUUUUUUUU
3 | UUUUUUUU01110UUUUUUUUUUUUUUUU
4 | UUUUUUUU01U10UUUUUUUUUUUUUUUU
5 | UUUUUUUU01U10UUUUUUUUUUUUUUUU
6 | UUUUUUUU01110UUUUUUUUUUUUUUUU
7 | UUUUUUUU01U10000000UUUUUUUUUU
8 | UUUUUUU001U10123210UUUUUUUUUU
9 | 00000000123211MMM10000000000U
10 | 111111112MUM223U321111111111U
11 | UU1UU1UU3U6UU1U2U1UU1UU1UU1UU
12 | 111111112MUM322U221111111111U
13 | 0000000023422M33M10000000000U
14 | UUUUUUU02MU334UM310UUUUUUUUUU
15 | UUUUUUU02MMUUUMM200UUUUUUUUUU
16 | UUUUUUU013MMMMM310UUUUUUUUUUU
17 | UUUUUUU00123332100UUUUUUUUUUU
18 | UUUUUUUU000000000UUUUUUUUUUUU
19 |
--------------------------------------------------------------------------------
/code/minedemo/samples/splitter.mines:
--------------------------------------------------------------------------------
1 | UUUUUUUUUUUUUUUUUUUUUUUUUUU
2 | UUUUUUUUUU001U100UUUUUUUUUU
3 | UUUUUUUUUU001U100UUUUUUUUUU
4 | UUUUUUUUUU0011100UUUUUUUUUU
5 | UUUUUUUUUU001U100UUUUUUUUUU
6 | UUUUUUUUUU001U100UUUUUUUUUU
7 | UUUUUUUUUU0011100UUUUUUUUUU
8 | UUUUUUUUUU001U100UUUUUUUUUU
9 | UUUUUUUUUU001U100UUUUUUUUUU
10 | U0000000000011100000000000U
11 | U111111111111U111111111111U
12 | UU1UU1UU1UU1U2U1UU1UU1UU1UU
13 | U111111111111U111111111111U
14 | U0000000000011100000000000U
15 | UUUUUUUUUU001U100UUUUUUUUUU
16 | UUUUUUUUUU001U100UUUUUUUUUU
17 | UUUUUUUUUU0011100UUUUUUUUUU
18 | UUUUUUUUUU001U100UUUUUUUUUU
19 | UUUUUUUUUU001U100UUUUUUUUUU
20 | UUUUUUUUUU0011100UUUUUUUUUU
21 | UUUUUUUUUU001U100UUUUUUUUUU
22 | UUUUUUUUUU001U100UUUUUUUUUU
23 | UUUUUUUUUU00UUU00UUUUUUUUUU
24 |
--------------------------------------------------------------------------------
/code/minedemo/samples/test.mines:
--------------------------------------------------------------------------------
1 | 0000000
2 | 0112110
3 | 01U2U10
4 | 0112110
5 | 0000000
6 |
--------------------------------------------------------------------------------
/code/minedemo/samples/wire.mines:
--------------------------------------------------------------------------------
1 | U000000000000000000U
2 | U111111111111111111U
3 | UU1UU1UU1UU1UU1UU1UU
4 | U111111111111111111U
5 | U000000000000000000U
6 |
--------------------------------------------------------------------------------
/code/minedemo/samples/xor.mines:
--------------------------------------------------------------------------------
1 | UUUUUUUUUUUU00000000000UUUUUUUUU
2 | U000000000001111110111000000000U
3 | U111111111112M33M212M2111111111U
4 | U1UU1UU1UU1UU3MM4UU3U3UU1UU1UU1U
5 | U1111111111112UU3112M2111111111U
6 | U000000000001233222321000000000U
7 | U111111111113MUUM3MM210UUUUUUUUU
8 | U1UU1UU1UU1UUMU6U4U6M20UUUUUUUUU
9 | U1111111111123MUM3MUM20UUUUUUUUU
10 | U000000000000235332U210UUUUUUUUU
11 | UUUUUUUUUUUU01MUM111100UUUUUUUUU
12 | UUUUUUUUUUUU0234222U100UUUUUUUUU
13 | UUUUUUUUUUUU02MU12MU210UUUUUUUUU
14 | UUUUUUUUUUUU02M5U4U5M10UUUUUUUUU
15 | UUUUUUUUUUUU012MM3MM210UUUUUUUUU
16 | UUUUUUUUUUUU00122222100UUUUUUUUU
17 | UUUUUUUUUUUUU000000000UUUUUUUUUU
18 |
--------------------------------------------------------------------------------
/code/ragel/teilbar.c:
--------------------------------------------------------------------------------
1 | /*
2 | * teilbar.c --- simple ragel example
3 | *
4 | * (c) 2023 Prof Dr Andreas Müller
5 | */
6 | #include
7 | #include
8 | #include
9 |
10 | %%{
11 | machine teilbar;
12 | action istteilbar { res = 1; }
13 | teilbar :=
14 | start: (
15 | '0' -> start |
16 | '1' -> one |
17 | '' %istteilbar -> final
18 | ),
19 | one: (
20 | '0' -> two |
21 | '1' -> start
22 | ),
23 | two: (
24 | '0' -> one |
25 | '1' -> two
26 | );
27 | }%%
28 |
29 | %% write data;
30 |
31 | int main(int argc, char *argv[]) {
32 | int cs, res = 0;
33 | int i;
34 | for (i = 1; i < argc; i++) {
35 | res = 0;
36 | char *p = argv[i];
37 | char *pe = p + strlen(p);
38 | char *eof = pe;
39 | %% write init;
40 | %% write exec;
41 | printf("%s %s\n", argv[i], (res) ? "teilbar" : "nicht teilbar");
42 | }
43 | return EXIT_SUCCESS;
44 | }
45 |
--------------------------------------------------------------------------------
/code/ragel/teilbar.dot:
--------------------------------------------------------------------------------
1 | digraph teilbar {
2 | rankdir=LR;
3 | node [ shape = point ];
4 | ENTRY;
5 | en_3;
6 | eof_3;
7 | node [ shape = circle, height = 0.2 ];
8 | node [ fixedsize = true, height = 0.65, shape = doublecircle ];
9 | 3;
10 | node [ shape = circle ];
11 | 1 -> 2 [ label = "48" ];
12 | 1 -> 3 [ label = "49" ];
13 | 2 -> 1 [ label = "48" ];
14 | 2 -> 2 [ label = "49" ];
15 | 3 -> 3 [ label = "48" ];
16 | 3 -> 1 [ label = "49" ];
17 | ENTRY -> 3 [ label = "IN" ];
18 | en_3 -> 3 [ label = "teilbar" ];
19 | 3 -> eof_3 [ label = "EOF / istteilbar" ];
20 | }
21 |
--------------------------------------------------------------------------------
/code/ragel/teilbar.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/code/ragel/teilbar.pdf
--------------------------------------------------------------------------------
/code/ragel/teilbar.rl:
--------------------------------------------------------------------------------
1 | /*
2 | * teilbar.rl -- durch 3 teilbare Binärzahlen
3 | *
4 | * (c) 2023 Prof Dr Andreas Müller
5 | */
6 |
7 | public class teilbar {
8 |
9 | %%{
10 | machine teilbar;
11 | action istteilbar { res = 1; }
12 | teilbar :=
13 | start: (
14 | '0' -> start |
15 | '1' -> one |
16 | '' %istteilbar -> final
17 | ),
18 | one: (
19 | '0' -> two |
20 | '1' -> start
21 | ),
22 | two: (
23 | '0' -> one |
24 | '1' -> two
25 | );
26 | }%%
27 | %% write data;
28 |
29 | public static void main(String args[]) {
30 | int cs, res = 0;
31 | int i;
32 | for (i = 1; i < args.length; i++) {
33 | String s = args[i];
34 | System.out.print(s + ": ");
35 |
36 | byte[] data = s.getBytes();
37 | res = 0;
38 | int p = 0;
39 | int pe = data.length;
40 | int eof = pe;
41 | %% write init;
42 | %% write exec;
43 |
44 | if (res == 0) {
45 | System.out.print("nicht ");
46 | }
47 | System.out.println("teilbar");
48 | }
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/code/ragel/ungerade.c:
--------------------------------------------------------------------------------
1 | /*
2 | * ungerade.c --- simple ragel example
3 | *
4 | * (c) 2023 Prof Dr Andreas Müller
5 | */
6 | #include
7 | #include
8 | #include
9 |
10 | %%{
11 | machine ungerade;
12 | action istungerade { res = 1; }
13 | }%%
14 |
15 | %% write data;
16 |
17 | int main(int argc, char *argv[]) {
18 | int cs, res = 0;
19 | int i;
20 | for (i = 1; i < argc; i++) {
21 | res = 0;
22 | char *p = argv[i];
23 | char *pe = p + strlen(p);
24 | char *eof = pe;
25 | %%{
26 | ungerade := ('1'*'0'('1'|'0'('1')*'0')*) %istungerade;
27 | write init;
28 | write exec;
29 | }%%
30 | printf("%s %sgerade Anzahl Nullen\n", argv[i],
31 | (res) ? "un" : "");
32 | }
33 | return EXIT_SUCCESS;
34 | }
35 |
--------------------------------------------------------------------------------
/code/ragel/ungerade.dot:
--------------------------------------------------------------------------------
1 | digraph ungerade {
2 | rankdir=LR;
3 | node [ shape = point ];
4 | ENTRY;
5 | en_1;
6 | eof_5;
7 | eof_6;
8 | eof_7;
9 | node [ shape = circle, height = 0.2 ];
10 | node [ fixedsize = true, height = 0.65, shape = doublecircle ];
11 | 5;
12 | 6;
13 | 7;
14 | node [ shape = circle ];
15 | 1 -> 5 [ label = "48" ];
16 | 1 -> 4 [ label = "49" ];
17 | 2 -> 6 [ label = "48" ];
18 | 2 -> 3 [ label = "49" ];
19 | 3 -> 6 [ label = "48" ];
20 | 3 -> 3 [ label = "49" ];
21 | 4 -> 5 [ label = "48" ];
22 | 4 -> 4 [ label = "49" ];
23 | 5 -> 2 [ label = "48" ];
24 | 5 -> 7 [ label = "49" ];
25 | 6 -> 2 [ label = "48" ];
26 | 6 -> 7 [ label = "49" ];
27 | 7 -> 2 [ label = "48" ];
28 | 7 -> 7 [ label = "49" ];
29 | ENTRY -> 1 [ label = "IN" ];
30 | en_1 -> 1 [ label = "ungerade" ];
31 | 5 -> eof_5 [ label = "EOF / istungerade" ];
32 | 6 -> eof_6 [ label = "EOF / istungerade" ];
33 | 7 -> eof_7 [ label = "EOF / istungerade" ];
34 | }
35 |
--------------------------------------------------------------------------------
/code/ragel/ungerade.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/code/ragel/ungerade.pdf
--------------------------------------------------------------------------------
/code/ragel/ungerade_minimized.dot:
--------------------------------------------------------------------------------
1 | digraph ungerade {
2 | rankdir=LR;
3 | node [ shape = point ];
4 | ENTRY;
5 | en_1;
6 | eof_2;
7 | node [ shape = circle, height = 0.2 ];
8 | node [ fixedsize = true, height = 0.65, shape = doublecircle ];
9 | 2;
10 | node [ shape = circle ];
11 | 1 -> 2 [ label = "48" ];
12 | 1 -> 1 [ label = "49" ];
13 | 2 -> 1 [ label = "48" ];
14 | 2 -> 2 [ label = "49" ];
15 | ENTRY -> 1 [ label = "IN" ];
16 | en_1 -> 1 [ label = "ungerade" ];
17 | 2 -> eof_2 [ label = "EOF / istungerade" ];
18 | }
19 |
--------------------------------------------------------------------------------
/code/ragel/ungerade_minimized.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndreasFMueller/AutoSpr/e2b732d79e15c29c87d8506f2e89dbe027485c0b/code/ragel/ungerade_minimized.pdf
--------------------------------------------------------------------------------
/code/regex/bash/regex.bash:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | #
3 | # The bash supports regex matching without recourse to an external program.
4 | # And it supports modern standard regex metacharacters. Here is how it
5 | # performs.
6 | #
7 | # (c) 2010 Prof Dr Andreas Mueller, Hochschule Rapperswil
8 | #
9 | string1='a'
10 | string2='a?'
11 | i=0
12 | while [ $i -lt 29 ]
13 | do
14 | if [[ ${string1} =~ ${string2}${string1} ]]
15 | then
16 | printf "%29s matches %s\n" ${string1} ${string2}${string1}
17 | else
18 | printf "%29s does not match %s\n" ${string1} ${string2}${string1}
19 | fi
20 | i=`expr $i + 1`
21 | string1="${string1}"a
22 | string2="${string2}"'a?'
23 | done
24 |
--------------------------------------------------------------------------------
/code/regex/c/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile -- Baue das Beispiel-Programm zum Regex-Matcher der C-Library
3 | #
4 | # (c) 2010 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | #
6 | regex: regex.c
7 | gcc -Wall -O -g -o regex regex.c
8 |
9 | test: regex
10 | time ./regex
11 |
12 | clean:
13 | rm ./regex
14 |
--------------------------------------------------------------------------------
/code/regex/cpp/Makefile:
--------------------------------------------------------------------------------
1 | GCC := g++ -Wall -std=c++14 -g -O2
2 |
3 | all: main.cpp regex.cpp
4 | $(GCC) -o regex main.cpp regex.cpp
5 |
6 | clean:
7 | rm ./regex
8 |
9 | test: regex
10 | ./regex
11 |
--------------------------------------------------------------------------------
/code/regex/cpp/regex.h:
--------------------------------------------------------------------------------
1 | #ifndef REGEX_H_
2 | #define REGEX_H_
3 |
4 | #include
5 | #include
6 |
7 | namespace Regex {
8 |
9 | void test(std::ostream & out, size_t const & numberOfRounds, int repetitions, bool measure);
10 |
11 | } // namespace Regex
12 |
13 | #endif /* REGEX_H_ */
14 |
--------------------------------------------------------------------------------
/code/regex/csharp/README:
--------------------------------------------------------------------------------
1 | Nach der heutigen Vorlesung musste ich natürlich verifizieren,
2 | dass die Regex-Engine von C# besser sein muss, als jene in Java.
3 | Zu meinem Schrecken musste ich nach Testen jedoch feststellen,
4 | dass dies nicht der Fall ist.
5 | Auch C# leidet wohl unter "Feature-itis" 😨 - immerhin verspricht
6 | .NET 5 besserung.
7 |
8 | Vorbedingung:
9 |
10 | Lokal Installiertes .NET Core SDK
11 | Verwendung:
12 |
13 | dotnet run true - Mit Option 'Compiled', etwa vier mal schneller,
14 | aber immer noch langsam
15 | dotnet run false - Ohne Optionen, fast so langsam wie Python
16 |
17 |
18 | Pascal Honegger
19 |
--------------------------------------------------------------------------------
/code/regex/csharp/csharp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | net6.0
5 |
6 |
7 |
--------------------------------------------------------------------------------
/code/regex/go/README:
--------------------------------------------------------------------------------
1 | to run type
2 |
3 | $ go run regex.go
4 |
--------------------------------------------------------------------------------
/code/regex/go/regex.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "regexp"
6 | "time"
7 | )
8 |
9 | func main() {
10 | r1 := ""
11 | r2 := ""
12 |
13 | for i := 0; i < 29; i++ {
14 | r1 += "a?"
15 | r2 += "a"
16 | regex := r1 + r2
17 | r, err := regexp.Compile(regex)
18 |
19 | if err != nil {
20 | fmt.Println(err)
21 | }
22 |
23 | start := time.Now()
24 | if r.MatchString(r2) {
25 | fmt.Printf("%8d us : %s matches %s\n", time.Since(start).Microseconds(), r2, regex)
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/code/regex/java/README:
--------------------------------------------------------------------------------
1 | Zwei regex-Interfaces, die aber intern den gleichen Code verwenden:
2 |
3 | ant test-string
4 | ant test-regex
5 |
--------------------------------------------------------------------------------
/code/regex/java/ch/ost/autospr/RegexMatcher.java:
--------------------------------------------------------------------------------
1 | //
2 | // RegexMatcher.java -- Matcher implementation based on java.util.regex
3 | //
4 | //
5 | // (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
6 | //
7 | package ch.ost.autospr;
8 |
9 | import java.util.regex.Pattern;
10 | import java.util.regex.Matcher;
11 |
12 | /**
13 | * Matcher implementation based on java.util.regex.
14 | *
15 | * This matcher uses the classes java.lang.regex.Pattern and
16 | * java.lang.regex.Matcher to perform matches.
17 | *
18 | * @author Andreas Mueller
19 | */
20 | public class RegexMatcher implements matcher {
21 | public RegexMatcher() { }
22 | public boolean matches(String string, String regex) {
23 | Pattern p = Pattern.compile(regex);
24 | Matcher m = p.matcher(string);
25 | return m.matches();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/code/regex/java/ch/ost/autospr/StringMatcher.java:
--------------------------------------------------------------------------------
1 | //
2 | // StringMatcher.java -- matcher implementation based on java.lang.String
3 | //
4 | //
5 | // (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
6 | //
7 | package ch.ost.autospr;
8 |
9 | /**
10 | * Matcher implementation based on java.lang.String.
11 | *
12 | * @author Andreas Mueller
13 | */
14 | public class StringMatcher implements matcher {
15 | public StringMatcher() { }
16 | public boolean matches(String string, String regex) {
17 | return string.matches(regex);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/code/regex/java/ch/ost/autospr/matcher.java:
--------------------------------------------------------------------------------
1 | //
2 | // matcher.java -- Common matcher interface
3 | //
4 | // (c) 2012 Prof Dr Andreas Müller, Hochschule Rapperswil
5 | //
6 | package ch.ost.autospr;
7 |
8 | import java.util.regex.Pattern;
9 | import java.util.regex.Matcher;
10 |
11 | /**
12 | * Common interface for regex matchers.
13 | *
14 | * Because the two regex matchers in question have completely
15 | * different APIs, we create a common API so that we can later
16 | * wrap both matchers in wrapper classes implementing this
17 | * common interface.
18 | *
19 | * @author Andreas Müller
20 | */
21 | public interface matcher {
22 | /**
23 | * Match a string against a regular expression.
24 | * @param string String to match
25 | * @param regex Regular expression string
26 | */
27 | public boolean matches(String string, String regex);
28 | }
29 |
--------------------------------------------------------------------------------
/code/regex/java/ch/ost/autospr/matcherfactory.java:
--------------------------------------------------------------------------------
1 | //
2 | // matcherfactory.java -- factory class to build matchers
3 | //
4 | // (c) 2012 Prof Dr Andreas Mueller, Hochschule Rapperswil
5 | //
6 | package ch.ost.autospr;
7 |
8 | import java.lang.reflect.Constructor;
9 | import java.lang.reflect.InvocationTargetException;
10 |
11 | /**
12 | * Construct matchers at runtime based on the class name.
13 | *
14 | * @author Andreas Mueller
15 | */
16 | public class matcherfactory {
17 | /**
18 | * Factory Method to construct matchers.
19 | * @param name Name identifying the matcher.
20 | */
21 | static public matcher get(String name) throws ClassNotFoundException,
22 | NoSuchMethodException, SecurityException,
23 | InstantiationException, IllegalAccessException,
24 | InvocationTargetException {
25 | Class> c = Class.forName(name);
26 | Constructor> constructor = c.getConstructor();
27 | return (matcher)constructor.newInstance();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/code/regex/javascript/regex.js:
--------------------------------------------------------------------------------
1 | var r1 = "";
2 | var r2 = "";
3 | var i = 0;
4 |
5 | while(i < 29) {
6 | i += 1;
7 | r1 += "a?";
8 | r2 += "a";
9 |
10 | var r = new RegExp(r1 + r2);
11 | if(r.test(r2)) {
12 | console.log(r2 + " matches " + r);
13 | } else {
14 | console.log("matching failure");
15 | }
16 | }
--------------------------------------------------------------------------------
/code/regex/mysql/regex_matcher.sql:
--------------------------------------------------------------------------------
1 | DROP PROCEDURE IF EXISTS regex_matcher;
2 |
3 | DELIMITER $$
4 | CREATE PROCEDURE regex_matcher()
5 | BEGIN
6 | DECLARE n INT DEFAULT 29;
7 | DECLARE i INT DEFAULT 0;
8 |
9 | DECLARE s1 VARCHAR(58) DEFAULT "";
10 | DECLARE s2 VARCHAR(29) DEFAULT "";
11 | DECLARE regex VARCHAR(87);
12 |
13 | WHILE i < n - 1 DO
14 | SET s1 = CONCAT(s1, 'a?');
15 | SET s2 = CONCAT(s2, 'a');
16 | SET regex = CONCAT(s1, s2);
17 |
18 | SELECT
19 | CASE
20 | WHEN s2 REGEXP regex THEN (SELECT CONCAT(s2, ' matches ', regex))
21 | END
22 | FROM dual;
23 |
24 | SET i = i + 1;
25 | END WHILE;
26 | END
27 | $$
28 |
29 | CALL regex_matcher();
--------------------------------------------------------------------------------
/code/regex/perl/regex.pl:
--------------------------------------------------------------------------------
1 | #! /usr/bin/perl
2 | #
3 | # Nachweis der potentiell exponentiellen Laufzeit des Regex Matchers von Perl
4 | #
5 | # Der regulaere Ausdruck
6 | #
7 | # a?a?a?a?a?a?aaaa
8 | #
9 | # beziehungsweise seine Verallgemeinerung (a?)^na^n akzeptiert den
10 | # String a^n, aber ein NEA wird dafuer Zeit O(2^n) benoetigen.
11 | #
12 | # Das Programm erzeugt nacheinander regulaere Ausdruecke und passende
13 | # Strings immer groesserer Laenge. Dabei kann man das exponentielle
14 | # Anwachsen der Laufzeit beobachten.
15 | #
16 | # Ausfuehrung:
17 | #
18 | # $ perl regex.pl
19 | #
20 | # (c) 2010 Prof Dr Andreas Mueller, Hochschule Rapperswil
21 | #
22 | use Time::HiRes qw(time);
23 | $string = "";
24 | $regex = "";
25 |
26 | # Test den Regex Matcher fuer Stringlaengen zwischen 1 und 29
27 | for ($i = 1; $i <= 29; $i++) {
28 | # Verlaengere die Komponenten $regex und $string um je ein
29 | # zusaetzliches Element
30 | $string .= "a";
31 | $regex .= "a?";
32 |
33 | # Baue daraus jetzt den regulaeren Ausdruck auf
34 | $r = $regex.$string;
35 |
36 | # Fuehre den Regex Match durch
37 | $start = time;
38 | if ($string =~ m/$r/) {
39 | $end = time;
40 | printf("%29s matches %s %*s %.6f\n", $string, $r, 3*(29-$i), "", $end - $start);
41 | } else {
42 | printf("%29s does not match %s\n", $string, $r);
43 | }
44 | }
45 |
46 | exit 0;
47 |
--------------------------------------------------------------------------------
/code/regex/powershell/regex.ps1:
--------------------------------------------------------------------------------
1 | $r1 = ""
2 | $r2 = ""
3 | for($i = 0; $i -lt 29; $i++) {
4 | $r1 += "a?"
5 | $r2 += "a"
6 | $r = $r1 + $r2
7 | if($r2 -match $r) {
8 | Write-Host "$r2 matches $r"
9 | } else {
10 | Write-Host "matching failure"
11 | }
12 | }
--------------------------------------------------------------------------------
/code/regex/python/README.md:
--------------------------------------------------------------------------------
1 | Dieser Ordner beinhaltet Tests für zwei verschiedene Regex-Libraries für Python:
2 |
3 | - `re` in der Python standard library (`regex_stdlib.py`)
4 | - `regex` [von PyPI](https://pypi.python.org/pypi/regex)
5 |
6 | regex installieren:
7 |
8 | python3 -m pip install regex
9 |
--------------------------------------------------------------------------------
/code/regex/python/regex_pypi.py:
--------------------------------------------------------------------------------
1 | #! /usr/bin/python
2 | import regex
3 | import time
4 | r1 = ""
5 | r2 = ""
6 | i = 0
7 | maxi = 26
8 | while i < maxi:
9 | i += 1
10 | r1 += "a?"
11 | r2 += "a"
12 | r = r1 + r2
13 | start = time.time()
14 | if regex.match(r, r2):
15 | end = time.time()
16 | print("%*s matches %*s %*.6f s" % (maxi, r2, -3*maxi, r, 10, end-start))
17 | else:
18 | print("matching failure\n")
19 |
20 |
--------------------------------------------------------------------------------
/code/regex/python/regex_stdlib.py:
--------------------------------------------------------------------------------
1 | #! /usr/bin/python
2 | import time
3 | import re
4 | r1 = ""
5 | r2 = ""
6 | i = 0
7 | maxi = 29
8 | while i < maxi:
9 | i += 1
10 | r1 += "a?"
11 | r2 += "a"
12 | r = r1 + r2
13 | before = time.time()
14 | if re.match(r, r2):
15 | runtime = time.time() - before
16 | print("%*s matches %*s %*.6f s" % (maxi, r2, -3*maxi, r, 10, runtime))
17 | else:
18 | print("matching failure")
19 |
20 |
--------------------------------------------------------------------------------
/code/regex/re2/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Makefile -- Baue Beispielprogramm fuer die Verwendung des schnellen
3 | # Regex Matchers RE2 von Google
4 | #
5 | # (c) 2010-2020 Prof Dr Andreas Mueller, Hochschule Rapperswil
6 | # (c) 2021 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
7 | #
8 |
9 | regex: regex.cpp
10 | g++ --std=c++17 -Wall -g -O2 -o regex regex.cpp \
11 | $$(pkg-config --cflags re2) \
12 | $$(pkg-config --libs re2)
13 |
--------------------------------------------------------------------------------
/code/regex/rust/.gitignore:
--------------------------------------------------------------------------------
1 | # Generated by Cargo
2 | # will have compiled files and executables
3 | debug/
4 | target/
5 |
6 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
7 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
8 | Cargo.lock
9 |
10 | # These are backup files generated by rustfmt
11 | **/*.rs.bk
12 |
--------------------------------------------------------------------------------
/code/regex/rust/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "regex-example"
3 | version = "0.1.0"
4 | authors = ["Jeremy Stucki "]
5 | edition = "2018"
6 |
7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8 |
9 | [dependencies]
10 | regex = "1"
11 |
--------------------------------------------------------------------------------
/code/regex/rust/readme.md:
--------------------------------------------------------------------------------
1 | Ausführen mit `cargo run --release`
2 |
--------------------------------------------------------------------------------
/code/regex/rust/src/main.rs:
--------------------------------------------------------------------------------
1 | use std::time::Instant;
2 | use regex::Regex;
3 |
4 | fn main() {
5 | for n in 0 ..= 29 {
6 | let input = "a".repeat(n);
7 | let pattern = "a?".repeat(n) + &input;
8 |
9 | let start_time = Instant::now();
10 | test_regex(&pattern, &input);
11 |
12 | let duration = start_time.elapsed();
13 | println!("{} matches {} and took {:?}", input, pattern, duration);
14 | }
15 | }
16 |
17 | fn test_regex(pattern: &str, input: &str) {
18 | let matcher = Regex::new(pattern).unwrap();
19 | let _ = matcher.is_match(input);
20 | }
21 |
--------------------------------------------------------------------------------
/code/regex/sh/regex.sh:
--------------------------------------------------------------------------------
1 | #! /bin/sh
2 | #
3 | # The shell does not have a built in regex matcher, so the only hope is to
4 | # use some command line tool The standard tool for this purpose would be
5 | # expr(1), so how fast is regex matching in expr? Unfortunately, expr
6 | # only understands a relatively old syntax of regex, in particular, it
7 | # does not understand the ? character. Never mind, this script puts together
8 | # an equivalent form.
9 | #
10 | # (c) 2010 Prof Dr Andreas Mueller, Hochschule Rapperswil
11 | #
12 | string1='a'
13 | string2='a\{0,1\}'
14 | i=0
15 | while [ $i -lt 29 ]
16 | do
17 | if expr ${string1} : ${string2}${string1} >/dev/null
18 | then
19 | printf "%29s matches %s\n" ${string1} ${string2}${string1}
20 | else
21 | printf "%29s does not match %s\n" ${string1} ${string2}${string1}
22 | fi
23 | i=`expr $i + 1`
24 | string1="${string1}"a
25 | string2="${string2}"'a\{0,1\}'
26 | done
27 |
--------------------------------------------------------------------------------
/code/turing/README:
--------------------------------------------------------------------------------
1 | Turing-Maschinen-Simulator und Beispieprogramme
2 |
3 | Das Verzeichnis pgm enthaelt einige Beispiel-Programme
4 |
5 | add binaere Addition von zwei Zahlen, die hintereinander auf dem
6 | Band stehen. Als initialer Bandinhalt muss eines der Files
7 | in data/addtape* verwendet werden.
8 |
9 | subtract Subtraktion von Zahlen in unaerer Darstellung. Als initialer
10 | Bandinhalt verwende man data/subtracttape
11 |
12 | beaver3 Bekannte busy beaver Programme mit 3 bis 5 Zustaenden
13 | beaver4
14 | beaver5
15 |
16 | How to copy the code to the linux emulator by Fabrice Bellart written
17 | in Javascript https://bellard.org/jslinux:
18 |
19 | 1. copy to pasteboard:
20 | pbcopy < turing-1.0.tar.gz.uu
21 |
22 |
23 |
--------------------------------------------------------------------------------
/code/turing/data/addtape:
--------------------------------------------------------------------------------
1 | 10100001011 01011001111
2 |
--------------------------------------------------------------------------------
/code/turing/data/addtape1:
--------------------------------------------------------------------------------
1 | 11100111000 10100001011
2 |
--------------------------------------------------------------------------------
/code/turing/data/addtape2:
--------------------------------------------------------------------------------
1 | 10111 10111
2 |
--------------------------------------------------------------------------------
/code/turing/data/addtape3:
--------------------------------------------------------------------------------
1 | 111010110111100110100010110001 000111010110111100110100010110
2 |
--------------------------------------------------------------------------------
/code/turing/data/subtracttape:
--------------------------------------------------------------------------------
1 | 1111111111111 111111111
2 |
--------------------------------------------------------------------------------
/code/turing/pgm/beaver3:
--------------------------------------------------------------------------------
1 | (0,0) -> (1,1) Right
2 | (0,1) -> (0,1) Halt
3 | (0,B) -> (1,1) Right
4 |
5 | (1,0) -> (2,0) Right
6 | (1,1) -> (1,1) Right
7 | (1,B) -> (2,0) Right
8 |
9 | (2,0) -> (2,1) Left
10 | (2,1) -> (0,1) Left
11 | (2,B) -> (2,1) Left
12 |
--------------------------------------------------------------------------------
/code/turing/pgm/beaver4:
--------------------------------------------------------------------------------
1 | (0,0) -> (1,1) Right
2 | (0,1) -> (1,1) Left
3 | (0,B) -> (1,1) Right
4 |
5 | (1,0) -> (0,1) Left
6 | (1,1) -> (2,0) Left
7 | (1,B) -> (0,1) Left
8 |
9 | (2,0) -> (2,1) Halt
10 | (2,1) -> (3,1) Left
11 | (2,B) -> (2,1) Halt
12 |
13 | (3,0) -> (3,1) Right
14 | (3,1) -> (0,0) Right
15 | (3,B) -> (3,1) Right
16 |
--------------------------------------------------------------------------------
/code/turing/pgm/beaver5:
--------------------------------------------------------------------------------
1 | (0,0) -> (1,1) Left
2 | (0,1) -> (2,1) Right
3 | (0,B) -> (1,1) Left
4 |
5 | (1,0) -> (2,1) Left
6 | (1,1) -> (1,1) Left
7 | (1,B) -> (2,1) Left
8 |
9 | (2,0) -> (3,1) Left
10 | (2,1) -> (4,0) Right
11 | (2,B) -> (3,1) Left
12 |
13 | (3,0) -> (0,1) Right
14 | (3,1) -> (3,1) Right
15 | (3,B) -> (0,1) Right
16 |
17 | (4,0) -> (4,1) Halt
18 | (4,1) -> (0,0) Right
19 | (4,B) -> (4,1) Halt
20 |
--------------------------------------------------------------------------------
/code/turing/pgm/subtract:
--------------------------------------------------------------------------------
1 | (0,0) -> (0,0) Right
2 | (0,1) -> (0,1) Right
3 | (0,B) -> (1,B) Right
4 |
5 | (1,0) -> (1,0) Right
6 | (1,1) -> (1,1) Right
7 | (1,B) -> (2,B) Left
8 |
9 | (2,0) -> (2,0) Left
10 | (2,1) -> (3,0) Left
11 | (2,B) -> (5,B) Right
12 |
13 | (3,0) -> (3,0) Left
14 | (3,1) -> (3,1) Left
15 | (3,B) -> (8,B) Left
16 |
17 | (4,0) -> (4,0) Right
18 | (4,1) -> (4,1) Right
19 | (4,B) -> (5,B) Right
20 |
21 | (5,0) -> (5,0) Right
22 | (5,1) -> (5,1) Right
23 | (5,B) -> (6,B) Left
24 |
25 | (6,0) -> (6,B) Left
26 | (6,1) -> (6,1) Left
27 | (6,B) -> (7,B) Left
28 |
29 | (7,0) -> (7,B) Left
30 | (7,1) -> (7,1) Left
31 | (7,B) -> (9,B) Right
32 |
33 | (8,0) -> (8,0) Left
34 | (8,1) -> (0,0) Right
35 | (8,B) -> (4,B) Right
36 |
37 | (9,0) -> (9,0) Halt
38 | (9,1) -> (9,1) Halt
39 | (9,B) -> (9,0) Halt
40 |
--------------------------------------------------------------------------------