Click here to Skip to main content
15,920,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have the above code which reads data from a dictionary file and does the following based on the operator

is_function is a set of pairs obeying the condition that if (x,y) ∈ f and (x,z) ∈ f, then y = z.
apply_function ...function application f(x) denotes the unique value y such that (x,y) ∈ f, if there is such a y, and is otherwise undefined.
domain....of a function f is the set dom(f) = { x : ∃ y : (x,y) ∈ f }.
I'm having trouble with my implementation. some of the operators work, but i can't seem to understand how to use cantor's diagonalization.

I'm trying to get the following operators to work... union,intersection, is-function, apply-function, set-difference, domain and inverse with cantor's diagonalization

\Sample Input but i read mine in son format

C#
let x0 be 1;
let x1 be 2;
let x2 be {x0,x1};
let x3 be {(1,2),(3,4)};
let x6 be x2 = {x0,2};
let x8 be ((0,1),(3,(4,5)));
let x9 be {x8};
let x10 be {(0,4),(1,6)};
let x12 be -1;
let x13 be x12 ∈ x2;
let x14 be x0 ∈ x2;
let x15 be x2 = {x0,x1,x1};
let x16 be 8;
let x17 be {1,2,x16};
let x18 be {x17,(1,x17)};
let x19 be (x18,x17);
# Operations after this line are only required in part 2.
# For part 1 submissions, results after this line may be "undefined!"
# if the operation is not yet implemented.
let x4 be @is-function(x2);
let x5 be @is-function(x3);
let x7 be x3 x0;
let x11 be x3 x1;
let x20 be {x19} ∪ x18;
let x21 be x20 ∖ {x17};
let x22 be x20 ∩ {x17};
let x23 be @dom(x10);
let x24 be @is-function(@inverse(x10));
let x25 be @diagonalize ({0,1}, {(0,{(0,1),(1,1)}),(1,{(0,0),(1,0)})},
                         {(0,1),(1,0)}, 2);


and output

C#
let x0 be 1;
let x1 be 2;
let x2 be {1, 2};
let x3 be {(1, 2), (3, 4)};
let x6 be 1;
let x8 be ((0, 1), (3, (4, 5)));
let x9 be {((0, 1), (3, (4, 5)))};
let x10 be {(0, 4), (1, 6)};
let x12 be -1;
let x13 be 0;
let x14 be 1;
let x15 be 1;
let x16 be 8;
let x17 be {1, 2, 8};
let x18 be {{1, 2, 8}, (1, {1, 2, 8})};
let x19 be ({{1, 2, 8}, (1, {1, 2, 8})}, {1, 2, 8});
let x4 be 0;
let x5 be 1;
let x7 be 2;
let x11 be undefined!;
let x20 be {{1, 2, 8}, (1, {1, 2, 8}), ({{1, 2, 8}, (1, {1, 2, 8})}, {1, 2, 8})};
let x21 be {(1, {1, 2, 8}), ({{1, 2, 8}, (1, {1, 2, 8})}, {1, 2, 8})};
let x22 be {{1, 2, 8}};
let x23 be {0, 1};
let x24 be 1;


What I have tried:

Python
def _rv_parse_apply_function(valinfo):
    assert valinfo['operator'] == 'apply-function'
    args = [parse_rvalue(a) for a in valinfo['arguments']]
    return "apply_function(" + ', '.join((str(a) for a in args)) + ")"

def _rv_parse_is_function(valinfo):
    assert valinfo['operator'] == 'is-function'
    args = [parse_rvalue(a) for a in valinfo['arguments']]
    return "is_function(" + ', '.join((str(a) for a in args)) + ")" 

def _rv_parse_union(valinfo):
    assert valinfo['operator'] == 'union'
    result= [];
    args = [parse_rvalue(a) for a in valinfo['arguments']]
    print len(args), args[0], '\n', args[1]
    for i in result:
        if i not in result:
            result.append(i)
    for j in result:
        if j not in result:
            result.append(j)
    return result   

def _rv_parse_set_difference(valinfo):
    assert valinfo['operator'] == 'set-difference'
    result = [];
    args = [parse_rvalue(a) for a in valinfo['arguments']]
    for i in args[0]:
        if i != args[1][0]:
            result.append(i)
    print result        
    return result

def _rv_parse_intersection(valinfo):
    assert valinfo['operator'] == 'intersection'
    result = [];
    args = [parse_rvalue(a) for a in valinfo['arguments']]
    for i in args[0]:
        print args[0],'intersect'
        for j in args[1]:
            print args[1],'intersect'
            if j == i:
                result.append(i)
    print result, 'intersect'    
    return result

def _rv_parse_domain(valinfo):
    assert valinfo['operator'] == 'domain'
    result = [];
    args = [parse_rvalue(a) for a in valinfo['arguments']]
    for i in args[0]:
        if i != args[1][0]:
            result.append(i)
    return result

def _rv_parse_inverse(valinfo):
    assert valinfo['operator'] == 'inverse'
    args = [parse_rvalue(a) for a in valinfo['arguments']]
    return 'Undefined!' 


}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900