Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6896439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:02:39+00:00 2026-05-27T07:02:39+00:00

I’m creating logic simplification program in sml. But I have a problem for this

  • 0

I’m creating logic simplification program in sml. But I have a problem for this input:

- Or(Or(Var"x", Var"y"), Var"z");
val it = Or (Or (Var #,Var #),Var "z") : formula
 - Simplify it;

And it’s in an infinite loop.

Here is my code:

fun Simplify (Or(True, _)) = True
| Simplify (Or(_, True)) = True
| Simplify (Or(False, False)) = False
| Simplify (Or(x, False)) = (Simplify x)
| Simplify (Or(False, x)) = (Simplify x)
| Simplify (Or (Var (x), Var (y))) = Or (Var (x), Var (y))
| Simplify (Or (x, y)) = (Simplify (Or (Simplify x, Simplify y)))

| Simplify (And(_, False)) = False
| Simplify (And(False, _)) = False
| Simplify (And(True, True)) = True
| Simplify (And(True, x)) = (Simplify x)
| Simplify (And(x, True)) = (Simplify x)
| Simplify (And(Var (x), Var(y))) = And (Var (x), Var (y))
| Simplify (And (x, y)) = (Simplify (And (Simplify x, Simplify y)))

| Simplify (Not(Not(x))) = (Simplify x)
| Simplify (Not(True)) = False
| Simplify (Not(False)) = True
| Simplify (Not(Var (x))) = (Not (Var x))
| Simplify (Not(x)) = (Simplify (Not (Simplify x)))

| Simplify True = True
| Simplify False = False
| Simplify (Var(x)) = Var(x);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:02:39+00:00Added an answer on May 27, 2026 at 7:02 am

    There are three cases which are really suspicious:

    | Simplify (Or (x, y)) = (Simplify (Or (Simplify x, Simplify y)))
    
    | Simplify (And (x, y)) = (Simplify (And (Simplify x, Simplify y)))
    
    | Simplify (Not(x)) = (Simplify (Not (Simplify x)))
    

    Basically, if x and y couldn’t be simplified further, Simplify x and Simplify y will return x and y. So you will invoke Simplify with the same input as before (Or(x, y), And(x, y) or Not x). You can test that your function doesn’t terminate with some examples such as: And(And(Var "x", Var "y"), Var "z") and Not(And(Var "x", Var "y").

    The idea of simplification is that you have True or False in an inner clause, you want to propagate it to outer levels. Note that you will not try to simplify if x and y are irreducible.

    UPDATE:

    Your function could be fixed as follows:

    fun Simplify (Or(True, _)) = True
        | ... (* Keep other cases as before *)
        | Simplify (Or (x, y)) = (case Simplify x of
                                    True => True
                                  | False => Simplify y
                                  | x' => (case Simplify y of
                                             True => True
                                           | False => x'
                                           | y' => Or(x', y')))
    
        | Simplify (And (x, y)) = (case Simplify x of
                                     False => False
                                   | True => Simplify y
                                   | x' => (case Simplify y of
                                              False => False
                                            | True => x'
                                            | y' => And(x', y')))
        | Simplify (Not x) = case Simplify x of
                                 True => False
                               | False => True
                               | x' => Not x'
    

    UPDATE 2:

    I think you tried to use top-down approach which is not really appropriate. I rewrite the function using bottom-up approach to make it shorter and more readable:

    fun Simplify True = True
     | Simplify False = False
     | Simplify (Var x) = Var x
     | Simplify (Not x) = (case Simplify x of
                             True => False
                           | False => True
                           | x' => Not x')
     | Simplify (And(x, y)) = (case Simplify x of
                                 False => False
                               | True => Simplify y
                               | x' => (case Simplify y of
                                          False => False
                                        | True => x'
                                        | y' => And(x', y')))
     | Simplify (Or(x, y)) = (case Simplify x of
                                True => True
                              | False => Simplify y
                              | x' => (case Simplify y of
                                         True => True
                                       | False => x'
                                       | y' => Or(x', y')))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.