You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
B and C are both on line AD, length of AC is 3, length of AB is 2.
The followings are expected to be infered:
B is on AC
length of BC is 1
My code fails because of RecursionError as lineLen and pointOn are dependent on each other:
Len=Relation()
On=Relation()
deflineLen(a, b, l):
""" Length of Line ab is l """c, l1, l2=vars(3)
returnlany(
Len(a, b, l),
lall( # when c in on ab, we have ab=ac+cbpointOn(c, a, b),
Len(a, c, l1),
Len(b, c, l2),
applyo(add, (l1, l2), l)),
lall( # when a is on bc, we have ab=bc-acpointOn(a, b, c),
Len(b, c, l1),
Len(a, c, l2),
applyo(sub, (l1, l2), l)
),
lall( # when b is on ac, we have ab=ac-bcpointOn(b, a, c),
Len(a, c, l1),
Len(b, c, l2),
applyo(sub, (l1, l2), l)
)
)
defpointOn(p, a, b):
""" Point p is on Line ab """d, l1, l2, r=vars(4)
returnlany(
On(p, a, b),
On(p, b, a),
# when p and b are both on line ad, and ab > ap, we know p is on ablall(On(p, a, d), On(b, a, d), lineLen(a, p, l1),
lineLen(a, b, l2), applyo(gt, (l2, l1), r), eq(r, True))
)
facts(On,
('B', 'A', 'D'),
('C', 'A', 'D'),
)
facts(Len,
('A', 'B', 3),
('A', 'C', 4),
)
a, b, c=vars(3)
res=run(0, (a, b, c), pointOn(a, b, c))
forpinres:
print(f'{p[0]} is on {p[1]}{p[2]}')
The case is simple, but seems not that easy to implement, any advice? BTW, using kanren, I find it easy to meet recursion error evenZzz is used.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
B and C are both on line AD, length of AC is 3, length of AB is 2.

The followings are expected to be infered:
My code fails because of
RecursionErroraslineLenandpointOnare dependent on each other:The case is simple, but seems not that easy to implement, any advice? BTW, using kanren, I find it easy to meet recursion error even
Zzzis used.All reactions