Age

Is someone over 80? A calendar question, answered with every day counted.

age.js · output · proof · check · try it in the playground


The question

Pat was born on 21 August 1944. Some benefits, discounts or rules start “after your 80th birthday”. It sounds easy, but calendars have leap years, months of different lengths and birthdays on 29 February, and we want an answer that shows its arithmetic.

On 1 October 2026, is Pat older than 80?


What we tell eyemind

Two facts: a birth date, and the date we ask about. Writing the date down (instead of reading the computer’s clock) means the answer and its proof are the same tomorrow.

fact(birth_date('pat_h', date(1944, 8, 21)))
fact(as_of(date(2026, 10, 1)))

// Without an explicit date, the reference date as_of/1 is used.
implied_by(age_above(Person, Duration), [as_of(Date), age_above(Person, Duration, Date)])

query(age_above(Person, years(80)))

A fact(...) is something we state as true; date(1944, 8, 21) is a date written as year, month, day. Capitalized names such as Person and Date are variables: placeholders for any value.

implied_by(conclusion, premise) is a backward rule, used on demand when a question needs it: a person’s age is above a duration if, on the as_of date, it is above that duration. A premise in square brackets needs all of its parts.

The last line is the question: find every Person whose age is above 80 years.


How the program counts

The rule for “older than N years on a date”, quoted from the program:

implied_by(
  age_above(Person, years(Years), Date),
  [
    is_int(Years),
    ge(Years, 0),
    birth_date(Person, Birth),
    date_day(Birth, Born),
    date_day(Date, Today),
    ge(Today, Born),
    anniversary(Birth, Years, Anniversary),
    date_day(Anniversary, Threshold),
    gt(Today, Threshold),
  ],
)

In words: the number of years must be a whole number, 0 or more; turn the birth date and the date into day numbers; the date must not be before the birth; find the anniversary that many years after the birth; and the date must come strictly after it. is_int, ge (“greater than or equal”) and gt (“greater than”) are built-in tests that eyemind evaluates directly. Strictly: on the 80th birthday itself Pat is exactly 80, not above it.

date_day gives each date its number in the Gregorian calendar, counting 1 January of year 1 as day 1. It adds up:

anniversary adds the years to the birth year, and clips the day to the month’s length (month_days), so a 29 February birthday falls on 28 February in a common year. All arithmetic is exact whole-number arithmetic, written as terms such as add, sub, mul, floordiv (division rounded down), mod (remainder) and min, and worked out by is(Result, calculation).

An invalid date, a reference date before the birth, an unknown person, or a negative or noninteger threshold gives no answer. The program takes reference dates from the input, so the same proof checks on any day.


What eyemind concludes

// Answers: each instance of a query() that holds.
age_above('pat_h', years(80))

Yes: Pat is older than 80 on 1 October 2026.

date day number
21 August 1944, Pat’s birth 709899
21 August 2024, Pat’s 80th birthday 739119
1 October 2026, the reference date 739890

739890 is greater than 739119, so the 80th birthday has passed.


The proof, line by line

eyemind --proof writes down how it reached the answer. This is the complete proof:

// Answers: each instance of a query() that holds.
age_above('pat_h', years(80))

// Certificate: the derived facts and every answer of each call the questions make.
called(age_above(A, years(80)), [age_above('pat_h', years(80))])
called(age_above(B, years(80), date(2026, 10, 1)), [age_above('pat_h', years(80), date(2026, 10, 1))])
called(date_day(date(1944, 8, 21), C), [date_day(date(1944, 8, 21), 709899)])
called(month_days(1944, 8, D), [month_days(1944, 8, 31)])
called(leap_extra(1944, 8, E), [leap_extra(1944, 8, 1)])
called(leap_year(1944), [leap_year(1944)])
called(common_year(1944), [])
called(date_day(date(2026, 10, 1), F), [date_day(date(2026, 10, 1), 739890)])
called(month_days(2026, 10, G), [month_days(2026, 10, 31)])
called(leap_extra(2026, 10, H), [leap_extra(2026, 10, 0)])
called(leap_year(2026), [])
called(common_year(2026), [common_year(2026)])
called(anniversary(date(1944, 8, 21), 80, I), [anniversary(date(1944, 8, 21), 80, date(2024, 8, 21))])
called(month_days(2024, 8, J), [month_days(2024, 8, 31)])
called(date_day(date(2024, 8, 21), K), [date_day(date(2024, 8, 21), 739119)])
called(leap_extra(2024, 8, L), [leap_extra(2024, 8, 1)])
called(leap_year(2024), [leap_year(2024)])
called(common_year(2024), [])

It has two parts:

A proof can also hold step(...) records of how forward rules derived facts, but every rule here is a backward rule, worked out only when asked, so this proof has none. The tests and calculations, such as ge(80, 0) or is(1943, sub(1944, 1)), are not written down either: the checker redoes them itself. Read the 18 tables as sentences:

Rule 4 then compares the day numbers itself: 739890 ≥ 709899, so the date is not before Pat’s birth, and 739890 > 739119, so it is after the 80th birthday. Each distinct call has one table, so the 31 days of August 1944 and 2024 are two tables, while a call made twice is answered from the same one.


Checked: what the report says

A proof is only worth something if someone else can check it. eyemind -c generates the proof and checks it against the program; --check-proof checks a saved proof. The checker never reasons by itself. It answers the question by applying the program’s rules one level at a time, taking the answer of every inner call from its table and redoing every test and calculation. Each table it consults is checked the same way, so a wrong table, such as one claiming 2026 is a leap year, shows up as a disagreement. A table the check does not use fails it too. This is the complete report:

// Checked answers: these follow from the input program and are every answer of its questions.
age_above('pat_h', years(80))

verdict('checked')

The verdict is checked: Pat’s age is above 80 on 1 October 2026, down to the last day, and that is every answer of the original question. Had the proof claimed a wrong answer, or left one out, the report would list each failure(...) and end with verdict(failed(N)).


Try it

eyemind examples/age.js
eyemind --goal "age_above('pat_h', years(80), date(2024, 8, 22))" examples/age.js
eyemind --goal "age_days('pat_h', date(2026, 10, 1), Days)" examples/age.js

The second asks about 22 August 2024, the day after the 80th birthday: it holds. The last one counts days and answers age_days('pat_h', date(2026, 10, 1), 29991): 739890 − 709899.

Or open it in the playground. Change as_of to date(2024, 8, 21), the 80th birthday itself: there is no answer, because on that day Pat is exactly 80, not above 80. Change it to date(2024, 8, 22), one day later, and the answer comes back.


Takeaway

Date arithmetic is where small mistakes hide. Here each day number and each leap-year decision is written down in a call table and rechecked, and each comparison is recomputed, so a “yes” can be audited down to the last day.