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

  • Home
  • SEARCH
  • 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 8306543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:21:09+00:00 2026-06-08T18:21:09+00:00

How can I generate the sum of minterms (boolean algebra) in java? We can

  • 0

How can I generate the sum of minterms (boolean algebra) in java? We can generate sum of minterms throw ANDing with (X+X'). The following example explains the algorithm for a function with three variables A,B and C:

F(A,B,C)= A + B´*C
        = A*(B+B´) + B´*C
        = A*B + A*B´ + B´*C
        = A*B*(C+C´) + A*B´*(C+C´) + B´*C*(A+A´)
        = A*B*C+A*B*C´+A*B´*C+A*B´*C´+B´*C*A+B´*C*A´
        = A*B*C+A*B*C´+A*B´*C+A*B´*C´+A*B´*C+A´*B´*C

The method in java looks like this:

String generateSumOfMinterms(String termsOfTheFunction, String variables){}


// Examples for functions with 2 variables A,B
generateSumOfMinterms("A", "A,B"){

//The result should looks like this
return "A*B+A*B'";
}
generateSumOfMinterms("A+B'", "A,B"){

//The result should looks like this (repeated terms are ok for example A*B')
return "A*B+A*B'+A'*B'+A*B'";
}


// Example for a function with 3 variables A,B,C 
generateSumOfMinterms("A", "A,B,C"){

//The result should looks like this
return "A*B*C+A*B*C'+A*B'*C+A*B'*C'";
}

I have tried the following:

public List<Minterm> completeMinterm(Minterm minterm, String variables){
    List<Minterm> minterms=new ArrayList<Minterm>();
    minterms.add(minterm);
    Minterm m1=new Minterm();
    Minterm m2=new Minterm();
    for (int k = 0; k < minterms.size(); k++) {
 //A AB--> AB+AB'
        for (int i = 0; i < variables.length(); i++) {
        boolean varInMinterm=false;
        for (int j = 0; j < minterms.get(k).atoms.size(); j++) {
            if(minterms.get(k).atoms.get(j).variable==variables.charAt(i)){
                varInMinterm=true;
                break;
            }
        }
        if(!varInMinterm){
            varInMinterm=false;
            m1= minterms.get(k);
            m1.addAtom(new Atom(variables.charAt(i),false));
            m2 = minterms.get(k);
            m2.addAtom(new Atom(variables.charAt(i),true));
            minterms.remove(k);
            minterms.add(m1);   
            minterms.add(m2);   
            k=0;

        }
    }
    }

I used eclipse debugger to find errors, I don’t understand, why the atom added to m2 is added to m1 too in the same time, when this line is run:

m2.addAtom(new Atom(variables.charAt(i),true));
  • 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-06-08T18:21:09+00:00Added an answer on June 8, 2026 at 6:21 pm

    Here is an outline of a possible approach: First, you should create a more convenient representation of the expression – for example, the expression could be a list of instances of a Minterm class, and Minterm could contain a list of instances of an Atom class, each of which could contain a char that tells which variable it is and a boolean that tells whether the variable is negated or not. The first thing you should do is to loop through termsOfTheFunction and create such objects that represent the expression. Then, you can loop through the minterms, and every time you see a minterm that is missing one variable, you can remove it from the list and add two new minterms with the missing variable. Finally, you can loop through the finished minterms and “print” them to a result String.

    Class declarations per request and for clarity (using public fields for brevity):

    public class Atom {
        public final char variable;
        public final bool negated;
        public Atom(char variable, bool negated) {
            this.variable = variable;
            this.negated = negated;
        }
    }
    
    public class Minterm {
        public final List<Atom> atoms = new ArrayList<Atom>();
    }
    

    In generateSumOfMinterms():

    List<Minterm> expression = new ArrayList<Minterm>();
    Minterm currentMinterm = new Minterm();
    expression.add(currentMinterm);
    

    Then, loop through the characters of termsOfTheFunction. Each time you see a letter, look at the next character to see if it is a ´, and add an Atom with that letter and with the correct negation. Each time you see a +, create a new Minterm and add it to expression, and keep going. Afterwards, you can start analyzing the minterms and expanding them.

    Edit in response to your code: Looks like you’re well on your way! The reason both atoms get added to the same minterm is that both m1 and m2 refer to the k‘th minterm since you say m1 = minterms.get(k); and m2 = minterms.get(k);. get() does not copy or remove an element from a list; the element will still be inside the list. So for m2, you need to create a new minterm that has all of the atoms from the old one, plus the new atom.

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

Sidebar

Related Questions

ASP.NET MVC can generate HTML elements using HTML Helpers, for example @Html.ActionLink() , @Html.BeginForm()
I know you can generate all permutations from a list, using glob or Algorithm::Permute
I want to create an XSD which can generate the following XML. <note> <email:to>abc@def.com</email:to>
For example: 1,2,4,5 has the following sum: 1,2,4,5 3,6,9 7,11 12 and every sum
I am trying to generate MD5 sum using MessageDigest. And i am having following
I can generate my models and schema.yml file based on an existing database. But
ASP.NET MVC 3 can generate scaffold code for us(controllers and views). The generated views
I found jquery can generate file tree structure based on existing folders and files
Does anyone know a C# framework that can generate public/private keys, X.509 certificates and
I'm wondering if i can generate a scaffold without getting that annyoing s after

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.