def f2(x, y, z): def g1(_z, _y): return _y def g2(_z, _y): return _z def g3(_z, _y): return 0 a = switch(x < 0, g1, g3) b = switch(x > 0, g2, g3) return a(DEAD, y) + b(z, DEAD)
def f1(x, y, z): def g1(): return y def g2(): return z def g3(): return 0 a = switch(x < 0, g1, g3) b = switch(x > 0, g2, g3) return a() + b()
def test_switch2(c, x, y): fn = switch( c, partial(scalar_sub, x), partial(scalar_add, x) ) return fn(y)
def f2(x, y): def g(a, c): return a + c def h(a, c): return a + c return switch(y < 0, g, h)(x + 1, x + 3)
def f2(x, y, z): def true_branch(_y, _z): return _y def false_branch(_y, _z): return _z return switch(x < 0, true_branch, false_branch)(y, z)
def before(x, y): def f1(x, y): return x, y def f2(x, y): return y, x return switch(x < 0, f1, f2)(x, y)[0]
def f1(x, y): def g(a, b, c): return a def h(a, b, c): return c return switch(y < 0, g, h)(x + 1, x + 2, x + 3)
def after(x, y): def f1(x, y): return x def f2(x, y): return y return switch(x < 0, f1, f2)(x, y)
def i(_x): def g(): return _x def h(): return -_x return switch(_x > 0, g, h)
def after_helper(x, y, z): def tb(y, z): return scalar_mul(y, z) def fb(y, z): return scalar_add(y, z) return switch(x < 0, tb, fb)(y, z)
def before(x, y): key = embed(x) def f1(x, y): return env_setitem(newenv, key, x * y) def f2(x, y): return env_setitem(newenv, key, x + y) return env_getitem(switch(x < 0, f1, f2)(x, y), key, 0)
def before(x, y): return env_getitem(switch(x < 0, newenv, newenv), embed(y), 5)
def after(x, y): return switch(x < 0, x[0], y[0])
def before(x, y): return switch(x < 0, x, y)[0]
def after(x, y): return switch(x < 0, x + y, y + x)
def before(x, y): cond = x < 0 a = switch(cond, x, y) b = switch(cond, y, x) return a + b
def before(x, y): a = y * y return switch(x < 0, a, a)
def after(a, b, c, d): x = a < 0 return switch(x, a, d)
def hof(fn): return switch(y < 0, g, fn)(x + 1, x + 2, x + 3)
def i(): return switch(x > 0, g, h)
def after(x, y): key = embed(y) return switch(x < 0, env_getitem(newenv, key, 5), env_getitem(newenv, key, 5))
def before(a, b, c, d): x = a < 0 y = b < 0 return switch(x, switch(y, a, b), switch(y, c, d))
def before(x, y): return switch(True, x, y)
def test_prim_switch(): assert switch(True, 1, 2) == 1 assert switch(False, 1, 2) == 2
def test_switch(c, x): return switch(c, scalar_usub, scalar_uadd)(x)
def before(x, y): return switch(False, x, y)