Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

container/float_sequence.fz


# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation.  If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
#  Tokiwa Software GmbH, Germany
#
#  Source code of Fuzion standard library feature float_sequence
#
#  Author: Michael Lill (michael.lill@tokiwa.software)
#
# -----------------------------------------------------------------------

# NYI
# mode
# Mean (geometric harmonic)
# quartile
# ...

# float_sequence -- a Sequence whose elements inherit from float
#
public float_sequence(public F type : float,
                      redef from Sequence F) : numeric_sequence F from is

  # create a list from this Sequence.
  #
  public redef as_list => from.as_list


  # the standard deviation of the sequence
  # https://en.wikipedia.org/wiki/Standard_deviation
  public std_dev =>
    variance.map (x -> F.sqrt x)


  # the euclidean norm of this sequence
  # i.e. the square of the sum of squares of this sequence
  #
  public euclidean_norm F =>
    F.sqrt ((map (x)->x**F.two).fold F.sum)