Skip to content

Commit

Permalink
Extends example 121 with scenario with a spouse
Browse files Browse the repository at this point in the history
  • Loading branch information
jacintodavila committed Jun 22, 2022
1 parent e8ac0d2 commit 525fa36
Show file tree
Hide file tree
Showing 5 changed files with 490 additions and 86 deletions.
132 changes: 78 additions & 54 deletions kb/tax121.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -29,18 +33,29 @@
% such property has been owned and used by the taxpayer as
% the taxpayers 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
Expand All @@ -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.

Expand All @@ -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
%
Expand All @@ -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.

").

Expand All @@ -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).
*/
Loading

0 comments on commit 525fa36

Please sign in to comment.