1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs kernel math math.intervals
4 namespaces sequences money math.order taxes.usa.w4
5 taxes.usa.futa math.finance taxes.usa.fica
9 ! Withhold: FICA, Medicare, Federal (FICA is social security)
11 TUPLE: tax-table entity single married ;
12 C: <tax-table> tax-table
14 GENERIC: adjust-allowances* ( salary w4 tax-table entity -- newsalary )
15 GENERIC: withholding* ( salary w4 tax-table entity -- x )
17 : adjust-allowances ( salary w4 tax-table -- newsalary )
18 dup entity>> adjust-allowances* ;
20 : withholding ( salary w4 tax-table -- x )
21 dup entity>> withholding* ;
23 : tax-bracket-range ( pair -- n ) first2 swap - ;
25 : tax-bracket ( tax salary triples -- tax salary )
26 [ [ tax-bracket-range min ] keep third * + ] 2keep
27 tax-bracket-range [-] ;
29 : tax ( salary triples -- x )
30 0 -rot [ tax-bracket ] each drop ;
32 : marriage-table ( w4 tax-table -- triples )
34 [ married>> ] [ single>> ] if ;