P-Adic numbers, basic: Difference between revisions

m
syntax highlighting fixup automation
(→‎{{header|Wren}}: Now uses new core library method.)
m (syntax highlighting fixup automation)
Line 52:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">
' ***********************************************
'subject: convert two rationals to p-adic numbers,
Line 413:
 
system
</syntaxhighlight>
</lang>
{{out|Examples}}
<pre>
Line 600:
=={{header|Go}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 929:
fmt.Println()
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,101:
p-Adic arithmetics and conversion between rationals is implemented as instances of <code>Eq</code>, <code>Num</code>, <code>Fractional</code> and <code>Real</code> classes, so, they could be treated as usual real numbers (up to existence of some rationals for non-prime bases).
 
<langsyntaxhighlight lang="haskell">{-# LANGUAGE KindSignatures, DataKinds #-}
module Padic where
 
Line 1,316:
let m = (x*r) `mod` p
_:zs = subMod p (x:xs) (mulMod p [m] (b:bs))
in m : go zs</langsyntaxhighlight>
 
Convertation between rationals and p-adic numbers
Line 1,364:
Uses the Nemo abstract algebra library. The Nemo library's rational reconstruction function gives up quite easily,
so another alternative to FreeBasic's crat() using vector products is below.
<langsyntaxhighlight Julialang="julia">using Nemo, LinearAlgebra
 
set_printing_mode(FlintPadicField, :terse)
Line 1,426:
println(a, "\n", dstring(a), "\n", b, "\n", dstring(b), "\n+ =\n", c, "\n", dstring(c), " $r\n")
end
</langsyntaxhighlight>{{out}}
<pre>
2 + O(2^5)
Line 1,576:
{{trans|Go}}
Translation of Go with some modifications, especially using exceptions when an error is encountered.
<langsyntaxhighlight Nimlang="nim">import math, strformat
 
const
Line 1,801:
echo ""
except PadicError:
echo getCurrentExceptionMsg()</langsyntaxhighlight>
 
{{out}}
Line 1,967:
=={{header|Phix}}==
{{libheader|Phix/Class}}
<langsyntaxhighlight Phixlang="phix">// constants
constant EMX = 64 // exponent maximum (if indexing starts at -EMX)
constant DMX = 1e5 // approximation loop maximum
Line 2,234:
end if
printf(1,"\n")
end for</langsyntaxhighlight>
{{out}}
<pre>
Line 2,259:
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line># 20210225 Raku programming solution
 
#!/usr/bin/env raku
Line 2,353:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,364:
{{trans|FreeBASIC}}
{{libheader|Wren-dynamic}}
<langsyntaxhighlight lang="ecmascript">import "/dynamic" for Struct
 
// constants
Line 2,637:
}
System.print()
}</langsyntaxhighlight>
 
{{out}}
10,333

edits