
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) (- z a))))
double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (z - a));
}
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)) / (z - a))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (z - a));
}
def code(x, y, z, t, a): return x + ((y * (z - t)) / (z - a))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y * Float64(z - t)) / Float64(z - a))) end
function tmp = code(x, y, z, t, a) tmp = x + ((y * (z - t)) / (z - a)); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - t\right)}{z - a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) (- z a))))
double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (z - a));
}
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)) / (z - a))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (z - a));
}
def code(x, y, z, t, a): return x + ((y * (z - t)) / (z - a))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y * Float64(z - t)) / Float64(z - a))) end
function tmp = code(x, y, z, t, a) tmp = x + ((y * (z - t)) / (z - a)); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - t\right)}{z - a}
\end{array}
(FPCore (x y z t a) :precision binary64 (+ (/ y (/ (- z a) (- z t))) x))
double code(double x, double y, double z, double t, double a) {
return (y / ((z - a) / (z - t))) + 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 / ((z - a) / (z - t))) + x
end function
public static double code(double x, double y, double z, double t, double a) {
return (y / ((z - a) / (z - t))) + x;
}
def code(x, y, z, t, a): return (y / ((z - a) / (z - t))) + x
function code(x, y, z, t, a) return Float64(Float64(y / Float64(Float64(z - a) / Float64(z - t))) + x) end
function tmp = code(x, y, z, t, a) tmp = (y / ((z - a) / (z - t))) + x; end
code[x_, y_, z_, t_, a_] := N[(N[(y / N[(N[(z - a), $MachinePrecision] / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{\frac{z - a}{z - t}} + x
\end{array}
Initial program 86.0%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6498.8
Applied rewrites98.8%
Final simplification98.8%
(FPCore (x y z t a) :precision binary64 (let* ((t_1 (* (/ y (- z a)) (- z t))) (t_2 (/ (* (- z t) y) (- z a)))) (if (<= t_2 -4e+22) t_1 (if (<= t_2 1e+203) (fma (/ z (- z a)) y x) t_1))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (y / (z - a)) * (z - t);
double t_2 = ((z - t) * y) / (z - a);
double tmp;
if (t_2 <= -4e+22) {
tmp = t_1;
} else if (t_2 <= 1e+203) {
tmp = fma((z / (z - a)), y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(Float64(y / Float64(z - a)) * Float64(z - t)) t_2 = Float64(Float64(Float64(z - t) * y) / Float64(z - a)) tmp = 0.0 if (t_2 <= -4e+22) tmp = t_1; elseif (t_2 <= 1e+203) tmp = fma(Float64(z / Float64(z - a)), y, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(y / N[(z - a), $MachinePrecision]), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -4e+22], t$95$1, If[LessEqual[t$95$2, 1e+203], N[(N[(z / N[(z - a), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{y}{z - a} \cdot \left(z - t\right)\\
t_2 := \frac{\left(z - t\right) \cdot y}{z - a}\\
\mathbf{if}\;t\_2 \leq -4 \cdot 10^{+22}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 \leq 10^{+203}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{z - a}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 y (-.f64 z t)) (-.f64 z a)) < -4e22 or 9.9999999999999999e202 < (/.f64 (*.f64 y (-.f64 z t)) (-.f64 z a)) Initial program 64.9%
Taylor expanded in x around 0
associate-/l*N/A
div-subN/A
distribute-lft-out--N/A
associate-/l*N/A
*-commutativeN/A
associate-/l*N/A
associate-/l*N/A
*-commutativeN/A
associate-/l*N/A
distribute-rgt-out--N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower--.f6486.5
Applied rewrites86.5%
if -4e22 < (/.f64 (*.f64 y (-.f64 z t)) (-.f64 z a)) < 9.9999999999999999e202Initial program 99.9%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f6493.0
Applied rewrites93.0%
Final simplification90.4%
(FPCore (x y z t a) :precision binary64 (let* ((t_1 (* (/ t a) y)) (t_2 (/ (* (- z t) y) (- z a)))) (if (<= t_2 -1e+152) t_1 (if (<= t_2 2e+303) (+ y x) t_1))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (t / a) * y;
double t_2 = ((z - t) * y) / (z - a);
double tmp;
if (t_2 <= -1e+152) {
tmp = t_1;
} else if (t_2 <= 2e+303) {
tmp = y + x;
} else {
tmp = t_1;
}
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) :: t_2
real(8) :: tmp
t_1 = (t / a) * y
t_2 = ((z - t) * y) / (z - a)
if (t_2 <= (-1d+152)) then
tmp = t_1
else if (t_2 <= 2d+303) then
tmp = y + x
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double t_1 = (t / a) * y;
double t_2 = ((z - t) * y) / (z - a);
double tmp;
if (t_2 <= -1e+152) {
tmp = t_1;
} else if (t_2 <= 2e+303) {
tmp = y + x;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t, a): t_1 = (t / a) * y t_2 = ((z - t) * y) / (z - a) tmp = 0 if t_2 <= -1e+152: tmp = t_1 elif t_2 <= 2e+303: tmp = y + x else: tmp = t_1 return tmp
function code(x, y, z, t, a) t_1 = Float64(Float64(t / a) * y) t_2 = Float64(Float64(Float64(z - t) * y) / Float64(z - a)) tmp = 0.0 if (t_2 <= -1e+152) tmp = t_1; elseif (t_2 <= 2e+303) tmp = Float64(y + x); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t, a) t_1 = (t / a) * y; t_2 = ((z - t) * y) / (z - a); tmp = 0.0; if (t_2 <= -1e+152) tmp = t_1; elseif (t_2 <= 2e+303) tmp = y + x; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(t / a), $MachinePrecision] * y), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1e+152], t$95$1, If[LessEqual[t$95$2, 2e+303], N[(y + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{t}{a} \cdot y\\
t_2 := \frac{\left(z - t\right) \cdot y}{z - a}\\
\mathbf{if}\;t\_2 \leq -1 \cdot 10^{+152}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 \leq 2 \cdot 10^{+303}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 y (-.f64 z t)) (-.f64 z a)) < -1e152 or 2e303 < (/.f64 (*.f64 y (-.f64 z t)) (-.f64 z a)) Initial program 54.7%
Taylor expanded in x around 0
associate-/l*N/A
div-subN/A
distribute-lft-out--N/A
associate-/l*N/A
*-commutativeN/A
associate-/l*N/A
associate-/l*N/A
*-commutativeN/A
associate-/l*N/A
distribute-rgt-out--N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower--.f6493.3
Applied rewrites93.3%
Taylor expanded in z around 0
Applied rewrites39.1%
Applied rewrites53.3%
if -1e152 < (/.f64 (*.f64 y (-.f64 z t)) (-.f64 z a)) < 2e303Initial program 99.9%
Taylor expanded in z around inf
lower-+.f6473.2
Applied rewrites73.2%
Final simplification67.0%
(FPCore (x y z t a) :precision binary64 (let* ((t_1 (fma (/ z (- z a)) y x))) (if (<= z -0.036) t_1 (if (<= z 1.9e-20) (fma (/ t a) y x) t_1))))
double code(double x, double y, double z, double t, double a) {
double t_1 = fma((z / (z - a)), y, x);
double tmp;
if (z <= -0.036) {
tmp = t_1;
} else if (z <= 1.9e-20) {
tmp = fma((t / a), y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a) t_1 = fma(Float64(z / Float64(z - a)), y, x) tmp = 0.0 if (z <= -0.036) tmp = t_1; elseif (z <= 1.9e-20) tmp = fma(Float64(t / a), y, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(z / N[(z - a), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]}, If[LessEqual[z, -0.036], t$95$1, If[LessEqual[z, 1.9e-20], N[(N[(t / a), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{z}{z - a}, y, x\right)\\
\mathbf{if}\;z \leq -0.036:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.9 \cdot 10^{-20}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t}{a}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -0.0359999999999999973 or 1.8999999999999999e-20 < z Initial program 78.5%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f6487.9
Applied rewrites87.9%
if -0.0359999999999999973 < z < 1.8999999999999999e-20Initial program 92.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6497.6
Applied rewrites97.6%
Taylor expanded in z around 0
lower-/.f6483.1
Applied rewrites83.1%
(FPCore (x y z t a) :precision binary64 (let* ((t_1 (fma z (/ y (- z a)) x))) (if (<= z -0.036) t_1 (if (<= z 1.9e-20) (fma (/ t a) y x) t_1))))
double code(double x, double y, double z, double t, double a) {
double t_1 = fma(z, (y / (z - a)), x);
double tmp;
if (z <= -0.036) {
tmp = t_1;
} else if (z <= 1.9e-20) {
tmp = fma((t / a), y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a) t_1 = fma(z, Float64(y / Float64(z - a)), x) tmp = 0.0 if (z <= -0.036) tmp = t_1; elseif (z <= 1.9e-20) tmp = fma(Float64(t / a), y, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(z * N[(y / N[(z - a), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[z, -0.036], t$95$1, If[LessEqual[z, 1.9e-20], N[(N[(t / a), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(z, \frac{y}{z - a}, x\right)\\
\mathbf{if}\;z \leq -0.036:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.9 \cdot 10^{-20}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t}{a}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -0.0359999999999999973 or 1.8999999999999999e-20 < z Initial program 78.5%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f6487.9
Applied rewrites87.9%
Applied rewrites86.3%
if -0.0359999999999999973 < z < 1.8999999999999999e-20Initial program 92.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6497.6
Applied rewrites97.6%
Taylor expanded in z around 0
lower-/.f6483.1
Applied rewrites83.1%
(FPCore (x y z t a) :precision binary64 (if (<= z -64.0) (+ y x) (if (<= z 2.2e+44) (fma (/ t a) y x) (+ y x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -64.0) {
tmp = y + x;
} else if (z <= 2.2e+44) {
tmp = fma((t / a), y, x);
} else {
tmp = y + x;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -64.0) tmp = Float64(y + x); elseif (z <= 2.2e+44) tmp = fma(Float64(t / a), y, x); else tmp = Float64(y + x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -64.0], N[(y + x), $MachinePrecision], If[LessEqual[z, 2.2e+44], N[(N[(t / a), $MachinePrecision] * y + x), $MachinePrecision], N[(y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -64:\\
\;\;\;\;y + x\\
\mathbf{elif}\;z \leq 2.2 \cdot 10^{+44}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t}{a}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if z < -64 or 2.19999999999999996e44 < z Initial program 77.1%
Taylor expanded in z around inf
lower-+.f6480.4
Applied rewrites80.4%
if -64 < z < 2.19999999999999996e44Initial program 92.4%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6497.8
Applied rewrites97.8%
Taylor expanded in z around 0
lower-/.f6480.4
Applied rewrites80.4%
Final simplification80.4%
(FPCore (x y z t a) :precision binary64 (if (<= z -64.0) (+ y x) (if (<= z 2.2e+44) (fma (/ y a) t x) (+ y x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -64.0) {
tmp = y + x;
} else if (z <= 2.2e+44) {
tmp = fma((y / a), t, x);
} else {
tmp = y + x;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -64.0) tmp = Float64(y + x); elseif (z <= 2.2e+44) tmp = fma(Float64(y / a), t, x); else tmp = Float64(y + x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -64.0], N[(y + x), $MachinePrecision], If[LessEqual[z, 2.2e+44], N[(N[(y / a), $MachinePrecision] * t + x), $MachinePrecision], N[(y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -64:\\
\;\;\;\;y + x\\
\mathbf{elif}\;z \leq 2.2 \cdot 10^{+44}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, t, x\right)\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if z < -64 or 2.19999999999999996e44 < z Initial program 77.1%
Taylor expanded in z around inf
lower-+.f6480.4
Applied rewrites80.4%
if -64 < z < 2.19999999999999996e44Initial program 92.4%
Taylor expanded in z around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6479.8
Applied rewrites79.8%
Final simplification80.1%
(FPCore (x y z t a) :precision binary64 (fma (/ (- z t) (- z a)) y x))
double code(double x, double y, double z, double t, double a) {
return fma(((z - t) / (z - a)), y, x);
}
function code(x, y, z, t, a) return fma(Float64(Float64(z - t) / Float64(z - a)), y, x) end
code[x_, y_, z_, t_, a_] := N[(N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{z - t}{z - a}, y, x\right)
\end{array}
Initial program 86.0%
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%
(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 86.0%
Taylor expanded in z around inf
lower-+.f6459.4
Applied rewrites59.4%
Final simplification59.4%
(FPCore (x y z t a) :precision binary64 (+ x (/ y (/ (- z a) (- z t)))))
double code(double x, double y, double z, double t, double a) {
return x + (y / ((z - a) / (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 / ((z - a) / (z - t)))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + (y / ((z - a) / (z - t)));
}
def code(x, y, z, t, a): return x + (y / ((z - a) / (z - t)))
function code(x, y, z, t, a) return Float64(x + Float64(y / Float64(Float64(z - a) / Float64(z - t)))) end
function tmp = code(x, y, z, t, a) tmp = x + (y / ((z - a) / (z - t))); end
code[x_, y_, z_, t_, a_] := N[(x + N[(y / N[(N[(z - a), $MachinePrecision] / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{\frac{z - a}{z - t}}
\end{array}
herbie shell --seed 2024235
(FPCore (x y z t a)
:name "Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisTicks from plot-0.2.3.4, A"
:precision binary64
:alt
(! :herbie-platform default (+ x (/ y (/ (- z a) (- z t)))))
(+ x (/ (* y (- z t)) (- z a))))