Efficient Boolean Formula Evaluation Functions for Simplified SML Programming"

In summary, the conversation is about a request for help with a boolean formula assignment. The formula involves different data types and the task is to write a cascading evaluation function without using "if" constructs. The person asking for help is a novice and is seeking clarification and explanations on how to begin the task. It is mentioned that the slides have been read, but another person named Philipp will not be able to provide assistance.
  • #1
Monsu
38
1
hi, pleaaaaaaaaaase! i need help urgently! I am completely stuck! I have no idea what to do on this question, it reads thus:





Given the following datatypes for boolean formulae and the truth values

datatype boolexp = bez | beo (*0 and 1*)
| bep of boolexp * boolexp (*plus*)
| bet of boolexp * boolexp (*times*)
| bec of boolexp (*complement*)
| bev of int (*variables*)
datatype mybool = mytrue | myfalse

write a cascading evaluation function eval : (int -> mybool) -> boolexp -> mybool
that takes an assignment $ and a boolean formula & and returns I$(&) as a value .
write a simplified version of the function evalbib : (int -> bool) -> boolexp -> bool. (without using "if" constructs)




I'm clueless as to how to begin this, and I am a novice in all languages, any acclaration and explanations will be highly appreciated, thanks in advance!


:rolleyes: :rolleyes: :rolleyes:
 
Computer science news on Phys.org
  • #2
read the slides


philipp
 
  • #3



Hi there,

I understand that you are struggling with the task of writing an efficient Boolean formula evaluation function for simplified SML programming. I'm happy to help you with this.

Firstly, let's break down the task into smaller parts to make it more manageable. The first part of the task is to write a cascading evaluation function that takes an assignment $ and a boolean formula & and returns I$(&) as a value. This means that the function should evaluate the boolean formula using the given assignment and return either mytrue or myfalse as the result.

To begin, we need to define the function eval as follows:

fun eval $ bez = myfalse (* if the boolean formula is bez, it evaluates to myfalse*)
| eval $ beo = mytrue (* if the boolean formula is beo, it evaluates to mytrue*)
| eval $ bep (exp1, exp2) = (* for a boolean formula with plus operator *)
if eval $ exp1 = mytrue orelse eval $ exp2 = mytrue then mytrue else myfalse (* if either of the sub-formulas evaluate to mytrue, then the entire formula evaluates to mytrue*)
| eval $ bet (exp1, exp2) = (* for a boolean formula with times operator *)
if eval $ exp1 = mytrue andalso eval $ exp2 = mytrue then mytrue else myfalse (* if both sub-formulas evaluate to mytrue, then the entire formula evaluates to mytrue*)
| eval $ bec exp = (* for a boolean formula with complement operator *)
if eval $ exp = mytrue then myfalse else mytrue (* if the sub-formula evaluates to mytrue, then the entire formula evaluates to myfalse and vice versa*)
| eval $ bev n = $ n (* for a boolean formula with variable *)
| eval $ _ = raise Fail "Invalid boolean formula" (* if the given formula is invalid, raise an exception *)

This is a recursive function that evaluates the boolean formula by checking each sub-formula and applying the appropriate logic based on the operator. It will continue until it reaches the base cases (bez and beo) or an exception is raised for an invalid formula.

Now, for the second part of the task, we need to write a simplified version of the function evalbib that does not use "if" constructs. This can be achieved by using pattern matching and logical operators
 

FAQ: Efficient Boolean Formula Evaluation Functions for Simplified SML Programming"

What is the purpose of "Efficient Boolean Formula Evaluation Functions for Simplified SML Programming"?

The purpose of this research is to develop efficient boolean formula evaluation functions for simplified SML programming, in order to improve the performance and usability of SML programming languages.

How does this research contribute to the field of computer science?

This research contributes to the field of computer science by providing a more efficient and user-friendly approach to programming in SML. This can lead to advancements in software development and optimization of computer systems.

What are the benefits of using efficient boolean formula evaluation functions in SML programming?

Using efficient boolean formula evaluation functions in SML programming can improve the speed and accuracy of program execution, reduce the complexity of code, and make it easier to write and maintain programs in SML.

Can this research be applied to other programming languages?

While the focus of this research is on SML programming, the principles and techniques used can also be applied to other programming languages that use boolean logic. This includes languages like Java, C++, and Python.

What are some potential future developments or applications of this research?

This research can potentially lead to the development of more advanced programming languages and software tools that utilize efficient boolean formula evaluation functions. It can also be applied to other areas such as artificial intelligence, database management, and data analysis.

Back
Top