
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) (- a t))))
double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (a - t));
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = x + ((y * (z - t)) / (a - t))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (a - t));
}
def code(x, y, z, t, a): return x + ((y * (z - t)) / (a - t))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y * Float64(z - t)) / Float64(a - t))) end
function tmp = code(x, y, z, t, a) tmp = x + ((y * (z - t)) / (a - t)); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - t\right)}{a - t}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) (- a t))))
double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (a - t));
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = x + ((y * (z - t)) / (a - t))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (a - t));
}
def code(x, y, z, t, a): return x + ((y * (z - t)) / (a - t))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y * Float64(z - t)) / Float64(a - t))) end
function tmp = code(x, y, z, t, a) tmp = x + ((y * (z - t)) / (a - t)); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - t\right)}{a - t}
\end{array}
(FPCore (x y z t a) :precision binary64 (fma (/ (- z t) (- a t)) y x))
double code(double x, double y, double z, double t, double a) {
return fma(((z - t) / (a - t)), y, x);
}
function code(x, y, z, t, a) return fma(Float64(Float64(z - t) / Float64(a - t)), y, x) end
code[x_, y_, z_, t_, a_] := N[(N[(N[(z - t), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{z - t}{a - t}, y, x\right)
\end{array}
Initial program 84.2%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6499.1
Applied rewrites99.1%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (/ (* y (- z t)) (- a t))))
(if (or (<= t_1 -5e+54) (not (<= t_1 1e-17)))
(* (- z t) (/ y (- a t)))
(fma (/ z (- a t)) y x))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (y * (z - t)) / (a - t);
double tmp;
if ((t_1 <= -5e+54) || !(t_1 <= 1e-17)) {
tmp = (z - t) * (y / (a - t));
} else {
tmp = fma((z / (a - t)), y, x);
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(Float64(y * Float64(z - t)) / Float64(a - t)) tmp = 0.0 if ((t_1 <= -5e+54) || !(t_1 <= 1e-17)) tmp = Float64(Float64(z - t) * Float64(y / Float64(a - t))); else tmp = fma(Float64(z / Float64(a - t)), y, x); end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -5e+54], N[Not[LessEqual[t$95$1, 1e-17]], $MachinePrecision]], N[(N[(z - t), $MachinePrecision] * N[(y / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z / N[(a - t), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{y \cdot \left(z - t\right)}{a - t}\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+54} \lor \neg \left(t\_1 \leq 10^{-17}\right):\\
\;\;\;\;\left(z - t\right) \cdot \frac{y}{a - t}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{a - t}, y, x\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 y (-.f64 z t)) (-.f64 a t)) < -5.00000000000000005e54 or 1.00000000000000007e-17 < (/.f64 (*.f64 y (-.f64 z t)) (-.f64 a t)) Initial program 66.5%
Taylor expanded in x around 0
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower--.f6483.6
Applied rewrites83.6%
if -5.00000000000000005e54 < (/.f64 (*.f64 y (-.f64 z t)) (-.f64 a t)) < 1.00000000000000007e-17Initial program 99.6%
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%
Taylor expanded in t around 0
lower-/.f6473.6
Applied rewrites73.6%
Taylor expanded in z around inf
lower-/.f64N/A
lower--.f6490.5
Applied rewrites90.5%
Final simplification87.3%
(FPCore (x y z t a) :precision binary64 (if (or (<= t -1.02e+121) (not (<= t 1.02e+105))) (+ y x) (fma (/ z (- a t)) y x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((t <= -1.02e+121) || !(t <= 1.02e+105)) {
tmp = y + x;
} else {
tmp = fma((z / (a - t)), y, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((t <= -1.02e+121) || !(t <= 1.02e+105)) tmp = Float64(y + x); else tmp = fma(Float64(z / Float64(a - t)), y, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[t, -1.02e+121], N[Not[LessEqual[t, 1.02e+105]], $MachinePrecision]], N[(y + x), $MachinePrecision], N[(N[(z / N[(a - t), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.02 \cdot 10^{+121} \lor \neg \left(t \leq 1.02 \cdot 10^{+105}\right):\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{a - t}, y, x\right)\\
\end{array}
\end{array}
if t < -1.02000000000000005e121 or 1.02e105 < t Initial program 65.7%
Taylor expanded in t around inf
+-commutativeN/A
lower-+.f6482.6
Applied rewrites82.6%
if -1.02000000000000005e121 < t < 1.02e105Initial program 93.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.7
Applied rewrites98.7%
Taylor expanded in t around 0
lower-/.f6467.9
Applied rewrites67.9%
Taylor expanded in z around inf
lower-/.f64N/A
lower--.f6486.1
Applied rewrites86.1%
Final simplification84.9%
(FPCore (x y z t a) :precision binary64 (if (or (<= t -1e+72) (not (<= t 5e+27))) (+ y x) (fma (- z t) (/ y a) x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((t <= -1e+72) || !(t <= 5e+27)) {
tmp = y + x;
} else {
tmp = fma((z - t), (y / a), x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((t <= -1e+72) || !(t <= 5e+27)) tmp = Float64(y + x); else tmp = fma(Float64(z - t), Float64(y / a), x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[t, -1e+72], N[Not[LessEqual[t, 5e+27]], $MachinePrecision]], N[(y + x), $MachinePrecision], N[(N[(z - t), $MachinePrecision] * N[(y / a), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1 \cdot 10^{+72} \lor \neg \left(t \leq 5 \cdot 10^{+27}\right):\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z - t, \frac{y}{a}, x\right)\\
\end{array}
\end{array}
if t < -9.99999999999999944e71 or 4.99999999999999979e27 < t Initial program 73.1%
Taylor expanded in t around inf
+-commutativeN/A
lower-+.f6476.6
Applied rewrites76.6%
if -9.99999999999999944e71 < t < 4.99999999999999979e27Initial program 93.9%
Taylor expanded in a around inf
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f6476.6
Applied rewrites76.6%
Final simplification76.6%
(FPCore (x y z t a) :precision binary64 (if (or (<= t -1.75e-29) (not (<= t 2.9e+29))) (+ y x) (fma (/ z a) y x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((t <= -1.75e-29) || !(t <= 2.9e+29)) {
tmp = y + x;
} else {
tmp = fma((z / a), y, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((t <= -1.75e-29) || !(t <= 2.9e+29)) tmp = Float64(y + x); else tmp = fma(Float64(z / a), y, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[t, -1.75e-29], N[Not[LessEqual[t, 2.9e+29]], $MachinePrecision]], N[(y + x), $MachinePrecision], N[(N[(z / a), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.75 \cdot 10^{-29} \lor \neg \left(t \leq 2.9 \cdot 10^{+29}\right):\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{a}, y, x\right)\\
\end{array}
\end{array}
if t < -1.7499999999999999e-29 or 2.8999999999999999e29 < t Initial program 76.1%
Taylor expanded in t around inf
+-commutativeN/A
lower-+.f6474.9
Applied rewrites74.9%
if -1.7499999999999999e-29 < t < 2.8999999999999999e29Initial program 93.7%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6478.6
Applied rewrites78.6%
Final simplification76.6%
(FPCore (x y z t a) :precision binary64 (if (or (<= t -7.5e-120) (not (<= t 4.5e-51))) (+ y x) (* (/ z a) y)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((t <= -7.5e-120) || !(t <= 4.5e-51)) {
tmp = y + x;
} else {
tmp = (z / a) * y;
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: tmp
if ((t <= (-7.5d-120)) .or. (.not. (t <= 4.5d-51))) then
tmp = y + x
else
tmp = (z / a) * y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if ((t <= -7.5e-120) || !(t <= 4.5e-51)) {
tmp = y + x;
} else {
tmp = (z / a) * y;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if (t <= -7.5e-120) or not (t <= 4.5e-51): tmp = y + x else: tmp = (z / a) * y return tmp
function code(x, y, z, t, a) tmp = 0.0 if ((t <= -7.5e-120) || !(t <= 4.5e-51)) tmp = Float64(y + x); else tmp = Float64(Float64(z / a) * y); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if ((t <= -7.5e-120) || ~((t <= 4.5e-51))) tmp = y + x; else tmp = (z / a) * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[t, -7.5e-120], N[Not[LessEqual[t, 4.5e-51]], $MachinePrecision]], N[(y + x), $MachinePrecision], N[(N[(z / a), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -7.5 \cdot 10^{-120} \lor \neg \left(t \leq 4.5 \cdot 10^{-51}\right):\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;\frac{z}{a} \cdot y\\
\end{array}
\end{array}
if t < -7.5000000000000004e-120 or 4.49999999999999974e-51 < t Initial program 79.0%
Taylor expanded in t around inf
+-commutativeN/A
lower-+.f6469.5
Applied rewrites69.5%
if -7.5000000000000004e-120 < t < 4.49999999999999974e-51Initial program 93.9%
Taylor expanded in a around inf
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f6481.6
Applied rewrites81.6%
Taylor expanded in z around inf
Applied rewrites44.9%
Final simplification61.0%
(FPCore (x y z t a) :precision binary64 (+ y x))
double code(double x, double y, double z, double t, double a) {
return y + x;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = y + x
end function
public static double code(double x, double y, double z, double t, double a) {
return y + x;
}
def code(x, y, z, t, a): return y + x
function code(x, y, z, t, a) return Float64(y + x) end
function tmp = code(x, y, z, t, a) tmp = y + x; end
code[x_, y_, z_, t_, a_] := N[(y + x), $MachinePrecision]
\begin{array}{l}
\\
y + x
\end{array}
Initial program 84.2%
Taylor expanded in t around inf
+-commutativeN/A
lower-+.f6456.1
Applied rewrites56.1%
(FPCore (x y z t a) :precision binary64 (+ x (/ y (/ (- a t) (- z t)))))
double code(double x, double y, double z, double t, double a) {
return x + (y / ((a - t) / (z - t)));
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = x + (y / ((a - t) / (z - t)))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + (y / ((a - t) / (z - t)));
}
def code(x, y, z, t, a): return x + (y / ((a - t) / (z - t)))
function code(x, y, z, t, a) return Float64(x + Float64(y / Float64(Float64(a - t) / Float64(z - t)))) end
function tmp = code(x, y, z, t, a) tmp = x + (y / ((a - t) / (z - t))); end
code[x_, y_, z_, t_, a_] := N[(x + N[(y / N[(N[(a - t), $MachinePrecision] / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{\frac{a - t}{z - t}}
\end{array}
herbie shell --seed 2024337
(FPCore (x y z t a)
:name "Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisTicks from plot-0.2.3.4, B"
:precision binary64
:alt
(! :herbie-platform default (+ x (/ y (/ (- a t) (- z t)))))
(+ x (/ (* y (- z t)) (- a t))))