
(FPCore (x y z t) :precision binary64 (* (/ (- x y) (- z y)) t))
double code(double x, double y, double z, double t) {
return ((x - y) / (z - y)) * t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((x - y) / (z - y)) * t
end function
public static double code(double x, double y, double z, double t) {
return ((x - y) / (z - y)) * t;
}
def code(x, y, z, t): return ((x - y) / (z - y)) * t
function code(x, y, z, t) return Float64(Float64(Float64(x - y) / Float64(z - y)) * t) end
function tmp = code(x, y, z, t) tmp = ((x - y) / (z - y)) * t; end
code[x_, y_, z_, t_] := N[(N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{z - y} \cdot t
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 17 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (* (/ (- x y) (- z y)) t))
double code(double x, double y, double z, double t) {
return ((x - y) / (z - y)) * t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((x - y) / (z - y)) * t
end function
public static double code(double x, double y, double z, double t) {
return ((x - y) / (z - y)) * t;
}
def code(x, y, z, t): return ((x - y) / (z - y)) * t
function code(x, y, z, t) return Float64(Float64(Float64(x - y) / Float64(z - y)) * t) end
function tmp = code(x, y, z, t) tmp = ((x - y) / (z - y)) * t; end
code[x_, y_, z_, t_] := N[(N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{z - y} \cdot t
\end{array}
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* t (/ (- x y) (- z y))))) (if (<= y -7e-66) t_1 (if (<= y 4.1e-18) (* (- x y) (/ t (- z y))) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = t * ((x - y) / (z - y));
double tmp;
if (y <= -7e-66) {
tmp = t_1;
} else if (y <= 4.1e-18) {
tmp = (x - y) * (t / (z - y));
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = t * ((x - y) / (z - y))
if (y <= (-7d-66)) then
tmp = t_1
else if (y <= 4.1d-18) then
tmp = (x - y) * (t / (z - y))
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = t * ((x - y) / (z - y));
double tmp;
if (y <= -7e-66) {
tmp = t_1;
} else if (y <= 4.1e-18) {
tmp = (x - y) * (t / (z - y));
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = t * ((x - y) / (z - y)) tmp = 0 if y <= -7e-66: tmp = t_1 elif y <= 4.1e-18: tmp = (x - y) * (t / (z - y)) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(t * Float64(Float64(x - y) / Float64(z - y))) tmp = 0.0 if (y <= -7e-66) tmp = t_1; elseif (y <= 4.1e-18) tmp = Float64(Float64(x - y) * Float64(t / Float64(z - y))); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = t * ((x - y) / (z - y)); tmp = 0.0; if (y <= -7e-66) tmp = t_1; elseif (y <= 4.1e-18) tmp = (x - y) * (t / (z - y)); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(t * N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -7e-66], t$95$1, If[LessEqual[y, 4.1e-18], N[(N[(x - y), $MachinePrecision] * N[(t / N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := t \cdot \frac{x - y}{z - y}\\
\mathbf{if}\;y \leq -7 \cdot 10^{-66}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 4.1 \cdot 10^{-18}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{t}{z - y}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -7.0000000000000001e-66 or 4.0999999999999998e-18 < y Initial program 99.8%
if -7.0000000000000001e-66 < y < 4.0999999999999998e-18Initial program 86.7%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6497.1
Applied rewrites97.1%
Final simplification98.7%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (/ (- x y) (- z y))))
(if (<= t_1 -1e-13)
(/ (* t x) z)
(if (<= t_1 1e-270)
(- (/ (* t y) z))
(if (<= t_1 0.8)
(* t (/ x z))
(if (<= t_1 2.0) (fma t (/ z y) t) (* t (/ x (- y)))))))))
double code(double x, double y, double z, double t) {
double t_1 = (x - y) / (z - y);
double tmp;
if (t_1 <= -1e-13) {
tmp = (t * x) / z;
} else if (t_1 <= 1e-270) {
tmp = -((t * y) / z);
} else if (t_1 <= 0.8) {
tmp = t * (x / z);
} else if (t_1 <= 2.0) {
tmp = fma(t, (z / y), t);
} else {
tmp = t * (x / -y);
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(x - y) / Float64(z - y)) tmp = 0.0 if (t_1 <= -1e-13) tmp = Float64(Float64(t * x) / z); elseif (t_1 <= 1e-270) tmp = Float64(-Float64(Float64(t * y) / z)); elseif (t_1 <= 0.8) tmp = Float64(t * Float64(x / z)); elseif (t_1 <= 2.0) tmp = fma(t, Float64(z / y), t); else tmp = Float64(t * Float64(x / Float64(-y))); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e-13], N[(N[(t * x), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[t$95$1, 1e-270], (-N[(N[(t * y), $MachinePrecision] / z), $MachinePrecision]), If[LessEqual[t$95$1, 0.8], N[(t * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2.0], N[(t * N[(z / y), $MachinePrecision] + t), $MachinePrecision], N[(t * N[(x / (-y)), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{x - y}{z - y}\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{-13}:\\
\;\;\;\;\frac{t \cdot x}{z}\\
\mathbf{elif}\;t\_1 \leq 10^{-270}:\\
\;\;\;\;-\frac{t \cdot y}{z}\\
\mathbf{elif}\;t\_1 \leq 0.8:\\
\;\;\;\;t \cdot \frac{x}{z}\\
\mathbf{elif}\;t\_1 \leq 2:\\
\;\;\;\;\mathsf{fma}\left(t, \frac{z}{y}, t\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot \frac{x}{-y}\\
\end{array}
\end{array}
if (/.f64 (-.f64 x y) (-.f64 z y)) < -1e-13Initial program 94.7%
Taylor expanded in y around 0
lower-/.f64N/A
lower-*.f6450.8
Applied rewrites50.8%
if -1e-13 < (/.f64 (-.f64 x y) (-.f64 z y)) < 1e-270Initial program 91.5%
Taylor expanded in z around inf
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower--.f64N/A
lower-/.f6492.6
Applied rewrites92.6%
Taylor expanded in x around 0
Applied rewrites61.9%
if 1e-270 < (/.f64 (-.f64 x y) (-.f64 z y)) < 0.80000000000000004Initial program 99.7%
Taylor expanded in y around 0
lower-/.f6458.1
Applied rewrites58.1%
if 0.80000000000000004 < (/.f64 (-.f64 x y) (-.f64 z y)) < 2Initial program 99.9%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
lower-*.f6473.3
Applied rewrites73.3%
Taylor expanded in y around inf
associate--l+N/A
distribute-lft-out--N/A
div-subN/A
+-commutativeN/A
mul-1-negN/A
distribute-lft-out--N/A
associate-/l*N/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
Applied rewrites99.4%
Taylor expanded in z around inf
Applied rewrites97.8%
if 2 < (/.f64 (-.f64 x y) (-.f64 z y)) Initial program 95.3%
Taylor expanded in x around inf
lower-/.f64N/A
lower--.f6493.4
Applied rewrites93.4%
Taylor expanded in z around 0
Applied rewrites52.5%
Final simplification69.7%
(FPCore (x y z t) :precision binary64 (/ t (/ (- z y) (- x y))))
double code(double x, double y, double z, double t) {
return t / ((z - y) / (x - y));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = t / ((z - y) / (x - y))
end function
public static double code(double x, double y, double z, double t) {
return t / ((z - y) / (x - y));
}
def code(x, y, z, t): return t / ((z - y) / (x - y))
function code(x, y, z, t) return Float64(t / Float64(Float64(z - y) / Float64(x - y))) end
function tmp = code(x, y, z, t) tmp = t / ((z - y) / (x - y)); end
code[x_, y_, z_, t_] := N[(t / N[(N[(z - y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{t}{\frac{z - y}{x - y}}
\end{array}
herbie shell --seed 2024228
(FPCore (x y z t)
:name "Numeric.Signal.Multichannel:$cput from hsignal-0.2.7.1"
:precision binary64
:alt
(! :herbie-platform default (/ t (/ (- z y) (- x y))))
(* (/ (- x y) (- z y)) t))