From 525fa362edca74107375ec899e2b95afaa56793a Mon Sep 17 00:00:00 2001 From: jacintodavila <> Date: Tue, 21 Jun 2022 20:27:22 -0400 Subject: [PATCH] Extends example 121 with scenario with a spouse --- kb/tax121.pl | 132 +++++++++++++++++++++++----------------- kb/tax121_0.pl | 118 ++++++++++++++++++++++++++++++------ kb/tax121_1.pl | 42 ++++++++----- kb/tax121_1_1.pl | 130 +++++++++++++++++++++++++++++++++++++++ kb/tax121_2.pl | 154 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 490 insertions(+), 86 deletions(-) create mode 100644 kb/tax121_1_1.pl create mode 100644 kb/tax121_2.pl diff --git a/kb/tax121.pl b/kb/tax121.pl index f5a3130..b73957b 100644 --- a/kb/tax121.pl +++ b/kb/tax121.pl @@ -4,22 +4,26 @@ the templates are: -gross income of *a taxpayer* excludes gain from *an exchange* of *a property*. +gross income of *a taxpayer* excludes gain from *an exchange* of *a property* at *a date*. *an exchange* of *a property* occurs at *a date*. -*a period* of *a number* days ends at *a date*. +*a period* of *a number* years ends at *a date*. *a property* has been owned by *a taxpayer* as residence for *a set* of periods. *a property* has been used by *a taxpayer* as residence for *a set* of periods. *a set* of periods aggregates to *a number* of years. -*a set* of periods is contained in *a bigger period*. -*a complete set* combines *a first set* and *a second set*. +*a set* of periods is contained in *a long period*. *a set of periods* as *a taxpayer*'s principal residence aggregates to *a number of* years or more during *a bigger period*. -the amount of gain excluded for *a taxpayer* from *a sale or exchange* under subsection a is *an amount*. +the amount of gain excluded for *a taxpayer* from *a sale or exchange* under subsection (a) is *an amount*. special rules for joint returns apply to *a taxpayer* and *a property*. *a person* is married to *an other person*. -neither *a taxpayer* nor *a spouse* are ineligible for the benefits of subsection a with respect to *a property* by reason of paragraph 3. -*a taxpayer* meets the ownership requirements of subsection a with respect to *a property*. -*a spouse* meets the use requirements of subsection a with respect to *a property*. -subsection a shall not apply to any sale or exchange of *a property* by *a person*. +both *a taxpayer* and *a spouse* are eligible for the benefits of subsection (a) with respect to *an exchange* of *a property* by reason of paragraph 3. +*a taxpayer* meets the ownership requirements of subsection (a) with respect to *an exchange* of *a property* at *a date*. +*a taxpayer* meets the use requirements of subsection (a) with respect to *an exchange* of *a property* at *a date*. +subsection (a) shall apply to *a sale or exchange* of *a property* by *a person*. +*a date* is included in *a period*. +*a property* has been owned by *a taxpayer* for periods aggregating *a number* years or more during *a period*. +*a property* has been used by *a taxpayer* as principal residence for periods aggregating *a number* years or more during *a period*. +*a set* of periods of *a taxpayer* owing *a property* aggregates to *a number* of years. +*a set* of periods of *a taxpayer* using *a property* as principal residence aggregates to *a number* of years. the knowledge base tax121 includes: @@ -29,18 +33,29 @@ % such property has been owned and used by the taxpayer as % the taxpayer’s principal residence for periods aggregating 2 years or more. -gross income of a taxpayer excludes gain from a sale or exchange of a property if - the sale or exchange of the property occurs at a date - and a 5-year period of 1825 days ends at the date - and the property has been owned by the taxpayer as residence for a property ownership set of periods - and the property has been used by the taxpayer as residence for a property usage set of periods - and the property ownership set as the taxpayer's principal residence aggregates to 2 years or more during the 5-year period - and the property usage set as the taxpayer's principal residence aggregates to 2 years or more during the 5-year period. - -a set as a person's principal residence aggregates to a top number of years or more during a bigger period if - the set of periods aggregates to a number of years - and the number >= the top number of - and the set of periods is contained in the bigger period. +gross income of a taxpayer excludes gain from a sale or exchange of a property at a date if + the taxpayer meets the ownership requirements of subsection (a) with respect to the sale or exchange of the property at the date + and the taxpayer meets the use requirements of subsection (a) with respect to the sale or exchange of the property at the date. + +a taxpayer meets the ownership requirements of subsection (a) with respect to a sale or exchange of a property at a date + if the sale or exchange of the property occurs at the date + and a period of 5 years ends at the date + and the property has been owned by the taxpayer for periods aggregating 2 years or more during the period. + +a taxpayer meets the use requirements of subsection (a) with respect to a sale or exchange of a property at a date + if the sale or exchange of the property occurs at the date + and a period of 5 years ends at the date + and the property has been used by the taxpayer as principal residence for periods aggregating 2 years or more during the period. + +a property has been owned by a taxpayer for periods aggregating a limit number years or more during a given period + if a set of periods of the taxpayer owing the property aggregates to a total number of years + and the total number >= the limit number + and the set of periods is contained in the given period. + +a property has been used by a taxpayer as principal residence for periods aggregating a limit number years or more during a given period + if a set of periods of the taxpayer using the property as principal residence aggregates to a total number of years + and the total number >= the limit number + and the set of periods is contained in the given period. % (b) Limitations % (1) In general @@ -49,8 +64,8 @@ % % Special rules for joint returns -the amount of gain excluded for a taxpayer from a sale or exchange under subsection a is 250000 - if gross income of the taxpayer excludes gain from the sale or exchange of a property +the amount of gain excluded for a taxpayer from a sale or exchange under subsection (a) is 250000 + if gross income of the taxpayer excludes gain from the sale or exchange of a property at a date and it is not the case that special rules for joint returns apply to the taxpayer and the property. @@ -62,26 +77,21 @@ % (iii) neither spouse is ineligible for the benefits of subsection (a) % with respect to such property by reason of paragraph (3). -the amount of gain excluded for a taxpayer from a sale or exchange under subsection a is 500000 - if gross income of a taxpayer excludes gain from the sale or exchange of a property +the amount of gain excluded for a taxpayer from a sale or exchange under subsection (a) is 500000 + if gross income of the taxpayer excludes gain from the sale or exchange of a property at a date and special rules for joint returns apply to the taxpayer and the property. special rules for joint returns apply to a taxpayer and a property if the taxpayer is married to a spouse - and the taxpayer meets the ownership requirements of subsection a with respect to the property - or the spouse meets the use requirements of subsection a with respect to the property - or neither the taxpayer nor the spouse are ineligible for the benefits of subsection a with respect to the property by reason of paragraph 3. - -% simplified (it does not correctly discriminate ownership from usage yet) -a person meets the ownership requirements of subsection a with respect to a property - if gross income of the person excludes gain from a sale or exchange of the property. - -a person meets the use requirements of subsection a with respect to a property - if gross income of the person excludes gain from a sale or exchange of the property. - -neither the taxpayer nor the spouse are ineligible for the benefits of subsection a with respect to the property by reason of paragraph 3 - if subsection a shall not apply to any sale or exchange of the property by the taxpayer - and subsection a shall not apply to any sale or exchange of the property by the spouse. + and the taxpayer meets the ownership requirements of subsection (a) with respect to a sale or exchange of the property at a date + or the spouse meets the ownership requirements of subsection (a) with respect to the sale or exchange of the property at the date + and the taxpayer meets the use requirements of subsection (a) with respect to the sale or exchange of the property at the date + and the spouse meets the use requirements of subsection (a) with respect to the sale or exchange of the property at the date + and both the taxpayer and the spouse are eligible for the benefits of subsection (a) with respect to the sale or exchange of the property by reason of paragraph 3. + +both a taxpayer and a spouse are eligible for the benefits of subsection (a) with respect to a sale or exchange of a property by reason of paragraph 3 + if subsection (a) shall apply to the sale or exchange of the property by the taxpayer + and subsection (a) shall apply to the sale or exchange of the property by the spouse. % % (B) Other joint returns % @@ -97,28 +107,40 @@ % during the 2-year period ending on the date of such sale or exchange, % there was any other sale or exchange by the taxpayer to which subsection (a) applied. -subsection a shall not apply to any sale or exchange of a property by a taxpayer +subsection (a) shall apply to a sale or exchange of a property by a taxpayer if the sale or exchange of the property occurs at a date - and a 2-year period of a number of days ends at the date - and an other sale or exchange of the property occurs at a second date - and the second date is included in the 2-year period - and gross income of the taxpayer excludes gain from the other sale or exchange of the property. + and it is not the case that + an other sale or exchange of the property occurs at a second date + and the other sale or exchange is different from the sale or exchange + and a period of 2 years ends at the date + and the second date is included in the period + and gross income of the taxpayer excludes gain from the other sale or exchange of the property at the second date. scenario one is: - the sale of the house occurs at 2022-01-01. - the big period of 1825 days ends at 2022-01-01. - the house has been owned by the taxpayer as residence for the first part of periods. - the house has been used by the taxpayer as residence for the second part of periods. - the first part of periods aggregates to 2 of years. - the second part of periods aggregates to 3 of years. - the first part of periods is contained in the big period. - the second part of periods is contained in the big period. + the sale of the house occurs at 2022-06-20. + the given period of 5 years ends at 2022-06-20. + first set of periods of the taxpayer owing the house aggregates to 2 of years. + first set of periods is contained in the given period. + second set of periods of the taxpayer using the house as principal residence aggregates to 3 of years. + second set of periods is contained in the given period. + +scenario two is: + the sale of the house occurs at 2022-06-20. + the given period of 5 years ends at 2022-06-20. + the testing period of 2 years ends at 2022-06-20. + the taxpayer is married to the spouse. + first set of periods of the taxpayer owing the house aggregates to 2 of years. + first set of periods is contained in the given period. + second set of periods of the taxpayer using the house as principal residence aggregates to 3 of years. + second set of periods is contained in the given period. + third set of periods of the spouse using the house as principal residence aggregates to 4 of years. + third set of periods is contained in the given period. query one is: - gross income of which taxpayer excludes gain from which exchange of which property. + gross income of which taxpayer excludes gain from which exchange of which property at which date. query two is: - the amount of gain excluded for the taxpayer from which sale under subsection a is which amount. + the amount of gain excluded for the taxpayer from which sale under subsection (a) is which amount. "). @@ -127,4 +149,6 @@ ?- answer("query two with scenario one"). ?- answer(one, with(one), le(E), R). ?- answer(two, with(one), le(E), R). +?- answer("query two with scenario two"). +?- answer(two, with(two), le(E), R). */ diff --git a/kb/tax121_0.pl b/kb/tax121_0.pl index 0489e8c..2582716 100644 --- a/kb/tax121_0.pl +++ b/kb/tax121_0.pl @@ -5,15 +5,24 @@ the templates are: gross income of *a taxpayer* excludes gain from *an exchange* of *a property*. -*an exchange* occurs at *a date*. -*a period* ends at *a date*. -the size of *a period* is *a number* days. +*an exchange* of *a property* occurs at *a date*. +*a period* of *a number* days ends at *a date*. *a property* has been owned by *a taxpayer* as residence for *a set* of periods. *a property* has been used by *a taxpayer* as residence for *a set* of periods. *a set* of periods aggregates to *a number* of years. *a set* of periods is contained in *a bigger period*. *a complete set* combines *a first set* and *a second set*. *a set of periods* as *a taxpayer*'s principal residence aggregates to *a number of* years or more during *a bigger period*. +the amount of gain excluded for *a taxpayer* from *a sale or exchange* under subsection a is *an amount*. +special rules for joint returns apply to *a taxpayer* and *a property*. +*a person* is married to *an other person*. +neither *a taxpayer* nor *a spouse* are ineligible for the benefits of subsection a with respect to *a property* by reason of paragraph 3. +*a taxpayer* meets the ownership requirements of subsection a with respect to *a property*. +*a taxpayer* meets the ownership requirements of subsection a with respect to *an exchange* of *a property* at *a date*. +*a spouse* meets the use requirements of subsection a with respect to *a property*. +*a taxpayer* meets the use requirements of subsection a with respect to *an exchange* of *a property* at *a date*. +subsection a shall not apply to any sale or exchange of *a property* by *a person*. +*a date* is included in *a period*. the knowledge base tax121 includes: @@ -24,35 +33,110 @@ % the taxpayer’s principal residence for periods aggregating 2 years or more. gross income of a taxpayer excludes gain from a sale or exchange of a property if - the sale or exchange occurs at a date - and a 5-year period ends at the date - and the size of the 5-year period is 1825 days - and the property has been owned by the taxpayer as residence for a first set of periods - and the property has been used by the taxpayer as residence for a second set of periods - and a complete set combines the first set and the second set - and the complete set as the taxpayer's principal residence aggregates to 2 years or more during the 5-year period. - + the taxpayer meets the ownership requirements of subsection a with respect to the sale or exchange of the property at a date + and the taxpayer meets the use requirements of subsection a with respect to the sale or exchange of the property at the date. + +a taxpayer meets the ownership requirements of subsection a with respect to a sale or exchange of a property at a date + if the sale or exchange of the property occurs at the date + and a 5-year period of 1825 days ends at the date + and the property has been owned by the taxpayer as residence for a property ownership set of periods + and the property ownership set as the taxpayer's principal residence aggregates to 2 years or more during the 5-year period. + +a taxpayer meets the use requirements of subsection a with respect to a sale or exchange of a property at a date + if the sale or exchange of the property occurs at the date + and a 5-year period of 1825 days ends at the date + and the property has been used by the taxpayer as residence for a property usage set of periods + and the property usage set as the taxpayer's principal residence aggregates to 2 years or more during the 5-year period. + a set as a person's principal residence aggregates to a top number of years or more during a bigger period if the set of periods aggregates to a number of years and the number >= the top number of and the set of periods is contained in the bigger period. + +% (b) Limitations +% (1) In general +% The amount of gain excluded from gross income under subsection (a) +% with respect to any sale or exchange shall not exceed $250,000. +% +% Special rules for joint returns + +the amount of gain excluded for a taxpayer from a sale or exchange under subsection a is 250000 + if gross income of the taxpayer excludes gain from the sale or exchange of a property + and it is not the case that + special rules for joint returns apply to the taxpayer and the property. + +% A) $500,000 Limitation for certain joint returns +% Paragraph (1) shall be applied +% by substituting “$500,000” for “$250,000” if— +% (i) either spouse meets the ownership requirements of subsection (a) with respect to such property; +% (ii) both spouses meet the use requirements of subsection (a) with respect to such property; and +% (iii) neither spouse is ineligible for the benefits of subsection (a) +% with respect to such property by reason of paragraph (3). + +the amount of gain excluded for a taxpayer from a sale or exchange under subsection a is 500000 + if gross income of a taxpayer excludes gain from the sale or exchange of a property + and special rules for joint returns apply to the taxpayer and the property. + +special rules for joint returns apply to a taxpayer and a property + if the taxpayer is married to a spouse + and the taxpayer meets the ownership requirements of subsection a with respect to the property + or the spouse meets the ownership requirements of subsection a with respect to the property + and the taxpayer meets the use requirements of subsection a with respect to the property + and the spouse meets the use requirements of subsection a with respect to the property + and neither the taxpayer nor the spouse are ineligible for the benefits of subsection a with respect to the property by reason of paragraph 3. + +a person meets the ownership requirements of subsection a with respect to a property + if the person meets the ownership requirements of subsection a with respect to a sale or exchange of the property at a date. + +a person meets the use requirements of subsection a with respect to a property + if the person meets the use requirements of subsection a with respect to a sale or exchange of the property at a date. + +neither a taxpayer nor a spouse are ineligible for the benefits of subsection a with respect to a property by reason of paragraph 3 + if subsection a shall not apply to any sale or exchange of the property by the taxpayer + and subsection a shall not apply to any sale or exchange of the property by the spouse. +% +% (B) Other joint returns +% +% If such spouses do not meet the requirements of subparagraph (A), +% the limitation under paragraph (1) shall be the sum of the limitations under paragraph (1) +% to which each spouse would be entitled if such spouses had not been married. +% For purposes of the preceding sentence, each spouse shall be treated as +% owning the property during the period that either spouse owned the property. + +% (3) Application to only 1 sale or exchange every 2 years +% +% Subsection (a) shall not apply to any sale or exchange by the taxpayer if, +% during the 2-year period ending on the date of such sale or exchange, +% there was any other sale or exchange by the taxpayer to which subsection (a) applied. + +subsection a shall not apply to any sale or exchange of a property by a taxpayer + if the sale or exchange of the property occurs at a date + and a 2-year period of a number of days ends at the date + and an other sale or exchange of the property occurs at a second date + and the second date is included in the 2-year period + and gross income of the taxpayer excludes gain from the other sale or exchange of the property. scenario one is: - the sale occurs at 1. - the big period ends at 1. - the size of the big period is 1825 days. + the sale of the house occurs at 2022-06-20. + the big period of 1825 days ends at 2022-06-20. the house has been owned by the taxpayer as residence for the first part of periods. the house has been used by the taxpayer as residence for the second part of periods. - [1, 2] combines the first part and the second part. - [1, 2] of periods aggregates to 3 of years. - [1, 2] of periods is contained in the big period. + the first part of periods aggregates to 2 of years. + the second part of periods aggregates to 3 of years. + the first part of periods is contained in the big period. + the second part of periods is contained in the big period. query one is: gross income of which taxpayer excludes gain from which exchange of which property. +query two is: + the amount of gain excluded for the taxpayer from which sale under subsection a is which amount. + "). /** ?- answer("query one with scenario one"). +?- answer("query two with scenario one"). ?- answer(one, with(one), le(E), R). +?- answer(two, with(one), le(E), R). */ diff --git a/kb/tax121_1.pl b/kb/tax121_1.pl index 638c868..2582716 100644 --- a/kb/tax121_1.pl +++ b/kb/tax121_1.pl @@ -1,4 +1,4 @@ -:- module('tax121_1+https://www.law.cornell.edu/uscode/text/26/121',[]). +:- module('tax121+https://www.law.cornell.edu/uscode/text/26/121',[]). en("the target language is: prolog. @@ -18,10 +18,13 @@ *a person* is married to *an other person*. neither *a taxpayer* nor *a spouse* are ineligible for the benefits of subsection a with respect to *a property* by reason of paragraph 3. *a taxpayer* meets the ownership requirements of subsection a with respect to *a property*. +*a taxpayer* meets the ownership requirements of subsection a with respect to *an exchange* of *a property* at *a date*. *a spouse* meets the use requirements of subsection a with respect to *a property*. -subsection a shall not apply to any sale or exchange of *a property* by *a person*. +*a taxpayer* meets the use requirements of subsection a with respect to *an exchange* of *a property* at *a date*. +subsection a shall not apply to any sale or exchange of *a property* by *a person*. +*a date* is included in *a period*. -the knowledge base tax121_1 includes: +the knowledge base tax121 includes: % (a) Exclusion % Gross income shall not include gain from the sale or exchange of property if, @@ -30,13 +33,21 @@ % the taxpayer’s principal residence for periods aggregating 2 years or more. gross income of a taxpayer excludes gain from a sale or exchange of a property if - the sale or exchange of the property occurs at a date - and a 5-year period of 1825 days ends at the date + the taxpayer meets the ownership requirements of subsection a with respect to the sale or exchange of the property at a date + and the taxpayer meets the use requirements of subsection a with respect to the sale or exchange of the property at the date. + +a taxpayer meets the ownership requirements of subsection a with respect to a sale or exchange of a property at a date + if the sale or exchange of the property occurs at the date + and a 5-year period of 1825 days ends at the date and the property has been owned by the taxpayer as residence for a property ownership set of periods + and the property ownership set as the taxpayer's principal residence aggregates to 2 years or more during the 5-year period. + +a taxpayer meets the use requirements of subsection a with respect to a sale or exchange of a property at a date + if the sale or exchange of the property occurs at the date + and a 5-year period of 1825 days ends at the date and the property has been used by the taxpayer as residence for a property usage set of periods - and the property ownership set as the taxpayer's principal residence aggregates to 2 years or more during the 5-year period and the property usage set as the taxpayer's principal residence aggregates to 2 years or more during the 5-year period. - + a set as a person's principal residence aggregates to a top number of years or more during a bigger period if the set of periods aggregates to a number of years and the number >= the top number of @@ -69,17 +80,18 @@ special rules for joint returns apply to a taxpayer and a property if the taxpayer is married to a spouse and the taxpayer meets the ownership requirements of subsection a with respect to the property - or the spouse meets the use requirements of subsection a with respect to the property - or neither the taxpayer nor the spouse are ineligible for the benefits of subsection a with respect to the property by reason of paragraph 3. + or the spouse meets the ownership requirements of subsection a with respect to the property + and the taxpayer meets the use requirements of subsection a with respect to the property + and the spouse meets the use requirements of subsection a with respect to the property + and neither the taxpayer nor the spouse are ineligible for the benefits of subsection a with respect to the property by reason of paragraph 3. -% simplified (it does not correctly discriminate ownership from usage yet) a person meets the ownership requirements of subsection a with respect to a property - if gross income of the person excludes gain from a sale or exchange of the property. + if the person meets the ownership requirements of subsection a with respect to a sale or exchange of the property at a date. a person meets the use requirements of subsection a with respect to a property - if gross income of the person excludes gain from a sale or exchange of the property. + if the person meets the use requirements of subsection a with respect to a sale or exchange of the property at a date. -neither the taxpayer nor the spouse are ineligible for the benefits of subsection a with respect to the property by reason of paragraph 3 +neither a taxpayer nor a spouse are ineligible for the benefits of subsection a with respect to a property by reason of paragraph 3 if subsection a shall not apply to any sale or exchange of the property by the taxpayer and subsection a shall not apply to any sale or exchange of the property by the spouse. % @@ -105,8 +117,8 @@ and gross income of the taxpayer excludes gain from the other sale or exchange of the property. scenario one is: - the sale of the house occurs at 2022-01-01. - the big period of 1825 days ends at 2022-01-01. + the sale of the house occurs at 2022-06-20. + the big period of 1825 days ends at 2022-06-20. the house has been owned by the taxpayer as residence for the first part of periods. the house has been used by the taxpayer as residence for the second part of periods. the first part of periods aggregates to 2 of years. diff --git a/kb/tax121_1_1.pl b/kb/tax121_1_1.pl new file mode 100644 index 0000000..638c868 --- /dev/null +++ b/kb/tax121_1_1.pl @@ -0,0 +1,130 @@ +:- module('tax121_1+https://www.law.cornell.edu/uscode/text/26/121',[]). + +en("the target language is: prolog. + +the templates are: + +gross income of *a taxpayer* excludes gain from *an exchange* of *a property*. +*an exchange* of *a property* occurs at *a date*. +*a period* of *a number* days ends at *a date*. +*a property* has been owned by *a taxpayer* as residence for *a set* of periods. +*a property* has been used by *a taxpayer* as residence for *a set* of periods. +*a set* of periods aggregates to *a number* of years. +*a set* of periods is contained in *a bigger period*. +*a complete set* combines *a first set* and *a second set*. +*a set of periods* as *a taxpayer*'s principal residence aggregates to *a number of* years or more during *a bigger period*. +the amount of gain excluded for *a taxpayer* from *a sale or exchange* under subsection a is *an amount*. +special rules for joint returns apply to *a taxpayer* and *a property*. +*a person* is married to *an other person*. +neither *a taxpayer* nor *a spouse* are ineligible for the benefits of subsection a with respect to *a property* by reason of paragraph 3. +*a taxpayer* meets the ownership requirements of subsection a with respect to *a property*. +*a spouse* meets the use requirements of subsection a with respect to *a property*. +subsection a shall not apply to any sale or exchange of *a property* by *a person*. + +the knowledge base tax121_1 includes: + +% (a) Exclusion +% Gross income shall not include gain from the sale or exchange of property if, +% during the 5-year period ending on the date of the sale or exchange, +% such property has been owned and used by the taxpayer as +% the taxpayer’s principal residence for periods aggregating 2 years or more. + +gross income of a taxpayer excludes gain from a sale or exchange of a property if + the sale or exchange of the property occurs at a date + and a 5-year period of 1825 days ends at the date + and the property has been owned by the taxpayer as residence for a property ownership set of periods + and the property has been used by the taxpayer as residence for a property usage set of periods + and the property ownership set as the taxpayer's principal residence aggregates to 2 years or more during the 5-year period + and the property usage set as the taxpayer's principal residence aggregates to 2 years or more during the 5-year period. + +a set as a person's principal residence aggregates to a top number of years or more during a bigger period if + the set of periods aggregates to a number of years + and the number >= the top number of + and the set of periods is contained in the bigger period. + +% (b) Limitations +% (1) In general +% The amount of gain excluded from gross income under subsection (a) +% with respect to any sale or exchange shall not exceed $250,000. +% +% Special rules for joint returns + +the amount of gain excluded for a taxpayer from a sale or exchange under subsection a is 250000 + if gross income of the taxpayer excludes gain from the sale or exchange of a property + and it is not the case that + special rules for joint returns apply to the taxpayer and the property. + +% A) $500,000 Limitation for certain joint returns +% Paragraph (1) shall be applied +% by substituting “$500,000” for “$250,000” if— +% (i) either spouse meets the ownership requirements of subsection (a) with respect to such property; +% (ii) both spouses meet the use requirements of subsection (a) with respect to such property; and +% (iii) neither spouse is ineligible for the benefits of subsection (a) +% with respect to such property by reason of paragraph (3). + +the amount of gain excluded for a taxpayer from a sale or exchange under subsection a is 500000 + if gross income of a taxpayer excludes gain from the sale or exchange of a property + and special rules for joint returns apply to the taxpayer and the property. + +special rules for joint returns apply to a taxpayer and a property + if the taxpayer is married to a spouse + and the taxpayer meets the ownership requirements of subsection a with respect to the property + or the spouse meets the use requirements of subsection a with respect to the property + or neither the taxpayer nor the spouse are ineligible for the benefits of subsection a with respect to the property by reason of paragraph 3. + +% simplified (it does not correctly discriminate ownership from usage yet) +a person meets the ownership requirements of subsection a with respect to a property + if gross income of the person excludes gain from a sale or exchange of the property. + +a person meets the use requirements of subsection a with respect to a property + if gross income of the person excludes gain from a sale or exchange of the property. + +neither the taxpayer nor the spouse are ineligible for the benefits of subsection a with respect to the property by reason of paragraph 3 + if subsection a shall not apply to any sale or exchange of the property by the taxpayer + and subsection a shall not apply to any sale or exchange of the property by the spouse. +% +% (B) Other joint returns +% +% If such spouses do not meet the requirements of subparagraph (A), +% the limitation under paragraph (1) shall be the sum of the limitations under paragraph (1) +% to which each spouse would be entitled if such spouses had not been married. +% For purposes of the preceding sentence, each spouse shall be treated as +% owning the property during the period that either spouse owned the property. + +% (3) Application to only 1 sale or exchange every 2 years +% +% Subsection (a) shall not apply to any sale or exchange by the taxpayer if, +% during the 2-year period ending on the date of such sale or exchange, +% there was any other sale or exchange by the taxpayer to which subsection (a) applied. + +subsection a shall not apply to any sale or exchange of a property by a taxpayer + if the sale or exchange of the property occurs at a date + and a 2-year period of a number of days ends at the date + and an other sale or exchange of the property occurs at a second date + and the second date is included in the 2-year period + and gross income of the taxpayer excludes gain from the other sale or exchange of the property. + +scenario one is: + the sale of the house occurs at 2022-01-01. + the big period of 1825 days ends at 2022-01-01. + the house has been owned by the taxpayer as residence for the first part of periods. + the house has been used by the taxpayer as residence for the second part of periods. + the first part of periods aggregates to 2 of years. + the second part of periods aggregates to 3 of years. + the first part of periods is contained in the big period. + the second part of periods is contained in the big period. + +query one is: + gross income of which taxpayer excludes gain from which exchange of which property. + +query two is: + the amount of gain excluded for the taxpayer from which sale under subsection a is which amount. + +"). + +/** +?- answer("query one with scenario one"). +?- answer("query two with scenario one"). +?- answer(one, with(one), le(E), R). +?- answer(two, with(one), le(E), R). +*/ diff --git a/kb/tax121_2.pl b/kb/tax121_2.pl new file mode 100644 index 0000000..24fbf45 --- /dev/null +++ b/kb/tax121_2.pl @@ -0,0 +1,154 @@ +:- module('tax121_2+https://www.law.cornell.edu/uscode/text/26/121',[]). + +en("the target language is: prolog. + +the templates are: + +gross income of *a taxpayer* excludes gain from *an exchange* of *a property* at *a date*. +*an exchange* of *a property* occurs at *a date*. +*a period* of *a number* years ends at *a date*. +*a property* has been owned by *a taxpayer* as residence for *a set* of periods. +*a property* has been used by *a taxpayer* as residence for *a set* of periods. +*a set* of periods aggregates to *a number* of years. +*a set* of periods is contained in *a long period*. +*a set of periods* as *a taxpayer*'s principal residence aggregates to *a number of* years or more during *a bigger period*. +the amount of gain excluded for *a taxpayer* from *a sale or exchange* under subsection (a) is *an amount*. +special rules for joint returns apply to *a taxpayer* and *a property*. +*a person* is married to *an other person*. +both *a taxpayer* and *a spouse* are eligible for the benefits of subsection (a) with respect to *an exchange* of *a property* by reason of paragraph 3. +*a taxpayer* meets the ownership requirements of subsection (a) with respect to *an exchange* of *a property* at *a date*. +*a taxpayer* meets the use requirements of subsection (a) with respect to *an exchange* of *a property* at *a date*. +subsection (a) shall apply to *a sale or exchange* of *a property* by *a person*. +*a date* is included in *a period*. +*a property* has been owned by *a taxpayer* for periods aggregating *a number* years or more during *a period*. +*a property* has been used by *a taxpayer* as principal residence for periods aggregating *a number* years or more during *a period*. +*a set* of periods of *a taxpayer* owing *a property* aggregates to *a number* of years. +*a set* of periods of *a taxpayer* using *a property* as principal residence aggregates to *a number* of years. + +the knowledge base tax121_2 includes: + +% (a) Exclusion +% Gross income shall not include gain from the sale or exchange of property if, +% during the 5-year period ending on the date of the sale or exchange, +% such property has been owned and used by the taxpayer as +% the taxpayer’s principal residence for periods aggregating 2 years or more. + +gross income of a taxpayer excludes gain from a sale or exchange of a property at a date if + the taxpayer meets the ownership requirements of subsection (a) with respect to the sale or exchange of the property at the date + and the taxpayer meets the use requirements of subsection (a) with respect to the sale or exchange of the property at the date. + +a taxpayer meets the ownership requirements of subsection (a) with respect to a sale or exchange of a property at a date + if the sale or exchange of the property occurs at the date + and a period of 5 years ends at the date + and the property has been owned by the taxpayer for periods aggregating 2 years or more during the period. + +a taxpayer meets the use requirements of subsection (a) with respect to a sale or exchange of a property at a date + if the sale or exchange of the property occurs at the date + and a period of 5 years ends at the date + and the property has been used by the taxpayer as principal residence for periods aggregating 2 years or more during the period. + +a property has been owned by a taxpayer for periods aggregating a limit number years or more during a given period + if a set of periods of the taxpayer owing the property aggregates to a total number of years + and the total number >= the limit number + and the set of periods is contained in the given period. + +a property has been used by a taxpayer as principal residence for periods aggregating a limit number years or more during a given period + if a set of periods of the taxpayer using the property as principal residence aggregates to a total number of years + and the total number >= the limit number + and the set of periods is contained in the given period. + +% (b) Limitations +% (1) In general +% The amount of gain excluded from gross income under subsection (a) +% with respect to any sale or exchange shall not exceed $250,000. +% +% Special rules for joint returns + +the amount of gain excluded for a taxpayer from a sale or exchange under subsection (a) is 250000 + if gross income of the taxpayer excludes gain from the sale or exchange of a property at a date + and it is not the case that + special rules for joint returns apply to the taxpayer and the property. + +% A) $500,000 Limitation for certain joint returns +% Paragraph (1) shall be applied +% by substituting “$500,000” for “$250,000” if— +% (i) either spouse meets the ownership requirements of subsection (a) with respect to such property; +% (ii) both spouses meet the use requirements of subsection (a) with respect to such property; and +% (iii) neither spouse is ineligible for the benefits of subsection (a) +% with respect to such property by reason of paragraph (3). + +the amount of gain excluded for a taxpayer from a sale or exchange under subsection (a) is 500000 + if gross income of the taxpayer excludes gain from the sale or exchange of a property at a date + and special rules for joint returns apply to the taxpayer and the property. + +special rules for joint returns apply to a taxpayer and a property + if the taxpayer is married to a spouse + and the taxpayer meets the ownership requirements of subsection (a) with respect to a sale or exchange of the property at a date + or the spouse meets the ownership requirements of subsection (a) with respect to the sale or exchange of the property at the date + and the taxpayer meets the use requirements of subsection (a) with respect to the sale or exchange of the property at the date + and the spouse meets the use requirements of subsection (a) with respect to the sale or exchange of the property at the date + and both the taxpayer and the spouse are eligible for the benefits of subsection (a) with respect to the sale or exchange of the property by reason of paragraph 3. + +both a taxpayer and a spouse are eligible for the benefits of subsection (a) with respect to a sale or exchange of a property by reason of paragraph 3 + if subsection (a) shall apply to the sale or exchange of the property by the taxpayer + and subsection (a) shall apply to the sale or exchange of the property by the spouse. +% +% (B) Other joint returns +% +% If such spouses do not meet the requirements of subparagraph (A), +% the limitation under paragraph (1) shall be the sum of the limitations under paragraph (1) +% to which each spouse would be entitled if such spouses had not been married. +% For purposes of the preceding sentence, each spouse shall be treated as +% owning the property during the period that either spouse owned the property. + +% (3) Application to only 1 sale or exchange every 2 years +% +% Subsection (a) shall not apply to any sale or exchange by the taxpayer if, +% during the 2-year period ending on the date of such sale or exchange, +% there was any other sale or exchange by the taxpayer to which subsection (a) applied. + +subsection (a) shall apply to a sale or exchange of a property by a taxpayer + if the sale or exchange of the property occurs at a date + and it is not the case that + an other sale or exchange of the property occurs at a second date + and the other sale or exchange is different from the sale or exchange + and a period of 2 years ends at the date + and the second date is included in the period + and gross income of the taxpayer excludes gain from the other sale or exchange of the property at the second date. + +scenario one is: + the sale of the house occurs at 2022-06-20. + the given period of 5 years ends at 2022-06-20. + first set of periods of the taxpayer owing the house aggregates to 2 of years. + first set of periods is contained in the given period. + second set of periods of the taxpayer using the house as principal residence aggregates to 3 of years. + second set of periods is contained in the given period. + +scenario two is: + the sale of the house occurs at 2022-06-20. + the given period of 5 years ends at 2022-06-20. + the testing period of 2 years ends at 2022-06-20. + the taxpayer is married to the spouse. + first set of periods of the taxpayer owing the house aggregates to 2 of years. + first set of periods is contained in the given period. + second set of periods of the taxpayer using the house as principal residence aggregates to 3 of years. + second set of periods is contained in the given period. + third set of periods of the spouse using the house as principal residence aggregates to 4 of years. + third set of periods is contained in the given period. + +query one is: + gross income of which taxpayer excludes gain from which exchange of which property at which date. + +query two is: + the amount of gain excluded for the taxpayer from which sale under subsection (a) is which amount. + +"). + +/** +?- answer("query one with scenario one"). +?- answer("query two with scenario one"). +?- answer(one, with(one), le(E), R). +?- answer(two, with(one), le(E), R). +?- answer("query two with scenario two"). +?- answer(two, with(two), le(E), R). +*/