
(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 83.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.5
Applied rewrites98.5%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (/ (* y (- z t)) (- a t))))
(if (or (<= t_1 -5e+140) (not (<= t_1 5e+78)))
(* (- z t) (/ y (- 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+140) || !(t_1 <= 5e+78)) {
tmp = (z - t) * (y / (a - t));
} else {
tmp = y + x;
}
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) :: t_1
real(8) :: tmp
t_1 = (y * (z - t)) / (a - t)
if ((t_1 <= (-5d+140)) .or. (.not. (t_1 <= 5d+78))) then
tmp = (z - t) * (y / (a - t))
else
tmp = y + x
end if
code = tmp
end function
public static 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+140) || !(t_1 <= 5e+78)) {
tmp = (z - t) * (y / (a - t));
} else {
tmp = y + x;
}
return tmp;
}
def code(x, y, z, t, a): t_1 = (y * (z - t)) / (a - t) tmp = 0 if (t_1 <= -5e+140) or not (t_1 <= 5e+78): tmp = (z - t) * (y / (a - t)) else: tmp = 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+140) || !(t_1 <= 5e+78)) tmp = Float64(Float64(z - t) * Float64(y / Float64(a - t))); else tmp = Float64(y + x); end return tmp end
function tmp_2 = code(x, y, z, t, a) t_1 = (y * (z - t)) / (a - t); tmp = 0.0; if ((t_1 <= -5e+140) || ~((t_1 <= 5e+78))) tmp = (z - t) * (y / (a - t)); else tmp = y + x; end tmp_2 = 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+140], N[Not[LessEqual[t$95$1, 5e+78]], $MachinePrecision]], N[(N[(z - t), $MachinePrecision] * N[(y / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(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^{+140} \lor \neg \left(t\_1 \leq 5 \cdot 10^{+78}\right):\\
\;\;\;\;\left(z - t\right) \cdot \frac{y}{a - t}\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if (/.f64 (*.f64 y (-.f64 z t)) (-.f64 a t)) < -5.00000000000000008e140 or 4.99999999999999984e78 < (/.f64 (*.f64 y (-.f64 z t)) (-.f64 a t)) Initial program 62.3%
Taylor expanded in x around 0
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower--.f6487.3
Applied rewrites87.3%
if -5.00000000000000008e140 < (/.f64 (*.f64 y (-.f64 z t)) (-.f64 a t)) < 4.99999999999999984e78Initial program 99.2%
Taylor expanded in t around inf
+-commutativeN/A
lower-+.f6473.9
Applied rewrites73.9%
Final simplification79.6%
(FPCore (x y z t a)
:precision binary64
(if (<= t -5.5e+54)
(+ y x)
(if (<= t 3.2e-18)
(fma (- z t) (/ y a) x)
(if (<= t 9e+47) (* (- 1.0 (/ z t)) y) (+ y x)))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= -5.5e+54) {
tmp = y + x;
} else if (t <= 3.2e-18) {
tmp = fma((z - t), (y / a), x);
} else if (t <= 9e+47) {
tmp = (1.0 - (z / t)) * y;
} else {
tmp = y + x;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (t <= -5.5e+54) tmp = Float64(y + x); elseif (t <= 3.2e-18) tmp = fma(Float64(z - t), Float64(y / a), x); elseif (t <= 9e+47) tmp = Float64(Float64(1.0 - Float64(z / t)) * y); else tmp = Float64(y + x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[t, -5.5e+54], N[(y + x), $MachinePrecision], If[LessEqual[t, 3.2e-18], N[(N[(z - t), $MachinePrecision] * N[(y / a), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t, 9e+47], N[(N[(1.0 - N[(z / t), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision], N[(y + x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -5.5 \cdot 10^{+54}:\\
\;\;\;\;y + x\\
\mathbf{elif}\;t \leq 3.2 \cdot 10^{-18}:\\
\;\;\;\;\mathsf{fma}\left(z - t, \frac{y}{a}, x\right)\\
\mathbf{elif}\;t \leq 9 \cdot 10^{+47}:\\
\;\;\;\;\left(1 - \frac{z}{t}\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if t < -5.50000000000000026e54 or 8.99999999999999958e47 < t Initial program 67.7%
Taylor expanded in t around inf
+-commutativeN/A
lower-+.f6481.9
Applied rewrites81.9%
if -5.50000000000000026e54 < t < 3.1999999999999999e-18Initial program 94.9%
Taylor expanded in a around inf
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f6477.1
Applied rewrites77.1%
if 3.1999999999999999e-18 < t < 8.99999999999999958e47Initial program 99.9%
Taylor expanded in a around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6485.2
Applied rewrites85.2%
Taylor expanded in y around inf
Applied rewrites70.8%
(FPCore (x y z t a)
:precision binary64
(if (<= t -4.6e+54)
(+ y x)
(if (<= t 3.2e-18)
(fma (/ z a) y x)
(if (<= t 9e+47) (* (- 1.0 (/ z t)) y) (+ y x)))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= -4.6e+54) {
tmp = y + x;
} else if (t <= 3.2e-18) {
tmp = fma((z / a), y, x);
} else if (t <= 9e+47) {
tmp = (1.0 - (z / t)) * y;
} else {
tmp = y + x;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (t <= -4.6e+54) tmp = Float64(y + x); elseif (t <= 3.2e-18) tmp = fma(Float64(z / a), y, x); elseif (t <= 9e+47) tmp = Float64(Float64(1.0 - Float64(z / t)) * y); else tmp = Float64(y + x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[t, -4.6e+54], N[(y + x), $MachinePrecision], If[LessEqual[t, 3.2e-18], N[(N[(z / a), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[t, 9e+47], N[(N[(1.0 - N[(z / t), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision], N[(y + x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -4.6 \cdot 10^{+54}:\\
\;\;\;\;y + x\\
\mathbf{elif}\;t \leq 3.2 \cdot 10^{-18}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{a}, y, x\right)\\
\mathbf{elif}\;t \leq 9 \cdot 10^{+47}:\\
\;\;\;\;\left(1 - \frac{z}{t}\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if t < -4.59999999999999988e54 or 8.99999999999999958e47 < t Initial program 67.7%
Taylor expanded in t around inf
+-commutativeN/A
lower-+.f6481.9
Applied rewrites81.9%
if -4.59999999999999988e54 < t < 3.1999999999999999e-18Initial program 94.9%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6473.9
Applied rewrites73.9%
if 3.1999999999999999e-18 < t < 8.99999999999999958e47Initial program 99.9%
Taylor expanded in a around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6485.2
Applied rewrites85.2%
Taylor expanded in y around inf
Applied rewrites70.8%
(FPCore (x y z t a) :precision binary64 (if (or (<= y -2.3e+67) (not (<= y 4e+61))) (* (- z t) (/ y (- a t))) (- x (/ (* (- z t) y) t))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((y <= -2.3e+67) || !(y <= 4e+61)) {
tmp = (z - t) * (y / (a - t));
} else {
tmp = x - (((z - t) * y) / t);
}
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 ((y <= (-2.3d+67)) .or. (.not. (y <= 4d+61))) then
tmp = (z - t) * (y / (a - t))
else
tmp = x - (((z - t) * y) / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if ((y <= -2.3e+67) || !(y <= 4e+61)) {
tmp = (z - t) * (y / (a - t));
} else {
tmp = x - (((z - t) * y) / t);
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if (y <= -2.3e+67) or not (y <= 4e+61): tmp = (z - t) * (y / (a - t)) else: tmp = x - (((z - t) * y) / t) return tmp
function code(x, y, z, t, a) tmp = 0.0 if ((y <= -2.3e+67) || !(y <= 4e+61)) tmp = Float64(Float64(z - t) * Float64(y / Float64(a - t))); else tmp = Float64(x - Float64(Float64(Float64(z - t) * y) / t)); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if ((y <= -2.3e+67) || ~((y <= 4e+61))) tmp = (z - t) * (y / (a - t)); else tmp = x - (((z - t) * y) / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[y, -2.3e+67], N[Not[LessEqual[y, 4e+61]], $MachinePrecision]], N[(N[(z - t), $MachinePrecision] * N[(y / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{+67} \lor \neg \left(y \leq 4 \cdot 10^{+61}\right):\\
\;\;\;\;\left(z - t\right) \cdot \frac{y}{a - t}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{\left(z - t\right) \cdot y}{t}\\
\end{array}
\end{array}
if y < -2.2999999999999999e67 or 3.9999999999999998e61 < y Initial program 65.3%
Taylor expanded in x around 0
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower--.f6478.9
Applied rewrites78.9%
if -2.2999999999999999e67 < y < 3.9999999999999998e61Initial program 97.2%
Taylor expanded in a around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6481.3
Applied rewrites81.3%
Final simplification80.3%
(FPCore (x y z t a) :precision binary64 (if (or (<= t -4.6e+54) (not (<= t 1e-7))) (+ y x) (fma (/ z a) y x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((t <= -4.6e+54) || !(t <= 1e-7)) {
tmp = y + x;
} else {
tmp = fma((z / a), y, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((t <= -4.6e+54) || !(t <= 1e-7)) 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, -4.6e+54], N[Not[LessEqual[t, 1e-7]], $MachinePrecision]], N[(y + x), $MachinePrecision], N[(N[(z / a), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -4.6 \cdot 10^{+54} \lor \neg \left(t \leq 10^{-7}\right):\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{a}, y, x\right)\\
\end{array}
\end{array}
if t < -4.59999999999999988e54 or 9.9999999999999995e-8 < t Initial program 70.6%
Taylor expanded in t around inf
+-commutativeN/A
lower-+.f6478.0
Applied rewrites78.0%
if -4.59999999999999988e54 < t < 9.9999999999999995e-8Initial program 95.0%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6472.9
Applied rewrites72.9%
Final simplification75.3%
(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 83.5%
Taylor expanded in t around inf
+-commutativeN/A
lower-+.f6461.2
Applied rewrites61.2%
(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 2024340
(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))))