-
Notifications
You must be signed in to change notification settings - Fork 14
/
cardan_ferrari.v
1166 lines (987 loc) · 24 KB
/
cardan_ferrari.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(*
MIT License
Copyright (c) 2017-2020 Frédéric Chardard, Institut Camille Jordan /
Université Jean Monnet de Saint-Etienne
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*)
(*
This file contains:
_A construction of a nth-root of complex numbers.
_A construction of a cubic root on C such that if the argument is real,
then the result is also real.
_A proof that Cardan-Tartaglia formula solves the general cubic equation
in the field of complex numbers.
__A proof that Ferrari method solves the general quartic equation in the
field of complex numbers.
This file was checked by Coq without error with following configuration:
base-bigarray base
base-threads base
base-unix base
cairo2 0.6.1 Binding to Cairo, a 2D Vector Graphics Library
conf-cairo 1 Virtual package relying on a Cairo system installation
conf-findutils 1 Virtual package relying on findutils
conf-g++ 1.0 Virtual package relying on the g++ compiler (for C++)
conf-gnome-icon-theme3 0 Virtual package relying on gnome-icon-theme
conf-gtk3 18 Virtual package relying on GTK+ 3
conf-gtksourceview3 0+2 Virtual package relying on a GtkSourceView-3 system installation
conf-m4 1 Virtual package relying on m4
conf-pkg-config 1.3 Virtual package relying on pkg-config installation
coq 8.12.0 Formal proof management system
coq-coquelicot 3.1.0 A Coq formalization of real analysis compatible with the standard library
coq-mathcomp-ssreflect 1.11.0 Small Scale Reflection
coqide 8.12.0 IDE of the Coq formal proof management system
dune 2.7.0 Fast, portable, and opinionated build system
dune-configurator 2.7.0 Helper library for gathering system configuration
lablgtk3 3.1.1 OCaml interface to GTK+3
lablgtk3-sourceview3 3.1.1 OCaml interface to GTK+ gtksourceview library
num 1.3 The legacy Num library for arbitrary-precision integer and rational arithmetic
ocaml 4.08.1 The OCaml compiler (virtual package)
ocaml-config 1 OCaml Switch Configuration
ocaml-system 4.08.1 The OCaml compiler (system version, from outside of opam)
ocamlfind 1.8.1 A library manager for OCaml
on Linux empmeticj012 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
(Ubuntu 20.04.1 LTS)
with OPAM 2.0.5.
*)
Require Import Reals Coq.Reals.Rtrigo_def Coquelicot.Coquelicot Coquelicot.ElemFct Lra.
Open Scope R_scope.
Ltac Rsimpl:=
repeat (
try rewrite Ropp_involutive;
try rewrite Ropp_0;
try rewrite Rplus_opp_l;
try rewrite Rplus_opp_r;
try rewrite Rplus_0_l;
try rewrite Rplus_0_r;
try rewrite Rmult_1_l;
try rewrite Rmult_1_r;
try rewrite Rmult_0_l;
try rewrite Rmult_0_r
).
Ltac Csimpl:=
repeat (
try rewrite Copp_0;
try rewrite Cplus_opp_r;
try rewrite Cplus_0_l;
try rewrite Cplus_0_r;
try rewrite Cmult_0_r;
try rewrite Cmult_1_r;
try rewrite Cmult_0_l;
try rewrite Cmult_1_l).
Lemma contraposition_neg : forall P Q:Prop, ( P -> Q ) -> ( (~Q) -> (~P)).
intros P Q hyp negQ vP.
apply negQ.
apply hyp.
assumption.
Qed.
Lemma f_notequal : forall A B:Type,forall f : (A->B), forall x y :A, f x<>f y -> x<>y.
intros A B f x y.
apply contraposition_neg.
apply f_equal.
Qed.
Lemma Rlt_neq: forall x:R, forall y:R, x<y -> y<>x.
intros x y ineq.
apply not_eq_sym.
apply Rlt_not_eq.
assumption.
Qed.
Lemma Reqdec : forall x:R, {x=0} + {x<>0}.
intros.
induction (total_order_T x 0) as [xneg|xspos].
induction xneg as [xsneg|x0].
right.
apply not_eq_sym.
apply Rlt_neq.
assumption.
left.
assumption.
right.
apply Rlt_neq.
assumption.
Qed.
Lemma normpos : forall x:R, forall y:R, 0<=x^2+y^2.
intros.
apply Rplus_le_le_0_compat;
apply pow2_ge_0.
Qed.
Lemma normspos : forall x:R, forall y:R, x<>0 -> 0<x^2+y^2.
intros.
do 2 rewrite<-Rsqr_pow2.
apply Rplus_lt_le_0_compat.
apply Rsqr_pos_lt.
assumption.
apply Rle_0_sqr.
Qed.
Lemma coordnorm : forall x:R, forall y:R, y<>0 -> -x<sqrt(x^2+y^2).
intros.
apply (Rle_lt_trans _ (Rabs x)).
rewrite<-Rabs_Ropp.
apply Rle_abs.
rewrite<-sqrt_Rsqr_abs.
apply sqrt_lt_1_alt.
split.
apply Rle_0_sqr.
repeat rewrite<-Rsqr_pow2.
apply Rminus_gt.
unfold Rminus.
rewrite Rplus_comm.
rewrite<-Rplus_assoc.
Rsimpl.
apply Rlt_0_sqr.
assumption.
Qed.
Lemma coordnormb : forall x:R, forall y:R, y<>0 -> 0<sqrt(x^2+y^2)+x.
intros.
rewrite<-(Ropp_involutive x) at 2.
apply Rlt_Rminus.
apply coordnorm.
assumption.
Qed.
Ltac Cfequal:=
repeat unfold RtoC,Cminus,Cplus,Copp,Cmult,Cdiv,Cinv,Re,Im,fst,snd.
Lemma cosatanspos : forall x:R, cos(atan x)>0.
intro.
apply cos_gt_0.
rewrite<-Ropp_div.
apply (proj1 (atan_bound _)).
apply (proj2 (atan_bound _)).
Qed.
Lemma cosatan : forall x:R, Rsqr (cos(atan x))=(/(1+Rsqr x))%R.
intro.
rewrite<-(atan_right_inv x) at 2.
unfold tan.
rewrite Rsqr_div.
rewrite sin2.
unfold Rsqr.
field.
split.
apply (Rlt_neq _ _ (cosatanspos _)).
unfold Rminus.
rewrite Rplus_comm.
rewrite Rplus_assoc.
Rsimpl.
apply R1_neq_R0.
apply (Rlt_neq _ _ (cosatanspos _)).
Qed.
Open Scope C_scope.
Fixpoint Cpow (r : C) (n : nat) {struct n} : C := match n with
| 0%nat => 1
| S n0 => (r * Cpow r n0)%C
end.
Theorem moivre : forall n:nat, forall x:R,
Cpow (cos x,sin x) n=(cos ((INR n)*x), sin ((INR n)*x))%C.
induction n.
unfold Cpow,INR.
intros.
Rsimpl.
rewrite cos_0.
rewrite sin_0.
reflexivity.
intro.
rewrite S_INR.
rewrite Rmult_plus_distr_r.
rewrite Rmult_1_l.
rewrite cos_plus.
rewrite sin_plus.
unfold Cpow.
fold Cpow.
rewrite IHn.
Cfequal.
f_equal;
field.
Qed.
Definition Rneg_or_not : forall z:C,
{0<Re z} + {Im z<>0} +{Im z=0 /\ Re z<=0}.
intros.
destruct z as (u,v).
unfold Im,Re,fst,snd.
unfold Rle.
destruct (total_order_T u 0) as [uneg|uspos];
try destruct uneg as [usneg|u0];
destruct (Reqdec v) as [veq0|vneq0];
auto.
Qed.
Definition Csqrt:=fun (z:C) =>
let (u,v):=z in
let a:=(sqrt(((Cmod z)+u)/2))%R in
let b:=(if (Rneg_or_not z)
then v/2/a
else sqrt(-u))%R in
(a,b)%C : C.
Lemma Csqrt_Cpow2 : forall z: C, (Csqrt z)*(Csqrt z)=z.
intro.
unfold Cmult.
pose (fst (Csqrt z)) as u.
pose (snd (Csqrt z)) as v.
fold u.
fold v.
fold (Rsqr u).
fold (Rsqr v).
induction z as (x,y).
rewrite Rmult_comm.
rewrite<-double.
unfold Csqrt,Re,Im,snd,fst in u,v.
fold u in v.
destruct Rneg_or_not as [znotneg|zneg].
unfold Im,Re,fst,snd in *.
assert(0<(Cmod(x,y)+x)%R) as nspos.
unfold Cmod,fst,snd.
destruct znotneg as [xspos|ynot0].
apply Rplus_le_lt_0_compat.
apply sqrt_pos.
assumption.
apply coordnormb.
assumption.
assert(0<u) as uspos.
unfold u.
apply sqrt_lt_R0.
apply Rdiv_lt_0_compat.
assumption.
apply Rlt_0_2.
pose proof (Rlt_neq _ _ uspos) as uneq0.
unfold v.
f_equal.
rewrite Rsqr_div.
rewrite<-(Rdiv_1 (Rsqr u)) at 1.
rewrite Rdiv_minus.
fold (Rsqr (Rsqr u)).
unfold u.
rewrite Rsqr_sqrt.
rewrite Rsqr_div.
rewrite Rsqr_plus.
unfold Cmod at 1.
unfold fst,snd.
rewrite Rsqr_sqrt.
unfold Rsqr.
field.
apply Rlt_neq.
assumption.
apply normpos.
apply Rlt_neq.
apply Rlt_0_2.
left.
apply Rdiv_lt_0_compat.
assumption.
apply Rlt_0_2.
apply R1_neq_R0.
apply Rlt_neq.
apply Rlt_0_sqr.
assumption.
assumption.
field.
assumption.
unfold Re,Im,fst,snd in *.
unfold u,v.
destruct zneg as [yeq0 xneg].
rewrite yeq0.
fold (RtoC x).
rewrite (Cmod_R x).
rewrite Rabs_left1.
unfold Rdiv.
Rsimpl.
rewrite sqrt_0.
Rsimpl.
rewrite Rsqr_sqrt.
unfold Rminus,Rsqr.
Rsimpl.
reflexivity.
rewrite<-Ropp_0.
apply Ropp_le_contravar.
assumption.
assumption.
Qed.
Definition cargument (z: C) : R :=
if (Rneg_or_not z) then (INR 2)*atan((Im (Csqrt z))/(Re (Csqrt z)))
else PI.
Lemma trigoform: forall z : C,
z=(cos(cargument z),sin(cargument z))*(Cmod z,0).
intro.
unfold cargument.
induction Rneg_or_not as [znotneg|zneg].
pose proof (Csqrt_Cpow2 z) as z2.
induction (Csqrt z) as (u,v).
assert (Cmod z<>0%R) as zmodnot0.
intro mz0.
pose proof (Cmod_eq_0 z mz0) as z0.
rewrite z0 in znotneg.
unfold Re,Im,fst,snd,RtoC in znotneg.
destruct znotneg as [rezspos|imzneq0].
apply (Rlt_neq _ _ rezspos).
reflexivity.
apply imzneq0.
reflexivity.
assert(u<>0) as uneq0.
intro ueq0.
rewrite ueq0 in z2.
unfold Cmult,fst,snd in z2.
repeat rewrite Rmult_0_r in z2.
repeat rewrite Rmult_0_l in z2.
unfold Rminus in z2.
repeat rewrite Rplus_0_l in z2.
rewrite<-z2 in znotneg.
unfold Re,Im,fst,snd in znotneg.
destruct znotneg as [sqrneg|neq00].
apply (Rlt_not_ge (Rsqr v) 0).
unfold Rsqr.
apply Ropp_lt_cancel.
rewrite Ropp_0.
assumption.
apply Rle_ge.
apply Rle_0_sqr.
apply neq00.
reflexivity.
assert( forall x:R, (x*x)%R =(Rsqr x)%R) as multsqr.
unfold Rsqr.
reflexivity.
rewrite<-z2.
unfold Im,Re,fst,snd.
rewrite z2 at 2.
unfold Cmult,Re,Im,fst,snd.
Rsimpl.
rewrite cos_2a.
repeat rewrite multsqr.
rewrite sin2.
assert( forall x:R, cos(x)<>0 -> (sin((INR 2) * x))%R =(2*(tan x)*(Rsqr (cos x)))%R) as sineq.
intros.
unfold tan,Rsqr.
rewrite sin_2a.
field.
assumption.
rewrite sineq.
rewrite cosatan.
rewrite atan_right_inv.
assert(Cmod z=(u*u+v*v)%R) as modz.
rewrite<-z2.
rewrite Cmod_mult.
repeat rewrite multsqr.
unfold Cmod,fst,snd.
rewrite Rsqr_sqrt.
repeat rewrite Rsqr_pow2.
reflexivity.
apply normpos.
rewrite modz.
unfold Rsqr.
rewrite modz in zmodnot0.
f_equal;
field;
split;
assumption.
apply Rlt_neq.
apply cosatanspos.
rewrite cos_PI.
rewrite sin_PI.
unfold Cmult,fst,snd.
destruct z as (u,v).
unfold Im,snd,Re,fst,Rminus in zneg.
rewrite (proj1 zneg).
fold (RtoC u).
rewrite Cmod_R.
unfold Rminus,RtoC.
Rsimpl.
rewrite Rabs_left1.
f_equal.
field.
apply (proj2 zneg).
Qed.
Lemma factorisationdeg3 : forall z1 z2 z3:C, forall z:C,
(z-z1)*(z-z2)*(z-z3)=Cpow z 3+(-(z1+z2+z3))*Cpow z 2+(z1*z2+z2*z3+z3*z1)*z+(-(z1*z2*z3)).
intros.
unfold Cpow.
field.
Qed.
Theorem Cpowexp : forall n:nat, forall x:R, ((exp(x))^n=exp((INR n)*x)) % R.
induction n.
unfold INR.
intro.
rewrite Rmult_0_l.
rewrite exp_0.
rewrite pow_O.
reflexivity.
intros.
rewrite<-tech_pow_Rmult.
rewrite S_INR.
rewrite Rmult_plus_distr_r.
rewrite Rmult_1_l.
rewrite exp_plus.
rewrite IHn.
field.
Qed.
Theorem comCpow: forall n : nat, forall z:C, forall u:C, (Cpow (z*u)%C n)=((Cpow z n)*(Cpow u n))%C.
induction n.
intros.
unfold Cpow.
Cfequal.
f_equal;
field.
intros.
unfold Cpow.
fold Cpow.
rewrite IHn.
field.
Qed.
Lemma RCpow : forall n:nat,forall x:R, Cpow (x,0)%C n = ((x^n)%R,0)%C.
induction n.
intro.
unfold Cpow.
rewrite pow_O.
reflexivity.
intro.
rewrite<-tech_pow_Rmult.
unfold Cpow at 1.
fold Cpow.
rewrite IHn.
Cfequal.
unfold Rminus.
Rsimpl.
reflexivity.
Qed.
Definition nroot (n:nat) (z:C) : C:=
if Ceq_dec z 0 then 0
else let argn:=((cargument z)/(INR n))%R in
(cos(argn),sin(argn))*(exp((ln (Cmod z))/(INR n)),0).
Theorem nroot_Cpown : forall n:nat,forall z:C,n<>O-> Cpow (nroot n z) n=z.
intros n z nneq0.
unfold nroot.
induction (Ceq_dec z 0) as [zeq0|zneq0].
rewrite zeq0.
unfold Cpow.
induction n.
contradiction nneq0.
reflexivity.
apply Cmult_0_l.
rewrite comCpow.
rewrite moivre.
rewrite (RCpow n).
rewrite Cpowexp.
rewrite (trigoform z) at 4.
unfold Rdiv.
repeat rewrite<-Rmult_assoc.
repeat rewrite Rinv_r_simpl_m.
rewrite exp_ln.
reflexivity.
apply Cmod_gt_0.
assumption.
apply not_0_INR.
assumption.
apply not_0_INR.
assumption.
Qed.
Lemma nrootpositive : forall x:R, forall n:nat, 0<=x -> Im( nroot n x ) =0%R.
intros.
unfold nroot.
induction(Ceq_dec x 0) as [xeq0|xneq0].
unfold RtoC,Im,snd.
reflexivity.
unfold Im,Re,Cmult,fst,snd.
Rsimpl.
apply Rmult_eq_0_compat_r.
rewrite<-sin_0.
f_equal.
unfold Rdiv.
apply Rmult_eq_0_compat_r.
unfold cargument,Csqrt.
rewrite Cmod_R.
unfold Rabs,Re,Im,RtoC,fst,snd.
destruct Rcase_abs as [xneg|xpos].
lra.
unfold Rdiv.
rewrite<-double.
unfold Rdiv.
destruct Rneg_or_not as [vra|fal].
repeat rewrite Rmult_0_l.
rewrite atan_0.
apply Rmult_0_r.
exfalso.
unfold Re,Im,fst,snd in fal.
destruct fal.
apply xneq0.
f_equal.
apply Rle_antisym;
assumption.
Qed.
Definition cubicroot (z:C) := if(Rcase_abs (Re z)) then -nroot 3 (-z) else nroot 3 z.
Lemma cubicroot3 : forall z:C, Cpow (cubicroot z) 3=z.
intro.
unfold cubicroot.
induction (Rcase_abs (Re z)).
transitivity (-Cpow (nroot 3 (-z)) 3).
unfold Cpow.
field.
rewrite nroot_Cpown.
field.
discriminate.
apply nroot_Cpown.
discriminate.
Qed.
Lemma cubicrootreal : forall (x:R), 0%R=Im (cubicroot x).
intro.
unfold cubicroot.
destruct Rcase_abs as [xneg|xpos].
transitivity (-Im(nroot 3 (-x)%R))%R.
rewrite nrootpositive.
rewrite Ropp_0.
reflexivity.
unfold RtoC,Re,fst in xneg.
lra.
repeat unfold RtoC,Im,fst,snd,Copp.
rewrite Ropp_0.
reflexivity.
symmetry.
apply nrootpositive.
unfold Re,RtoC,fst in xpos.
apply Rge_le.
assumption.
Qed.
Definition CJ := ((-/2)%R,(sqrt (3/4))%R)%C.
Lemma CJ2: CJ*CJ=-CJ-1.
unfold CJ.
Cfequal.
fold (Rsqr (sqrt (3/4))).
rewrite Rsqr_sqrt.
f_equal;
field.
lra.
Qed.
Lemma CJ3 : CJ*CJ*CJ=1%C.
rewrite CJ2.
transitivity (-(CJ*CJ)-CJ).
unfold Cpow.
field.
rewrite CJ2.
field.
Qed.
Lemma Cval2 : RtoC 2=RtoC 1+RtoC 1.
unfold Cplus,fst,snd,RtoC.
f_equal;
field.
Qed.
Lemma Cval3 : RtoC 3=RtoC 1+RtoC 1+RtoC 1.
unfold Cplus,fst,snd,RtoC.
f_equal;
field.
Qed.
Lemma Cval4: (RtoC 4=(RtoC 1+RtoC 1)*(RtoC 1+RtoC 1)).
unfold Cplus,Cmult,fst,snd,RtoC.
f_equal;
field.
Qed.
Lemma Cval6 : RtoC 6=(RtoC 1+RtoC 1+RtoC 1)*(RtoC 1+RtoC 1).
unfold Cmult,Cplus,fst,snd,RtoC.
f_equal;
field.
Qed.
Lemma Cval8 : RtoC 8=(RtoC 1+RtoC 1)*(RtoC 1+RtoC 1)*(RtoC 1+RtoC 1).
unfold Cmult,Cplus,fst,snd,RtoC.
f_equal;
field.
Qed.
Lemma shiftdeg3 : forall u:C, forall a b c:C, forall z:C,
Cpow (z+u) 3+a*Cpow (z+u) 2+b*(z+u)+c
=Cpow z 3+(a+3*u)*Cpow z 2+(b+2*u*a+3*Cpow u 2)*z+(c+b*u+a*Cpow u 2+Cpow u 3).
intros.
unfold Cpow.
rewrite Cval3.
rewrite Cval2.
field.
Qed.
Lemma permprod: forall e f g:C, g*f*e=e*g*f.
intros e f g.
rewrite Cmult_comm.
rewrite Cmult_assoc.
reflexivity.
Qed.
Ltac nneq0:=unfold RtoC;
injection;
intro;
lra.
Ltac developall:=
unfold Cpow;
repeat (try Csimpl;
try rewrite Cmult_plus_distr_r;
try rewrite Cmult_plus_distr_l);
repeat (
repeat rewrite (permprod CJ);
repeat rewrite Cmult_assoc).
Definition Cardan_Tartaglia_formula:=fun (a1:C) (a2:C) (a3:C) (n:nat) =>
let s:=-a1/3 in
let p:=a2+2*s*a1+3*Cpow s 2 in
let q:=a3+a2*s+a1*Cpow s 2+Cpow s 3 in
let Delta:=(Cpow (q/2) 2)+(Cpow (p/3) 3) in
let alpha : C :=if(Ceq_dec p 0) then (RtoC 0) else (cubicroot (-(q/2)+Csqrt Delta)) in
let beta:=if(Ceq_dec p 0) then -cubicroot q else -(p/3)/alpha in
s+(alpha*Cpow CJ n+beta*Cpow CJ (n+n)).
Theorem Cardan_Tartaglia : forall a1 a2 a3 :C,
let u1:=(Cardan_Tartaglia_formula a1 a2 a3 0) in
let u2:=(Cardan_Tartaglia_formula a1 a2 a3 1) in
let u3:=(Cardan_Tartaglia_formula a1 a2 a3 2) in
forall u:C, (u-u1)*(u-u2)*(u-u3)=Cpow u 3+a1*Cpow u 2+a2*u+a3.
intros.
pose (-a1/3) as s.
pose (a2+2*s*a1+3*Cpow s 2) as p.
pose (a3+a2*s+a1*Cpow s 2+Cpow s 3) as q.
pose ((Cpow (q/2) 2)+(Cpow (p/3) 3)) as Delta.
pose (if(Ceq_dec p 0) then (RtoC 0) else (cubicroot (-(q/2)+Csqrt Delta)))%C as alpha.
pose (if(Ceq_dec p 0) then -cubicroot q else -(p/3)/alpha) as beta.
pose (alpha+beta) as z1.
pose (alpha*CJ+beta*Cpow CJ 2) as z2.
pose (alpha*Cpow CJ 2+beta*CJ) as z3.
assert(u1=s+z1 /\ u2=s+z2 /\ u3=s+z3) as uv.
unfold u1,z1,u2,z2,u3,z3,Cardan_Tartaglia_formula.
fold s p q Delta alpha beta.
unfold Nat.add,Cpow.
repeat rewrite Cmult_1_r.
pose proof CJ3 as CJ3b.
rewrite<-Cmult_assoc in CJ3b.
rewrite CJ3b.
rewrite Cmult_1_r.
repeat split;reflexivity.
destruct uv as [uv1 uv2].
destruct uv2 as [uv2 uv3].
rewrite uv1.
rewrite uv2.
rewrite uv3.
assert(RtoC 1<>RtoC 0) as neq0_1 by nneq0.
assert(RtoC 2<>RtoC 0) as neq0_2 by nneq0.
assert(RtoC 3<>RtoC 0) as neq0_3 by nneq0.
assert(forall z0:C, z0<>0 -> /z0 <> 0) as invnot0.
intros z0 z0neq0.
pose proof (Cinv_r z0 z0neq0) as prodz0.
intro z0eq0.
rewrite z0eq0 in prodz0.
rewrite Cmult_0_r in prodz0.
apply neq0_1.
rewrite prodz0.
reflexivity.
assert(forall f g h:C, f+g-(g+h)=f-h) as mincancel.
intros.
field.
intros.
pose (z:=u-s).
assert(u=z+s) as Hszu.
unfold z.
field.
rewrite Hszu.
rewrite (shiftdeg3 s).
fold p.
fold q.
unfold s at 7.
rewrite (Cmult_comm 3).
unfold Cdiv.
rewrite<-(Cmult_assoc _ _ 3).
rewrite (Cinv_l _ neq0_3).
Csimpl.
repeat rewrite mincancel.
rewrite factorisationdeg3.
destruct (Ceq_dec p 0) as [peq0|pneq0].
unfold Cpow in z2,z3.
unfold z1,z2,z3,alpha.
Csimpl.
f_equal.
f_equal.
rewrite CJ2.
field.
f_equal.
rewrite peq0.
developall.
rewrite CJ3.
rewrite CJ2.
field.
developall.
rewrite CJ3.
rewrite<-(cubicroot3 q).
unfold beta.
unfold Cpow.
field.
assert((Cpow alpha 3)<>0) as alpha3neq0.
unfold alpha.
rewrite cubicroot3.
apply( (f_notequal _ _ (fun z => (q/2)+z) )).
rewrite Cplus_assoc.
Csimpl.
apply( (f_notequal _ _ (fun z => Cpow z 2) )).
unfold Cpow at 1.
rewrite Cmult_1_r.
rewrite Csqrt_Cpow2.
unfold Delta.
rewrite Cplus_comm.
apply( (f_notequal _ _ (fun z => (z+-Cpow (q/2) 2)) )).
rewrite<-Cplus_assoc.
Csimpl.
unfold Cpow.
repeat apply Cmult_neq_0;
try apply invnot0;
try assumption.
assert (alpha<>0) as alphaneq0.
apply( (f_notequal _ _ (fun z => Cpow z 3))).
unfold Cpow at 2.
repeat rewrite Cmult_0_l.
assumption.
f_equal.
f_equal.
f_equal.
replace (z1+z2+z3) with (RtoC 0).
Csimpl.
reflexivity.
unfold z1,z2,z3.
unfold Cpow.
developall.
rewrite CJ2.
field.
f_equal.
unfold z1,z2,z3.
unfold Cpow.
developall.
rewrite CJ3.
repeat rewrite Cmult_1_l.
rewrite CJ2.
unfold Cminus.
developall.
transitivity(-(3*alpha*beta)).
rewrite Cval3.
field.
unfold beta.
field; try (split; [ nneq0 | ]).
assumption.
unfold z1,z2,z3.
developall.
rewrite CJ3.
rewrite CJ2.
developall.
transitivity(-(Cpow alpha 3+Cpow beta 3)).
unfold Cpow.
field.
transitivity(--q).
f_equal.
rewrite<-Cmult_1_r at 1.
rewrite<-Cmult_1_r.
rewrite<-(Cinv_r (Cpow alpha 3)).
repeat rewrite Cmult_assoc.
f_equal.
rewrite Cmult_plus_distr_r.
rewrite<-(comCpow _ beta alpha).
unfold beta.
unfold Cdiv.
rewrite<-Cmult_assoc.
rewrite Cinv_l.
fold (Cdiv p 3).
unfold alpha.
rewrite cubicroot3.
developall.
rewrite Csqrt_Cpow2.
generalize (Csqrt Delta).
intro.
unfold Delta,Cpow.
rewrite Cval2.
field; split; nneq0.
assumption.
assumption.
field.
Qed.
Lemma shiftdeg4 : forall u:C, forall a b c d:C, forall z:C,
Cpow (z+u) 4+a*Cpow (z+u) 3+b*Cpow (z+u) 2+c*(z+u)+d
=Cpow z 4+(a+4*u)*Cpow z 3+(b+3*u*a+6*Cpow u 2)*Cpow z 2
+(c+2*b*u+3*a*Cpow u 2+4*Cpow u 3)*z+(d+c*u+b*Cpow u 2+a*Cpow u 3+Cpow u 4).
intros.
unfold Cpow.
rewrite Cval6.
rewrite Cval4.
rewrite Cval3.
rewrite Cval2.
field.
Qed.
Definition binom_solution:= fun (b:C) (c:C) (n:nat) =>
-b/2+(Csqrt (Cpow (b/2) 2-c))*Cpow (-1) n.
Lemma Binom_solution_proof : forall (b:C) (c:C), forall z:C,
Cpow z 2+b*z+c=(z-binom_solution b c 0)*(z-binom_solution b c 1).
intros.
transitivity (Cpow z 2+-(binom_solution b c 0+binom_solution b c 1)*z
+(binom_solution b c 0)*(binom_solution b c 1)).
unfold binom_solution.
unfold Cpow.
f_equal.
f_equal.
f_equal.
repeat rewrite Cmult_1_r.
assert(forall (f:C) (g:C), (f+g)+(f+g*(-1))=f+f) as aux1.
intros.
destruct f,g.
unfold RtoC,Cmult,Copp,Cplus,fst,snd.
f_equal;field.
rewrite aux1.
rewrite Cval2.
field; nneq0.
repeat rewrite Cmult_1_r.
assert(forall u v :C, (u+v)*(u+v*-1)=u*u-v*v) as diffsq.
intros.
destruct u,v.
unfold RtoC,Cminus,Cmult,Copp,Cplus,fst,snd.
f_equal;field.
rewrite diffsq.
rewrite Csqrt_Cpow2.
field; nneq0.
unfold Cpow.
field.
Qed.