#!/usr/local/bin/maple # -*- maplev -*- # Nathaniel Shar # HW 7 # Experimental Mathematics # It is okay to link to this assignment on the course webpage. Help := proc(): print(`ge(x,y), le(x,y), eq(x,y), lt(x,y), gt(x,y), plus(x,y), neg(x), IsNumber(x), SN(n), times(x,y), NaiveMUL(a,n), CheckNaiveMul(K), HalfToPower(n)`): end: # From my c7.txt ge := proc(x,y) local xL, xR, yL, yR, i: xR := x[2]: yL := y[1]: if not(evalb(true in {seq(ge(y,i), i=xR)})) and not(evalb(true in {seq(ge(i, x), i=yL)})) then: return true: else: return false: fi: end: le := proc(x,y): return ge(y,x): end: eq := proc(x,y): if ge(x,y) and ge(y,x) then: return true: else: return false: fi: end: lt := proc(x,y): if le(x,y) and not le(y,x) then: return true: else: return false: fi: end: gt := proc(x,y): if ge(x,y) and not ge(y,x) then: return true: else: return false: fi: end: plus := proc(x,y) local i: option remember: return [{seq(plus(i,y), i in x[1]), seq(plus(x,i), i in y[1])}, {seq(plus(i,y), i in x[2]), seq(plus(x,i), i in y[2])}]: end: neg := proc(x): return [map(neg, x[2]), map(neg, x[1])]: end: IsNumber := proc(x) local xL, xR: option remember: if not(whattype(x)=list) or not(nops(x)=2) or not(whattype(x[1]) = set) or not(whattype(x[2])=set) then: return false: elif evalb(false in map(IsNumber, x[1])) or evalb(false in map(IsNumber, x[2])) then: return false: elif evalb(true in {seq(seq(ge(xL, xR), xL=x[1]), xR=x[2])}) then: return false: else: return true: fi: end: SN := proc(n): if n = 0 then: return [{}, {}]: elif n > 0 then: return [{SN(n-1)}, {}]: else: return neg(SN(-n)): fi: end: times := proc(x,y) local i, j: option remember: return [{seq(seq(plus(plus(times(i,y), times(x, j)), neg(times(i,j))), i=x[1]), j=y[1]), seq(seq(plus(plus(times(i,y), times(x, j)), neg(times(i,j))), i=x[2]), j=y[2])}, {seq(seq(plus(plus(times(i,y), times(x, j)), neg(times(i,j))), i=x[1]), j=y[2]), seq(seq(plus(plus(times(i,y), times(x, j)), neg(times(i,j))), i=x[2]), j=y[1])}]: end: ############# # Problem 1 # ############# NaiveMUL := proc(a,n) option remember: if n = 0 then: return SN(0): else: return plus(a,NaiveMUL(a,n-1)): fi: end: ############# # Problem 2 # ############# CheckNaiveMul := proc(K) local m, n, L: L := {}: for m from 1 to K do: for n from 1 to K do: if not eq(NaiveMUL(SN(m),n), SN(m*n)) then: L := L union {"SN(m),n"}: fi: od: od: return L: end: # CheckNaiveMul(10) = {} ############# # Problem 3 # ############# HalfToPower := proc(n): if n = 0 then: return SN(1): elif n < 0 then: return SN(2^{-n}): else: return [{SN(0)}, {HalfToPower(n-1)}]: fi: end: ############# # Problem 4 # ############# MUL := times: ############# # Problem 5 # ############# # 2*2 does indeed equal 4. # I ran out of patience for 3*4.