
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / 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 - x)) / t)
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
def code(x, y, z, t): return x + ((y * (z - x)) / t)
function code(x, y, z, t) return Float64(x + Float64(Float64(y * Float64(z - x)) / t)) end
function tmp = code(x, y, z, t) tmp = x + ((y * (z - x)) / t); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - x\right)}{t}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / 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 - x)) / t)
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
def code(x, y, z, t): return x + ((y * (z - x)) / t)
function code(x, y, z, t) return Float64(x + Float64(Float64(y * Float64(z - x)) / t)) end
function tmp = code(x, y, z, t) tmp = x + ((y * (z - x)) / t); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - x\right)}{t}
\end{array}
(FPCore (x y z t) :precision binary64 (fma (/ y t) (- z x) x))
double code(double x, double y, double z, double t) {
return fma((y / t), (z - x), x);
}
function code(x, y, z, t) return fma(Float64(y / t), Float64(z - x), x) end
code[x_, y_, z_, t_] := N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)
\end{array}
Initial program 94.4%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6498.9
Applied egg-rr98.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (+ x (/ (* y (- z x)) t))))
(if (<= t_1 -1e+262)
(* (/ y t) (- z x))
(if (<= t_1 5e+296) (+ x (/ (* y z) t)) (* y (/ (- z x) t))))))
double code(double x, double y, double z, double t) {
double t_1 = x + ((y * (z - x)) / t);
double tmp;
if (t_1 <= -1e+262) {
tmp = (y / t) * (z - x);
} else if (t_1 <= 5e+296) {
tmp = x + ((y * z) / t);
} else {
tmp = y * ((z - x) / t);
}
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 = x + ((y * (z - x)) / t)
if (t_1 <= (-1d+262)) then
tmp = (y / t) * (z - x)
else if (t_1 <= 5d+296) then
tmp = x + ((y * z) / t)
else
tmp = y * ((z - x) / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = x + ((y * (z - x)) / t);
double tmp;
if (t_1 <= -1e+262) {
tmp = (y / t) * (z - x);
} else if (t_1 <= 5e+296) {
tmp = x + ((y * z) / t);
} else {
tmp = y * ((z - x) / t);
}
return tmp;
}
def code(x, y, z, t): t_1 = x + ((y * (z - x)) / t) tmp = 0 if t_1 <= -1e+262: tmp = (y / t) * (z - x) elif t_1 <= 5e+296: tmp = x + ((y * z) / t) else: tmp = y * ((z - x) / t) return tmp
function code(x, y, z, t) t_1 = Float64(x + Float64(Float64(y * Float64(z - x)) / t)) tmp = 0.0 if (t_1 <= -1e+262) tmp = Float64(Float64(y / t) * Float64(z - x)); elseif (t_1 <= 5e+296) tmp = Float64(x + Float64(Float64(y * z) / t)); else tmp = Float64(y * Float64(Float64(z - x) / t)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x + ((y * (z - x)) / t); tmp = 0.0; if (t_1 <= -1e+262) tmp = (y / t) * (z - x); elseif (t_1 <= 5e+296) tmp = x + ((y * z) / t); else tmp = y * ((z - x) / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+262], N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+296], N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x + \frac{y \cdot \left(z - x\right)}{t}\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+262}:\\
\;\;\;\;\frac{y}{t} \cdot \left(z - x\right)\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+296}:\\
\;\;\;\;x + \frac{y \cdot z}{t}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{z - x}{t}\\
\end{array}
\end{array}
if (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < -1e262Initial program 89.7%
Taylor expanded in y around inf
div-subN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6491.7
Simplified91.7%
associate-*r/N/A
associate-*l/N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6499.9
Applied egg-rr99.9%
if -1e262 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < 5.0000000000000001e296Initial program 99.2%
Taylor expanded in z around inf
/-lowering-/.f64N/A
*-lowering-*.f6484.7
Simplified84.7%
if 5.0000000000000001e296 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) Initial program 81.9%
Taylor expanded in y around inf
div-subN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6493.0
Simplified93.0%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (+ x (/ (* y (- z x)) t))) (t_2 (* y (/ (- z x) t)))) (if (<= t_1 -1e+262) t_2 (if (<= t_1 5e+296) (fma (/ z t) y x) t_2))))
double code(double x, double y, double z, double t) {
double t_1 = x + ((y * (z - x)) / t);
double t_2 = y * ((z - x) / t);
double tmp;
if (t_1 <= -1e+262) {
tmp = t_2;
} else if (t_1 <= 5e+296) {
tmp = fma((z / t), y, x);
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x + Float64(Float64(y * Float64(z - x)) / t)) t_2 = Float64(y * Float64(Float64(z - x) / t)) tmp = 0.0 if (t_1 <= -1e+262) tmp = t_2; elseif (t_1 <= 5e+296) tmp = fma(Float64(z / t), y, x); else tmp = t_2; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+262], t$95$2, If[LessEqual[t$95$1, 5e+296], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x + \frac{y \cdot \left(z - x\right)}{t}\\
t_2 := y \cdot \frac{z - x}{t}\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+262}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+296}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < -1e262 or 5.0000000000000001e296 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) Initial program 86.4%
Taylor expanded in y around inf
div-subN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6492.3
Simplified92.3%
if -1e262 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < 5.0000000000000001e296Initial program 99.2%
Taylor expanded in z around inf
/-lowering-/.f64N/A
*-lowering-*.f6484.7
Simplified84.7%
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6479.9
Applied egg-rr79.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ z t) y x))) (if (<= t -1.32e+39) t_1 (if (<= t 2e-78) (* (/ y t) (- z x)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma((z / t), y, x);
double tmp;
if (t <= -1.32e+39) {
tmp = t_1;
} else if (t <= 2e-78) {
tmp = (y / t) * (z - x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(Float64(z / t), y, x) tmp = 0.0 if (t <= -1.32e+39) tmp = t_1; elseif (t <= 2e-78) tmp = Float64(Float64(y / t) * Float64(z - x)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision]}, If[LessEqual[t, -1.32e+39], t$95$1, If[LessEqual[t, 2e-78], N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{if}\;t \leq -1.32 \cdot 10^{+39}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 2 \cdot 10^{-78}:\\
\;\;\;\;\frac{y}{t} \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -1.32e39 or 2e-78 < t Initial program 89.4%
Taylor expanded in z around inf
/-lowering-/.f64N/A
*-lowering-*.f6481.9
Simplified81.9%
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6486.7
Applied egg-rr86.7%
if -1.32e39 < t < 2e-78Initial program 99.1%
Taylor expanded in y around inf
div-subN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6477.9
Simplified77.9%
associate-*r/N/A
associate-*l/N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6488.0
Applied egg-rr88.0%
(FPCore (x y z t) :precision binary64 (if (<= x -3.2e+270) (* y (/ x (- t))) (if (<= x 1.75e+251) (fma (/ z t) y x) (- (* (/ y t) x)))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -3.2e+270) {
tmp = y * (x / -t);
} else if (x <= 1.75e+251) {
tmp = fma((z / t), y, x);
} else {
tmp = -((y / t) * x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (x <= -3.2e+270) tmp = Float64(y * Float64(x / Float64(-t))); elseif (x <= 1.75e+251) tmp = fma(Float64(z / t), y, x); else tmp = Float64(-Float64(Float64(y / t) * x)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[x, -3.2e+270], N[(y * N[(x / (-t)), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.75e+251], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], (-N[(N[(y / t), $MachinePrecision] * x), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.2 \cdot 10^{+270}:\\
\;\;\;\;y \cdot \frac{x}{-t}\\
\mathbf{elif}\;x \leq 1.75 \cdot 10^{+251}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;-\frac{y}{t} \cdot x\\
\end{array}
\end{array}
if x < -3.2000000000000001e270Initial program 100.0%
Taylor expanded in y around inf
div-subN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f64100.0
Simplified100.0%
Taylor expanded in z around 0
mul-1-negN/A
neg-lowering-neg.f64100.0
Simplified100.0%
if -3.2000000000000001e270 < x < 1.75000000000000002e251Initial program 94.5%
Taylor expanded in z around inf
/-lowering-/.f64N/A
*-lowering-*.f6475.3
Simplified75.3%
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6475.0
Applied egg-rr75.0%
if 1.75000000000000002e251 < x Initial program 90.2%
Taylor expanded in y around inf
div-subN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6474.4
Simplified74.4%
Taylor expanded in z around 0
mul-1-negN/A
neg-lowering-neg.f6474.4
Simplified74.4%
associate-*r/N/A
associate-*l/N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
neg-lowering-neg.f6479.1
Applied egg-rr79.1%
Final simplification76.1%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (/ x (- t))))) (if (<= x -2.35e+272) t_1 (if (<= x 9.6e+250) (fma (/ z t) y x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x / -t);
double tmp;
if (x <= -2.35e+272) {
tmp = t_1;
} else if (x <= 9.6e+250) {
tmp = fma((z / t), y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(y * Float64(x / Float64(-t))) tmp = 0.0 if (x <= -2.35e+272) tmp = t_1; elseif (x <= 9.6e+250) tmp = fma(Float64(z / t), y, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(x / (-t)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.35e+272], t$95$1, If[LessEqual[x, 9.6e+250], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \frac{x}{-t}\\
\mathbf{if}\;x \leq -2.35 \cdot 10^{+272}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 9.6 \cdot 10^{+250}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -2.35e272 or 9.60000000000000051e250 < x Initial program 93.2%
Taylor expanded in y around inf
div-subN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6482.3
Simplified82.3%
Taylor expanded in z around 0
mul-1-negN/A
neg-lowering-neg.f6482.3
Simplified82.3%
if -2.35e272 < x < 9.60000000000000051e250Initial program 94.5%
Taylor expanded in z around inf
/-lowering-/.f64N/A
*-lowering-*.f6475.3
Simplified75.3%
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6475.0
Applied egg-rr75.0%
Final simplification75.8%
(FPCore (x y z t) :precision binary64 (if (<= t -5.7e+166) x (if (<= t 3e+51) (* (/ y t) z) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -5.7e+166) {
tmp = x;
} else if (t <= 3e+51) {
tmp = (y / t) * z;
} else {
tmp = x;
}
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) :: tmp
if (t <= (-5.7d+166)) then
tmp = x
else if (t <= 3d+51) then
tmp = (y / t) * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= -5.7e+166) {
tmp = x;
} else if (t <= 3e+51) {
tmp = (y / t) * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -5.7e+166: tmp = x elif t <= 3e+51: tmp = (y / t) * z else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -5.7e+166) tmp = x; elseif (t <= 3e+51) tmp = Float64(Float64(y / t) * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -5.7e+166) tmp = x; elseif (t <= 3e+51) tmp = (y / t) * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -5.7e+166], x, If[LessEqual[t, 3e+51], N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -5.7 \cdot 10^{+166}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 3 \cdot 10^{+51}:\\
\;\;\;\;\frac{y}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -5.69999999999999977e166 or 3e51 < t Initial program 85.4%
Taylor expanded in y around 0
Simplified73.5%
if -5.69999999999999977e166 < t < 3e51Initial program 97.8%
Taylor expanded in x around 0
/-lowering-/.f64N/A
*-lowering-*.f6452.1
Simplified52.1%
associate-*l/N/A
*-lowering-*.f64N/A
/-lowering-/.f6454.2
Applied egg-rr54.2%
(FPCore (x y z t) :precision binary64 (fma (/ z t) y x))
double code(double x, double y, double z, double t) {
return fma((z / t), y, x);
}
function code(x, y, z, t) return fma(Float64(z / t), y, x) end
code[x_, y_, z_, t_] := N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{z}{t}, y, x\right)
\end{array}
Initial program 94.4%
Taylor expanded in z around inf
/-lowering-/.f64N/A
*-lowering-*.f6472.2
Simplified72.2%
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6472.3
Applied egg-rr72.3%
(FPCore (x y z t) :precision binary64 x)
double code(double x, double y, double z, double t) {
return x;
}
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
end function
public static double code(double x, double y, double z, double t) {
return x;
}
def code(x, y, z, t): return x
function code(x, y, z, t) return x end
function tmp = code(x, y, z, t) tmp = x; end
code[x_, y_, z_, t_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 94.4%
Taylor expanded in y around 0
Simplified33.7%
(FPCore (x y z t) :precision binary64 (- x (+ (* x (/ y t)) (* (- z) (/ y t)))))
double code(double x, double y, double z, double t) {
return x - ((x * (y / t)) + (-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 - ((x * (y / t)) + (-z * (y / t)))
end function
public static double code(double x, double y, double z, double t) {
return x - ((x * (y / t)) + (-z * (y / t)));
}
def code(x, y, z, t): return x - ((x * (y / t)) + (-z * (y / t)))
function code(x, y, z, t) return Float64(x - Float64(Float64(x * Float64(y / t)) + Float64(Float64(-z) * Float64(y / t)))) end
function tmp = code(x, y, z, t) tmp = x - ((x * (y / t)) + (-z * (y / t))); end
code[x_, y_, z_, t_] := N[(x - N[(N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision] + N[((-z) * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right)
\end{array}
herbie shell --seed 2024204
(FPCore (x y z t)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, D"
:precision binary64
:alt
(! :herbie-platform default (- x (+ (* x (/ y t)) (* (- z) (/ y t)))))
(+ x (/ (* y (- z x)) t)))