src/operations.c
//this function simplifies the postfix array of structs when it is an
//algebraic expression
this function simplifies the postfix array of structs when it is an
algebraic expression
this function simplifies the postfix array of structs when it is an algebraic expression
int simplification(struct inputSeperate *input, int length){
    int inPos;
    struct inputSeperate outputX;
    struct inputSeperate outputPlain;
    outputX.value = 0;
    outputPlain.value = 0;
    struct inputSeperate scanned;
    int split = 0;
    int full = 0;
    for (inPos = 0; inPos < length; inPos++){
        scanned = input[inPos];
        if (scanned.isOperator != 0){
            struct inputSeperate struct1 = input[inPos - 2];
            struct inputSeperate struct2 = input[inPos - 1];
            if (full == 1){
                struct1 = outputX;
            }
            if (scanned.content[0] == '+'){
                if (struct1.Xponent == struct2.Xponent && struct1.Xponent != 0){
                    outputX.value = struct1.value + struct2.value;
                    outputX.Xponent = struct1.Xponent;
                }
                else if (struct1.Xponent == struct2.Xponent && struct1.Xponent == 0){
                    outputPlain.value = struct1.value + struct2.value;
                }
                else if (struct1.Xponent != struct2.Xponent && struct1.Xponent == 0){
                    outputPlain.value = struct1.value;
                    outputX.value = struct2.value;
                    split = 1;
                }
                else if (struct1.Xponent != struct2.Xponent && struct1.Xponent != 0){
                    outputX.value = struct1.value;
                    outputPlain.value = struct2.value;
                    split = 1;
                }
            }
            else if (scanned.content[0] == '-'){
                if (struct1.Xponent == struct2.Xponent && struct1.Xponent != 0){
                    outputX.value = struct1.value - struct2.value;
                    outputX.Xponent = struct1.Xponent;
                }
                else if (struct1.Xponent == struct2.Xponent && struct1.Xponent == 0){
                    outputPlain.value = struct1.value - struct2.value;
                }
                else if (struct1.Xponent != struct2.Xponent && struct1.Xponent == 0){
                    outputPlain.value = struct1.value;
                    outputX.value = -1*struct2.value;
                    split = 1;
                }
                else if (struct1.Xponent != struct2.Xponent && struct1.Xponent != 0){
                    outputX.value = struct1.value;
                    outputPlain.value = -1*struct2.value;
                    split = 1;
                }
            }
            else if (scanned.content[0] == '*'){
                if (split == 1){
                    outputX.value = outputX.value*struct2.value;
                    outputPlain.value = outputPlain.value*struct2.value;
                }
                else {
                    if (struct1.Xponent != 0){
                        outputX.value = struct1.value*struct2.value;
                        outputX.Xponent = struct1.Xponent + struct2.Xponent;
                    }
                    else {
                        outputPlain.value = struct1.value*struct2.value;
                    }
                }
            }
            else if (scanned.content[0] == '/'){
                if (split == 1){
                    outputX.value = outputX.value/struct2.value;
                    outputPlain.value = outputPlain.value/struct2.value;
                }
                else {
                    if (struct1.Xponent != 0){
                        outputX.value = struct1.value/struct2.value;
                        outputX.Xponent = struct1.Xponent - struct2.Xponent;
                    }
                    else {
                        outputPlain.value = struct1.value/struct2.value;
                    }
                }
            }
            else if (scanned.content[0] == '^'){
                if (struct1.Xponent != 0){
                    outputX.value = pow(struct1.value,struct2.value);
                    outputX.Xponent = struct1.Xponent*struct2.value;
                }
                else {
                    outputPlain.value = pow(struct1.value,struct2.value);
                }
            }
            full = 1;
        }
    }
    if (outputX.value != 0 && outputPlain.value != 0){
        if (outputX.Xponent == 0 || outputX.Xponent == 1){
            if (outputPlain.value < 0){
                printf("%.3fx-%.3f\n",outputX.value, fabs(outputPlain.value));
            } 
            else {
                printf("%.3fx+%.3f\n",outputX.value, outputPlain.value);
            }  
        }
        else{
            if (outputPlain.value < 0){
                printf("%.3fx^%.3f-%.3f\n",outputX.value, outputX.Xponent, fabs(outputPlain.value));
            }
            else {
                printf("%.3fx^%.3f+%.3f\n",outputX.value, outputX.Xponent, outputPlain.value);
            } 
        }
    }
    else if (outputX.value != 0 && outputPlain.value == 0){
        if (outputX.Xponent == 0 || outputX.Xponent == 1){
            printf("%.3fx\n",outputX.value);
        }
        else{
            printf("%.3fx^%.3f\n",outputX.value, outputX.Xponent);
        }
    }
    else if (outputX.value == 0 && outputPlain.value != 0){
        printf("%.3f\n",outputPlain.value);
    }
    return 0;
}
int simplification ( struct inputSeperate * input , int length ) { int inPos ; struct inputSeperate outputX ; struct inputSeperate outputPlain ; outputX . value = 0 ; outputPlain . value = 0 ; struct inputSeperate scanned ; int split = 0 ; int full = 0 ; for ( inPos = 0 ; inPos < length ; inPos ++ ) { scanned = input [ inPos ] ; if ( scanned . isOperator != 0 ) { struct inputSeperate struct1 = input [ inPos - 2 ] ; struct inputSeperate struct2 = input [ inPos - 1 ] ; if ( full == 1 ) { struct1 = outputX ; } if ( scanned . content [ 0 ] == ' ' ) { if ( struct1 . Xponent == struct2 . Xponent && struct1 . Xponent != 0 ) { outputX . value = struct1 . value + struct2 . value ; outputX . Xponent = struct1 . Xponent ; } else if ( struct1 . Xponent == struct2 . Xponent && struct1 . Xponent == 0 ) { outputPlain . value = struct1 . value + struct2 . value ; } else if ( struct1 . Xponent != struct2 . Xponent && struct1 . Xponent == 0 ) { outputPlain . value = struct1 . value ; outputX . value = struct2 . value ; split = 1 ; } else if ( struct1 . Xponent != struct2 . Xponent && struct1 . Xponent != 0 ) { outputX . value = struct1 . value ; outputPlain . value = struct2 . value ; split = 1 ; } } else if ( scanned . content [ 0 ] == ' ' ) { if ( struct1 . Xponent == struct2 . Xponent && struct1 . Xponent != 0 ) { outputX . value = struct1 . value - struct2 . value ; outputX . Xponent = struct1 . Xponent ; } else if ( struct1 . Xponent == struct2 . Xponent && struct1 . Xponent == 0 ) { outputPlain . value = struct1 . value - struct2 . value ; } else if ( struct1 . Xponent != struct2 . Xponent && struct1 . Xponent == 0 ) { outputPlain . value = struct1 . value ; outputX . value = -1 * struct2 . value ; split = 1 ; } else if ( struct1 . Xponent != struct2 . Xponent && struct1 . Xponent != 0 ) { outputX . value = struct1 . value ; outputPlain . value = -1 * struct2 . value ; split = 1 ; } } else if ( scanned . content [ 0 ] == ' ' ) { if ( split == 1 ) { outputX . value = outputX . value * struct2 . value ; outputPlain . value = outputPlain . value * struct2 . value ; } else { if ( struct1 . Xponent != 0 ) { outputX . value = struct1 . value * struct2 . value ; outputX . Xponent = struct1 . Xponent + struct2 . Xponent ; } else { outputPlain . value = struct1 . value * struct2 . value ; } } } else if ( scanned . content [ 0 ] == ' ' ) { if ( split == 1 ) { outputX . value = outputX . value / struct2 . value ; outputPlain . value = outputPlain . value / struct2 . value ; } else { if ( struct1 . Xponent != 0 ) { outputX . value = struct1 . value / struct2 . value ; outputX . Xponent = struct1 . Xponent - struct2 . Xponent ; } else { outputPlain . value = struct1 . value / struct2 . value ; } } } else if ( scanned . content [ 0 ] == ' ' ) { if ( struct1 . Xponent != 0 ) { outputX . value = pow ( struct1 . value , struct2 . value ) ; outputX . Xponent = struct1 . Xponent * struct2 . value ; } else { outputPlain . value = pow ( struct1 . value , struct2 . value ) ; } } full = 1 ; } } if ( outputX . value != 0 && outputPlain . value != 0 ) { if ( outputX . Xponent == 0 || outputX . Xponent == 1 ) { if ( outputPlain . value < 0 ) { printf ( " \n " , outputX . value , fabs ( outputPlain . value ) ) ; } else { printf ( " \n " , outputX . value , outputPlain . value ) ; } } else { if ( outputPlain . value < 0 ) { printf ( " \n " , outputX . value , outputX . Xponent , fabs ( outputPlain . value ) ) ; } else { printf ( " \n " , outputX . value , outputX . Xponent , outputPlain . value ) ; } } } else if ( outputX . value != 0 && outputPlain . value == 0 ) { if ( outputX . Xponent == 0 || outputX . Xponent == 1 ) { printf ( " \n " , outputX . value ) ; } else { printf ( " \n " , outputX . value , outputX . Xponent ) ; } } else if ( outputX . value == 0 && outputPlain . value != 0 ) { printf ( " \n " , outputPlain . value ) ; } return 0 ; }
this function simplifies the postfix array of structs when it is an
algebraic expression
this function simplifies the postfix array of structs when it is an algebraic expression
//find each operator in the postfix array. when it is found, apply it appropriately //to the previous 2 values. this includes only adding/substracting terms with an equal x indice, //while multiplying/dividing/exponentiating any term (including both x and non-x terms if they  //are split), and applying transformations to both coefficients and exponents //determine if there are values that have been places in the x and non-x variables. //if there are, move them out so we can apply operations to them //if the operator is add, apply the following transformations: //if the two values have equal x-indices  //if the two values dont have x-indices  //if the two values have different x-indices //its pretty much the same for each operator so I wont repeat the same comments //apply relevant print statements. these are all printing the same things, the //if statements are just nessecary to ensure negatives and instances where there //is no exponent/x term/non x-term print nicely