
(FPCore (x y z t) :precision binary64 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))
double code(double x, double y, double z, double t) {
return x + ((y * z) * (tanh((t / y)) - tanh((x / y))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y * z) * (tanh((t / y)) - tanh((x / y))))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * z) * (Math.tanh((t / y)) - Math.tanh((x / y))));
}
def code(x, y, z, t): return x + ((y * z) * (math.tanh((t / y)) - math.tanh((x / y))))
function code(x, y, z, t) return Float64(x + Float64(Float64(y * z) * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))))) end
function tmp = code(x, y, z, t) tmp = x + ((y * z) * (tanh((t / y)) - tanh((x / y)))); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * z), $MachinePrecision] * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\end{array}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))
double code(double x, double y, double z, double t) {
return x + ((y * z) * (tanh((t / y)) - tanh((x / y))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y * z) * (tanh((t / y)) - tanh((x / y))))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * z) * (Math.tanh((t / y)) - Math.tanh((x / y))));
}
def code(x, y, z, t): return x + ((y * z) * (math.tanh((t / y)) - math.tanh((x / y))))
function code(x, y, z, t) return Float64(x + Float64(Float64(y * z) * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))))) end
function tmp = code(x, y, z, t) tmp = x + ((y * z) * (tanh((t / y)) - tanh((x / y)))); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * z), $MachinePrecision] * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\end{array}
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (tanh (/ t y)) (tanh (/ x y)))))
(if (<= (+ x (* (* y z) t_1)) 1e+305)
(fma (* t_1 z) y x)
(fma (- t x) z x))))
double code(double x, double y, double z, double t) {
double t_1 = tanh((t / y)) - tanh((x / y));
double tmp;
if ((x + ((y * z) * t_1)) <= 1e+305) {
tmp = fma((t_1 * z), y, x);
} else {
tmp = fma((t - x), z, x);
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))) tmp = 0.0 if (Float64(x + Float64(Float64(y * z) * t_1)) <= 1e+305) tmp = fma(Float64(t_1 * z), y, x); else tmp = fma(Float64(t - x), z, x); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x + N[(N[(y * z), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision], 1e+305], N[(N[(t$95$1 * z), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * z + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\\
\mathbf{if}\;x + \left(y \cdot z\right) \cdot t\_1 \leq 10^{+305}:\\
\;\;\;\;\mathsf{fma}\left(t\_1 \cdot z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < 9.9999999999999994e304Initial program 93.4%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-/.f64N/A
lift-tanh.f64N/A
lift-/.f64N/A
lift-tanh.f64N/A
+-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites97.2%
lift-fma.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-/.f64N/A
lift-tanh.f64N/A
lift-/.f64N/A
lift-tanh.f64N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites97.2%
if 9.9999999999999994e304 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) Initial program 93.4%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6460.7
Applied rewrites60.7%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (tanh (/ t y))))
(if (<= (+ x (* (* y z) (- t_1 (tanh (/ x y))))) 1e+305)
(fma y (* z t_1) x)
(fma (- t x) z x))))
double code(double x, double y, double z, double t) {
double t_1 = tanh((t / y));
double tmp;
if ((x + ((y * z) * (t_1 - tanh((x / y))))) <= 1e+305) {
tmp = fma(y, (z * t_1), x);
} else {
tmp = fma((t - x), z, x);
}
return tmp;
}
function code(x, y, z, t) t_1 = tanh(Float64(t / y)) tmp = 0.0 if (Float64(x + Float64(Float64(y * z) * Float64(t_1 - tanh(Float64(x / y))))) <= 1e+305) tmp = fma(y, Float64(z * t_1), x); else tmp = fma(Float64(t - x), z, x); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(x + N[(N[(y * z), $MachinePrecision] * N[(t$95$1 - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e+305], N[(y * N[(z * t$95$1), $MachinePrecision] + x), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * z + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \tanh \left(\frac{t}{y}\right)\\
\mathbf{if}\;x + \left(y \cdot z\right) \cdot \left(t\_1 - \tanh \left(\frac{x}{y}\right)\right) \leq 10^{+305}:\\
\;\;\;\;\mathsf{fma}\left(y, z \cdot t\_1, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < 9.9999999999999994e304Initial program 93.4%
Taylor expanded in x around 0
associate-/r*N/A
div-subN/A
rec-expN/A
rec-expN/A
tanh-def-aN/A
lift-tanh.f64N/A
lift-/.f6479.3
Applied rewrites79.3%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f6480.2
Applied rewrites80.2%
if 9.9999999999999994e304 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) Initial program 93.4%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6460.7
Applied rewrites60.7%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (fma (- t x) z x)))
(if (<= y -7.6e+18)
t_1
(if (<= y 2.95e+57) (fma (/ (* t t) (+ t x)) z x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma((t - x), z, x);
double tmp;
if (y <= -7.6e+18) {
tmp = t_1;
} else if (y <= 2.95e+57) {
tmp = fma(((t * t) / (t + x)), z, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(Float64(t - x), z, x) tmp = 0.0 if (y <= -7.6e+18) tmp = t_1; elseif (y <= 2.95e+57) tmp = fma(Float64(Float64(t * t) / Float64(t + x)), z, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(t - x), $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[y, -7.6e+18], t$95$1, If[LessEqual[y, 2.95e+57], N[(N[(N[(t * t), $MachinePrecision] / N[(t + x), $MachinePrecision]), $MachinePrecision] * z + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(t - x, z, x\right)\\
\mathbf{if}\;y \leq -7.6 \cdot 10^{+18}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 2.95 \cdot 10^{+57}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t \cdot t}{t + x}, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -7.6e18 or 2.95000000000000006e57 < y Initial program 93.4%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6460.7
Applied rewrites60.7%
if -7.6e18 < y < 2.95000000000000006e57Initial program 93.4%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6460.7
Applied rewrites60.7%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
unpow2N/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-+.f6441.5
Applied rewrites41.5%
Taylor expanded in x around 0
pow2N/A
lift-*.f6452.2
Applied rewrites52.2%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (- t x) z x))) (if (<= y -2.1e+103) t_1 (if (<= y 8e+103) (fma t z x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma((t - x), z, x);
double tmp;
if (y <= -2.1e+103) {
tmp = t_1;
} else if (y <= 8e+103) {
tmp = fma(t, z, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(Float64(t - x), z, x) tmp = 0.0 if (y <= -2.1e+103) tmp = t_1; elseif (y <= 8e+103) tmp = fma(t, z, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(t - x), $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[y, -2.1e+103], t$95$1, If[LessEqual[y, 8e+103], N[(t * z + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(t - x, z, x\right)\\
\mathbf{if}\;y \leq -2.1 \cdot 10^{+103}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 8 \cdot 10^{+103}:\\
\;\;\;\;\mathsf{fma}\left(t, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -2.1000000000000002e103 or 8e103 < y Initial program 93.4%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6460.7
Applied rewrites60.7%
if -2.1000000000000002e103 < y < 8e103Initial program 93.4%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6460.7
Applied rewrites60.7%
Taylor expanded in x around 0
Applied rewrites58.2%
(FPCore (x y z t) :precision binary64 (if (<= z -7.2e-33) (fma t z x) (if (<= z 2.1e-125) (- x (* z x)) (fma t z x))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -7.2e-33) {
tmp = fma(t, z, x);
} else if (z <= 2.1e-125) {
tmp = x - (z * x);
} else {
tmp = fma(t, z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -7.2e-33) tmp = fma(t, z, x); elseif (z <= 2.1e-125) tmp = Float64(x - Float64(z * x)); else tmp = fma(t, z, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -7.2e-33], N[(t * z + x), $MachinePrecision], If[LessEqual[z, 2.1e-125], N[(x - N[(z * x), $MachinePrecision]), $MachinePrecision], N[(t * z + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.2 \cdot 10^{-33}:\\
\;\;\;\;\mathsf{fma}\left(t, z, x\right)\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{-125}:\\
\;\;\;\;x - z \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, z, x\right)\\
\end{array}
\end{array}
if z < -7.20000000000000068e-33 or 2.1e-125 < z Initial program 93.4%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6460.7
Applied rewrites60.7%
Taylor expanded in x around 0
Applied rewrites58.2%
if -7.20000000000000068e-33 < z < 2.1e-125Initial program 93.4%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6460.7
Applied rewrites60.7%
Taylor expanded in x around 0
lower-*.f6417.2
Applied rewrites17.2%
Taylor expanded in t around 0
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6453.4
Applied rewrites53.4%
(FPCore (x y z t) :precision binary64 (fma t z x))
double code(double x, double y, double z, double t) {
return fma(t, z, x);
}
function code(x, y, z, t) return fma(t, z, x) end
code[x_, y_, z_, t_] := N[(t * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(t, z, x\right)
\end{array}
Initial program 93.4%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6460.7
Applied rewrites60.7%
Taylor expanded in x around 0
Applied rewrites58.2%
(FPCore (x y z t) :precision binary64 (* t z))
double code(double x, double y, double z, double t) {
return t * z;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = t * z
end function
public static double code(double x, double y, double z, double t) {
return t * z;
}
def code(x, y, z, t): return t * z
function code(x, y, z, t) return Float64(t * z) end
function tmp = code(x, y, z, t) tmp = t * z; end
code[x_, y_, z_, t_] := N[(t * z), $MachinePrecision]
\begin{array}{l}
\\
t \cdot z
\end{array}
Initial program 93.4%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6460.7
Applied rewrites60.7%
Taylor expanded in x around 0
lower-*.f6417.2
Applied rewrites17.2%
herbie shell --seed 2025138
(FPCore (x y z t)
:name "SynthBasics:moogVCF from YampaSynth-0.2"
:precision binary64
(+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))