I have this recursive function I am trying to define by way of Fixpoint, but the if condition is giving me trouble.
Require Import Arith.
Variables Cd : nat -> nat -> Prop.
Variables T : nat -> nat.
Fixpoint delay (t:nat) {struct t} : nat :=
match t with
| 0 => 0
| S t => if ((T (S t)) = 0 /\ ((Cd ((S t) + (delay t) + 1 mod 2)) (S t))) then (delay t) + 1 else (delay t)
end.
Coq complains that the if condition is of type Prop and not a coinductive type. I am not really sure what problem it is trying to tell me.
What I currently have instead is two hypotheses:
Hypothesis delay_def1 : forall t: nat, ((T (S t)) = 0 /\ ((Cd ((S t) + (delay t) + 1 mod 2)) (S t))) -> (delay (S t)) = (delay t) + 1.
Hypothesis delay_def2 : forall t: nat, ~((T (S t)) = 0 /\ ((Cd ((S t) + (delay t) + 1 mod 2)) (S t))) -> (delay (S t)) = (delay t).
More context to give a better idea of the problem I am working on. This is a hobby project to learn Coq where I am trying to prove certain properties of a selection function for weapons inside a game.
There are six sequences in total that depend on each other:
Require Import Arith.
Require Import Coq.Logic.Classical.
Require Import Coq.Arith.PeanoNat.
Require Import Coq.Structures.OrdersFacts.
Variables ATK0 Sd0 : Prop.
Variables Sel0 : nat -> Prop.
Variables Cd : nat -> nat -> Prop.
Variables T delay : nat -> nat.
Definition Sel (x t:nat): Prop :=
match t with
| 0 => (Sel0 x)
| (S t) => ~(((T (S t)) = 2 /\ ~((Cd x) (S t)))
\/ ((T (S t)) = 0 /\ ((Cd (1 - x)) (S t)) /\ ((Cd x) (S t)))
) /\ ((S t) + (delay t)) mod 2 = x
end.
Definition ATK (t:nat) : Prop :=
match t with
| 0 => ATK0
| S t => exists x: nat, ((Sel x) t) /\ ~ ((Cd x) t)
end.
Fixpoint Sd (t:nat) : Prop :=
match t with
| 0 => (ATK t) \/ ((T t) > 0 /\ Sd0)
| (S t) => (ATK (S t)) \/ ((T t) > 0 /\ (Sd t))
end.
Hypothesis T_def1 : forall t : nat, (T t) = 2 \/ ((T t) = 0 /\ (Sd t)) -> (T (S t)) = 0.
Hypothesis T_def2 : forall t : nat, ~((T t) = 2 \/ ((T t) = 0 /\ (Sd t))) -> (T (S t)) = (S (T t)).
Hypothesis T_lt_3: forall t : nat, (lt (T t) 3).
Hypothesis Cd_def1 : forall t x : nat, ((Sel x) t) /\ ~((Cd x) t) -> ((Cd x) (S t)).
Hypothesis Cd_def2 : forall t x : nat, ((Sel x) t) /\ ((Cd x) t) -> ~((Cd x) (S t)).
Hypothesis Cd_def3 : forall t x : nat, ~((Sel x) t) -> (((Cd x) (S t)) <-> ((Cd x) t)).
Hypothesis delay_def1 : forall t: nat, ((T (S t)) = 0 /\ ((Cd ((S t) + (delay t) + 1 mod 2)) (S t))) -> (delay (S t)) = (delay t) + 1.
Hypothesis delay_def2 : forall t: nat, ~((T (S t)) = 0 /\ ((Cd ((S t) + (delay t) + 1 mod 2)) (S t))) -> (delay (S t)) = (delay t).
ATK t
is shorthand for whether an attack happened at timet
. AProp
Sel x t
is whether Weapon x is selected at timet
. AProp
Cd x t
is whether Weapon x is on cooldown at timet
. AProp
delay t
: On a basic level,Sel
just switches back and forth between two weapons. In some cases I skip a frame, in which case delay is incremented so it changes which weapon comes next.Sd t
Attacks influence the length of the cycle of T in a certain way that is captured by Sd. Sd is carried over between frames until T=0, at which point it is reset.T t
captures a certain cycle in the game that essentially is a squence0 1 2 0 0 1 2 0 0 ...
I was already able to prove two Lemmas, for one of which I had a proof on paper before I started.
Lemma only_2_weapons : forall t x : nat, t > 0 /\ ((Sel x) t) -> x < 2.
Lemma no_ATK_on_first_draw : forall t : nat, t > 0 /\ (T (t)) = 2 -> ~(ATK (S t)).
And the end goal is to prove or disprove
Theorem no_ATK_on_draw : forall t: nat, ((T t) = 0 /\ (ATK t)) -> forall t1: nat, ((t1 > t /\ (T t1) = 0) -> ~(ATK t1)).
The goal of my questions regarding Fixpoint, Definition etc. is to make the proof as smooth as possible. I started by defining all the sequences as Hypotheses.
Cd
andT
are given as variables (if their content does not influence the question) or defined (if it does). $\endgroup$mod
come from? (You probably want to add an import) $\endgroup$x + 1 mod 2
is equal tox + (1 mod 2) = x + 1
? $\endgroup$