简体   繁体   中英

Why is chain of equational reasoning failing to meet trivially solvable constraints?

The following Agda code:

module test where

open import Data.Float

import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; step-≡; _∎)

postulate
  distrib : {m a b : Float} → m * (a + b) ≡ (m * a) + (m * b)

dbg : (m a b : Float) → m * (a + b) ≡ (m * a) + (m * b)
dbg m a b =
  begin
    m * (a + b)
  ≡⟨ distrib ⟩  -- (Line "22")
    (m * a) + (m * b)
  ∎

yields:

_m_18 : Float  [ at /Users/dbanas/Documents/Agda/agda_misc/test.agda:22,6-13 ]
_a_19 : Float  [ at /Users/dbanas/Documents/Agda/agda_misc/test.agda:22,6-13 ]
_b_20 : Float  [ at /Users/dbanas/Documents/Agda/agda_misc/test.agda:22,6-13 ]

———— Errors ————————————————————————————————————————————————
Failed to solve the following constraints:
  (_m_18 * _a_19) + (_m_18 * _b_20) = (m * a) + (m * b) : Float
  _m_18 * (_a_19 + _b_20) = m * (a + b) : Float

after I type Cc Cl .
( Note: "22,6-13" identifies the second occurrence of the word "distrib".)

I don't understand why the constraints can't be met. They seem trivially solvable:

_m_18 = m
_a_19 = a
_b_20 = b

While those solutions are correct, they're not inevitable, because multiplication and addition are not injective. In this case, you can fill in just m in line 22, ie distrib {m = m} .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM