Skip to content

Run #2

def value(wallet, valuation):
return sum(wallet * valuation)
def ixpayment(wallet, valuation, quantity):
"""
quantity (float): the amount to transfer
wallet (vector): the tokens owned by this wallet
valuation (vector of len(wallet)): the valuation to use for each token
"""
return wallet * (quantity / value(wallet, valuation))
def conciliation(wallet, source, target, quantity):
"""
wallet (vector): the tokens owned by this wallet
source (vector of len(wallet)): the valuation according to the starting wallet
target (vector of len(wallet)): the valuation according to the destination wallet
quantity (float): the target amount to transfer
"""
return value(ixpayment(wallet, target, quantity), source) - quantity
def payment(wallet, source, target, quantity):
return ixpayment(wallet, source, quantity + conciliation(wallet, source, target, quantity))
oks = 0
for _ in range(samples:=1000000):
wallet = np.random.randint(0, 100, 3)
honest_valuation = np.random.uniform(-10, 100, 3)
feigned_valuation = np.random.uniform(-10, 100, 3)
vendor_valuation = np.random.uniform(-10, 100, 3)
quantity = random.randint(1, 100)
ix_feigned = payment(wallet, feigned_valuation, vendor_valuation, quantity)
ix_honest = payment(wallet, honest_valuation, vendor_valuation, quantity)
customer_value_feign = value(ix_feigned, honest_valuation)
vendor_value_feign = value(ix_feigned, vendor_valuation)
customer_value_honest = value(ix_honest, honest_valuation)
vendor_value_honest = value(ix_honest, vendor_valuation)
ok = np.isclose(customer_value_feign, customer_value_honest, rtol=1e-5) and np.isclose(vendor_value_feign, vendor_value_honest, rtol=1e-5) and all(np.isclose(ix_feigned, ix_honest, rtol=1e-5))
if not ok:
print(f"{wallet=}")
print(f"{honest_valuation=}")
print(f"{feigned_valuation=}")
print(f"{vendor_valuation=}")
print(f"{quantity=}")
print(f"{ix_feigned=}")
print(f"{ix_honest=}")
print(f"when feigning, you feel like you pay {customer_value_feign}")
print(f"when feigning, they feel like they receive {vendor_value_feign}")
print(f"when honest, you feel like you pay {customer_value_honest}")
print(f"when honest, they feel like they receive {vendor_value_honest}")
print(f"{'OK' if ok else 'bad'}")
break
oks += 1
print(f"{oks} samples ok")

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.