Thread: Adding multiplication signs to a math formula...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    16

    Adding multiplication signs to a math formula...

    Hey,

    I'm wrapping up a project for school and for the life of me I cant figure out how to place multiplication signs in the correct places of a math formula.

    The basic idea of the project is to multiply matrices in the most optimal way. So, Ive written the code to find the optimal parenthesization and Ive written a function to multiply two matrices together.

    I am left with (A1((A2A3)(((A4A5)A6)A7))) where each A is a matrix. I need to place multiplication signs in the correct places so I can put it into an expression tree and evaluate it.

    So I need to get from (A1((A2A3)(((A4A5)A6)A7))) to (A1*((A2*A3)*(((A4*A5)*A6)*A7)))

    But how?!? Everything I have tried doesn't work!

    Any suggestions?! Thanks...

    BC

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by BC2210 View Post
    Hey,

    So I need to get from (A1((A2A3)(((A4A5)A6)A7))) to (A1*((A2*A3)*(((A4*A5)*A6)*A7)))

    But how?!? Everything I have tried doesn't work!

    BC
    I would have suggested a stack for this, and then use Reverse Polish Notation perhaps, but...

    First blush looks like you only want the * after a digit, unless:

    1) The digit is the last digit in the equation: like A7)))
    or
    2) the digit is followed by a closing parenthesis, in which case the digit goes immediately after the closing parenthesis.

    Load them doggies up into a char array, and add 'em in, rawhide!

    Edit: Well, that may not be really as helpful as I'd like. Tell you what, why don't you post up some sample strings - may 10 or 20, so we'll have something to play with. Trying to work from one example is not good.
    Last edited by Adak; 12-05-2009 at 05:37 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. American math students ...
    By whiteflags in forum A Brief History of Cprogramming.com
    Replies: 36
    Last Post: 05-26-2008, 12:47 PM
  2. SVN Import Causes Crash
    By Tonto in forum Tech Board
    Replies: 6
    Last Post: 11-01-2006, 03:44 PM
  3. how to use operator+() in this code?
    By barlas in forum C++ Programming
    Replies: 10
    Last Post: 07-09-2005, 07:22 PM
  4. category of Math signs???
    By Vorkosigan in forum C++ Programming
    Replies: 2
    Last Post: 01-22-2004, 05:00 PM
  5. Math formula (js -->C++)
    By Demon1s in forum C++ Programming
    Replies: 20
    Last Post: 05-02-2003, 05:22 AM