Q

docx

School

Arizona State University, Tempe *

*We aren’t endorsed by this school

Course

240

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

3

Uploaded by MinisterRat3615

Report
Q) write up in a word document (200-250 words) on how you built your program. What other applications do you think could be built in Prolog that would save developers time? How could Prolog be used to build an application that create an AI system? I developed a Prolog program (students.pl) to find students who share at least two courses together. The program consists of three main predicates: same_class, which checks if two students are enrolled in the same class, students_with_shared_classes, which identifies pairs of students with at least two shared classes, and find_students_with_two_courses, which retrieves the list of such student pairs. I also included utility predicates to print the results neatly. To accomplish this, I first defined a set of students and classes, and then established enrollments. I ensured that each class has at least three students enrolled to meet the requirement. The code iterates through each pair of students and uses same_class to find common classes. If a pair shares at least two classes, they are included in the final list. I also included the print_list predicate to neatly display the results, including the students who share courses and the classes they have in common. Prolog's logical nature and pattern-matching capabilities make it suitable for various applications. One potential use is in Natural Language Processing (NLP) tasks, like parsing and generating sentences. Prolog's rule-based approach aligns well with linguistic rules and can simplify the implementation of grammar rules. Prolog can also be leveraged for expert systems and rule-based decision-making, such as in medical diagnosis or troubleshooting. Its ability to handle complex rule sets efficiently can save developers significant time. To create an AI system in Prolog, one could build upon its rule-based foundation, like for instance for creating an AI system, Prolog can be employed in conjunction with other technologies. it can be used as a knowledge representation language to build the knowledge base of an AI system, while machine learning models can be used for data-driven tasks. This hybrid approach combines Prolog's logical reasoning with the statistical power of machine learning, enabling AI systems to make informed decisions based on both facts and patterns in data. Such AI systems can be applied in recommendation systems, autonomous vehicles, and personalized medicine, among others. Overall, Prolog's declarative nature and efficient handling of logical inference make it a valuable tool for developing applications that involve complex rule sets and decision-making processes.
2) The output of my code: Here I have used this command to get the output, You can use the same one for the neat output. There is more output, but to save the space in the file I have cut it. Here, I defined a set of students and classes, and then established enrollments. I ensured that each class has at least three students enrolled to meet the requirement. The code iterates through each pair of students and uses same_class to find common classes. The database can be seen in my code. ?- find_students_with_two_courses(Students), print_list(Students). Students: alex emma Shared Classes: math science ----------------------- Students: alex ethan Shared Classes: math science ----------------------- Students: andrew ava Shared Classes: math computer_science ----------------------- Students: andrew chris Shared Classes: math history ----------------------- Students: andrew ella Shared Classes: math history ----------------------- Students: andrew
john Shared Classes: math history There is more output, but to save the space in the file I have cut it. 3) The code: *I have not included the database in this file, but it is there in the .pl file* same_class(Student1, Student2, Class) :- enrolled(Student1, Class), enrolled(Student2, Class), Student1 \= Student2. students_with_shared_classes(Student1, Student2, Classes) :- student(Student1), student(Student2), Student1 @< Student2, findall(Class, same_class(Student1, Student2, Class), Classes), length(Classes, NumClasses), NumClasses >= 2. find_students_with_two_courses(Students) :- setof([Student1, Student2, Classes], students_with_shared_classes(Student1, Student2, Classes), Students). print_list([]). print_list([[Student1, Student2, Classes]|T]) :- writeln('Students:'), writeln(Student1), writeln(Student2), writeln('Shared Classes:'), print_classes(Classes), writeln('-----------------------'), print_list(T). print_classes([]). print_classes([Class|T]) :- writeln(Class), print_classes(T).
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help