
(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}
Sampling outcomes in binary64 precision:
Herbie found 10 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 (fma (* (- (tanh (/ t y)) (tanh (/ x y))) y) z x))
double code(double x, double y, double z, double t) {
return fma(((tanh((t / y)) - tanh((x / y))) * y), z, x);
}
function code(x, y, z, t) return fma(Float64(Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))) * y), z, x) end
code[x_, y_, z_, t_] := N[(N[(N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \cdot y, z, x\right)
\end{array}
Initial program 94.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6498.1
Applied rewrites98.1%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (fma (* (- (tanh (/ t y)) (/ x y)) y) z x)))
(if (<= t -4.5e+44)
t_1
(if (<= t -42000000000000.0)
(fma (/ (* t t) (+ x t)) z x)
(if (<= t 3.8e-41) (fma (- (/ t y) (tanh (/ x y))) (* z y) x) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = fma(((tanh((t / y)) - (x / y)) * y), z, x);
double tmp;
if (t <= -4.5e+44) {
tmp = t_1;
} else if (t <= -42000000000000.0) {
tmp = fma(((t * t) / (x + t)), z, x);
} else if (t <= 3.8e-41) {
tmp = fma(((t / y) - tanh((x / y))), (z * y), x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(Float64(Float64(tanh(Float64(t / y)) - Float64(x / y)) * y), z, x) tmp = 0.0 if (t <= -4.5e+44) tmp = t_1; elseif (t <= -42000000000000.0) tmp = fma(Float64(Float64(t * t) / Float64(x + t)), z, x); elseif (t <= 3.8e-41) tmp = fma(Float64(Float64(t / y) - tanh(Float64(x / y))), Float64(z * y), x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[(x / y), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[t, -4.5e+44], t$95$1, If[LessEqual[t, -42000000000000.0], N[(N[(N[(t * t), $MachinePrecision] / N[(x + t), $MachinePrecision]), $MachinePrecision] * z + x), $MachinePrecision], If[LessEqual[t, 3.8e-41], N[(N[(N[(t / y), $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(z * y), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\left(\tanh \left(\frac{t}{y}\right) - \frac{x}{y}\right) \cdot y, z, x\right)\\
\mathbf{if}\;t \leq -4.5 \cdot 10^{+44}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq -42000000000000:\\
\;\;\;\;\mathsf{fma}\left(\frac{t \cdot t}{x + t}, z, x\right)\\
\mathbf{elif}\;t \leq 3.8 \cdot 10^{-41}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t}{y} - \tanh \left(\frac{x}{y}\right), z \cdot y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -4.5e44 or 3.79999999999999979e-41 < t Initial program 97.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
lower-/.f6466.8
Applied rewrites66.8%
if -4.5e44 < t < -4.2e13Initial program 91.3%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6455.9
Applied rewrites55.9%
Applied rewrites30.2%
Taylor expanded in x around 0
Applied rewrites91.1%
if -4.2e13 < t < 3.79999999999999979e-41Initial program 91.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6495.9
Applied rewrites95.9%
Taylor expanded in y around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
associate-*r/N/A
distribute-lft1-inN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
distribute-lft1-inN/A
lower--.f64N/A
lower-/.f64N/A
distribute-lft1-inN/A
metadata-evalN/A
mul0-lft91.8
Applied rewrites91.8%
lift-fma.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
Applied rewrites87.7%
(FPCore (x y z t) :precision binary64 (if (or (<= t -4.2e+35) (not (<= t 4e-41))) (fma (* (- (tanh (/ t y)) (/ x y)) y) z x) (fma (* (- (/ t y) (tanh (/ x y))) y) z x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -4.2e+35) || !(t <= 4e-41)) {
tmp = fma(((tanh((t / y)) - (x / y)) * y), z, x);
} else {
tmp = fma((((t / y) - tanh((x / y))) * y), z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((t <= -4.2e+35) || !(t <= 4e-41)) tmp = fma(Float64(Float64(tanh(Float64(t / y)) - Float64(x / y)) * y), z, x); else tmp = fma(Float64(Float64(Float64(t / y) - tanh(Float64(x / y))) * y), z, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -4.2e+35], N[Not[LessEqual[t, 4e-41]], $MachinePrecision]], N[(N[(N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[(x / y), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] * z + x), $MachinePrecision], N[(N[(N[(N[(t / y), $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -4.2 \cdot 10^{+35} \lor \neg \left(t \leq 4 \cdot 10^{-41}\right):\\
\;\;\;\;\mathsf{fma}\left(\left(\tanh \left(\frac{t}{y}\right) - \frac{x}{y}\right) \cdot y, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(\frac{t}{y} - \tanh \left(\frac{x}{y}\right)\right) \cdot y, z, x\right)\\
\end{array}
\end{array}
if t < -4.1999999999999998e35 or 4.00000000000000002e-41 < t Initial program 97.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
lower-/.f6465.7
Applied rewrites65.7%
if -4.1999999999999998e35 < t < 4.00000000000000002e-41Initial program 91.5%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6496.1
Applied rewrites96.1%
Taylor expanded in y around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
associate-*r/N/A
distribute-lft1-inN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
distribute-lft1-inN/A
lower--.f64N/A
lower-/.f64N/A
distribute-lft1-inN/A
metadata-evalN/A
mul0-lft90.7
Applied rewrites90.7%
Final simplification77.8%
(FPCore (x y z t)
:precision binary64
(if (<= x -1.05e+140)
(fma (/ (* t t) (+ x t)) z x)
(if (<= x 5e+125)
(fma (* (- (tanh (/ t y)) (/ x y)) y) z x)
(fma (* (/ (* t t) (* (- x t) (+ x t))) (- x t)) z x))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.05e+140) {
tmp = fma(((t * t) / (x + t)), z, x);
} else if (x <= 5e+125) {
tmp = fma(((tanh((t / y)) - (x / y)) * y), z, x);
} else {
tmp = fma((((t * t) / ((x - t) * (x + t))) * (x - t)), z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (x <= -1.05e+140) tmp = fma(Float64(Float64(t * t) / Float64(x + t)), z, x); elseif (x <= 5e+125) tmp = fma(Float64(Float64(tanh(Float64(t / y)) - Float64(x / y)) * y), z, x); else tmp = fma(Float64(Float64(Float64(t * t) / Float64(Float64(x - t) * Float64(x + t))) * Float64(x - t)), z, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[x, -1.05e+140], N[(N[(N[(t * t), $MachinePrecision] / N[(x + t), $MachinePrecision]), $MachinePrecision] * z + x), $MachinePrecision], If[LessEqual[x, 5e+125], N[(N[(N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[(x / y), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] * z + x), $MachinePrecision], N[(N[(N[(N[(t * t), $MachinePrecision] / N[(N[(x - t), $MachinePrecision] * N[(x + t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x - t), $MachinePrecision]), $MachinePrecision] * z + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{+140}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t \cdot t}{x + t}, z, x\right)\\
\mathbf{elif}\;x \leq 5 \cdot 10^{+125}:\\
\;\;\;\;\mathsf{fma}\left(\left(\tanh \left(\frac{t}{y}\right) - \frac{x}{y}\right) \cdot y, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t \cdot t}{\left(x - t\right) \cdot \left(x + t\right)} \cdot \left(x - t\right), z, x\right)\\
\end{array}
\end{array}
if x < -1.0500000000000001e140Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6448.7
Applied rewrites48.7%
Applied rewrites13.9%
Taylor expanded in x around 0
Applied rewrites62.1%
if -1.0500000000000001e140 < x < 4.99999999999999962e125Initial program 92.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6497.4
Applied rewrites97.4%
Taylor expanded in x around 0
lower-/.f6476.7
Applied rewrites76.7%
if 4.99999999999999962e125 < x Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6455.8
Applied rewrites55.8%
Applied rewrites14.6%
Taylor expanded in x around 0
Applied rewrites62.8%
Applied rewrites65.2%
(FPCore (x y z t)
:precision binary64
(if (<= z -1.92e+28)
(fma (/ (* t t) (+ x t)) z x)
(if (<= z 1.12e-144)
(fma (- x) z x)
(if (<= z 5.8e+78) (fma (* z y) (/ t y) x) (fma (- t x) z x)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.92e+28) {
tmp = fma(((t * t) / (x + t)), z, x);
} else if (z <= 1.12e-144) {
tmp = fma(-x, z, x);
} else if (z <= 5.8e+78) {
tmp = fma((z * y), (t / y), x);
} else {
tmp = fma((t - x), z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -1.92e+28) tmp = fma(Float64(Float64(t * t) / Float64(x + t)), z, x); elseif (z <= 1.12e-144) tmp = fma(Float64(-x), z, x); elseif (z <= 5.8e+78) tmp = fma(Float64(z * y), Float64(t / y), x); else tmp = fma(Float64(t - x), z, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.92e+28], N[(N[(N[(t * t), $MachinePrecision] / N[(x + t), $MachinePrecision]), $MachinePrecision] * z + x), $MachinePrecision], If[LessEqual[z, 1.12e-144], N[((-x) * z + x), $MachinePrecision], If[LessEqual[z, 5.8e+78], N[(N[(z * y), $MachinePrecision] * N[(t / y), $MachinePrecision] + x), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * z + x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.92 \cdot 10^{+28}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t \cdot t}{x + t}, z, x\right)\\
\mathbf{elif}\;z \leq 1.12 \cdot 10^{-144}:\\
\;\;\;\;\mathsf{fma}\left(-x, z, x\right)\\
\mathbf{elif}\;z \leq 5.8 \cdot 10^{+78}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot y, \frac{t}{y}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\
\end{array}
\end{array}
if z < -1.91999999999999998e28Initial program 93.5%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6433.9
Applied rewrites33.9%
Applied rewrites28.8%
Taylor expanded in x around 0
Applied rewrites38.0%
if -1.91999999999999998e28 < z < 1.12e-144Initial program 99.1%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6475.8
Applied rewrites75.8%
Taylor expanded in x around inf
Applied rewrites90.3%
if 1.12e-144 < z < 5.80000000000000034e78Initial program 99.8%
Taylor expanded in y around inf
lower-/.f64N/A
lower--.f6443.6
Applied rewrites43.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6443.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6443.6
Applied rewrites43.6%
Taylor expanded in x around 0
Applied rewrites60.9%
if 5.80000000000000034e78 < z Initial program 84.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6442.9
Applied rewrites42.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (fma (- t x) z x)))
(if (<= z -1.75e-12)
t_1
(if (<= z 1.12e-144)
(fma (- x) z x)
(if (<= z 5.8e+78) (fma (* z y) (/ t y) x) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = fma((t - x), z, x);
double tmp;
if (z <= -1.75e-12) {
tmp = t_1;
} else if (z <= 1.12e-144) {
tmp = fma(-x, z, x);
} else if (z <= 5.8e+78) {
tmp = fma((z * y), (t / y), 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 (z <= -1.75e-12) tmp = t_1; elseif (z <= 1.12e-144) tmp = fma(Float64(-x), z, x); elseif (z <= 5.8e+78) tmp = fma(Float64(z * y), Float64(t / y), 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[z, -1.75e-12], t$95$1, If[LessEqual[z, 1.12e-144], N[((-x) * z + x), $MachinePrecision], If[LessEqual[z, 5.8e+78], N[(N[(z * y), $MachinePrecision] * N[(t / y), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(t - x, z, x\right)\\
\mathbf{if}\;z \leq -1.75 \cdot 10^{-12}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.12 \cdot 10^{-144}:\\
\;\;\;\;\mathsf{fma}\left(-x, z, x\right)\\
\mathbf{elif}\;z \leq 5.8 \cdot 10^{+78}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot y, \frac{t}{y}, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -1.75e-12 or 5.80000000000000034e78 < z Initial program 88.7%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6439.9
Applied rewrites39.9%
if -1.75e-12 < z < 1.12e-144Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6475.6
Applied rewrites75.6%
Taylor expanded in x around inf
Applied rewrites92.6%
if 1.12e-144 < z < 5.80000000000000034e78Initial program 99.8%
Taylor expanded in y around inf
lower-/.f64N/A
lower--.f6443.6
Applied rewrites43.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6443.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6443.6
Applied rewrites43.6%
Taylor expanded in x around 0
Applied rewrites60.9%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.75e-12) (not (<= z 4e-146))) (fma (- t x) z x) (fma (- x) z x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.75e-12) || !(z <= 4e-146)) {
tmp = fma((t - x), z, x);
} else {
tmp = fma(-x, z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.75e-12) || !(z <= 4e-146)) tmp = fma(Float64(t - x), z, x); else tmp = fma(Float64(-x), z, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.75e-12], N[Not[LessEqual[z, 4e-146]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * z + x), $MachinePrecision], N[((-x) * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.75 \cdot 10^{-12} \lor \neg \left(z \leq 4 \cdot 10^{-146}\right):\\
\;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-x, z, x\right)\\
\end{array}
\end{array}
if z < -1.75e-12 or 4.0000000000000001e-146 < z Initial program 91.5%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6442.2
Applied rewrites42.2%
if -1.75e-12 < z < 4.0000000000000001e-146Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6475.6
Applied rewrites75.6%
Taylor expanded in x around inf
Applied rewrites92.6%
Final simplification61.5%
(FPCore (x y z t) :precision binary64 (if (or (<= z -3.3e-10) (not (<= z 5.8e-10))) (* (- t x) z) (fma (- x) z x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.3e-10) || !(z <= 5.8e-10)) {
tmp = (t - x) * z;
} else {
tmp = fma(-x, z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.3e-10) || !(z <= 5.8e-10)) tmp = Float64(Float64(t - x) * z); else tmp = fma(Float64(-x), z, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.3e-10], N[Not[LessEqual[z, 5.8e-10]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * z), $MachinePrecision], N[((-x) * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{-10} \lor \neg \left(z \leq 5.8 \cdot 10^{-10}\right):\\
\;\;\;\;\left(t - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-x, z, x\right)\\
\end{array}
\end{array}
if z < -3.3e-10 or 5.79999999999999962e-10 < z Initial program 90.2%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6437.6
Applied rewrites37.6%
Applied rewrites32.5%
Taylor expanded in x around inf
Applied rewrites19.5%
Taylor expanded in z around inf
Applied rewrites36.9%
if -3.3e-10 < z < 5.79999999999999962e-10Initial program 99.9%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6475.0
Applied rewrites75.0%
Taylor expanded in x around inf
Applied rewrites87.4%
Final simplification60.4%
(FPCore (x y z t) :precision binary64 (* (- t x) z))
double code(double x, double y, double z, double t) {
return (t - x) * 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 - x) * z
end function
public static double code(double x, double y, double z, double t) {
return (t - x) * z;
}
def code(x, y, z, t): return (t - x) * z
function code(x, y, z, t) return Float64(Float64(t - x) * z) end
function tmp = code(x, y, z, t) tmp = (t - x) * z; end
code[x_, y_, z_, t_] := N[(N[(t - x), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\left(t - x\right) \cdot z
\end{array}
Initial program 94.8%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6455.0
Applied rewrites55.0%
Applied rewrites39.6%
Taylor expanded in x around inf
Applied rewrites51.1%
Taylor expanded in z around inf
Applied rewrites23.5%
Final simplification23.5%
(FPCore (x y z t) :precision binary64 (* z t))
double code(double x, double y, double z, double t) {
return z * t;
}
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 = z * t
end function
public static double code(double x, double y, double z, double t) {
return z * t;
}
def code(x, y, z, t): return z * t
function code(x, y, z, t) return Float64(z * t) end
function tmp = code(x, y, z, t) tmp = z * t; end
code[x_, y_, z_, t_] := N[(z * t), $MachinePrecision]
\begin{array}{l}
\\
z \cdot t
\end{array}
Initial program 94.8%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6455.0
Applied rewrites55.0%
Taylor expanded in x around 0
Applied rewrites15.4%
(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(y * Float64(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[(y * N[(z * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right)
\end{array}
herbie shell --seed 2024363
(FPCore (x y z t)
:name "SynthBasics:moogVCF from YampaSynth-0.2"
:precision binary64
:alt
(! :herbie-platform default (+ x (* y (* z (- (tanh (/ t y)) (tanh (/ x y)))))))
(+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))