
(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 7 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 91.4%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6496.8
Applied egg-rr96.8%
(FPCore (x y z t) :precision binary64 (if (<= (+ x (/ (* y (- z x)) t)) 2e+306) x (* t (/ x t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x + ((y * (z - x)) / t)) <= 2e+306) {
tmp = x;
} else {
tmp = t * (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) :: tmp
if ((x + ((y * (z - x)) / t)) <= 2d+306) then
tmp = x
else
tmp = t * (x / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x + ((y * (z - x)) / t)) <= 2e+306) {
tmp = x;
} else {
tmp = t * (x / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x + ((y * (z - x)) / t)) <= 2e+306: tmp = x else: tmp = t * (x / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(x + Float64(Float64(y * Float64(z - x)) / t)) <= 2e+306) tmp = x; else tmp = Float64(t * Float64(x / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x + ((y * (z - x)) / t)) <= 2e+306) tmp = x; else tmp = t * (x / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], 2e+306], x, N[(t * N[(x / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + \frac{y \cdot \left(z - x\right)}{t} \leq 2 \cdot 10^{+306}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t \cdot \frac{x}{t}\\
\end{array}
\end{array}
if (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < 2.00000000000000003e306Initial program 94.0%
Taylor expanded in y around 0
Simplified42.9%
if 2.00000000000000003e306 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) Initial program 78.9%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6498.0
Applied egg-rr98.0%
Taylor expanded in t around 0
distribute-lft-out--N/A
*-commutativeN/A
unsub-negN/A
mul-1-negN/A
associate-+r+N/A
+-commutativeN/A
/-lowering-/.f64N/A
associate-+r+N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-outN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
+-rgt-identityN/A
accelerator-lowering-fma.f6478.6
Simplified78.6%
Taylor expanded in t around inf
+-rgt-identityN/A
*-commutativeN/A
accelerator-lowering-fma.f642.9
Simplified2.9%
+-rgt-identityN/A
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6423.9
Applied egg-rr23.9%
(FPCore (x y z t) :precision binary64 (if (<= z -34.0) (fma (/ y t) z x) (if (<= z 2.9e-62) (* x (- 1.0 (/ y t))) (+ x (* (/ y t) z)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -34.0) {
tmp = fma((y / t), z, x);
} else if (z <= 2.9e-62) {
tmp = x * (1.0 - (y / t));
} else {
tmp = x + ((y / t) * z);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -34.0) tmp = fma(Float64(y / t), z, x); elseif (z <= 2.9e-62) tmp = Float64(x * Float64(1.0 - Float64(y / t))); else tmp = Float64(x + Float64(Float64(y / t) * z)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -34.0], N[(N[(y / t), $MachinePrecision] * z + x), $MachinePrecision], If[LessEqual[z, 2.9e-62], N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -34:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z, x\right)\\
\mathbf{elif}\;z \leq 2.9 \cdot 10^{-62}:\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{t} \cdot z\\
\end{array}
\end{array}
if z < -34Initial program 89.4%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6498.5
Applied egg-rr98.5%
Taylor expanded in z around inf
Simplified89.1%
if -34 < z < 2.89999999999999986e-62Initial program 92.4%
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
*-lowering-*.f6492.4
Applied egg-rr92.4%
+-commutativeN/A
sub0-negN/A
*-commutativeN/A
distribute-lft-inN/A
sub-negN/A
associate-*l/N/A
*-commutativeN/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
/-lowering-/.f6495.8
Applied egg-rr95.8%
Taylor expanded in x around inf
mul-1-negN/A
*-inversesN/A
sub-negN/A
div-subN/A
*-lowering-*.f64N/A
div-subN/A
*-inversesN/A
--lowering--.f64N/A
/-lowering-/.f6488.2
Simplified88.2%
if 2.89999999999999986e-62 < z Initial program 92.0%
Taylor expanded in z around inf
Simplified85.5%
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6490.4
Applied egg-rr90.4%
Final simplification89.0%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ y t) z x))) (if (<= z -490.0) t_1 (if (<= z 9e-62) (* x (- 1.0 (/ y t))) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma((y / t), z, x);
double tmp;
if (z <= -490.0) {
tmp = t_1;
} else if (z <= 9e-62) {
tmp = x * (1.0 - (y / t));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(Float64(y / t), z, x) tmp = 0.0 if (z <= -490.0) tmp = t_1; elseif (z <= 9e-62) tmp = Float64(x * Float64(1.0 - Float64(y / t))); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y / t), $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[z, -490.0], t$95$1, If[LessEqual[z, 9e-62], N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{y}{t}, z, x\right)\\
\mathbf{if}\;z \leq -490:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 9 \cdot 10^{-62}:\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -490 or 9.00000000000000036e-62 < z Initial program 90.7%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6497.6
Applied egg-rr97.6%
Taylor expanded in z around inf
Simplified89.7%
if -490 < z < 9.00000000000000036e-62Initial program 92.4%
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
*-lowering-*.f6492.4
Applied egg-rr92.4%
+-commutativeN/A
sub0-negN/A
*-commutativeN/A
distribute-lft-inN/A
sub-negN/A
associate-*l/N/A
*-commutativeN/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
/-lowering-/.f6495.8
Applied egg-rr95.8%
Taylor expanded in x around inf
mul-1-negN/A
*-inversesN/A
sub-negN/A
div-subN/A
*-lowering-*.f64N/A
div-subN/A
*-inversesN/A
--lowering--.f64N/A
/-lowering-/.f6488.2
Simplified88.2%
(FPCore (x y z t) :precision binary64 (if (<= t -3e+55) x (if (<= t 1.15e-9) (* (/ y t) z) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -3e+55) {
tmp = x;
} else if (t <= 1.15e-9) {
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 <= (-3d+55)) then
tmp = x
else if (t <= 1.15d-9) 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 <= -3e+55) {
tmp = x;
} else if (t <= 1.15e-9) {
tmp = (y / t) * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -3e+55: tmp = x elif t <= 1.15e-9: tmp = (y / t) * z else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -3e+55) tmp = x; elseif (t <= 1.15e-9) 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 <= -3e+55) tmp = x; elseif (t <= 1.15e-9) tmp = (y / t) * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -3e+55], x, If[LessEqual[t, 1.15e-9], N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -3 \cdot 10^{+55}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 1.15 \cdot 10^{-9}:\\
\;\;\;\;\frac{y}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -3.00000000000000017e55 or 1.15e-9 < t Initial program 82.1%
Taylor expanded in y around 0
Simplified70.2%
if -3.00000000000000017e55 < t < 1.15e-9Initial program 98.1%
Taylor expanded in x around 0
+-rgt-identityN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6450.9
Simplified50.9%
+-rgt-identityN/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6457.6
Applied egg-rr57.6%
Final simplification62.8%
(FPCore (x y z t) :precision binary64 (fma (/ y t) z x))
double code(double x, double y, double z, double t) {
return fma((y / t), z, x);
}
function code(x, y, z, t) return fma(Float64(y / t), z, x) end
code[x_, y_, z_, t_] := N[(N[(y / t), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{t}, z, x\right)
\end{array}
Initial program 91.4%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6496.8
Applied egg-rr96.8%
Taylor expanded in z around inf
Simplified77.9%
(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 91.4%
Taylor expanded in y around 0
Simplified37.1%
(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 2024195
(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)))