def order_span(orderable):

    for i in range(len(orderable)):
        recursive_start = general_functions.first_occurence(orderable, i, "(")

        if recursive_start == -1:
            break
        else:

            recursive_end = general_functions.first_occurence(
                orderable, recursive_start, ")")
            recursor = orderable[recursive_start + 1:recursive_end]
            recursed = order_span(recursor)
            del orderable[recursive_start:recursive_end + 1]
            orderable = general_functions.insert_list(orderable, recursor,
                                                      recursive_start)

    orderable = kill_parentheses(orderable)

    orderable = unary_op_template(orderable)

    orderable = binary_op_template(orderable, "^", "^")

    orderable = binary_op_template(orderable, "mod", "%")

    orderable = binary_op_template(orderable, "log", "_")

    orderable = nary_op_template(orderable, "*")

    orderable = nary_op_template(orderable, "+")

    end_at = general_functions.first_occurence(orderable, 0, ")")
    if end_at != -1 and end_at == len(orderable) - 1:
        del orderable[end_at]
    return orderable
Example #2
0
def format_inverse_template(parseable, insertable, i):
    if parseable[i + 1] in trig_list or parseable[i] in ["sin", "cos", "("]:
        insert_at = general_functions.first_occurence(parseable, i, ")") + 1
    else:
        insert_at = i + 2
    parseable = general_functions.insert_list(parseable, insertable, insert_at)
    return parseable
Example #3
0
def format_inverse_template(parseable, insertable, i):
    if parseable[i+1] in trig_list or parseable[i] in ["sin", "cos", "("]:
        insert_at = general_functions.first_occurence(parseable, i, ")") + 1
    else:
        insert_at = i + 2
    parseable = general_functions.insert_list(parseable, insertable, insert_at)
    return parseable
def order_span(orderable):

    for i in range(len(orderable)):
        recursive_start = general_functions.first_occurence(orderable, i, "(")

        if recursive_start == -1:
            break
        else:

            recursive_end = general_functions.first_occurence(orderable,
                                                             recursive_start,
                                                             ")")
            recursor = orderable[recursive_start+1:recursive_end]
            recursed =  order_span(recursor)
            del orderable  [recursive_start:recursive_end+1]
            orderable = general_functions.insert_list(orderable,recursor,recursive_start)

    orderable = kill_parentheses(orderable)

    orderable = unary_op_template(orderable)

    orderable = binary_op_template(orderable, "^", "^")


    orderable = binary_op_template(orderable, "mod", "%")


    orderable = binary_op_template(orderable, "log", "_")


    orderable = nary_op_template(orderable, "*")


    orderable = nary_op_template(orderable, "+")

    end_at = general_functions.first_occurence(orderable, 0, ")")
    if end_at != -1 and end_at == len(orderable) - 1:
        del orderable[end_at]
    return orderable
Example #5
0
def format_trig(parseable):
    i = 0
    for i in range(len(parseable)):
        if parseable[i] in trig_list:
            span = general_functions.first_occurence(parseable, i, ")")
            input_ = parseable[i+2:span]
            tan_or_sec = lambda x: x == "tan" or x == "cot"
            templates = {"tan": ["sin", "(", ")", "*", "cos", "(", ")", "^", "-1"],
                         "cot": ["cos", "(", ")", "*", "sin", "(", ")", "^", "-1"],
                         "sec": ["cos", "(", ")", "^", "-1"],
                         "csc": ["sin", "(", ")", "^", "-1"]}
            adjusted = format_trig_tmeplate(templates[parseable[i]], input_, tan_or_sec(parseable[i]))

            del parseable[i:span+1]
            general_functions.insert_list(parseable, adjusted, i)

    return parseable
Example #6
0
def format_trig(parseable):
    i = 0
    for i in range(len(parseable)):
        if parseable[i] in trig_list:
            span = general_functions.first_occurence(parseable, i, ")")
            input_ = parseable[i + 2 : span]
            tan_or_sec = lambda x: x == "tan" or x == "cot"
            templates = {
                "tan": ["sin", "(", ")", "*", "cos", "(", ")", "^", "-1"],
                "cot": ["cos", "(", ")", "*", "sin", "(", ")", "^", "-1"],
                "sec": ["cos", "(", ")", "^", "-1"],
                "csc": ["sin", "(", ")", "^", "-1"],
            }
            adjusted = format_trig_tmeplate(templates[parseable[i]], input_, tan_or_sec(parseable[i]))

            del parseable[i : span + 1]
            general_functions.insert_list(parseable, adjusted, i)

    return parseable
#!/usr/bin/env python3
import general_functions

nary_op = ["+", "*"]
binary_op = ["^", "mod", "log", "="]
unary_op = {"sin": "~", "cos": "&"}
unary_op_plus = ["sin", "cos"]
op = ["+", "*", "^", "mod", "log", "sin", "cos"]
find_end = lambda orderable, start_at: general_functions.first_occurence(orderable, start_at, ")")

def order_span(orderable):

    for i in range(len(orderable)):
        recursive_start = general_functions.first_occurence(orderable, i, "(")

        if recursive_start == -1:
            break
        else:

            recursive_end = general_functions.first_occurence(orderable,
                                                             recursive_start,
                                                             ")")
            recursor = orderable[recursive_start+1:recursive_end]
            recursed =  order_span(recursor)
            del orderable  [recursive_start:recursive_end+1]
            orderable = general_functions.insert_list(orderable,recursor,recursive_start)

    orderable = kill_parentheses(orderable)

    orderable = unary_op_template(orderable)
#!/usr/bin/env python3
import general_functions

nary_op = ["+", "*"]
binary_op = ["^", "mod", "log", "="]
unary_op = {"sin": "~", "cos": "&"}
unary_op_plus = ["sin", "cos"]
op = ["+", "*", "^", "mod", "log", "sin", "cos"]
find_end = lambda orderable, start_at: general_functions.first_occurence(
    orderable, start_at, ")")


def order_span(orderable):

    for i in range(len(orderable)):
        recursive_start = general_functions.first_occurence(orderable, i, "(")

        if recursive_start == -1:
            break
        else:

            recursive_end = general_functions.first_occurence(
                orderable, recursive_start, ")")
            recursor = orderable[recursive_start + 1:recursive_end]
            recursed = order_span(recursor)
            del orderable[recursive_start:recursive_end + 1]
            orderable = general_functions.insert_list(orderable, recursor,
                                                      recursive_start)

    orderable = kill_parentheses(orderable)