Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Ludwig-Work/Lazy-Math-Instructor
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.3.0
Choose a base ref
...
head repository: Ludwig-Work/Lazy-Math-Instructor
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 5 commits
  • 7 files changed
  • 1 contributor

Commits on Jul 13, 2023

  1. Copy the full SHA
    b1e8e26 View commit details

Commits on Aug 1, 2023

  1. Add presentation slides

    Ludwig-Work committed Aug 1, 2023
    Copy the full SHA
    d45d7c1 View commit details
  2. Copy the full SHA
    7a416f6 View commit details

Commits on Aug 12, 2023

  1. Copy the full SHA
    35fa8bd View commit details

Commits on Feb 18, 2024

  1. Add final submission

    I just noticed I hadn't pushed the paper to this repository yet. This was my final submission for the proseminar.
    Ludwig-Work committed Feb 18, 2024
    Copy the full SHA
    642ced3 View commit details
Showing with 111 additions and 6 deletions.
  1. +8 −1 .gitignore
  2. +1 −1 LazyMathInstructor/Polynomial.cs
  3. BIN LazyMathInstructor_Paper.pdf
  4. +28 −4 README.md
  5. BIN Slides.pdf
  6. +71 −0 TermGenerator/termgenerator.py
  7. +3 −0 long_term.txt
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -360,4 +360,11 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd



# Python compiled / optimized files
__pycache__/
*.py[cod]
*$py.class
2 changes: 1 addition & 1 deletion LazyMathInstructor/Polynomial.cs
Original file line number Diff line number Diff line change
@@ -276,7 +276,7 @@ public override bool Equals(object obj)
/// </summary>
public override string ToString()
{
return string.Join(" + ", Coefficients.Select(x => (x.Value == 1 ? "" : x.Value)
return string.Join(" + ", Coefficients.Select(x => (x.Value == 1 && x.Key.Exponents.Any() ? "" : x.Value)
+ x.Key.ToString()));
}
}
Binary file added LazyMathInstructor_Paper.pdf
Binary file not shown.
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
# Lazy Math Instructor

## Introduction
This is my code for the proseminar [Selected Fun Problems of the ACM Programming Contest](https://db.cs.uni-tuebingen.de/teaching/ss23/acm-programming-contest-proseminar/) at the University of Tübingen, Summer Term 2023.
This is my code for the proseminar [Selected Fun Problems of the ACM Programming Contest](https://db.cs.uni-tuebingen.de/teaching/ss23/acm-programming-contest-proseminar/)
at the University of Tübingen, Summer Term 2023.

The problem worked on is the [Lazy Math Instructor](./Lazy-Math-Instructor.pdf): The exercise is to check arbitrary terms for equivalence.
The problem worked on is *Lazy Math Instructor*: The exercise is to check arbitrary terms for equivalence.
Terms may contain brackets, addition, subtraction and multiplication of integer constants and variables `a` to `z`.

They are evaluated from left to right with no operator precedence.
They are evaluated from left to right with equal operator precedence for all operations.


## Contents

This repository contains:
- The [problem description](./Lazy-Math-Instructor.pdf)
- My [presentation slides](./Slides.pdf)
- My [submitted paper](./LazyMathInstructor_Paper.pdf)
- My [source code](./LazyMathInstructor) (split in several `.cs` files)
- Several input examples: [Binomial formulas](./binomial_formulas.txt), [Examples from the problem description](./problem_examples.txt) and a [long term](./long_term.txt)
- A [term generator](./TermGenerator/termgenerator.py) that can generate random terms of a desired length


## Usage of the program

@@ -21,4 +34,15 @@ Program writes to STDOUT:
- `YES` if the `k`-th pair of terms are equivalent
- `NO` if they aren't.

Verbose mode can be enabled by passing `-v` as a command line argument, in which case the program will print each term after it was parsed, normalized and ordered deterministically.
Verbose mode can be enabled by passing `-v` as a command line argument, in which case the program will print each addition,
subtraction and multiplication operation it performs, as well as each term after it was parsed, normalized and ordered deterministically.


## Usage of the term generator:

Calling the script without any arguments, it generates `N = 20` random terms of approximately `LENGTH = 250` characters.

`N` and `LENGTH` can be passed as command line arguments to adjust the output.
`N` must be an even number because the Lazy Math Instructor program can only work with *pairs* of terms.

The script's STDOUT can be used as STDIN for the main program for benchmarking.
Binary file added Slides.pdf
Binary file not shown.
71 changes: 71 additions & 0 deletions TermGenerator/termgenerator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from random import choice, randint
import sys


def print_args_error():
print('\nUsage: termgenerator.py N LENGTH\nwhere\n' +
' N: Number of terms to generate (must be even)\n' +
' LENGTH: Approximate length of each generated term\n' +
'The output of this script can be used as input for the LazyMathInstructor program.')


def read_config():
# Number of terms to be generated
N = 20

# Approximate length of the term to be generated
LENGTH = 250

if len(sys.argv) == 3:
try:
N = int(sys.argv[1])
LENGTH = int(sys.argv[2])
except ValueError:
print_args_error()
sys.exit(1)

if (N <= 0) or (LENGTH <= 0) or (N % 2 == 1):
print_args_error()
sys.exit(1)

elif len(sys.argv) != 1:
print_args_error()
sys.exit(1)

return N, LENGTH



ATOMS = [chr(x) for x in range(ord('a'), ord('z') + 1)] * 4 + [str(x) for x in range(101)]
def random_atom():
return choice(ATOMS)


def random_term(length):
term = random_atom()

while len(term) < length:
choice = randint(0, 101)
if choice < 25:
term = f'({term})'
elif choice < 45:
term = f'{term}+{random_term(randint(1, (length - len(term))))}'
elif choice < 75:
term = f'{term}-{random_term(randint(1, (length - len(term))))}'
else:
term = f'{term}*{random_term(randint(1, (length - len(term))))}'

return term


def main():
N, LENGTH = read_config()

print(N // 2)
for i in range(N):
print(random_term(LENGTH))



if __name__ == '__main__':
main()
Loading