
(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 8 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 (if (<= y -5e+18) (fma (/ (- z x) t) y x) (- x (/ (- x z) (/ t y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -5e+18) {
tmp = fma(((z - x) / t), y, x);
} else {
tmp = x - ((x - z) / (t / y));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= -5e+18) tmp = fma(Float64(Float64(z - x) / t), y, x); else tmp = Float64(x - Float64(Float64(x - z) / Float64(t / y))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, -5e+18], N[(N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision] * y + x), $MachinePrecision], N[(x - N[(N[(x - z), $MachinePrecision] / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+18}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z - x}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x - z}{\frac{t}{y}}\\
\end{array}
\end{array}
if y < -5e18Initial program 90.1%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
if -5e18 < y Initial program 94.4%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/r*N/A
clear-num-revN/A
lower-/.f64N/A
lower-/.f6498.9
Applied rewrites98.9%
Final simplification99.1%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (+ (/ (* z y) t) x))) (if (<= z -6.5e-25) t_1 (if (<= z 3.7e-134) (* (- 1.0 (/ y t)) x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = ((z * y) / t) + x;
double tmp;
if (z <= -6.5e-25) {
tmp = t_1;
} else if (z <= 3.7e-134) {
tmp = (1.0 - (y / t)) * x;
} 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 = ((z * y) / t) + x
if (z <= (-6.5d-25)) then
tmp = t_1
else if (z <= 3.7d-134) then
tmp = (1.0d0 - (y / t)) * x
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 = ((z * y) / t) + x;
double tmp;
if (z <= -6.5e-25) {
tmp = t_1;
} else if (z <= 3.7e-134) {
tmp = (1.0 - (y / t)) * x;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = ((z * y) / t) + x tmp = 0 if z <= -6.5e-25: tmp = t_1 elif z <= 3.7e-134: tmp = (1.0 - (y / t)) * x else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(Float64(Float64(z * y) / t) + x) tmp = 0.0 if (z <= -6.5e-25) tmp = t_1; elseif (z <= 3.7e-134) tmp = Float64(Float64(1.0 - Float64(y / t)) * x); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = ((z * y) / t) + x; tmp = 0.0; if (z <= -6.5e-25) tmp = t_1; elseif (z <= 3.7e-134) tmp = (1.0 - (y / t)) * x; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[z, -6.5e-25], t$95$1, If[LessEqual[z, 3.7e-134], N[(N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{z \cdot y}{t} + x\\
\mathbf{if}\;z \leq -6.5 \cdot 10^{-25}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 3.7 \cdot 10^{-134}:\\
\;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -6.5e-25 or 3.7e-134 < z Initial program 94.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6486.9
Applied rewrites86.9%
if -6.5e-25 < z < 3.7e-134Initial program 91.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6488.2
Applied rewrites88.2%
Final simplification87.4%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (- 1.0 (/ y t)) x))) (if (<= t -5.4e-8) t_1 (if (<= t 7000000.0) (/ (* (- z x) y) t) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = (1.0 - (y / t)) * x;
double tmp;
if (t <= -5.4e-8) {
tmp = t_1;
} else if (t <= 7000000.0) {
tmp = ((z - x) * y) / t;
} 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 = (1.0d0 - (y / t)) * x
if (t <= (-5.4d-8)) then
tmp = t_1
else if (t <= 7000000.0d0) then
tmp = ((z - x) * y) / t
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 = (1.0 - (y / t)) * x;
double tmp;
if (t <= -5.4e-8) {
tmp = t_1;
} else if (t <= 7000000.0) {
tmp = ((z - x) * y) / t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = (1.0 - (y / t)) * x tmp = 0 if t <= -5.4e-8: tmp = t_1 elif t <= 7000000.0: tmp = ((z - x) * y) / t else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(Float64(1.0 - Float64(y / t)) * x) tmp = 0.0 if (t <= -5.4e-8) tmp = t_1; elseif (t <= 7000000.0) tmp = Float64(Float64(Float64(z - x) * y) / t); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (1.0 - (y / t)) * x; tmp = 0.0; if (t <= -5.4e-8) tmp = t_1; elseif (t <= 7000000.0) tmp = ((z - x) * y) / t; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[t, -5.4e-8], t$95$1, If[LessEqual[t, 7000000.0], N[(N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision] / t), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(1 - \frac{y}{t}\right) \cdot x\\
\mathbf{if}\;t \leq -5.4 \cdot 10^{-8}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 7000000:\\
\;\;\;\;\frac{\left(z - x\right) \cdot y}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -5.40000000000000005e-8 or 7e6 < t Initial program 88.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6481.6
Applied rewrites81.6%
if -5.40000000000000005e-8 < t < 7e6Initial program 98.4%
Taylor expanded in y around inf
div-subN/A
associate-/l*N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6483.7
Applied rewrites83.7%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (- 1.0 (/ y t)) x))) (if (<= x -5.4e-170) t_1 (if (<= x 4.1e-213) (/ (* z y) t) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = (1.0 - (y / t)) * x;
double tmp;
if (x <= -5.4e-170) {
tmp = t_1;
} else if (x <= 4.1e-213) {
tmp = (z * y) / t;
} 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 = (1.0d0 - (y / t)) * x
if (x <= (-5.4d-170)) then
tmp = t_1
else if (x <= 4.1d-213) then
tmp = (z * y) / t
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 = (1.0 - (y / t)) * x;
double tmp;
if (x <= -5.4e-170) {
tmp = t_1;
} else if (x <= 4.1e-213) {
tmp = (z * y) / t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = (1.0 - (y / t)) * x tmp = 0 if x <= -5.4e-170: tmp = t_1 elif x <= 4.1e-213: tmp = (z * y) / t else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(Float64(1.0 - Float64(y / t)) * x) tmp = 0.0 if (x <= -5.4e-170) tmp = t_1; elseif (x <= 4.1e-213) tmp = Float64(Float64(z * y) / t); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (1.0 - (y / t)) * x; tmp = 0.0; if (x <= -5.4e-170) tmp = t_1; elseif (x <= 4.1e-213) tmp = (z * y) / t; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -5.4e-170], t$95$1, If[LessEqual[x, 4.1e-213], N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(1 - \frac{y}{t}\right) \cdot x\\
\mathbf{if}\;x \leq -5.4 \cdot 10^{-170}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 4.1 \cdot 10^{-213}:\\
\;\;\;\;\frac{z \cdot y}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -5.3999999999999997e-170 or 4.09999999999999975e-213 < x Initial program 93.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6476.2
Applied rewrites76.2%
if -5.3999999999999997e-170 < x < 4.09999999999999975e-213Initial program 93.0%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6476.2
Applied rewrites76.2%
(FPCore (x y z t) :precision binary64 (if (<= t -2.65e+45) (* 1.0 x) (if (<= t 7500000.0) (* (/ y t) z) (* 1.0 x))))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -2.65e+45) {
tmp = 1.0 * x;
} else if (t <= 7500000.0) {
tmp = (y / t) * z;
} else {
tmp = 1.0 * 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 <= (-2.65d+45)) then
tmp = 1.0d0 * x
else if (t <= 7500000.0d0) then
tmp = (y / t) * z
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= -2.65e+45) {
tmp = 1.0 * x;
} else if (t <= 7500000.0) {
tmp = (y / t) * z;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -2.65e+45: tmp = 1.0 * x elif t <= 7500000.0: tmp = (y / t) * z else: tmp = 1.0 * x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -2.65e+45) tmp = Float64(1.0 * x); elseif (t <= 7500000.0) tmp = Float64(Float64(y / t) * z); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -2.65e+45) tmp = 1.0 * x; elseif (t <= 7500000.0) tmp = (y / t) * z; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -2.65e+45], N[(1.0 * x), $MachinePrecision], If[LessEqual[t, 7500000.0], N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.65 \cdot 10^{+45}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;t \leq 7500000:\\
\;\;\;\;\frac{y}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if t < -2.64999999999999996e45 or 7.5e6 < t Initial program 87.7%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
frac-2negN/A
div-invN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
neg-mul-1N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f6499.0
Applied rewrites99.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6481.5
Applied rewrites81.5%
Taylor expanded in y around 0
Applied rewrites69.0%
if -2.64999999999999996e45 < t < 7.5e6Initial program 98.5%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6455.9
Applied rewrites55.9%
Applied rewrites56.7%
(FPCore (x y z t) :precision binary64 (if (<= y -5000.0) (fma (/ (- z x) t) y x) (fma (/ y t) (- z x) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -5000.0) {
tmp = fma(((z - x) / t), y, x);
} else {
tmp = fma((y / t), (z - x), x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= -5000.0) tmp = fma(Float64(Float64(z - x) / t), y, x); else tmp = fma(Float64(y / t), Float64(z - x), x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, -5000.0], N[(N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5000:\\
\;\;\;\;\mathsf{fma}\left(\frac{z - x}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\
\end{array}
\end{array}
if y < -5e3Initial program 90.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
if -5e3 < y Initial program 94.3%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.5
Applied rewrites98.5%
(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 93.6%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6496.6
Applied rewrites96.6%
(FPCore (x y z t) :precision binary64 (* 1.0 x))
double code(double x, double y, double z, double t) {
return 1.0 * 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 = 1.0d0 * x
end function
public static double code(double x, double y, double z, double t) {
return 1.0 * x;
}
def code(x, y, z, t): return 1.0 * x
function code(x, y, z, t) return Float64(1.0 * x) end
function tmp = code(x, y, z, t) tmp = 1.0 * x; end
code[x_, y_, z_, t_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot x
\end{array}
Initial program 93.6%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
frac-2negN/A
div-invN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
neg-mul-1N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f6496.5
Applied rewrites96.5%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6464.9
Applied rewrites64.9%
Taylor expanded in y around 0
Applied rewrites39.5%
(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 2024298
(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)))