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 3879764
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:45:50+00:00 2026-05-19T22:45:50+00:00

module Algorithm where import System.Random import Data.Maybe import Data.List type Atom = String type

  • 0
module Algorithm where

import System.Random
import Data.Maybe
import Data.List

type Atom = String
type Literal = (Bool,Atom)
type Clause = [Literal]
type Formula = [Clause]
type Model = [(Atom, Bool)]
type Node = (Formula, ([Atom], Model))

-- This function  takess a Clause and return the set of Atoms of that Clause.
atomsClause :: Clause -> [Atom]


-- This function  takes a Formula returns the set of Atoms of a Formula
atoms :: Formula -> [Atom]


-- This function returns True if the given Literal can be found within
-- the Clause.
isLiteral :: Literal -> Clause -> Bool


-- this function takes a Model and an Atom and flip the truthvalue of
-- the atom in the model
flipSymbol :: Model -> Atom -> Model -- is this ok?

Additional functions :
remove :: (Eq a) )a ->[a] ->[a] 
-This function removes an item from a list.

 neg :: Literal->Literal
-This function flips a literal (ie. from P to :P and from :P to P).
falseClause :: Model -> Clause -> Bool 
-This function takes a Model and a Clause and returns True
if the clause is unsatisfied by the model or False otherwise.
falseClauses :: Formula -> Model -> [Clause]
-This function takes a Formula and a Model and returns the list of clauses of the  formula that are not satisfied.
 assignModel :: Model -> Formula -> Formula 
 -This function applies the assign function for all the assignments of a given model.
 checkFormula :: Formula -> Maybe Bool This function checks whether a formula can be  decided to be satisfiable or unsatisfiable based on the effects of the assign function.
 satisfies :: Model -> Formula -. Bool This function checks whether a model satisfies a formula. This is done with the combination of the assignModel and checkFormula functions.
  • 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-19T22:45:51+00:00Added an answer on May 19, 2026 at 10:45 pm

    One place to get you started: look at

     removeTautologies :: Formula -> Formula
    

    Now suppose we can write an function

     isTautology :: Clause -> Bool
    

    Then we may have a chance of using that function to filter general formulae. So I would attempt to ignore everything but the function isTautology. Essentially the question here is: What is a tautology and how do we detect it? Some of the ideas posted by Edward Z. Yang should definitely help you here in understanding what is going on. In this case, we could look at the clause [(True,"A"), (True,"B"), (False,"A")] and try to feed it to isTautology for testing it. Likewise with the other clause Edward posted, [(True,"B"), (True,"C"), (True,"A")].

    The trick in general is to figure out how to break up the functions into smaller constituents which are easily written and then afterwards glue these individual pieces together with code to solve the final problem. We are decomposing removeTautologies which works on general formulae into a helper isTautology which can work on clauses in the formula, and then we seek to define removeTautologies in terms of it via some filtering glue code.

    I hope this helps you start on your problem. It may seem to be quite irrelevant but do take note that more advanced variants of this is used in Model Checking algorithms which verify that your CPU is correct, that protocols behave and recently is has also been used in automatic refactoring, see http://coccinelle.lip6.fr/ for a use. So this problem is a good way to learn some serious applicability in the real world!


    I’ll edit it here to help you rather than replying in the comment section. You wrote:

    rt ((x, x') : (y, y') : rest) | x' == y' = rt rest
                                  | otherwise = (x, x') : rt ((y, y') : rest)
    

    There are a couple of problems with this approach as you mention. First, the game is that your rt function is working on clauses. If the given clause is a tautology it should be removed, so it would be better to call it isTautology with the type I mention above, or perhaps simply:

    isRemovableClause :: Clause -> Bool
    

    The path you have taken requires you to sort the list in the clause lexicographically and then consider what to do in the case you have [P, P, not P, Q] for instance. Another approach is to establish a search. Suppose we have

    isRemovableClause ((tv, name) : rest) = ...
    

    Notice that if the value (not tv, name) is present in rest this clause must be a tautology. Otherwise, we can throw away (tv, name) and look for a tautology in rest.

    Moving the focus to removeTautologies, it is clear that the function can be written using isRemovableClause: A formula is a list of clauses, so we can simply walk through the clause-list and remove all those for which isRemovableClause returns true. The bold solver will use List.filter, a higher order function, to achieve this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

plotting module def plotGraph(X,Y): fignum = random.randint(0,sys.maxint) plt.figure(fignum) ### Plotting arrangements ### return fignum
Three module exists. Cfg, Main and Component Cfg.py value = 0 Component.py import Cfg
I have simple map-reduce type algorithm, which I want to implement in python and
I am writing an algorithm to represent regression trees, using pydot module (an interface
I got a module which RSA encrypts the data and passes on to the
I'm writing a genetic algorithm to generate the string helloworld. But the evolve function
What algorithm to use to check if a given string matches one of set
Not able to install module HTTP::DAV::Browse, which has dependency ->Algorithm::C3. Now issue is :-
I'm trying to implement a Fisher-Yates shuffle of some data. This algorithm is easy
Module: ./FOO/BAR/Foobar.pm use strict; use warnings; package Foobar; our($VERSION , @ISA , @EXPORT ,

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.