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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:25:14+00:00 2026-06-01T20:25:14+00:00

I am at a loss with how to solve my problem. I have a

  • 0

I am at a loss with how to solve my problem. I have a homework in which I need to simplify expressions using the rules the professor set out. I need to take strings of expressions:

"(and(x x))"
"(or (and x z) y)"
"(and (or z (not x))(or e a))"

and simplify them using rules:

(or x nil) => x; 
(or nil x) => x;
(or 1 x) => 1;
(or x 1) => 1;
(and x nil) => nil; 
(and nil x) => nil;
(and x 1) => x; 
(and 1 x) => x;
(not nil) => 1;
(not 1) => nil;
(not (and x y)) => (or (not x) (not y));
(not (or x y)) => (and (not x) (not y));

I decided to take the expressions in the exact form that it is above (can’t be any other way), and parse it into an array, so in each index for example, it would look like this:

and or x y z //ArrayBuffer[String]

I then use a recursive function which checks the left and right expressions, until it gets the simplified expression. My problem is not with the rules, as I have figured that out. I essentially have 3 cases done, which are:

"(and z (or x y)" // the case when the left symbol is simple but the right side must be recursed
"(and (or x y) z)" // case when the right symbol is simple but the right side must be recursed
"(and x y)" // simple case where no recursion is necessary

I am missing the case when both the left and right symbols must be recursed in order to obtain those simplified symbols. I don’t have a way to know when they end or begin, and there could be many cases in which it must be recursed even within those inner expressions:

"(and (or (and x y) z)(or x a))"
"(and (or (and x y) z)(or (and y z) a))"

I have thought about how this can be done in an efficient manner with the current implementation I have, but haven’t gotten anything yet. I am asking for some advice on how to go about it. I am providing no code as I would like to get it done on my own, just need a nudge in the right direction. If clarification is needed, please ask and I will do so. Thanks again advance!

  • 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-01T20:25:14+00:00Added an answer on June 1, 2026 at 8:25 pm
    and or x y z //ArrayBuffer[String]
    

    I would avoid representing an expression like this. While is is possible to unambiguously get the structure of the expression in prefix notion, it’s not quite as easy as when you have a recursive structure.

    You should instead represent the expression with a recursively-defined class hierarchy. Without giving too many details, you will probably have an interface (a Trait or abstract Class), and implementers of that interface that depend on the number of arguments: one for expressions with three parts (like ((or, x, y), or (and, (or x y), z))), one for expressions with two parts (like (not, x)), and one for expressions with one part (like x, y, z, nil, etc).

    Then your simplification procedure becomes one big pattern-matching method that can call itself recursively to traverse the expression’s parse tree:

    def simplify(expression: ExpressionIterface) = 
        expression match {
            case /* pattern */ => /* result, possibly with a recursive call to simplify */
            ...
        }
    

    EDIT: Converting the ArrayBuffer[String] into your classes could be done with a simple recursive parsing function since you know how many arguments should be associated with each operator. You could traverse the buffer, and every time you see an and or or, you start creating a 3-part expression, every time you see a not, you start creating a 2-part expression, and you create a 1-part expression for anything else.

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

Sidebar

Related Questions

I have a problem that I believe I need to use grouping using xsl:key
We're looking for an algorithm to solve this problem in under O(N). given two
I'm taking an operating systems design class in which they have given us a
I'm at a loss. I'm using JQuery 1.4.2 and JCrop 0.98. Everything else works
I have AMQ + Activemessaging running in a Rails App. I'm facing a problem
I've run into something odd, here, and I'm at a loss -- I have
EDIT: Was a hardware problem.....getting a duplicate device or cable seemed to solve the
This is an interesting problem that I’ve not been able to solve yet. I
I've started using HTML5 and WebSQL, and I quickly ran into a problem: all
I have a library with C++ python extensions (C++ calls python which in turn

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.