
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (- (* x (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (z + y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 97.6%
*-commutative97.6%
sub-neg97.6%
distribute-rgt-in97.6%
metadata-eval97.6%
neg-mul-197.6%
associate-+r+97.6%
unsub-neg97.6%
+-commutative97.6%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -7.2e+152)
(* x y)
(if (<= x -1.0)
(* x z)
(if (<= x 2.5e-82)
(- z)
(if (or (<= x 1.45e+54) (not (<= x 7.2e+254))) (* x y) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7.2e+152) {
tmp = x * y;
} else if (x <= -1.0) {
tmp = x * z;
} else if (x <= 2.5e-82) {
tmp = -z;
} else if ((x <= 1.45e+54) || !(x <= 7.2e+254)) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= (-7.2d+152)) then
tmp = x * y
else if (x <= (-1.0d0)) then
tmp = x * z
else if (x <= 2.5d-82) then
tmp = -z
else if ((x <= 1.45d+54) .or. (.not. (x <= 7.2d+254))) then
tmp = x * y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -7.2e+152) {
tmp = x * y;
} else if (x <= -1.0) {
tmp = x * z;
} else if (x <= 2.5e-82) {
tmp = -z;
} else if ((x <= 1.45e+54) || !(x <= 7.2e+254)) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7.2e+152: tmp = x * y elif x <= -1.0: tmp = x * z elif x <= 2.5e-82: tmp = -z elif (x <= 1.45e+54) or not (x <= 7.2e+254): tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7.2e+152) tmp = Float64(x * y); elseif (x <= -1.0) tmp = Float64(x * z); elseif (x <= 2.5e-82) tmp = Float64(-z); elseif ((x <= 1.45e+54) || !(x <= 7.2e+254)) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7.2e+152) tmp = x * y; elseif (x <= -1.0) tmp = x * z; elseif (x <= 2.5e-82) tmp = -z; elseif ((x <= 1.45e+54) || ~((x <= 7.2e+254))) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7.2e+152], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[x, 2.5e-82], (-z), If[Or[LessEqual[x, 1.45e+54], N[Not[LessEqual[x, 7.2e+254]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{+152}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{-82}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{+54} \lor \neg \left(x \leq 7.2 \cdot 10^{+254}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -7.1999999999999998e152 or 2.4999999999999999e-82 < x < 1.4499999999999999e54 or 7.19999999999999954e254 < x Initial program 93.2%
*-commutative93.2%
sub-neg93.2%
distribute-rgt-in93.2%
metadata-eval93.2%
neg-mul-193.2%
associate-+r+93.2%
unsub-neg93.2%
+-commutative93.2%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 82.8%
Taylor expanded in x around inf 69.9%
if -7.1999999999999998e152 < x < -1 or 1.4499999999999999e54 < x < 7.19999999999999954e254Initial program 98.5%
*-commutative98.5%
sub-neg98.5%
distribute-rgt-in98.5%
metadata-eval98.5%
neg-mul-198.5%
associate-+r+98.5%
unsub-neg98.5%
+-commutative98.5%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 69.3%
Taylor expanded in x around inf 67.9%
*-commutative67.9%
Simplified67.9%
if -1 < x < 2.4999999999999999e-82Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 79.7%
neg-mul-179.7%
Simplified79.7%
Final simplification73.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (* x y) z)))
(if (<= x -5.2e+152)
t_0
(if (<= x -3.8e+17)
(* x z)
(if (<= x 1.55e+54) t_0 (if (<= x 2.2e+248) (* x z) (* x y)))))))
double code(double x, double y, double z) {
double t_0 = (x * y) - z;
double tmp;
if (x <= -5.2e+152) {
tmp = t_0;
} else if (x <= -3.8e+17) {
tmp = x * z;
} else if (x <= 1.55e+54) {
tmp = t_0;
} else if (x <= 2.2e+248) {
tmp = x * z;
} else {
tmp = x * y;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = (x * y) - z
if (x <= (-5.2d+152)) then
tmp = t_0
else if (x <= (-3.8d+17)) then
tmp = x * z
else if (x <= 1.55d+54) then
tmp = t_0
else if (x <= 2.2d+248) then
tmp = x * z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * y) - z;
double tmp;
if (x <= -5.2e+152) {
tmp = t_0;
} else if (x <= -3.8e+17) {
tmp = x * z;
} else if (x <= 1.55e+54) {
tmp = t_0;
} else if (x <= 2.2e+248) {
tmp = x * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): t_0 = (x * y) - z tmp = 0 if x <= -5.2e+152: tmp = t_0 elif x <= -3.8e+17: tmp = x * z elif x <= 1.55e+54: tmp = t_0 elif x <= 2.2e+248: tmp = x * z else: tmp = x * y return tmp
function code(x, y, z) t_0 = Float64(Float64(x * y) - z) tmp = 0.0 if (x <= -5.2e+152) tmp = t_0; elseif (x <= -3.8e+17) tmp = Float64(x * z); elseif (x <= 1.55e+54) tmp = t_0; elseif (x <= 2.2e+248) tmp = Float64(x * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * y) - z; tmp = 0.0; if (x <= -5.2e+152) tmp = t_0; elseif (x <= -3.8e+17) tmp = x * z; elseif (x <= 1.55e+54) tmp = t_0; elseif (x <= 2.2e+248) tmp = x * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]}, If[LessEqual[x, -5.2e+152], t$95$0, If[LessEqual[x, -3.8e+17], N[(x * z), $MachinePrecision], If[LessEqual[x, 1.55e+54], t$95$0, If[LessEqual[x, 2.2e+248], N[(x * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot y - z\\
\mathbf{if}\;x \leq -5.2 \cdot 10^{+152}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -3.8 \cdot 10^{+17}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 1.55 \cdot 10^{+54}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{+248}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5.2000000000000001e152 or -3.8e17 < x < 1.55e54Initial program 97.3%
*-commutative97.3%
sub-neg97.3%
distribute-rgt-in97.3%
metadata-eval97.3%
neg-mul-197.3%
associate-+r+97.3%
unsub-neg97.3%
+-commutative97.3%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 91.6%
if -5.2000000000000001e152 < x < -3.8e17 or 1.55e54 < x < 2.1999999999999999e248Initial program 98.4%
*-commutative98.4%
sub-neg98.4%
distribute-rgt-in98.4%
metadata-eval98.4%
neg-mul-198.4%
associate-+r+98.4%
unsub-neg98.4%
+-commutative98.4%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 70.2%
Taylor expanded in x around inf 70.2%
*-commutative70.2%
Simplified70.2%
if 2.1999999999999999e248 < x Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 100.0%
Taylor expanded in x around inf 100.0%
Final simplification86.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.55e-53) (not (<= y 380000000.0))) (- (* x y) z) (- (* x z) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.55e-53) || !(y <= 380000000.0)) {
tmp = (x * y) - z;
} else {
tmp = (x * z) - z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-1.55d-53)) .or. (.not. (y <= 380000000.0d0))) then
tmp = (x * y) - z
else
tmp = (x * z) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.55e-53) || !(y <= 380000000.0)) {
tmp = (x * y) - z;
} else {
tmp = (x * z) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.55e-53) or not (y <= 380000000.0): tmp = (x * y) - z else: tmp = (x * z) - z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.55e-53) || !(y <= 380000000.0)) tmp = Float64(Float64(x * y) - z); else tmp = Float64(Float64(x * z) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.55e-53) || ~((y <= 380000000.0))) tmp = (x * y) - z; else tmp = (x * z) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.55e-53], N[Not[LessEqual[y, 380000000.0]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.55 \cdot 10^{-53} \lor \neg \left(y \leq 380000000\right):\\
\;\;\;\;x \cdot y - z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z - z\\
\end{array}
\end{array}
if y < -1.55000000000000008e-53 or 3.8e8 < y Initial program 95.1%
*-commutative95.1%
sub-neg95.1%
distribute-rgt-in95.1%
metadata-eval95.1%
neg-mul-195.1%
associate-+r+95.1%
unsub-neg95.1%
+-commutative95.1%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 89.8%
if -1.55000000000000008e-53 < y < 3.8e8Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 86.7%
Final simplification88.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.8e-26) (not (<= x 2.7e-82))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e-26) || !(x <= 2.7e-82)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-3.8d-26)) .or. (.not. (x <= 2.7d-82))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e-26) || !(x <= 2.7e-82)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.8e-26) or not (x <= 2.7e-82): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.8e-26) || !(x <= 2.7e-82)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.8e-26) || ~((x <= 2.7e-82))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.8e-26], N[Not[LessEqual[x, 2.7e-82]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-26} \lor \neg \left(x \leq 2.7 \cdot 10^{-82}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -3.80000000000000015e-26 or 2.7000000000000001e-82 < x Initial program 95.9%
*-commutative95.9%
sub-neg95.9%
distribute-rgt-in95.9%
metadata-eval95.9%
neg-mul-195.9%
associate-+r+95.9%
unsub-neg95.9%
+-commutative95.9%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 61.7%
Taylor expanded in x around inf 53.5%
if -3.80000000000000015e-26 < x < 2.7000000000000001e-82Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 82.2%
neg-mul-182.2%
Simplified82.2%
Final simplification65.6%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 97.6%
*-commutative97.6%
sub-neg97.6%
distribute-rgt-in97.6%
metadata-eval97.6%
neg-mul-197.6%
associate-+r+97.6%
unsub-neg97.6%
+-commutative97.6%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 40.7%
neg-mul-140.7%
Simplified40.7%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 97.6%
*-commutative97.6%
sub-neg97.6%
distribute-rgt-in97.6%
metadata-eval97.6%
neg-mul-197.6%
associate-+r+97.6%
unsub-neg97.6%
+-commutative97.6%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 40.7%
neg-mul-140.7%
Simplified40.7%
neg-sub040.7%
sub-neg40.7%
add-sqr-sqrt22.6%
sqrt-unprod16.0%
sqr-neg16.0%
sqrt-unprod1.1%
add-sqr-sqrt2.3%
Applied egg-rr2.3%
+-lft-identity2.3%
Simplified2.3%
herbie shell --seed 2024141
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))